As the order of numbers in the input doesn't matter, let's suppose that they are given in sorted order, and let's say that the median of numbers ai,aj,ak is aj for i<j<k.
Suppose that our triples are (a_{x_i}, a_{y_i}, a_{z_i}) with $x_i<