/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
#include <stdio.h>
void spiral(int n, int m,int arr[n][m]){
int row=0,col=0;
while(row<n && col<m){
for(int j=col; j<m; j++){
printf("%d ",arr[row][j]);
}
for(int i=row+1; i<n; i++){
printf("%d ",arr[i][m-1]);
}
for(int j=m-2; j>=col; j--){
printf("%d ",arr[n-1][j]);
}
row++;
m--;
for(int i=n-2;i>=row; i--){
printf("%d ",arr[i][col]);
}
col++;
n--;
}}
int main()
{
int n=4,m=5;
int arr[n][m];
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
scanf("%d",&arr[i][j]);
}
}
spiral(n,m,arr);
return 0;
}