#5059. Problem 1. Flight Routes

0

Problem 1. Flight Routes

Problem 1. Flight Routes

USACO 2023 December Contest, Gold

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.

INPUT FORMAT (input arrives from the terminal / stdin):

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 FORMAT (print output to the terminal / stdout):

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

SAMPLE INPUT:


3
11
1

SAMPLE OUTPUT:


2

There are two direct flights: 121\to 2 and 232\to 3. There is one flight route from 11 to 22 and 22 to 33, each consisting of a single direct flight. There is one flight route from 11 to 33 (1231\to 2\to 3).

SAMPLE INPUT:


5
1111
101
01
1

SAMPLE OUTPUT:


6

There are six direct flights 12,14,15,23,35,451\to 2, 1\to 4, 1\to 5, 2\to 3, 3\to 5, 4\to 5. These result in the following numbers of flight routes:


Flight Route Counts:

            dest
          1 2 3 4 5

       1  0 1 1 1 3 
       2  0 0 1 0 1 
source 3  0 0 0 0 1 
       4  0 0 0 0 1 
       5  0 0 0 0 0

which is equivalent to the sample input after taking all the numbers (mod2)\pmod{2}.

SCORING: Inputs 3-4: N6N\le 6Inputs 5-12: N100N\le 100Inputs 13-22: No additional constraints.

Problem credits: Benjamin Qi