try thinking like this:

how much do mary's friends donate

this is number of people * donation

number of people: n

donation: 500

amount: 500n

how much dotheir friendsdonate

number of people: n*n

donation: 500

Amount = 500n^2

so the total donated is:

500n + 500n^2 = 500(n^2 + n)