Problem:
Rotating Photo
PCK is developing an application for processing photos by rotating them. In this application, a square photo is input, and then the photo is rotated by several rotation commands, each of which rotates the photo 90 degrees clockwise or counterclockwise around a point in the middle of the photo (the intersection of the diagonals of the square).
Given a photo and a rotation instruction, write a program that draws the photo after processing all the instructions. The photo consists of $N \times N$ pixels, and the information of one pixel is represented by a single letter.
Input
The input is given in the following format.
$N$
$row_1$
$row_2$
:
$row_N$
$Q$
$r_1$
$r_2$
:
$r_Q$
The first line gives the number of pixels in the photo $N$ ($1 \leq N \leq 1,000$), in both height and width. In the following $N$ lines, the pixel information $row_i$ of the $i$-th row from the top is given, where $row_i$ is a string of length $N$ consisting of letters. The next line gives the number of rotation instructions $Q$ ($1 \leq Q \leq 200,000$). In the following line $Q$, an integer $r_i$ (-1 or 1) is given to indicate the direction of rotation; a value of $r_i$ of 1 means clockwise rotation, and a value of -1 means counterclockwise rotation by 90 degrees.
Output
Output the pixel information of the photo after processing all the rotation commands in $N$ lines. The pixel information of the $i$-th row from the top is output to the $i$-th row.
Sample Input and Output
Sample Input 1
2
AI
ZU
2
1
1
Sample Output 1
UZ
IA
Sample Input 2
3
xOO
OOy
OOO
1
-1
Sample Output 2
OyO
OOO
xOO

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(a) a.begin(), a.end()

vector<string> rotate(vector<string> s)
{
    int n = s.size();
    vector<vector<char>> res(s.size(), vector<char>(s.size()));
    rep(i, n)
    {
        rep(j, n)
        {
            res[j][n - i - 1] = s[i][j];
        }
    }
    vector<string> p;
    for (auto x : res)
    {
        string q;
        for (auto y : x)
        {
            q += y;
        }
        p.push_back(q);
    }
    return p;
}

int main()
{
    ll n;
    cin >> n;
    vector<string> s(n);
    rep(i, n) cin >> s[i];
    ll q;
    cin >> q;
    ll md = 0;
    rep(i, q)
    {
        int x;
        cin >> x;
        md += x;
    }
    md %= 4;
    md += 100;
    md %= 4;
    rep(i, md)
    {
        s = rotate(s);
    }
    for (auto x : s)
    {
        cout << x << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 8320
final_rank: 13

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef double dou;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
struct four_ll_pair{ll ff,fs,sf,ss;};
typedef pair<char,ll> pcl;
struct three_pcl_pair{pcl l,c,r;};
typedef string str;
typedef vector<str> vstr;
typedef map<ll,ll> mll;
typedef priority_queue<ll> maxpq;
typedef priority_queue<ll,vll,greater<ll>> minpq;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define f0r(i,b) for(ll i=0;i<b;i++)
#define SORT(a) sort(a.begin(),a.end());
#define llin(a,n) f0r(i,n) {cin>>a[i];}
#define REVERSE(a) reverse(a.begin(),a.end());
const ll llmax=9223372036854775783LL;
const ll mod=998244353LL;
const ll MOD=1000000007LL;
str ALP="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
str alp="abcdefghijklmnopqrstuvwxyz";
void Yn(bool b) {cout<<(b?"Yes":"No")<<endl;}
void YN(bool b) {cout<<(b?"YES":"NO")<<endl;}
vll Remove_duplicates(vll a){
    a.erase(unique(a.begin(),a.end()),a.end());
    return a;
}
vll coordinate_compression(vll v){
    ll n=v.size();
    vll b=v;SORT(b);
    b=Remove_duplicates(b);
    vll ans(n);
    f0r(i,n){
        ll pos=lower_bound(b.begin(),b.end(),v[i])-b.begin();
        ans[i]=pos+1;
    }
    return ans;
}
namespace mod_calc{
    ll mod_pow(ll base,ll a,ll m){
        ll result=1;
        while(a>0){
            if (a%2==1) result=(result*base)%m;
            base=(base*base)%m;
            a>>=1;
        }
        return result;
    }
    ll mod_divide(ll a,ll b,ll m){
        return a*mod_pow(b,m-2,m)%m;
    }
    ll mod_fraction(ll n,ll a,ll b,ll m){
        return mod_divide((n*a%m),b,m);
    }
    ll mod_com(ll a,ll b,ll m){
        ll ans=1;
        if (a<b) return 0;
        if (a==b) return 1;
        for(ll i=0;i<b;i++) ans=mod_fraction(ans,a-i,1+i,m);
        return ans;
    }
}
struct Cumulative_Sum_2D{
    vvll data;
    Cumulative_Sum_2D(ll W,ll H):data(W+1,vll(H+1,0)){}
    void input(ll x,ll y,ll z){
        x++;y++;
        data[x][y]=z;
    }
    void build(){
        FOR(i,1,data.size()) FOR(j,1,data[i].size()) data[i][j]=data[i][j-1]+data[i-1][j]-data[i-1][j-1];
    }
    ll query(ll sx,ll sy,ll gx,ll gy){
        return(data[gx][gy]-data[sx][gy]-data[gx][sy]+data[sx][sy]);
    }
};
struct unionfind{
    vll parent,ver_size;
    unionfind(ll n):parent(n),ver_size(n,1){
        iota(parent.begin(),parent.end(),0); 
    }
    ll find(ll node,vll&parent){
        vll path;
        while(parent[node]!=node){
            path.push_back(node);
            node=parent[node];
        }
        for(ll u:path) parent[u]=node;
        return node;
    }
    void unionSets(ll u,ll w,vll&ver_size,vll&parent){
        ll rootU=find(u,parent),rootW=find(w,parent);
        if(rootU!=rootW){
            if(ver_size[rootU]<ver_size[rootW]){
                parent[rootU]=rootW;
                ver_size[rootW]+=ver_size[rootU];
            }else{
                parent[rootW]=rootU;
                ver_size[rootU]+=ver_size[rootW];
            }
        }
    }
};
namespace divisor_calc{
    ll gcd(ll a,ll b){
        while(b!=0){
            ll tmp=a%b;
            a=b;
            b=tmp;
        }
        return a;
    }
    ll lcm(ll a,ll b){
        return a*b/gcd(a,b);
    }
    vll factorizations_vll(ll n){
        ll mema=n;
        vll ftz_ans;
        for(ll i=2;i*i<=mema;i++){
            while(mema%i==0){
                mema/=i;
                ftz_ans.push_back(i);
            }
        }
        if(mema!=1) ftz_ans.push_back(mema);
        return ftz_ans;
    }
    mll factorizations_mll(ll n){
        ll mema=n;
        mll ftz_ans;
        for(ll i=2;i*i<=mema;i++){
            while(mema%i==0){
                mema/=i;
                ftz_ans[i]++;
            }
        }
        if(mema!=1) ftz_ans[mema]++;
        return ftz_ans;
    }
}
namespace all_distances{
    dou euclidean_distance(dou ax,dou ay,dou bx,dou by){
        return sqrt(pow(ax-bx,2)+pow(ay-by,2));
    }
    dou manhattan_distance(dou ax,dou ay,dou bx,dou by){
        return abs(ax-bx)+abs(ay-by);
    }
    dou chebyshev_distance(dou ax,dou ay,dou bx,dou by){
        return max(abs(ax-bx),abs(ay-by));
    }
}
static ll bit_ceil(ll n){
    if(n<=1)return 1;
    ll x=1;
    while(x<n)x<<=1;
    return x;
}
template<class S,S(*op)(S,S),S(*e)()>struct segtree{
    public:
    segtree():segtree(0){}
    explicit segtree(ll n):segtree(vector<S>(n,e())){}
    explicit segtree(const vector<S>& v):_n((ll)v.size()){
        size=(ll)bit_ceil(_n);
        d=vector<S>(2*size,e());
        for(ll i=0;i<_n;i++)d[size+i]=v[i];
        for(ll i=size-1;i>=1;i--)update(i);
    }

    void set(ll p,S x){
        assert(0<=p&&p<_n);
        p+=size;
        d[p]=x;
        for(p>>=1;p>=1;p>>=1)update(p);
    }
    S get(ll p)const{
        assert(0<=p&&p<_n);
        return d[p+size];
    }
    S prod(ll l,ll r)const{
        assert(0<=l&&l<=r&&r<=_n);
        S sml=e(),smr=e();
        l+=size;
        r+=size;
        while(l<r){
            if(l&1)sml=op(sml,d[l++]);
            if(r&1)smr=op(d[--r],smr);
            l>>=1;
            r>>=1;
        }
        return op(sml,smr);
    }
    S all_prod()const{return d[1];}
    private:
    ll _n,size;
    vector<S> d;
    void update(ll k){d[k]=op(d[2*k],d[2*k+1]);}
};
ll sum_op(ll a,ll b){return a+b;}       ll sum_e(){return 0LL;}
ll max_op(ll a,ll b){return max(a,b);}  ll max_e(){return -1LL;}
ll min_op(ll a,ll b){return min(a,b);}  ll min_e(){return llmax;}
ll xor_op(ll a,ll b){return a^b;}  ll xor_e(){return 0LL;}
four_ll_pair second_largest_op(four_ll_pair a,four_ll_pair b){
    ll FF,FS,SF,SS;
    if(a.ff==b.ff){
        FF=a.ff;FS=a.fs+b.fs;
        if(a.sf==b.sf){
            SF=a.sf;SS=a.ss+b.ss;
        }else{
            SF=max(a.sf,b.sf);
            SS=(SF==a.sf?a.ss:b.ss);
        }
    }else{
        FF=max(a.ff,b.ff);FS=(FF==a.ff?a.fs:b.fs);
        if(a.sf==b.sf){
            SF=a.sf;SS=a.ss+b.ss;
        }else{
            SF=max(a.sf,b.sf);SS=(SF==a.sf?a.ss:b.ss);
        }
        if(SF==min(a.ff,b.ff)){
            SS+=(SF==a.ff?a.fs:b.fs);
        }else{
            SF=max(SF,min(a.ff,b.ff));SS=(SF==min(a.ff,b.ff)?(SF==a.ff?a.fs:b.fs):SS);
        }
    }
    return {FF,FS,SF,SS};
} 
four_ll_pair second_largest_e(){return {0,0,0,0};}
three_pcl_pair max_combo_op(three_pcl_pair a,three_pcl_pair b){
    ll Max=max(a.c.second,b.c.second);
    if(a.r.first==b.l.first) Max=max(Max,a.r.second+b.l.second);
    char check=((a.c.first=='T'&&b.c.first=='T')?'T':'F');
    if(a.l.first!=b.l.first) check='F';
    pcl re_l=a.l,re_r=b.r;
    if(re_l.first=='0')re_l=b.l;
    else if(a.c.first=='T'&&a.r.first==b.l.first) re_l.second+=b.l.second;
    if(re_r.first=='0')re_r=a.r;
    else if(b.c.first=='T'&&a.r.first==b.l.first) re_r.second+=a.r.second;
    return {re_l,{check,Max},re_r};
}
three_pcl_pair max_combo_e(){return {{'0',0},{'T',0},{'0',0}};}
ll sum_mod_op(ll a,ll b){return (a+b)%mod;} ll sum_mod_e(){return 0LL;}
vll bfsdis(ll s,vvll graph){
    vll dist(graph.size(),1145141919810);
    queue<ll> q;
    dist[s]=0;
    q.push(s);
    while(!q.empty()){
        ll u=q.front();q.pop();
        for(ll v:graph[u]){
            if (dist[v]==1145141919810) {
                dist[v]=dist[u]+1;
                q.push(v);
            }
        }
    }
    return dist;
}
ll Ackermann_function(ll m,ll n){
    if(m<=1) return n+1+m;
    else if(m==2) return 2*n+3;
    else{
        ll ans=1LL;
        f0r(i,n+3) ans*=2LL;
        return ans-3LL;
    }
}
ll ans=0,k;
vector<vector<char>> s;
vector<vector<bool>> a;
void dfs(ll i,ll j,ll dist){
    a[i][j]=false;
    if(dist==k) {ans++; a[i][j]=true; return;}
    if(s[i][j+1]=='.'&&a[i][j+1]) dfs(i,j+1,dist+1);
    if(s[i][j-1]=='.'&&a[i][j-1]) dfs(i,j-1,dist+1);
    if(s[i+1][j]=='.'&&a[i+1][j]) dfs(i+1,j,dist+1);
    if(s[i-1][j]=='.'&&a[i-1][j]) dfs(i-1,j,dist+1);
    a[i][j]=true;
}
int main(){
    ll n;cin>>n;
    vstr s(n);llin(s,n);
    ll r=0,q;
    cin>>q;
    f0r(i,q){
        ll a;cin>>a;
        r+=a;
    }
    r=(r+1234560)%4;
    if(r==0){
        f0r(i,n) {
            f0r(j,n) cout<<s[i][j];
            cout<<endl;
        }
    }else if(r==3){
        f0r(i,n) {
            f0r(j,n) cout<<s[j][n-i-1];
            cout<<endl;
        }
    }else if(r==2){
        f0r(i,n) {
            f0r(j,n) cout<<s[n-i-1][n-j-1];
            cout<<endl;
        }
    }else if(r==1){
        f0r(i,n) {
            f0r(j,n) cout<<s[n-j-1][i];
            cout<<endl;
        }
    }
}
accuracy: 1
time_ms: 40
memory_kb: 5360
final_rank: 10

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,N) for(int i=0;i<(int)N;i++)
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define pb push_back

int main(){
    int N;cin>>N;
    vector<string>S(N);
    rep(i,N)cin>>S[i];
    int Q;cin>>Q;
    int t = 0;
    rep(i,Q){
        int r;cin>>r;
        t+=r;
        t+=4;
        t%=4;
    }
    rep(ttt,t){
        vector<string>T(N,string(N,'0'));
        rep(i,N)rep(j,N){
            T[j][N-i-1]=S[i][j];
        }
        swap(S,T);
    }
    rep(i,N)cout<<S[i]<<endl;
}
accuracy: 1
time_ms: 30
memory_kb: 5932
final_rank: 7

code_snippet: //#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(a) (a).begin(), (a).end()
using ll = long long;
const ll INF32 = 2e9;
const ll INF64 = 4e18;
#define int long long

void printYN(bool ok){
    if(ok)cout << "Yes" << endl;
    else cout << "No" << endl;
    return;
}

void rorate(int type, vector<string> &P){
    int N = P.size();
    vector<string> res(N);
    if(type==1){
        rep(i, N)rep(j, N){
            res[i].push_back(P[N-j-1][i]);
        }
    }
    else if(type==2){
        rep(i, N)rep(j, N){
            res[i].push_back(P[N-i-1][N-1-j]);
        }
    }
    else if(type==3){
        rep(i, N)rep(j, N){
            res[i].push_back(P[j][N-1-i]);
        }
    } else {
        res = P;
    }
    P = res;
    return;
}

signed main(){
    int N;
    cin >> N;
    vector<string> P(N);
    rep(i, N)cin >> P[i];
    int Q;
    cin >> Q;
    int sum= 0;
    rep(i, Q){
        int type;
        cin >> type;
        sum += type;
    }
    sum += 4*INF32;
    rorate(sum%4, P);
    rep(i, N)cout << P[i] << endl;
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 6992
final_rank: 14

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ld=long double;
#define fi first
#define se second
#define i128 __int128_t
#define all(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define si(a) (long)(a.size())
template<typename T>bool chmin(T&a,T b){return b<a?(a=b,1):0;}
template<typename T>bool chmax(T&a,T b){return b>a?(a=b,1):0;}
const int INF=1e9+100;
const long INFL=3e18+100;
struct _ {
   _() { cin.tie(0)->sync_with_stdio(0), cout.tie(0); }
} __;

int main(){
    int N;
    cin>>N;
    vector<vector<char>> S(N,vector<char>(N));
    rep(i,N)rep(j,N)cin>>S[i][j];
    int Q;
    cin>>Q;
    int k=0;
    while(Q--){
        int a;
        cin>>a;
        k+=(a+4);
        k%=4;
    }
    rep(_,k){
        vector T=S;
        rep(i,N)rep(j,N) S[i][j]=T[N-j-1][i];
    }
    rep(i,N){
        rep(j,N)cout<<S[i][j];
        cout<<"\n";
    }
}
accuracy: 1
time_ms: 20
memory_kb: 5376
final_rank: 4

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main()
{
    int n;
    cin>>n;
    vector<vector<char>> p(n,vector<char>(n));
    for(int i=0;i<n;i++) for(int j=0;j<n;j++) cin>>p[i][j];
    int q;
    cin>>q;
    int rot = 0;
    while(q--)
    {
        int a;
        cin>>a;
        rot += a;
    }
    
    rot %= 4;
    rot += 4;
    rot %= 4;
    
    
    for(int l=0;l<rot;l++)
    {
        auto rotp = p;
        for(int i=0;i<n;i++) for(int j=0;j<n;j++)
        {
            rotp[i][j] = p[n-1-j][i];
        }
        p = rotp;
    }
    
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            cout<<p[i][j];
        }
        cout<<endl;
    }
}
accuracy: 1
time_ms: 50
memory_kb: 5060
final_rank: 17

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define ll long long
const long long mod=998244353;
const long long hmod=46216567629137;

int main(){
    cin.tie(0)->sync_with_stdio(0);
    cout.tie(0);
    int N;
    cin>>N;
    char S[N+1][N+1];
    for(int i=1;i<=N;i++){
        for(int j=1;j<=N;j++) cin>>S[i][j];
    }
    int Q;
    cin>>Q;
    int kaiten=0;
    for(int i=1;i<=Q;i++){
        int r;
        cin>>r;
        kaiten+=r;
    }
    kaiten%=4;
    if(kaiten<0) kaiten+=4;
    for(int z=1;z<=kaiten;z++){
        int nex[N+1][N+1];
        for(int i=1;i<=N;i++){
            for(int j=1;j<=N;j++){
                nex[i][j]=S[N-j+1][i];
            }
        }
        for(int i=1;i<=N;i++){
            for(int j=1;j<=N;j++){
                S[i][j]=nex[i][j];
            }
        }
    }
    for(int i=1;i<=N;i++){
        for(int j=1;j<=N;j++) cout<<S[i][j];
        cout<<endl;
    }
}
accuracy: 1
time_ms: 20
memory_kb: 8224
final_rank: 12

code_snippet: #include<bits/stdc++.h>
//#include<atcoder/all>

using namespace std;
//using namespace atcoder;
#define rep(i,n) for(ll i=0; i<n; i++)
#define rrep(i,n) for(ll i=n-1; i>=0; i--)
#define print(a) cout<<a<<endl
typedef long long ll;
#define yn(flg) if(flg){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YN(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define so(a) sort(a.begin(),a.end())
#define mp make_pair
#define vi vector<int>
#define vl vector<ll>
#define vs vector<string>
#define pb push_back
#define a2i(a,s) (ll)(a-s)
#define i2a(s,a) (char)(s+a)
#define ssize(a) a.size()
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<pair<ll,ll>,ll> P3;
typedef pair<pair<ll,ll>,pair<ll,ll>> P4;

typedef pair<ll, ll> Pll;
typedef pair<ll,Pll> Plll;
typedef pair<Pii, int> Piii;
const ll INF = 1000000000000000000;

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//vector<ll> saiki(ll bit,ll n){
//	vector<ll> s(n);
//	for(ll i=0;i<n;i++){
//		if(bit&(1<<i)){
//			s[i]=1;
//		}else s[i]=0;
//	}
//	return s;
//}


int main(){
//入力

	cin.tie(0);
	ios::sync_with_stdio(0);

	ll n;
	cin>>n;
	vector<string> s(n);
	rep(i,n)cin>>s[i];

//判定
	ll v=0;
	ll q;
	cin>>q;
	rep(i,q){
		ll r;
		cin>>r;
		v+=r;
	}
	v=v%4;

//判定２
	if(v==1||v==-3){
		for(ll j=0;j<n;j++){
			for(ll i=n-1;i>=0;i--){
				cout<<s[i][j];
			}
			cout<<endl;
		}
	}
	if(v==2||v==-2){
		for(ll i=n-1;i>=0;i--){
			for(ll j=n-1;j>=0;j--){
				cout<<s[i][j];
			}
			cout<<endl;
		}
	}
	if(v==3||v==-1){
		for(ll j=n-1;j>=0;j--){
			for(ll i=0;i<n;i++){
				cout<<s[i][j];
			}
			cout<<endl;
		}
	}
	if(v==0){
		rep(i,n){
			rep(j,n){
				cout<<s[i][j];
			}
			cout<<endl;
		}
	}


	return 0;

}
accuracy: 1
time_ms: 20
memory_kb: 4428
final_rank: 1

code_snippet: #include<bits/stdc++.h>
using namespace std;
int main(){
        int n;
        cin >>n;
        string s[n];
        for(int i = 0;i < n;i++)cin >>s[i];
        int q;
        cin >>q;
        int x = 0;
        for(int i = 0,j;i < q;i++){
                cin >>j;
                x += j;
        }
        x%=4;
        if(x < 0){
                x += 4;
        }
        for(int i = 0;i < x;i++){
                string t[n];
                for(int j = 0;j < n;j++)t[j] = s[j];
                for(int j = 0;j < n;j++){
                        for(int k = 0;k < n;k++){
                                s[k][n-1-j] = t[j][k];
                        }
                }
        }
        for(int i = 0;i < n;i++){
                for(int j = 0;j < n;j++){
                        cout <<s[i][j];
                }
                cout <<"\n";
        }
}
accuracy: 1
time_ms: 40
memory_kb: 6292
final_rank: 16

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define oke cout << "Yes" << '\n';
#define dame cout << "No" << '\n';
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using HaiI = vector<vector<int>>;
using Hai2 = vector<vector<ll>>;
using HaiB = vector<vector<bool>>;
using Hai3 = vector<vector<vector<ll>>>;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(15);
	ll N;
	cin>>N;
	vector<string>S(N);
	rep(i,N){
		cin>>S[i];
	}
	ll Q,cut=0;
	cin>>Q;
	rep(i,Q){
		ll a;
		cin>>a;
		cut+=a;
	}
	cut%=4;
	if(cut<0){
		cut+=4;
	}
	rep(to,cut){
		vector<string>B=S;
		rep(i,N){
			rep(j,N){
				S[j][N-i-1]=B[i][j];
			}
		}
	}
	rep(i,N){
		rep(j,N){
			cout<<S[i][j];
		}
		cout<<"\n";
	}
}
accuracy: 1
time_ms: 20
memory_kb: 5256
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 1LL<<60
int main(){
   
   ll n,r=0,q;cin>>n;
   vector<vector<char>> ma(n,vector<char>(n));
   for(auto& i:ma)for(auto& j:i)cin>>j;
   cin>>q;
   while(q--){
    ll f;cin>>f;
    r+=f;
   }
   r=(r%4+4)%4;
   for(ll k=0;k<r;k++){
    vector<vector<char>> mf(n,vector<char>(n));
    for(ll i=0;i<n;i++){
        for(ll j=0;j<n;j++){
            mf[j][n-1-i]=ma[i][j];
        }
    }
    ma=mf;
   }
   for(auto i:ma){
    for(auto j:i)cout<<j;
    cout<<endl;
   }
}
accuracy: 1
time_ms: 50
memory_kb: 5156
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, e) for (int i = (int)(s); i < (int)(e); ++i)
#define all(a) (a).begin(),(a).end()

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    
    int N;
    cin >> N;
    vector S(N, vector<char>(N));
    rep(i, 0, N) rep(j, 0, N) cin >> S[i][j];
    
    int Q;
    cin >> Q;
    int op = 0;
    rep(i, 0, Q) {
        int r;
        cin >> r;
        op += r;
    }
    
    op = (op % 4 + 4) % 4;
    
    rep(itr, 0, op) {
        vector T(N, vector<char>(N));
        
        rep(i, 0, N) rep(j, 0, N) {
            T[j][N - i - 1] = S[i][j];
        }
        S = T;
    }
    rep(i, 0, N) {
        rep(j, 0, N) cout << S[i][j];
        cout << '\n';
    }
}
accuracy: 1
time_ms: 30
memory_kb: 5164
final_rank: 5

code_snippet: #include<bits/stdc++.h>
using namespace std;
void rotate(vector<vector<char>> &R){
    int n = R.size();
	vector<vector<char>> R2 = R;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			R[j][n-i-1] = R2[i][j];
		}
	}
}

int main(){
    int n;
	cin >> n;
	vector<vector<char>> r(n, vector<char>(n));
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			cin >> r[i][j];
		}
	}
	int q;
	cin >> q;
	int cnt = 0;
	while(q--){
		int r2;
		cin >> r2;
		if(r2 == 1){
			cnt++;
		}
		else{
			cnt += 3;
		}
		cnt %= 4;
	}
    for(int i = 0; i < cnt; i++) rotate(r);
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			cout << r[i][j];
		}
		cout << '\n';
	}
}
accuracy: 1
time_ms: 50
memory_kb: 5156
final_rank: 18

code_snippet: #include<bits/stdc++.h>
using namespace std;

int N;

void solve(vector<vector<char>> &R){
	vector<vector<char>> RR=R;
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			R[j][N-i-1]=RR[i][j];
		}
	}
}

int main(){
	cin >> N;
	vector<vector<char>> R(N,vector<char>(N));
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			cin >> R[i][j];
		}
	}
	vector<vector<vector<char>>> data(4);
	data[0]=R;
	for(int i=1;i<4;i++){
		solve(R);
		data[i]=R;
	}
	int Q;
	cin >> Q;
	int cnt=0;
	for(;Q--;){
		int r;
		cin >> r;
		if(r==1){
			cnt++;
		}
		else{
			cnt+=3;
		}
		cnt%=4;
	}
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			cout << data[cnt][i][j];
		}
		cout << '\n';
	}
}
accuracy: 1
time_ms: 50
memory_kb: 8484
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; ++i)

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;
    vector<string> row(n);
    rep(i,n) cin >> row[i];

    int q;
    cin >> q;
    int sum = 0;
    while(q--) {
        int r;
        cin >> r;
        sum += r;
    }

    vector<vector<char>> ans(n, vector<char>(n));
    int ans_rotate = sum % 4;
    if(ans_rotate == 1 || ans_rotate == -3) {
        rep(i,n) {
            rep(j,n) {
                ans[j][n-1-i] = row[i][j];
            }
        }
    }else if(ans_rotate == 2 || ans_rotate == -2) {
        rep(i,n) {
            rep(j,n) {
                ans[n-i-1][n-j-1] = row[i][j];
            }
        }
    }else if(ans_rotate == 3 || ans_rotate == -1) {
        rep(i,n) {
            rep(j,n) {
                ans[n-j-1][i] = row[i][j];
            }
        }
    }else {
        rep(i,n) {
            rep(j,n) {
                ans[i][j] = row[i][j];
            }
        }
    }
    rep(i,n) {
        rep(j,n) {
            cout << ans[i][j];
        }
        cout << endl;
    }

    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 5192
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,q,g;
    cin>>n;
    string a[n],b[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        b[i]=a[i];
    }
    cin>>q;
    int r;
    for(int i=0;i<q;i++){
        cin>>r;
        g+=r;
    }
    if(g<0){
        for(int i=0;i<g%4*-1;i++){
            for(int j=0;j<n;j++){
                for(int k=0;k<n;k++){
                    b[j][k]=a[k][n-1-j];
                }
            }
            for(int j=0;j<n;j++)a[j]=b[j];
        }
        for(int j=0;j<n;j++)cout<<a[j]<<endl;
    }
    else if(g>0){
        for(int i=0;i<g%4;i++){
            for(int j=0;j<n;j++){
                for(int k=0;k<n;k++){
                    b[j][k]=a[n-1-k][j];
                }
            }
            for(int j=0;j<n;j++)a[j]=b[j];
        }
        for(int j=0;j<n;j++)cout<<a[j]<<endl;
    }
    else for(int j=0;j<n;j++)cout<<a[j]<<endl;
}
accuracy: 1
time_ms: 30
memory_kb: 6400
final_rank: 9

code_snippet: #include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,i,j,q,flg=0,k,cnt=0,cnt2=0,ans;
	cin>>n;
	string s[n],t[n];
	for(i=0;i<n;i++){
		cin>>s[i];
		t[i]=s[i];
	}
	cin>>q;
	int r[q];
	for(i=0;i<q;i++){
		cin>>r[i];
	}
	for(i=0;i<q;i++){
		if(r[i]==1)	cnt++;
		if(r[i]==-1)	cnt2++;
	}
	cnt=cnt%4;
	cnt2=cnt2%4;
	if(cnt>cnt2){
		ans=cnt-cnt2;
		flg=1;
	}
	else{
		//cout<<'A'<<endl;
		ans=cnt2-cnt;
	}
	//cout<<ans<<endl;
	if(flg==0){
		//cout<<'A'<<endl;
		for(k=0;k<ans;k++){
			for(i=0;i<n;i++){
				for(j=0;j<n;j++){
					t[i][j]=s[j][n-1-i];
				}
			}
			for(i=0;i<n;i++)	s[i]=t[i];
		}
	}
	else{
		for(k=0;k<ans;k++){
			for(i=0;i<n;i++){
				for(j=0;j<n;j++){
					t[i][j]=s[n-1-j][i];
				}
			}
			for(i=0;i<n;i++)	s[i]=t[i];
		}
	}
	for(i=0;i<n;i++){
		cout<<s[i]<<endl;
	}
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 7176
final_rank: 15

code_snippet: #include<bits/stdc++.h>
using namespace std;
char r1[1000][1001],r2[1000][1001];
int main(void)
{
	int n,i,j,k,q,r,s;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>r1[i];
	}
	cin>>q;
	s=0;
	for(i=0;i<q;i++){
		cin>>r;
		s+=r;
	}
	s=s%4;
	if(s<0){
		s+=4;
	}
	for(i=0;i<s;i++){
		for(j=0;j<n;j++){
			for(k=0;k<n;k++){
				r2[j][k]=r1[n-k-1][j];
			}
		}
		for(j=0;j<n;j++){
			for(k=0;k<n;k++){
				r1[j][k]=r2[j][k];
			}
		}
	}
	for(i=0;i<n;i++){
		cout<<r1[i]<<endl;
	}
	return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 5320
final_rank: 6

code_snippet: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,r,cnt=0,cnt1=0,ans=0,flg=0;
    string s[1001],t[1001];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s[i];
        t[i]=s[i];
    }
    int q;
    cin>>q;
    for(int k=0;k<q;k++){
        cin>>r;
        if(r==-1)cnt++;
        if(r==1)cnt1++;
    }
    cnt=cnt%4;
    cnt1=cnt1%4;
    if(cnt>cnt1){
        ans=cnt-cnt1;
        flg=1;
    }
    else {
        ans=cnt1-cnt;
    }
    //cout<<ans<<endl;
    //cout<<flg<<endl;
    if(!flg){
        //cout<<'A' <<endl;
    for(int k=0;k<ans;k++){
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                t[i][j]=s[n-1-j][i];
            }
        }
        for(int i=0;i<n;i++)s[i]=t[i];
    }
    }
    else{
        for(int k=0;k<ans;k++){
            for(int i=0;i<n;i++){
                for(int j=0;j<n;j++){
                t[i][j]=s[j][n-1-i];
            }
        }
        for(int i=0;i<n;i++)    s[i]=t[i];
        }
    }
    for(int i=0;i<n;i++){
        cout<<t[i]<<endl;
    }
}
accuracy: 1
time_ms: 30
memory_kb: 6328
final_rank: 8

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main(void){
	int n,q,r,ans=0,i,j;
	string raw[1001];
	cin>>n;
	for(i=0;i<n;i++) cin>>raw[i];
	cin>>q;
	for(i=0;i<q;i++){
		cin>>r;
		ans+=r;
	}
	if(ans%4==0){
		for(i=0;i<n;i++){
			for(j=0;j<n;j++) cout<<raw[i][j];
			cout<<endl;
		}
	}
	else if(ans%4==1 || ans%4==-3){
		for(i=0;i<n;i++){
			for(j=n-1;0<=j;j--) cout<<raw[j][i];
			cout<<endl;
		}
	}
	else if(ans%4==2 || ans%4==-2){
		for(i=n-1;0<=i;i--){
			for(j=n-1;0<=j;j--) cout<<raw[i][j];
			cout<<endl;
		}
	}
	else{
		for(i=n-1;0<=i;i--){
			for(j=0;j<n;j++) cout<<raw[j][i];
			cout<<endl;
		}
	}
	return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 5368
final_rank: 11