In an ancient temple, a legendary treasure is hidden, symbolizing the eternal friendship of the hamster Shustrik and the cat Persik. Shustrik and Persik want to show you this magical place. To get there, they need to open the gates of the ancient temple, which requires arranging a circular mosaic of sacred symbols (digits $$$0$$$-$$$9$$$) in the correct order.
The mosaic will be considered arranged in the correct order if the potential of the string of sacred symbols and the number of applications of the magical operation are minimized. The potential of a string is defined as the number of blocks of identical digits it consists of. For example, the potential of the string $$$112223$$$ is $$$3$$$, while for $$$12233321$$$ it is $$$5$$$. The magical operation that Shustrik and Persik can perform is as follows: they can cyclically shift the string to the right or left by $$$1$$$. Since the place is truly magical, the friends can perform this operation as many times as they want.
Help Shustrik and Persik calculate how many times they will have to apply the magical operation for the mosaic to be arranged in the correct order. Remember that the mosaic is considered arranged in the correct order only when both the potential of the string of sacred symbols and the number of applications of the magical operation are minimized.
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^{6}$$$).
The second line contains the string $$$s$$$ — the mosaic of sacred symbols.
Output the number of magical operations that Shustrik and Persik will have to perform. If during the magical operations the friends shift to the left, output the number of magical operations with a negative sign «-» (without quotes); if to the right, output it without the negative sign «-».
| Group | Points | Additional constraints | Required groups |
| 1 | 20 | $$$n \le 8$$$ | – |
| 2 | 10 | $$$n \le 18$$$ | 1 |
| 3 | 30 | $$$n \le 1\,000$$$ | 1, 2 |
| 4 | 40 | No additional constraints | 1, 2, 3 |
6112223
0
9112223111
-2
9122333211
-1
| Name |
|---|


