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.*;
import java.util.*;
import java.math.*;

public class Task {

    static Point[] a;
    static int sum;
    static int[] took;
    static int[] ans;
    static int size;
    static int[][] d;

    static void go(int need, int last, int cur) {
        if (need == 0) {
            if (cur > sum) {
                sum = cur;
                ans = Arrays.copyOf(took, size);
            }
        } else {
            ++size;
            for (int i = last; i < a.length; ++i) {
                took[size - 1] = i;
                int now = 0;
                for (int j = 0; j < size - 1; ++j) {
                    now += d[took[j]][i];
                }
                go(need - 1, i, cur + now);
            }
            --size;
        }
    }

    public void solve() throws IOException {
        int n = in.nextInt();
        int r = in.nextInt();
        a = new Point[3000];
        int s = 0;
        for (int i = 0; i <= r; ++i) {
            for (int j = 0; i * i + j * j <= r * r; ++j) {
                a[s++] = new Point(i, j);
                if (i > 0) a[s++] = new Point(-i, j);
                if (i > 0 & j > 0) a[s++] = new Point(-i, -j);
                if (j > 0) a[s++] = new Point(i, -j);
            }
        }
        a = Point.convexHull(Arrays.copyOf(a, s));
        d = new int[a.length][a.length];
        for (int i = 0; i < a.length; ++i) {
            for (int j = 0; j < a.length; ++j) {
                d[i][j] = a[i].sub(a[j]).len2();
            }
        }
        took = new int[n];
        go(n, 0, 0);
        out.println(sum);
        for (int i : ans) {
            out.println(a[i].x + " " + a[i].y);
        }
    }

    static FastReader in;
    static PrintWriter out;
    static PrintStream err;

    public static void main(String[] args) throws IOException {
        try {
            in = new FastReader();
            out = new PrintWriter(System.out);
            err = System.err;
            new Task().solve();
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        }
    }
}

class FastReader {
    BufferedReader br;
    StringTokenizer in;

    FastReader() {
        this.br = new BufferedReader(new InputStreamReader(System.in));
    }

    FastReader(String filename) {
        try {
            this.br = new BufferedReader(new FileReader(filename));
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    public String nextToken() throws IOException {
        while (in == null || !in.hasMoreTokens()) {
            in = new StringTokenizer(br.readLine());
        }
        return in.nextToken();
    }

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

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

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

class Point {
    int x;
    int y;

    public Point(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public int mulv(Point a) {
        return this.x * a.y - this.y * a.x;
    }

    public int len2() {
        return x * x + y * y;
    }

    public Point sub(Point a) {
        return new Point(this.x - a.x, this.y - a.y);
    }

    public Point add(Point a) {
        return new Point(this.x + a.x, this.y + a.y);
    }

    public static Point[] convexHull(Point[] a) {
        int n = a.length;
        int mn = 0;
        for (int i = 1; i < n; ++i) {
            if (a[i].x < a[mn].x || (a[i].x == a[mn].x && a[i].y < a[mn].y)) {
                mn = i;
            }
        }
        Point start = a[mn];
        a[mn] = a[0];
        a[0] = start;
        for (int i = 1; i < n; ++i) {
            a[i] = a[i].sub(start);
        }
        Arrays.sort(a, 1, a.length, new Comparator<Point>() {
            @Override
            public int compare(Point o1, Point o2) {
                int m = o1.mulv(o2);
                if (m != 0) {
                    return m > 0 ? -1 : 1;
                }
                int d = o1.len2() - o2.len2();
                return d > 0 ? 1 : d < 0 ? -1 : 0;
            }
        });
        for (int i = 1; i < n; ++i) {
            a[i] = a[i].add(start);
        }
        Point[] h = new Point[n];
        int size = 0;
        for (int i = 0; i < n; ++i) {
            while (size > 1 && h[size - 1].sub(h[size - 2]).mulv(a[i].sub(h[size - 2])) <= 0) {
                --size;
            }
            h[size++] = a[i];
        }
        return Arrays.copyOf(h, size);
    }
}