#include #include char cache[1001][1001]; int test(int m,int n) { if (cache[m][n]!=(-1)) return cache[m][n]; if (m==0 && n==0) { cache[m][n]=0; return 0; } if (m>0 && n>0 && !test(m-1,n-1)) { cache[m][n]=1; return 1; } if (m>0 && !test(m-1,n)) { cache[m][n]=1; return 1; } if (n>0 && !test(m,n-1)) { cache[m][n]=1; return 1; } cache[m][n]=0; return 0; } main() { int m,n; int i,j; scanf("%d %d",&m,&n); while (m && n) { for (i=0;i<=m;i++) for (j=0;j<=n;j++) cache[i][j]=(-1); if (!test(m-1,n-1)) printf("Win by taking from both\n"); else if (!test(m-1,n)) printf("Win by taking from first\n"); else if (!test(m,n-1)) printf("Win by taking from second\n"); else printf("Can't win\n"); scanf("%d %d",&m,&n); } }