formula for COM is = mass of A (distance from the line we want to find COM) +mass of B (d from line)+ mass of C (d from line) / mass of( A+B+C)
as all spheres are identical so mass will be same of all 3
now there can be 2 ways of approaching this question
first one if we find COM from the line passing through center of sphere of A then its distance from line will be 0
so m(0)+m(2R)+m(4R) / 3m = 2R
second one if we are finding it from the line A is starting then distance of center of A will be R so m(R)+m(3R)+m(5R) / 3m= 3R
hope it will help you