#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int n, m, r;
vector<pair<int, int> > H;
int det(pair<int, int> a, pair<int, int> b, pair<int, int> c) {
  return (b.first - a.first) * (c.second - a.second) -
         (b.second - a.second) * (c.first - a.first);
}
int dist(pair<int, int> a, pair<int, int> b) {
  return (a.first - b.first) * (a.first - b.first) +
         (a.second - b.second) * (a.second - b.second);
}
int w, c;
vector<pair<int, int> > R, C;
void solve(int z = 0, int k = 0) {
  if (k == n) {
    if (c > w) {
      w = c;
      R = C;
    }
  } else {
    for (int i = (z); i < (m); ++i) {
      int sc = c;
      for (pair<int, int> p : C) c += dist(p, H[i]);
      C.push_back(H[i]);
      solve(i, k + 1);
      C.pop_back();
      c = sc;
    }
  }
}
int main() {
  scanf("%d %d", &n, &r);
  if (n & 1) {
    for (int second = (0); second < (r + 1); ++second) {
      int first = 0;
      while (first * first + second * second <= r * r) ++first;
      --first;
      while (H.size() > 1 &&
             det(H[H.size() - 2], H.back(), pair<int, int>(first, second)) <= 0)
        H.pop_back();
      H.push_back(pair<int, int>(first, second));
    }
    m = H.size();
    for (int i = (0); i < (m); ++i) {
      H.push_back(pair<int, int>(-H[i].first, H[i].second));
      H.push_back(pair<int, int>(H[i].first, -H[i].second));
      H.push_back(pair<int, int>(-H[i].first, -H[i].second));
    }
    sort(H.begin(), H.end());
    H.erase(unique(H.begin(), H.end()), H.end());
    m = H.size();
    solve();
    printf("%d\n", w);
    for (int i = (0); i < (n); ++i) printf("%d %d\n", R[i].first, R[i].second);
  } else {
    printf("%d\n", n * n * r * r);
    for (int i = (0); i < (n / 2); ++i) printf("0 %d\n", r);
    for (int i = (0); i < (n / 2); ++i) printf("0 %d\n", -r);
  }
  return 0;
}
