func_code_string: #include <bits/stdc++.h>   using namespace std;   char a[1000][1001], s[] =  DIMA ;   bool b = 0, f[1000][1000];   int q, w, d[1000][1000];   void l(short int r, short int t, short int e) {     int y = 0;     if ((f[r][t]) || (b)) {       b = 1;       return;     }     f[r][t] = 1;     e %= 4;     if ((r) && (a[r - 1][t] == s[e])) {       if (d[r - 1][t] == -1) l(r - 1, t, e + 1);       if (y < d[r - 1][t]) y = d[r - 1][t];     }     if ((r < q - 1) && (a[r + 1][t] == s[e])) {       if (d[r + 1][t] == -1) l(r + 1, t, e + 1);       if (y < d[r + 1][t]) y = d[r + 1][t];     }     if ((t) && (a[r][t - 1] == s[e])) {       if (d[r][t - 1] == -1) l(r, t - 1, e + 1);       if (y < d[r][t - 1]) y = d[r][t - 1];     }     if ((t < w - 1) && (a[r][t + 1] == s[e])) {       if (d[r][t + 1] == -1) l(r, t + 1, e + 1);       if (y < d[r][t + 1]) y = d[r][t + 1];     }     if (e == 0) y++;     d[r][t] = y;   }   int main() {     int e, r, t = 0, c;     scanf( %d%d , &q, &w);     for (e = 0; e < q; e++) {       scanf( %s , a[e]);       for (r = 0; r < w; r++) {         d[e][r] = -1;         f[e][r] = 0;       }     }     for (e = 0; e < q; e++)       for (r = 0; r < w; r++)         if (a[e][r] ==  D ) {           if (d[e][r] == -1) l(e, r, 1);           if (b) goto stop;           if (t < d[e][r]) t = d[e][r];         }   stop:     if (b)       printf( Poor Inna! );     else if (t == 0)       printf( Poor Dima! );     else       printf( %d , t);     return 0;   }   