logo AlgoBeat OnlineJudge
登录 注册

#215274. [USACO26JAN2] Farmer John Loves Rotations S

内存限制:256 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Farmer John has an array containing integers (). He picks his favorite index and take out a sheet of paper with only written on it. He can then perform the following operation some number of times:

  • Cyclically shift all elements in one spot to the left or one spot to the right. Then, write down on a piece of paper.

Let denote the set of distinct integers that occur in . Farmer John wonders what the minimum number of operations he must perform is so that the paper contains all integers that appear in .

Since it is unclear what FJ's favorite index is, output the answer for all possible favorite indices . Note for each index, is reset to its original form before performing any operations.

输入格式

The first line contains .

The following line contains .

输出格式

Output space-separated integers, where the 'th integer is the answer for his favorite index .

样例

样例输入 1

6
1 2 3 1 3 4

样例输出 1

4 3 3 4 3 3

样例输入 2

12
1 1 2 1 1 3 1 1 4 1 1 1

样例输出 2

8 7 6 7 8 9 8 7 6 7 8 9

数据范围与提示

Sample 1 Explanation

The distinct numbers are . Suppose Farmer John’s favorite index is . He starts off with written on a piece of paper. We can track the array after each cyclic shift Farmer John makes.

  • Cyclic shift right: FJ writes down . :::align{center} 4 1 2 3 1 3 :::
  • Cyclic shift left: FJ writes down again. :::align{center} 1 2 3 1 3 4 :::
  • Cyclic shift left: FJ writes down . :::align{center} 2 3 1 3 4 1 :::
  • Cyclic shift left: FJ writes down . :::align{center} 3 1 3 4 1 2 ::: At this point, Farmer John has written down every number in using 4 operations.

SCORING:

  • Inputs 3-5:
  • Inputs 6-8:
  • Inputs 9-17: No additional constraints.