Solution (source code)

= Solution

The <strong maximum principle for subharmonic functions> states that an upper semicontinuous subharmonic function on a connected open set which attains its finite global maximum at an interior point is constant. In particular this holds for a harmonic function; negating the function gives the corresponding minimum principle for superharmonic functions.

Let the maximum be $M$, attained at $x_0$. For every sufficiently small ball centered at $x_0$, the <mean value inequality> gives
$$
M=u(x_0)\leq\frac1{|B_r|}\int_{B_r(x_0)}u\leq M.
$$
Therefore its average equals $M$. If some point in the ball had value less than $M$, <upper semicontinuity> would give an open neighborhood where $u\leq M-\eta$ for some $\eta>0$. That positive-measure neighborhood would make the average strictly less than $M$, a contradiction. Thus $u=M$ throughout a neighborhood of $x_0$.

The same argument at each maximizing point shows that $\{u=M\}$ is open; it is also closed relative to the domain by upper semicontinuity. It is nonempty, so connectedness forces it to be the whole domain. Without connectedness, constancy is only guaranteed on the component containing the maximizing point.