#P1028E. Restore Array

    ID: 4348 Type: RemoteJudge 2000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>constructive algorithms*2400

Restore Array

No submission language available for this problem.

Description

While discussing a proper problem A for a Codeforces Round, Kostya created a cyclic array of positive integers a1,a2,,ana_1, a_2, \ldots, a_n. Since the talk was long and not promising, Kostya created a new cyclic array b1,b2,,bnb_1, b_2, \ldots, b_{n} so that bi=(aimod  ai+1)b_i = (a_i \mod a_{i + 1}), where we take an+1=a1a_{n+1} = a_1. Here modmod is the modulo operation. When the talk became interesting, Kostya completely forgot how array aa had looked like. Suddenly, he thought that restoring array aa from array bb would be an interesting problem (unfortunately, not A).

The first line contains a single integer nn (2n1405822 \le n \le 140582) — the length of the array aa.

The second line contains nn integers b1,b2,,bnb_1, b_2, \ldots, b_{n} (0bi1871260 \le b_i \le 187126).

If it is possible to restore some array aa of length nn so that bi=aimod  a(imod  n)+1b_i = a_i \mod a_{(i \mod n) + 1} holds for all i=1,2,,ni = 1, 2, \ldots, n, print «YES» in the first line and the integers a1,a2,,ana_1, a_2, \ldots, a_n in the second line. All aia_i should satisfy 1ai10181 \le a_i \le 10^{18}. We can show that if an answer exists, then an answer with such constraint exists as well.

It it impossible to restore any valid aa, print «NO» in one line.

You can print each letter in any case (upper or lower).

Input

The first line contains a single integer nn (2n1405822 \le n \le 140582) — the length of the array aa.

The second line contains nn integers b1,b2,,bnb_1, b_2, \ldots, b_{n} (0bi1871260 \le b_i \le 187126).

Output

If it is possible to restore some array aa of length nn so that bi=aimod  a(imod  n)+1b_i = a_i \mod a_{(i \mod n) + 1} holds for all i=1,2,,ni = 1, 2, \ldots, n, print «YES» in the first line and the integers a1,a2,,ana_1, a_2, \ldots, a_n in the second line. All aia_i should satisfy 1ai10181 \le a_i \le 10^{18}. We can show that if an answer exists, then an answer with such constraint exists as well.

It it impossible to restore any valid aa, print «NO» in one line.

You can print each letter in any case (upper or lower).

Samples

Sample Input 1

4
1 3 1 0

Sample Output 1

YES
1 3 5 2

Sample Input 2

2
4 4

Sample Output 2

NO

Note

In the first example:

  • 1mod  3=11 \mod 3 = 1
  • 3mod  5=33 \mod 5 = 3
  • 5mod  2=15 \mod 2 = 1
  • 2mod  1=02 \mod 1 = 0