func_code_string: #include <bits/stdc++.h>   using namespace std;   const int maxn = 1010;   const int INF = 100000000;   string str[maxn];   int dp[maxn][maxn];   int n, m, ans;   int flag[maxn][maxn];   int dir[4][2] = {0, -1, 0, 1, 1, 0, -1, 0};   char ch[5] = { D ,  I ,  M ,  A };   vector<pair<int, int> > q;   bool Ok(int ki, int kj) {     if (ki >= 0 && ki < n && kj >= 0 && kj < m) return true;     return false;   }   int dfs(int ki, int kj, int d, int f) {     int Ans = 1;     for (int i = 0; i < 4; i++) {       int ti = ki + dir[i][0];       int tj = kj + dir[i][1];       if (Ok(ti, tj) && str[ti][tj] == ch[d + 1 < 4 ? d + 1 : 0]) {         if (flag[ti][tj] < f) {           int k = flag[ti][tj];           flag[ti][tj] = f;           if (dp[ti][tj] > 0)             Ans = max(Ans, dp[ti][tj] + 1);           else             Ans = max(Ans, dfs(ti, tj, d + 1 < 4 ? d + 1 : 0, f) + 1);           flag[ti][tj] = k;         } else {           Ans = INF;           break;         }       }     }     dp[ki][kj] = Ans;     return Ans;   }   void solve() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) {       cin >> str[i];       for (int j = 0; j < m; j++) {         if (str[i][j] ==  D ) q.push_back(pair<int, int>(i, j));       }     }     for (int i = 0; i < q.size(); i++) {       if (dp[q[i].first][q[i].second] == 0)         ans = max(ans, dfs(q[i].first, q[i].second, 0, i + 1) / 4);     }     if (ans == 0)       cout <<  Poor Dima!  << endl;     else if (ans >= 2500000)       cout <<  Poor Inna!  << endl;     else       cout << ans << endl;   }   int main() {     solve();     return 0;   }   