Wolfgang Amadeus Mozart has too many keys! He has
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 -pattern of a key be the sequence of relative key
lengths of the keys
following key in
clockwise order on the keychain. For example, if keychain has
keys of lengths in clockwise order, then the -pattern of the key of length
can be expressed as
the string “”, since , , and .
Note that the last key of length is followed by the first key of
length .
Please help Wolfgang determine for each key the smallest
such that the
-pattern of the key is
unique (no other key’s -pattern is the same).
Input
The first line of input contains a single integer
(), the number
of keys on Wolfgang’s circular keychain.
The next lines each
contain an integer between and 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
Output lines, one
integer per line. The integer should be
the smallest such that
the -pattern of key
(in input order) is
unique among all -patterns. If there exists no such
, then the integer should be
.
Sample Input 1 |
Sample Output 1 |
5
1
8
3
4
2
|
3
4
3
2
4
|
Sample Input 2 |
Sample Output 2 |
4
1
4
2
3
|
-1
-1
-1
-1
|