func_code_string: #include <bits/stdc++.h>   using namespace std;   int arr[1003][1003];   int n, m;   int dp[1003][1003];   int vis[1003][1003];   int dx[4] = {0, 1, 0, -1};   int dy[4] = {1, 0, -1, 0};   int dfs(int i, int j, int x) {     if (vis[i][j] == 2) {       printf( Poor Inna! n );       exit(0);     }     if (dp[i][j] != -1) return dp[i][j];     vis[i][j] = 2;     int temp2 = 0;     int temp3 = 0;     if (arr[i][j] == 3) temp3 = 1;     for (int k = 0; k < 4; k++) {       int ee = i + dx[k];       int rr = j + dy[k];       if (ee >= 0 & ee < n && rr >= 0 && rr < m && arr[ee][rr] == (x + 1) % 4) {         temp2 = max(temp2, dfs(ee, rr, (x + 1) % 4));       }     }     temp2 += temp3;     vis[i][j] = 1;     if (arr[i][j] == 0) dp[i][j] = temp2;     return temp2;   }   int main() {     char temp;     for (int i = 0; i < 1003; i++)       for (int j = 0; j < 1003; j++) {         dp[i][j] = -1;         vis[i][j] = 0;       }     scanf( %d %d , &n, &m);     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         cin >> temp;         if (temp ==  D ) arr[i][j] = 0;         if (temp ==  I ) arr[i][j] = 1;         if (temp ==  M ) arr[i][j] = 2;         if (temp ==  A ) arr[i][j] = 3;       }     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         if (arr[i][j] == 0 && vis[i][j] == 0) {           int temp1 = dfs(i, j, 0);         }       }     int ans = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (ans < dp[i][j]) ans = dp[i][j];     if (ans == 0)       printf( Poor Dima! n );     else       printf( %d n , ans);     return 0;   }   