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 PYTHON):

Solution:
from collections import defaultdict
def op(a, b):
    return a[0] * b[1] - a[1] * b[0]
def opp(a, b, c):
    ba = (b[0] - a[0], b[1] - a[1])
    ca = (c[0] - b[0], c[1] - b[1])
    return op(ba, ca)
def solve(n, r):
    p = [(i, j) for i in xrange(-r, r+1) for j in xrange(-r, r+1) if i*i + j*j <= r*r]
    p.sort()
    q = [p[0], p[1]]
    i = 2
    while i < len(p):
        while len(q) >= 2 and opp(q[-2], q[-1], p[i]) <= 0:
            q.pop()
        q.append(p[i])
        i += 1
    q.extend((x[0], -x[1]) for x in q[1:-1])
    d = [defaultdict(int) for i in xrange(n+1)]
    d[0][(0,0)] = [0]
    for i in xrange(n):
        for x, v in d[i].items():
            for y in q:
                nx = (x[0] + y[0], x[1] + y[1])
                nv = v[0] + (y[0] * y[0] + y[1] * y[1]) * (n - 1) - 2 * y[0] * x[0] - 2 * y[1] * x[1]
                d[i+1][nx] = max(d[i+1][nx], (nv, y, x))
    w = max(d[-1].values())
    for x, v in d[-1].items():
        if v == w:
            ans = []
            for i in xrange(n, 0, -1):
                ans.append(d[i][x][1])
                x = d[i][x][2]
            return (v[0], ans)
d={
(2,1): (4, [(1, 0), (-1, 0)]) ,
(2,2): (16, [(2, 0), (-2, 0)]) ,
(2,3): (36, [(3, 0), (-3, 0)]) ,
(2,4): (64, [(4, 0), (-4, 0)]) ,
(2,5): (100, [(5, 0), (-5, 0)]) ,
(2,6): (144, [(6, 0), (-6, 0)]) ,
(2,7): (196, [(7, 0), (-7, 0)]) ,
(2,8): (256, [(8, 0), (-8, 0)]) ,
(2,9): (324, [(9, 0), (-9, 0)]) ,
(2,10): (400, [(10, 0), (-10, 0)]) ,
(2,11): (484, [(11, 0), (-11, 0)]) ,
(2,12): (576, [(12, 0), (-12, 0)]) ,
(2,13): (676, [(13, 0), (-13, 0)]) ,
(2,14): (784, [(14, 0), (-14, 0)]) ,
(2,15): (900, [(15, 0), (-15, 0)]) ,
(2,16): (1024, [(16, 0), (-16, 0)]) ,
(2,17): (1156, [(17, 0), (-17, 0)]) ,
(2,18): (1296, [(18, 0), (-18, 0)]) ,
(2,19): (1444, [(19, 0), (-19, 0)]) ,
(2,20): (1600, [(20, 0), (-20, 0)]) ,
(2,21): (1764, [(21, 0), (-21, 0)]) ,
(2,22): (1936, [(22, 0), (-22, 0)]) ,
(2,23): (2116, [(23, 0), (-23, 0)]) ,
(2,24): (2304, [(24, 0), (-24, 0)]) ,
(2,25): (2500, [(25, 0), (-25, 0)]) ,
(2,26): (2704, [(26, 0), (-26, 0)]) ,
(2,27): (2916, [(27, 0), (-27, 0)]) ,
(2,28): (3136, [(28, 0), (-28, 0)]) ,
(2,29): (3364, [(29, 0), (-29, 0)]) ,
(2,30): (3600, [(30, 0), (-30, 0)]) ,
(3,1): (8, [(1, 0), (1, 0), (-1, 0)]) ,
(3,2): (32, [(2, 0), (2, 0), (-2, 0)]) ,
(3,3): (76, [(3, 0), (0, 3), (-2, -2)]) ,
(3,4): (130, [(4, 0), (0, 4), (-2, -3)]) ,
(3,5): (224, [(5, 0), (-3, 4), (-3, -4)]) ,
(3,6): (312, [(6, 0), (-3, 5), (-3, -5)]) ,
(3,7): (416, [(7, 0), (-3, 6), (-3, -6)]) ,
(3,8): (554, [(8, 0), (0, 8), (-5, -6)]) ,
(3,9): (722, [(9, 0), (-4, 8), (-4, -8)]) ,
(3,10): (896, [(10, 0), (-6, 8), (-6, -8)]) ,
(3,11): (1064, [(11, 0), (-6, 9), (-6, -9)]) ,
(3,12): (1248, [(12, 0), (-6, 10), (-6, -10)]) ,
(3,13): (1512, [(13, 0), (-5, 12), (-5, -12)]) ,
(3,14): (1746, [(14, 0), (-7, 12), (-7, -12)]) ,
(3,15): (2016, [(15, 0), (-9, 12), (-9, -12)]) ,
(3,16): (2264, [(16, 0), (-9, 13), (-9, -13)]) ,
(3,17): (2600, [(17, 0), (-8, 15), (-8, -15)]) ,
(3,18): (2888, [(18, 0), (-8, 16), (-8, -16)]) ,
(3,19): (3218, [(19, 0), (-6, 18), (-10, -16)]) ,
(3,20): (3584, [(20, 0), (-12, 16), (-12, -16)]) ,
(3,21): (3912, [(21, 0), (-6, 20), (-12, -17)]) ,
(3,22): (4344, [(22, 0), (-11, 19), (-11, -19)]) ,
(3,23): (4712, [(23, 0), (-11, 20), (-11, -20)]) ,
(3,24): (5138, [(24, 0), (-13, 20), (-13, -20)]) ,
(3,25): (5612, [(24, 7), (-7, -24), (-15, 20)]) ,
(3,26): (6062, [(26, 0), (-12, 23), (-12, -23)]) ,
(3,27): (6536, [(27, 0), (-14, 23), (-14, -23)]) ,
(3,28): (6984, [(28, 0), (-14, 24), (-14, -24)]) ,
(3,29): (7520, [(28, 7), (-7, -28), (-20, 21)]) ,
(3,30): (8084, [(30, 0), (-13, 27), (-18, -24)]) ,
(4,1): (16, [(1, 0), (1, 0), (-1, 0), (-1, 0)]) ,
(4,2): (64, [(2, 0), (2, 0), (-2, 0), (-2, 0)]) ,
(4,3): (144, [(3, 0), (3, 0), (-3, 0), (-3, 0)]) ,
(4,4): (256, [(4, 0), (4, 0), (-4, 0), (-4, 0)]) ,
(4,5): (400, [(5, 0), (5, 0), (-5, 0), (-5, 0)]) ,
(4,6): (576, [(6, 0), (6, 0), (-6, 0), (-6, 0)]) ,
(4,7): (784, [(7, 0), (7, 0), (-7, 0), (-7, 0)]) ,
(4,8): (1024, [(8, 0), (8, 0), (-8, 0), (-8, 0)]) ,
(4,9): (1296, [(9, 0), (9, 0), (-9, 0), (-9, 0)]) ,
(4,10): (1600, [(10, 0), (10, 0), (-10, 0), (-10, 0)]) ,
(4,11): (1936, [(11, 0), (11, 0), (-11, 0), (-11, 0)]) ,
(4,12): (2304, [(12, 0), (12, 0), (-12, 0), (-12, 0)]) ,
(4,13): (2704, [(13, 0), (13, 0), (-13, 0), (-13, 0)]) ,
(4,14): (3136, [(14, 0), (14, 0), (-14, 0), (-14, 0)]) ,
(4,15): (3600, [(15, 0), (15, 0), (-15, 0), (-15, 0)]) ,
(4,16): (4096, [(16, 0), (16, 0), (-16, 0), (-16, 0)]) ,
(4,17): (4624, [(17, 0), (17, 0), (-17, 0), (-17, 0)]) ,
(4,18): (5184, [(18, 0), (18, 0), (-18, 0), (-18, 0)]) ,
(4,19): (5776, [(19, 0), (19, 0), (-19, 0), (-19, 0)]) ,
(4,20): (6400, [(20, 0), (20, 0), (-20, 0), (-20, 0)]) ,
(4,21): (7056, [(21, 0), (21, 0), (-21, 0), (-21, 0)]) ,
(4,22): (7744, [(22, 0), (22, 0), (-22, 0), (-22, 0)]) ,
(4,23): (8464, [(23, 0), (23, 0), (-23, 0), (-23, 0)]) ,
(4,24): (9216, [(24, 0), (24, 0), (-24, 0), (-24, 0)]) ,
(4,25): (10000, [(25, 0), (25, 0), (-25, 0), (-25, 0)]) ,
(4,26): (10816, [(26, 0), (26, 0), (-26, 0), (-26, 0)]) ,
(4,27): (11664, [(27, 0), (27, 0), (-27, 0), (-27, 0)]) ,
(4,28): (12544, [(28, 0), (28, 0), (-28, 0), (-28, 0)]) ,
(4,29): (13456, [(29, 0), (29, 0), (-29, 0), (-29, 0)]) ,
(4,30): (14400, [(30, 0), (30, 0), (-30, 0), (-30, 0)]) ,
(5,1): (24, [(1, 0), (1, 0), (1, 0), (-1, 0), (-1, 0)]) ,
(5,2): (96, [(2, 0), (2, 0), (2, 0), (-2, 0), (-2, 0)]) ,
(5,3): (218, [(3, 0), (3, 0), (0, 3), (-2, -2), (-3, 0)]) ,
(5,4): (384, [(4, 0), (4, 0), (4, 0), (-4, 0), (-4, 0)]) ,
(5,5): (624, [(5, 0), (3, 4), (3, -4), (-5, 0), (-5, 0)]) ,
(5,6): (880, [(6, 0), (6, 0), (0, 6), (-3, -5), (-6, 0)]) ,
(5,7): (1188, [(7, 0), (7, 0), (0, 7), (-3, -6), (-7, 0)]) ,
(5,8): (1572, [(8, 0), (8, 0), (0, 8), (-5, -6), (-8, 0)]) ,
(5,9): (2014, [(9, 0), (9, 0), (-4, 8), (-4, -8), (-9, 0)]) ,
(5,10): (2496, [(10, 0), (6, 8), (6, -8), (-10, 0), (-10, 0)]) ,
(5,11): (2984, [(11, 0), (6, 9), (6, -9), (-11, 0), (-11, 0)]) ,
(5,12): (3520, [(12, 0), (12, 0), (0, 12), (-6, -10), (-12, 0)]) ,
(5,13): (4224, [(13, 0), (5, 12), (5, -12), (-12, 5), (-12, -5)]) ,
(5,14): (4870, [(14, 0), (14, 0), (-5, 13), (-7, -12), (-14, 0)]) ,
(5,15): (5616, [(15, 0), (9, 12), (9, -12), (-15, 0), (-15, 0)]) ,
(5,16): (6336, [(16, 0), (9, 13), (9, -13), (-16, 0), (-16, 0)]) ,
(5,17): (7224, [(17, 0), (17, 0), (-8, 15), (-8, -15), (-17, 0)]) ,
(5,18): (8056, [(18, 0), (18, 0), (-8, 16), (-8, -16), (-18, 0)]) ,
(5,19): (9008, [(19, 0), (18, -6), (0, 19), (-18, -6), (-18, -6)]) ,
(5,20): (9984, [(20, 0), (12, 16), (12, -16), (-20, 0), (-20, 0)]) ,
(5,21): (10942, [(21, 0), (21, 0), (-6, 20), (-12, -17), (-21, 0)]) ,
(5,22): (12080, [(22, 0), (22, 0), (-11, 19), (-11, -19), (-22, 0)]) ,
(5,23): (13144, [(23, 0), (23, 0), (-11, 20), (-11, -20), (-23, 0)]) ,
(5,24): (14326, [(24, 0), (13, 20), (13, -20), (-24, 0), (-24, 0)]) ,
(5,25): (15624, [(25, 0), (7, 24), (7, -24), (-20, 15), (-20, -15)]) ,
(5,26): (16896, [(26, 0), (10, 24), (10, -24), (-24, 10), (-24, -10)]) ,
(5,27): (18184, [(27, 0), (14, 23), (14, -23), (-27, 0), (-27, 0)]) ,
(5,28): (19488, [(28, 0), (26, -10), (0, 28), (-22, -17), (-28, 0)]) ,
(5,29): (20968, [(29, 0), (21, 20), (0, -29), (-21, 20), (-28, -7)]) ,
(5,30): (22480, [(30, 0), (27, 13), (0, -30), (-24, 18), (-30, 0)]) ,
(6,1): (36, [(1, 0), (1, 0), (1, 0), (-1, 0), (-1, 0), (-1, 0)]) ,
(6,2): (144, [(2, 0), (2, 0), (2, 0), (-2, 0), (-2, 0), (-2, 0)]) ,
(6,3): (324, [(3, 0), (3, 0), (3, 0), (-3, 0), (-3, 0), (-3, 0)]) ,
(6,4): (576, [(4, 0), (4, 0), (4, 0), (-4, 0), (-4, 0), (-4, 0)]) ,
(6,5): (900, [(5, 0), (5, 0), (5, 0), (-5, 0), (-5, 0), (-5, 0)]) ,
(6,6): (1296, [(6, 0), (6, 0), (6, 0), (-6, 0), (-6, 0), (-6, 0)]) ,
(6,7): (1764, [(7, 0), (7, 0), (7, 0), (-7, 0), (-7, 0), (-7, 0)]) ,
(6,8): (2304, [(8, 0), (8, 0), (8, 0), (-8, 0), (-8, 0), (-8, 0)]) ,
(6,9): (2916, [(9, 0), (9, 0), (9, 0), (-9, 0), (-9, 0), (-9, 0)]) ,
(6,10): (3600, [(10, 0), (10, 0), (10, 0), (-10, 0), (-10, 0), (-10, 0)]) ,
(6,11): (4356, [(11, 0), (11, 0), (11, 0), (-11, 0), (-11, 0), (-11, 0)]) ,
(6,12): (5184, [(12, 0), (12, 0), (12, 0), (-12, 0), (-12, 0), (-12, 0)]) ,
(6,13): (6084, [(13, 0), (13, 0), (13, 0), (-13, 0), (-13, 0), (-13, 0)]) ,
(6,14): (7056, [(14, 0), (14, 0), (14, 0), (-14, 0), (-14, 0), (-14, 0)]) ,
(6,15): (8100, [(15, 0), (15, 0), (15, 0), (-15, 0), (-15, 0), (-15, 0)]) ,
(6,16): (9216, [(16, 0), (16, 0), (16, 0), (-16, 0), (-16, 0), (-16, 0)]) ,
(6,17): (10404, [(17, 0), (17, 0), (17, 0), (-17, 0), (-17, 0), (-17, 0)]) ,
(6,18): (11664, [(18, 0), (18, 0), (18, 0), (-18, 0), (-18, 0), (-18, 0)]) ,
(6,19): (12996, [(19, 0), (19, 0), (19, 0), (-19, 0), (-19, 0), (-19, 0)]) ,
(6,20): (14400, [(20, 0), (20, 0), (20, 0), (-20, 0), (-20, 0), (-20, 0)]) ,
(6,21): (15876, [(21, 0), (21, 0), (21, 0), (-21, 0), (-21, 0), (-21, 0)]) ,
(6,22): (17424, [(22, 0), (22, 0), (22, 0), (-22, 0), (-22, 0), (-22, 0)]) ,
(6,23): (19044, [(23, 0), (23, 0), (23, 0), (-23, 0), (-23, 0), (-23, 0)]) ,
(6,24): (20736, [(24, 0), (24, 0), (24, 0), (-24, 0), (-24, 0), (-24, 0)]) ,
(6,25): (22500, [(25, 0), (25, 0), (25, 0), (-25, 0), (-25, 0), (-25, 0)]) ,
(6,26): (24336, [(26, 0), (26, 0), (26, 0), (-26, 0), (-26, 0), (-26, 0)]) ,
(6,27): (26244, [(27, 0), (27, 0), (27, 0), (-27, 0), (-27, 0), (-27, 0)]) ,
(6,28): (28224, [(28, 0), (28, 0), (28, 0), (-28, 0), (-28, 0), (-28, 0)]) ,
(6,29): (30276, [(29, 0), (29, 0), (29, 0), (-29, 0), (-29, 0), (-29, 0)]) ,
(6,30): (32400, [(30, 0), (30, 0), (30, 0), (-30, 0), (-30, 0), (-30, 0)]) ,
(7,1): (48, [(1, 0), (1, 0), (1, 0), (1, 0), (-1, 0), (-1, 0), (-1, 0)]) ,
(7,2): (192, [(2, 0), (2, 0), (2, 0), (2, 0), (-2, 0), (-2, 0), (-2, 0)]) ,
(7,3): (432, [(3, 0), (3, 0), (3, 0), (3, 0), (-3, 0), (-3, 0), (-3, 0)]) ,
(7,4): (768, [(4, 0), (4, 0), (4, 0), (4, 0), (-4, 0), (-4, 0), (-4, 0)]) ,
(7,5): (1224, [(5, 0), (5, 0), (5, 0), (-3, 4), (-3, -4), (-4, 3), (-4, -3)]) ,
(7,6): (1740, [(6, 0), (6, 0), (6, 0), (0, 6), (-3, -5), (-6, 0), (-6, 0)]) ,
(7,7): (2356, [(7, 0), (7, 0), (7, 0), (0, 7), (-3, -6), (-7, 0), (-7, 0)]) ,
(7,8): (3102, [(8, 0), (8, 0), (8, 0), (0, 8), (-5, -6), (-8, 0), (-8, 0)]) ,
(7,9): (3954, [(9, 0), (9, 0), (9, 0), (-4, 8), (-4, -8), (-9, 0), (-9, 0)]) ,
(7,10): (4896, [(10, 0), (10, 0), (10, 0), (-6, 8), (-6, -8), (-8, 6), (-8, -6)]) ,
(7,11): (5872, [(11, 0), (11, 0), (11, 0), (0, 11), (-6, -9), (-11, 0), (-11, 0)]) ,
(7,12): (6960, [(12, 0), (12, 0), (12, 0), (0, 12), (-6, -10), (-12, 0), (-12, 0)]) ,
(7,13): (8280, [(13, 0), (12, 5), (12, -5), (-5, 12), (-5, -12), (-13, 0), (-13, 0)]) ,
(7,14): (9564, [(14, 0), (14, 0), (14, 0), (-5, 13), (-7, -12), (-14, 0), (-14, 0)]) ,
(7,15): (11016, [(15, 0), (15, 0), (15, 0), (-9, 12), (-9, -12), (-12, 9), (-12, -9)]) ,
(7,16): (12456, [(16, 0), (16, 0), (9, 13), (9, -13), (-16, 0), (-16, 0), (-16, 0)]) ,
(7,17): (14160, [(17, 0), (17, 0), (17, 0), (-8, 15), (-8, -15), (-17, 0), (-17, 0)]) ,
(7,18): (15816, [(18, 0), (18, 0), (18, 0), (-8, 16), (-8, -16), (-18, 0), (-18, 0)]) ,
(7,19): (17666, [(19, 0), (19, 0), (18, -6), (0, 19), (-18, -6), (-18, -6), (-19, 0)]) ,
(7,20): (19584, [(20, 0), (20, 0), (20, 0), (-12, 16), (-12, -16), (-16, 12), (-16, -12)]) ,
(7,21): (21500, [(21, 0), (21, 0), (21, 0), (-6, 20), (-12, -17), (-21, 0), (-21, 0)]) ,
(7,22): (23688, [(22, 0), (22, 0), (22, 0), (-11, 19), (-11, -19), (-22, 0), (-22, 0)]) ,
(7,23): (25808, [(23, 0), (23, 0), (23, 0), (-11, 20), (-11, -20), (-23, 0), (-23, 0)]) ,
(7,24): (28122, [(24, 0), (24, 0), (13, 20), (13, -20), (-24, 0), (-24, 0), (-24, 0)]) ,
(7,25): (30624, [(25, 0), (20, 15), (20, -15), (-7, 24), (-7, -24), (-25, 0), (-25, 0)]) ,
(7,26): (33120, [(26, 0), (24, 10), (24, -10), (-10, 24), (-10, -24), (-26, 0), (-26, 0)]) ,
(7,27): (35664, [(27, 0), (27, 0), (14, 23), (14, -23), (-27, 0), (-27, 0), (-27, 0)]) ,
(7,28): (38266, [(28, 0), (28, 0), (26, -10), (0, 28), (-22, -17), (-28, 0), (-28, 0)]) ,
(7,29): (41200, [(29, 0), (29, 0), (29, 0), (-21, 20), (-21, 20), (-21, -20), (-21, -20)]) ,
(7,30): (44076, [(30, 0), (30, 0), (27, 13), (0, -30), (-24, 18), (-30, 0), (-30, 0)]) ,
}
n, r = map(int, raw_input().split())
if n % 2:
    print d[n,r][0]
    for x in d[n,r][1]:
        print x[0], x[1]
else:
    print n * n * r * r
    for _ in xrange(n/2): 
        print r, 0
        print -r, 0