@@ -0,0 +1,1223 @@
+import java.io.*;%0Aimport java.util.*;%0A%0Aclass Main%0A%7B%0A%09static int N;%0A%0A%09public static void main(String args%5B%5D) throws IOException%0A%09%7B%0A%09%09BufferedReader f = new BufferedReader(new InputStreamReader(System.in));%0A%09%09StringTokenizer st;%0A%0A%09%09st = new StringTokenizer(f.readLine());%0A%09%09N = Integer.parseInt(st.nextToken());%0A%0A%09%09List%3CList%3CInteger%3E%3E rows = new ArrayList%3CList%3CInteger%3E%3E(1000);%0A%09%09for(int i = 0; i %3C N; i++)%0A%09%09%7B%0A%09%09%09rows.add(new ArrayList%3CInteger%3E(50));%0A%0A%09%09%09st = new StringTokenizer(f.readLine());%0A%09%09%09int current = Integer.parseInt(st.nextToken());%0A%09%09%09while(current != -1)%0A%09%09%09%7B%0A%09%09%09%09rows.get(i).add(current);%0A%09%09%09%09current = Integer.parseInt(st.nextToken());%0A%09%09%09%7D%0A%09%09%7D%0A%0A%09%09Collections.sort(rows, new Comparator%3CList%3CInteger%3E%3E()%0A%09%09%7B%0A%09%09%09public int compare(List%3CInteger%3E a, List%3CInteger%3E b)%0A%09%09%09%7B%0A%09%09%09%09int aIndx = 0;%0A%09%09%09%09int bIndx = 0;%0A%0A%09%09%09%09while(aIndx %3C a.size() && bIndx %3C b.size())%0A%09%09%09%09%7B%0A%09%09%09%09%09if(a.get(aIndx) != b.get(bIndx))%0A%09%09%09%09%09%7B%0A%09%09%09%09%09%09return a.get(aIndx) - b.get(bIndx);%0A%09%09%09%09%09%7D%0A%0A%09%09%09%09%09aIndx++;%0A%09%09%09%09%09bIndx++;%0A%09%09%09%09%7D%0A%0A%09%09%09%09return a.size() - b.size();%0A%09%09%09%7D%0A%09%09%7D);%0A%0A%09%09for(int i = 0; i %3C N; i++)%0A%09%09%7B%0A%09%09%09for(int j = 0; j %3C rows.get(i).size(); j++)%0A%09%09%09%7B%0A%09%09%09%09System.out.print(rows.get(i).get(j) + %22 %22);%0A%09%09%09%7D%0A%09%09%09System.out.println();%0A%09%09%7D%0A%09%7D%0A%7D%0A

Create SORTROWS.java