func_code_string: #include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e3 + 13;   const int INF = 1e6 + 7;   int t[MAXN][MAXN];   int tab[MAXN * MAXN];   bool odw[MAXN * MAXN];   int wyn[MAXN * MAXN];   bool prze[MAXN * MAXN];   int xx[4] = {0, 0, -1, 1};   int yy[4] = {-1, 1, 0, 0};   vector<int> v[MAXN * MAXN];   int check(int x) {     int spr = 0;     odw[x] = true;     prze[x] = true;     for (auto it : v[x]) {       if (odw[it] && prze[it])         spr = 1;       else if (!odw[it])         spr = max(spr, check(it));     }     prze[x] = false;     return spr;   }   int DFS(int x, int gl) {     odw[x] = true;     for (auto it : v[x]) {       if (odw[it])         wyn[x] = max(wyn[x], wyn[it]);       else         wyn[x] = max(wyn[x], DFS(it, gl + 1));     }     wyn[x]++;     return wyn[x];   }   int main() {     int n, m;     int mx = 0;     char c;     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf(   );       for (int j = 1; j <= m; j++) {         scanf( %c , &c);         if (c ==  I ) t[i][j] = 1;         if (c ==  M ) t[i][j] = 2;         if (c ==  A ) t[i][j] = 3;         tab[(i - 1) * m + j] = t[i][j];       }       t[i][0] = t[i][m + 1] = 5;     }     for (int i = 1; i <= m; i++) t[0][i] = t[n + 1][i] = 5;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         for (int l = 0; l < 4; l++) {           if (t[i + xx[l]][j + yy[l]] == (t[i][j] + 1) % 4)             v[(i - 1) * m + j].push_back((i + xx[l] - 1) * m + j + yy[l]);         }       }     }     for (int i = 1; i <= n * m; i++) {       if (!odw[i] && tab[i] == 0) {         if (check(i) == 1) {           printf( Poor Inna! );           return 0;         }       }     }     for (int i = 1; i <= n * m; i++) odw[i] = false;     for (int i = 1; i <= n * m; i++) {       if (!odw[i] && tab[i] == 0) mx = max(mx, DFS(i, 1) / 4);     }     if (mx == 0)       printf( Poor Dima! );     else       printf( %d , mx);     return 0;   }   