Flight Routes

시간 제한2초메모리 제한1024 MB

요약
모든 도시 쌍 i<j에 대해 i에서 j로 가는 항공 경로 개수의 홀짝이 주어질 때, 직항편의 개수를 구한다.
난이도

어려움10점 중 8점

유형
그래프, 동적 계획법, 조합론, 수학
정답자
아직 제출이 없습니다

문제

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 (2≤N≤7502\le N\le 750) cities labeled 1…N1\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 k≥2k\ge 2 cities a=c_1\<c_2<…\<c_k=ba=c\_1\<c\_2<\dots\<c\_k=b such that for each 1≤i\<k1\le i\<k, there is a direct flight from city c_ic\_i to city c_i+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 N−1N-1 lines. The iith line contains N−iN-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.

예제2

  1. 예제 1

    입력
    3
    11
    1
    
    예상 출력
    2
    
  2. 예제 2

    입력
    5
    1111
    101
    01
    1
    
    예상 출력
    6