BOI acronym

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

요약
B, O, I로 이루어진 문자열의 모든 부분 문자열마다 최빈 문자의 등장 횟수가 주어질 때, B가 나타나는 모든 위치를 복원한다.
난이도

어려움10점 중 9점

유형
구현, 완전 탐색, 그리디
정답자
아직 제출이 없습니다

문제

As you certainly know, BOI is an acronym for the name of the Baltic Olympiad in Informatics.

The organisers find the acronym BOI too easy to pronounce (it forms a single syllable in the English language, after all). Therefore they came up with a new acronym. In order to easily distinguish it from the other regional Olympiads (like CEOI), the new acronym still consists only of characters “B”, “O” and “I”. Additionally, “B” is strictly the most common character in the acronym. That is, there are strictly more occurrences of “B” than “O”, and there are also strictly more occurrences of “B” than “I”.

For example, acronyms “OBOIIBB” and “B” are valid, but “IBIIBB”, “BOI”, “O” and “BCB” are not.

To make things more exciting, instead of publishing it in full they have only provided some hints. Namely, for each consecutive substring of the new acronym, they gave you the number of occurrences of the most common character in this substring. Note that this character is not necessarily “B”, and also the most common character is not necessarily unique. Surprisingly, it can be proven that this information is actually enough to recover all the occurrences of “B”. Can you find them?

입력

The first line contains an integer nn (1≤n≤20001 ≤ n ≤ 2000), denoting the length of the new acronym.

The following nn lines describe the hints. The ii-th line contains n−i+1n - i + 1 integers M_i,i,M_i,i+1,…,M_i,nM\_{i,i}, M\_{i,i+1}, \dots , M\_{i,n} (1≤M_ℓ,r≤n1 ≤ M\_{ℓ,r} ≤ n), where M_ℓ,rM\_{ℓ,r} denotes the number of occurrences of the most common character in the substring that starts at the ℓℓ-th position and ends at the rr-th position of the acronym. The positions are numbered from 11 to nn.

You can assume that there exists at least one valid acronym that is consistent with the given hints.

출력

Output one line with the positions of all occurrences of “B”, in the increasing order, separated by single spaces. Each position must be an integer in the range from 11 to nn.

예제1

  1. 예제 1

    입력
    6
    1 1 2 3 3 3
    1 1 2 2 2
    1 2 2 2
    1 1 2
    1 2
    1
    
    예상 출력
    1 3 4