func_code_string: #include <bits/stdc++.h>   using namespace std;   const int MAX_N = 1505;   const int dx[] = {-1, 0, 1, 0};   const int dy[] = {0, 1, 0, -1};   int visx[MAX_N][MAX_N];   int visy[MAX_N][MAX_N];   char A[MAX_N][MAX_N];   int sx, sy;   int n, m;   queue<pair<int, int> > q;   bool in(int x, int y) { return x >= 0 && x < n && y >= 0 && y < m; }   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> A[i];     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (A[i][j] ==  S ) {           A[i][j] =  . ;           sx = i, sy = j;         }       }     }     sx += n * m;     sy += n * m;     q.push(make_pair(sx, sy));     memset(visx, -1, sizeof(visx));     memset(visy, -1, sizeof(visy));     while (!q.empty()) {       pair<int, int> t = q.front();       q.pop();       if (A[(t.first + n) % n][(t.second + m) % m] ==  # ) continue;       if (visx[(t.first + n) % n][(t.second + m) % m] == t.first &&           visy[(t.first + n) % n][(t.second + m) % m] == t.second)         continue;       if (visx[(t.first + n) % n][(t.second + m) % m] == -1)         visx[(t.first + n) % n][(t.second + m) % m] = t.first;       if (visy[(t.first + n) % n][(t.second + m) % m] == -1)         visy[(t.first + n) % n][(t.second + m) % m] = t.second;       if (visx[(t.first + n) % n][(t.second + m) % m] != t.first ||           visy[(t.first + n) % n][(t.second + m) % m] != t.second) {         cout <<  Yes  << endl;         return 0;       }       for (int i = 0; i < 4; i++) {         int nx = dx[i] + t.first;         int ny = dy[i] + t.second;         q.push(make_pair(nx, ny));       }     }     cout <<  No  << endl;     return 0;   }   