Solution (source code)

= Solution

Since every $p_i$ is fixed, $f\circ\varphi$ has poles only among the first $g+1$ points, with order at most one: a biholomorphic change of coordinate preserves pole order. Thus $h=f-f\circ\varphi$ also has at most $g+1$ poles, counted with multiplicity. At every $p_i$ with $i>g+1$, both terms are finite and equal, so $h(p_i)=0$.

If $h$ were not zero, its <principal divisor> would have degree zero. It would therefore have at most $g+1$ zeros counted with multiplicity. But it has at least $n-(g+1)$ distinct zeros. When $n>2g+2$ this number exceeds $g+1$, a contradiction. Consequently
$$
\boxed{n>2g+2\implies f=f\circ\varphi.}
$$