This page is still under construction.

Parts of this page are still being built. What you see may change.

3-Second Sort

Interview

Time limit2sMemory limit1024 MB

Summary
Given a sequence that is not sorted, decide whether at most 3 element replacements can make it nondecreasing, and output one such sequence of operations.
Level

Medium7 of 10

Topics
Greedy, Implementation, Array, Sorting
Solved
No attempts yet

Problem

While you are peacefully reading this problem, the extremist fundamentalist mint-chocolate terrorist Kim Junwon has already seized the school outside the auditorium.

If you do not make the given sequence sorted in ascending order within 3 seconds, the mint-chocolate bomb planted in the auditorium will explode.

You may replace any element AiA_i of the sequence with another number XX.

This operation takes 1 second.

3...

2...

1...

Input

The first line gives the length NN of the sequence you must make sorted.

The second line gives NN integers A1,A2,⋯ ,ANA_1, A_2, \cdots , A_N representing the elements of the sequence, separated by spaces.

Output

If you can make the sequence sorted in ascending order within 3 operations,

  • Print YES on the first line.

  • From the second line onward, print a method to make the sequence sorted in the following form.

    • On the first line, print the number of operations KK.
    • Then, over KK lines, print the operations to apply in order.
      Specifically, on each line print two integers ii and XX. This means the operation of replacing element AiA_i with XX. (1≤i≤N1 \le i \le N, 1≤X≤1 000 000 0001 \leq X \leq 1\,000\,000\,000)

You do not need to minimize the number of operations, and if several methods are possible, you may print any one of them. You may modify the same element multiple times.

If you cannot make the sequence sorted in ascending order within 3 operations,

  • Print NO on the first line.

Constraints

  • 1≤N≤200 0001 \leq N \leq 200\,000
  • 1≤Ai≤1 000 000 0001 \leq A_i \leq 1\,000\,000\,000 (1≤i≤N1 \le i \le N)
  • The sequence is not given already sorted in ascending order.

Hint

A sequence A1,⋯ ,ANA_1, \cdots, A_N being sorted in ascending order means that A1≤A2A_1 \le A_2, A2≤A3A_2 \le A_3, ⋯\cdots, AN−1≤ANA_{N-1} \le A_N.

Examples3

  1. Example 1

    Input
    5
    6 7 10 8 20
    
    Expected output
    YES
    1
    4 15
    
  2. Example 2

    Input
    3
    9 1 7
    
    Expected output
    YES
    3
    1 1
    2 2
    3 3
    
  3. Example 3

    Input
    10
    10 9 8 7 6 5 4 3 2 1
    
    Expected output
    NO