Cesar invested a total of $41000 in two accounts. The first account earned 7% after one year. However the second account suffered a 5% loss in the same time. At the end of one year the total amount of money gained was $1670. How much he invested in each account?