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 CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
int b[10];
int c[10];
int k, r;
struct aa {
  int x;
  int y;
  int z;
} a[5000];
int is_ok(int x, int y) {
  if (x * x + y * y <= r * r) return 1;
  return 0;
}
bool comp(aa p, aa q) { return p.z > q.z; }
int solve(int x, int y) {
  return (a[x].x - a[y].x) * (a[x].x - a[y].x) +
         (a[x].y - a[y].y) * (a[x].y - a[y].y);
}
int main(void) {
  int max = 0;
  scanf("%d%d", &k, &r);
  int t = -1;
  for (int i = -r; i <= r; i++) {
    for (int j = -r; j <= r; j++) {
      if (is_ok(i, j)) {
        a[++t].x = i;
        a[t].y = j;
        a[t].z = i * i + j * j;
      }
    }
  }
  sort(a, a + t, comp);
  int tt = 20;
  for (int i = t; i < tt; i++) {
    a[i].x = a[i].y = 0;
  }
  for (int i1 = 0; i1 < tt; i1++) {
    for (int i2 = i1; i2 < tt; i2++) {
      if (k == 2) {
        int s = 0;
        c[0] = i1;
        c[1] = i2;
        for (int i = 0; i < k; i++) {
          for (int j = i; j < k; j++) {
            s += solve(c[i], c[j]);
          }
        }
        if (s > max) {
          b[0] = i1;
          b[1] = i2;
          max = s;
        }
        continue;
      }
      for (int i3 = i2; i3 < tt; i3++) {
        if (k == 3) {
          int s = 0;
          c[0] = i1;
          c[1] = i2;
          c[2] = i3;
          for (int i = 0; i < k; i++) {
            for (int j = i; j < k; j++) {
              s += solve(c[i], c[j]);
            }
          }
          if (s > max) {
            b[0] = i1;
            b[1] = i2;
            b[2] = i3;
            max = s;
          }
          continue;
        }
        for (int i4 = i3; i4 < tt; i4++) {
          if (k == 4) {
            int s = 0;
            c[0] = i1;
            c[1] = i2;
            c[2] = i3;
            c[3] = i4;
            for (int i = 0; i < k; i++) {
              for (int j = i; j < k; j++) {
                s += solve(c[i], c[j]);
              }
            }
            if (s > max) {
              b[0] = i1;
              b[1] = i2;
              b[2] = i3;
              b[3] = i4;
              max = s;
            }
            continue;
          }
          for (int i5 = i4; i5 < tt; i5++) {
            if (k == 5) {
              int s = 0;
              c[0] = i1;
              c[1] = i2;
              c[2] = i3;
              c[3] = i4;
              c[4] = i5;
              for (int i = 0; i < k; i++) {
                for (int j = i; j < k; j++) {
                  s += solve(c[i], c[j]);
                }
              }
              if (s > max) {
                b[0] = i1;
                b[1] = i2;
                b[2] = i3;
                b[3] = i4;
                b[4] = i5;
                max = s;
              }
              continue;
            }
            for (int i6 = i5; i6 < tt; i6++) {
              if (k == 6) {
                int s = 0;
                c[0] = i1;
                c[1] = i2;
                c[2] = i3;
                c[3] = i4;
                c[4] = i5;
                c[5] = i6;
                for (int i = 0; i < k; i++) {
                  for (int j = i; j < k; j++) {
                    s += solve(c[i], c[j]);
                  }
                }
                if (s > max) {
                  b[0] = i1;
                  b[1] = i2;
                  b[2] = i3;
                  b[3] = i4;
                  b[4] = i5;
                  b[5] = i6;
                  max = s;
                }
                continue;
              }
              for (int i7 = i6; i7 < tt; i7++) {
                if (k == 7) {
                  int s = 0;
                  c[0] = i1;
                  c[1] = i2;
                  c[2] = i3;
                  c[3] = i4;
                  c[4] = i5;
                  c[5] = i6;
                  c[6] = i7;
                  for (int i = 0; i < k; i++) {
                    for (int j = i; j < k; j++) {
                      s += solve(c[i], c[j]);
                    }
                  }
                  if (s > max) {
                    b[0] = i1;
                    b[1] = i2;
                    b[2] = i3;
                    b[3] = i4;
                    b[4] = i5;
                    b[5] = i6;
                    b[6] = i7;
                    max = s;
                  }
                  continue;
                }
                for (int i8 = i7; i8 < tt; i8++) {
                  int s = 0;
                  c[0] = i1;
                  c[1] = i2;
                  c[2] = i3;
                  c[3] = i4;
                  c[4] = i5;
                  c[5] = i6;
                  c[6] = i7;
                  c[7] = i8;
                  for (int i = 0; i < k; i++) {
                    for (int j = i; j < k; j++) {
                      s += solve(c[i], c[j]);
                    }
                  }
                  if (s > max) {
                    b[0] = i1;
                    b[1] = i2;
                    b[2] = i3;
                    b[3] = i4;
                    b[4] = i5;
                    b[5] = i6;
                    b[6] = i7;
                    b[7] = i8;
                    max = s;
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  printf("%d\n", max);
  for (int i = 0; i < k; i++) {
    printf("%d %d\n", a[b[i]].x, a[b[i]].y);
  }
  return 0;
}