A magic rectangle with the greatest size - original question I filled in a $3\times k$ rectangle with non negativ integers, such that the sum of the three numbers in each column is the same number $n$, and in each row all the numbers are different.
Find the maximum value of $k$.
If you try for $n=0,1,2,3,4,5,6$, you get $1,1,2,3,3,4,4$. It is a strange sequence, but 
I got an extra homework. So I need help! I am very thankful for every solution!

Well, here's a partial answer for you: the function $k(n)$ is obviously non-decreasing, the upper bound is $k={2\over3}n+1$, and this bound is sharp (that is, exact) when $n$ is divisible by 3.
The bound can be established as follows. The sum of all numbers in the table is obviously $k\cdot n$. On the other hand, if we look at the rows first, each row contains $k$ different non-negative integers. Their sum can't be smaller than $0+1+2+\ldots+(k-1) = {k(k-1)\over2}$. Since we have three such rows, this implies:
$$3{k(k-1)\over2}\leqslant k\cdot n$$
or
$$k\leqslant {2\over3}n+1$$
As to why the bound is sharp, well, just extend the following pattern:
$$n=3: \\ \begin{array}{|c|c|c|}
0&1&2 \\
1&2&0 \\
2&0&1
\end{array}$$
$$n=6: \\ \begin{array}{|c|c|c|c|c|}
0&1&2&3&4 \\
2&3&4&0&1 \\
4&2&0&3&1
\end{array}$$
$$n=9: \\ \begin{array}{|c|c|c|c|c|c|c|}
0&1&2&3&4&5&6 \\
3&4&5&6&0&1&2 \\
6&4&2&0&5&3&1
\end{array}$$
$$n=12: \\ \begin{array}{|c|c|c|c|c|c|c|c|c|}
0&1&2&3&4&5&6&7&8 \\
4&5&6&7&8&0&1&2&3 \\
8&6&4&2&0&7&5&3&1
\end{array}$$
