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:

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.


前 i 次旋转下,是否可以旋转到 j 度的位置,那么转移方程有:dp[i][j] = dp[ i - 1 ][ j - a[i] ] | dp[ i - 1 ][ j + a[i] ]

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <numeric>
#include <cmath>
#include<unordered_set>
#define ll long long
using namespace std;
int dir[][] = { {,},{-,},{,},{,-} }; int main()
{
int n;
cin >> n;
vector<int> a(n+1);
for (int i = 1; i <= n; i++)
cin >> a[i];
vector<vector<bool>> dp(16, vector<bool>(360));
dp[0][0] = true;
for (int i = 1; i <= n; i++)
{
for (int j = 0; j < 360; j++)
{
if (dp[i - 1][(j - a[i] + 360) % 360])
dp[i][j] = true;
if (dp[i - 1][(j + a[i] + 360) % 360])
dp[i][j] = true;
}
}
cout << (dp[n][0] ? "YES" : "NO") << endl;
//system("pause");
return 0;
}

最新文章

  1. jquery mobile
  2. BZOJ1129 : [POI2008]Per
  3. Spring的注解方式
  4. AndroidManifest修改重打包全过程
  5. 去除Linq to Sql 查询结果中的空格
  6. 队列的实现(JAVA)
  7. 关于AppStore上传相关问题
  8. HtmlTextNode &amp; HtmlCommentNode
  9. cocos2dx定时器
  10. ASP.NET MVC3中的路由系统 Routes
  11. 日常问题181101: ueditor文本编辑器
  12. 怎么样启用红米手机5的ROOT权限
  13. 500 OOPS: bad bool value in config file for: anon_world_readable_only Login failed.
  14. iOS 横屏模态进入下一级界面, 竖屏退出
  15. php 创建返回结果配置文件 实例
  16. mysql更新字段值提示You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column To disable safe mode
  17. win10专业版激活方法
  18. Oracle 10.2.0.1 精简客户端配置
  19. Codeforces Beta Round #11 A. Increasing Sequence 贪心
  20. Linux 系统文件类型

热门文章

  1. navicat永久激活
  2. php Allowed memory size of 134217728 bytes exhausted
  3. 用MyEclipse远程debug
  4. Spring Boot整合Dubbo2.x,解决其中遇到的坑
  5. jQuery---学习roadmap---4 parts
  6. 2020算法设计竞赛 H 坐火车
  7. Linux 配置mysql 远程连接
  8. Centos6.5安装Nmap、tcpdump、mysql、tomcat、靶场WAVSEP
  9. python 数组array的一些操作
  10. android 获取webview内容真实高度(webview上下可滚动距离)