https://www.acmicpc.net/problem/1913
n=int(input())
m=int(input())
num=n*n
t=0
r=n
arr=[[0]*n for _ in range(n)]
x=0
y=0
while num>0:
x=t
y=t
for i in range(y,r):
arr[i][x]=num
num-=1
y=r-1
for i in range(x+1,r):
arr[y][i]=num
num-=1
x=r-1
for i in range(y-1,t-1,-1):
arr[i][x]=num
num-=1
y=t
for i in range(x-1,t,-1):
arr[y][i]=num
num-=1
t+=1
r-=1
q=0
w=0
for i in range(n):
for j in range(n):
if arr[i][j]==m:
q=i+1
w=j+1
print(arr[i][j], end=' ')
print()
print("%d %d"%(q,w))