#K50272. Reduce Array to Prime

    ID: 28828 Type: Default 1000ms 256MiB

Reduce Array to Prime

Reduce Array to Prime

You are given an array of n positive integers \(a_1, a_2, \ldots, a_n\)

You must perform exactly \(n-1\) operations. In one operation you select two adjacent elements in the array (i.e. elements at positions \(i\) and \(i+1\)) and replace them with their sum. Formally, if you choose positions \(i\) and \(i+1\) then these two elements are removed and the value \(a_i+a_{i+1}\) is inserted at the position of the first element. Note that the sum of all elements remains invariant regardless of the order of operations.

Your task is to determine whether it is possible to perform these operations so that the final remaining number is a prime number. Since the final number is the sum of all original numbers, the problem reduces to checking whether \(S = \sum_{i=1}^{n}a_i\) is prime.

If \(S\) is prime, output "YES" and print any valid sequence of exactly \(n-1\) operations (using 0-indexed positions) that would combine the array into a single number. Otherwise, output "NO".

Note: When \(n=1\), no operations are needed. In that case, simply check if the single element is prime.

inputFormat

The input is given via standard input and has the following format:

  • The first line contains an integer \(n\) \( (1 \le n \le 10^5) \).
  • The second line contains \(n\) positive integers \(a_1, a_2, \ldots, a_n\) separated by spaces \( (1 \le a_i \le 10^5) \).

outputFormat

If it is possible to reduce the array to a single prime number, print YES on the first line. Then, print exactly \(n-1\) lines, each containing two integers \(i\) and \(j\) (0-indexed) representing the positions of the two adjacent elements chosen in that operation. If \(n = 1\) and the single element is prime, only print YES.

If it is not possible, print NO.

## sample
3
2 2 3
YES

0 1 0 1

</p>