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;
vector<int> X, Y;
vector<pair<int, int> > Points;
vector<pair<int, int> > hull;
vector<pair<int, int> > cur, save;
int best = -1;
void Rec(int ind, int sumx, int sumx2, int sumy, int sumy2) {
  if (cur.size() == n) {
    int tmp = n * (sumx2 + sumy2) - (sumx * sumx + sumy * sumy);
    if (tmp > best) {
      best = tmp;
      save = cur;
    }
    return;
  }
  for (int i = ind; i < hull.size(); ++i) {
    cur.push_back(hull[i]);
    int x = hull[i].first, y = hull[i].second;
    Rec(i, sumx + x, sumx2 + x * x, sumy + y, sumy2 + y * y);
    cur.pop_back();
  }
}
int main() {
  cin >> n >> r;
  if (n == 2) {
    cout << 4 * r * r << endl;
    cout << r << " " << 0 << endl;
    cout << -r << " " << 0 << endl;
    return 0;
  }
  vector<int> max_Y(r + 1, 0);
  for (int x = 0; x <= r; ++x) {
    for (int y = r; y >= 0; --y)
      if (x * x + y * y <= r * r) {
        max_Y[x] = y;
        break;
      }
  }
  for (int x = r; x >= -r; --x) Points.push_back(make_pair(x, max_Y[abs(x)]));
  for (int x = -r + 1; x < r; ++x)
    Points.push_back(make_pair(x, -max_Y[abs(x)]));
  hull.push_back(Points[0]);
  hull.push_back(Points[1]);
  for (int i = 2; i <= Points.size(); ++i) {
    int ind = i % Points.size();
    while (hull.size() >= 2) {
      int x1 = hull[hull.size() - 1].first - hull[hull.size() - 2].first;
      int y1 = hull[hull.size() - 1].second - hull[hull.size() - 2].second;
      int x2 = Points[ind].first - hull[hull.size() - 2].first;
      int y2 = Points[ind].second - hull[hull.size() - 2].second;
      int cross = x1 * y2 - y1 * x2;
      if (cross <= 0)
        hull.pop_back();
      else
        break;
    }
    if (i < Points.size()) hull.push_back(Points[ind]);
  }
  Rec(0, 0, 0, 0, 0);
  cout << best << endl;
  for (int i = 0; i < save.size(); ++i)
    cout << save[i].first << " " << save[i].second << endl;
  return 0;
}