Dreamoon likes to play with sets, integers and $gcd$. $\operatorname{gcd}(a, b)$ is defined as the largest positive integer that divides both a and b.

Let S be a set of exactly four distinct integers greater than 0. Define S to be of rank k if and only if for all pairs of distinct elements s_{i}, s_{j} from S, $\operatorname{gcd}(s_{i}, s_{j}) = k$.

Given k and n, Dreamoon wants to make up n sets of rank k using integers from 1 to m such that no integer is used in two different sets (of course you can leave some integers without use). Calculate the minimum m that makes it possible and print one possible solution.


-----Input-----

The single line of the input contains two space separated integers n, k (1 ≤ n ≤ 10 000, 1 ≤ k ≤ 100).


-----Output-----

On the first line print a single integer — the minimal possible m. 

On each of the next n lines print four space separated integers representing the i-th set.

Neither the order of the sets nor the order of integers within a set is important. If there are multiple possible solutions with minimal m, print any one of them.


-----Examples-----
Input
1 1

Output
5
1 2 3 5

Input
2 2

Output
22
2 4 6 22
14 18 10 16



-----Note-----

For the first example it's easy to see that set {1, 2, 3, 4} isn't a valid set of rank 1 since $\operatorname{gcd}(2,4) = 2 \neq 1$.

Difficulty: interview

Starter code:

Solutions:
'''
Created on Oct 12, 2014

@author: Ismael
'''
#import time

from fractions import gcd

def checkSet(setK,newVal):
    for v in setK:
        if(gcd(v,newVal) != 1):
            return False
    return True

def solve(n,k):
    j = 1
    sets = []
    for _ in range(n):
        setK = set()
        while(len(setK) < 4):
            if(checkSet(setK,j) and not(len(setK) == 0 and j%3==0)):
                setK.add(j)
            j += 1
        sets.append(setK)
    maxV = 0
    for setK in sets:
        maxV = max(maxV,max(setK))
    print(maxV*k)
    for setK in sets:
        print(' '.join([str(x*k) for x in setK]))
    
#t = time.clock()
n,k = list(map(int,input().split()))
solve(n,k)
#print(time.clock()-t)


k = 0
i = 1
a = []
while k <10000:
	b = []
	b.append(i)
	b.append(i+1)
	b.append(i+2)
	b.append(i+4)
	i += 6
	a.append(b)
	k += 1
n, k = tuple(map(int, input().split()))
print(a[n-1][3]*k)
for i in range(0, n):
	print(a[i][0]*k, a[i][1]*k, a[i][2]*k, a[i][3]*k)

'''
Created on Oct 12, 2014

@author: Ismael
'''
#import time

from fractions import gcd

def checkSet(setK,newVal):
    for v in setK:
        if(gcd(v,newVal) != 1):
            return False
    return True

def solve(n,k):
    j = 1
    sets = []
    for _ in range(n):
        setK = set()
        while(len(setK) < 4):
            if(checkSet(setK,j) and not(len(setK) == 0 and j%3==0)):
                setK.add(j)
            j += 1
        sets.append(setK)
    maxV = 0
    for setK in sets:
        maxV = max(maxV,max(setK))
    print(maxV*k)
    for setK in sets:
        print(' '.join([str(x*k) for x in setK]))
    
#t = time.clock()
n,k = list(map(int,input().split()))
solve(n,k)
#print(time.clock()-t)


load = [int(i) for i in input().split()]
n = load[0]
k = load[1]
print(k * (6 * n - 1))
for i in range(1, n + 1):
    buff = ""
    buff += str(k * (6 * i - 5)) + ' '
    buff += str(k * (6 * i - 3)) + ' '
    buff += str(k * (6 * i - 2)) + ' '
    buff += str(k * (6 * i - 1)) + ' '
    print(buff)


a, b = list(map(int, input().split(' ')))
print((6*a-1)*b)
for i in range(a):
    print((6*i+1)*b, (6*i+2)*b, (6*i+3)*b, (6*i+5)*b)


#input
n,k=map(int,input().split())

#variables

#main
print((6*n-1)*k)

for i in range(n):
	print(str((6*i+1)*k)+' '+str((6*i+2)*k)+' '+str((6*i+3)*k)+' '+str((6*i+5)*k))

n, k = map(int, input().split())
print(k * (2 * (3 * n) - 1))
now = 1
m = 2
for i in range(n):
	print(k * m, end = ' ')
	for j in range(3):
		print(k * now, end = ' ')
		now += 2
	m += 6
	print()

n, k = list(map(int, input().split()))

print((6*n-1)*k)

print(("\n".join(
   "%i %i %i %i" % tuple(k*(6*i+j) for j in (1,2,3,5)) for i in range(n)
)))


n, k = map(int, input().split())
print(k * (2 * (3 * n) - 1))
now = 1
m = 2
for i in range(n):
    print(k * m, end = ' ')
    for j in range(3):
        print(k * now, end = ' ')
        now += 2
    m += 6
    print()

n, k = list(map(int, input().split()))
print((n * 6 - 1) * k)
for i in range(n):
    m = i * 6
    print((m + 1) * k, (m + 2) * k, (m + 3) * k, (m + 5) * k)    


n, k = map(int, input().split())
print((6 * n - 1) * k)
for i in range(1, 6 * n, 6): print(i * k, (i + 2) * k, (i + 3) * k, (i + 4) * k)

n, k = map(int, input().split())
m = 6 * n - 1
print(m * k)
for i in range(n):
    for j in [1, 2, 3, 5]:
        print(k * (6 * i + j), end = ' ')
    print()


import sys

def solve():
    n, k, = rv()
    res = list()
    cur = 1
    for i in range(n):
        while cur % 2 == 0: cur+=1
        res.append(((cur) * k, (cur + 1) * k, (cur + 2) * k, (cur + 4) * k))
        cur += 5
    print(res[-1][-1])
    print('\n'.join((' '.join(map(str, l))) for l in res))

#12 14 16 20
# 2 * 2 * 3   2 * 7   2 * 2 * 2 * 2   2 * 3 * 3
# 1 2 3 5
# 7 8 9 11
# 13
# 19
# 25
# 31

def prt(l): return print(' '.join(l))
def rv(): return map(int, input().split())
def rl(n): return [list(map(int, input().split())) for _ in range(n)]
if sys.hexversion == 50594544 : sys.stdin = open("test.txt")
solve()




import sys

def solve():
    n, k, = rv()
    res = list()
    cur = 1
    for i in range(n):
        while cur % 2 == 0: cur+=1
        res.append(((cur) * k, (cur + 1) * k, (cur + 2) * k, (cur + 4) * k))
        cur += 5
    print(res[-1][-1])
    print('\n'.join((' '.join(map(str, l))) for l in res))

#12 14 16 20
# 2 * 2 * 3   2 * 7   2 * 2 * 2 * 2   2 * 3 * 3
# 1 2 3 5
# 7 8 9 11
# 13
# 19
# 25
# 31

def prt(l): return print(' '.join(l))
def rv(): return map(int, input().split())
def rl(n): return [list(map(int, input().split())) for _ in range(n)]
if sys.hexversion == 50594544 : sys.stdin = open("test.txt")
solve()




n, k = list(map(int,input().split()))
print((6*n-1)*k)
for i in range(0, n): print((6*i+1)*k,(6*i+2)*k,(6*i+3)*k,(6*i+5)*k)

n, k = map(int, input().split())
print(k * (6 * (n - 1) + 5))
for i in range(0, n): print(k * (6 * i + 1), k * (6 * i + 2), k * (6 * i + 3), k * (6 * i + 5))

l = input().split(" ")
n = int(l[0])
k = int(l[1])
print((6*n-1)*k)
for i in range(n):
    print(str((6*i+1)*k)+" "+str((6*i+2)*k)+" "+str((6*i+3)*k)+" "+str((6*i+5)*k))

n, k = list(map(int, input().split()))
print(k * (6 * (n - 1) + 5))
for i in range(0, n):
    t = [6 * i + 1, 6 * i + 2, 6 * i + 3, 6 * i + 5]
    print((' '.join([str(m * k) for m in t])));



n, k = map(int, input().split())
print(k*(6*n-1))
for i in range (n):
    print(k*(6*i+1), k * (6*i+3), k*(6*i+4), k * (6*i+5))

x, y = map(int, input().split())
z = []
print((6 * x - 1) * y)
for i in range(0, x):
    z.append((6 * i + 1) * y); z.append((6 * i + 3) * y); z.append((6 * i + 4) * y); z.append((6 * i + 5) * y)
    print(*z)
    z.clear()

inp = input().split(' ')
def result(sets,maximum_divisor):
    output = list()
    output.append(str(int(maximum_divisor) * (6 * int(sets) - 1)))
    for i in range(int(sets)):
        output.append(str(int(maximum_divisor)* (6 * int(i) + 1)) + ' ' + str(int(maximum_divisor) * (6 * int(i) + 3)) + ' ' + str(int(maximum_divisor) * (6 * int(i) + 4)) + ' ' + str(int(maximum_divisor) * (6 * int(i) + 5)))
    return output
for i in result(inp[0],inp[1]):
    print(i)


n,k = [int(i) for i in input().split()]
print((6*n-1)*k)
for a in range(n):
    val = 6*a
    print((val+1)*k,(val+2)*k,(val+3)*k,(val+5)*k)


n, k = [int(x) for x in input().split()]
print(k*((n-1)*6+5))
for i in range(n):
    print(k*(6*i+1),k*(6*i+3),k*(6*i+5),k*(6*i+2))

n, k = map(int, input().split())
print(k * (6 * n - 1))
for i in range(1, n + 1):
    x = (i - 1) * 6 + 1
    print(k * x, end = ' ')
    print(k * (x + 1), end = ' ')
    print(k * (x + 2), end = ' ')
    print(k * (x + 4))