Language: C++

#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,NAME,...) NAME
#define pr(...) GET_MACRO(__VA_ARGS__,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)
#define pr1(a) (#a)<<"="<<(a)
#define pr2(a,b) pr1(a)<<", "<<pr1(b)
#define pr3(a,b,c) pr2(a,b)<<", "<<pr1(c)
#define pr4(a,b,c,d) pr3(a,b,c)<<", "<<pr1(d)
#define pr5(a,b,c,d,e) pr4(a,b,c,d)<<", "<<pr1(e)
#define int long long
#define double long double
using namespace std;
const int N = 100010;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
typedef pair<int,int> P;
typedef long long ll;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
//ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
//istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
//ostream& operator<<(ostream& o,vector<auto> &a){int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
//istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
//void prArr(auto a,string s=" "){int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}

typedef vector<int> vec;
typedef vector<vec> mat;

mat move(mat a,mat b){
  int n = a.size();
  mat res(n,vec(n));

  assert(a.size() == b.size());
  assert(a[0].size() == b[0].size());
  assert(a[0].size() == a.size());

  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++) {
      int y = a[i][j] / n;
      int x = a[i][j] % n;
      res[i][j] = b[y][x];
    }
  return res;
}

int n,len;
int pos;
string str;

mat bfs();
mat repeat();
int number();
  
mat repeat(){
  assert(str[pos] == '(');
  pos++;
  mat x = bfs();
  assert(str[pos]==')');
  pos++;
  int num = number();
  
  mat res(n,vec(n));
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++) res[i][j] = i * n + j;

  while(num){
    if(num%2) res = move(res,x);
    x = move(x,x);
    num = num/2;
  }
  return res;
}

int number(){
  assert(isdigit(str[pos]));
  int res = 0;
  while(isdigit(str[pos])) res = res * 10 + str[pos] - '0', pos++;
  return res;
}

void L(mat &A){
  assert(str[pos++] == 'L');
  int k = number() - 1;
  for(int i=0;i<n-1;i++) swap(A[k][i],A[k][i+1]);
}

void R(mat &A){
  assert(str[pos++] == 'R');
  int k = number() - 1;
  for(int i=0;i<n-1;i++) swap(A[k][n-1-i],A[k][n-2-i]);
};

mat U(mat &A){
  assert(str[pos++] == 'U');
  int k = number() - 1;
  for(int i=0;i<n-1;i++) swap(A[i][k],A[i+1][k]);
};
mat D(mat &A){
  assert(str[pos++] == 'D');
  int k = number() - 1;
  for(int i=0;i<n-1;i++) swap(A[n-1-i][k],A[n-2-i][k]);
};

mat bfs(){
  mat res(n,vec(n));
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++) res[i][j] = i*n + j;
  
  while(pos < (int)str.size()){
    char ch = str[pos];
    if(ch == '(') res = repeat();
    else if(ch == 'L') L(res);
    else if(ch == 'R') R(res);
    else if(ch == 'U') U(res);
    else if(ch == 'D') D(res);
    else break;
  }
  return res;
}

signed main(){
  int L;
  cin>>n>>L;
  cin>>str;
  
  mat ans = bfs();
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++) ans[i][j] ++;
  for(int i=0;i<n;i++) cout<<ans[i]<<endl;
  
  return 0;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:130:28: error: no match for 'operator<<' (operand types are 'std::ostream' {aka 'std::basic_ostream<char>'} and '__gnu_cxx::__alloc_traits<std::allocator<std::vector<long long int> >, std::vector<long long int> >::value_type' {aka 'std::vector<long long int>'})
  130 |   for(int i=0;i<n;i++) cout<<ans[i]<<endl;
In file included from /usr/include/c++/14/istream:41,
                 from /usr/include/c++/14/sstream:40,
                 from /usr/include/c++/14/complex:45,
                 from /usr/include/c++/14/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:127,
                 from a.cc:1:
/usr/include/c++/14/ostream:116:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(__ostream_type& (*)(__ostream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  116 |       operator<<(__ostream_type& (*__pf)(__ostream_type&))
      |       ^~~~~~~~
/usr/include/c++/14/ostream:116:36: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::vector<long long int> >, std::vector<long long int> >::value_type' {aka 'std::vector<long long int>'} to 'std::basic_ostream<char>::__ostream_type& (*)(std::basic_ostream<char>::__ostream_type&)' {aka 'std::basic_ostream<char>& (*)(std::basic_ostream<char>&)'}
  116 |       operator<<(__ostream_type& (*__pf)(__ostream_type&))
      |                  ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/ostream:125:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(__ios_type& (*)(__ios_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>; __ios_type = std::basic_ios<char>]'
  125 |       operator<<(__ios_type& (*__pf)(__ios_type&))
      |       ^~~~~~~~
/usr/include/c++/14/ostream:125:32: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::vector<long long int> >, std::vector<long long int> >::value_type' {aka 'std::vector<long long int>'} to 'std::basic_ostream<char>::__ios_type& (*)(std::basic_ostream<char>::__ios_type&)' {aka 'std::basic_ios<char>& (*)(std::basic_ios<char>&)'}
  125 |       operator<<(__ios_type& (*__pf)(__ios_type&))
      |                  ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
/usr/include/c++/14/ostream:135:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::ios_base& (*)(std::ios_base&)) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  135 |       operator<<(ios_base& (*__pf) (ios_base&))
      |       ^~~~~~~~
/usr/include/c++/14/ostream:135:30: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::vector<long long int> >, std::vector<long long int> >::value_type' {aka 'std::vector<long long int>'} to 'std::ios_base& (*)(std::ios_base&)'
  135 |       operator<<(ios_base& (*__pf) (ios_base&))
      |                  ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/ostream:174:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  174 |       operator<<(long __n)
      |       ^~~~~~~~
/usr/include/c++/14/ostream:174:23: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::vector<long long int> >, std::vector<long long int> >::value_type' {aka 'std::vector<long long int>'} to 'long int'
  174 |       operator<<(long __n)
      |                  ~~~~~^~~
/usr/include/c++/14/ostream:178:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  178 |       operator<<(unsigned long __n)
      |       ^~~~~~~~
/usr/include/c++/14/ostream:178:32: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::vector<long long int> >, std::vector<long long int> >::value_type' {aka 'std::vector<long long int>'} to 'long unsigned int'
  178 |       operator<<(unsigned long __n)
      |                  ~~~~~~~~~~~~~~^~~
/usr/include/c++/14/ostream:182:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  182 |       operator<<(bool __n)
      |       ^~~~~~~~
/usr/include/c++/14/ostream:182:23: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::vector<long long int> >, std::vector<long long int> >::value_type' {aka 'std::vector<long long int>'} to 'bool'
  182 |       operator<<(bool __n)
      |                  ~~~~~^~~
In file included from /usr/include/c++/14/ostream:1022:
/usr/include/c++/14/bits/ostream.tcc:96:5: note: candidate: 'std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short int) [with _CharT = char; _Traits = std::char_traits<char>]'
   96 |     basic_ostream<_CharT, _Traits>::
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/ostream.tcc:97:22: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::vector<long long int> >, std::vector<long long int> >::value_type' {aka 'std::vector<long long int>'} to 'short int'
   97 |     operator<<(short __n)
      |                ~~~~~~^~~
/usr/include/c++/14/ostream:189:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(short unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  189 |       operator<<(unsigned short __n)
      |       ^~~~~~~~
/usr/include/c++/14/ostream:189:33: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::vector<long long int> >, std::vector<long long int> >::value_type' {aka 'std::vector<long long int>'} to 'short unsigned int'
  189 |       operator<<(unsigned short __n)
      |                  ~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/ostream.tcc:110:5: note: candidate: 'std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(int) [with _CharT = char; _Traits = std::char_traits<char>]'
  110 |     basic_ostream<_CharT, _Traits>::
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/ostream.tcc:111:20: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::vector<long long int> >, std::vector<long long int> >::value_type' {aka 'std::vector<long long int>'} to 'int'
  111 |     operator<<(int __n)
      |                ~~~~^~~
/usr/include/c++/14/ostream:200:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  200 |       operator<<(unsigned int __n)
      |       ^~~~~~~~
/usr/include/c++/14/ostream:200:31: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::vector<long long int> >, std::vector<long long int> >::value_type' {aka 'std::vector<long long int>'} to 'unsigned int'
  200 |       operator<<(unsigned int __n)
      |                  ~~~~~~~~~~~~~^~~
/usr/include/c++/14/ostream:211:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  211 |       operator<<(long long __n)
      |       ^~~~~~~~
/usr/include/c++/14/ostream:211:28: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::vector<long long int> >, std::vector<long long int> >::value_type' {aka 'std::vector<long long int>'} to 'long long int'
  211 |       operator<<(long long __n)
      |                  ~~~~~~~~~~^~~
/usr/include/c++/14/ostream:215:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  215 |       operator<<(unsigned long long __n)
      |       ^~~~~~~~
/usr/include/c++/14/ostream:215:37: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::vector<long long int> >, std::vector<long long int> >::value_type' {aka 'std::vector<long long int>'} to 'long long unsigned int'
  215 |       operator<<(unsigned long long __n)
      |                  ~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/ostream:231:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(double) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  231 |       operator<<(double __f)
      |       ^~~~~~~~
/usr/include/c++/14/ostream:231:25: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::vector<long long int> >, std::vector<long long int> >::value_type' {aka 'std::vector<long long int>'} to 'double'
  231 |       operator<<(double __f)
      |                  ~~~~~~~^~~
/usr/include/c++/14/ostream:235:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(float) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  235 |       operator<<(float __f)
      |       ^~~~~~~~
/usr/include/c++/14/ostream:235:24: note:   no known conversion for argument 1 from '__gnu_cxx