Mainak and Array solution codeforces

Mainak has an array 𝑎1,𝑎2,…,𝑎𝑛a1,a2,…,an of 𝑛n positive integers. He will do the following operation to this array exactly once: Pick a subsegment of this array and cyclically rotate it by any amount. Formally, he can do the following exactly once: Pick two integers 𝑙l and 𝑟r, such that 1≤𝑙≤𝑟≤𝑛1≤l≤r≤n, and any positive integer 𝑘k. Repeat this 𝑘k times: set 𝑎𝑙=𝑎𝑙+1,𝑎𝑙+1=𝑎𝑙+2,…,𝑎𝑟−1=𝑎𝑟,𝑎𝑟=𝑎𝑙al=al+1,al+1=al+2,…,ar−1=ar,ar=al (all changes happen at the same time). Mainak … Read more