Distance between centers of two intersecting circles if the radii and common chord length is given

Given are two circles, with given radii, which intersect each other and have a common chord. The length of the common chord is given. The task is to find the distance between the centres of the two circles.


Input:  r1 = 24, r2 = 37, x = 40
Output: 44

Input: r1 = 14, r2 = 7, x = 10
Output: 17