Problem: 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.

Solution (in JAVA):

Solution:
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.lang.*;
import static java.lang.Math.*;

public class Main implements Runnable {
    public static void main(String[] args) {
        new Thread(null, new Main(), "Check2", 1 << 28).start();// to increse stack size in java
    }
    static long mod = (long) (1e9 + 7);
    public void run() {
        InputReader in = new InputReader(System.in);
        PrintWriter w = new PrintWriter(System.out);



        int ar[][] = new int[2001][2001];
        int n = in.nextInt();
        int vl = 0;

        for ( int  i = 1; i <= n/4; i ++ ){
            for ( int j = 1; j <= n/4; j ++){
                int r = (i-1)*4 + 1;
                int c = (j-1)*4 + 1;
                for ( int l = 1; l <= 4; l ++){
                    for ( int m = 1; m <= 4; m ++){
                        ar[r+l-1][c+m-1] = vl;
                        vl++;
                    }
                }
            }
        }

        for (int i=1;i<=n;i++){
            for (int j=1;j<=n;j++)w.print(ar[i][j]+" ");
            w.println();
        }


        w.close();
    }
    int uniqueElemtns = 0;
    boolean isPossible(int mid,int a[]){
        Map <Integer,Integer> frqMap = new HashMap<>();
        Map <Integer,Set<Integer>> invFrqMap = new HashMap<>();

        int n = a.length;
        for (int i=0;i<n;i++)frqMap.put(a[i],frqMap.getOrDefault(a[i],0) + 1);
        for (int itr : frqMap.keySet()){
            Set <Integer> numbers = invFrqMap.get(frqMap.get(itr));
            if (numbers == null)numbers = new HashSet<>();
            numbers.add(itr);
            invFrqMap.put(frqMap.get(itr),numbers);
        }


        for (int i = 0 ; i < mid; i++){
            int frq = frqMap.get(a[i]);

            if (frq == 1){
                frqMap.remove(a[i]);
                Set <Integer> set1 = invFrqMap.get(frq);
                set1.remove(a[i]);
                invFrqMap.put(frq,set1);
            }
            else {
                frqMap.put(a[i],frq - 1);
                Set <Integer> set1 = invFrqMap.getOrDefault(frq,new HashSet<>());
                Set <Integer> set2 = invFrqMap.getOrDefault(frq - 1,new HashSet<>());
                set1.remove(a[i]);
                set2.add(a[i]);
                invFrqMap.put(frq,set1);
                invFrqMap.put(frq - 1 , set2);
            }
        }

        if (isFinalState(invFrqMap,n))return true;

        int left = 0;
        for (int i = mid; i < n; i++){
            int frq = frqMap.get(a[i]);
            if (frq == 1){
                frqMap.remove(a[i]);
                Set <Integer> set1 = invFrqMap.get(frq);
                set1.remove(a[i]);
                invFrqMap.put(frq,set1);
            }
            else {
                frqMap.put(a[i],frq - 1);
                Set <Integer> set1 = invFrqMap.get(frq);
                Set <Integer> set2 = invFrqMap.getOrDefault(frq - 1,new HashSet<>());
                set1.remove(a[i]);
                set2.add(a[i]);
                invFrqMap.put(frq,set1);
                invFrqMap.put(frq - 1 , set2);
            }

            int frq1 = frqMap.getOrDefault(a[left],0);
            frqMap.put(a[left],frq1 + 1);
            Set <Integer> set1 = invFrqMap.getOrDefault(frq1,new HashSet<>());
            Set <Integer> set2 = invFrqMap.getOrDefault(frq1 + 1, new HashSet<>());
            set1.remove(a[left]);
            set2.add(a[left]);
            left++;
            invFrqMap.put(frq1,set1);
            invFrqMap.put(frq1 + 1,set2);
            if (isFinalState(invFrqMap,a.length))return true;
        }
        return false;
    }
    private boolean isFinalState(Map <Integer,Set<Integer>> invFrqMap,int n){
        for (int itr : invFrqMap.keySet()){
           if (itr > 1 && invFrqMap.get(itr).size() > 0)return false;
        }
        return true;
    }
    void debug(Object...args) {
        System.out.println(Arrays.deepToString(args));
    }
    static class pair implements Comparable<pair>{

        int a;
        int b;

        pair(int a,int b){
            this.a = a;
            this.b = b;
        }
        public int compareTo(pair o){
            if(this.b != o.b)return this.b - o.b;
            return this.a - o.a;
        }

    }
    long modinv(long a,long b) {
        long p=power(b,mod-2,mod);

        p=a%mod*p%mod;
        p%=mod;

        return p;

    }
    long power(long x,long y,long mod){
        if(y==0)return 1%mod;
        if(y==1)return x%mod;
        long res=1;
        x=x%mod;
        while(y>0)
        {
            if((y%2)!=0){
                res=(res*x)%mod;
            }
            y=y/2;
            x=(x*x)%mod;
        }
        return res;
    }
    long gcd(long a,long b){

        if(b==0)return a;
        return gcd(b,a%b);
    }
    void sev(int a[],int n){

        for(int i=2;i<=n;i++)a[i]=i;
        for(int i=2;i<=n;i++){

            if(a[i]!=0){
                for(int j=2*i;j<=n;){

                    a[j]=0;
                    j=j+i;
                }
            }

        }

    }
    static class InputReader
    {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream)
        {
            this.stream = stream;
        }

        public int read()
        {
            if (numChars==-1)
                throw new InputMismatchException();

            if (curChar >= numChars){
                curChar = 0;
                try
                {
                    numChars = stream.read(buf);
                }
                catch (IOException e)
                {
                    throw new InputMismatchException();
                }

                if(numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine()
        {
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            String stock = "";
            try
            {
                stock = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return stock;
        }
        public int nextInt()
        {
            int c = read();

            while(isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-')
            {
                sgn = -1;
                c = read();
            }

            int res = 0;
            do
            {
                if(c<'0'||c>'9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public long nextLong()
        {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-')
            {
                sgn = -1;
                c = read();
            }
            long res = 0;

            do
            {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
            return res * sgn;
        }

        public double nextDouble()
        {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-')
            {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.')
            {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.')
            {
                c = read();
                double m = 1;
                while (!isSpaceChar(c))
                {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public String readString()
        {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do
            {
                res.appendCodePoint(c);
                c = read();
            }
            while (!isSpaceChar(c));

            return res.toString();
        }

        public boolean isSpaceChar(int c)
        {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next()
        {
            return readString();
        }

        public interface SpaceCharFilter
        {
            public boolean isSpaceChar(int ch);
        }
    }
}