func_code_string: #include <bits/stdc++.h>   using namespace std;   const int MAXN = 1555;   const int dx[4] = {0, 0, 1, -1};   const int dy[4] = {1, -1, 0, 0};   int n, m;   template <typename T>   inline T mod(const T& lhs, const T& rhs) {     T _lhs = lhs;     while (_lhs < 0) {       _lhs += rhs;     }     return _lhs % rhs;   }   char gra[MAXN][MAXN];   bool used[MAXN][MAXN];   pair<int, int> visited[MAXN][MAXN];   queue<pair<int, int> > Q;   bool bfs(int x, int y) {     pair<int, int> now(x, y);     Q.push(now);     visited[now.first][now.second] = now;     used[x][y] = 1;     while (!Q.empty()) {       now = Q.front();       Q.pop();       for (int i = 0; i < 4; i++) {         int tx = dx[i] + now.first, ty = dy[i] + now.second;         int rx = mod(tx, n), ry = mod(ty, m);         if (gra[rx][ry] ==  # ) {           continue;         }         if (!used[rx][ry]) {           used[rx][ry] = 1;           Q.push(pair<int, int>(tx, ty));           visited[rx][ry] = pair<int, int>(tx, ty);         } else {           if (visited[rx][ry].first != tx || visited[rx][ry].second != ty) {             return true;           }         }       }     }     return false;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) {       scanf( %s , gra[i]);     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (gra[i][j] ==  S ) {           if (bfs(i, j)) {             puts( Yes );           } else {             puts( No );           }           return 0;         }       }     }   }   