def restore_array(n: int, b: List[int]) -> Union[str, Tuple[str, List[int]]]:
    """
    While discussing a proper problem A for a Codeforces Round, Kostya created a cyclic array of positive integers $a_1, a_2, \ldots, a_n$. Since the talk was long and not promising, Kostya created a new cyclic array $b_1, b_2, \ldots, b_{n}$ so that $b_i = (a_i \mod a_{i + 1})$, where we take $a_{n+1} = a_1$. Here $mod$ is the modulo operation. When the talk became interesting, Kostya completely forgot how array $a$ had looked like. Suddenly, he thought that restoring array $a$ from array $b$ would be an interesting problem (unfortunately, not A).
    
    
    -----Input-----
    
    The first line contains a single integer $n$ ($2 \le n \le 140582$) — the length of the array $a$.
    
    The second line contains $n$ integers $b_1, b_2, \ldots, b_{n}$ ($0 \le b_i \le 187126$).
    
    
    -----Output-----
    
    If it is possible to restore some array $a$ of length $n$ so that $b_i = a_i \mod a_{(i \mod n) + 1}$ holds for all $i = 1, 2, \ldots, n$, print «YES» in the first line and the integers $a_1, a_2, \ldots, a_n$ in the second line. All $a_i$ should satisfy $1 \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 $a$, print «NO» in one line.
    
    You can print each letter in any case (upper or lower).
    
    
    -----Examples-----
    Input
    4
    1 3 1 0
    
    Output
    YES
    1 3 5 2
    
    Input
    2
    4 4
    
    Output
    NO
    
    
    
    -----Note-----
    
    In the first example:  $1 \mod 3 = 1$  $3 \mod 5 = 3$  $5 \mod 2 = 1$  $2 \mod 1 = 0$
    """


# Tests

def check(candidate):
    assert candidate(4, [1, 3, 1, 0]) == ('YES', [1, 3, 5, 2])
    assert candidate(2, [4, 4]) == 'NO'
    assert candidate(5, [5, 4, 3, 2, 1]) == ('YES', [5, 20, 16, 13, 11])
    assert candidate(10, [3, 3, 3, 5, 6, 9, 3, 1, 7, 3]) == ('YES', [38, 35, 32, 29, 24, 9, 52, 49, 48, 41])
    assert candidate(100, [57, 5, 28, 44, 99, 10, 66, 93, 76, 32, 67, 92, 67, 81, 33, 3, 6, 6, 67, 10, 41, 72, 5, 71, 27, 22, 21, 54, 21, 59, 36, 62, 43, 39, 28, 49, 55, 65, 21, 73, 87, 40, 0, 62, 67, 59, 40, 18, 56, 71, 15, 97, 73, 73, 2, 61, 54, 44, 6, 52, 25, 34, 13, 20, 18, 13, 25, 51, 19, 66, 63, 87, 50, 63, 82, 60, 11, 11, 54, 58, 88, 20, 33, 40, 85, 68, 13, 74, 37, 51, 63, 32, 45, 20, 30, 28, 32, 64, 82, 19]) == ('YES', [332, 275, 270, 242, 99, 4629, 4619, 4553, 4460, 4384, 4352, 4285, 4193, 4126, 4045, 4012, 4009, 4003, 3997, 3930, 3920, 3879, 3807, 3802, 3731, 3704, 3682, 3661, 3607, 3586, 3527, 3491, 3429, 3386, 3347, 3319, 3270, 3215, 3150, 3129, 3056, 2969, 2929, 2929, 2867, 2800, 2741, 2701, 2683, 2627, 2556, 2541, 2444, 2371, 2298, 2296, 2235, 2181, 2137, 2131, 2079, 2054, 2020, 2007, 1987, 1969, 1956, 1931, 1880, 1861, 1795, 1732, 1645, 1595, 1532, 1450, 1390, 1379, 1368, 1314, 1256, 1168, 1148, 1115, 1075, 990, 922, 909, 835, 798, 747, 684, 652, 607, 587, 557, 529, 497, 433, 351])
    assert candidate(5, [1, 2, 3, 4, 5]) == ('YES', [20, 19, 17, 14, 5])
    assert candidate(2, [0, 0]) == ('YES', [1, 1])
    assert candidate(3, [1, 3, 0]) == ('YES', [7, 3, 7])
    assert candidate(2, [100000, 100000]) == 'NO'
    assert candidate(5, [1, 0, 0, 1, 1]) == ('YES', [3, 2, 2, 1, 4])
check(restore_array)