#include using namespace std; typedef long long ll; #define inRange(x,a,b) (a <= x && x < b) int di[8] = {0,0,1,-1,1,1,-1,-1}; int dj[8] = {1,-1,0,0,1,-1,1,-1}; ll c[5][5]; bool f[5][5] = {}, memo[1<<25] = {}; ll sum = 0, ans = 1ll<<60; void dfs(int val, ll acc){ memo[val] = true; if(val == (1<<25)-1) return; ans = min(ans, abs(sum-acc-acc)); for(int x = 0; x < 25; x++){ int i = x/5, j = x%5; if(f[i][j] || memo[val+(1<> c[i][j]; sum += c[i][j]; } } f[0][0] = true; dfs(1, c[0][0]); cout << ans << endl; return 0; }