Memory limit

On original contest memory limit for this problem was 512 kb. The problem was designed so that input file must be read twice and (important!) it is impossible to create array N^2 of boolean. Solutions that used array 1000x1000 of boolean got MLE. Of course in Timus it is impossible to read input twice, but it is quite possible to prohibit creating N^2 matrix. I think that 1 Mb memory limit should be good for this problem. Of course, one more problem not solvable in Java will appear.