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 long long int INF = (long long int)1e9 + 10;
const long long int INFLL = (long long int)1e18 + 10;
const long double EPS = 1e-8;
const long double EPSLD = 1e-18;
const long long int MOD = 1e9 + 7;
template <class T>
T &chmin(T &a, const T &b) {
  return a = min(a, b);
}
template <class T>
T &chmax(T &a, const T &b) {
  return a = max(a, b);
}
namespace std {
template <class T>
bool operator<(const complex<T> &a, const complex<T> &b) {
  return a.real() == b.real() ? a.imag() < b.imag() : a.real() < b.real();
}
}  // namespace std
long long int dot(complex<long long int> a, complex<long long int> b) {
  return (conj(a) * b).real();
}
long long int cross(complex<long long int> a, complex<long long int> b) {
  return (conj(a) * b).imag();
}
long long int ccw(complex<long long int> a, complex<long long int> b,
                  complex<long long int> c) {
  b -= a, c -= a;
  if (cross(b, c) > 0) return +1;
  if (cross(b, c) < 0) return -1;
  if (dot(b, c) < 0) return +2;
  if (norm(b) < norm(c)) return -2;
  return 0;
}
inline bool cross(const complex<long long int> &a,
                  const complex<long long int> &b,
                  const complex<long long int> &c,
                  const complex<long long int> &d) {
  return ccw(a, c, b) * ccw(a, d, b) == -1 && ccw(c, a, d) * ccw(c, b, d) == -1;
}
vector<complex<long long int> > convex_hull(
    vector<complex<long long int> > ps) {
  int n = ((long long int)(ps).size());
  int k = 0;
  sort((ps).begin(), (ps).end());
  vector<complex<long long int> > ch(2 * n);
  for (int i = 0; i < n; ch[k++] = ps[i++])
    while (k >= 2 && ccw(ch[k - 2], ch[k - 1], ps[i]) <= 0) k--;
  for (int i = n - 2, t = k + 1; i >= 0; ch[k++] = ps[i--])
    while (k >= t && ccw(ch[k - 2], ch[k - 1], ps[i]) <= 0) k--;
  ch.resize(k - 1);
  return ch;
}
enum { OUT, ON, IN };
int contains(const vector<complex<long long int> > pol,
             const complex<long long int> p) {
  bool in = false;
  for (int i = 0; i < pol.size(); ++i) {
    complex<long long int> a = pol[i] - p, b = pol[(i + 1) % pol.size()] - p;
    if (imag(a) > imag(b)) swap(a, b);
    if (imag(a) <= 0 && 0 < imag(b))
      if (cross(a, b) < 0) in = !in;
    if (cross(a, b) == 0 && dot(a, b) <= 0) return ON;
  }
  return in ? IN : OUT;
}
long long int n, r;
long long int ansv;
vector<complex<long long int> > ans;
vector<complex<long long int> > cp;
vector<complex<long long int> > ps;
void dfs(long long int c, long long int k, long long int res) {
  if (c == n) {
    if (ansv < res) {
      ansv = res;
      ans = cp;
    }
    return;
  }
  for (long long int i = (k); i < (long long int)(((long long int)(ps).size()));
       i++) {
    long long int nres = res;
    for (long long int j = (0); j < (long long int)(c); j++)
      nres += norm(ps[i] - cp[j]);
    cp.emplace_back(ps[i]);
    dfs(c + 1, i, nres);
    cp.pop_back();
  }
}
int main() {
  scanf("%lld %lld", &n, &r);
  for (long long int i = (-r); i < (long long int)(r + 1); i++)
    for (long long int j = (-r); j < (long long int)(r + 1); j++)
      if (i * i + j * j <= r * r) ps.emplace_back(complex<long long int>(i, j));
  ps = convex_hull(ps);
  if (n % 2 == 0)
    ps = {complex<long long int>(r, 0), complex<long long int>(-r, 0)};
  dfs(0, 0, 0);
  printf("%lld\n", ansv);
  for (auto &w : ans) printf("%lld %lld\n", w.real(), w.imag());
  return 0;
}