People do many crazy things to stand out in a crowd. Some of them dance, some learn by heart rules of Russian language, some try to become an outstanding competitive programmers, while others collect funny math objects.

Alis is among these collectors. Right now she wants to get one of k-special tables. In case you forget, the table n × n is called k-special if the following three conditions are satisfied:  every integer from 1 to n^2 appears in the table exactly once;  in each row numbers are situated in increasing order;  the sum of numbers in the k-th column is maximum possible. 

Your goal is to help Alice and find at least one k-special table of size n × n. Both rows and columns are numbered from 1 to n, with rows numbered from top to bottom and columns numbered from left to right.


-----Input-----

The first line of the input contains two integers n and k (1 ≤ n ≤ 500, 1 ≤ k ≤ n) — the size of the table Alice is looking for and the column that should have maximum possible sum.


-----Output-----

First print the sum of the integers in the k-th column of the required table.

Next n lines should contain the description of the table itself: first line should contains n elements of the first row, second line should contain n elements of the second row and so on.

If there are multiple suitable table, you are allowed to print any.


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

Output
28
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16

Input
5 3

Output
85
5 6 17 18 19
9 10 23 24 25
7 8 20 21 22
3 4 14 15 16
1 2 11 12 13

Difficulty: interview

Starter code:

Solutions:
n, k = map(int, input().split())
ans = [[0 for i in range(n)]for j in range(n)]
cur = 1
sum_k = 0
for i in range(n):
    for j in range(k-1):
        ans[i][j] = cur
        cur += 1
for i in range(n):
    for j in range(k-1, n):
        ans[i][j] = cur
        cur += 1
for i in range(n):
    sum_k += ans[i][k-1]
print(sum_k)
for i in range(n):
    for j in range(n):
        print(ans[i][j], end = ' ')
    print('')

        
        


n, k = map(int, input().split())
k -= 1
answer = [[0] * n for i in range(n)]
cur = 1
for i in range(n):
    for j in range(k):
        answer[i][j] = cur
        cur += 1
for i in range(n):
    for j in range(k, n):
        answer[i][j] = cur
        cur += 1
summa = 0
for i in range(n):
    summa += answer[i][k]
print(summa)
for i in range(n):
    print(*answer[i])

#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2016 missingdays <missingdays@missingdays>
#
# Distributed under terms of the MIT license.

"""

"""

def read_list():
    return [int(i) for i in input().split()]
def new_list(n):
    return [0 for i in range(n)]
def new_matrix(n, m=0):
    return [[0 for i in range(m)] for i in range(n)]

n, k = read_list()

a = new_matrix(n, n)

cmi = 1
cma = n**2

for i in range(n):

    for j in range(k-1):
        a[i][j] = cmi
        cmi += 1
    for j in range(n-1, k-2, -1):
        a[i][j] = cma
        cma -= 1
s = 0
for i in range(n):
    s += a[i][k-1]

print(s)

for i in range(n):
    for j in range(n):
        print(a[i][j], end=" ")
    print()
    


n, k = map(int, input().split())
matrix = [[0 for i in range(n)] for j in range(n)]
cur_number = 1
for i in range(n):
    for j in range(k - 1):
        matrix[i][j] = cur_number
        cur_number += 1
for i in range(n):
    for j in range(k - 1, n):
        matrix[i][j] = cur_number
        cur_number += 1
s = 0
for i in range(n):
    s += matrix[i][k - 1]
print(s)
for i in range(n):
    print(' '.join(map(str, matrix[i])))

n, k = [int(x) for x in input().split()]
M1 = [[i + n*j for j in range(k-1)] for i in range(1, n+1)]
M2 = [[(k-1)*n + i*(n-k+1) + j for j in range(1, n-k+2)] for i in range(0, n)]
M = [M1[i] + M2[i] for i in range(n)]
print((n-k+1)*(n-1)*n // 2 + ((k-1)*n + 1)*n)
for i in range(n):
    for j in range(n):
        print(M[i][j], end = ' ')
    print()


3

n,k = [int(i) for i in input().split()]

total_sum = n*n-(n-k)
for row in range(1,n):
	row_right = n*n - (row)*(n-k+1)
	val = row_right - (n-k)
	total_sum += val

print(total_sum)

next_l_num = 1

for row in range(1,n+1):
	row_right = n*n - (row-1)*(n-k+1)
	next_r_num = row_right - (n-k)
	for col in range(1,n+1):
		if col < k:
			print(next_l_num, end=' ')
			next_l_num += 1
		else:
			print(next_r_num, end=' ')
			next_r_num += 1

	print()



# strs = [input() for _ in range(3)]

def main():
	n, k = map(int, input().split())

	left = k - 1
	right = n - k + 1
	lcntr = 1
	rcntr = left * n + 1
	s = 0
	ls = []
	for i in range(n):
		ll = [str(c) for c in range(lcntr, lcntr + left)]
		rl = [str(c) for c in range(rcntr, rcntr + right)]
		lcntr += left
		rcntr += right
		tl = ll + rl
		s += int(tl[left])
		ls.append(' '.join(tl))

	print(s)
	print('\n'.join(ls))

main()

n, k = list(map(int, input().split()))
arr = [[0 for i in range(n)] for j in range(n)]
c = n * n
s = 0
for i in range(n):
    #arr[i][n - 1] = c
    #c -= 1
    for j in range(n - 1, k - 2, -1):
        arr[i][j] = c
        c -= 1
    s += c + 1
for i in range(n):
    for j in range(k - 2, -1, -1):
        arr[i][j] = c
        c -= 1
print(s)
for i in arr:
    print(*i)


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

sol = [[0] * n for _ in range(n)]

res = 0
c = 1
for j in range(k - 1):
    for i in range(n):
        sol[i][j] = c
        c += 1

for i in range(n):
    for j in range(k - 1, n):
        sol[i][j] = c
        c += 1

for i in range(n):
    res += sol[i][k - 1]

print(res)
for line in sol:
    for col in line:
        print(col, end=" ")
    print()


n, k = map(int, input().split())
a = n * (k - 1) + 1
sm = n * (2 * a + (n - 1) * (n - k + 1)) // 2
t = [ [0] * n for i in range(n) ]
x = 1
for j in range(k-1):
    for i in range(n):
        t[i][j] = x
        x += 1
for i in range(n):
    for j in range(k-1, n):
        t[i][j] = x
        x += 1
print(sm)
for row in t:
    print(" ".join(map(str, row)))

N, k = map(int, input().split())
a = [ [0] * (N + 1) for i in range(N + 1) ]
x = N * (k - 1) + 1
S = 0
for i in range(1, N + 1):
    S += x
    a[i][k] = x
    x += 1
    for j in range(k + 1, N + 1):
        a[i][j] = x
        x += 1
x = 1
for i in range(1, N + 1):
    for j in range(1, k):
        a[i][j] = x
        x += 1
print(S)
for i in range(1, N + 1):
    print(*a[i][1:])

n, k = map(int, input().split())
print(int((((n * (k - 1) + 1)) + ((n - 1) * (n - k + 1)) / 2) * n))
for i in range(n):
    curr = []
    for j in range(n):
        if j + 1 == k:
            curr.append((n * (k - 1) + 1) + i * (n - k + 1))
        elif j + 1 > k:
            curr.append((n * (k - 1) + 1) + i * (n - k + 1) + (j + 1 - k))
        else:
            curr.append(i * (k - 1) + j + 1)
    print(' '.join(map(str, curr)))

def main():
    n, k = [int(t) for t in input().split()]

    grid = [[-1] * n for _ in range(n)]

    current = n * n

    for row in range(n):
        for column in range(n - 1, k - 2, -1):
            grid[row][column] = current
            current -= 1

    for row in range(n):
        for column in range(k - 2, -1, -1):
            grid[row][column] = current
            current -= 1

    s = sum(grid[row][k - 1] for row in range(n))
    print(s)
    for row in range(n):
        print(' '.join(str(grid[row][column]) for column in range(n)))


def __starting_point():
    main()

__starting_point()

n, k = list(map(int, input().split()))
g = [[0 for _ in range(n)] for _ in range(n)]
x = 1
for i in range(n):
    for j in range(k-1):
        g[i][j] = x
        x += 1
for i in range(n):
    for j in range(k-1, n):
        g[i][j] = x
        x += 1
ret = 0
for i in range(n):
    ret += g[i][k-1]
print(ret)
print("\n".join([" ".join(map(str, x)) for x in g]))


sLine = input()
sSplit = sLine.split()
n = int(sSplit[0])
k = int(sSplit[1])
v = []
for i in range(n) :
	v.append([])
	for j in range(n) :
		v[i].append(0)
x1 = n * n
x2 = 1
for i in range(n) :
	for j in range(n-1, (k-1)-1, -1) :
		v[i][j] = x1
		x1 -= 1
	for j in range(0, (k-1), 1) :
		v[i][j] = x2
		x2 += 1
nSum = 0
for i in range(n) :
	nSum += v[i][k-1]
print(nSum)
for i in range(n) :
	for j in range(n) :
		print(v[i][j], end='')
		if j == n - 1 :
			print('')
		else :
			print(' ', end='')


n, k = (int(x) for x in input().split())
summ = 0
data = []
for i in range(1, n+1):
	last = n**2-(n-k)*i -i+1
	data.append(last)
	summ += last
print(summ)
for i in range(1,n+1):
	t = list(range(last - k+1, last))
	value = [0]*n
	for j in range(1, n+1):
		if (j < k):
			value[j-1] = str((t[j-1]))
		elif (j == k):
			value[j-1] = str(data[i-1])
		else:
			value[j-1] = str(data[i-1] +j-k)
	last-=k-1
	print(' '.join(value))

n,m=map(int,input().split())
a=[[0]*n for _ in range(n)]
for i in range(n*n):
	if i<(m-1)*n:
		a[i//(m-1)][i%(m-1)]=i+1
	else:
		a[(i-(m-1)*n)//(n-m+1)][(i-(m-1)*n)%(n-m+1)+m-1]=i+1
r=0
for j in range(n):
	r+=a[j][m-1]
print(r)
for i in range(n):
	for j in range(n):
		print(a[i][j],end=' ')
	print()

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

cisel_vlavo = n * (k-1)
prve_v_k = cisel_vlavo + 1
prve_vlavo = 1

riadok_vpravo = n - k + 1
cislo = prve_v_k
su = 0
for _ in range(n):
    su += cislo
    cislo += riadok_vpravo
print(su)

for r in range(n):
    space = False
    for c in range(1, n+1):
        if space:
            print(" ", end="")
        else:
            space = True
        if c < k:
            print(prve_vlavo, end="")
            prve_vlavo += 1
        else:
            print(prve_v_k, end="")
            prve_v_k += 1
        
    print()

# You lost the game.

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

T = ["" for _ in range(n)]

t = 0
r = 0
for i in range(n):
    for j in range(k-1):
        t += 1
        T[i] += str(t) + " "
for i in range(n):
    r += t+1
    for j in range(k-1,n):
        t += 1
        T[i] += str(t) + " "
print(r)
for i in range(n):
    print(T[i][:(len(T[i])-1)])




import collections
import math

def is_prime(x): 
    for i in range(2, math.ceil(math.sqrt(x))):
        if x % i == 0:
            return False
    return True

n, k = map(int, input().split())
T = [[0] * n for _ in range(n)]
ans = 0
s = n * n
for i in range(n):
    for j in range(n - k + 1):
        T[i][n - j - 1] = s
        s -= 1
a = 1
for i in range(n):
    for j in range(k - 1):
        T[i][j] = a
        a += 1
for i in range(n):
    ans += T[i][k - 1]
print(ans)
for i in range(n):
    print(' '.join(map(str, T[i])))

n, k = map(int, input().split())
data = [[None for i in range(n)] for j in range(n)]
data[0][k - 1] = n ** 2 - n + k
help = 0
answer = data[0][k - 1]
for i in range(1, n):
    data[i][k - 1] = data[i - 1][k - 1] - (n - k + 1)
    answer += data[i][k - 1]
for i in range(n - 1, -1, -1):
    for j in range(k, n):
        data[i][j] = data[i][j - 1] + 1
for i in range(n - 1, -1, -1):
    for j in range(k - 1):
        data[i][j] = help + 1
        help += 1
print(answer)
for i in range(n):
    print(*data[i])

inp = input()
inp = inp.split()
n = int(inp[0])
k = int(inp[1])-1

ans = 0
count=1
table = [[0] * n for i in range(n)]

for i in range(k):
    for j in range(n):
        table[j][i]=count
        count = count + 1

for i in range(n):
    for j in range(k,n):
        table[i][j]=count
        count = count + 1

for i in range(n):
    ans = ans + table[i][k]

print (ans)

for i in table:
    for j in i:
        print (j, end=' ')
    print ()

n,k=map(int,input().split())
a=[]
for i in range(n):
    a.append([])
    for j in range(n):
        a[i].append(0)
m=n**2
for j in range(n):
    for i in range(n-k+1):
        a[j][n-i-1]=m-i
    m-=n-k+1
c=n*k-n
while c>0:
    a[(c-1)%n][(c-1)//n]=m
    c-=1
    m-=1
s=0
for i in range(n):
    s+=a[i][k-1]
print(s)
for i in range(n):
    for j in range(n-1):
        print(a[i][j],end=' ')
    print(a[i][n-1])

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

a = [[0 for x in range(n)] for x in range(n)]
cur = n*n
for i in range(0,n):
    for j in range(n-1,k-2,-1):
        a[i][j] = cur
        cur -= 1

for i in range(0,n):
    for j in range(k-2,-1,-1):
        a[i][j] = cur
        cur -= 1

total = 0
for i in range(0,n):
    total += a[i][k-1]

print(total)
for i in range(0,n):
    for j in range(0,n):
        print(a[i][j], end=" ")
    print()