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;
const int N = -1;
const long long INF = 1e9 + 19;
struct pt {
  long long x, y;
  pt() {}
  pt(long long xx, long long yy) : x(xx), y(yy) {}
  pt operator+(pt A) { return pt(x + A.x, y + A.y); }
  pt operator-(pt A) { return pt(x - A.x, y - A.y); }
  long long operator*(pt A) { return x * A.y - y * A.x; }
  long long operator%(pt A) { return x * A.x + y * A.y; }
  pt operator*(long long k) { return pt(x * k, y * k); }
  long long len2() { return x * x + y * y; }
  bool operator==(pt A) { return x == A.x && y == A.y; }
  bool operator!=(pt A) { return x != A.x || y != A.y; }
  pt rotate() { return pt(-y, x); }
  void read() { scanf("%lld%lld", &x, &y); }
  void Epr() { cerr << "x y " << x << " " << y << endl; }
};
long long getScore(vector<pt> p) {
  long long res = 0;
  for (int i = 0; i < (int)p.size(); i++)
    for (int j = i + 1; j < (int)p.size(); j++) res += (p[i] - p[j]).len2();
  return res;
}
vector<pt> solve(int n, int r) {
  vector<pt> answer;
  long long res = 0;
  srand(time(NULL));
  int C = 400;
  for (int tt = 0; tt < C; tt++) {
    vector<pt> c;
    for (; (int)c.size() < n;) {
      pt A(rand() % (r + r + 2) - r, rand() % (r + r + 1) - r);
      if (A.len2() <= r * r) c.push_back(A);
    }
    long long curScore = getScore(c);
    bool changed = 1;
    while (changed) {
      changed = 0;
      int second = 20;
      for (int i = 0; i < n; i++) {
        for (int dx = -second; dx <= second; dx++)
          for (int dy = -second; dy <= second; dy++) {
            pt A = c[i] + pt(dx, dy);
            if (A.len2() <= r * r) {
              auto d = c;
              d[i] = A;
              long long tmpScore = getScore(d);
              if (tmpScore > curScore) {
                curScore = tmpScore;
                c = d;
                changed = 1;
              }
            }
          }
      }
    }
    if (res < curScore) {
      res = curScore;
      answer = c;
    }
    if (clock() * 1.0 / CLOCKS_PER_SEC > 2.7) break;
  }
  return answer;
}
vector<pt> solve2(int n, int r) {
  vector<pt> answer;
  long long res = 0;
  srand(time(NULL));
  int C = 2000;
  for (int tt = 0; tt < C; tt++) {
    vector<pt> c;
    for (; (int)c.size() < n;) {
      pt A(rand() % (r + r + 2) - r, rand() % (r + r + 1) - r);
      if (A.len2() <= r * r) c.push_back(A);
    }
    c[0] = pt(r, 0);
    long long curScore = getScore(c);
    bool changed = 1;
    while (changed) {
      changed = 0;
      int second = 20;
      for (int i = 1; i < n; i++) {
        for (int dx = -second; dx <= second; dx++)
          for (int dy = -second; dy <= second; dy++) {
            pt A = c[i] + pt(dx, dy);
            if (A.len2() <= r * r) {
              auto d = c;
              d[i] = A;
              long long tmpScore = getScore(d);
              if (tmpScore > curScore) {
                curScore = tmpScore;
                c = d;
                changed = 1;
              }
            }
          }
      }
    }
    if (res < curScore) {
      res = curScore;
      answer = c;
    }
    if (clock() * 1.0 / CLOCKS_PER_SEC > 2.7) break;
  }
  return answer;
}
vector<pt> convexHull(vector<pt> p) {
  sort((p).begin(), (p).end(),
       [](pt A, pt B) { return A.x < B.x || (A.x == B.x && A.y < B.y); });
  vector<pt> st;
  for (int tt = 0; tt < 2; tt++) {
    int cur = st.size();
    for (auto A : p) {
      for (; (int)st.size() >= cur + 2 &&
             (st.back() - st[st.size() - 2]) * (A - st.back()) <= 0;
           st.pop_back())
        ;
      st.push_back(A);
    }
    st.pop_back();
    reverse((p).begin(), (p).end());
  }
  return st;
}
vector<pt> solve3(int n, int r) {
  vector<pt> p;
  {
    int dx[4] = {1, 0, -1, 0};
    int dy[4] = {0, 1, 0, -1};
    for (int i = -r; i <= r; i++)
      for (int j = -r; j <= r; j++) {
        if (i * i + j * j <= r * r) {
          int cntBad = 0;
          for (int t = 0; t < 4; t++) {
            pt first(i + dx[t], j + dy[t]);
            cntBad += (first.len2() > r * r);
          }
          if (cntBad >= 2) p.push_back(pt(i, j));
        }
      }
  }
  sort((p).begin(), (p).end(), [&](pt A, pt B) {
    A = A - pt(-r, 0);
    B = B - pt(-r, 0);
    return A * B > 0 || (A * B == 0 && A.len2() < B.len2());
  });
  auto hull = p;
  vector<pt> answer;
  cerr << "hull.size()"
       << " = " << hull.size() << endl;
  int C = 40000;
  for (int tt = 0; tt < C; tt++) {
    vector<int> pos;
    for (int i = 0; i < n; i++) pos.push_back(rand() % hull.size());
    bool changed = 1;
    long long curScore = 0;
    while (changed) {
      changed = 0;
      int second = 3;
      for (int i = 0; i < n; i++) {
        for (int dx = -second; dx <= second; dx += 2) {
          auto pos2 = pos;
          pos2[i] = (pos2[i] + dx + hull.size()) % hull.size();
          vector<pt> f;
          for (auto id : pos2) f.push_back(hull[id]);
          long long tmpScore = getScore(f);
          if (curScore < tmpScore) {
            curScore = tmpScore;
            pos = pos2;
            changed = 1;
            break;
          }
        }
      }
    }
    vector<pt> cand;
    for (auto id : pos) cand.push_back(hull[id]);
    if (answer.empty() || getScore(cand) > getScore(answer)) {
      answer = cand;
    }
    if (clock() * 1.0 / CLOCKS_PER_SEC > 2.7) break;
  }
  return answer;
}
void printAns(vector<pt> answer) {
  cout << getScore(answer) << endl;
  for (auto A : answer) cout << A.x << " " << A.y << endl;
}
int main() {
  if (1) {
    int n, r;
    scanf("%d%d", &n, &r);
    printAns(solve3(n, r));
  } else {
    for (int n = 6; n <= 8; n++) {
      for (int r = 1; r <= 30; r++) {
        cerr << "("
             << "n"
             << ", "
             << "r"
             << ") = (" << n << ", " << r << ")\n";
        ;
        auto r1 = solve(n, r);
        auto r2 = solve3(n, r);
        printAns(r1);
        printAns(r2);
        cerr << "getScore(r1)"
             << " = " << getScore(r1) << endl;
        cerr << "getScore(r2)"
             << " = " << getScore(r2) << endl;
        assert(getScore(r1) <= getScore(r2));
      }
    }
  }
  return 0;
}