Daenerys Targaryen has an army consisting of k groups of soldiers, the i-th group contains ai soldiers. She wants to bring her army to the other side of the sea to get the Iron Throne. She has recently bought an airplane to carry her army through the sea. The airplane has nrows, each of them has 8 seats. We call two seats neighbor, if they are in the same row and in seats {1, 2}, {3, 4}, {4, 5}, {5, 6} or {7, 8}.

A row in the airplane

Daenerys Targaryen wants to place her army in the plane so that there are no two soldiers from different groups sitting on neighboring seats.

Your task is to determine if there is a possible arranging of her army in the airplane such that the condition above is satisfied.

Input

The first line contains two integers n and k (1 ≤ n ≤ 10000, 1 ≤ k ≤ 100) — the number of rows and the number of groups of soldiers, respectively.

The second line contains k integers a1, a2, a3, ..., ak (1 ≤ ai ≤ 10000), where ai denotes the number of soldiers in the i-th group.

It is guaranteed that a1 + a2 + ... + ak ≤ 8·n.

Output

If we can place the soldiers in the airplane print "YES" (without quotes). Otherwise print "NO" (without quotes).

You can choose the case (lower or upper) for each letter arbitrary.

Examples
input
2 2
5 8
output
YES
input
1 2
7 1
output
NO
input
1 2
4 4
output
YES
input
1 4
2 2 1 2
output
YES
Note

In the first sample, Daenerys can place the soldiers like in the figure below:

In the second sample, there is no way to place the soldiers in the plane since the second group soldier will always have a seat neighboring to someone from the first group.

In the third example Daenerys can place the first group on seats (1, 2, 7, 8), and the second group an all the remaining seats.

In the fourth example she can place the first two groups on seats (1, 2) and (7, 8), the third group on seats (3), and the fourth group on seats (5, 6).


  题目大意 (题目太长简(长)洁(了),无法概述)

  因为4个挨在一起的位置很复杂,所以考虑先把所有4个位置挨在一起的座位干掉。

  当存在某个队还没被安排的人数大于等于4,那么就扔一个这样的座位给他们,如果不存在这样的座位,那就分配一个两个座的座位。如果分配出了问题,直接输出NO吧。

  然后考虑剩余人数为3的队伍,要么安排4座,要么安排1个两座剩1人(余下来的一人等会儿考虑,并加入暂时无法安排的人)。

  此时,所有队伍剩余人数不超过2人。

  继续考虑剩余人数为2的队伍,如果存在4座,那么旁边就会多出可以坐1人的座位,否则就安排坐2座,如果没有2座,就把暂时无法安排的人数加2。

  最后所有剩下的座位显然都是要1个人1个人地坐了,所以计算一下,判断还可以坐的人数是否大于等于暂时无法安排的人数。

Code

 /**
* Codeforces
* Problem#839B
* Accepted
* Time: 15ms
* Memory: 2100k
*/
#include <bits/stdc++.h>
using namespace std; int n, k;
int rest[], cnt[]; inline void init() {
scanf("%d%d", &n, &k);
rest[] = n << , rest[] = n;
for(int i = , x; i <= k; i++) {
scanf("%d", &x);
while(x > ) {
if(rest[])
rest[]--, x -= ;
else if(rest[])
rest[]--, x -= ;
else {
puts("NO");
exit();
}
}
if(x)
cnt[x]++;
}
} inline void solve() {
while(cnt[]--) {
if(rest[])
rest[]--, rest[]++;
else if(rest[])
rest[]--;
else
cnt[] += ;
}
puts((rest[] * + rest[] + rest[] >= cnt[]) ? ("YES") : ("NO"));
} int main() {
init();
solve();
return ;
}

最新文章

  1. python的颜色显示
  2. Processing与Java混编初探
  3. 自定义控件的自定义的属性attrs.xml下的declare-styleable中format详解
  4. Vmware 虚拟的Linux系统如何与宿主主机共享上网
  5. HBase-再看HBase
  6. 手机淘宝用JS来动态写meta标签(1像素边框处理方法)
  7. 关于sql 资源竞争死锁现象
  8. Android中SharedPreferences使用方法介绍
  9. 基于物联网操作系统HelloX的智慧家庭体系架构
  10. 强化:把treeview的QString路径转换为QModelIndex节点,有了节点就什么都好办了
  11. iOS如何添加照片模拟器(附带诉讼)
  12. linux复制文件命令scp
  13. 【Ubuntu 16】 wifi连接 并解决无桌面图标问题
  14. HDU 5504 GT and sequence 模拟
  15. 关于PLC
  16. Jenkins设置备份
  17. uploadify中文开发文档,解决php多图上传
  18. 20155228 实验五 Android开发基础
  19. Linux Centos 7.4 内核升级
  20. MySQL用户管理、常用sql语句、MySQL数据库备份恢复

热门文章

  1. vue中实现浏览器的复制功能
  2. 解决Windows内存问题的两个小工具RamMap和VMMap
  3. 6.短信验证码60s倒计时
  4. !! MACD战法总结
  5. centos安装java的jdk
  6. Spring MVC / Boot
  7. clientWidth,offsetWidth,scrollWidth区别
  8. tcp/ip 3次握手和4次挥手
  9. 查询和修改mysql最大连接数的方法
  10. vue 父子组件