using System.Collections.Generic; using System; public class Hello { public static int h, w; static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); h = int.Parse(line[0]); w = int.Parse(line[1]); var t = new List(); for (int i = 0; i < h; i++) { line = Console.ReadLine().Trim().Split(' '); for (int j = 0; j < w; j++) t.Add(int.Parse(line[j])); } getAns(t); } static void getAns(List t) { t.Sort(); var p = 0; var res = new int[w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) res[j] = t[j + p]; Console.WriteLine(string.Join(" ", res)); p += w; } } }