CF339E.Three Swaps

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Xenia the horse breeder has nn (n>1)(n>1) horses that stand in a row. Each horse has its own unique number. Initially, the ii -th left horse has number ii . That is, the sequence of numbers of horses in a row looks as follows (from left to right): 1, 2, 3, ...... , nn .

Xenia trains horses before the performance. During the practice sessions, she consistently gives them commands. Each command is a pair of numbers l,rl,r (1<=l<r<=n)(1<=l<r<=n) . The command l,rl,r means that the horses that are on the ll -th, (l+1)(l+1) -th, (l+2)(l+2) -th, ...... , rr -th places from the left must be rearranged. The horses that initially stand on the ll -th and rr -th places will swap. The horses on the (l+1)(l+1) -th and (r1)(r-1) -th places will swap. The horses on the (l+2)(l+2) -th and (r2)(r-2) -th places will swap and so on. In other words, the horses that were on the segment [l,r][l,r] change their order to the reverse one.

For example, if Xenia commanded l=2,r=5l=2,r=5 , and the sequence of numbers of horses before the command looked as (2, 1, 3, 4, 5, 6), then after the command the sequence will be (2, 5, 4, 3, 1, 6).

We know that during the practice Xenia gave at most three commands of the described form. You have got the final sequence of numbers of horses by the end of the practice. Find what commands Xenia gave during the practice. Note that you do not need to minimize the number of commands in the solution, find any valid sequence of at most three commands.

输入格式

The first line contains an integer nn (2<=n<=1000)(2<=n<=1000) — the number of horses in the row. The second line contains nn distinct integers a1,a2,...,ana_{1},a_{2},...,a_{n} (1<=ai<=n)(1<=a_{i}<=n) , where aia_{i} is the number of the ii -th left horse in the row after the practice.

输出格式

The first line should contain integer kk (0<=k<=3)(0<=k<=3) — the number of commads Xenia gave during the practice. In each of the next kk lines print two integers. In the ii -th line print numbers li,ril_{i},r_{i} (1<=li<ri<=n)(1<=l_{i}<r_{i}<=n) — Xenia's ii -th command during the practice.

It is guaranteed that a solution exists. If there are several solutions, you are allowed to print any of them.

输入输出样例

  • 输入#1

    5
    1 4 3 2 5
    

    输出#1

    1
    2 4
    
  • 输入#2

    6
    2 1 4 3 6 5
    

    输出#2

    3
    1 2
    3 4
    5 6
    
首页