func_code_string: #include <bits/stdc++.h>   using namespace std;   int dx[] = {-1, 1, 0, 0, 1, -1, 1, -1};   int dy[] = {0, -0, -1, 1, 1, -1, -1, 1};   void run() {}   int fixMod(int a, int b) { return ((a % b) + b) % b; }   long long gcd(long long a, long long b) {     return (b == 0 ? abs(a) : gcd(b, a % b));   }   void fast() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   int n, m;   vector<vector<char>> grid;   bool flag = 0;   pair<int, int> per[1510][1510];   bool vis[1510][1510];   int stx, sty;   bool dfs(int x, int y) {     int xm = (x + n * 2000) % n;     int ym = (y + m * 2000) % m;     if (grid[xm][ym] ==  # ) return 0;     if (vis[xm][ym]) {       return per[xm][ym] != make_pair(x, y);     }     vis[xm][ym] = 1;     per[xm][ym] = {x, y};     bool ret = 0;     for (int i = 0; i < 4; i++) {       ret |= dfs(x + dx[i], y + dy[i]);     }     return ret;   }   int main() {     run();     fast();     cin >> n >> m;     grid.resize(n);     for (int i = 0; i < n; i++) {       grid[i].resize(m);       for (int j = 0; j < m; j++) {         cin >> grid[i][j];         if (grid[i][j] ==  S ) stx = i, sty = j;       }     }     if (dfs(stx, sty))       cout <<  YES             <<   n ;     else       cout <<  NO             <<   n ;     return 0;   }   