// an overcomplicated solution #include using namespace std; const int oo = 1<<20; int main(void) { int n; scanf("%d", &n); vector> Eout(n), Ein(n); for (int i = 1; i < n; ++i) { char w[n]; scanf("%s", w); for (int j = 0; j < i; ++j) { int a = w[j] == '1' ? i : j, b = i+j-a; Eout[a].push_back(b); Ein[b].push_back(a); } } set> cost; vector curcost(n); for (int i = 0; i < n; ++i) { curcost[i] = Eout[i].size(); cost.insert(make_pair(Eout[i].size(), i)); } int ans = 0, cur = 0; while (!cost.empty()) { cur += cost.begin()->first; ans = max(ans, cur); int i = cost.begin()->second; cost.erase(cost.begin()); for (int j: Eout[i]) { if (curcost[j] < oo) { cost.erase(make_pair(curcost[j], j)); --curcost[j]; cost.insert(make_pair(curcost[j], j)); } } for (int j: Ein[i]) { if (curcost[j] < oo) { cost.erase(make_pair(curcost[j], j)); --curcost[j]; cost.insert(make_pair(curcost[j], j)); } } curcost[i] = oo; } printf("%d\n", ans); }