#include <bits/stdc++.h>
using namespace std;
struct Point {
  int x, y;
  Point(int a, int b) {
    x = a;
    y = b;
  }
};
int n, R, ans, m;
vector<Point> G;
int pos[10005], rec[10005];
int dist(Point A) { return A.x * A.x + A.y * A.y; }
int Distance(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) > dist(B); }
void dfs(int dep, int f, int sum) {
  if (dep == n) {
    if (sum > ans) {
      ans = max(ans, sum);
      memcpy(rec, pos, sizeof(pos));
    }
    return;
  }
  for (int i = f; i < m; i++) {
    int tmp = 0;
    for (int j = 0; j < dep; j++) tmp += Distance(G[pos[j]], G[i]);
    pos[dep] = i;
    dfs(dep + 1, i, sum + tmp);
  }
}
int T;
int main() {
  scanf("%d%d", &n, &R);
  for (int i = -R; i <= R; i++)
    for (int j = -R; j <= R; j++)
      if (i * i + j * j <= R * R) G.push_back(Point(i, j));
  ans = 0;
  m = min((int)G.size(), 18);
  sort(G.begin(), G.end(), cmp);
  dfs(0, 0, 0);
  printf("%d\n", ans);
  for (int i = 0; i < n; i++) printf("%d %d\n", G[rec[i]].x, G[rec[i]].y);
  G.clear();
  memset(pos, 0, sizeof(pos));
  return 0;
}
