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;
static const int ans3[][3][2] = {
    {
        {0, 1},
        {0, -1},
        {-1, 0},
    },
    {
        {0, 2},
        {0, -2},
        {-2, 0},
    },
    {
        {2, -2},
        {0, 3},
        {-3, 0},
    },
    {
        {2, -3},
        {0, 4},
        {-4, 0},
    },
    {
        {3, 4},
        {3, -4},
        {-5, 0},
    },
    {
        {3, 5},
        {3, -5},
        {-6, 0},
    },
    {
        {3, 6},
        {3, -6},
        {-7, 0},
    },
    {
        {5, -6},
        {0, 8},
        {-8, 0},
    },
    {
        {4, 8},
        {4, -8},
        {-9, 0},
    },
    {
        {6, 8},
        {6, -8},
        {-10, 0},
    },
    {
        {6, 9},
        {6, -9},
        {-11, 0},
    },
    {
        {6, 10},
        {6, -10},
        {-12, 0},
    },
    {
        {5, 12},
        {5, -12},
        {-13, 0},
    },
    {
        {7, 12},
        {7, -12},
        {-14, 0},
    },
    {
        {9, 12},
        {9, -12},
        {-15, 0},
    },
    {
        {9, 13},
        {9, -13},
        {-16, 0},
    },
    {
        {8, 15},
        {8, -15},
        {-17, 0},
    },
    {
        {8, 16},
        {8, -16},
        {-18, 0},
    },
    {
        {10, -16},
        {6, 18},
        {-19, 0},
    },
    {
        {12, 16},
        {12, -16},
        {-20, 0},
    },
    {
        {12, -17},
        {6, 20},
        {-21, 0},
    },
    {
        {11, 19},
        {11, -19},
        {-22, 0},
    },
    {
        {11, 20},
        {11, -20},
        {-23, 0},
    },
    {
        {13, 20},
        {13, -20},
        {-24, 0},
    },
    {
        {15, -20},
        {7, 24},
        {-24, -7},
    },
    {
        {12, 23},
        {12, -23},
        {-26, 0},
    },
    {
        {14, 23},
        {14, -23},
        {-27, 0},
    },
    {
        {14, 24},
        {14, -24},
        {-28, 0},
    },
    {
        {20, -21},
        {7, 28},
        {-28, -7},
    },
    {
        {18, -24},
        {13, 27},
        {-30, 0},
    },
};
static const int ans5[][5][2] = {
    {
        {0, 1},
        {0, 1},
        {0, -1},
        {0, -1},
        {-1, 0},
    },
    {
        {0, 2},
        {0, 2},
        {0, -2},
        {0, -2},
        {-2, 0},
    },
    {
        {2, -2},
        {0, 3},
        {0, 3},
        {0, -3},
        {-3, 0},
    },
    {
        {0, 4},
        {0, 4},
        {0, -4},
        {0, -4},
        {-4, 0},
    },
    {
        {3, 4},
        {3, -4},
        {0, 5},
        {0, -5},
        {-5, 0},
    },
    {
        {3, -5},
        {0, 6},
        {0, 6},
        {0, -6},
        {-6, 0},
    },
    {
        {3, -6},
        {0, 7},
        {0, 7},
        {0, -7},
        {-7, 0},
    },
    {
        {5, -6},
        {0, 8},
        {0, 8},
        {0, -8},
        {-8, 0},
    },
    {
        {4, 8},
        {4, -8},
        {0, 9},
        {0, -9},
        {-9, 0},
    },
    {
        {6, 8},
        {6, -8},
        {0, 10},
        {0, -10},
        {-10, 0},
    },
    {
        {6, 9},
        {6, -9},
        {0, 11},
        {0, -11},
        {-11, 0},
    },
    {
        {6, -10},
        {0, 12},
        {0, 12},
        {0, -12},
        {-12, 0},
    },
    {
        {12, -5},
        {5, 12},
        {0, -13},
        {-5, 12},
        {-12, -5},
    },
    {
        {7, -12},
        {5, 13},
        {0, 14},
        {0, -14},
        {-14, 0},
    },
    {
        {9, 12},
        {9, -12},
        {0, 15},
        {0, -15},
        {-15, 0},
    },
    {
        {9, 13},
        {9, -13},
        {0, 16},
        {0, -16},
        {-16, 0},
    },
    {
        {8, 15},
        {8, -15},
        {0, 17},
        {0, -17},
        {-17, 0},
    },
    {
        {8, 16},
        {8, -16},
        {0, 18},
        {0, -18},
        {-18, 0},
    },
    {
        {6, 18},
        {6, -18},
        {6, -18},
        {0, 19},
        {-19, 0},
    },
    {
        {12, 16},
        {12, -16},
        {0, 20},
        {0, -20},
        {-20, 0},
    },
    {
        {12, -17},
        {6, 20},
        {0, 21},
        {0, -21},
        {-21, 0},
    },
    {
        {11, 19},
        {11, -19},
        {0, 22},
        {0, -22},
        {-22, 0},
    },
    {
        {11, 20},
        {11, -20},
        {0, 23},
        {0, -23},
        {-23, 0},
    },
    {
        {13, 20},
        {13, -20},
        {0, 24},
        {0, -24},
        {-24, 0},
    },
    {
        {20, 15},
        {20, -15},
        {-7, 24},
        {-7, -24},
        {-25, 0},
    },
    {
        {24, -10},
        {10, 24},
        {0, -26},
        {-10, 24},
        {-24, -10},
    },
    {
        {14, 23},
        {14, -23},
        {0, 27},
        {0, -27},
        {-27, 0},
    },
    {
        {10, 26},
        {10, -26},
        {7, -27},
        {0, 28},
        {-28, 0},
    },
    {
        {20, 21},
        {20, -21},
        {0, -29},
        {-7, 28},
        {-29, 0},
    },
    {
        {18, -24},
        {13, 27},
        {0, 30},
        {0, -30},
        {-30, 0},
    },
};
static const int ans7[][7][2] = {{
                                     {0, 1},
                                     {0, 1},
                                     {0, 1},
                                     {0, -1},
                                     {0, -1},
                                     {0, -1},
                                     {-1, 0},
                                 },
                                 {
                                     {0, 2},
                                     {0, 2},
                                     {0, 2},
                                     {0, -2},
                                     {0, -2},
                                     {0, -2},
                                     {-2, 0},
                                 },
                                 {
                                     {0, 3},
                                     {0, 3},
                                     {0, 3},
                                     {0, -3},
                                     {0, -3},
                                     {0, -3},
                                     {-3, 0},
                                 },
                                 {
                                     {0, 4},
                                     {0, 4},
                                     {0, 4},
                                     {0, -4},
                                     {0, -4},
                                     {0, -4},
                                     {-4, 0},
                                 },
                                 {
                                     {3, -4},
                                     {3, -4},
                                     {0, 5},
                                     {0, 5},
                                     {0, 5},
                                     {-3, -4},
                                     {-4, -3},
                                 },
                                 {
                                     {3, -5},
                                     {0, 6},
                                     {0, 6},
                                     {0, 6},
                                     {0, -6},
                                     {0, -6},
                                     {-6, 0},
                                 },
                                 {
                                     {3, -6},
                                     {0, 7},
                                     {0, 7},
                                     {0, 7},
                                     {0, -7},
                                     {0, -7},
                                     {-7, 0},
                                 },
                                 {
                                     {5, -6},
                                     {0, 8},
                                     {0, 8},
                                     {0, 8},
                                     {0, -8},
                                     {0, -8},
                                     {-8, 0},
                                 },
                                 {
                                     {4, 8},
                                     {4, -8},
                                     {0, 9},
                                     {0, 9},
                                     {0, -9},
                                     {0, -9},
                                     {-9, 0},
                                 },
                                 {
                                     {6, -8},
                                     {6, -8},
                                     {0, 10},
                                     {0, 10},
                                     {0, 10},
                                     {-6, -8},
                                     {-8, -6},
                                 },
                                 {
                                     {6, -9},
                                     {0, 11},
                                     {0, 11},
                                     {0, 11},
                                     {0, -11},
                                     {0, -11},
                                     {-11, 0},
                                 },
                                 {
                                     {6, -10},
                                     {0, 12},
                                     {0, 12},
                                     {0, 12},
                                     {0, -12},
                                     {0, -12},
                                     {-12, 0},
                                 },
                                 {
                                     {12, -5},
                                     {5, 12},
                                     {0, 13},
                                     {0, -13},
                                     {0, -13},
                                     {-5, 12},
                                     {-12, -5},
                                 },
                                 {
                                     {7, -12},
                                     {5, 13},
                                     {0, 14},
                                     {0, 14},
                                     {0, -14},
                                     {0, -14},
                                     {-14, 0},
                                 },
                                 {
                                     {9, -12},
                                     {9, -12},
                                     {0, 15},
                                     {0, 15},
                                     {0, 15},
                                     {-9, -12},
                                     {-12, -9},
                                 },
                                 {
                                     {9, 13},
                                     {9, -13},
                                     {0, 16},
                                     {0, 16},
                                     {0, -16},
                                     {0, -16},
                                     {-16, 0},
                                 },
                                 {
                                     {8, 15},
                                     {8, -15},
                                     {0, 17},
                                     {0, 17},
                                     {0, -17},
                                     {0, -17},
                                     {-17, 0},
                                 },
                                 {
                                     {8, 16},
                                     {8, -16},
                                     {0, 18},
                                     {0, 18},
                                     {0, -18},
                                     {0, -18},
                                     {-18, 0},
                                 },
                                 {
                                     {6, 18},
                                     {6, -18},
                                     {6, -18},
                                     {0, 19},
                                     {0, 19},
                                     {0, -19},
                                     {-19, 0},
                                 },
                                 {
                                     {12, -16},
                                     {12, -16},
                                     {0, 20},
                                     {0, 20},
                                     {0, 20},
                                     {-12, -16},
                                     {-16, -12},
                                 },
                                 {
                                     {12, -17},
                                     {6, 20},
                                     {0, 21},
                                     {0, 21},
                                     {0, -21},
                                     {0, -21},
                                     {-21, 0},
                                 },
                                 {
                                     {11, 19},
                                     {11, -19},
                                     {0, 22},
                                     {0, 22},
                                     {0, -22},
                                     {0, -22},
                                     {-22, 0},
                                 },
                                 {
                                     {11, 20},
                                     {11, -20},
                                     {0, 23},
                                     {0, 23},
                                     {0, -23},
                                     {0, -23},
                                     {-23, 0},
                                 },
                                 {
                                     {13, 20},
                                     {13, -20},
                                     {0, 24},
                                     {0, 24},
                                     {0, -24},
                                     {0, -24},
                                     {-24, 0},
                                 },
                                 {
                                     {15, -20},
                                     {15, -20},
                                     {7, 24},
                                     {0, -25},
                                     {-7, 24},
                                     {-7, 24},
                                     {-24, -7},
                                 },
                                 {
                                     {24, -10},
                                     {10, 24},
                                     {0, 26},
                                     {0, -26},
                                     {0, -26},
                                     {-10, 24},
                                     {-24, -10},
                                 },
                                 {
                                     {14, 23},
                                     {14, -23},
                                     {0, 27},
                                     {0, 27},
                                     {0, -27},
                                     {0, -27},
                                     {-27, 0},
                                 },
                                 {
                                     {17, -22},
                                     {10, 26},
                                     {0, 28},
                                     {0, 28},
                                     {0, -28},
                                     {0, -28},
                                     {-28, 0},
                                 },
                                 {
                                     {20, -21},
                                     {20, -21},
                                     {0, 29},
                                     {0, 29},
                                     {0, 29},
                                     {-20, -21},
                                     {-20, -21},
                                 },
                                 {
                                     {18, -24},
                                     {13, 27},
                                     {0, 30},
                                     {0, 30},
                                     {0, -30},
                                     {0, -30},
                                     {-30, 0},
                                 }};
static inline int sqr(int x) { return x * x; }
int main(int argc, const char* argv[]) {
  int n, r;
  cin >> n >> r;
  if (!(n & 1)) {
    cout << n * n * r * r << endl;
    for (int i = 0; i < n; i += 2) {
      cout << -r << " 0" << endl;
      cout << r << " 0" << endl;
    }
    return 0;
  }
  const int(*a)[2];
  if (n == 3) {
    a = &ans3[r - 1][0];
  } else if (n == 5) {
    a = &ans5[r - 1][0];
  } else {
    a = &ans7[r - 1][0];
  }
  int ret = 0;
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++)
      ret += sqr(a[i][0] - a[j][0]) + sqr(a[i][1] - a[j][1]);
  cout << ret << endl;
  for (int i = 0; i < n; i++) cout << a[i][0] << ' ' << a[i][1] << endl;
  return 0;
}