func_code_string: #include <bits/stdc++.h>   using namespace std;   int n, m;   char arr[1503][1503];   int inix, iniy;   bool visit[4503][4504];   int X[] = {0, 0, 1, -1};   int Y[] = {1, -1, 0, 0};   int nn, mm;   int colax[4503 * 4503];   int colay[4503 * 4503];   bool dentro(int a, int b) {     if (a < 0 || b < 0 || a >= nn || b >= mm) return false;     return true;   }   inline void bfs(int x, int y) {     visit[x][y] = true;     int xx, yy;     int q = 0;     colax[q] = x;     colay[q++] = y;     for (int j = 0; j < q; j++) {       x = colax[j];       y = colay[j];       for (int i = 0; i < 4; i++) {         xx = x + X[i];         yy = y + Y[i];         if (!visit[(xx + nn) % nn][(yy + mm) % mm] &&             arr[(xx + n) % n][(yy + m) % m] !=  # ) {           visit[(xx + nn) % nn][(yy + mm) % mm] = true;           colax[q] = (xx + nn) % nn;           colay[q++] = (yy + mm) % mm;         }       }     }   }   int main() {     scanf( %d %d , &n, &m);     nn = n * 3;     mm = m * 3;     for (int i = 0; i < n; i++) scanf( %s , arr[i]);     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (arr[i][j] ==  S ) {           inix = i, iniy = j;         };     iniy += m;     inix += n;     bfs(inix, iniy);     for (int i = -1; i < 2; i++)       for (int j = -1; j < 2; j++) {         if (i == j && i == 0) continue;         if (visit[inix + i * n][iniy + j * m]) {           cout <<  Yes  << endl;           return 0;         }       }     cout <<  No  << endl;     return 0;   }   