https://www.acmicpc.net/problem/1913
import java.io.*;
import java.util.*;
public class Main {
public static void main(String args[]) throws IOException, NoSuchElementException {
Scanner s=new Scanner(System.in);
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int n=s.nextInt();
int m=s.nextInt();
int num=n*n;
int t=0;
int r=n;
int arr[][]=new int[n][n];
int x=0,y=0;
while(num>0){
x=t;
y=t;
for(int i=y;i<r;i++){
arr[i][x]=num--;
}
y=r-1;
for(int i=x+1;i<r;i++){
arr[y][i]=num--;
}
x=r-1;
for(int i=y-1;i>=t;i--){
arr[i][x]=num--;
}
y=t;
for(int i=x-1;i>t;i--){
arr[y][i]=num--;
}
t++;
r--;
}
int q=0;
int w=0;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(arr[i][j]==m){
q=i+1;
w=j+1;
}
bw.write(arr[i][j] + " ");
}
bw.newLine();
}
bw.write(q + " " + w);
bw.flush();
}
}