Given an array of integers, determine whether the array can be sorted in ascending order using only one of the following operations one time.

  1. Swap two elements.
  2. Reverse one sub-segment.

Determine whether one, both or neither of the operations will complete the task. Output is as follows.

  1. If the array is already sorted, output yes on the first line. You do not need to output anything else.

  2. If you can sort this array using one single operation (from the two permitted operations) then output yes on the first line and then:

    • If elements can only be swapped, and , output swap l r in the second line. and are the indices of the elements to be swapped, assuming that the array is indexed from to .
    • If elements can only be reversed, for the segment , output reverse l r in the second line. and are the indices of the first and last elements of the subarray to be reversed, assuming that the array is indexed from to . Here represents the subarray that begins at index and ends at index , both inclusive.

If an array can be sorted both ways, by using either swap or reverse, choose swap.

  1. If the array cannot be sorted either way, output no on the first line.

Example

Either swap the and at indices 3 and 4, or reverse them to sort the array. As mentioned above, swap is preferred over reverse. Choose swap. On the first line, print yes. On the second line, print swap 3 4.

Function Description

Complete the almostSorted function in the editor below.

almostSorted has the following parameter(s):

  • int arr[n]: an array of integers

Prints

  • Print the results as described and return nothing.

Input Format

The first line contains a single integer , the size of .
The next line contains space-separated integers where .

Constraints



All are distinct.

Output Format

  1. If the array is already sorted, output yes on the first line. You do not need to output anything else.

  2. If you can sort this array using one single operation (from the two permitted operations) then output yes on the first line and then:

    a. If elements can be swapped, and , output swap l r in the second line. and are the indices of the elements to be swapped, assuming that the array is indexed from to .

    b. Otherwise, when reversing the segment , output reverse l r in the second line. and are the indices of the first and last elements of the subsequence to be reversed, assuming that the array is indexed from to .

    represents the sub-sequence of the array, beginning at index and ending at index , both inclusive.

If an array can be sorted by either swapping or reversing, choose swap.

  1. If you cannot sort the array either way, output no on the first line.

Sample Input 1

STDIN   Function
-----   --------
2       arr[] size n = 2
4 2     arr = [4, 2]

Sample Output 1

yes  
swap 1 2

Explanation 1

You can either swap(1, 2) or reverse(1, 2). You prefer swap.

Sample Input 2

3
3 1 2

Sample Output 2

no

Explanation 2

It is impossible to sort by one single operation.

Sample Input 3

6
1 5 4 3 2 6

Sample Output 3

yes
reverse 2 5

Explanation 3

You can reverse the sub-array d[2...5] = "5 4 3 2", then the array becomes sorted.

  1. Challenge Walkthrough
    Let's walk through this sample challenge and explore the features of the code editor.1 of 6
  2. Review the problem statement
    Each challenge has a problem statement that includes sample inputs and outputs. Some challenges include additional information to help you out.2 of 6
  3. Choose a language
    Select the language you wish to use to solve this challenge.3 of 6
  4. Enter your code
    Code your solution in our custom editor or code in your own environment and upload your solution as a file.4 of 6
  5. Test your code
    You can compile your code and test it for errors and accuracy before submitting.5 of 6
  6. Submit to see results
    When you're ready, submit your solution! Remember, you can go back and refine your code anytime.6 of 6
  1. Check your score