#include <bits/stdc++.h>
using namespace std;
struct PT {
  int x, y;
  PT(int X = 0, int Y = 0) : x(X), y(Y) {}
  PT operator+(const PT &A) const { return PT(x + A.x, y + A.y); }
  PT operator-(const PT &A) const { return PT(x - A.x, y - A.y); }
  PT operator*(int a) const { return PT(x * a, y * a); }
  PT operator/(const int &A) const { return PT(x / A, y / A); }
  int operator^(const PT &A) const { return x * A.y - y * A.x; }
  int len() { return x * x + y * y; }
  PT norm() const { return PT(-y, x); }
} t[1010], s[1010];
bool cmp(const PT &a, const PT &b) {
  return (a.x < b.x) || ((a.x == b.x) && (a.y < b.y));
}
bool cmp1(PT a, PT b) { return (a.len()) > (b.len()); }
int cross(PT x, PT a, PT b) { return (a - x) ^ (b - x); }
int len(PT a, PT b) { return (a - b).len(); }
int top, ma;
void convex_hull(int n) {
  sort(t, t + n, cmp);
  top = 0;
  for (int i = 0; i < n; i++) {
    while (top >= 2 && cross(s[top - 2], s[top - 1], t[i]) <= 0) top--;
    s[top++] = t[i];
  }
  for (int i = n - 2, k = top + 1; i >= 0; i--) {
    while (top >= k && cross(s[top - 2], s[top - 1], t[i]) <= 0) top--;
    s[top++] = t[i];
  }
  top--;
}
int ans[10];
int tmp[10];
void dfs(int now, int n, int total, int size, int where) {
  if (now == n) {
    if (ma < total) {
      ma = total;
      for (int i = 0; i < n; i++) ans[i] = tmp[i];
    }
    return;
  }
  for (int i = where; i < size; i++) {
    tmp[now] = i;
    int _total = total;
    for (int j = 0; j < now; j++) _total += len(s[i], s[tmp[j]]);
    dfs(now + 1, n, _total, size, i);
  }
}
void special(int n, int k) {
  int a = n / 2;
  int b = a * a * 4 * k * k;
  printf("%d\n", b);
  while (a--) printf("%d 0\n", k);
  a = n / 2;
  while (a--) printf("%d 0\n", -k);
  return;
}
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  if (n % 2 == 0) {
    special(n, k);
    return 0;
  }
  int now = 0;
  t[now++] = PT(k, 0);
  t[now++] = PT(-k, 0);
  for (int i = -k + 1; i <= k - 1; i++)
    for (int j = 1; j <= k; j++) {
      if ((i * i + j * j) <= k * k && (i * i + (j + 1) * (j + 1)) > k * k) {
        t[now++] = PT(i, j);
        t[now++] = PT(i, -j);
        break;
      }
    }
  top = 0;
  convex_hull(now);
  ma = 0;
  sort(s, s + top, cmp1);
  dfs(0, n, 0, top, 0);
  printf("%d\n", ma);
  for (int i = 0; i < n; i++) printf("%d %d\n", s[ans[i]].x, s[ans[i]].y);
}
