#C848. Wizard Spell Assignment Problem

    ID: 52466 Type: Default 1000ms 256MiB

Wizard Spell Assignment Problem

Wizard Spell Assignment Problem

In this problem, you are given a circular arrangement of N wizards. Each wizard makes a claim regarding the total number of spells that can be cast by themselves and their two adjacent wizards. Formally, you are given an integer N and an array a of length N, where the i-th wizard claims that the sum of spells of wizard ((i-1) mod N), wizard i, and wizard ((i+1) mod N) is equal to (a_i). Each wizard can either cast 0 or 1 spell. Your task is to determine whether there exists an assignment of spells (0 or 1 for each wizard) such that all the wizards' claims are satisfied.

Note: The input guarantees that (1 \le a_i \le 3) for every wizard. Print Yes if such an assignment exists and No otherwise.

Example: For N = 5 and a = [2, 2, 2, 3, 2], one valid assignment is possible, so the answer is Yes.

inputFormat

The input is given via standard input (stdin). The first line contains an integer N denoting the number of wizards. The second line contains N integers (a_0, a_1, \dots, a_{N-1}), where (a_i) represents the claim of the i-th wizard.

outputFormat

Output a single line to the standard output (stdout) containing Yes if there exists a valid assignment of spells, or No otherwise.## sample

5
2 2 2 3 2
Yes