Let us define a magic grid to be a square matrix of integers of size n × n, satisfying the following conditions. 

  * All integers from 0 to (n^2 - 1) inclusive appear in the matrix exactly once. 
  * [Bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) of all elements in a row or a column must be the same for each row and column. 



You are given an integer n which is a multiple of 4. Construct a magic grid of size n × n.

Input

The only line of input contains an integer n (4 ≤ n ≤ 1000). It is guaranteed that n is a multiple of 4.

Output

Print a magic grid, i.e. n lines, the i-th of which contains n space-separated integers, representing the i-th row of the grid.

If there are multiple answers, print any. We can show that an answer always exists.

Examples

Input


4


Output


8 9 1 13
3 12 7 5
0 2 4 11
6 10 15 14

Input


8


Output


19 55 11 39 32 36 4 52
51 7 35 31 12 48 28 20
43 23 59 15 0 8 16 44
3 47 27 63 24 40 60 56
34 38 6 54 17 53 9 37
14 50 30 22 49 5 33 29
2 10 18 46 41 21 57 13
26 42 62 58 1 45 25 61

Note

In the first example, XOR of each row and each column is 13.

In the second example, XOR of each row and each column is 60.
import java.io.*;
import java.util.*;
import java.util.stream.IntStream;

public class Laba {
    FScanner fs;
    PrintWriter pw;
    int n;
    boolean[] used;
    int[][] g;
    int[][] dst;
    int[][] arr;

    public static void main(String[] args) throws IOException {
        new Laba().start();
    }

    public void start() throws IOException {
        fs = new FScanner(new InputStreamReader(System.in));
        // reader = new FScanner(new FileReader("input"));
        //pw = new PrintWriter("input.txt");
        pw = new PrintWriter(System.out);
        int n = fs.nextInt();
        arr = new int[n][n];
        int v = 0;
        for (int c = 0; c < 4; c++) {
            for (int i = 0, j = c; i < 4; i++, j = (j + 1) % 4) {
                arr[i][j] = v++;
            }
        }
        int sz = 4;
        while (sz < n) {
            for (int i = 0; i < sz; i+= 4) {
                for (int c = 0; c < 4; c++) {
                    for (int k = i, j = sz + c; k < i + 4; k++) {
                        arr[k][j] = v++;
                        j++;
                        if (j >= sz + 4) {
                            j = sz;
                        }
                    }
                }
            }
            for (int i = 0; i < sz; i+= 4) {
                for (int c = 0; c < 4; c++) {
                    for (int k = sz, j = i + c; k < sz + 4; k++) {
                        arr[k][j] = v++;
                        j++;
                        if (j >= i + 4) {
                            j = i;
                        }
                    }
                }
            }
                for (int c = 0; c < 4; c++) {
                    for (int k = sz, j = sz + c; k < sz + 4; k++) {
                        arr[k][j] = v++;
                        j++;
                        if (j >= sz + 4) {
                            j = sz;
                        }
                    }
                }
            sz += 4;
        }



      /*  int res = 0;
        for (int i = 0; i < n; i++)
            res ^= arr[i][0];
        for (int i = 0; i < n; i++) {
            int vv = 0;
            for (int j = 0; j < n; j++) {
                vv ^= arr[j][i];
            }
            if (vv != res)
                pw.println("FF");
        } */
       for (int i =0 ; i < n; i++) {
            for (int j =0 ; j <n ; j++)
                pw.print(arr[i][j] + " ");
            pw.println();
        }
        pw.close();
    }


}

class Pair {
    int x, y, c;

    Pair(int x1, int y1, int c1) {
        x = x1;
        y = y1;
        c = c1;
    }
}

class FScanner {
    StringTokenizer st;
    BufferedReader reader;

    FScanner(InputStreamReader isr) throws IOException {
        reader = new BufferedReader(isr);
    }

    String nextLine() throws IOException {
        return reader.readLine();
    }

    String nextToken() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            String s = reader.readLine();
            if (s == null)
                return null;
            st = new StringTokenizer(s);
        }
        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    char nextChar() throws IOException {
        return (char) reader.read();
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    int[] iarr(int n) throws IOException {
        int[] mas = new int[n];
        for (int i = 0; i < n; i++)
            mas[i] = nextInt();
        return mas;
    }

    double[] darr(int n) throws IOException {
        double[] mas = new double[n];
        for (int i = 0; i < n; i++)
            mas[i] = nextDouble();
        return mas;
    }

    char[][] cmas2(int n, int m) throws IOException {
        char[][] mas = new char[n][m];
        for (int i = 0; i < n; i++)
            mas[i] = nextLine().toCharArray();
        return mas;
    }

    long[] larr(int n) throws IOException {
        long[] mas = new long[n];
        for (int i = 0; i < n; i++)
            mas[i] = nextLong();
        return mas;
    }
}