Problem: Roland loves growing flowers. He has recently grown a beautiful rose at point (0, 0) of the Cartesian coordinate system. The rose is so beautiful that Roland is afraid that the evil forces can try and steal it. 

To protect the rose, Roland wants to build n watch towers. Let's assume that a tower is a point on the plane at the distance of at most r from the rose. Besides, Roland assumes that the towers should be built at points with integer coordinates and the sum of squares of distances between all pairs of towers must be as large as possible. Note, that Roland may build several towers at the same point, also he may build some of them at point (0, 0).

Help Roland build the towers at the integer points so that the sum of squares of distances between all towers is maximum possible. Note that the distance in this problem is defined as the Euclidian distance between points.

Input

The first line contains two integers, n and r (2 ≤ n ≤ 8; 1 ≤ r ≤ 30).

Output

In the first line print an integer — the maximum possible sum of squared distances. In the i-th of the following n lines print two integers, xi, yi — the coordinates of the i-th tower. Each tower must be inside or on the border of the circle with radius r. Note that there may be several towers located at the same point of the plane, also some towers can be located at point (0, 0).

If there are multiple valid optimal arrangements, choose any of them.

Examples

Input

4 1


Output

16
0 1
0 1
0 -1
0 -1


Input

3 6


Output

312
0 6
5 -3
-5 -3

Solution (in JAVA):

Solution:
import java.io.*;
import java.util.*;

public class CF {
	FastScanner in;
	PrintWriter out;

	class Point implements Comparable<Point> {
		int x, y;

		public Point(int x, int y) {
			super();
			this.x = x;
			this.y = y;
		}

		@Override
		public int compareTo(Point o) {
			if (x == o.x)
				return Integer.compare(y, o.y);
			return Integer.compare(x, o.x);
		}

		@Override
		public String toString() {
			return "Point [x=" + x + ", y=" + y + "]";
		}

	}

	int vectMul(Point a, Point b, Point c) {
		int val = (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
		return Integer.signum(val);
	}

	ArrayList<Point> convexHull(ArrayList<Point> pts) {
		Collections.sort(pts);
		ArrayList<Point> down = new ArrayList<>();
		ArrayList<Point> up = new ArrayList<>();
		Point f = pts.get(0);
		Point s = pts.get(pts.size() - 1);
		for (int i = 0; i < pts.size(); i++) {
			Point cur = pts.get(i);
			if (vectMul(f, s, cur) >= 0) {
				// up
				while (up.size() > 1
						&& vectMul(up.get(up.size() - 2),
								up.get(up.size() - 1), cur) >= 0) {
					up.remove(up.size() - 1);
				}
				up.add(cur);
			}
			if (vectMul(f, s, cur) <= 0) {
				// down
				while (down.size() > 1
						&& vectMul(down.get(down.size() - 2),
								down.get(down.size() - 1), cur) <= 0) {
					down.remove(down.size() - 1);
				}
				down.add(cur);
			}
		}
		down.addAll(up.subList(1, up.size() - 1));
		return down;
	}

	ArrayList<Point> all;

	void go(int from, int curCnt, int curSum) {
		if (from == all.size())
			return;
		if (curCnt == need) {
			if (curSum > bestSum) {
				bestSum = curSum;
				for (int i = 0; i < need; i++)
					best[i] = res[i];
			}
		} else {
			go(from + 1, curCnt, curSum);
			for (int i = 0; i < curCnt; i++) {
				int dx = res[i].x - all.get(from).x, dy = res[i].y
						- all.get(from).y;
				curSum += dx * dx + dy * dy;
			}
			res[curCnt++] = all.get(from);
			go(from, curCnt, curSum);
		}
	}

	Point[] res;
	Point[] best;

	long bestSum = -1;
	int need;

	void solve() {
		need = in.nextInt();
		int r = in.nextInt();
		all = new ArrayList<>();
		for (int x = -r; x <= r; x++)
			for (int y = -r; y <= r; y++)
				if (x * x + y * y <= r * r)
					all.add(new Point(x, y));
		all = convexHull(all);
		Collections.sort(all, new Comparator<Point>() {

			@Override
			public int compare(Point o1, Point o2) {
				int d1 = o1.x * o1.x + o1.y * o1.y;
				int d2 = o2.x * o2.x + o2.y * o2.y;
				return -Integer.compare(d1, d2);
			}
		});
		ArrayList<Point> tmp = new ArrayList<>();
		tmp.addAll(all.subList(0, Math.min(30, all.size())));
		all = tmp;
		res = new Point[need];
		best = new Point[need];
		go(0, 0, 0);
		out.println(bestSum);
		for (int i = 0; i < need; i++) {
			out.println(best[i].x + " " + best[i].y);
		}
	}

	void runIO() {

		in = new FastScanner(System.in);
		out = new PrintWriter(System.out);

		solve();

		out.close();
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		public FastScanner(InputStream f) {
			br = new BufferedReader(new InputStreamReader(f));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return null;
				st = new StringTokenizer(s);
			}
			return st.nextToken();
		}

		boolean hasMoreTokens() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return false;
				st = new StringTokenizer(s);
			}
			return true;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}
	}

	public static void main(String[] args) {
		new CF().runIO();
	}
}