CF207B3 Military Trainings
题目描述
### 题目大意
有 $n$ 个坦克,从 $1$ 到 $n$ 编号,它们要进行消息传输。
每一次传输如下,列表中第一个坦克将信息传输到列表中的某个坦克。接收到该消息的坦克将其进一步发送到列表后的某个坦克。该过程将继续进行,直到最后一个坦克收到消息。可能不是列表中的所有坦克都会收到消息,但列表中的最后一个坦克必须收到消息。
当最后一个坦克收到消息时,它将挪到第一个位置,并发送一条消息。当信息到达最后一个坦克时,该坦克移动到列的开头,并将下一条信息发送到列表的末尾,依此类推。因此,当列中的坦克返回到其原始顺序时,练习就完成了。
在两个坦克之间传输信息需要一秒钟,然而,并非总是一个坦克可以将信息传输给另一个坦克。让我们考虑列中的两个坦克,使它们中的第一个是从开始计数的列中的第 $i$ 个,第二个是列中的 $j$ 个,并假设第二个坦克的编号为 $x$。然后,如果$i
输入格式
第一行一个正整数 $n\ (1\le n \le 2.5\times10^5)$。
接下来 $n$ 行,第 $i+1$ 行为 $a_{i}$。
输出格式
一行一个正整数,表示答案。
Translate by [liujiaxi123456](https://www.luogu.com.cn/user/638148).
说明/提示
In the first sample the original order of tanks is $ 1,2,3 $ . The first tank sends a message to the second one, then the second tank sends it to the third one — it takes two seconds. The third tank moves to the beginning of the column and the order of tanks now is $ 3,1,2 $ . The third tank sends a message to the first one, then the first one sends it to the second one — it takes two more seconds. The second tank moves to the beginning and the order of the tanks is now $ 2,3,1 $ . With this arrangement, the second tank can immediately send a message to the first one, since the message receiving radius of the first tank is large enough — it takes one second. Finally, the tanks return to their original order $ 1,2,3 $ . In total, the exercise takes $ 5 $ seconds.
In the second sample, all five tanks are the same and sending a single message takes two seconds, so in total the exercise takes $ 10 $ seconds.