Problem: Roland loves growing flowers. He has recently grown a beautiful rose at point (0, 0) of the Cartesian coordinate system. The rose is so beautiful that Roland is afraid that the evil forces can try and steal it. 

To protect the rose, Roland wants to build n watch towers. Let's assume that a tower is a point on the plane at the distance of at most r from the rose. Besides, Roland assumes that the towers should be built at points with integer coordinates and the sum of squares of distances between all pairs of towers must be as large as possible. Note, that Roland may build several towers at the same point, also he may build some of them at point (0, 0).

Help Roland build the towers at the integer points so that the sum of squares of distances between all towers is maximum possible. Note that the distance in this problem is defined as the Euclidian distance between points.

Input

The first line contains two integers, n and r (2 ≤ n ≤ 8; 1 ≤ r ≤ 30).

Output

In the first line print an integer — the maximum possible sum of squared distances. In the i-th of the following n lines print two integers, xi, yi — the coordinates of the i-th tower. Each tower must be inside or on the border of the circle with radius r. Note that there may be several towers located at the same point of the plane, also some towers can be located at point (0, 0).

If there are multiple valid optimal arrangements, choose any of them.

Examples

Input

4 1


Output

16
0 1
0 1
0 -1
0 -1


Input

3 6


Output

312
0 6
5 -3
-5 -3

Solution (in JAVA):

Solution:
import java.io.IOException;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.ArrayList;
import java.util.Comparator;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author George Marcus
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskE solver = new TaskE();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskE {
    int N;
    int R;
    int K;
    int[][] P;
    int[][] S;
    int best;
    int[][] B;

    public void solve(int testNumber, InputReader in, PrintWriter out) {
        N = in.nextInt();
        R = in.nextInt();

        ArrayList<Integer> pts = new ArrayList<Integer>();
        for (int x = -R; x <= R; x++) {
            for (int y = -R; y <= R; y++) {
                if (x * x + y * y <= R * R) {
                    pts.add(x);
                    pts.add(y);
                }
            }
        }
        K = pts.size() / 2;
        P = new int[K][2];
        for (int i = 0; i < K; i++) {
            P[i][0] = pts.get(2 * i);
            P[i][1] = pts.get(2 * i + 1);
        }
        Arrays.sort(P, new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                int d1 = o1[0] * o1[0] + o1[1] * o1[1];
                int d2 = o2[0] * o2[0] + o2[1] * o2[1];
                if (d1 != d2) {
                    return d1 > d2 ? -1 : 1;
                }
                return 0;
            }
        });

        K = Math.min(K, 30);
        S = new int[N][2];
        B = new int[N][2];
        best = 0;
        back(0, 0, 0);

        out.println(best);
        for (int i = 0; i < N; i++) {
            out.println(B[i][0] + " " + B[i][1]);
        }
    }

    private void back(int p, int sum, int idx) {
        if (p == N) {
            int crt = sum;
            if (crt > best) {
                best = crt;
                for (int i = 0; i < N; i++) {
                    B[i][0] = S[i][0];
                    B[i][1] = S[i][1];
                }
            }
            return;
        }

        for (int i = idx; i < K; i++) {
            int add = 0;
            S[p][0] = P[i][0];
            S[p][1] = P[i][1];
            for (int j = 0; j < p; j++) {
                int dx = S[j][0] - S[p][0];
                int dy = S[j][1] - S[p][1];
                add += dx * dx + dy * dy;
            }
            back(p + 1, sum + add, i);
        }
    }
}

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

    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 int nextInt() {
        return Integer.parseInt(nextString());
    }

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

        return res.toString();
    }

    private boolean isSpaceChar(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

}