Petr and a Combination Lock

Practice this coding question on Coding Gurukul.

Problem statement

Petr is testing a circular dial on a storage locker. The pointer begins at zero degrees, and the test card lists rotations that must all be performed. For each rotation he may choose clockwise or counterclockwise, but he cannot skip an angle or change its size. Your task Decide whether some choice of direction for every listed angle returns the pointer to zero after all rotations. A full turn is 360 degrees. Important details Use every angle exactly once in the listed order. Returning to zero means the signed total is any multiple of 360, including zero or a negative multiple. Intermediate pointer positions do not matter. Report existence only; do not print a sequence of directions. Worked example For angles 15, 35 and 50, clockwise 15 and 35 followed by counterclockwise 50 gives a total of zero, so print YES. Two rotations of 180 degrees can also return to zero by completing one full turn. A single 90-degree rotation cannot return to zero.

Input format

Read n, followed by n angles separated by whitespace.

Output format

Print YES if possible, otherwise NO.

Constraints

1 <= n <= 15; 1 <= angle[i] <= 180.

Sample input

3
15 35 50

Sample output

YES

Sign in to run or submit a solution in C++, Java or Python.

Loading Coding Gurukul…