#include <bits/stdc++.h>
using namespace std;
struct re {
  int x, y;
} tmp[10001], Ans[10001];
int n, r, ans, Cnt;
int x[10001], y[10001], cnt, p[10001];
double ttmp;
bool cmp(int a, int b) {
  return x[a] * x[a] + y[a] * y[a] > x[b] * x[b] + y[b] * y[b];
}
void dfs(int N, int sx, int sy, int sx2, int sy2, int sum, int t) {
  if (N == n) {
    if (sum > ans) {
      ans = sum;
      for (int i = 1; i <= N; i++) Ans[i] = tmp[i];
    }
    return;
  }
  for (int i = t; i <= cnt; i++) {
    tmp[N + 1] = (re){x[p[i]], y[p[i]]};
    dfs(N + 1, sx + x[p[i]], sy + y[p[i]], sx2 + x[p[i]] * x[p[i]],
        sy2 + y[p[i]] * y[p[i]],
        sum + N * x[p[i]] * x[p[i]] + N * y[p[i]] * y[p[i]] + sx2 + sy2 -
            2 * sx * x[p[i]] - 2 * sy * y[p[i]],
        i);
  }
}
int main() {
  scanf("%d%d", &n, &r);
  if ((n & 1) == 0) {
    x[++cnt] = 0;
    y[cnt] = r;
    x[++cnt] = 0;
    y[cnt] = -r;
    p[1] = 1;
    p[2] = 2;
  } else {
    for (int i = 1; i < r; i++) {
      int tmp = r * r - i * i;
      double ttmp = (int)sqrt(tmp);
      if (ttmp == y[cnt] && cnt != 0) cnt--;
      x[++cnt] = i;
      y[cnt] = ttmp;
    }
    Cnt = cnt;
    for (int i = 1; i <= Cnt; i++) {
      x[++cnt] = x[i];
      y[cnt] = -y[i];
      x[++cnt] = -x[i];
      y[cnt] = y[i];
      x[++cnt] = -x[i];
      y[cnt] = -y[i];
    }
    x[++cnt] = r;
    y[cnt] = 0;
    x[++cnt] = -r;
    y[cnt] = 0;
    x[++cnt] = 0;
    y[cnt] = r;
    x[++cnt] = 0;
    y[cnt] = -r;
    for (int i = 1; i <= cnt; i++) p[i] = i;
    sort(p + 1, p + 1 + cnt, cmp);
    if (n == 7) cnt = min(30, cnt);
  }
  dfs(0, 0, 0, 0, 0, 0, 1);
  printf("%d\n", ans);
  for (int i = 1; i <= n; i++) printf("%d %d\n", Ans[i].x, Ans[i].y);
}
