Let ages of Ram and Shyam be 5x and 7x respectively.
So, ratio = 5 : 7
Ram's age + 9 = 5x + 9
Shyam's age - 9 = 7x - 9
Ratio of the new ages = 2 : 1
i.e. 5x - 9 / 7x - 9 = 2 / 1
1(5x + 9) = 2(7x- 9 )
5x + 9 = 14x - 18
18 + 9 = 14x - 5x
27 = 9x
x = 3
So, The present ages of Ram and Shyam is 15 (3 x 5) and 21 (3 x 7) respectively.