#include <bits/stdc++.h>
using namespace std;
struct Point {
  int x, y;
} point[10000], o;
int ans[10000], maxans;
int stk[10000], top;
int tot, n, r, m;
inline int dist(Point a, Point b) {
  return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}
bool cmp(Point a, Point b) { return dist(a, o) > dist(b, o); }
void dfs(int x, int used, int sum) {
  if (used == n) {
    if (maxans < sum) {
      maxans = sum;
      memcpy(ans, stk, sizeof(stk));
    }
    return;
  }
  for (int i = x; i <= m; i++) {
    stk[++top] = i;
    int tmp = 0;
    for (int j = 1; j < top; j++) tmp += dist(point[stk[j]], point[i]);
    dfs(i, used + 1, sum + tmp);
    --top;
  }
}
int main() {
  scanf("%d%d", &n, &r);
  for (int i = -r; i <= r; i++)
    for (int j = -r; j <= r; j++) {
      Point t;
      t.x = i;
      t.y = j;
      if (dist(t, o) <= r * r) point[++tot] = t;
    }
  sort(point + 1, point + tot + 1, cmp);
  m = min(18, max(n, tot));
  dfs(1, 0, 0);
  printf("%d\n", maxans);
  for (int i = 1; i <= n; i++)
    printf("%d %d\n", point[ans[i]].x, point[ans[i]].y);
}
