Solution (source code)

= Solution

For a <compact boson> $X\sim X+2\pi R$, a closed spatial circuit of the worldsheet may wind around the target circle:
$$
\boxed{X(\tau,\sigma+2\pi)=X(\tau,\sigma)+2\pi Rw,
\qquad w\in\mathbb Z}.
$$
Single-valued target-space wavefunctions quantize the zero-mode momentum as $p=n/R$, $n\in\mathbb Z$. In the convention
$$
p_L=\frac nR+wR,
\qquad
p_R=\frac nR-wR,
$$
the Hamiltonian and worldsheet momentum become
$$
\boxed{H=\frac12\left(\frac{n^2}{R^2}+w^2R^2\right)-\frac1{12}
+\sum_{k\geq1}k(N_k+\widetilde N_k)},
$$
$$
\boxed{P=nw+\sum_{k\geq1}k(\widetilde N_k-N_k)}.
$$
The $nw$ term is the zero-mode contribution to <closed-string level matching>.