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;
void _fill_int(int* p, int val, int rep) {
  int i;
  for (i = 0; i < rep; i++) p[i] = val;
}
int N, R;
vector<pair<int, int> > V, V2;
int mat[1000][1000];
int ma, st[10], be[10];
void dfs(int cur, int pos, int sum) {
  int i, j;
  if (cur == N) {
    if (sum > ma) {
      ma = sum;
      for (i = 0; i < N; i++) be[i] = st[i];
    }
    return;
  }
  for (i = pos; i < V.size(); i++) {
    int nsum = sum;
    for (j = 0; j < cur; j++) nsum += mat[st[j]][i];
    st[cur] = i;
    dfs(cur + 1, i, nsum);
  }
}
signed long long veccross(pair<int, int> p1, pair<int, int> p2,
                          pair<int, int> p3) {
  p3.first -= p1.first;
  p2.first -= p1.first;
  p3.second -= p1.second;
  p2.second -= p1.second;
  return p3.first * (signed long long)p2.second -
         p2.first * (signed long long)p3.second;
}
vector<int> convex_hull(vector<pair<int, int> >& vp) {
  vector<pair<pair<int, int>, int> > sorted;
  vector<int> res;
  int i, k = 0, rb;
  if (vp.size() <= 2) {
    if (vp.size() >= 1) res.push_back(0);
    if (vp.size() >= 2) res.push_back(1);
    return res;
  }
  for (i = 0; i < vp.size(); i++) sorted.push_back(make_pair(vp[i], i));
  sort(sorted.begin(), sorted.end());
  res.resize(vp.size() * 2);
  for (i = 0; i < vp.size(); i++) {
    while (k > 1 &&
           veccross(vp[res[k - 2]], vp[res[k - 1]], sorted[i].first) <= 0)
      k--;
    res[k++] = sorted[i].second;
  }
  for (rb = k, i = vp.size() - 2; i >= 0; i--) {
    while (k > rb &&
           veccross(vp[res[k - 2]], vp[res[k - 1]], sorted[i].first) <= 0)
      k--;
    res[k++] = sorted[i].second;
  }
  res.resize(k - 1);
  return res;
}
void solve() {
  int f, i, j, k, l, x, y;
  cin >> N >> R;
  for (i = 0; i < R + 1; i++) {
    y = 0;
    while ((y + 1) * (y + 1) + i * i <= R * R) y++;
    V2.push_back(make_pair(i, y));
    V2.push_back(make_pair(i, -y));
    V2.push_back(make_pair(-i, y));
    V2.push_back(make_pair(-i, -y));
  }
  sort(V2.begin(), V2.end());
  V2.erase(unique(V2.begin(), V2.end()), V2.end());
  vector<int> VV;
  VV = convex_hull(V2);
  for (i = 0; i < VV.size(); i++) V.push_back(V2[VV[i]]);
  for (i = 0; i < V.size(); i++)
    for (j = 0; j < V.size(); j++)
      mat[i][j] = (V[i].first - V[j].first) * (V[i].first - V[j].first) +
                  (V[i].second - V[j].second) * (V[i].second - V[j].second);
  dfs(0, 0, 0);
  (void)printf("%d\n", ma);
  for (i = 0; i < N; i++)
    (void)printf("%d %d\n", V[be[i]].first, V[be[i]].second);
}
int main(int argc, char** argv) {
  string s;
  if (argc == 1) ios::sync_with_stdio(false);
  for (int i = 1; i < argc; i++) s += argv[i], s += '\n';
  for (int i = s.size() - 1; i >= 0; i--) ungetc(s[i], stdin);
  solve();
  return 0;
}