#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > arr, tmp, out;
int ans = 0, n;
void dfs(int pp, int sq, int adx, int ady) {
  if (tmp.size() == n) {
    if (sq * n - adx * adx - ady * ady > ans) {
      ans = sq * n - adx * adx - ady * ady;
      out = tmp;
    }
    return;
  }
  for (int u = pp; u < min(20, (int)arr.size()); u++) {
    tmp.push_back(arr[u]);
    dfs(u, sq + arr[u].first * arr[u].first + arr[u].second * arr[u].second,
        adx + arr[u].first, ady + arr[u].second);
    tmp.pop_back();
  }
}
int cmp(pair<int, int> a, pair<int, int> b) {
  return a.first * a.first + a.second * a.second >
         b.first * b.first + b.second * b.second;
}
int main() {
  int m, i, j;
  scanf("%d%d", &n, &m);
  if (n % 2 == 0) {
    printf("%d\n", m * m * 4 * n * n / 4);
    for (i = 0; i < n / 2; i++) printf("%d 0\n-%d 0\n", m, m);
    return 0;
  }
  for (i = -m; i <= m; i++) {
    for (j = 0; j <= m; j++) {
      if (i * i + j * j > m * m) break;
    }
    j--;
    arr.push_back(make_pair(i, j));
    arr.push_back(make_pair(i, -j));
  }
  sort(arr.begin(), arr.end(), cmp);
  dfs(0, 0, 0, 0);
  printf("%d\n", ans);
  for (i = 0; i < out.size(); i++) {
    printf("%d %d\n", out[i].first, out[i].second);
  }
}
