Alan and John have some stamps. If Alan gives John 80 stamps, both of them will have the same number of stamps. If John gives Alan 58 stamps, the number of stamps Alan has to the number of stamps John has will be in the ratio 4:1. How many stamps do the two boys have altogether?

Alans number --- x

John's number --- y

Case1
Alan: x-80
John: y+80

x-80 = y+80
x - y = 160
x = y + 160

case2
John: y-58
Alan: x+58

Alan : John = 4:1
(x+58)/(y-58) = 4
x + 58 = 4y - 232
use substi.
(y+160) + 58 = 4y - 232
450 = 3y
y = 150
then x = y + 160 = 310

Alan had 310
John had 150