Mary has a total of $5000 invested in two accounts. One account pays 5% and the other 8%. Her interest in the first year was $331. Write and solve a system of equations to find out how much she has invested in both accounts.

.05 x + .08(5000-x) = 331

To solve this problem, we need to set up a system of equations using the given information.

Let's assume Mary invested x dollars in the account that pays 5% interest, and y dollars in the account that pays 8% interest.

The interest earned on the first account can be calculated by multiplying the amount invested (x) by the interest rate (5% or 0.05):

Interest on the first account = 0.05x

The interest earned on the second account can be calculated by multiplying the amount invested (y) by the interest rate (8% or 0.08):

Interest on the second account = 0.08y

According to the problem, Mary's total interest earned in the first year is $331. So, we can write the first equation as:

0.05x + 0.08y = 331 ................. (Equation 1)

Mary has a total of $5000 invested in both accounts. Therefore, the sum of the amounts invested in each account should equal $5000:

x + y = 5000 ....................... (Equation 2)

To solve this system of equations, we can use any method, such as substitution or elimination.

Let's solve by substitution:
1. Solve Equation 2 for x, which gives: x = 5000 - y.
2. Substitute this value of x in Equation 1:

0.05(5000 - y) + 0.08y = 331

250 - 0.05y + 0.08y = 331

Combine like terms:

0.03y = 331 - 250

0.03y = 81

3. Solve for y by dividing both sides of the equation by 0.03:

y = 81 / 0.03

y ≈ 2700

Now, substitute the value of y back into Equation 2 to find x:

x + 2700 = 5000

x = 5000 -2700

x ≈ 2300

So, Mary has invested approximately $2300 in the account paying 5% interest, and approximately $2700 in the account paying 8% interest.