#include #include #include using namespace std; #define DOWN 1 #define LEFT 2 #define DIAG 4 int pole[2010][2010]; char first[2010][12]; char second[2010][12]; int kudy[2010][2010]; int znac[2010][2010]; inline int MIN(int a, int b) { if (a>b) return b; else return a; } int main() { while (scanf("%s",first[1]),*first[1]!='.') { first[0][0]=0; second[0][0]=0; int fcnt=2; int scnt=1; do { scanf("%s",first[fcnt++]); } while (*first[fcnt-1]!='.'); --fcnt; while (scanf("%s",second[scnt]),*second[scnt]!='.') ++scnt; for (int i=0;i=0;i--) { for (int j=0;j=0;i--) { for (int j=scnt+4;j>=0;j--) { znac[i][j]=0; } } znac[fcnt-1][scnt-1]=1; for (int i=fcnt-1;i>=0;i--) { for (int j=scnt-1;j>=0;j--) { if (pole[i+1][j+1]==pole[i][j] && znac[i+1][j+1] && !strcmp(first[i+1],second[j+1])) znac[i][j]=1; if (pole[i][j+1]==pole[i][j]+1 && znac[i][j+1]) znac[i][j]=1; if (pole[i+1][j]==pole[i][j]+1 && znac[i+1][j]) znac[i][j]=1; } } /* for (int i=fcnt;i>=0;i--) { for (int j=0;j<=scnt;j++) { printf("%3d ",znac[i][j]); } printf("\n"); } printf("\n");*/ int posi=0,posj=0; int min=-1; while (posi