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;
#pragma comment(linker, "/STACK:64000000")
const int maxn = 18;
const int maxm = 110;
const int maxmask = (1 << maxn) - 1;
const int infi = 1e9 + 7;
const long long infl = 1e18;
const double eps = 1e-6;
const int mod = 1e9 + 7;
pair<int, int> ar[5000];
int sqr(int a) { return a * a; }
int res;
pair<int, int> ans[10];
pair<int, int> per1[10];
void per(int i, int &n, int &a, int &m, int sumkvx, int sumx, int sumkvy,
         int sumy, int x) {
  if (n == i) {
    if (res < x) {
      res = x;
      for (int j = 0; j < n; ++j) {
        ans[j] = per1[j];
      }
    }
    return;
  }
  for (int j = a; j < m; ++j) {
    per1[i] = ar[j];
    per(i + 1, n, j, m, sumkvx + sqr(ar[j].first), sumx + ar[j].first,
        sumkvy + sqr(ar[j].second), sumy + ar[j].second,
        x + i * (sqr(ar[j].first) + sqr(ar[j].second)) + sumkvx + sumkvy -
            2 * ar[j].first * sumx - 2 * ar[j].second * sumy);
  }
  return;
}
pair<int, int> vec(pair<int, int> a, pair<int, int> b) {
  return make_pair(a.first - b.first, a.second - b.second);
}
vector<pair<int, int> > arz;
int sn(pair<int, int> a, pair<int, int> b) {
  return a.first * b.second - a.second * b.first;
}
int dist(pair<int, int> a) { return sqr(a.first) + sqr(a.second); }
bool comp(pair<int, int> a, pair<int, int> b) {
  int c = sn(a, b);
  return c > 0 || (c == 0 && dist(a) < dist(b));
}
int main() {
  int n, r;
  cin >> n >> r;
  int m = 0;
  for (int i = -r; i <= r; ++i) {
    for (int j = -r; j <= r; ++j) {
      if (sqr(i) + sqr(j) <= sqr(r)) {
        if ((sqr(i) + sqr(j - 1) <= sqr(r) && (sqr(i) + sqr(j + 1) > sqr(r))) ||
            (sqr(i) + sqr(j - 1) > sqr(r) && (sqr(i) + sqr(j + 1) <= sqr(r))) ||
            (sqr(i) + sqr(j - 1) > sqr(r) && (sqr(i) + sqr(j + 1) > sqr(r)))) {
          ar[m] = make_pair(i, j);
          ++m;
        }
      }
    }
  }
  pair<int, int> b = ar[0];
  for (int i = 0; i < m; ++i) {
    ar[i].first -= b.first;
    ar[i].second -= b.second;
  }
  sort(ar, ar + m, comp);
  arz.push_back(ar[0]), arz.push_back(ar[1]);
  for (int i = 2; i < m; ++i) {
    int q = sn(vec(arz[arz.size() - 1], arz[arz.size() - 2]),
               vec(ar[i], arz[arz.size() - 1]));
    while (q <= 0) {
      arz.pop_back();
      if (arz.size() < 2) {
        break;
      }
      q = sn(vec(arz[arz.size() - 1], arz[arz.size() - 2]),
             vec(ar[i], arz[arz.size() - 1]));
    }
    arz.push_back(ar[i]);
  }
  for (int i = 0; i < arz.size(); ++i) {
    arz[i].first += b.first;
    arz[i].second += b.second;
    ar[i] = arz[i];
  }
  m = (int)arz.size();
  int a = 0;
  per(0, n, a, m, 0, 0, 0, 0, 0);
  cout << res << endl;
  for (int i = 0; i < n; ++i) {
    cout << ans[i].first << ' ' << ans[i].second << endl;
  }
  return 0;
}