The Hamiltonian of a point mass connected to a fixed point by a spring in (1-dimensional) space is $$H(x,p)=\frac{p^2}{2m}+\frac{1}{2}kx^2\tag{1}\label{eq1}$$ The Hamiltonian equations are $$\begin{equation} \frac{dx}{dt}= \frac{\partial H}{\partial p} = \frac{p}{m}\\ \frac{dp}{dt}= -\frac{\partial H}{\partial x} = -kx \tag{2} \end{equation}$$ If $(x(t),\,p(t))$ is a solution of this equation then $(x(t)+vt,\,p(t)+mv)$ isn't, so Hamiltonian $(\ref{eq1})$ isn't Galilean-invariant. This isn't surprising if we know the physical background: the "fixed point" is fixed only in one special reference frame. The situation immediately changes when we consider two point-masses connected to each other by a spring. For this system, the Hamiltonian is $$H(x_1,x_2,p_1,p_2) = \frac{p_1^2}{2m_1}+\frac{p_2^2}{2m_2} + \frac{1}{2}k(x_2-x_1)^2\tag{3}\label{eq3}$$ , and the Hamiltonian equations are: $$\begin{equation} \frac{dx_1}{dt}= \frac{\partial H}{\partial p_1} = \frac{p_1}{m_1}\\ \frac{dx_2}{dt}= \frac{\partial H}{\partial p_2} = \frac{p_2}{m_1}\\ \frac{dp_1}{dt}= -\frac{\partial H}{\partial x_1} = k(x_2-x_1)\\ \frac{dp_2}{dt}= -\frac{\partial H}{\partial x_2} = k(x_1-x_2)\tag{4} \end{equation}$$ In this case, together with solution $s_0(t)=(x_1(t),x_2(t),p_1(t),p_2(t))$, $s_v(t) =(x_1(t)+vt,\,x_2(t)+vt,\,p_1(t)+m_1v,\,p_2(t)+m_2v)$ is also a solution, so Hamiltonian $(\ref{eq3})$ is Galilean-invariant as expected.
My question: what is the general, exact mathematical condition for a Hamiltonian $H$ of a system of point masses to be invariant for a Galilean boost?