提出 #73751841


ソースコード 拡げる

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("inline")
#include<bits/stdc++.h>
#include<sys/time.h>
using namespace std;
template<class T> struct cLtraits_identity{
  using type = T;
}
;
template<class T> using cLtraits_try_make_signed =
  typename conditional<
    is_integral<T>::value,
    make_signed<T>,
    cLtraits_identity<T>
    >::type;
template <class S, class T> struct cLtraits_common_type{
  using tS = typename cLtraits_try_make_signed<S>::type;
  using tT = typename cLtraits_try_make_signed<T>::type;
  using type = typename common_type<tS,tT>::type;
}
;
template<class S, class T> inline auto min_L(S a, T b)
-> typename cLtraits_common_type<S,T>::type{
  return (typename cLtraits_common_type<S,T>::type) a <= (typename cLtraits_common_type<S,T>::type) b ? a : b;
}
struct Timer{
  double x;
  double gettimeofday_sec(void){
    timeval t;
    gettimeofday(&t, 0);
    return t.tv_sec + t.tv_usec * 1e-6;
  }
  void set(void){
    x = gettimeofday_sec();
  }
  double get(void){
    return gettimeofday_sec() - x;
  }
}
;
struct Rand{
  unsigned x;
  unsigned y;
  unsigned z;
  unsigned w;
  Rand(void){
    x=123456789;
    y=362436069;
    z=521288629;
    w=(unsigned)time(NULL);
  }
  Rand(unsigned seed){
    x=123456789;
    y=362436069;
    z=521288629;
    w=seed;
  }
  inline unsigned get(void){
    unsigned t;
    t = (x^(x<<11));
    x=y;
    y=z;
    z=w;
    w = (w^(w>>19))^(t^(t>>8));
    return w;
  }
  inline double getUni(void){
    return get()/4294967296.0;
  }
  inline int get(int a){
    return (int)(a*getUni());
  }
  inline int get(int a, int b){
    return a+(int)((b-a+1)*getUni());
  }
  inline long long get(long long a){
    return(long long)(a*getUni());
  }
  inline long long get(long long a, long long b){
    return a+(long long)((b-a+1)*getUni());
  }
  inline double get(double a, double b){
    return a+(b-a)*getUni();
  }
  inline int getExp(int a){
    return(int)(exp(getUni()*log(a+1.0))-1.0);
  }
  inline int getExp(int a, int b){
    return a+(int)(exp(getUni()*log((b-a+1)+1.0))-1.0);
  }
}
;
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(char &c){
  int i;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c = i;
}
inline int rd(char c[]){
  int i;
  int sz = 0;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = my_getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
template<class T> inline void wt_L(const vector<T> &x);
template<class T> inline void wt_L(const set<T> &x);
template<class T> inline void wt_L(const multiset<T> &x);
template<class T1, class T2> inline void wt_L(const pair<T1,T2> x);
inline void wt_L(const char a){
  my_putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    my_putchar_unlocked(c[i]);
  }
}
const int LOCAL = 0;
const int TEST_CASE = 20;
const double TL = 1.9;
Timer timer;
Rand rnd;
int N;
int AK;
int AM;
int AW;
char V[20][21];
char H[19][22];
int K;
int M[500];
int I0[500];
int J0[500];
int D0[500];
char A[500][2000][2];
int B[500][2000][2];
int res_M[500];
int res_I0[500];
int res_J0[500];
int res_D0[500];
char res_A[500][2000][2];
int res_B[500][2000][2];
char res_V[20][21];
char res_H[19][22];
int res_Kabe;
const char*dir = "URDL";
int dx[4] = {-1,0,1,0};
int dy[4] = {0,1,0,-1};
const char*com = "FRL";
int cover[20][20];
int is_movable(int i, int j, int d){
  int ni;
  int nj;
  ni = i + dx[d];
  nj = j + dy[d];
  if(ni < 0 || ni >= N || nj < 0 || nj >= N){
    return 0;
  }
  if(i != ni && H[min_L(i, ni)][j]){
    return 0;
  }
  if(j != nj && V[i][min_L(j, nj)]){
    return 0;
  }
  return 1;
}
void add_cover(int ind){
  static int vis[20][20][4][2000];
  int mm = M[ind];
  int i;
  int j;
  int d;
  int m;
  int bi;
  int bj;
  int bd;
  int bm;
  int mova;
  for(i=(0);i<(N);i++){
    for(j=(0);j<(N);j++){
      for(d=(0);d<(4);d++){
        for(m=(0);m<(mm);m++){
          vis[i][j][d][m] = 0;
        }
      }
    }
  }
  i = I0[ind];
  j = J0[ind];
  d = D0[ind];
  m = 0;
  for(;;){
    vis[i][j][d][m]++;
    if(vis[i][j][d][m]==2){
      cover[i][j]++;
    }
    if(vis[i][j][d][m]==3){
      break;
    }
    bi = i;
    bj = j;
    bd = d;
    bm = m;
    mova = is_movable(i,j,d);
    if(A[ind][m][1-mova] == 'F'){
      i += dx[d];
      j += dy[d];
      m = B[ind][m][1-mova];
    }
    else if(A[ind][m][1-mova] == 'R'){
      d = (d+1)%4;
      m = B[ind][m][1-mova];
    }
    else if(A[ind][m][1-mova] == 'L'){
      d = (d+3)%4;
      m = B[ind][m][1-mova];
    }
  }
}
void umekomi(){
  int i;
  int j;
  int k;
  int ok;
  int loop;
  int loop2;
  int ki;
  int kj;
  int Kabe;
  for(loop2=(0);loop2<(20);loop2++){
    if(loop2==0){
      Kabe = 0;
    }
    else{
      Kabe = 1;
      ki = rnd.get(N);
      if(ki){
        kj = rnd.get(N-1);
      }
      while(V[ki][kj]){
        ki = rnd.get(N);
        kj = rnd.get(N-1);
      }
    }
    if(Kabe){
      V[ki][kj] = 1;
    }
    for(loop=(0);loop<(25);loop++){
      for(I0[0]=(0);I0[0]<(3);I0[0]++){
        for(J0[0]=(0);J0[0]<(3);J0[0]++){
          for(D0[0]=(0);D0[0]<(4);D0[0]++){
            if(loop==0){
              K = 1;
              M[0] = 4;
              A[0][0][0] = 'R';
              B[0][0][0] = 1;
              A[0][0][1] = 'R';
              B[0][0][1] = 1;
              A[0][1][0] = 'F';
              B[0][1][0] = 2;
              A[0][1][1] = 'L';
              B[0][1][1] = 3;
              A[0][2][0] = 'L';
              B[0][2][0] = 3;
              A[0][2][1] = 'L';
              B[0][2][1] = 1;
              A[0][3][0] = 'F';
              B[0][3][0] = 0;
              A[0][3][1] = 'R';
              B[0][3][1] = 3;
            }
            if(loop==1){
              K = 1;
              M[0] = 4;
              A[0][0][0] = 'L';
              B[0][0][0] = 1;
              A[0][0][1] = 'L';
              B[0][0][1] = 2;
              A[0][1][0] = 'F';
              B[0][1][0] = 3;
              A[0][1][1] = 'R';
              B[0][1][1] = 2;
              A[0][2][0] = 'F';
              B[0][2][0] = 0;
              A[0][2][1] = 'R';
              B[0][2][1] = 1;
              A[0][3][0] = 'R';
              B[0][3][0] = 2;
              A[0][3][1] = 'L';
              B[0][3][1] = 1;
            }
            if(loop==2){
              K = 1;
              M[0] = 5;
              A[0][0][0] = 'F';
              B[0][0][0] = 0;
              A[0][0][1] = 'R';
              B[0][0][1] = 1;
              A[0][1][0] = 'F';
              B[0][1][0] = 4;
              A[0][1][1] = 'R';
              B[0][1][1] = 0;
              A[0][2][0] = 'R';
              B[0][2][0] = 0;
              A[0][2][1] = 'L';
              B[0][2][1] = 2;
              A[0][3][0] = 'F';
              B[0][3][0] = 3;
              A[0][3][1] = 'R';
              B[0][3][1] = 2;
              A[0][4][0] = 'R';
              B[0][4][0] = 3;
              A[0][4][1] = 'R';
              B[0][4][1] = 4;
            }
            if(loop==3){
              K = 1;
              M[0] = 5;
              A[0][0][0] = 'L';
              B[0][0][0] = 3;
              A[0][0][1] = 'R';
              B[0][0][1] = 2;
              A[0][1][0] = 'R';
              B[0][1][0] = 2;
              A[0][1][1] = 'R';
              B[0][1][1] = 3;
              A[0][2][0] = 'F';
              B[0][2][0] = 0;
              A[0][2][1] = 'L';
              B[0][2][1] = 3;
              A[0][3][0] = 'F';
              B[0][3][0] = 1;
              A[0][3][1] = 'L';
              B[0][3][1] = 4;
              A[0][4][0] = 'L';
              B[0][4][0] = 4;
              A[0][4][1] = 'L';
              B[0][4][1] = 2;
            }
            if(loop==4){
              K = 1;
              M[0] = 5;
              A[0][0][0] = 'F';
              B[0][0][0] = 4;
              A[0][0][1] = 'R';
              B[0][0][1] = 1;
              A[0][1][0] = 'F';
              B[0][1][0] = 2;
              A[0][1][1] = 'L';
              B[0][1][1] = 0;
              A[0][2][0] = 'L';
              B[0][2][0] = 0;
              A[0][2][1] = 'L';
              B[0][2][1] = 1;
              A[0][3][0] = 'F';
              B[0][3][0] = 1;
              A[0][3][1] = 'R';
              B[0][3][1] = 0;
              A[0][4][0] = 'R';
              B[0][4][0] = 1;
              A[0][4][1] = 'R';
              B[0][4][1] = 0;
            }
            if(loop==5){
              K = 1;
              M[0] = 5;
              A[0][0][0] = 'F';
              B[0][0][0] = 4;
              A[0][0][1] = 'L';
              B[0][0][1] = 0;
              A[0][1][0] = 'F';
              B[0][1][0] = 2;
              A[0][1][1] = 'R';
              B[0][1][1] = 0;
              A[0][2][0] = 'R';
              B[0][2][0] = 0;
              A[0][2][1] = 'R';
              B[0][2][1] = 1;
              A[0][3][0] = 'R';
              B[0][3][0] = 2;
              A[0][3][1] = 'L';
              B[0][3][1] = 2;
              A[0][4][0] = 'L';
              B[0][4][0] = 1;
              A[0][4][1] = 'L';
              B[0][4][1] = 1;
            }
            if(loop==6){
              K = 1;
              M[0] = 5;
              A[0][0][0] = 'F';
              B[0][0][0] = 1;
              A[0][0][1] = 'L';
              B[0][0][1] = 0;
              A[0][1][0] = 'L';
              B[0][1][0] = 4;
              A[0][1][1] = 'L';
              B[0][1][1] = 4;
              A[0][2][0] = 'R';
              B[0][2][0] = 0;
              A[0][2][1] = 'R';
              B[0][2][1] = 4;
              A[0][3][0] = 'L';
              B[0][3][0] = 3;
              A[0][3][1] = 'R';
              B[0][3][1] = 0;
              A[0][4][0] = 'F';
              B[0][4][0] = 2;
              A[0][4][1] = 'L';
              B[0][4][1] = 3;
            }
            if(loop==7){
              K = 1;
              M[0] = 5;
              A[0][0][0] = 'R';
              B[0][0][0] = 1;
              A[0][0][1] = 'R';
              B[0][0][1] = 2;
              A[0][1][0] = 'F';
              B[0][1][0] = 4;
              A[0][1][1] = 'L';
              B[0][1][1] = 3;
              A[0][2][0] = 'L';
              B[0][2][0] = 1;
              A[0][2][1] = 'R';
              B[0][2][1] = 3;
              A[0][3][0] = 'F';
              B[0][3][0] = 2;
              A[0][3][1] = 'L';
              B[0][3][1] = 1;
              A[0][4][0] = 'R';
              B[0][4][0] = 3;
              A[0][4][1] = 'R';
              B[0][4][1] = 1;
            }
            if(loop==8){
              K = 1;
              M[0] = 5;
              A[0][0][0] = 'L';
              B[0][0][0] = 4;
              A[0][0][1] = 'R';
              B[0][0][1] = 1;
              A[0][1][0] = 'F';
              B[0][1][0] = 0;
              A[0][1][1] = 'R';
              B[0][1][1] = 3;
              A[0][2][0] = 'R';
              B[0][2][0] = 3;
              A[0][2][1] = 'R';
              B[0][2][1] = 1;
              A[0][3][0] = 'F';
              B[0][3][0] = 3;
              A[0][3][1] = 'R';
              B[0][3][1] = 4;
              A[0][4][0] = 'R';
              B[0][4][0] = 1;
              A[0][4][1] = 'R';
              B[0][4][1] = 2;
            }
            if(loop==9){
              K = 1;
              M[0] = 5;
              A[0][0][0] = 'L';
              B[0][0][0] = 4;
              A[0][0][1] = 'L';
              B[0][0][1] = 4;
              A[0][1][0] = 'R';
              B[0][1][0] = 4;
              A[0][1][1] = 'L';
              B[0][1][1] = 1;
              A[0][2][0] = 'F';
              B[0][2][0] = 0;
              A[0][2][1] = 'R';
              B[0][2][1] = 2;
              A[0][3][0] = 'R';
              B[0][3][0] = 2;
              A[0][3][1] = 'R';
              B[0][3][1] = 4;
              A[0][4][0] = 'F';
              B[0][4][0] = 3;
              A[0][4][1] = 'L';
              B[0][4][1] = 2;
            }
            if(loop==10){
              K = 1;
              M[0] = 5;
              A[0][0][0] = 'L';
              B[0][0][0] = 3;
              A[0][0][1] = 'L';
              B[0][0][1] = 3;
              A[0][1][0] = 'F';
              B[0][1][0] = 0;
              A[0][1][1] = 'R';
              B[0][1][1] = 4;
              A[0][2][0] = 'L';
              B[0][2][0] = 1;
              A[0][2][1] = 'L';
              B[0][2][1] = 1;
              A[0][3][0] = 'R';
              B[0][3][0] = 4;
              A[0][3][1] = 'R';
              B[0][3][1] = 3;
              A[0][4][0] = 'F';
              B[0][4][0] = 1;
              A[0][4][1] = 'L';
              B[0][4][1] = 2;
            }
            if(loop==11){
              K = 1;
              M[0] = 6;
              A[0][0][0] = 'L';
              B[0][0][0] = 1;
              A[0][0][1] = 'L';
              B[0][0][1] = 3;
              A[0][1][0] = 'F';
              B[0][1][0] = 5;
              A[0][1][1] = 'R';
              B[0][1][1] = 3;
              A[0][2][0] = 'F';
              B[0][2][0] = 5;
              A[0][2][1] = 'R';
              B[0][2][1] = 3;
              A[0][3][0] = 'F';
              B[0][3][0] = 0;
              A[0][3][1] = 'L';
              B[0][3][1] = 1;
              A[0][4][0] = 'F';
              B[0][4][0] = 3;
              A[0][4][1] = 'R';
              B[0][4][1] = 0;
              A[0][5][0] = 'R';
              B[0][5][0] = 3;
              A[0][5][1] = 'R';
              B[0][5][1] = 1;
            }
            if(loop==12){
              K = 1;
              M[0] = 6;
              A[0][0][0] = 'R';
              B[0][0][0] = 5;
              A[0][0][1] = 'R';
              B[0][0][1] = 5;
              A[0][1][0] = 'R';
              B[0][1][0] = 3;
              A[0][1][1] = 'L';
              B[0][1][1] = 2;
              A[0][2][0] = 'F';
              B[0][2][0] = 2;
              A[0][2][1] = 'R';
              B[0][2][1] = 0;
              A[0][3][0] = 'F';
              B[0][3][0] = 1;
              A[0][3][1] = 'L';
              B[0][3][1] = 4;
              A[0][4][0] = 'L';
              B[0][4][0] = 2;
              A[0][4][1] = 'R';
              B[0][4][1] = 3;
              A[0][5][0] = 'F';
              B[0][5][0] = 5;
              A[0][5][1] = 'L';
              B[0][5][1] = 3;
            }
            if(loop==13){
              K = 1;
              M[0] = 6;
              A[0][0][0] = 'L';
              B[0][0][0] = 1;
              A[0][0][1] = 'L';
              B[0][0][1] = 4;
              A[0][1][0] = 'F';
              B[0][1][0] = 1;
              A[0][1][1] = 'L';
              B[0][1][1] = 2;
              A[0][2][0] = 'L';
              B[0][2][0] = 4;
              A[0][2][1] = 'R';
              B[0][2][1] = 5;
              A[0][3][0] = 'F';
              B[0][3][0] = 4;
              A[0][3][1] = 'R';
              B[0][3][1] = 3;
              A[0][4][0] = 'F';
              B[0][4][0] = 4;
              A[0][4][1] = 'L';
              B[0][4][1] = 5;
              A[0][5][0] = 'F';
              B[0][5][0] = 0;
              A[0][5][1] = 'R';
              B[0][5][1] = 2;
            }
            if(loop==14){
              K = 1;
              M[0] = 6;
              A[0][0][0] = 'L';
              B[0][0][0] = 1;
              A[0][0][1] = 'R';
              B[0][0][1] = 5;
              A[0][1][0] = 'R';
              B[0][1][0] = 5;
              A[0][1][1] = 'R';
              B[0][1][1] = 4;
              A[0][2][0] = 'F';
              B[0][2][0] = 2;
              A[0][2][1] = 'R';
              B[0][2][1] = 1;
              A[0][3][0] = 'L';
              B[0][3][0] = 0;
              A[0][3][1] = 'L';
              B[0][3][1] = 5;
              A[0][4][0] = 'R';
              B[0][4][0] = 2;
              A[0][4][1] = 'L';
              B[0][4][1] = 3;
              A[0][5][0] = 'F';
              B[0][5][0] = 0;
              A[0][5][1] = 'R';
              B[0][5][1] = 3;
            }
            if(loop==15){
              K = 1;
              M[0] = 7;
              A[0][0][0] = 'F';
              B[0][0][0] = 5;
              A[0][0][1] = 'L';
              B[0][0][1] = 6;
              A[0][1][0] = 'F';
              B[0][1][0] = 5;
              A[0][1][1] = 'R';
              B[0][1][1] = 5;
              A[0][2][0] = 'R';
              B[0][2][0] = 0;
              A[0][2][1] = 'R';
              B[0][2][1] = 1;
              A[0][3][0] = 'R';
              B[0][3][0] = 4;
              A[0][3][1] = 'L';
              B[0][3][1] = 0;
              A[0][4][0] = 'R';
              B[0][4][0] = 3;
              A[0][4][1] = 'R';
              B[0][4][1] = 3;
              A[0][5][0] = 'L';
              B[0][5][0] = 6;
              A[0][5][1] = 'L';
              B[0][5][1] = 4;
              A[0][6][0] = 'F';
              B[0][6][0] = 2;
              A[0][6][1] = 'R';
              B[0][6][1] = 6;
            }
            if(loop==16){
              K = 1;
              M[0] = 7;
              A[0][0][0] = 'F';
              B[0][0][0] = 0;
              A[0][0][1] = 'L';
              B[0][0][1] = 5;
              A[0][1][0] = 'L';
              B[0][1][0] = 1;
              A[0][1][1] = 'R';
              B[0][1][1] = 4;
              A[0][2][0] = 'F';
              B[0][2][0] = 4;
              A[0][2][1] = 'L';
              B[0][2][1] = 6;
              A[0][3][0] = 'F';
              B[0][3][0] = 3;
              A[0][3][1] = 'L';
              B[0][3][1] = 6;
              A[0][4][0] = 'R';
              B[0][4][0] = 6;
              A[0][4][1] = 'L';
              B[0][4][1] = 2;
              A[0][5][0] = 'L';
              B[0][5][0] = 3;
              A[0][5][1] = 'R';
              B[0][5][1] = 4;
              A[0][6][0] = 'L';
              B[0][6][0] = 2;
              A[0][6][1] = 'L';
              B[0][6][1] = 5;
            }
            if(loop==17){
              K = 1;
              M[0] = 7;
              A[0][0][0] = 'F';
              B[0][0][0] = 2;
              A[0][0][1] = 'L';
              B[0][0][1] = 4;
              A[0][1][0] = 'F';
              B[0][1][0] = 3;
              A[0][1][1] = 'L';
              B[0][1][1] = 0;
              A[0][2][0] = 'R';
              B[0][2][0] = 1;
              A[0][2][1] = 'R';
              B[0][2][1] = 0;
              A[0][3][0] = 'L';
              B[0][3][0] = 0;
              A[0][3][1] = 'R';
              B[0][3][1] = 1;
              A[0][4][0] = 'F';
              B[0][4][0] = 3;
              A[0][4][1] = 'L';
              B[0][4][1] = 0;
              A[0][5][0] = 'R';
              B[0][5][0] = 0;
              A[0][5][1] = 'R';
              B[0][5][1] = 2;
              A[0][6][0] = 'F';
              B[0][6][0] = 5;
              A[0][6][1] = 'L';
              B[0][6][1] = 3;
            }
            if(loop==18){
              K = 1;
              M[0] = 7;
              A[0][0][0] = 'F';
              B[0][0][0] = 0;
              A[0][0][1] = 'R';
              B[0][0][1] = 6;
              A[0][1][0] = 'R';
              B[0][1][0] = 4;
              A[0][1][1] = 'L';
              B[0][1][1] = 0;
              A[0][2][0] = 'L';
              B[0][2][0] = 0;
              A[0][2][1] = 'L';
              B[0][2][1] = 5;
              A[0][3][0] = 'F';
              B[0][3][0] = 3;
              A[0][3][1] = 'L';
              B[0][3][1] = 4;
              A[0][4][0] = 'F';
              B[0][4][0] = 4;
              A[0][4][1] = 'L';
              B[0][4][1] = 2;
              A[0][5][0] = 'F';
              B[0][5][0] = 0;
              A[0][5][1] = 'R';
              B[0][5][1] = 3;
              A[0][6][0] = 'F';
              B[0][6][0] = 1;
              A[0][6][1] = 'L';
              B[0][6][1] = 3;
            }
            if(loop==19){
              K = 1;
              M[0] = 8;
              A[0][0][0] = 'F';
              B[0][0][0] = 7;
              A[0][0][1] = 'L';
              B[0][0][1] = 3;
              A[0][1][0] = 'L';
              B[0][1][0] = 1;
              A[0][1][1] = 'L';
              B[0][1][1] = 4;
              A[0][2][0] = 'R';
              B[0][2][0] = 5;
              A[0][2][1] = 'R';
              B[0][2][1] = 0;
              A[0][3][0] = 'R';
              B[0][3][0] = 6;
              A[0][3][1] = 'L';
              B[0][3][1] = 3;
              A[0][4][0] = 'R';
              B[0][4][0] = 3;
              A[0][4][1] = 'R';
              B[0][4][1] = 5;
              A[0][5][0] = 'F';
              B[0][5][0] = 6;
              A[0][5][1] = 'L';
              B[0][5][1] = 5;
              A[0][6][0] = 'L';
              B[0][6][0] = 7;
              A[0][6][1] = 'L';
              B[0][6][1] = 7;
              A[0][7][0] = 'F';
              B[0][7][0] = 2;
              A[0][7][1] = 'R';
              B[0][7][1] = 3;
            }
            if(loop==20){
              K = 1;
              M[0] = 8;
              A[0][0][0] = 'R';
              B[0][0][0] = 2;
              A[0][0][1] = 'L';
              B[0][0][1] = 0;
              A[0][1][0] = 'R';
              B[0][1][0] = 1;
              A[0][1][1] = 'L';
              B[0][1][1] = 6;
              A[0][2][0] = 'F';
              B[0][2][0] = 5;
              A[0][2][1] = 'L';
              B[0][2][1] = 7;
              A[0][3][0] = 'R';
              B[0][3][0] = 2;
              A[0][3][1] = 'R';
              B[0][3][1] = 7;
              A[0][4][0] = 'F';
              B[0][4][0] = 2;
              A[0][4][1] = 'L';
              B[0][4][1] = 2;
              A[0][5][0] = 'L';
              B[0][5][0] = 7;
              A[0][5][1] = 'L';
              B[0][5][1] = 2;
              A[0][6][0] = 'L';
              B[0][6][0] = 6;
              A[0][6][1] = 'R';
              B[0][6][1] = 3;
              A[0][7][0] = 'F';
              B[0][7][0] = 3;
              A[0][7][1] = 'R';
              B[0][7][1] = 2;
            }
            if(loop==21){
              K = 1;
              M[0] = 8;
              A[0][0][0] = 'R';
              B[0][0][0] = 7;
              A[0][0][1] = 'L';
              B[0][0][1] = 7;
              A[0][1][0] = 'R';
              B[0][1][0] = 6;
              A[0][1][1] = 'R';
              B[0][1][1] = 5;
              A[0][2][0] = 'F';
              B[0][2][0] = 7;
              A[0][2][1] = 'R';
              B[0][2][1] = 5;
              A[0][3][0] = 'L';
              B[0][3][0] = 7;
              A[0][3][1] = 'L';
              B[0][3][1] = 6;
              A[0][4][0] = 'F';
              B[0][4][0] = 5;
              A[0][4][1] = 'L';
              B[0][4][1] = 4;
              A[0][5][0] = 'F';
              B[0][5][0] = 6;
              A[0][5][1] = 'L';
              B[0][5][1] = 2;
              A[0][6][0] = 'L';
              B[0][6][0] = 2;
              A[0][6][1] = 'L';
              B[0][6][1] = 3;
              A[0][7][0] = 'R';
              B[0][7][0] = 5;
              A[0][7][1] = 'R';
              B[0][7][1] = 2;
            }
            if(loop==22){
              K = 1;
              M[0] = 8;
              A[0][0][0] = 'R';
              B[0][0][0] = 6;
              A[0][0][1] = 'L';
              B[0][0][1] = 2;
              A[0][1][0] = 'L';
              B[0][1][0] = 0;
              A[0][1][1] = 'R';
              B[0][1][1] = 4;
              A[0][2][0] = 'F';
              B[0][2][0] = 0;
              A[0][2][1] = 'R';
              B[0][2][1] = 6;
              A[0][3][0] = 'R';
              B[0][3][0] = 2;
              A[0][3][1] = 'L';
              B[0][3][1] = 1;
              A[0][4][0] = 'L';
              B[0][4][0] = 4;
              A[0][4][1] = 'L';
              B[0][4][1] = 2;
              A[0][5][0] = 'L';
              B[0][5][0] = 2;
              A[0][5][1] = 'L';
              B[0][5][1] = 6;
              A[0][6][0] = 'F';
              B[0][6][0] = 5;
              A[0][6][1] = 'R';
              B[0][6][1] = 2;
              A[0][7][0] = 'R';
              B[0][7][0] = 0;
              A[0][7][1] = 'L';
              B[0][7][1] = 0;
            }
            if(loop==23){
              K = 1;
              M[0] = 10;
              A[0][0][0] = 'F';
              B[0][0][0] = 7;
              A[0][0][1] = 'R';
              B[0][0][1] = 1;
              A[0][1][0] = 'F';
              B[0][1][0] = 1;
              A[0][1][1] = 'R';
              B[0][1][1] = 7;
              A[0][2][0] = 'F';
              B[0][2][0] = 0;
              A[0][2][1] = 'R';
              B[0][2][1] = 2;
              A[0][3][0] = 'R';
              B[0][3][0] = 0;
              A[0][3][1] = 'L';
              B[0][3][1] = 4;
              A[0][4][0] = 'F';
              B[0][4][0] = 5;
              A[0][4][1] = 'R';
              B[0][4][1] = 7;
              A[0][5][0] = 'L';
              B[0][5][0] = 8;
              A[0][5][1] = 'L';
              B[0][5][1] = 8;
              A[0][6][0] = 'L';
              B[0][6][0] = 7;
              A[0][6][1] = 'R';
              B[0][6][1] = 5;
              A[0][7][0] = 'R';
              B[0][7][0] = 9;
              A[0][7][1] = 'R';
              B[0][7][1] = 0;
              A[0][8][0] = 'L';
              B[0][8][0] = 3;
              A[0][8][1] = 'R';
              B[0][8][1] = 6;
              A[0][9][0] = 'F';
              B[0][9][0] = 5;
              A[0][9][1] = 'R';
              B[0][9][1] = 8;
            }
            if(loop==24){
              K = 1;
              M[0] = 11;
              A[0][0][0] = 'F';
              B[0][0][0] = 0;
              A[0][0][1] = 'L';
              B[0][0][1] = 8;
              A[0][1][0] = 'L';
              B[0][1][0] = 9;
              A[0][1][1] = 'L';
              B[0][1][1] = 4;
              A[0][2][0] = 'R';
              B[0][2][0] = 8;
              A[0][2][1] = 'L';
              B[0][2][1] = 9;
              A[0][3][0] = 'R';
              B[0][3][0] = 9;
              A[0][3][1] = 'R';
              B[0][3][1] = 8;
              A[0][4][0] = 'R';
              B[0][4][0] = 5;
              A[0][4][1] = 'L';
              B[0][4][1] = 3;
              A[0][5][0] = 'F';
              B[0][5][0] = 7;
              A[0][5][1] = 'R';
              B[0][5][1] = 9;
              A[0][6][0] = 'F';
              B[0][6][0] = 6;
              A[0][6][1] = 'L';
              B[0][6][1] = 7;
              A[0][7][0] = 'R';
              B[0][7][0] = 0;
              A[0][7][1] = 'R';
              B[0][7][1] = 3;
              A[0][8][0] = 'L';
              B[0][8][0] = 10;
              A[0][8][1] = 'L';
              B[0][8][1] = 10;
              A[0][9][0] = 'F';
              B[0][9][0] = 3;
              A[0][9][1] = 'R';
              B[0][9][1] = 8;
              A[0][10][0] = 'F';
              B[0][10][0] = 2;
              A[0][10][1] = 'R';
              B[0][10][1] = 7;
            }
            for(i=(0);i<(N);i++){
              for(j=(0);j<(N);j++){
                cover[i][j] = 0;
              }
            }
            add_cover(0);
            ok = 0;
            for(i=(0);i<(N);i++){
              for(j=(0);j<(N);j++){
                if(cover[i][j]){
                  ok++;
                }
              }
            }
            if(ok==N*N && res_M[0] * AM + res_Kabe * AW > M[0] * AM + Kabe * AW){
              int m;
              res_M[0] = M[0];
              res_I0[0] = I0[0];
              res_J0[0] = J0[0];
              res_D0[0] = D0[0];
              for(m=(0);m<(M[0]);m++){
                res_A[0][m][0] = A[0][m][0];
              }
              for(m=(0);m<(M[0]);m++){
                res_B[0][m][0] = B[0][m][0];
              }
              for(m=(0);m<(M[0]);m++){
                res_A[0][m][1] = A[0][m][1];
              }
              for(m=(0);m<(M[0]);m++){
                res_B[0][m][1] = B[0][m][1];
              }
              res_Kabe = Kabe;
              for(i=(0);i<(N);i++){
                for(j=(0);j<(N-1);j++){
                  res_V[i][j] = 0;
                }
              }
              for(i=(0);i<(N-1);i++){
                for(j=(0);j<(N);j++){
                  res_H[i][j] = 0;
                }
              }
              if(Kabe){
                res_V[ki][kj] = 1;
              }
            }
          }
        }
      }
    }
    if(Kabe){
      V[ki][kj] = 0;
    }
  }
}
int dist[400][4][400];
char commA[400][4][400];
char commB[400][4][400];
int nexsA[400][4][400];
int nexsB[400][4][400];
int next1[400][4][400];
int next2[400][4][400];
int gogo(int i, int j, int d, int ca, int na, int cb, int nb, int &ni, int &nj, int &nd){
  int step = 0;
  int nni;
  int nnj;
  int nnd;
  int mova;
  ni = i;
  nj = j;
  nd = d;
  for(;;){
    step++;
    if(step==22){
      return 0;
    }
    mova = is_movable(ni,nj,nd);
    if( (mova==1 && com[ca]=='F') || (mova==0 && com[cb]=='F') ){
      ni += dx[nd];
      nj += dy[nd];
      if( (mova==1 && na==1) || (mova==0 && nb==1) ){
        break;
      }
    }
    else if( (mova==1 && com[ca]=='R') || (mova==0 && com[cb]=='R') ){
      nd = (nd+1)%4;
      if( (mova==1 && na==1) || (mova==0 && nb==1) ){
        break;
      }
    }
    else{
      nd = (nd+3)%4;
      if( (mova==1 && na==1) || (mova==0 && nb==1) ){
        break;
      }
    }
  }
  return 1;
}
int doit(int pxy[]){
  int i;
  int j;
  int k;
  int c;
  int d;
  int ni;
  int nj;
  int s;
  int nnij;
  int nnd;
  int m;
  static int vis[400];
  M[0] = 0;
  I0[0] = J0[0] = 0;
  D0[0] = 1;
  for(i=(0);i<(N*N);i++){
    vis[i] = 0;
  }
  vis[0] = 1;
  i = I0[0];
  j = J0[0];
  d = D0[0];
  s = 0;
  pxy[N*N] = 0;
  for(c=(0);c<(N*N+1);c++){
    if(!vis[pxy[c]] || c==N*N){
      ni = pxy[c] / N;
      nj = pxy[c] % N;
      while(i != ni || j != nj){
        A[0][s][0] = commA[i*N+j][d][ni*N+nj];
        A[0][s][1] = commB[i*N+j][d][ni*N+nj];
        B[0][s][0] = s + nexsA[i*N+j][d][ni*N+nj];
        B[0][s][1] = s + nexsB[i*N+j][d][ni*N+nj];
        nnij = next1[i*N+j][d][ni*N+nj];
        nnd  = next2[i*N+j][d][ni*N+nj];
        i = nnij / N;
        j = nnij % N;
        d = nnd;
        s++;
        vis[i*N+j] = 1;
      }
      if(s > 1650){
        break;
      }
    }
  }
  if(d != D0[0]){
    A[0][s][0] = 'R';
    A[0][s][1] = 'R';
    B[0][s][0] = s + 1;
    B[0][s][1] = s + 1;
    d = (d+1) % 4;
    s++;
  }
  M[0] = s;
  for(i=(0);i<(s);i++){
    B[0][i][0] %= s;
  }
  for(i=(0);i<(s);i++){
    B[0][i][1] %= s;
  }
  if(res_M[0] * AM + res_Kabe * AW > M[0] * AM){
    res_M[0] = M[0];
    res_I0[0] = I0[0];
    res_J0[0] = J0[0];
    res_D0[0] = D0[0];
    for(m=(0);m<(M[0]);m++){
      res_A[0][m][0] = A[0][m][0];
    }
    for(m=(0);m<(M[0]);m++){
      res_B[0][m][0] = B[0][m][0];
    }
    for(m=(0);m<(M[0]);m++){
      res_A[0][m][1] = A[0][m][1];
    }
    for(m=(0);m<(M[0]);m++){
      res_B[0][m][1] = B[0][m][1];
    }
    res_Kabe = 0;
    for(i=(0);i<(N);i++){
      for(j=(0);j<(N-1);j++){
        res_V[i][j] = 0;
      }
    }
    for(i=(0);i<(N-1);i++){
      for(j=(0);j<(N);j++){
        res_H[i][j] = 0;
      }
    }
  }
  return s;
}
double solver(){
  int i;
  int j;
  int k;
  int m;
  int ok;
  int p;
  int NN;
  int ans;
  double t;
  int cells;
  int px[410];
  int py[410];
  int pxy[410];
  int now_score;
  int tmp_score;
  int tmp_xy[410];
  timer.set();
  rd(N);
  rd(AK);
  rd(AM);
  rd(AW);
  {
    int TnpbgAiR;
    for(TnpbgAiR=(0);TnpbgAiR<(N);TnpbgAiR++){
      rd(V[TnpbgAiR]);
    }
  }
  {
    int DqkhdKrO;
    for(DqkhdKrO=(0);DqkhdKrO<(N-1);DqkhdKrO++){
      rd(H[DqkhdKrO]);
    }
  }
  for(i=(0);i<(N);i++){
    for(j=(0);j<(N-1);j++){
      V[i][j] -= '0';
    }
  }
  for(i=(0);i<(N-1);i++){
    for(j=(0);j<(N);j++){
      H[i][j] -= '0';
    }
  }
  NN = N*N;
  for(i=(0);i<(NN);i++){
    for(j=(0);j<(4);j++){
      for(k=(0);k<(NN);k++){
        dist[i][j][k] = 1073709056;
      }
    }
  }
  for(i=(0);i<(NN);i++){
    for(j=(0);j<(4);j++){
      dist[i][j][i] = 0;
    }
  }
  K = 1;
  for(;;){
    int ok = 0;
    int ca;
    int cb;
    int na;
    int nb;
    int ni;
    int nj;
    int nd;
    for(i=(0);i<(NN);i++){
      for(j=(0);j<(4);j++){
        for(ca=(0);ca<(3);ca++){
          for(cb=(1);cb<(3);cb++){
            for(na=(0);na<(2);na++){
              for(nb=(0);nb<(2);nb++){
                if(gogo(i/N, i%N, j, ca, na, cb, nb, ni, nj, nd) == 0){
                  continue;
                }
                for(k=(0);k<(NN);k++){
                  if(dist[i][j][k] > dist[ni*N+nj][nd][k] + 1){
                    dist[i][j][k] = dist[ni*N+nj][nd][k] + 1;
                    commA[i][j][k] = com[ca];
                    nexsA[i][j][k] = na;
                    commB[i][j][k] = com[cb];
                    nexsB[i][j][k] = nb;
                    next1[i][j][k] = ni*N+nj;
                    next2[i][j][k] = nd;
                    ok++;
                  }
                }
              }
            }
          }
        }
      }
    }
    if(!ok){
      break;
    }
  }
  res_M[0] = 1600;
  res_Kabe = 0;
  umekomi();
  cells = N * N;
  for(i=(0);i<(cells);i++){
    pxy[i] = i;
  }
  for(i=(0);i<(cells);i++){
    px[i] = pxy[i] / N;
    py[i] = pxy[i] % N;
  }
  now_score = doit(pxy);
  for(;;){
    t = ( TL - timer.get() ) / TL;
    if(t < 0){
      break;
    }
    for(i=(0);i<(cells);i++){
      tmp_xy[i] = pxy[i];
    }
    if(rnd.getUni() < 0.5){
      i = rnd.get(cells);
      j = rnd.get(cells);
      while(i==j){
        j = rnd.get(cells);
      }
      swap(tmp_xy[i], tmp_xy[j]);
    }
    else{
      i = rnd.get(cells);
      j = rnd.get(cells);
      while(i==j){
        j = rnd.get(cells);
      }
      if(i > j){
        swap(i, j);
      }
      reverse(tmp_xy+i, tmp_xy+j);
    }
    tmp_score = doit(tmp_xy);
    if(tmp_score <= now_score){
      now_score = tmp_score;
      for(i=(0);i<(cells);i++){
        pxy[i] = tmp_xy[i];
      }
    }
    else{
    }
  }
  wt_L(K);
  wt_L('\n');
  for(k=(0);k<(K);k++){
    wt_L(res_M[k]);
    wt_L(' ');
    wt_L(res_I0[k]);
    wt_L(' ');
    wt_L(res_J0[k]);
    wt_L(' ');
    wt_L(dir[res_D0[k]]);
    wt_L('\n');
    for(m=(0);m<(res_M[k]);m++){
      wt_L(res_A[k][m][0]);
      wt_L(' ');
      wt_L(res_B[k][m][0]);
      wt_L(' ');
      wt_L(res_A[k][m][1]);
      wt_L(' ');
      wt_L(res_B[k][m][1]);
      wt_L('\n');
    }
  }
  for(i=(0);i<(N);i++){
    for(j=(0);j<(N-1);j++){
      V[i][j] = '0' + res_V[i][j];
    }
  }
  for(i=(0);i<(N-1);i++){
    for(j=(0);j<(N);j++){
      H[i][j] = '0' + res_H[i][j];
    }
  }
  {
    int DQE7Sh4i;
    for(DQE7Sh4i=(0);DQE7Sh4i<(N);DQE7Sh4i++){
      wt_L(V[DQE7Sh4i]);
      wt_L('\n');
    }
  }
  {
    int bmvZK7G7;
    for(bmvZK7G7=(0);bmvZK7G7<(N-1);bmvZK7G7++){
      wt_L(H[bmvZK7G7]);
      wt_L('\n');
    }
  }
  return res_M[0];
}
int main(){
  if(LOCAL){
    int i;
    double score = 0;
    double s;
    for(i=(0);i<(TEST_CASE);i++){
      s = solver();
      score += s;
      fprintf(stderr, "CASE %d: %f: %f\n", i, s, score);
    }
    fprintf(stderr, "SCORE %f\n", score);
    fprintf(stderr, "SCORE %f * 1e9 (300 cases)\n", score*300/1e9/TEST_CASE);
  }
  else{
    double score;
    score = solver();
    fprintf(stderr, "SCORE %f\n", score);
  }
  return 0;
}
template<class T> inline void wt_L(const vector<T> &x){
  int fg = 0;
  for(auto a : x){
    if(fg){
      my_putchar_unlocked(' ');
    }
    fg = 1;
    wt_L(a);
  }
}
template<class T> inline void wt_L(const set<T> &x){
  int fg = 0;
  for(auto a : x){
    if(fg){
      my_putchar_unlocked(' ');
    }
    fg = 1;
    wt_L(a);
  }
}
template<class T> inline void wt_L(const multiset<T> &x){
  int fg = 0;
  for(auto a : x){
    if(fg){
      my_putchar_unlocked(' ');
    }
    fg = 1;
    wt_L(a);
  }
}
template<class T1, class T2> inline void wt_L(const pair<T1,T2> x){
  wt_L(x.first);
  my_putchar_unlocked(' ');
  wt_L(x.second);
}
// cLay version 20250308-1

// --- original code ---
// const int LOCAL = 0;
// const int TEST_CASE = 20;
// const double TL = 1.9;
// 
// // cat master_in/inA/* > in
// 
// Timer timer;
// Rand rnd;
// 
// int N, AK, AM, AW;
// char V[20][21], H[19][22];
// 
// int K, M[500], I0[500], J0[500], D0[500];
// char A[500][2000][2];
// int B[500][2000][2];
// 
// int res_M[500], res_I0[500], res_J0[500], res_D0[500];
// char res_A[500][2000][2];
// int res_B[500][2000][2];
// char res_V[20][21], res_H[19][22]; int res_Kabe;
// 
// const char *dir = "URDL";
// int dx[4] = {-1,0,1,0};
// int dy[4] = {0,1,0,-1};
// 
// const char *com = "FRL";
// 
// int cover[20][20];
// 
// int is_movable(int i, int j, int d){
//   int ni, nj;
//   ni = i + dx[d];
//   nj = j + dy[d];
//   if(ni < 0 || ni >= N || nj < 0 || nj >= N) return 0;
//   if(i != ni && H[min(i,ni)][j]) return 0;
//   if(j != nj && V[i][min(j,nj)]) return 0;
//   return 1;
// }
// 
// 
// 
// 
// void add_cover(int ind){
//   static int vis[20][20][4][2000];
//   int mm = M[ind];
//   int i, j, d, m, bi, bj, bd, bm, mova;
// 
//   rep(i,N) rep(j,N) rep(d,4) rep(m,mm) vis[i][j][d][m] = 0;
//   i = I0[ind];
//   j = J0[ind];
//   d = D0[ind];
//   m = 0;
// 
//   for(;;){
//     vis[i][j][d][m]++;
//     if(vis[i][j][d][m]==2) cover[i][j]++;
//     if(vis[i][j][d][m]==3) break;
//     bi = i;
//     bj = j;
//     bd = d;
//     bm = m;
//     mova = is_movable(i,j,d);
// 
//     if(A[ind][m][1-mova] == 'F'){
//       i += dx[d];
//       j += dy[d];
//       m = B[ind][m][1-mova];
//     }else if(A[ind][m][1-mova] == 'R'){
//       d = (d+1)%4;
//       m = B[ind][m][1-mova];
//     }else if(A[ind][m][1-mova] == 'L'){
//       d = (d+3)%4;
//       m = B[ind][m][1-mova];
//     }
//   }
// }
// 
// 
// 
// void umekomi(){
//   int i, j, k, ok, loop, loop2;
//   int ki, kj, Kabe;
// 
//   rep(loop2,20){
//     if(loop2==0){
//       Kabe = 0;
//     } else {
//       Kabe = 1;
//       ki = rnd.get(N);
//       if(ki)
//       kj = rnd.get(N-1);
//       while(V[ki][kj]) ki = rnd.get(N), kj = rnd.get(N-1);
//     }
//     if(Kabe) V[ki][kj] = 1;
//     rep(loop,25){
//       rep(I0[0], 3) rep(J0[0], 3) rep(D0[0],4){
//       if(loop==0){
//         K = 1;
//         M[0] = 4;
//         A[0][0][0] = 'R'; B[0][0][0] = 1; A[0][0][1] = 'R'; B[0][0][1] = 1;
//         A[0][1][0] = 'F'; B[0][1][0] = 2; A[0][1][1] = 'L'; B[0][1][1] = 3;
//         A[0][2][0] = 'L'; B[0][2][0] = 3; A[0][2][1] = 'L'; B[0][2][1] = 1;
//         A[0][3][0] = 'F'; B[0][3][0] = 0; A[0][3][1] = 'R'; B[0][3][1] = 3;
//       }
//       if(loop==1){
//         K = 1;
//         M[0] = 4;
//         A[0][0][0] = 'L'; B[0][0][0] = 1; A[0][0][1] = 'L'; B[0][0][1] = 2;
//         A[0][1][0] = 'F'; B[0][1][0] = 3; A[0][1][1] = 'R'; B[0][1][1] = 2;
//         A[0][2][0] = 'F'; B[0][2][0] = 0; A[0][2][1] = 'R'; B[0][2][1] = 1;
//         A[0][3][0] = 'R'; B[0][3][0] = 2; A[0][3][1] = 'L'; B[0][3][1] = 1;
//       }
//       if(loop==2){
//         K = 1;
//         M[0] = 5;
//         A[0][0][0] = 'F'; B[0][0][0] = 0; A[0][0][1] = 'R'; B[0][0][1] = 1;
//         A[0][1][0] = 'F'; B[0][1][0] = 4; A[0][1][1] = 'R'; B[0][1][1] = 0;
//         A[0][2][0] = 'R'; B[0][2][0] = 0; A[0][2][1] = 'L'; B[0][2][1] = 2;
//         A[0][3][0] = 'F'; B[0][3][0] = 3; A[0][3][1] = 'R'; B[0][3][1] = 2;
//         A[0][4][0] = 'R'; B[0][4][0] = 3; A[0][4][1] = 'R'; B[0][4][1] = 4;
//       }
//       if(loop==3){
//         K = 1;
//         M[0] = 5;
//         A[0][0][0] = 'L'; B[0][0][0] = 3; A[0][0][1] = 'R'; B[0][0][1] = 2;
//         A[0][1][0] = 'R'; B[0][1][0] = 2; A[0][1][1] = 'R'; B[0][1][1] = 3;
//         A[0][2][0] = 'F'; B[0][2][0] = 0; A[0][2][1] = 'L'; B[0][2][1] = 3;
//         A[0][3][0] = 'F'; B[0][3][0] = 1; A[0][3][1] = 'L'; B[0][3][1] = 4;
//         A[0][4][0] = 'L'; B[0][4][0] = 4; A[0][4][1] = 'L'; B[0][4][1] = 2;
//       }
//       if(loop==4){
//         K = 1;
//         M[0] = 5;
//         A[0][0][0] = 'F'; B[0][0][0] = 4; A[0][0][1] = 'R'; B[0][0][1] = 1;
//         A[0][1][0] = 'F'; B[0][1][0] = 2; A[0][1][1] = 'L'; B[0][1][1] = 0;
//         A[0][2][0] = 'L'; B[0][2][0] = 0; A[0][2][1] = 'L'; B[0][2][1] = 1;
//         A[0][3][0] = 'F'; B[0][3][0] = 1; A[0][3][1] = 'R'; B[0][3][1] = 0;
//         A[0][4][0] = 'R'; B[0][4][0] = 1; A[0][4][1] = 'R'; B[0][4][1] = 0;
//       }
//       if(loop==5){
//         K = 1;
//         M[0] = 5;
//         A[0][0][0] = 'F'; B[0][0][0] = 4; A[0][0][1] = 'L'; B[0][0][1] = 0;
//         A[0][1][0] = 'F'; B[0][1][0] = 2; A[0][1][1] = 'R'; B[0][1][1] = 0;
//         A[0][2][0] = 'R'; B[0][2][0] = 0; A[0][2][1] = 'R'; B[0][2][1] = 1;
//         A[0][3][0] = 'R'; B[0][3][0] = 2; A[0][3][1] = 'L'; B[0][3][1] = 2;
//         A[0][4][0] = 'L'; B[0][4][0] = 1; A[0][4][1] = 'L'; B[0][4][1] = 1;
//       }
//       if(loop==6){
//         K = 1;
//         M[0] = 5;
//         A[0][0][0] = 'F'; B[0][0][0] = 1; A[0][0][1] = 'L'; B[0][0][1] = 0;
//         A[0][1][0] = 'L'; B[0][1][0] = 4; A[0][1][1] = 'L'; B[0][1][1] = 4;
//         A[0][2][0] = 'R'; B[0][2][0] = 0; A[0][2][1] = 'R'; B[0][2][1] = 4;
//         A[0][3][0] = 'L'; B[0][3][0] = 3; A[0][3][1] = 'R'; B[0][3][1] = 0;
//         A[0][4][0] = 'F'; B[0][4][0] = 2; A[0][4][1] = 'L'; B[0][4][1] = 3;
//       }
//       if(loop==7){
//         K = 1;
//         M[0] = 5;
//         A[0][0][0] = 'R'; B[0][0][0] = 1; A[0][0][1] = 'R'; B[0][0][1] = 2;
//         A[0][1][0] = 'F'; B[0][1][0] = 4; A[0][1][1] = 'L'; B[0][1][1] = 3;
//         A[0][2][0] = 'L'; B[0][2][0] = 1; A[0][2][1] = 'R'; B[0][2][1] = 3;
//         A[0][3][0] = 'F'; B[0][3][0] = 2; A[0][3][1] = 'L'; B[0][3][1] = 1;
//         A[0][4][0] = 'R'; B[0][4][0] = 3; A[0][4][1] = 'R'; B[0][4][1] = 1;
//       }
//       if(loop==8){
//         K = 1;
//         M[0] = 5;
//         A[0][0][0] = 'L'; B[0][0][0] = 4; A[0][0][1] = 'R'; B[0][0][1] = 1;
//         A[0][1][0] = 'F'; B[0][1][0] = 0; A[0][1][1] = 'R'; B[0][1][1] = 3;
//         A[0][2][0] = 'R'; B[0][2][0] = 3; A[0][2][1] = 'R'; B[0][2][1] = 1;
//         A[0][3][0] = 'F'; B[0][3][0] = 3; A[0][3][1] = 'R'; B[0][3][1] = 4;
//         A[0][4][0] = 'R'; B[0][4][0] = 1; A[0][4][1] = 'R'; B[0][4][1] = 2;
//       }
//       if(loop==9){
//         K = 1;
//         M[0] = 5;
//         A[0][0][0] = 'L'; B[0][0][0] = 4; A[0][0][1] = 'L'; B[0][0][1] = 4;
//         A[0][1][0] = 'R'; B[0][1][0] = 4; A[0][1][1] = 'L'; B[0][1][1] = 1;
//         A[0][2][0] = 'F'; B[0][2][0] = 0; A[0][2][1] = 'R'; B[0][2][1] = 2;
//         A[0][3][0] = 'R'; B[0][3][0] = 2; A[0][3][1] = 'R'; B[0][3][1] = 4;
//         A[0][4][0] = 'F'; B[0][4][0] = 3; A[0][4][1] = 'L'; B[0][4][1] = 2;
//       }
//       if(loop==10){
//         K = 1;
//         M[0] = 5;
//         A[0][0][0] = 'L'; B[0][0][0] = 3; A[0][0][1] = 'L'; B[0][0][1] = 3;
//         A[0][1][0] = 'F'; B[0][1][0] = 0; A[0][1][1] = 'R'; B[0][1][1] = 4;
//         A[0][2][0] = 'L'; B[0][2][0] = 1; A[0][2][1] = 'L'; B[0][2][1] = 1;
//         A[0][3][0] = 'R'; B[0][3][0] = 4; A[0][3][1] = 'R'; B[0][3][1] = 3;
//         A[0][4][0] = 'F'; B[0][4][0] = 1; A[0][4][1] = 'L'; B[0][4][1] = 2;
//       }
//       if(loop==11){
//         K = 1;
//         M[0] = 6;
//         A[0][0][0] = 'L'; B[0][0][0] = 1; A[0][0][1] = 'L'; B[0][0][1] = 3;
//         A[0][1][0] = 'F'; B[0][1][0] = 5; A[0][1][1] = 'R'; B[0][1][1] = 3;
//         A[0][2][0] = 'F'; B[0][2][0] = 5; A[0][2][1] = 'R'; B[0][2][1] = 3;
//         A[0][3][0] = 'F'; B[0][3][0] = 0; A[0][3][1] = 'L'; B[0][3][1] = 1;
//         A[0][4][0] = 'F'; B[0][4][0] = 3; A[0][4][1] = 'R'; B[0][4][1] = 0;
//         A[0][5][0] = 'R'; B[0][5][0] = 3; A[0][5][1] = 'R'; B[0][5][1] = 1;
//       }
//       if(loop==12){
//         K = 1;
//         M[0] = 6;
//         A[0][0][0] = 'R'; B[0][0][0] = 5; A[0][0][1] = 'R'; B[0][0][1] = 5;
//         A[0][1][0] = 'R'; B[0][1][0] = 3; A[0][1][1] = 'L'; B[0][1][1] = 2;
//         A[0][2][0] = 'F'; B[0][2][0] = 2; A[0][2][1] = 'R'; B[0][2][1] = 0;
//         A[0][3][0] = 'F'; B[0][3][0] = 1; A[0][3][1] = 'L'; B[0][3][1] = 4;
//         A[0][4][0] = 'L'; B[0][4][0] = 2; A[0][4][1] = 'R'; B[0][4][1] = 3;
//         A[0][5][0] = 'F'; B[0][5][0] = 5; A[0][5][1] = 'L'; B[0][5][1] = 3;
//       }
//       if(loop==13){
//         K = 1;
//         M[0] = 6;
//         A[0][0][0] = 'L'; B[0][0][0] = 1; A[0][0][1] = 'L'; B[0][0][1] = 4;
//         A[0][1][0] = 'F'; B[0][1][0] = 1; A[0][1][1] = 'L'; B[0][1][1] = 2;
//         A[0][2][0] = 'L'; B[0][2][0] = 4; A[0][2][1] = 'R'; B[0][2][1] = 5;
//         A[0][3][0] = 'F'; B[0][3][0] = 4; A[0][3][1] = 'R'; B[0][3][1] = 3;
//         A[0][4][0] = 'F'; B[0][4][0] = 4; A[0][4][1] = 'L'; B[0][4][1] = 5;
//         A[0][5][0] = 'F'; B[0][5][0] = 0; A[0][5][1] = 'R'; B[0][5][1] = 2;
//       }
//       if(loop==14){
//         K = 1;
//         M[0] = 6;
//         A[0][0][0] = 'L'; B[0][0][0] = 1; A[0][0][1] = 'R'; B[0][0][1] = 5;
//         A[0][1][0] = 'R'; B[0][1][0] = 5; A[0][1][1] = 'R'; B[0][1][1] = 4;
//         A[0][2][0] = 'F'; B[0][2][0] = 2; A[0][2][1] = 'R'; B[0][2][1] = 1;
//         A[0][3][0] = 'L'; B[0][3][0] = 0; A[0][3][1] = 'L'; B[0][3][1] = 5;
//         A[0][4][0] = 'R'; B[0][4][0] = 2; A[0][4][1] = 'L'; B[0][4][1] = 3;
//         A[0][5][0] = 'F'; B[0][5][0] = 0; A[0][5][1] = 'R'; B[0][5][1] = 3;
//       }
//       if(loop==15){
//         K = 1;
//         M[0] = 7;
//         A[0][0][0] = 'F'; B[0][0][0] = 5; A[0][0][1] = 'L'; B[0][0][1] = 6;
//         A[0][1][0] = 'F'; B[0][1][0] = 5; A[0][1][1] = 'R'; B[0][1][1] = 5;
//         A[0][2][0] = 'R'; B[0][2][0] = 0; A[0][2][1] = 'R'; B[0][2][1] = 1;
//         A[0][3][0] = 'R'; B[0][3][0] = 4; A[0][3][1] = 'L'; B[0][3][1] = 0;
//         A[0][4][0] = 'R'; B[0][4][0] = 3; A[0][4][1] = 'R'; B[0][4][1] = 3;
//         A[0][5][0] = 'L'; B[0][5][0] = 6; A[0][5][1] = 'L'; B[0][5][1] = 4;
//         A[0][6][0] = 'F'; B[0][6][0] = 2; A[0][6][1] = 'R'; B[0][6][1] = 6;
//       }
//       if(loop==16){
//         K = 1;
//         M[0] = 7;
//         A[0][0][0] = 'F'; B[0][0][0] = 0; A[0][0][1] = 'L'; B[0][0][1] = 5;
//         A[0][1][0] = 'L'; B[0][1][0] = 1; A[0][1][1] = 'R'; B[0][1][1] = 4;
//         A[0][2][0] = 'F'; B[0][2][0] = 4; A[0][2][1] = 'L'; B[0][2][1] = 6;
//         A[0][3][0] = 'F'; B[0][3][0] = 3; A[0][3][1] = 'L'; B[0][3][1] = 6;
//         A[0][4][0] = 'R'; B[0][4][0] = 6; A[0][4][1] = 'L'; B[0][4][1] = 2;
//         A[0][5][0] = 'L'; B[0][5][0] = 3; A[0][5][1] = 'R'; B[0][5][1] = 4;
//         A[0][6][0] = 'L'; B[0][6][0] = 2; A[0][6][1] = 'L'; B[0][6][1] = 5;
//       }
//       if(loop==17){
//         K = 1;
//         M[0] = 7;
//         A[0][0][0] = 'F'; B[0][0][0] = 2; A[0][0][1] = 'L'; B[0][0][1] = 4;
//         A[0][1][0] = 'F'; B[0][1][0] = 3; A[0][1][1] = 'L'; B[0][1][1] = 0;
//         A[0][2][0] = 'R'; B[0][2][0] = 1; A[0][2][1] = 'R'; B[0][2][1] = 0;
//         A[0][3][0] = 'L'; B[0][3][0] = 0; A[0][3][1] = 'R'; B[0][3][1] = 1;
//         A[0][4][0] = 'F'; B[0][4][0] = 3; A[0][4][1] = 'L'; B[0][4][1] = 0;
//         A[0][5][0] = 'R'; B[0][5][0] = 0; A[0][5][1] = 'R'; B[0][5][1] = 2;
//         A[0][6][0] = 'F'; B[0][6][0] = 5; A[0][6][1] = 'L'; B[0][6][1] = 3;
//       }
//       if(loop==18){
//         K = 1;
//         M[0] = 7;
//         A[0][0][0] = 'F'; B[0][0][0] = 0; A[0][0][1] = 'R'; B[0][0][1] = 6;
//         A[0][1][0] = 'R'; B[0][1][0] = 4; A[0][1][1] = 'L'; B[0][1][1] = 0;
//         A[0][2][0] = 'L'; B[0][2][0] = 0; A[0][2][1] = 'L'; B[0][2][1] = 5;
//         A[0][3][0] = 'F'; B[0][3][0] = 3; A[0][3][1] = 'L'; B[0][3][1] = 4;
//         A[0][4][0] = 'F'; B[0][4][0] = 4; A[0][4][1] = 'L'; B[0][4][1] = 2;
//         A[0][5][0] = 'F'; B[0][5][0] = 0; A[0][5][1] = 'R'; B[0][5][1] = 3;
//         A[0][6][0] = 'F'; B[0][6][0] = 1; A[0][6][1] = 'L'; B[0][6][1] = 3;
//       }
//       if(loop==19){
//         K = 1;
//         M[0] = 8;
//         A[0][0][0] = 'F'; B[0][0][0] = 7; A[0][0][1] = 'L'; B[0][0][1] = 3;
//         A[0][1][0] = 'L'; B[0][1][0] = 1; A[0][1][1] = 'L'; B[0][1][1] = 4;
//         A[0][2][0] = 'R'; B[0][2][0] = 5; A[0][2][1] = 'R'; B[0][2][1] = 0;
//         A[0][3][0] = 'R'; B[0][3][0] = 6; A[0][3][1] = 'L'; B[0][3][1] = 3;
//         A[0][4][0] = 'R'; B[0][4][0] = 3; A[0][4][1] = 'R'; B[0][4][1] = 5;
//         A[0][5][0] = 'F'; B[0][5][0] = 6; A[0][5][1] = 'L'; B[0][5][1] = 5;
//         A[0][6][0] = 'L'; B[0][6][0] = 7; A[0][6][1] = 'L'; B[0][6][1] = 7;
//         A[0][7][0] = 'F'; B[0][7][0] = 2; A[0][7][1] = 'R'; B[0][7][1] = 3;
//       }
//       if(loop==20){
//         K = 1;
//         M[0] = 8;
//         A[0][0][0] = 'R'; B[0][0][0] = 2; A[0][0][1] = 'L'; B[0][0][1] = 0;
//         A[0][1][0] = 'R'; B[0][1][0] = 1; A[0][1][1] = 'L'; B[0][1][1] = 6;
//         A[0][2][0] = 'F'; B[0][2][0] = 5; A[0][2][1] = 'L'; B[0][2][1] = 7;
//         A[0][3][0] = 'R'; B[0][3][0] = 2; A[0][3][1] = 'R'; B[0][3][1] = 7;
//         A[0][4][0] = 'F'; B[0][4][0] = 2; A[0][4][1] = 'L'; B[0][4][1] = 2;
//         A[0][5][0] = 'L'; B[0][5][0] = 7; A[0][5][1] = 'L'; B[0][5][1] = 2;
//         A[0][6][0] = 'L'; B[0][6][0] = 6; A[0][6][1] = 'R'; B[0][6][1] = 3;
//         A[0][7][0] = 'F'; B[0][7][0] = 3; A[0][7][1] = 'R'; B[0][7][1] = 2;
//       }
//       if(loop==21){
//         K = 1;
//         M[0] = 8;
//         A[0][0][0] = 'R'; B[0][0][0] = 7; A[0][0][1] = 'L'; B[0][0][1] = 7;
//         A[0][1][0] = 'R'; B[0][1][0] = 6; A[0][1][1] = 'R'; B[0][1][1] = 5;
//         A[0][2][0] = 'F'; B[0][2][0] = 7; A[0][2][1] = 'R'; B[0][2][1] = 5;
//         A[0][3][0] = 'L'; B[0][3][0] = 7; A[0][3][1] = 'L'; B[0][3][1] = 6;
//         A[0][4][0] = 'F'; B[0][4][0] = 5; A[0][4][1] = 'L'; B[0][4][1] = 4;
//         A[0][5][0] = 'F'; B[0][5][0] = 6; A[0][5][1] = 'L'; B[0][5][1] = 2;
//         A[0][6][0] = 'L'; B[0][6][0] = 2; A[0][6][1] = 'L'; B[0][6][1] = 3;
//         A[0][7][0] = 'R'; B[0][7][0] = 5; A[0][7][1] = 'R'; B[0][7][1] = 2;
//       }
//       if(loop==22){
//         K = 1;
//         M[0] = 8;
//         A[0][0][0] = 'R'; B[0][0][0] = 6; A[0][0][1] = 'L'; B[0][0][1] = 2;
//         A[0][1][0] = 'L'; B[0][1][0] = 0; A[0][1][1] = 'R'; B[0][1][1] = 4;
//         A[0][2][0] = 'F'; B[0][2][0] = 0; A[0][2][1] = 'R'; B[0][2][1] = 6;
//         A[0][3][0] = 'R'; B[0][3][0] = 2; A[0][3][1] = 'L'; B[0][3][1] = 1;
//         A[0][4][0] = 'L'; B[0][4][0] = 4; A[0][4][1] = 'L'; B[0][4][1] = 2;
//         A[0][5][0] = 'L'; B[0][5][0] = 2; A[0][5][1] = 'L'; B[0][5][1] = 6;
//         A[0][6][0] = 'F'; B[0][6][0] = 5; A[0][6][1] = 'R'; B[0][6][1] = 2;
//         A[0][7][0] = 'R'; B[0][7][0] = 0; A[0][7][1] = 'L'; B[0][7][1] = 0;
//       }
//       if(loop==23){
//         K = 1;
//         M[0] = 10;
//         A[0][0][0] = 'F'; B[0][0][0] = 7; A[0][0][1] = 'R'; B[0][0][1] = 1;
//         A[0][1][0] = 'F'; B[0][1][0] = 1; A[0][1][1] = 'R'; B[0][1][1] = 7;
//         A[0][2][0] = 'F'; B[0][2][0] = 0; A[0][2][1] = 'R'; B[0][2][1] = 2;
//         A[0][3][0] = 'R'; B[0][3][0] = 0; A[0][3][1] = 'L'; B[0][3][1] = 4;
//         A[0][4][0] = 'F'; B[0][4][0] = 5; A[0][4][1] = 'R'; B[0][4][1] = 7;
//         A[0][5][0] = 'L'; B[0][5][0] = 8; A[0][5][1] = 'L'; B[0][5][1] = 8;
//         A[0][6][0] = 'L'; B[0][6][0] = 7; A[0][6][1] = 'R'; B[0][6][1] = 5;
//         A[0][7][0] = 'R'; B[0][7][0] = 9; A[0][7][1] = 'R'; B[0][7][1] = 0;
//         A[0][8][0] = 'L'; B[0][8][0] = 3; A[0][8][1] = 'R'; B[0][8][1] = 6;
//         A[0][9][0] = 'F'; B[0][9][0] = 5; A[0][9][1] = 'R'; B[0][9][1] = 8;
//       }
//       if(loop==24){
//         K = 1;
//         M[0] = 11;
//         A[0][0][0] = 'F'; B[0][0][0] = 0; A[0][0][1] = 'L'; B[0][0][1] = 8;
//         A[0][1][0] = 'L'; B[0][1][0] = 9; A[0][1][1] = 'L'; B[0][1][1] = 4;
//         A[0][2][0] = 'R'; B[0][2][0] = 8; A[0][2][1] = 'L'; B[0][2][1] = 9;
//         A[0][3][0] = 'R'; B[0][3][0] = 9; A[0][3][1] = 'R'; B[0][3][1] = 8;
//         A[0][4][0] = 'R'; B[0][4][0] = 5; A[0][4][1] = 'L'; B[0][4][1] = 3;
//         A[0][5][0] = 'F'; B[0][5][0] = 7; A[0][5][1] = 'R'; B[0][5][1] = 9;
//         A[0][6][0] = 'F'; B[0][6][0] = 6; A[0][6][1] = 'L'; B[0][6][1] = 7;
//         A[0][7][0] = 'R'; B[0][7][0] = 0; A[0][7][1] = 'R'; B[0][7][1] = 3;
//         A[0][8][0] = 'L'; B[0][8][0] = 10; A[0][8][1] = 'L'; B[0][8][1] = 10;
//         A[0][9][0] = 'F'; B[0][9][0] = 3; A[0][9][1] = 'R'; B[0][9][1] = 8;
//         A[0][10][0] = 'F'; B[0][10][0] = 2; A[0][10][1] = 'R'; B[0][10][1] = 7;
//       }
// 
//       rep(i,N) rep(j,N) cover[i][j] = 0;
//         add_cover(0);
// 
//         ok = 0;
//         rep(i,N) rep(j,N) if(cover[i][j]) ok++;
//         if(ok==N*N && res_M[0] * AM + res_Kabe * AW > M[0] * AM + Kabe * AW){
//           res_M[0] = M[0];
//           res_I0[0] = I0[0];
//           res_J0[0] = J0[0];
//           res_D0[0] = D0[0];
//           rep(m,M[0]) res_A[0][m][0] = A[0][m][0];
//           rep(m,M[0]) res_B[0][m][0] = B[0][m][0];
//           rep(m,M[0]) res_A[0][m][1] = A[0][m][1];
//           rep(m,M[0]) res_B[0][m][1] = B[0][m][1];
//           res_Kabe = Kabe;
//           rep(i,N) rep(j,N-1) res_V[i][j] = 0;
//           rep(i,N-1) rep(j,N) res_H[i][j] = 0;
//           if(Kabe) res_V[ki][kj] = 1;
//         }
//       }
//     }
//     if(Kabe) V[ki][kj] = 0;
//   }
// }
// 
// 
// int dist[400][4][400];
// char commA[400][4][400], commB[400][4][400];
// int nexsA[400][4][400], nexsB[400][4][400];
// int next1[400][4][400], next2[400][4][400];
// 
// int gogo(int i, int j, int d, int ca, int na, int cb, int nb, int &ni, int &nj, int &nd){
//   int step = 0;
//   int nni, nnj, nnd, mova;
// 
//   ni = i;
//   nj = j;
//   nd = d;
// 
//   for(;;){
//     step++;
//     if(step==22) return 0;
// 
//     mova = is_movable(ni,nj,nd);
// 
//     if( (mova==1 && com[ca]=='F') || (mova==0 && com[cb]=='F') ){
//       ni += dx[nd];
//       nj += dy[nd];
//       if( (mova==1 && na==1) || (mova==0 && nb==1) ) break;
//     }else if( (mova==1 && com[ca]=='R') || (mova==0 && com[cb]=='R') ){
//       nd = (nd+1)%4;
//       if( (mova==1 && na==1) || (mova==0 && nb==1) ) break;
//     }else{
//       nd = (nd+3)%4;
//       if( (mova==1 && na==1) || (mova==0 && nb==1) ) break;
//     }
//   }
// 
//   return 1;
// }
// 
// 
// int doit(int pxy[]){
//   int i, j, k, c, d, ni, nj, s, nnij, nnd, m;
//   static int vis[400];
// 
//   M[0] = 0;
//   I0[0] = J0[0] = 0;
//   D0[0] = 1;
// 
//   rep(i,N*N) vis[i] = 0;
//   vis[0] = 1;
// 
//   i = I0[0];
//   j = J0[0];
//   d = D0[0];
//   s = 0;
//   pxy[N*N] = 0;
//   rep(c,N*N+1) if(!vis[pxy[c]] || c==N*N){
//     ni = pxy[c] / N;
//     nj = pxy[c] % N;
//     while(i != ni || j != nj){
//       A[0][s][0] = commA[i*N+j][d][ni*N+nj];
//       A[0][s][1] = commB[i*N+j][d][ni*N+nj];
//       B[0][s][0] = s + nexsA[i*N+j][d][ni*N+nj];
//       B[0][s][1] = s + nexsB[i*N+j][d][ni*N+nj];
//       nnij = next1[i*N+j][d][ni*N+nj];
//       nnd  = next2[i*N+j][d][ni*N+nj];
//       i = nnij / N;
//       j = nnij % N;
//       d = nnd;
//       s++;
//       vis[i*N+j] = 1;
//     }
//     if(s > 1650) break;
//   }
//   if(d != D0[0]){
//     A[0][s][0] = 'R';
//     A[0][s][1] = 'R';
//     B[0][s][0] = s + 1;
//     B[0][s][1] = s + 1;
//     d = (d+1) % 4;
//     s++;
//   }
//   M[0] = s;
//   rep(i,s) B[0][i][0] %= s;
//   rep(i,s) B[0][i][1] %= s;
// 
//   if(res_M[0] * AM + res_Kabe * AW > M[0] * AM){
//     res_M[0] = M[0];
//     res_I0[0] = I0[0];
//     res_J0[0] = J0[0];
//     res_D0[0] = D0[0];
//     rep(m,M[0]) res_A[0][m][0] = A[0][m][0];
//     rep(m,M[0]) res_B[0][m][0] = B[0][m][0];
//     rep(m,M[0]) res_A[0][m][1] = A[0][m][1];
//     rep(m,M[0]) res_B[0][m][1] = B[0][m][1];
//     res_Kabe = 0;
//     rep(i,N) rep(j,N-1) res_V[i][j] = 0;
//     rep(i,N-1) rep(j,N) res_H[i][j] = 0;
//   }
// 
//   return s;
// }
// 
// 
// 
// double solver(){
//   int i, j, k, m, ok, p, NN;
//   int ans;
// 
//   double t;
//   int cells, px[410], py[410], pxy[410];
//   int now_score, tmp_score, tmp_xy[410];
// 
//   timer.set();
// 
//   rd(N,AK,AM,AW,V(N),H(N-1));
//   rep(i,N) rep(j,N-1) V[i][j] -= '0';
//   rep(i,N-1) rep(j,N) H[i][j] -= '0';
// 
//   NN = N*N;
//   rep(i,NN) rep(j,4) rep(k,NN) dist[i][j][k] = int_inf;
//   rep(i,NN) rep(j,4) dist[i][j][i] = 0;
// 
//   K = 1;
// 
//   for(;;){
//     int ok = 0;
//     int ca, cb, na, nb, ni, nj, nd;
// 
//     rep(i,NN) rep(j,4) rep(ca,3) rep(cb,1,3) rep(na,2) rep(nb,2){
//       if(gogo(i/N, i%N, j, ca, na, cb, nb, ni, nj, nd) == 0) continue;
//       rep(k,NN) if(dist[i][j][k] > dist[ni*N+nj][nd][k] + 1){
//         dist[i][j][k] = dist[ni*N+nj][nd][k] + 1;
//         commA[i][j][k] = com[ca];
//         nexsA[i][j][k] = na;
//         commB[i][j][k] = com[cb];
//         nexsB[i][j][k] = nb;
//         next1[i][j][k] = ni*N+nj;
//         next2[i][j][k] = nd;
//         ok++;
//       }
//     }
// 
//     if(!ok) break;
//   }
// 
//   res_M[0] = 1600;
//   res_Kabe = 0;
// 
//   umekomi();
// 
//   cells = N * N;
//   rep(i,cells) pxy[i] = i;
//   // random_shuffle(pxy, pxy+cells);
//   rep(i,cells) px[i] = pxy[i] / N, py[i] = pxy[i] % N;
// 
//   now_score = doit(pxy);
// 
//   for(;;){
//     t = ( TL - timer.get() ) / TL;
//     if(t < 0) break;
// 
//     rep(i,cells) tmp_xy[i] = pxy[i];
// 
//     if(rnd.getUni() < 0.5){
//       i = rnd.get(cells);
//       j = rnd.get(cells);
//       while(i==j) j = rnd.get(cells);
//       swap(tmp_xy[i], tmp_xy[j]);
//     } else {
//       i = rnd.get(cells);
//       j = rnd.get(cells);
//       while(i==j) j = rnd.get(cells);
//       if(i > j) swap(i, j);
//       reverse(tmp_xy+i, tmp_xy+j);
//     }
//     
//     tmp_score = doit(tmp_xy);
//     if(tmp_score <= now_score){
//       now_score = tmp_score;
//       rep(i,cells) pxy[i] = tmp_xy[i];
//     } else {
// 
//     }
// 
//   }
// 
//     // ok = 0;
//     // rep(i,N) rep(j,N) if(cover[i][j]) ok++;
//     // if(ok==N*N){
//     //   ans = res_M[0] = M[0];
//     //   res_I0[0] = I0[0];
//     //   res_J0[0] = J0[0];
//     //   res_D0[0] = D0[0];
//     //   rep(m,M[0]) res_A[0][m][0] = A[0][m][0];
//     //   rep(m,M[0]) res_B[0][m][0] = B[0][m][0];
//     //   rep(m,M[0]) res_A[0][m][1] = A[0][m][1];
//     //   rep(m,M[0]) res_B[0][m][1] = B[0][m][1];
//     // }
// 
// 
//   wt(K);
//   rep(k,K){
//     wt(res_M[k], res_I0[k], res_J0[k], dir[res_D0[k]]);
//     rep(m,res_M[k]) wt(res_A[k][m][0], res_B[k][m][0], res_A[k][m][1], res_B[k][m][1]);
//   }
// 
//   rep(i,N) rep(j,N-1) V[i][j] = '0' + res_V[i][j];
//   rep(i,N-1) rep(j,N) H[i][j] = '0' + res_H[i][j];
//   wtLn(V(N));
//   wtLn(H(N-1));
// 
//   return res_M[0];
// }
// 
// {
//   if(LOCAL){
//     int i;
//     double score = 0, s;
//     rep(i, TEST_CASE){
//       s = solver();
//       score += s;
//       fprintf(stderr, "CASE %d: %f: %f\n", i, s, score);
//     }
//     fprintf(stderr, "SCORE %f\n", score);
//     fprintf(stderr, "SCORE %f * 1e9 (300 cases)\n", score*300/1e9/TEST_CASE);
//   } else {
//     double score;
//     score = solver();
//     fprintf(stderr, "SCORE %f\n", score);
//   }
// }

提出情報

提出日時
問題 B - Periodic Patrol Automata (B)
ユーザ LayCurse
言語 C++23 (GCC 15.2.0)
得点 2064508043
コード長 62611 Byte
結果 AC
実行時間 1904 ms
メモリ 24284 KiB

コンパイルエラー

./Main.cpp: In function 'void add_cover(int)':
./Main.cpp:276:7: warning: variable 'bi' set but not used [-Wunused-but-set-variable]
  276 |   int bi;
      |       ^~
./Main.cpp:277:7: warning: variable 'bj' set but not used [-Wunused-but-set-variable]
  277 |   int bj;
      |       ^~
./Main.cpp:278:7: warning: variable 'bd' set but not used [-Wunused-but-set-variable]
  278 |   int bd;
      |       ^~
./Main.cpp:279:7: warning: variable 'bm' set but not used [-Wunused-but-set-variable]
  279 |   int bm;
      |       ^~
./Main.cpp: In function 'void umekomi()':
./Main.cpp:325:7: warning: unused variable 'k' [-Wunused-variable]
  325 |   int k;
      |       ^
./Main.cpp: In function 'int gogo(int, int, int, int, int, int, int, int&, int&, int&)':
./Main.cpp:1151:7: warning: unused variable 'nni' [-Wunused-variable]
 1151 |   int nni;
      |       ^~~
./Main.cpp:1152:7: warning: unused variable 'nnj' [-Wunused-variable]
 1152 |   int nnj;
      |       ^~~
./Main.cpp:1153:7: warning: unused variable 'nnd' [-Wunused-variable]
 1153 |   int nnd;
      |       ^~~
./Main.cpp: In function 'int doit(int*)':
./Main.cpp:1189:7: warning: unused variable 'k' [-Wunused-variable]
 1189 |   int k;
      |       ^
./Main.cpp: In function 'double solver()':
./Main.cpp:1284:7: warning: unused variable 'ok' [-Wunused-variable]
 1284 |   int ok;
      |       ^~
./Main.cpp:1285:7: warning: unused variable 'p' [-Wunused-variable]
 1285 |   int p;
      |       ^
./Main.cpp:1287:7: warning: unused variable 'ans' [-Wunused-variable]
 1287 |   int ans;
      |       ^~~
./Main.cpp:1290:7: warning: variable 'px' set but not used [-Wunused-but-set-variable]
 1290 |   int px[410];
      |       ^~
./Main.cpp:1291:7: warning: variable 'py' set but not used [-Wunused-but-set-variable]
 1291 |   int py[410];
      |       ^~
In function 'umekomi',
    inlined from 'solver' at ./Main.cpp:1379:10:
./Main.cpp:342:21: warning: 'kj' may be used uninitialized [-Wmaybe-uninitialized]
  342 |       while(V[ki][kj]){
      |                     ^
./Main.cpp: In function 'solver':
./Main.cpp:330:7: note: 'kj' was declared here
  330 |   int kj;
      |       ^

ジャッジ結果

セット名 test_ALL
得点 / 配点 2064508043 / 15000000000
結果
AC × 150
セット名 テストケース
test_ALL test_0000.txt, test_0001.txt, test_0002.txt, test_0003.txt, test_0004.txt, test_0005.txt, test_0006.txt, test_0007.txt, test_0008.txt, test_0009.txt, test_0010.txt, test_0011.txt, test_0012.txt, test_0013.txt, test_0014.txt, test_0015.txt, test_0016.txt, test_0017.txt, test_0018.txt, test_0019.txt, test_0020.txt, test_0021.txt, test_0022.txt, test_0023.txt, test_0024.txt, test_0025.txt, test_0026.txt, test_0027.txt, test_0028.txt, test_0029.txt, test_0030.txt, test_0031.txt, test_0032.txt, test_0033.txt, test_0034.txt, test_0035.txt, test_0036.txt, test_0037.txt, test_0038.txt, test_0039.txt, test_0040.txt, test_0041.txt, test_0042.txt, test_0043.txt, test_0044.txt, test_0045.txt, test_0046.txt, test_0047.txt, test_0048.txt, test_0049.txt, test_0050.txt, test_0051.txt, test_0052.txt, test_0053.txt, test_0054.txt, test_0055.txt, test_0056.txt, test_0057.txt, test_0058.txt, test_0059.txt, test_0060.txt, test_0061.txt, test_0062.txt, test_0063.txt, test_0064.txt, test_0065.txt, test_0066.txt, test_0067.txt, test_0068.txt, test_0069.txt, test_0070.txt, test_0071.txt, test_0072.txt, test_0073.txt, test_0074.txt, test_0075.txt, test_0076.txt, test_0077.txt, test_0078.txt, test_0079.txt, test_0080.txt, test_0081.txt, test_0082.txt, test_0083.txt, test_0084.txt, test_0085.txt, test_0086.txt, test_0087.txt, test_0088.txt, test_0089.txt, test_0090.txt, test_0091.txt, test_0092.txt, test_0093.txt, test_0094.txt, test_0095.txt, test_0096.txt, test_0097.txt, test_0098.txt, test_0099.txt, test_0100.txt, test_0101.txt, test_0102.txt, test_0103.txt, test_0104.txt, test_0105.txt, test_0106.txt, test_0107.txt, test_0108.txt, test_0109.txt, test_0110.txt, test_0111.txt, test_0112.txt, test_0113.txt, test_0114.txt, test_0115.txt, test_0116.txt, test_0117.txt, test_0118.txt, test_0119.txt, test_0120.txt, test_0121.txt, test_0122.txt, test_0123.txt, test_0124.txt, test_0125.txt, test_0126.txt, test_0127.txt, test_0128.txt, test_0129.txt, test_0130.txt, test_0131.txt, test_0132.txt, test_0133.txt, test_0134.txt, test_0135.txt, test_0136.txt, test_0137.txt, test_0138.txt, test_0139.txt, test_0140.txt, test_0141.txt, test_0142.txt, test_0143.txt, test_0144.txt, test_0145.txt, test_0146.txt, test_0147.txt, test_0148.txt, test_0149.txt
ケース名 結果 実行時間 メモリ
test_0000.txt AC 1902 ms 24220 KiB
test_0001.txt AC 1902 ms 24176 KiB
test_0002.txt AC 1903 ms 24272 KiB
test_0003.txt AC 1902 ms 24232 KiB
test_0004.txt AC 1903 ms 24188 KiB
test_0005.txt AC 1902 ms 24264 KiB
test_0006.txt AC 1902 ms 24116 KiB
test_0007.txt AC 1902 ms 24116 KiB
test_0008.txt AC 1902 ms 24176 KiB
test_0009.txt AC 1902 ms 24092 KiB
test_0010.txt AC 1902 ms 24044 KiB
test_0011.txt AC 1902 ms 24272 KiB
test_0012.txt AC 1902 ms 24232 KiB
test_0013.txt AC 1902 ms 24176 KiB
test_0014.txt AC 1902 ms 24176 KiB
test_0015.txt AC 1902 ms 24284 KiB
test_0016.txt AC 1902 ms 24052 KiB
test_0017.txt AC 1902 ms 24272 KiB
test_0018.txt AC 1902 ms 24220 KiB
test_0019.txt AC 1902 ms 24176 KiB
test_0020.txt AC 1902 ms 24156 KiB
test_0021.txt AC 1902 ms 24176 KiB
test_0022.txt AC 1902 ms 24264 KiB
test_0023.txt AC 1902 ms 24220 KiB
test_0024.txt AC 1902 ms 24176 KiB
test_0025.txt AC 1902 ms 24220 KiB
test_0026.txt AC 1902 ms 24256 KiB
test_0027.txt AC 1902 ms 24124 KiB
test_0028.txt AC 1902 ms 24188 KiB
test_0029.txt AC 1902 ms 24272 KiB
test_0030.txt AC 1903 ms 24284 KiB
test_0031.txt AC 1902 ms 24044 KiB
test_0032.txt AC 1902 ms 24272 KiB
test_0033.txt AC 1902 ms 24220 KiB
test_0034.txt AC 1902 ms 24232 KiB
test_0035.txt AC 1902 ms 24272 KiB
test_0036.txt AC 1902 ms 24052 KiB
test_0037.txt AC 1902 ms 24100 KiB
test_0038.txt AC 1902 ms 24044 KiB
test_0039.txt AC 1902 ms 24160 KiB
test_0040.txt AC 1902 ms 24052 KiB
test_0041.txt AC 1902 ms 24272 KiB
test_0042.txt AC 1902 ms 24264 KiB
test_0043.txt AC 1902 ms 24272 KiB
test_0044.txt AC 1902 ms 24272 KiB
test_0045.txt AC 1902 ms 24048 KiB
test_0046.txt AC 1902 ms 24048 KiB
test_0047.txt AC 1902 ms 24048 KiB
test_0048.txt AC 1902 ms 24232 KiB
test_0049.txt AC 1902 ms 24044 KiB
test_0050.txt AC 1902 ms 24052 KiB
test_0051.txt AC 1902 ms 24124 KiB
test_0052.txt AC 1902 ms 24048 KiB
test_0053.txt AC 1902 ms 24160 KiB
test_0054.txt AC 1902 ms 24052 KiB
test_0055.txt AC 1902 ms 24124 KiB
test_0056.txt AC 1902 ms 24044 KiB
test_0057.txt AC 1902 ms 24188 KiB
test_0058.txt AC 1902 ms 24188 KiB
test_0059.txt AC 1902 ms 24260 KiB
test_0060.txt AC 1902 ms 24284 KiB
test_0061.txt AC 1902 ms 24192 KiB
test_0062.txt AC 1902 ms 24188 KiB
test_0063.txt AC 1902 ms 24176 KiB
test_0064.txt AC 1902 ms 24220 KiB
test_0065.txt AC 1902 ms 24260 KiB
test_0066.txt AC 1902 ms 24048 KiB
test_0067.txt AC 1902 ms 24188 KiB
test_0068.txt AC 1902 ms 24052 KiB
test_0069.txt AC 1902 ms 24176 KiB
test_0070.txt AC 1902 ms 24232 KiB
test_0071.txt AC 1902 ms 24232 KiB
test_0072.txt AC 1902 ms 24232 KiB
test_0073.txt AC 1902 ms 24264 KiB
test_0074.txt AC 1902 ms 24272 KiB
test_0075.txt AC 1902 ms 24176 KiB
test_0076.txt AC 1902 ms 24188 KiB
test_0077.txt AC 1902 ms 24284 KiB
test_0078.txt AC 1902 ms 24048 KiB
test_0079.txt AC 1902 ms 24232 KiB
test_0080.txt AC 1902 ms 24220 KiB
test_0081.txt AC 1902 ms 24160 KiB
test_0082.txt AC 1902 ms 24116 KiB
test_0083.txt AC 1904 ms 24160 KiB
test_0084.txt AC 1902 ms 24188 KiB
test_0085.txt AC 1902 ms 24232 KiB
test_0086.txt AC 1902 ms 24044 KiB
test_0087.txt AC 1902 ms 24284 KiB
test_0088.txt AC 1902 ms 24252 KiB
test_0089.txt AC 1902 ms 24272 KiB
test_0090.txt AC 1902 ms 24116 KiB
test_0091.txt AC 1902 ms 24192 KiB
test_0092.txt AC 1902 ms 24256 KiB
test_0093.txt AC 1902 ms 24284 KiB
test_0094.txt AC 1902 ms 24100 KiB
test_0095.txt AC 1902 ms 24124 KiB
test_0096.txt AC 1902 ms 24284 KiB
test_0097.txt AC 1903 ms 24080 KiB
test_0098.txt AC 1902 ms 24188 KiB
test_0099.txt AC 1903 ms 24048 KiB
test_0100.txt AC 1902 ms 24256 KiB
test_0101.txt AC 1902 ms 24272 KiB
test_0102.txt AC 1902 ms 24188 KiB
test_0103.txt AC 1902 ms 24256 KiB
test_0104.txt AC 1902 ms 24188 KiB
test_0105.txt AC 1902 ms 24160 KiB
test_0106.txt AC 1902 ms 24160 KiB
test_0107.txt AC 1902 ms 24188 KiB
test_0108.txt AC 1902 ms 24220 KiB
test_0109.txt AC 1902 ms 24160 KiB
test_0110.txt AC 1902 ms 24188 KiB
test_0111.txt AC 1902 ms 24188 KiB
test_0112.txt AC 1902 ms 24116 KiB
test_0113.txt AC 1902 ms 24164 KiB
test_0114.txt AC 1902 ms 24160 KiB
test_0115.txt AC 1902 ms 24044 KiB
test_0116.txt AC 1902 ms 24264 KiB
test_0117.txt AC 1902 ms 24052 KiB
test_0118.txt AC 1902 ms 24176 KiB
test_0119.txt AC 1902 ms 24256 KiB
test_0120.txt AC 1902 ms 24188 KiB
test_0121.txt AC 1902 ms 24232 KiB
test_0122.txt AC 1902 ms 24160 KiB
test_0123.txt AC 1902 ms 24188 KiB
test_0124.txt AC 1902 ms 24256 KiB
test_0125.txt AC 1902 ms 24048 KiB
test_0126.txt AC 1902 ms 24264 KiB
test_0127.txt AC 1903 ms 24044 KiB
test_0128.txt AC 1902 ms 24124 KiB
test_0129.txt AC 1902 ms 24048 KiB
test_0130.txt AC 1902 ms 24160 KiB
test_0131.txt AC 1902 ms 24232 KiB
test_0132.txt AC 1902 ms 24188 KiB
test_0133.txt AC 1902 ms 24284 KiB
test_0134.txt AC 1902 ms 24160 KiB
test_0135.txt AC 1902 ms 24256 KiB
test_0136.txt AC 1902 ms 24264 KiB
test_0137.txt AC 1902 ms 24220 KiB
test_0138.txt AC 1902 ms 24052 KiB
test_0139.txt AC 1902 ms 24044 KiB
test_0140.txt AC 1902 ms 24176 KiB
test_0141.txt AC 1902 ms 24160 KiB
test_0142.txt AC 1902 ms 24048 KiB
test_0143.txt AC 1902 ms 24188 KiB
test_0144.txt AC 1902 ms 24232 KiB
test_0145.txt AC 1902 ms 24176 KiB
test_0146.txt AC 1902 ms 24200 KiB
test_0147.txt AC 1903 ms 24160 KiB
test_0148.txt AC 1902 ms 24188 KiB
test_0149.txt AC 1902 ms 24188 KiB