Solution (source code)

= Solution

Apply Riemann-Roch at $D=K$ and use $\ell(K)=g$ and $\ell(0)=1$:
$$
g-1=\deg K+1-g.
$$
Rearranging gives \b[$\deg K=2g-2$]. This holds for every <canonical divisor>, since any two differ by a <principal divisor> of degree zero.