#include <iostream>
#include<bits/stdc++.h>
using namespace std;
void printPattern(int n) {
int num = 1;
vector<vector<int>>matrix(n,vector<int>(n,0));
int i=n-1,j=0;
bool check=false;
if(n%2==1)check=true;
int limit=n*(n+1)/2;
while(true){
matrix[i][j]=num++;
if(num>limit)break;
if(!check){
if(i==n-1){
j++;
check=true;
}else{
i++;
j++;
}
}else{
if(j==0){
i--;
check=false;
}else{
i--;
j--;
}
}
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(matrix[i][j]==0)cout<<" "<<"\t";
else cout<<matrix[i][j]<<"\t";
}
cout<<endl;
}
}
int main() {
int n;
cout << "Enter the value of n: ";
cin >> n;
printPattern(n);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZTxiaXRzL3N0ZGMrKy5oPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdm9pZCBwcmludFBhdHRlcm4oaW50IG4pIHsKICAgIGludCBudW0gPSAxOwogICAgdmVjdG9yPHZlY3RvcjxpbnQ+Pm1hdHJpeChuLHZlY3RvcjxpbnQ+KG4sMCkpOwogICAgaW50IGk9bi0xLGo9MDsKICAgIGJvb2wgY2hlY2s9ZmFsc2U7CiAgICBpZihuJTI9PTEpY2hlY2s9dHJ1ZTsKICAgIGludCBsaW1pdD1uKihuKzEpLzI7CiAgICB3aGlsZSh0cnVlKXsKICAgICAgICAKICAgICAgICBtYXRyaXhbaV1bal09bnVtKys7CiAgICAgICAgaWYobnVtPmxpbWl0KWJyZWFrOwogICAgICAgIGlmKCFjaGVjayl7CiAgICAgICAgICAgIGlmKGk9PW4tMSl7CiAgICAgICAgICAgICAgICBqKys7CiAgICAgICAgICAgICAgICBjaGVjaz10cnVlOwogICAgICAgICAgICB9ZWxzZXsKICAgICAgICAgICAgICAgIGkrKzsKICAgICAgICAgICAgICAgIGorKzsKICAgICAgICAgICAgfQogICAgICAgIH1lbHNlewogICAgICAgICAgICBpZihqPT0wKXsKICAgICAgICAgICAgICAgIGktLTsKICAgICAgICAgICAgICAgIGNoZWNrPWZhbHNlOwogICAgICAgICAgICB9ZWxzZXsKICAgICAgICAgICAgICAgIGktLTsKICAgICAgICAgICAgICAgIGotLTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KICAgIAogICAgZm9yKGludCBpPTA7aTxuO2krKyl7CiAgICAgICAgIGZvcihpbnQgaj0wO2o8bjtqKyspewogICAgICAgICAgICBpZihtYXRyaXhbaV1bal09PTApY291dDw8IiAiPDwiXHQiOwogICAgICAgICAgICBlbHNlIGNvdXQ8PG1hdHJpeFtpXVtqXTw8Ilx0IjsKICAgICAgICAgfQogICAgICAgICBjb3V0PDxlbmRsOwogICAgfQp9CgoKaW50IG1haW4oKSB7CiAgICBpbnQgbjsKICAgIGNvdXQgPDwgIkVudGVyIHRoZSB2YWx1ZSBvZiBuOiAiOwogICAgY2luID4+IG47CiAgICAKICAgIHByaW50UGF0dGVybihuKTsKICAgIAogICAgcmV0dXJuIDA7Cn0=