#abc283f. [abc283_f]Permutation Distance
[abc283_f]Permutation Distance
Problem Statement
You are given a permutation of .
Find the following value for all :
- $D _ i=\\displaystyle\\min_{j\\neq i}\\left\\lparen\\left\\lvert P _ i-P _ j\\right\\rvert+\\left\\lvert i-j\\right\\rvert\\right\\rparen$.
What is a permutation? A permutation of is a sequence that is obtained by rearranging . In other words, a sequence of length is a permutation of if and only if each occurs in exactly once.
Constraints
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print in ascending order of , separated by spaces.
Sample Input 1
4
3 2 4 1
Sample Output 1
2 2 3 3
For example, for ,
- if , we have and ;
- if , we have and ;
- if , we have and .
Thus, the value is minimum when , where $\\left\\lvert P _ i-P _ j\\right\\rvert+\\left\\lvert i-j\\right\\rvert=2$, so .
Sample Input 2
7
1 2 3 4 5 6 7
Sample Output 2
2 2 2 2 2 2 2
Sample Input 3
16
12 10 7 14 8 3 11 13 2 5 6 16 4 1 15 9
Sample Output 3
3 3 3 5 3 4 3 3 4 2 2 4 4 4 4 7