Problem: Find all real-valued functions $f$ defined on pairs of real numbers,
having the following property: for all real numbers $a, b, c$,
the median of $f(a,b), f(b,c), f(c,a)$ equals the median of $a, b, c$.

(The \emph{median} of three real numbers, not necessarily distinct,
is the number that is in the middle when the three numbers
are arranged in nondecreasing order.)

Solution: The following solution is joint with Andrew He.

We prove the following main claim,
from which repeated applications can deduce the problem.

\begin{claim*}
  Let $a < b < c$ be arbitrary. On $\{a,b,c\}^2$,
  $f$ takes one of the following two forms,
  where the column indicates the $x$-value
  and the row indicates the $y$-value.
  \[
   \begin{array}{c|rrr}
    f & a & b & c \\ \hline
    a & a & b & \ge c \\
    b & \le a & b & \ge c \\
    c & \le a & b & c
   \end{array}
   \qquad
   \text{or}
   \qquad
   \begin{array}{c|rrr}
    f & a & b & c \\ \hline
    a & a & \le a & \le a \\
    b & b & b & b \\
    c & \ge c & \ge c & c
   \end{array}
  \]
\end{claim*}
\begin{proof}
  First, we of course have $f(x,x) = x$ for all $x$.
  Now:
  \begin{itemize}
  \ii By considering the assertion for $(a,a,c)$ and $(a,c,c)$
  we see that one of $f(a,c)$ and $f(c,a)$ is $\ge c$
  and the other is $\le a$.
  \ii Hence, by considering $(a,b,c)$ we find that
  one of $f(a,b)$ and $f(b,c)$ must be $b$,
  and similarly for $f(b,a)$ and $f(c,b)$.
  \ii Now, WLOG $f(b,a) = b$; we prove we get the first case.
  \ii By considering $(a,a,b)$ we deduce $f(a,b) \le a$,
  so $f(b,c) = b$ and then $f(c,b) \ge c$.
  \ii Finally, considering $(c,b,a)$ once again
  in conjunction with the first bullet, we arrive at the conclusion
  that $f(a,c) \le a$; similarly $f(c,a) \ge c$.
  \qedhere
  \end{itemize}
\end{proof}
From this it's easy to obtain that $f(x,y) \equiv x$
or $f(x,y) \equiv y$ are the only solutions.