func_code_string: #include <bits/stdc++.h>   using namespace std;   char ans[1005][1005];   int x[1005][1005], y[1005][1005];   int n;   int dx[] = {1, 0, -1, 0};   int dy[] = {0, 1, 0, -1};   bool isvalid(int i, int j) {     if (i < 0 || j < 0 || i >= n || j >= n) return 0;     return 1;   }   void color(int i, int j) {     if (i < 0 || j < 0 || i >= n || j >= n || ans[i][j] ==  Z  || x[i][j] != -1 ||         y[i][j] != -1)       return;     ans[i][j] =  Z ;     for (int k = 0; k < 4; k++) color(i + dx[k], j + dy[k]);   }   void DFS(int i, int j, char ch, int ka, int kh) {     if (i < 0 || j < 0 || i >= n || j >= n || x[i][j] == -1 || ans[i][j] !=  K )       return;     ans[i][j] = ch;     if (isvalid(i + 1, j) && x[i + 1][j] == ka && y[i + 1][j] == kh) {       DFS(i + 1, j,  U , ka, kh);     }     if (isvalid(i - 1, j) && x[i - 1][j] == ka && y[i - 1][j] == kh) {       DFS(i - 1, j,  D , ka, kh);     }     if (isvalid(i, j + 1) && x[i][j + 1] == ka && y[i][j + 1] == kh) {       DFS(i, j + 1,  L , ka, kh);     }     if (isvalid(i, j - 1) && x[i][j - 1] == ka && y[i][j - 1] == kh) {       DFS(i, j - 1,  R , ka, kh);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         cin >> x[i][j] >> y[i][j];         ans[i][j] =  K ;       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (x[i][j] == -1 && y[i][j] == -1)           color(i, j);         else if (x[i][j] == i + 1 && y[i][j] == j + 1)           DFS(i, j,  X , i + 1, j + 1);       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (ans[i][j] ==  Z ) {           if (isvalid(i + 1, j) && x[i + 1][j] == -1) {             ans[i][j] =  D ;             ans[i + 1][j] =  U ;           } else if (isvalid(i - 1, j) && x[i - 1][j] == -1) {             ans[i][j] =  U ;             ans[i - 1][j] =  D ;           } else if (isvalid(i, j + 1) && x[i][j + 1] == -1) {             ans[i][j] =  R ;             ans[i][j + 1] =  L ;           } else if (isvalid(i, j - 1) && x[i][j - 1] == -1) {             ans[i][j] =  L ;             ans[i][j - 1] =  R ;           }         }       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (ans[i][j] ==  K  || ans[i][j] ==  Z ) {           cout <<  INVALID ;           return 0;         }       }     }     cout <<  VALID n ;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) cout << ans[i][j];       cout <<   n ;     }     return 0;   }   