#include <bits/stdc++.h>
using namespace std;
int n, r;
vector<int> X, Y;
vector<pair<int, int> > Points;
vector<pair<int, int> > hull;
vector<pair<int, int> > cur, save;
int best = -1;
void Rec(int ind, int sumx, int sumx2, int sumy, int sumy2) {
  if (cur.size() == n) {
    int tmp = n * (sumx2 + sumy2) - (sumx * sumx + sumy * sumy);
    if (tmp > best) {
      best = tmp;
      save = cur;
    }
    return;
  }
  for (int i = ind; i < hull.size(); ++i) {
    cur.push_back(hull[i]);
    int x = hull[i].first, y = hull[i].second;
    Rec(i, sumx + x, sumx2 + x * x, sumy + y, sumy2 + y * y);
    cur.pop_back();
  }
}
int main() {
  cin >> n >> r;
  if (n == 2) {
    cout << 4 * r * r << endl;
    cout << r << " " << 0 << endl;
    cout << -r << " " << 0 << endl;
    return 0;
  }
  vector<int> max_Y(r + 1, 0);
  for (int x = 0; x <= r; ++x) {
    for (int y = r; y >= 0; --y)
      if (x * x + y * y <= r * r) {
        max_Y[x] = y;
        break;
      }
  }
  for (int x = r; x >= -r; --x) Points.push_back(make_pair(x, max_Y[abs(x)]));
  for (int x = -r + 1; x < r; ++x)
    Points.push_back(make_pair(x, -max_Y[abs(x)]));
  hull.push_back(Points[0]);
  hull.push_back(Points[1]);
  for (int i = 2; i <= Points.size(); ++i) {
    int ind = i % Points.size();
    while (hull.size() >= 2) {
      int x1 = hull[hull.size() - 1].first - hull[hull.size() - 2].first;
      int y1 = hull[hull.size() - 1].second - hull[hull.size() - 2].second;
      int x2 = Points[ind].first - hull[hull.size() - 2].first;
      int y2 = Points[ind].second - hull[hull.size() - 2].second;
      int cross = x1 * y2 - y1 * x2;
      if (cross <= 0)
        hull.pop_back();
      else
        break;
    }
    if (i < Points.size()) hull.push_back(Points[ind]);
  }
  Rec(0, 0, 0, 0, 0);
  cout << best << endl;
  for (int i = 0; i < save.size(); ++i)
    cout << save[i].first << " " << save[i].second << endl;
  return 0;
}
