In this HackerEarth Gift for Almas problem solution On his birthday, Almas was given a N x N(1 <= N <= 500) matrix of natural numbers up to 500 and instructions for it. The instruction consisted of symbols L and R, where if the symbol L is given you need to rotate the matrix 90 degrees to the left, and for the symbol R you need to rotate the matrix 90 degrees to the right. The instruction was only 3 characters in length so Almas could handle the twists with ease. Your task is to display the matrix that Almas had at the end of these turns.

## HackerEarth Gift for Almas problem solution.

```# include <bits/stdc++.h>

# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++)
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define debug(x) cerr << #x << " = " << x << endl
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)

void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void setIO(string s = "") {
if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 2e5+5;
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};

int rnd (int l, int r) {
return uniform_int_distribution<int> (l, r)(gen);
}

void rotate(vector<vector<int> > &a) {
int n = a.size();
vector<vector<int> > b = a;
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
b[j][n-i-1] = a[i][j];

a.swap(b);
}

namespace ProblemA {

void solve() {
int n;
cin >> n;
vector < vector < int > > a(n, vector<int> (n));

for (auto &ve : a)
for (auto &x : ve)
cin >> x;

string s;
cin >> s;
int balance = 0;
for(auto &it : s) {
balance += it == 'R';
balance -= it == 'L';
}

balance = (balance + 4) % 4;

for (int it = 0; it < balance; ++it)
rotate(a);

for (int i = 0; i < n; ++i) {
if(i) cout << '\n';
for (int j = 0; j < n; ++j) {
if(j) cout << ' ';
cout << a[i][j];
}
}
}
};

int32_t main () {
SpeedForce;

int TestCases = 1;

for (int TestCase = 1; TestCase <= TestCases; ++TestCase) {

ProblemA::solve();
}

return Accepted;
}```

### Second solution

```n = int(input())
a = []
for i in range(n):
a += [list(map(int, input().split()))]
rotate_l = sum(c == 'L' for c in input()) % 2 == 0
for j in (reversed(range(n)) if rotate_l else range(n)):
print(*(a[i][j] for i in (range(n) if rotate_l else reversed(range(n)))))```