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;
struct PT {
  int x, y;
  PT(int X = 0, int Y = 0) : x(X), y(Y) {}
  PT operator+(const PT &A) const { return PT(x + A.x, y + A.y); }
  PT operator-(const PT &A) const { return PT(x - A.x, y - A.y); }
  PT operator*(int a) const { return PT(x * a, y * a); }
  PT operator/(const int &A) const { return PT(x / A, y / A); }
  int operator^(const PT &A) const { return x * A.y - y * A.x; }
  int len() { return x * x + y * y; }
  PT norm() const { return PT(-y, x); }
} t[1010], s[1010];
bool cmp(const PT &a, const PT &b) {
  return (a.x < b.x) || ((a.x == b.x) && (a.y < b.y));
}
bool cmp1(PT a, PT b) { return (a.len()) > (b.len()); }
int cross(PT x, PT a, PT b) { return (a - x) ^ (b - x); }
int len(PT a, PT b) { return (a - b).len(); }
int top, ma;
void convex_hull(int n) {
  sort(t, t + n, cmp);
  top = 0;
  for (int i = 0; i < n; i++) {
    while (top >= 2 && cross(s[top - 2], s[top - 1], t[i]) <= 0) top--;
    s[top++] = t[i];
  }
  for (int i = n - 2, k = top + 1; i >= 0; i--) {
    while (top >= k && cross(s[top - 2], s[top - 1], t[i]) <= 0) top--;
    s[top++] = t[i];
  }
  top--;
}
int ans[10];
int tmp[10];
void dfs(int now, int n, int total, int size, int where) {
  if (now == n) {
    if (ma < total) {
      ma = total;
      for (int i = 0; i < n; i++) ans[i] = tmp[i];
    }
    return;
  }
  for (int i = where; i < size; i++) {
    tmp[now] = i;
    int _total = total;
    for (int j = 0; j < now; j++) _total += len(s[i], s[tmp[j]]);
    dfs(now + 1, n, _total, size, i);
  }
}
void special(int n, int k) {
  int a = n / 2;
  int b = a * a * 4 * k * k;
  printf("%d\n", b);
  while (a--) printf("%d 0\n", k);
  a = n / 2;
  while (a--) printf("%d 0\n", -k);
  return;
}
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  if (n % 2 == 0) {
    special(n, k);
    return 0;
  }
  int now = 0;
  t[now++] = PT(k, 0);
  t[now++] = PT(-k, 0);
  for (int i = -k + 1; i <= k - 1; i++)
    for (int j = 1; j <= k; j++) {
      if ((i * i + j * j) <= k * k && (i * i + (j + 1) * (j + 1)) > k * k) {
        t[now++] = PT(i, j);
        t[now++] = PT(i, -j);
        break;
      }
    }
  top = 0;
  convex_hull(now);
  ma = 0;
  sort(s, s + top, cmp1);
  dfs(0, n, 0, top, 0);
  printf("%d\n", ma);
  for (int i = 0; i < n; i++) printf("%d %d\n", s[ans[i]].x, s[ans[i]].y);
}