Let the money with the first person and second person be Rs x and Rs y respectively. According to the question

Subtracting equation (1) from equation (3), we obtain:

Putting the value of x in equation (1), we obtain

Thus, the two friends had 40 Rs and 170 Rs with them.