#include <iostream> #include <limits.h> #include <cmath> #include <string> #include <stdio.h> #include <algorithm> #include <stdlib.h> #include <vector> #include <stack> #include <map> #include <fstream> #include <list> #include <queue> #include <iomanip> #include <deque> #include <set> using namespace std; #define pb push_back #define mp make_pair //ifstream f("b.txt"); //#define cin f int a[1001][1001]; vector<int> q; #define pb push_back int main() { int n,m; cin >> n >> m; for(int i = 1; i <=n; i++) for(int j = 1; j <=m; j++) cin>>a[i][j]; for (int i = 1; i <= (n/2)+(n%2); i++) { for (int j = i; j <= m-i+1; j++) q.pb(a[i][j]); for (int j = 1+i; j <= n-i+1; j++) q.pb(a[j][m-i+1]); for (int j = m-i; j >= i; j--) q.pb(a[n-1+1][j]); for (int j = n-i; j >= i+1; j--) q.pb(a[j][i]); } for(int i = 0; i < q.size(); i++) { cout<<q[i]; if(i+1 != q.size()) cout<<" "; } }