I am solving a problem and someone tol me to use this formula

MgH = (1/2)*k*(H-2-10)^2 + Mg*2

where did this equation come from. Its not in my book. What concepts does it use?
Is it solved correctly?
MgH = (1/2)*k*(H-2-10)^2 + Mg*2
MgH = 0.5k(H-12)^2 + 2Mg
MgH = 05k(H^2 - 24H + 144) + 2Mg
MgH = 0.5kH^2 - 12kH + 72k + 2Mg
0.5kH^2 - 12kH - MgH + 72k + 2Mg = 0
0.5kH^2 - H(12k + Mg) + (72k + 2Mg) = 0

The formula looks suspicious. The left side units are MgH and the rightmost term of the right side is Mg*2. Unless H represents some "unitless" parameter (not impossible, but unlikely), the units do not match.