#include <bits/stdc++.h>
using namespace std;
struct node {
  int x, y, z;
};
node p[300];
int xt[300];
int yt[300];
int xa[300];
int ya[300];
int d;
int n;
int maxi;
bool cmp(node a, node b) { return a.z > b.z; }
void dfs(int l, int cnt) {
  int i, j;
  if (cnt == n) {
    int x = 0;
    for (i = 0; i < cnt; i++)
      for (j = i + 1; j < cnt; j++)
        x += (xt[i] - xt[j]) * (xt[i] - xt[j]) +
             (yt[i] - yt[j]) * (yt[i] - yt[j]);
    if (x > maxi) {
      maxi = x;
      for (i = 0; i < cnt; i++) {
        xa[i] = xt[i];
        ya[i] = yt[i];
      }
    }
    return;
  }
  for (i = l; i < d; i++) {
    xt[cnt] = p[i].x;
    yt[cnt] = p[i].y;
    dfs(i, cnt + 1);
  }
}
int main() {
  int r;
  while (scanf("%d%d", &n, &r) != EOF) {
    int i, j;
    memset(p, 0, sizeof(p));
    d = 0;
    maxi = 0;
    int rm = r * r;
    int rs = (r - 1) * (r - 1);
    for (i = -r; i <= r; i++)
      for (j = -r; j <= r; j++) {
        int x = i * i + j * j;
        if (x <= rm && x > rs) {
          p[d].x = i;
          p[d].y = j;
          p[d++].z = x;
        }
      }
    sort(p, p + d, cmp);
    d = 30 - n * 2;
    dfs(0, 0);
    printf("%d\n", maxi);
    for (i = 0; i < n; i++) printf("%d %d\n", xa[i], ya[i]);
  }
  return 0;
}
