.
From the condition, you have these two equations
(1) J - 20 = P + 20 ("If Julian gave Patrick 20 marbles, both of them would have an equal number of marbles")
(2) 3*(P - 20) = J + 20 ("If Patrick gave Julian 20 marbles, Julian would have three times as many marbles as Patrick")
From eq(1), express J = P+40 and substitute it into eq(2). You will get
3*(P-20) = (P+40) + 20, or
3P - 60 = P + 60,
3P - P = 60 + 60
2P = 120 ====> P = 120/2 = 60.
Answer. Patrick had initially 60 marbles; Julian had P+40 = 60+40 = 100 marbles.
Check on your own that the equations (1) and (2) are hold in this case.