#include"stdio.h" #include"string.h" #include using namespace std; int a[1005][1005]; int dp[1005][1005]; int main() { int n,m; while(scanf("%d%d",&n,&m)!=EOF) { for(int i=0;i=1 && j>=1) dp[i][j]=min(dp[i-1][j-1]+a[i-1][j]*a[i][j],dp[i][j]); if(i>=1 && j>=1) dp[i][j]=min(dp[i-1][j-1]+a[i][j-1]*a[i][j],dp[i][j]); if(i>=2) dp[i][j]=min(dp[i-2][j]+a[i-1][j]*a[i][j],dp[i][j]); if(j>=2) dp[i][j]=min(dp[i][j-2]+a[i][j-1]*a[i][j],dp[i][j]); } } } printf("%d\n",dp[n-1][m-1]); } return 0; }