Solution:
Note that rearranging the columns does not change the medians, hence we may sort the first row, so that d1,1≤d1,2≤…≤d1,7. The calculations are much simplified if we subtract i−1 from each row. In other words, we put Di,j=di,j−(i−1). This subtracts i−1 from the median mi as well - that is if Mi is the median of Di,j's, then Mi=mi−(i−1). Thus the sum of the Mi's is equal to the sum of the mi's minus 0+1+2+…+9=45. We shall show that sum of Mi's is 0, so that the sum of the mi's is 45 and the average is always 4.5.
Note that since D1,1≤D1,2≤…≤D1,7 the entry D1,4 is a median. The fourth column will continue to contain a median until di,7=0 (at which point the third column will contain a median), that is 10−D1,7 times (note that d1,7=D1,7). The sum of those medians is then equal D1,4(10−D1,7). After that, median moves to the third column and stays there until di,6=0 (this may be no time at all, if d1,6=d1,7, but that will not affect the calculation). The contribution of those medians is D1,3(D1,7−D1,6). Continuing this way we see that the medians in the second column contribute D1,2(D1,6−D1,5) and ones in the first column D1,1(D1,5−D1,4). A median then moves to the seventh column, but by that point its value has dropped, Di,7=D1,7−10. The contribution of those medians is then (D1,7−10)(D1,4−D1,3). Similarly for those in sixth and fifth columns we get (D1,6−10)(D1,3−D1,2) and (D1,5−10)(D1,2−D1,1). Finally the median moves to the fourth column again, staying there remaining D1,1 times, contributing (D1,4−10)D1,1. Overall, the sum of all medians is thus
D1,4(10−D1,7)+D1,3(D1,7−D1,6)+D1,2(D1,6−D1,5)+D1,1(D1,5−D1,4)+(D1,7−10)(D1,4−D1,3)+(D1,6−10)(D1,3−D1,2)+(D1,5−10)(D1,2−D1,1)+(D1,4−10)D1,1.
It is fairly easy to see that this expression is in fact equal to 0 (for example, by considering the linear and quadratic terms separately). This means that the sum of new medians Mi is zero, and the sum of the original mi's is 45, as wanted.