func_code_string: #include <bits/stdc++.h>   using namespace std;   const int SCALE = 101;   int g[SCALE * 2][SCALE * 2];   int tx, ty;   int stepr[4] = {0, -1, 0, 1};   int stepc[4] = {-1, 0, 1, 0};   string s;   bool BuildMap(const string& s) {     int x = 0;     int y = 0;     memset(g, 0, sizeof(g));     g[(x + SCALE)][(y + SCALE)] = 1;     for (int i = 0; i < s.size(); ++i) {       int d = 0;       switch (s[i]) {         case  L :           d = 0;           break;         case  U :           d = 1;           break;         case  R :           d = 2;           break;         case  D :           d = 3;           break;       }       x += stepr[d];       y += stepc[d];       if (g[(x + SCALE)][(y + SCALE)] == 1) {         return false;       } else {         g[(x + SCALE)][(y + SCALE)] = 1;       }     }     tx = x;     ty = y;     return true;   }   int Dfs(int x, int y, int cost) {     if (x == tx && y == ty) return cost;     int v = 10000;     for (int i = 0; i < 4; ++i) {       int tmpx = x + stepr[i];       int tmpy = y + stepc[i];       int& tmpg = g[(tmpx + SCALE)][(tmpy + SCALE)];       if (tmpg == 1) {         tmpg = -1;         int tv = Dfs(tmpx, tmpy, cost + 1);         v = min(tv, v);         tmpg = 1;       }     }     return v;   }   bool CheckShort() {     g[(0 + SCALE)][(0 + SCALE)] = -1;     int cost = Dfs(0, 0, 0);     if (cost < s.size() - 1) {       return false;     }     return true;   }   int main() {     while (cin >> s) {       bool b = BuildMap(s);       if (b == false) {         cout <<  BUG  << endl;         continue;       }       b = CheckShort();       if (b == false) {         cout <<  BUG  << endl;         continue;       }       cout <<  OK  << endl;     }     return 0;   }   