func_code_string: #include <bits/stdc++.h>   using namespace std;   const int MAX_N = 100000;   const int D[4][2] = {{1, 1}, {1, -1}, {-1, 1}, {-1, -1}};   set<pair<int, int> > s;   set<pair<pair<int, int>, int> > vis;   char dir[10];   int sx, sy, h, w, d, tar;   inline void update(int& a, int b) {     if (b < a) a = b;   }   int main() {     scanf( %d%d%d%d%s , &h, &w, &sx, &sy, dir);     tar = ((h + w) * 2 - 4) >> 1;     if (dir[0] ==  U  && dir[1] ==  L )       d = 3;     else if (dir[0] ==  U  && dir[1] ==  R )       d = 2;     else if (dir[0] ==  D  && dir[1] ==  L )       d = 1;     else       d = 0;     --tar;     s.insert(make_pair(sx, sy));     vis.insert(make_pair(make_pair(sx, sy), d));     long long ans = 1;     pair<int, int> p1;     pair<pair<int, int>, int> p2;     while (tar > 0) {       if ((D[d][0] == 1 && sx == h) || (D[d][0] == -1 && sx == 1)) d ^= 2;       if ((D[d][1] == 1 && sy == w) || (D[d][1] == -1 && sy == 1)) d ^= 1;       int g = 0x3f3f3f3f;       if (D[d][0] == 1)         update(g, h - sx);       else         update(g, sx - 1);       if (D[d][1] == 1)         update(g, w - sy);       else         update(g, sy - 1);       ans += g;       sx += D[d][0] * g;       sy += D[d][1] * g;       p1 = make_pair(sx, sy);       if (s.find(p1) == s.end()) {         --tar;         s.insert(p1);       }       p2 = make_pair(p1, d);       if (vis.find(p2) != vis.end()) {         printf( -1 n );         return 0;       } else         vis.insert(p2);     }     printf(          %I64d            n ,         ans);     return 0;   }   