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 Point {
  int x, y;
  inline Point() {}
  inline Point(int _x, int _y) {
    x = _x;
    y = _y;
  }
} po[6000];
int n, r;
inline int sqr(int x) { return x * x; }
int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
inline bool ok(int x, int y) {
  int a = sqr(x), b = sqr(y), c = sqr(r);
  if (a + b > c) return 0;
  if (a + b == c) return 1;
  for (int i = 0; i < 4; ++i) {
    int xx = x + dx[i], yy = y + dy[i];
    if (sqr(xx) + sqr(yy) > c) return 1;
  }
  return 0;
}
int dp[10][505][505];
int p1[10][505][505], p2[10][505][505];
bool inq[10][505][505];
int V = 250;
struct Node {
  int c, s1, s2;
  inline Node() {}
  inline Node(int _c, int _s1, int _s2) {
    c = _c;
    s1 = _s1;
    s2 = _s2;
  }
};
queue<Node> Q;
void output(int c, int s1, int s2) {
  if (!c) return;
  output(c - 1, p1[c][s1][s2], p2[c][s1][s2]);
  printf("%d %d\n", s1 - p1[c][s1][s2], s2 - p2[c][s1][s2]);
}
int main() {
  scanf("%d%d", &n, &r);
  int cc = 0;
  for (int i = -r; i <= r; ++i)
    for (int j = -r; j <= r; ++j)
      if (ok(i, j)) po[cc++] = Point(i, j);
  memset(dp, -0x3f, sizeof(dp));
  dp[0][V][V] = 0;
  Q.push(Node(0, V, V));
  Node u;
  while (!Q.empty()) {
    u = Q.front();
    Q.pop();
    if (u.c == n) continue;
    inq[u.c][u.s1][u.s2] = 0;
    for (int i = 0; i < cc; ++i) {
      int sum1 = u.s1 + po[i].x, sum2 = u.s2 + po[i].y;
      int val = dp[u.c][u.s1][u.s2] + n * (sqr(po[i].x) + sqr(po[i].y));
      if (val > dp[u.c + 1][sum1][sum2]) {
        dp[u.c + 1][sum1][sum2] = val;
        p1[u.c + 1][sum1][sum2] = u.s1;
        p2[u.c + 1][sum1][sum2] = u.s2;
        if (!inq[u.c + 1][sum1][sum2]) {
          inq[u.c + 1][sum1][sum2] = 1;
          Q.push(Node(u.c + 1, sum1, sum2));
        }
      }
    }
  }
  int ans = -0x3f3f3f3f, l, r;
  for (int i = 0; i <= 500; ++i)
    for (int j = 0; j <= 500; ++j) {
      if (dp[n][i][j] < 0) continue;
      int val = dp[n][i][j] - sqr(i - V) - sqr(j - V);
      if (val > ans) {
        ans = val;
        l = i;
        r = j;
      }
    }
  printf("%d\n", ans);
  output(n, l, r);
  return 0;
}