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 a[22], b[22];
int v[(1 << 20) + 1][8];
int sx[(1 << 20) + 1][8];
int sy[(1 << 20) + 1][8];
int s2[(1 << 20) + 1][8];
int pi[(1 << 20) + 1][8];
int pmask[(1 << 20) + 1][8];
void rec(int x, int y) {
  if (y > 1) rec(pmask[x][y], y - 1);
  cout << a[pi[x][y]] << " " << b[pi[x][y]] << endl;
}
int main() {
  int m = 0;
  int n, r;
  cin >> n >> r;
  for (int i = r * r; i > 0; i--) {
    for (int x = -r; x <= r; x++)
      for (int y = -r; y <= r; y++)
        if (x * x + y * y == i) {
          if (m < 20) {
            a[m] = x;
            b[m] = y;
            m++;
          }
        }
  }
  v[0][0] = 1;
  for (int k = 0; k < n; k++) {
    for (int mask = 0; mask < (1 << m); mask++) {
      if (v[mask][k] == 0) continue;
      for (int i = 0; i < m; i++) {
        int newmask = mask | (1 << i);
        int news = -a[i] * sx[mask][k] - b[i] * sy[mask][k];
        news += v[mask][k] + s2[mask][k] + k * (a[i] * a[i] + b[i] * b[i]);
        if (news <= v[newmask][k + 1]) continue;
        pi[newmask][k + 1] = i;
        pmask[newmask][k + 1] = mask;
        v[newmask][k + 1] = news;
        sx[newmask][k + 1] = sx[mask][k] + 2 * a[i];
        sy[newmask][k + 1] = sy[mask][k] + 2 * b[i];
        s2[newmask][k + 1] = s2[mask][k] + a[i] * a[i] + b[i] * b[i];
      }
    }
  }
  int ans = 0;
  int mask;
  for (int i = 0; i < (1 << 20); i++)
    if (v[i][n] > ans) {
      ans = v[i][n];
      mask = i;
    }
  cout << ans - 1 << endl;
  rec(mask, n);
}