#include // Greedy O(n^3) solution to diploma ceremony // Author: Torstein Stromme using namespace std; #define MAXN 5000 #define rep(i,n) for(int i=0;i<(n);i++) int graph[MAXN][MAXN], is_winner[MAXN], a, b, n, worst_k, running_k; int main() { // Read graph scanf("%d", &n); rep(i, n-1) rep(j, i+1) { char c; scanf(" %c", &c); if (c == '1') { graph[i+1][j] = 1; } else { graph[j][i+1] = 1; } } // Greedily make a winner of the one who has smallest "new_bad-old_bad" rep(ignore, n) { int best_score = n + 1; int best_id = n + 1; rep(i, n) if (!is_winner[i]) { // Calculate this person's score int score = 0; rep(j, n) if (i != j) { if (is_winner[j] && graph[i][j]) score--; if (!is_winner[j] && !graph[i][j]) score++; } // Remember him if he is the best so far best_id = score < best_score ? i : best_id; best_score = score < best_score ? score : best_score; } is_winner[best_id] = 1; running_k += best_score; worst_k = running_k > worst_k ? running_k : worst_k; } cout << worst_k << endl; return 0; }