#P4749. [CERC2017] Kitchen Knobs
[CERC2017] Kitchen Knobs
题目描述
You are cooking on a gigantic stove at a large fast-food restaurant. The stove contains heating elements arranged in a line and numbered with integers through left to right. Each element is operated by its control knob. The knobs are a bit unusual: each knob is marked with seven non-zero digits evenly distributed around a circle. The power of the heating element is equal to the positive integer obtained by reading the digits on its control knob clockwise starting from the top of the knob.

In a single step, you can rotate one or more consecutive knobs by any number of positions in any direction. However, all knobs rotated in one step need to be rotated by the same number of positions in the same direction.
Find the smallest number of steps needed to set all the heating elements to maximal possible power.
输入格式
The first line contains an integer — the number of heating elements. The of the following lines contains an integer — the initial power of the heating element. Each consists of exactly seven non-zero digits.
输出格式
Output a single integer — the minimal number of steps needed.
6
9689331
1758824
3546327
5682494
9128291
9443696
3
7
5941186
3871463
8156346
9925977
8836125
9999999
5987743
2
提示
In the first example, one of the ways to achieve maximal possible power is: rotate knobs through by positions in the counterclockwise direction, rotate knob by positions in the counterclockwise direction, and rotate knobs through by positions in the clockwise direction.