func_code_string: #include <bits/stdc++.h>   using namespace std;   int maze[1500][1500];   pair<int, int> was[1500][1500];   int n, m;   int sr, sc;   inline int rem(int x, int y) {     x %= y;     return (x < 0) ? x + y : x;   }   bool dfs(int r, int c) {     int rm = rem(r, n), cm = rem(c, m);     if (maze[rm][cm] == 1) {       return was[rm][cm] != pair<int, int>(r, c);     }     int rmn, cmn;     if (maze[rm][cm] == 0) {       maze[rm][cm] = 1;       was[rm][cm] = pair<int, int>(r, c);       rmn = rem(r, n), cmn = rem(c - 1, m);       if (maze[rmn][cmn] != -1 && dfs(r, c - 1)) return true;       rmn = rem(r, n), cmn = rem(c + 1, m);       if (maze[rmn][cmn] != -1 && dfs(r, c + 1)) return true;       rmn = rem(r + 1, n), cmn = rem(c, m);       if (maze[rmn][cmn] != -1 && dfs(r + 1, c)) return true;       rmn = rem(r - 1, n), cmn = rem(c, m);       if (maze[rmn][cmn] != -1 && dfs(r - 1, c)) return true;     }     return false;   }   void TheSolution(istream& input, ostream& output) {     input >> n >> m;     string s;     memset(maze, -1, sizeof(maze));     for (int i = 0; i < n; i++) {       input >> s;       for (int j = 0; j < m; j++) {         if (s[j] ==  . ) maze[i][j] = 0;         if (s[j] ==  S ) {           sr = i;           sc = j;           maze[i][j] = 0;         }         was[i][j] = pair<int, int>(-1000000, -1000000);       }     }     output << (dfs(sr, sc) ?  Yes  :  No );   }   int main() {     TheSolution(cin, cout);     return 0;   }   