PivotOJ

Flight Routes

시간 제한: 2000ms메모리 제한: 1024MB출처: USACO 2023 December GoldBOJ 31057

문제

Bessie recently discovered that her favorite pop artist, Elsie Swift, is performing in her new Eras Tour! Unfortunately, tickets are selling out fast, so Bessie is thinking of flying to another city to attend the concert. The Eras tour is happening in NN (2N7502\le N\le 750) cities labeled 1N1\dots N, and for each pair of cities (i,j)(i,j) with i<ji<j there either exists a single direct flight from ii to jj or not.

A flight route from city aa to city bb (a<ba<b) is a sequence of k2k\ge 2 cities a=c1<c2<<ck=ba=c_1<c_2<\dots<c_k=b such that for each 1i<k1\le i<k, there is a direct flight from city cic_i to city ci+1c_{i+1}. For every pair of cities (i,j)(i,j) with i<ji<j, you are given the parity of the number of flight routes between them (0 for even, 1 for odd).

While planning her travel itinerary, Bessie got distracted and now wants to know how many pairs of cities have direct flights between them. It can be shown that the answer is uniquely determined.

입력

The first line contains NN.

Then follow N1N-1 lines. The iith line contains NiN-i integers. The jjth integer of the iith line is equal to the parity of the number of flight routes from ii to i+ji+j.

출력

Output the number of pairs of cities with direct flights between them.

예제

예제 1

입력
3
11
1
출력
2

예제 2

입력
5
1111
101
01
1
출력
6
코드를 제출하려면 로그인하세요.