#P12417. Equalizing a Sequence via Pairwise Multiplication

    ID: 14520 Type: Default 1000ms 256MiB

Equalizing a Sequence via Pairwise Multiplication

Equalizing a Sequence via Pairwise Multiplication

Given a sequence of real numbers (a_1, a_2, \ldots, a_n), you are allowed to perform the following operation any number of times: choose two indices (i) and (j) (they may be arbitrary and not necessarily distinct between operations) and update both values simultaneously as follows: [ a_i \leftarrow a_i \times a_j, \quad a_j \leftarrow a_i \times a_j. ]

For example, if the sequence is (7,,4,,5), and you choose indices corresponding to (7) and (5), then after one operation the sequence becomes (35,,4,,35) (since (7\times5=35)).

Your task is to design a fixed operation scheme (i.e. a predetermined sequence of operations that depends only on (n)) such that for any sequence of (n) real numbers, if you perform the operations in that order, all the numbers become equal at the end.

It turns out that such a universal scheme exists if and only if (n) is a power of two. When (n) is not a power of two, no fixed sequence of operations can equalize every input sequence.

Your program will be given an integer (n) followed by (n) real numbers. If (n) is a power of two, you must output a valid sequence of operations that will force the sequence to become constant, regardless of the initial values. Otherwise, output “NO".

A valid operation scheme works as follows for (n=2^k} (with (k\ge 1)):

  1. First, pair adjacent indices to equalize them. For every odd index (i) (i.e. (i=1,3,5,\dots)), perform an operation on (i) and (i+1).
  2. Then, for block sizes of (2,4,8,\dots, n), merge blocks by performing operations between corresponding elements of consecutive blocks. Specifically, for block size (s), for every block starting at index (i) (with step (2s)), for each (j=0,1,\dots, s-1), perform an operation on indices (i+j) and (i+j+s).

After performing all these operations, every element becomes [ \prod_{i=1}^n a_i] (in the multiplicative (or logarithmic) sense).

Note: The operations are 1-indexed.

inputFormat

The first line contains an integer (n) ((1 \le n \le 10^5)). The second line contains (n) real numbers (a_1, a_2, \ldots, a_n).

Note: It is guaranteed that if (n) is a power of two then a valid operation scheme exists. Otherwise, the answer is “NO".

outputFormat

If (n) is a power of two, first output a line with the word “YES" and on the next line output an integer (m) denoting the number of operations. Then output (m) lines, each containing two integers (i) and (j) (1-indexed) representing an operation applied on elements at positions (i) and (j) (in that order).

If (n) is not a power of two, output a single line containing “NO".

sample

2
3.0 5.0
YES

1 1 2

</p>