欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

B. Petr and a Combination Lock

程序员文章站 2023-12-26 23:04:27
...

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Petr has just bought a new car. He's just arrived at the most known Petersburg's petrol station to refuel it when he suddenly discovered that the petrol tank is secured with a combination lock! The lock has a scale of 360360 degrees and a pointer which initially points at zero:

B. Petr and a Combination Lock

Petr called his car dealer, who instructed him to rotate the lock's wheel exactly nn times. The ii-th rotation should be aiai degrees, either clockwise or counterclockwise, and after all nn rotations the pointer should again point at zero.

This confused Petr a little bit as he isn't sure which rotations should be done clockwise and which should be done counterclockwise. As there are many possible ways of rotating the lock, help him and find out whether there exists at least one, such that after all nn rotations the pointer will point at zero again.

Input

The first line contains one integer nn (1≤n≤151≤n≤15) — the number of rotations.

Each of the following nn lines contains one integer aiai (1≤ai≤1801≤ai≤180) — the angle of the ii-th rotation in degrees.

Output

If it is possible to do all the rotations so that the pointer will point at zero after all of them are performed, print a single word "YES". Otherwise, print "NO". Petr will probably buy a new car in this case.

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

Examples

input

Copy

3
10
20
30

output

Copy

YES

input

Copy

3
10
10
10

output

Copy

NO

input

Copy

3
120
120
120

output

Copy

YES

Note

In the first example, we can achieve our goal by applying the first and the second rotation clockwise, and performing the third rotation counterclockwise.

In the second example, it's impossible to perform the rotations in order to make the pointer point at zero in the end.

In the third example, Petr can do all three rotations clockwise. In this case, the whole wheel will be rotated by 360360 degrees clockwise and the pointer will point at zero again.

 

解题说明:此题是一道模拟题,给你n个数,问你经过加或减的操作,最后和是否能整除360,可以使用二进制枚举方法来处理。

#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;


int main() 
{
	int n; scanf("%d\n", &n);
	int a[20];
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
	}
	for (int i = 0; i < 1 << n; i++)
	{
		int s = 0;
		for (int j = 0; j < n; j++) 
		{
			if (i & 1 << j)
			{
				s += a[j];
			}
			else
			{
				s -= a[j];
			}
		}
		if (s % 360 == 0) 
		{
			printf("yes\n");
			return 0;
		}
	}
	printf("no\n");
	return 0;
}

 

上一篇:

下一篇: