import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class prog { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s = br.readLine(); int n = Integer.parseInt(s); int ns = n * n; String s2 = br.readLine(); String[] split = s2.split(" "); List list = new ArrayList(ns); for (String nrs : split) { if (nrs != null) { list.add(Integer.parseInt(nrs)); } } Collections.sort(list, Collections.reverseOrder()); int [] [] a = new int[n][n]; for (int i = 0; i < n; i++) { a[i][i] = list.get(i); } // list.removeAll(list.subList(0, n)); for (int i = 0; i < n; i++) { list.remove(0); } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i != j) { a[i][j] = list.remove(0); } } } int nm1 = n -1; for (int i = 0; i < n; i++) { for (int j = 0; j < nm1; j++) { System.out.print(a[i][j] + " "); } System.out.println(a[i][n-1]); } } }