#include <bits/stdc++.h>   using namespace std;   const long long int INF = (long long int)1e9 + 10;   const long long int INFLL = (long long int)1e18 + 10;   const long double EPS = 1e-8;   const long double EPSLD = 1e-18;   const long long int MOD = 1e9 + 7;   template <class T>   T &chmin(T &a, const T &b) {     return a = min(a, b);   }   template <class T>   T &chmax(T &a, const T &b) {     return a = max(a, b);   }   namespace std {   template <class T>   bool operator<(const complex<T> &a, const complex<T> &b) {     return a.real() == b.real() ? a.imag() < b.imag() : a.real() < b.real();   }   }  // namespace std   long long int dot(complex<long long int> a, complex<long long int> b) {     return (conj(a) * b).real();   }   long long int cross(complex<long long int> a, complex<long long int> b) {     return (conj(a) * b).imag();   }   long long int ccw(complex<long long int> a, complex<long long int> b,                     complex<long long int> c) {     b -= a, c -= a;     if (cross(b, c) > 0) return +1;     if (cross(b, c) < 0) return -1;     if (dot(b, c) < 0) return +2;     if (norm(b) < norm(c)) return -2;     return 0;   }   inline bool cross(const complex<long long int> &a,                     const complex<long long int> &b,                     const complex<long long int> &c,                     const complex<long long int> &d) {     return ccw(a, c, b) * ccw(a, d, b) == -1 && ccw(c, a, d) * ccw(c, b, d) == -1;   }   vector<complex<long long int> > convex_hull(       vector<complex<long long int> > ps) {     int n = ((long long int)(ps).size());     int k = 0;     sort((ps).begin(), (ps).end());     vector<complex<long long int> > ch(2 * n);     for (int i = 0; i < n; ch[k++] = ps[i++])       while (k >= 2 && ccw(ch[k - 2], ch[k - 1], ps[i]) <= 0) k--;     for (int i = n - 2, t = k + 1; i >= 0; ch[k++] = ps[i--])       while (k >= t && ccw(ch[k - 2], ch[k - 1], ps[i]) <= 0) k--;     ch.resize(k - 1);     return ch;   }   enum { OUT, ON, IN };   int contains(const vector<complex<long long int> > pol,                const complex<long long int> p) {     bool in = false;     for (int i = 0; i < pol.size(); ++i) {       complex<long long int> a = pol[i] - p, b = pol[(i + 1) % pol.size()] - p;       if (imag(a) > imag(b)) swap(a, b);       if (imag(a) <= 0 && 0 < imag(b))         if (cross(a, b) < 0) in = !in;       if (cross(a, b) == 0 && dot(a, b) <= 0) return ON;     }     return in ? IN : OUT;   }   long long int n, r;   long long int ansv;   vector<complex<long long int> > ans;   vector<complex<long long int> > cp;   vector<complex<long long int> > ps;   void dfs(long long int c, long long int k, long long int res) {     if (c == n) {       if (ansv < res) {         ansv = res;         ans = cp;       }       return;     }     for (long long int i = (k); i < (long long int)(((long long int)(ps).size()));          i++) {       long long int nres = res;       for (long long int j = (0); j < (long long int)(c); j++)         nres += norm(ps[i] - cp[j]);       cp.emplace_back(ps[i]);       dfs(c + 1, i, nres);       cp.pop_back();     }   }   int main() {     scanf( %lld %lld , &n, &r);     for (long long int i = (-r); i < (long long int)(r + 1); i++)       for (long long int j = (-r); j < (long long int)(r + 1); j++)         if (i * i + j * j <= r * r) ps.emplace_back(complex<long long int>(i, j));     ps = convex_hull(ps);     if (n % 2 == 0)       ps = {complex<long long int>(r, 0), complex<long long int>(-r, 0)};     dfs(0, 0, 0);     printf( %lld n , ansv);     for (auto &w : ans) printf( %lld %lld n , w.real(), w.imag());     return 0;   }