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.

Let's denote the amount invested in the first account as x, and the amount invested in the second account as y.

According to the problem, Mary has a total of $5000 invested, so the first equation is:
x + y = 5000 (Equation 1)

We are also given that the interest in the first year from the first account was $331, which we can calculate by multiplying the amount invested (x) by the interest rate (0.05):
0.05x = 331 (Equation 2)

In order to solve this system of equations, let's solve Equation 1 for x:
x = 5000 - y

Next, substitute this expression for x into Equation 2:
0.05(5000 - y) = 331

Now, let's simplify and solve for y:
250 - 0.05y = 331
-0.05y = 331 - 250
-0.05y = 81
y = 81 / (-0.05)
y ≈ -1620

However, since the amount invested cannot be negative, there seems to be an error with the given information or the calculations.

Please double-check the information provided and ensure all values are accurate.

To solve this problem, let's use two variables to represent the amounts Mary invested in each account. Let's call the amount she invested in the account that pays 5% "x" dollars, and the amount she invested in the account that pays 8% "y" dollars.

We are given that Mary invested a total of $5000, so our first equation is:

x + y = 5000

We are also given that the interest she earned in the first year was $331. The interest earned from the account that pays 5% is calculated by multiplying the amount invested by the interest rate:

0.05x

Similarly, the interest earned from the account that pays 8% is calculated by multiplying the amount invested by the interest rate:

0.08y

We can write a second equation based on the interest earned:

0.05x + 0.08y = 331

Now we have a system of equations:

Equation 1: x + y = 5000
Equation 2: 0.05x + 0.08y = 331

To solve this system of equations, we can use any method such as substitution or elimination. Let's solve it using the elimination method.

To eliminate the decimals, we can multiply Equation 2 by 100:

100(0.05x + 0.08y) = 100(331)
5x + 8y = 33100

Now, we can multiply Equation 1 by -5:

-5(x + y) = -5(5000)
-5x - 5y = -25000

Now, we add both equations together:

(-5x - 5y) + (5x + 8y) = -25000 + 33100
3y = 8100

Finally, we solve for y by dividing both sides of the equation by 3:

3y/3 = 8100/3
y = 2700

Now, we substitute the value of y back into Equation 1 to solve for x:

x + 2700 = 5000
x = 2300

Therefore, Mary invested $2300 in the account that pays 5% and $2700 in the account that pays 8%.