The Lifesaving Riddle
InterviewTime limit1sMemory limit1024 MB
For each shift x from 1 to n-1, decide whether some array a can produce the given difference array b under a left cyclic shift.
- Level
Medium5 of 10
- Topics
- Math, Number theory, Array
- Solved
- No attempts yet
Problem
The Riddler kidnaps Gil Colson, the district attorney.
To escape, Colson must solve three riddles. Batman helps him with the first two, but the third one is too hard. Can you help him solve it?
The riddle works as follows:
- The Riddler writes down and hides an integer array of length .
- He then cyclically shifts it left by some amount , and subtracts the shifted array from the original element by element.
- The resulting array (that is, the array with for all ) is given to Colson.
Given array , restore all possible shift values that could produce from some array .
Input
The first line contains a single integer , the length of the original array ().
The second line contains integers separated by spaces, the elements of the array that the Riddler gave ().
Output
Print integers separated by spaces. The -th of them is 1 if could have occurred, and 0 otherwise.
Hints
In the first example, the array could come from shifted left by 1, or from shifted left by 2.
In the first example, this array could not come from any shifted by 3, while shifts 1 or 4 work, for example with and respectively.
For the third example, one can show that such could not have been produced in the way described in the statement.