Finding Keys

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

요약
원형 열쇠고리에서 각 열쇠마다 다음 k개 열쇠와의 대소 비교 패턴이 유일해지는 최소 k를 구한다.
난이도

어려움10점 중 8점

유형
문자열 매칭, 정렬, 이분 탐색, 문자열
정답자
아직 제출이 없습니다

문제

Wolfgang Amadeus Mozart has too many keys! He has nn keys of distinct lengths on his circular keychain. Unfortunately, Wolfgang can only judge whether a key fits into a door by its relative size compared to the keys surrounding it. Let the kk-pattern of a key xx be the sequence of relative key lengths of the kk keys following key xx in clockwise order on the keychain. For example, if keychain has keys of lengths 1,5,3,4,21, 5, 3, 4, 2 in clockwise order, then the 33-pattern of the key of length 33 can be expressed as the string “<>>”, since 33 < 44, 44 > 22, and 22 > 11. Note that the last key of length 22 is followed by the first key of length 11.

Please help Wolfgang determine for each key the smallest kk such that the kk-pattern of the key is unique (no other key’s kk-pattern is the same).

입력

The first line of input contains a single integer nn (2≤n≤2⋅1052 ≤ n ≤ 2 \cdot 10^5), the number of keys on Wolfgang’s circular keychain.

The next nn lines each contain an integer between 11 and 10910^9 representing the length of one key. The key lengths are given in their clockwise order on the keychain. It is guaranteed that all key lengths are unique.

출력

Output nn lines, one integer per line. The iith integer should be the smallest kk such that the kk-pattern of key ii (in input order) is unique among all kk-patterns. If there exists no such kk, then the iith integer should be −1-1.

예제2

  1. 예제 1

    입력
    5
    1
    8
    3
    4
    2
    
    예상 출력
    3
    4
    3
    2
    4
    
  2. 예제 2

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