When thinking about the perfect diet, people usually try to hit a single "ideal" number of calories or macro count. The ideal diet usually involves a laser-like focus on optimizing your intake of fruits and veggies, proteins, carbs, and healthy fats so you're feeding your body the best to stay healthy and strong.

But what you eat can also affect your mental health, depending upon your age, says recent research published in Nutritional Neuroscience.

For the study, researchers polled people of all ages around the world with the Food-Mood Questionnaire, which includes food-related questions focused on neurochemistry and neurobiology. After crunching the data, the researchers noticed a distinct trend: Younger people (ages 18-29) prefer food like meat, which can improve a person's mood by increasing the intensity of neurotransmitter precursors in the brain.

“Young-adult mood appears to be sensitive to a build-up of brain chemicals,” said study co-author Lina Begdache, Ph.D., assistant professor of health and wellness studies at Binghamton University in New York. “Regular consumption of meat leads to a build-up of two brain chemicals—serotonin and dopamine—known to promote mood. Regular exercise leads to a build-up of these and other neurotransmitters as well. In other words, young adults who ate meat [red or white] less than three times a week and exercised less than three times a week showed a significant mental distress.”

People over 30, on the other hand, typically ate more food like fruit (which offers more antioxidants), stayed away from stuff that primes the sympathetic nervous system (like coffee), and avoided skipping breakfast.

“With aging, there is an increase in free radical formation [oxidants], so our need for antioxidants increases,” she said. “Free radicals cause disturbances in the brain, which increases the risk for mental distress. Also, our ability to regulate stress decreases, so if we consume food that activates the stress response—such as coffee and too much carbohydrates—we are more likely to experience mental distress."

Of course, you should always focus your diet on your broader health and fitness goals. If you're trying to gain muscle, focus on these 30 protein-rich foods; if you're trying to lose weight, load up on these fiber-packed eats.