#include #include using namespace std; int main() { int n; cin >> n; auto grid = vector>(n, vector(n, 0)); for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { cin >> grid[i][j]; } } auto my_team = vector(n, false); for(int i = 0; i < n/2; i++) { long long best_score = -10000000000LL; int best_member = -1; for(int j = 0; j < n; j++) { if(my_team[j]) continue; long long this_score = 0; for(int k = 0; k < n; k++) { this_score += grid[j][k]; } if(this_score > best_score) { best_score = this_score; best_member = j; } } my_team[best_member] = true; } long long result = 0; for(int i = 0; i < n; i++) { for(int j = i + 1; j < n; j++) { if(my_team[i] && my_team[j]) result += grid[i][j]; else if(!my_team[i] && !my_team[j]) { result -= grid[i][j]; } } } cout << result << endl; }