Under construction

Still being built. Things may change

Magic Square and Sudoku

Time limit1sMemory limit512 MB

Summary
Construct a 16 by 16 Sudoku in which every 4 by 4 box is a magic square, and print any valid grid.
Level

Medium6 of 10

Topics
Math, Implementation, Matrix
Solved
No attempts yet

Problem

Jisu became friends with Joshua Müller, a passionate math puzzle fan, while studying in Germany. Joshua especially likes magic squares (Zauberquadrat) and Sudoku. According to Joshua, people think Sudoku is fun to solve at any time, but magic squares are rarely solved because their easy solving method is well known.

A magic square is defined as follows.

The board of a magic square is an N×NN \times N grid. Each cell must contain exactly one integer from 11 to N2N^2. The sum of the numbers in each of the NN rows, each of the NN columns, and the 2 diagonals must all be equal.

A Sudoku is defined as follows.

The board of a Sudoku is an N2×N2N^2 \times N^2 grid, divided into N2N^2 smaller boards of size N×NN \times N. Each cell can contain an integer from 11 to N2N^2. In each of the N2N^2 rows, N2N^2 columns, and N2N^2 smaller boards, each integer from 11 to N2N^2 must appear exactly once.

Joshua wants to combine magic squares with Sudoku. He tries to build an N2×N2N^2 \times N^2 Sudoku in which each of the N2N^2 smaller boards is a magic square. Joshua found quickly that such a puzzle is impossible when N=3N = 3. Soon after, he easily built a 16×1616 \times 16 (N=4N = 4) puzzle that meets his conditions.

Joshua asks Jisu to build a 16×1616 \times 16 puzzle that meets his conditions. Jisu is busy with an internship at a lab, so you will build the 16×1616 \times 16 puzzle instead.

Input

This problem has no input.

Output

Print the constructed puzzle over 16 lines. If there are several answers, print any one of them.

Examples1

  1. Example 1

    Input
    -
    
    Expected output
    4 10 9 15 1 7 13 8 6 14 2 12 16 5 3 11
    2 5 3 1 15 4 11 16 13 9 8 7 6 10 12 14
    14 6 13 12 3 10 5 2 16 11 1 4 8 15 9 7
    11 7 16 8 6 14 9 12 5 3 10 15 1 2 13 4
    8 16 11 4 13 15 14 9 2 5 7 3 12 1 10 6
    1 14 6 13 12 8 4 5 10 16 9 11 2 3 7 15
    10 15 5 3 2 1 6 7 4 12 14 8 9 11 16 13
    12 2 7 9 11 3 16 10 15 13 6 1 4 8 14 5
    9 4 1 10 14 2 3 13 11 15 12 6 7 16 5 8
    5 8 14 16 7 9 1 6 3 4 13 10 11 12 15 2
    7 3 15 6 16 11 12 4 8 2 5 9 14 13 1 10
    13 12 2 11 10 5 8 15 7 1 16 14 3 6 4 9
    15 9 8 2 4 12 7 3 1 10 11 13 5 14 6 16
    6 13 12 5 9 16 15 1 14 8 4 2 10 7 11 3
    16 11 4 7 8 13 10 14 12 6 3 5 15 9 2 1
    3 1 10 14 5 6 2 11 9 7 15 16 13 4 8 12