// No.1130 Grid Numbers package main import ( "fmt" "slices" "strconv" "strings" ) func main() { var h, w int fmt.Scan(&h, &w) var a = make([][]int, h) for y := 0; y < h; y++ { a[y] = make([]int, w) for x := 0; x < w; x++ { fmt.Scan(&a[y][x]) } } var aa []int for i := 0; i < h; i++ { aa = append(aa, a[i]...) } slices.Sort(aa) var b = make([]string, len(aa)) for i, v := range aa { b[i] = strconv.Itoa(v) } for j := 0; j < h; j++ { fmt.Println(strings.Join(b[j*w:j*w+w], " ")) } }