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 N, R;
struct point {
  int x;
  int y;
  point(int xx, int yy) {
    x = xx;
    y = yy;
  }
};
bool inner(point A) { return (A.x * A.x + A.y * A.y <= R * R); }
vector<point> convex_hull;
int area(point A, point B, point C) {
  int p = B.x - A.x;
  int q = B.y - A.y;
  int r = C.x - A.x;
  int l = C.y - A.y;
  return (q * r - p * l);
}
void Init() { cin >> N >> R; }
void Make_Convex_Hull() {
  convex_hull.push_back(point(0, R));
  while (true) {
    point cur = convex_hull[convex_hull.size() - 1];
    --cur.y;
    while (!inner(point(cur.x + 1, cur.y))) --cur.y;
    while (inner(point(cur.x + 1, cur.y))) ++cur.x;
    if (cur.y == 0) break;
    if (area(convex_hull[convex_hull.size() - 1], cur, point(R, 0)) >= 0)
      convex_hull.push_back(cur);
    while (convex_hull.size() >= 3 &&
           area(convex_hull[convex_hull.size() - 3],
                convex_hull[convex_hull.size() - 2],
                convex_hull[convex_hull.size() - 1]) <= 0) {
      convex_hull[convex_hull.size() - 2] = convex_hull[convex_hull.size() - 1];
      convex_hull.pop_back();
    }
  }
  int s = convex_hull.size();
  for (int i = 0; i < s; ++i)
    convex_hull.push_back(point(convex_hull[i].y, -convex_hull[i].x));
  for (int i = 0; i < s; ++i)
    convex_hull.push_back(point(-convex_hull[i].x, -convex_hull[i].y));
  for (int i = 0; i < s; ++i)
    convex_hull.push_back(point(-convex_hull[i].y, convex_hull[i].x));
}
int maxx = 0;
int cur = 0;
vector<point> ans;
vector<point> best;
void Case(int px, int sx, int py, int sy, int iteration, int last) {
  if (iteration < N) {
    for (int i = last; i < convex_hull.size(); ++i) {
      int curx = iteration * convex_hull[i].x * convex_hull[i].x -
                 2 * px * convex_hull[i].x + sx;
      int cury = iteration * convex_hull[i].y * convex_hull[i].y -
                 2 * py * convex_hull[i].y + sy;
      cur += curx;
      cur += cury;
      int dpx = convex_hull[i].x;
      int dpy = convex_hull[i].y;
      int dsx = convex_hull[i].x * convex_hull[i].x;
      int dsy = convex_hull[i].y * convex_hull[i].y;
      ans.push_back(convex_hull[i]);
      Case(px + dpx, sx + dsx, py + dpy, sy + dsy, iteration + 1, i);
      cur -= curx;
      cur -= cury;
      ans.pop_back();
    }
  } else {
    if (maxx < cur) {
      maxx = cur;
      best = ans;
    }
  }
}
int main() {
  Init();
  Make_Convex_Hull();
  Case(0, 0, 0, 0, 0, 0);
  cout << maxx << "\n";
  for (int i = 0; i < best.size(); ++i)
    cout << best[i].x << " " << best[i].y << "\n";
  return 0;
}