Daenerys Targaryen has an army consisting of k groups of soldiers, the i-th group contains a_{i} 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 n rows, 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}.

 [Image] 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 a_1, a_2, a_3, ..., a_{k} (1 ≤ a_{i} ≤ 10000), where a_{i} denotes the number of soldiers in the i-th group.

It is guaranteed that a_1 + a_2 + ... + a_{k} ≤ 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:

 [Image] 

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).

Difficulty: HARD
Tags: Complete search

Implementation

Greedy algorithms
Skill types: Complete search

Greedy algorithms

Starter code:

Solutions:
(n, k) = list(map(int, input().split()))
a = sorted(list(map(int, input().split())))[::-1]
m = n
for j in range(len(a)):
	waste = min(a[j] // 4, m)
	m -= waste
	a[j] -= waste * 4
	if m == 0:
		break
(m1, m2, m3, msukabljat) = (0, 0, 0, [])
for x in a:
	m1 += x == 1
	m2 += x == 2
	m3 += x == 3
	msukabljat += [x] if x >= 4 else []
waste = min(m1, m2, m)
(m, m1, m2) = (m - waste, m1 - waste, m2 - waste)
waste = min(m3 // 2, m // 2)
(m, m3) = (m - waste * 2, m3 - waste * 2)
waste = min(m2 // 3, m // 2)
(m, m2) = (m - waste * 2, m2 - waste * 3)
waste = min(m1, m2, m3, m // 2)
(m, m1, m2, m3) = (m - waste * 2, m1 - waste, m2 - waste, m3 - waste)
waste = min(m3, m)
(m, m3) = (m - waste, m3 - waste)
waste = min(m1 // 2, m)
(m, m1) = (m - waste, m1 - 2 * waste)
waste = min(m1, m)
(m, m1) = (m - waste, m1 - waste)
waste = min(m2, m)
(m, m2) = (m - waste, m2 - waste)
if m1 + m2 + m3 * 2 + sum([x // 2 + x % 2 for x in msukabljat]) <= 2 * n:
	print('YES')
else:
	print('NO')


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
(fours, twos, ones) = (n, 2 * n, 0)
for i in range(k):
	while a[i] >= 4:
		a[i] -= 4
		if fours:
			fours -= 1
		elif twos >= 2:
			twos -= 2
		else:
			print('NO')
			exit()
for i in range(k):
	if a[i] == 3:
		a[i] = 0
		if fours:
			fours -= 1
		elif twos >= 2:
			twos -= 2
		else:
			print('NO')
			exit()
for i in range(k):
	if a[i] == 2:
		a[i] = 0
		if twos:
			twos -= 1
		elif fours:
			fours -= 1
			ones += 1
		elif ones >= 2:
			ones -= 2
		else:
			print('NO')
			exit()
ones += 2 * fours + twos
if a.count(1) > ones:
	print('NO')
else:
	print('YES')


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
c = [0, 0, 0, 0]
for t in a:
	c[0] += t // 4
	if t % 4:
		c[t % 4] += 1
c[0] += c[3]
c[3] = 0
if c[0] > n:
	c[2] += 2 * (c[0] - n)
	c[0] = n
t = min(n - c[0], c[1], c[2])
c[0] += t
c[1] -= t
c[2] -= t
t = min(n - c[0], (c[1] + 1) // 2)
c[0] += t
c[1] -= min(c[1], t * 2)
t = min(n - c[0], c[2])
c[0] += t
c[2] -= min(c[2], t + t // 2)
c[2] += c[1]
c[1] = 0
print('YES' if c[2] <= 2 * n else 'NO')


(N, K) = map(int, input().split())
a = [int(i) for i in input().split()]
N = {4: N, 3: 0, 2: N * 2, 1: 0}
works = True
a.sort(reverse=True)
for i in range(K):
	r4 = min(N[4], a[i] // 4)
	a[i] -= 4 * r4
	N[4] -= r4
a.sort(reverse=True)
for i in range(K):
	if a[i] == 0:
		continue
	r2 = min(N[2], a[i] // 2)
	a[i] -= 2 * r2
	N[2] -= r2
a.sort(reverse=True)
for i in range(K):
	if a[i] == 0:
		continue
	if a[i] >= 4:
		works = False
		break
	if a[i] == 3:
		x = min(N[4], 1)
		a[i] -= 3 * x
		N[4] -= x
	elif a[i] == 2:
		x = min(N[2], a[i] // 2)
		a[i] -= 2 * x
		N[2] -= x
		x = min(N[4], a[i] // 2)
		a[i] -= 2 * x
		N[4] -= x
		N[1] += x
		x = min(N[1], a[i])
		a[i] -= x
		N[1] -= x
	elif a[i] == 1:
		N[1] += N[2]
		N[1] += 2 * N[4]
		N[4] = 0
		N[2] = 0
		x = min(N[1], a[i])
		a[i] -= x
		N[1] -= x
	if a[i] != 0:
		works = False
		break
if works:
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
p = n
for i in range(m):
	b = l[i] // 4
	l[i] = l[i] - 4 * min(p, l[i] // 4)
	p = p - min(p, b)
p1 = n * 2
for i in range(m):
	b = l[i] // 2
	l[i] = l[i] - 2 * min(p1, l[i] // 2)
	p1 = p1 - min(p1, b)
p2 = p + p1
p3 = p
for i in range(m):
	b = l[i] // 2
	l[i] = l[i] - 2 * min(p2, l[i] // 2)
	p2 = p2 - min(p2, b)
k = 0
p3 += p2
for i in range(m):
	k = k + l[i]
if k > p3:
	print('NO')
else:
	print('YES')


import sys
(n, k) = [int(x) for x in input().split()]
arr = list(map(int, input().split()))
cnt_2 = 2 * n
cnt_4 = n
cnt_1 = 0
i = 0
while cnt_4 > 0 and i < k:
	tmp = int(arr[i] / 4)
	if tmp > 0 and cnt_4 > 0:
		arr[i] = arr[i] - 4 * min(tmp, cnt_4)
		cnt_4 = cnt_4 - min(tmp, cnt_4)
	i = i + 1
if cnt_4 > 0:
	cnt_2 = cnt_2 + cnt_4
	cnt_1 = cnt_1 + cnt_4
	cnt_4 = 0
i = 0
while cnt_2 > 0 and i < k:
	tmp = int(arr[i] / 2)
	if tmp > 0 and cnt_2 > 0:
		arr[i] = arr[i] - 2 * min(tmp, cnt_2)
		cnt_2 = cnt_2 - min(tmp, cnt_2)
	i = i + 1
if cnt_2 > 0:
	cnt_1 = cnt_1 + cnt_2
	cnt_2 = 0
i = 0
while i < k:
	tmp = arr[i]
	if tmp > cnt_1:
		print('NO')
		sys.exit(0)
	elif tmp > 0 and tmp <= cnt_1:
		cnt_1 = cnt_1 - tmp
		arr[i] = arr[i] - tmp
	i = i + 1
print('YES')


from math import ceil
(n, k) = map(int, input().split())
a = list(map(int, input().split()))

def solve(n, k, a):
	(one, two, four) = (0, n * 2, n)
	for size in a:
		while size >= 4:
			if four > 0:
				four -= 1
			else:
				two -= 2
			size -= 4
		while size > 0:
			if four > 0:
				four -= 1
				if size == 2:
					one += 1
				elif size == 1:
					two += 1
				break
			elif two > 0:
				two -= 1
				size -= 2
			elif one > 0:
				one -= 1
				size -= 1
			else:
				return 'NO'
	return 'YES'
print(solve(n, k, sorted(a, reverse=True)))


import sys
import inspect
import re
import math
from pprint import pprint as pp
mod = 998244353
MAX = 10 ** 15

def deb(p):
	for line in inspect.getframeinfo(inspect.currentframe().f_back)[3]:
		m = re.search('\\bdeb\\s*\\(\\s*([A-Za-z_][A-Za-z0-9_]*)\\s*\\)', line)
		print('%s %d' % (m.group(1), p))

def vector(size, val=0):
	vec = [val for i in range(size)]
	return vec

def matrix(rowNum, colNum, val=0):
	mat = []
	for i in range(rowNum):
		collumn = [val for j in range(colNum)]
		mat.append(collumn)
	return mat

def main():
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	(x, y, z) = (n, 2 * n, 0)
	for i in range(k):
		temp = min(a[i] // 4, x)
		a[i] -= 4 * temp
		x -= temp
	y += x
	z += x
	for i in range(k):
		temp = min(a[i] // 2, y)
		a[i] -= 2 * temp
		y -= temp
	z += y
	for i in range(k):
		temp = min(a[i], z)
		a[i] -= temp
		z -= temp
	for i in range(k):
		if a[i]:
			return print('NO')
	print('YES')
main()


tmp = input().split()
n = int(tmp[0])
k = int(tmp[1])
tmp = input().split()
sum = 0
sum1 = 0
sum2 = 0
for i in range(k):
	if int(tmp[i]) % 4 == 2:
		sum2 += 1
	sum += int(tmp[i])
	sum1 += int(tmp[i]) % 2
if sum2 > 3 * n:
	if sum + sum1 + (sum2 - 3 * n) * 2 <= 8 * n:
		print('YES')
	else:
		print('NO')
elif sum + sum1 <= 8 * n:
	print('YES')
else:
	print('NO')


def func(a):
	if a < 0:
		return 0
	else:
		return a
(n, k) = list(map(int, input().split()))
l = list(map(int, input().split()))
two = 2 * n
four = n
baki = []
for val in l:
	if val >= 4:
		ans = min(four, val // 4)
		val = val - ans * 4
		four -= ans
	ans = min(two, val // 2)
	val = val - ans * 2
	two -= ans
	baki.append(func(val))
store = sum(baki)
if store == 0:
	print('YES')
elif store > 0 and four == 0 and (two == 0):
	print('NO')
else:
	baki.sort(reverse=True)
	cap1 = four
	cap2 = four
	for val in baki:
		if val == 3:
			if cap1 > 0 and cap2 > 0:
				cap1 -= 1
				cap2 -= 1
			else:
				two -= 2
		elif val == 2:
			if two > 0:
				two -= 1
			elif cap1 > 0:
				cap1 -= 1
			else:
				cap2 -= 2
		elif val == 1:
			if cap2 > 0:
				cap2 -= 1
			elif cap1 > 0:
				cap1 -= 1
			else:
				two -= 1
	if cap2 < 0 or cap1 < 0 or two < 0:
		print('NO')
	else:
		print('YES')


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
all_sum = sum(a)
(r4, r2) = (n, n * 2)
for v in range(len(a)):
	mid = a[v] // 4
	a[v] = a[v] % 4
	if mid <= r4:
		r4 -= mid
	else:
		a[v] += 4 * (mid - r4)
		r4 = 0
	if r4 == 0:
		break
mid = 0
r22 = 0
for v in a:
	if v % 2 == 1:
		mid += 1
	r22 += v // 2
if r4 > 0:
	mid -= r4
	r22 -= r4
	if mid < 0:
		r22 -= mid // -2
		mid = 0
if r22 + mid > r2:
	print('NO')
else:
	print('YES')


import sys
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
mid = n
side = n * 2

def removeZeroes(a):
	return [x for x in a if x > 0]
for i in range(len(a)):
	if a[i] >= 4:
		while a[i] >= 4 and (mid > 0 or side > 1):
			a[i] -= 4
			if mid:
				mid -= 1
			else:
				side -= 2
for i in range(len(a)):
	if not (mid > 0 or side > 1):
		break
	if a[i] == 3:
		if mid > 0:
			mid -= 1
		else:
			side -= 2
		a[i] = 0
a = removeZeroes(a)
if a.count(2) + a.count(1) != len(a):
	print('NO')
	return
for i in range(len(a)):
	if a[i] == 2 and side > 0:
		side -= 1
		a[i] = 0
for i in range(len(a)):
	if a[i] == 1 and side > 0:
		side -= 1
		a[i] = 0
a = removeZeroes(a)
a.sort()
while len(a) > 0 and a[0] == 1 and (a[-1] == 2) and (mid > 0):
	a = a[1:-1]
	mid -= 1
if len(a) > 0 and a[0] == 1:
	if (a.count(1) + 1) // 2 <= mid:
		print('YES')
		return
	else:
		print('NO')
		return
elif len(a) > 0 and a[0] == 2:
	while len(a) > 2 and mid > 1:
		a = a[3:]
		mid -= 2
	if mid >= len(a):
		print('YES')
		return
if len(a) > 0:
	print('NO')
else:
	print('YES')


def test():
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	total = n * 8
	place = 0
	sum = 0
	i = 0
	temp = 0
	flag = 0
	while i < k:
		sum += a[i]
		if a[i] % 2 is 1:
			place += 1
		else:
			flag += 1
		if a[i] % 4 != 0:
			temp += 1
		i += 1
	if sum == total:
		if place != 0 or (flag % 4 == 0 and n * 4 == k):
			print('NO')
		else:
			print('YES')
	elif sum + place > total or (n * 4 == k and flag // 4 == place):
		print('NO')
	else:
		print('YES')
test()


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
left4seat = n
left2seat = n * 2
left1seat = 0
for i in range(0, k):
	left4seat -= a[i] // 4
	if left4seat < 0:
		left2seat += 2 * left4seat
		left4seat = 0
index = 0
while index < k:
	leftSol = a[index] % 4
	if leftSol == 3:
		if left4seat > 0:
			left4seat -= 1
		elif left1seat > 0:
			if left2seat == 0 and left1seat >= 2:
				left1seat -= 3
			else:
				left2seat -= 1
				left1seat -= 1
		else:
			left2seat -= 2
	elif leftSol == 2:
		if left4seat > 0:
			left4seat -= 1
			left1seat += 1
		elif left2seat == 0 and left1seat >= 2:
			left1seat -= 2
		else:
			left2seat -= 1
	elif leftSol == 1:
		if left1seat > 0:
			left1seat -= 1
		elif left4seat > 0:
			left4seat -= 1
			left2seat += 1
		else:
			left2seat -= 1
	if left4seat < 0 or left2seat < 0:
		break
	index += 1
if index == k and left4seat >= 0 and (left2seat >= 0):
	print('YES')
else:
	print('NO')


def odd(a):
	return a % 2 == 1
[n, k] = [int(i) for i in input().split()]
(s2, s4) = (n * 2, n)
a = [int(i) for i in input().split()]
for i in range(k):
	(x, y) = divmod(a[i], 4)
	used4 = min(x, s4)
	unused4 = x - used4
	(s4, a[i]) = (s4 - used4, y + 4 * unused4)
	if a[i] == 3 and s4 > 0:
		s4 -= 1
		a[i] = 0
s1 = s4
if s4 > 0:
	s2 += s4
	for i in range(k):
		if a[i] == 1 and s1 > 0:
			(s1, a[i]) = (s1 - 1, 0)
used = sum(a) + len(list(filter(odd, a)))
if used <= s2 * 2 + s1:
	print('YES')
else:
	print('NO')


(n, k) = map(int, input().split())
l = [0, 0, 2 * n, 0, n]
inp = sorted(map(int, input().split()), reverse=True)
for i in range(k):
	if inp[i] > 1 and inp[i] & 1:
		inp[i] -= 1
		inp.append(1)
for a in inp:
	if a == 1:
		if l[1]:
			l[1] -= 1
			a = 0
		elif l[2]:
			l[2] -= 1
			a = 0
		elif l[4]:
			l[4] -= 1
			l[2] += 1
			a = 0
	else:
		while a > 2 and l[4]:
			a -= 4
			l[4] -= 1
		while a and l[2]:
			a -= 2
			l[2] -= 1
		while a and l[4]:
			a -= 2
			l[4] -= 1
			l[1] += 1
		while a and l[1]:
			a -= 1
			l[1] -= 1
	if a:
		print('NO')
		return
print('YES')


def main():
	(n, k) = map(int, input().split())
	(cnt, a4) = ([0] * 4, 0)
	for a in map(int, input().split()):
		a4 += a // 4
		cnt[a % 4] += 1
	(_, a1, a2, a3) = cnt
	a4 += a3
	if a4 * 2 < a2:
		n -= a4
		a2 -= a4 * 2
		if a1 * 3 > a2:
			n -= a2 // 3
			a1 -= a2 // 3
			a2 %= 3
			n -= (a1 + a2 + 3) // 4
		else:
			n -= a1
			a2 -= a1 * 3
			n -= a2 // 7 * 2 + (a2 % 7 + 2) // 3
		print(('YES', 'NO')[n < 0])
	else:
		print(('YES', 'NO')[n * 4 < a4 * 2 + a2 + a1])
main()


def solve(a, n, k):
	cnt = [0 for i in range(5)]
	(duplas, quads, sozinhos) = (2 * n, n, 0)
	for i in a:
		for j in range(k):
			while i >= 3:
				if quads > 0:
					i -= 4
					quads -= 1
				elif duplas > 0:
					i -= 2
					duplas -= 1
				else:
					return 'no'
		if i > 0:
			cnt[i] += 1
	while cnt[2]:
		if duplas > 0:
			duplas -= 1
			cnt[2] -= 1
		elif quads > 0:
			cnt[2] -= 1
			quads -= 1
			sozinhos += 1
		else:
			cnt[2] -= 1
			cnt[1] += 2
	if cnt[1] > sozinhos + duplas + 2 * quads:
		return 'no'
	return 'yes'
(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
print(solve(a, n, k))


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
mist2 = n * 2
mist4 = n
otn = 10
for i in range(k):
	otn = min(mist4, l[i] // 4)
	mist4 -= otn
	l[i] -= otn * 4
mist2 += mist4
for i in range(k):
	otn = min(mist2, l[i] // 2)
	mist2 -= otn
	l[i] -= otn * 2
mist4 += mist2
mist4 -= sum(l)
if mist4 >= 0:
	print('YES')
else:
	print('NO')


import sys
import heapq

class Seats:

	def __init__(self, n):
		self.seat_que = [-4] * n + [-2, -2] * n

	def push(self, x):
		heapq.heappush(self.seat_que, -x)

	def pop(self):
		seat = -heapq.heappop(self.seat_que)
		return seat
(n, m) = (int(x) for x in input().split())
soldiers = sorted([int(x) for x in input().split()], reverse=True)
seats = Seats(n)
for soldier in soldiers:
	while soldier > 0:
		try:
			seat = seats.pop()
			if seat > soldier:
				seats.push(seat - soldier - 1)
			soldier -= seat
		except IndexError:
			print('NO')
			sys.exit()
print('YES')


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
s2 = n * 2
s4 = n
s1 = 0
f = 1
rem1 = 0
rem2 = 0
for i in range(len(a)):
	if f:
		while a[i] >= 3:
			if s4 > 0:
				a[i] -= 4
				s4 -= 1
			elif s2 > 0:
				a[i] -= 2
				s2 -= 1
			else:
				f = 0
		if a[i] == 1 and f:
			rem1 += 1
		elif a[i] == 2 and f:
			rem2 += 1
while rem2 > 0 and f:
	if s2 > 0:
		rem2 -= 1
		s2 -= 1
	elif s4 > 0:
		rem2 -= 1
		s4 -= 1
		s1 += 1
	else:
		rem2 -= 1
		rem1 += 2
if rem1 > s1 + s2 + s4 * 2:
	f = 0
if f:
	print('YES')
else:
	print('NO')


def solve(n, k, a):
	fourSeatLeft = n
	twoSeatLeft = n * 2
	for i in range(k):
		while a[i] >= 4:
			if fourSeatLeft > 0:
				fourSeatLeft -= 1
				a[i] -= min(a[i], 4)
			else:
				break
	for i in range(k):
		while a[i] >= 3:
			if fourSeatLeft > 0:
				fourSeatLeft -= 1
				a[i] -= min(a[i], 4)
			else:
				break
	for i in range(k):
		while a[i] >= 2:
			if twoSeatLeft > 0:
				twoSeatLeft -= 1
				a[i] -= min(a[i], 2)
			else:
				break
	for i in range(k):
		while a[i] >= 1:
			if twoSeatLeft > 0:
				twoSeatLeft -= 1
				a[i] -= min(a[i], 2)
			else:
				break
	twoSeatLeft += fourSeatLeft
	oneSeatLeft = fourSeatLeft
	fourSeatLeft = 0
	for i in range(k):
		while a[i] >= 2:
			if twoSeatLeft > 0:
				twoSeatLeft -= 1
				a[i] -= min(a[i], 2)
			else:
				break
	oneSeatLeft += twoSeatLeft
	twoSeatLeft = 0
	for i in range(k):
		while a[i] >= 1:
			if oneSeatLeft > 0:
				oneSeatLeft -= 1
				a[i] -= min(a[i], 1)
			else:
				break
	if sum(a) > 0:
		return 'NO'
	return 'YES'
[n, k] = [eval(v) for v in input().split()]
a = [eval(v) for v in input().split()]
print(solve(n, k, a))


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
l = sorted(l, reverse=True)
s = 0
for _ in range(n):
	if l[0] <= 0:
		break
	if l[0] <= 2:
		l[0] -= min(l[0], 2)
		s += 1
	l[0] -= min(l[0], 4)
	l = sorted(l, reverse=True)
for _ in range(n):
	if l[0] <= 0:
		break
	l[0] -= min(l[0], 2)
	l = sorted(l, reverse=True)
for _ in range(n):
	if l[0] <= 0:
		break
	l[0] -= min(l[0], 2)
	l = sorted(l, reverse=True)
for _ in range(s):
	if l[0] <= 0:
		break
	l[0] -= min(l[0], 1)
	l = sorted(l, reverse=True)
if l[0] <= 0:
	print('YES')
else:
	print('NO')


(n, k) = map(int, input().split())
inp = list(map(int, input().split()))
a = n * 2
b = n
for i in range(k):
	x = inp[i] // 4
	y = min(x, b)
	b -= y
	inp[i] -= y * 4
a += b
c = b
for i in range(k):
	x = inp[i] // 2
	y = min(x, a)
	a -= y
	inp[i] -= y * 2
if sum(inp) <= a + b:
	print('YES')
else:
	print('NO')


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
s2 = 2 * n
s4 = n
s1 = 0
tmp = sum(map(lambda ai: ai // 4, a))
s4 -= min(tmp, n)
s2 -= 2 * max(tmp - n, 0)
for ai in a:
	if ai % 4 == 2:
		if 0 < s2:
			s2 -= 1
		elif 0 < s4:
			s4 -= 1
			s1 += 1
		else:
			s1 -= 2
for ai in a:
	if ai % 4 == 1:
		if 0 < s1:
			s1 -= 1
		elif 0 < s2:
			s2 -= 1
		else:
			s4 -= 1
			s2 += 1
for ai in a:
	if ai % 4 == 3:
		if 0 < s4:
			s4 -= 1
		elif 1 < s2:
			s2 -= 2
		elif 1 == s2:
			s2 -= 1
			s1 -= 1
		else:
			s1 -= 3
if 0 <= s1 and 0 <= s2 and (0 <= s4):
	print('YES')
else:
	print('NO')


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
s2 = 2 * n
s4 = n
s1 = 0
fail = 0
for i in range(k):
	while a[i] >= 4:
		if s4 > 0:
			s4 -= 1
			a[i] -= 4
		elif s2 > 0:
			s2 -= 1
			a[i] -= 2
		elif s1 > 0:
			s1 -= 1
			a[i] -= 1
		else:
			fail = 1
			break
for i in range(k):
	while a[i] >= 2:
		if s4 > 0:
			s4 -= 1
			a[i] -= 2
			s1 += 1
		elif s2 > 0:
			s2 -= 1
			a[i] -= 2
		elif s1 > 0:
			s1 -= 1
			a[i] -= 1
		else:
			fail = 1
			break
for i in range(k):
	while a[i] >= 1:
		if s4 > 0:
			s4 -= 1
			a[i] -= 1
			s1 += 1
		elif s2 > 0:
			s2 -= 1
			a[i] -= 1
		elif s1 > 0:
			s1 -= 1
			a[i] -= 1
		else:
			fail = 1
			break
if fail:
	print('NO')
else:
	print('YES')


read = lambda : map(int, input().split())
(k, n) = read()
a = list(read())
cnt4 = k
cnt2 = 2 * k
for i in range(n):
	cnt = min(cnt4, a[i] // 4)
	a[i] -= cnt * 4
	cnt4 -= cnt
for i in range(n):
	cnt = min(cnt2, a[i] // 2)
	a[i] -= cnt * 2
	cnt2 -= cnt
c = [0] * 20
for i in a:
	c[min(i, 19)] += 1
d = min(cnt4, c[3])
c[3] -= d
cnt4 -= d
d = min(cnt4, c[1], c[2])
c[1] -= d
c[2] -= d
cnt4 -= d
d = min(cnt2, c[2])
c[2] -= d
cnt2 -= d
d = min(cnt2, c[1])
c[1] -= d
cnt2 -= d
d = min(cnt4, (c[2] + 2) // 3 + int(c[2] > 1))
c[2] -= d + d // 2
cnt4 -= d
d = min(cnt4, c[2])
c[2] -= d
cnt4 -= d
d = min(cnt4, (c[1] + 1) // 2)
c[1] -= d * 2
cnt4 -= d
d = min(cnt4, c[1])
c[1] -= d
cnt4 -= d
print('YES' if sum(c[1:]) == 0 else 'NO')


(n, k) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
count = 0
for i in range(0, len(a)):
	if a[i] % 2 == 0:
		count = count + 1
if k - count <= n * 8 - sum(a):
	if k - count < n and k == n * 4:
		print('NO')
	else:
		print('YES')
else:
	print('NO')


def main():
	(n, k) = list(map(int, input().split()))
	nums = list(map(int, input().split()))
	seat_two = n * 2
	seat_four = n
	seat_one = 0
	n_four = sum([x // 4 for x in nums])
	nums = [x % 4 for x in nums]
	n_two = sum([x // 2 for x in nums])
	n_one = sum([x % 2 for x in nums])
	if seat_four >= n_four:
		seat_four -= n_four
		n_four = 0
		seat_two += seat_four
		seat_one += seat_four
		seat_four = 0
	else:
		n_four -= seat_four
		seat_four = 0
		n_two += n_four * 2
		n_four = 0
	if seat_two >= n_two:
		seat_two -= n_two
		n_two = 0
		if seat_two + seat_one >= n_one:
			print('YES')
		else:
			print('NO')
	else:
		n_two -= seat_two
		seat_two = 0
		n_one += n_two * 2
		if seat_one >= n_one:
			print('YES')
		else:
			print('NO')

def __starting_point():
	main()
1
__starting_point()


import math
(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
mid = n
sides = 2 * n
arr.sort(reverse=True)
for i in range(k):
	if arr[i] >= 3:
		r = min(mid, (arr[i] + 1) // 4)
		mid -= r
		if mid == 0:
			arr[i] -= r * 4
			break
		elif arr[i] % 4 == 3:
			arr[i] = 0
		else:
			arr[i] = arr[i] % 4
arr.sort(reverse=True)
mid_2 = 0
if mid > 0:
	for i in range(k):
		if arr[i] == 2:
			mid -= 1
			mid_2 += 1
			arr[i] = 0
		if arr[i] == 1:
			mid -= 1
			mid_2 += 1
			arr[i] = 0
		if mid == 0:
			break
	arr.sort()
	for i in range(k):
		if arr[i] == 2 and mid_2 > 1:
			mid_2 -= 2
			arr[i] = 0
		if arr[i] == 1 and mid_2 > 0:
			mid_2 -= 1
			arr[i] = 0
		if mid_2 == 0:
			break
arr.sort(reverse=True)
for i in range(k):
	sides -= math.ceil(arr[i] / 2)
if mid >= 0 and sides >= 0:
	print('YES')
else:
	print('NO')


import sys
import os
import math
import re
(n, k) = map(int, input().split())
sol = list(map(int, input().split()))
totalSeats = 8 * n
middle = n
leftRight = 2 * n
single = 0
for i in range(k):
	fours = min((sol[i] + 1) // 4, middle)
	middle -= fours
	sol[i] = max(0, sol[i] - 4 * fours)
leftRight += middle
single += middle
for i in range(k):
	twos = min(sol[i] // 2, leftRight)
	leftRight -= twos
	sol[i] = max(0, sol[i] - 2 * twos)
single += leftRight
for i in range(k):
	single -= sol[i]
if single < 0:
	print('No')
else:
	print('Yes')


import sys

def r():
	return list(map(int, input().split()))
(n, k) = map(int, input().split())
a = r()
cnt4 = n
cnt2 = 2 * n
cnt1 = 0
for i in range(k):
	x = min((a[i] + 1) // 4, cnt4)
	cnt4 -= x
	a[i] = max(0, a[i] - 4 * x)
cnt2 += cnt4
cnt1 += cnt4
for i in range(k):
	x = min(a[i] // 2, cnt2)
	cnt2 -= x
	a[i] = max(0, a[i] - 2 * x)
cnt1 += cnt2
for i in range(k):
	cnt1 -= a[i]
if cnt1 < 0:
	print('NO')
else:
	print('YES')


(n, k) = list(map(int, input().strip().split()))
groups = list(map(int, input().strip().split()))

def fetch(delim, num_places):
	for (i, g) in enumerate(groups):
		num_g = min(g // delim, num_places)
		g -= num_g * delim
		num_places -= num_g
		groups[i] = g
		if num_places == 0:
			break
	return num_places
num_4 = fetch(4, n)
num_2 = fetch(2, 2 * n) + num_4
num_2 += fetch(2, num_4)
if sum(groups) <= num_2:
	print('YES')
else:
	print('NO')


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
a1 = 0
a2 = 2 * n
a4 = n
flag = True
s1 = 0
s2 = 0
for x in a:
	while x >= 3:
		if a4:
			a4 -= 1
			x -= 4
		elif a2 > 1:
			a2 -= 1
			x -= 2
		else:
			flag = False
			break
	if not flag:
		break
	if x == 2:
		s2 += 1
	elif x == 1:
		s1 += 1
while s2:
	if a2:
		a2 -= 1
		s2 -= 1
	elif a4:
		a4 -= 1
		a1 += 1
		s2 -= 1
	else:
		s1 += 2
		s2 -= 1
print('YES' if flag and a1 + a2 + a4 * 2 >= s1 else 'NO')


class Solution(object):

	def __init__(self, rows, a):
		self.rows = rows
		self.x = rows
		self.y = 2 * rows
		self.z = 0
		self.a = a

	def solve(self):
		length = len(self.a)
		for i in range(length):
			while self.a[i] >= 4 and self.x > 0:
				self.a[i] = self.a[i] - 4
				self.x = self.x - 1
		self.y = self.y + self.x
		self.z = self.x
		for i in range(length):
			while self.a[i] >= 2 and self.y > 0:
				self.a[i] = self.a[i] - 2
				self.y = self.y - 1
		self.z = self.y + self.z
		for i in range(length):
			while self.a[i] >= 1 and self.z > 0:
				self.a[i] = self.a[i] - 1
				self.z = self.z - 1
		for i in range(length):
			if self.a[i] > 0:
				return False
		return True
line1 = input().split()
n = int(line1[0])
k = int(line1[1])
line2 = input().split()
a = []
for i in line2:
	a.append(int(i))
s = Solution(n, a)
ans = s.solve()
if ans:
	print('YES')
else:
	print('NO')


(n, cn) = map(int, input().split())
a = list(map(int, input().split()))
sums = 0
for i in a:
	sums += i
cnt_2 = 2 * n
cnt_4 = n
cnt_2_4 = 0
chk = False
while cnt_4 > 0:
	chk = 0
	for j in range(cn):
		if a[j] > 3:
			a[j] -= 4
			cnt_4 -= 1
			chk = 1
			break
	if not chk:
		break
cnt_2 += cnt_4
cnt_2_4 += cnt_4
while cnt_2 > 0:
	chk = 0
	for j in range(cn):
		if a[j] > 1:
			a[j] -= 2
			cnt_2 -= 1
			chk = 1
			break
	if not chk:
		break
cnt_2_4 += cnt_2
while cnt_2_4 > 0:
	chk = 0
	for j in range(cn):
		if a[j] > 0:
			a[j] -= 1
			cnt_2_4 -= 1
			chk = 1
			break
	if not chk:
		break
chk1 = 0
for i in a:
	if i > 0:
		chk1 = 1
if chk1:
	print('NO')
else:
	print('YES')


(n, m) = map(int, input().split())
z = list(map(int, input().split()))
h = z[:]
double = 2 * n
four = n
jj = []
for i in range(len(h)):
	while four > 0 and h[i] >= 4:
		h[i] -= 4
		four -= 1
	if h[i] != 0:
		jj.append(h[i])
ss = []
for i in range(len(jj)):
	while four > 0 and jj[i] >= 3:
		jj[i] -= 3
		four -= 1
	if jj[i] != 0:
		ss.append(jj[i])
tt = []
for i in range(len(ss)):
	while double > 0 and ss[i] >= 2:
		ss[i] -= 2
		double -= 1
	if ss[i]:
		tt.append(ss[i])
places = double + four * 2
gg = []
for i in range(len(tt)):
	while four > 0 and tt[i] >= 2:
		tt[i] -= 2
		places -= 1
		four -= 1
	if tt[i]:
		gg.append(tt[i])
if sum(gg) <= places:
	print('YES')
else:
	print('NO')


(n, k) = map(int, input().split())
wuya = [int(x) for x in input().split()]
n_4 = sum([x // 4 for x in wuya])
wuya = [x % 4 for x in wuya]
n_2 = sum([x // 2 for x in wuya])
n_1 = sum([x % 2 for x in wuya])
p4 = n
(p4, n_4) = (p4 - min(n_4, p4), n_4 - min(n_4, p4))
p2 = 2 * n + p4
n_2 += 2 * n_4
(p2, n_2) = (p2 - min(n_2, p2), n_2 - min(n_2, p2))
p1 = p4 + p2
n_1 += n_2 * 2
if p1 >= n_1:
	print('YES')
else:
	print('NO')


(n, k) = list(map(int, input().split()))
A = list(map(int, input().split()))
middles = n
sides = n * 2
singles = 0
for (i, a) in enumerate(A):
	s = a // 4
	s = min(s, middles)
	middles -= s
	A[i] -= 4 * s
for (i, a) in enumerate(A):
	s = a // 2
	s = min(s, sides)
	sides -= s
	A[i] -= 2 * s
for (i, a) in enumerate(A):
	s = a // 2
	s = min(s, middles)
	middles -= s
	singles += s
	A[i] -= 2 * s
singles += sides
singles += middles * 2
for (i, a) in enumerate(A):
	s = a
	s = min(s, singles)
	singles -= s
	A[i] -= s
rem = sum(A)
if rem == 0:
	print('YES')
else:
	print('NO')


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
l.sort(reverse=True)
j = 1
ans = 0
for i in range(k):
	if l[i] >= 3:
		if j == n + 1:
			break
		a = l[i] // 4
		b = l[i] % 4
		if n + 1 - j >= a:
			ans += 4 * a
			j += a
			l[i] = b
		else:
			ans += (n + 1 - j) * 4
			l[i] -= min(l[i], (n + 1 - j) * 4)
			j = n + 1
		if j == n + 1:
			break
		if b == 3:
			j += 1
			ans += 4
			l[i] -= 3
l.sort(reverse=True)
x = 1
for i in range(k):
	if x == n + 1:
		break
	if l[i] == 0:
		break
	a = l[i] // 2
	b = l[i] % 2
	if b > 0:
		a += 1
	if n + 1 - x >= a:
		ans += 2
		x += a
		l[i] = 0
	else:
		ans += (n + 1 - x) * 2
		l[i] -= min(l[i], (n + 1 - x) * 2)
		x = n + 1
		break
l.sort(reverse=True)
x = 1
for i in range(k):
	if x == n + 1:
		break
	if l[i] == 0:
		break
	a = l[i] // 2
	b = l[i] % 2
	if b > 0:
		a += 1
	if n + 1 - x >= a:
		ans += 2
		x += a
		l[i] = 0
	else:
		ans += (n + 1 - x) * 2
		l[i] -= min(l[i], (n + 1 - x) * 2)
		x = n + 1
		break
if l.count(0) != k:
	if j != n + 1:
		a = l.count(1)
		b = l.count(2)
		x = 0
		if a > b:
			x += b + (a - b) // 2
			if (a - b) % 2 != 0:
				x += 1
		elif b > a:
			x += a + 2 * ((b - a) // 3)
			if (b - a) % 3 != 0:
				x += (b - a) % 3
		else:
			x = a
		if x <= n + 1 - j:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')
else:
	print('YES')


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=300006, func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] <= key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater

class TrieNode:

	def __init__(self):
		self.children = [None] * 26
		self.isEndOfWord = False

class Trie:

	def __init__(self):
		self.root = self.getNode()

	def getNode(self):
		return TrieNode()

	def _charToIndex(self, ch):
		return ord(ch) - ord('a')

	def insert(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				pCrawl.children[index] = self.getNode()
			pCrawl = pCrawl.children[index]
		pCrawl.isEndOfWord = True

	def search(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				return False
			pCrawl = pCrawl.children[index]
		return pCrawl != None and pCrawl.isEndOfWord

class Node:

	def __init__(self, data):
		self.data = data
		self.count = 0
		self.left = None
		self.right = None

class BinaryTrie:

	def __init__(self):
		self.root = Node(0)

	def insert(self, pre_xor):
		self.temp = self.root
		for i in range(31, -1, -1):
			val = pre_xor & 1 << i
			if val:
				if not self.temp.right:
					self.temp.right = Node(0)
				self.temp = self.temp.right
				self.temp.count += 1
			if not val:
				if not self.temp.left:
					self.temp.left = Node(0)
				self.temp = self.temp.left
				self.temp.count += 1
		self.temp.data = pre_xor

	def query(self, xor):
		self.temp = self.root
		for i in range(31, -1, -1):
			val = xor & 1 << i
			if not val:
				if self.temp.left and self.temp.left.count > 0:
					self.temp = self.temp.left
				elif self.temp.right:
					self.temp = self.temp.right
			elif self.temp.right and self.temp.right.count > 0:
				self.temp = self.temp.right
			elif self.temp.left:
				self.temp = self.temp.left
			self.temp.count -= 1
		return xor ^ self.temp.data
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
four = n
two = 2 * n
for i in range(m):
	if four == 0:
		break
	t = min(four, a[i] // 4)
	a[i] -= t * 4
	four -= t
for i in range(m):
	er = a[i] // 4
	two -= 2 * er
	a[i] %= 4
for i in range(m):
	if a[i] == 3:
		if four > 0:
			four -= 1
		elif two > 1:
			two -= 2
		else:
			print('NO')
			sys.exit(0)
		a[i] = 0
x = 0
y = 0
leffour = four
for i in a:
	if i == 1:
		y += 1
	if i == 2:
		x += 1
for i in range(x):
	if two > 0:
		two -= 1
	elif four > 0:
		four -= 1
		continue
	else:
		y += 2
four = leffour - four + four * 2
for i in range(y):
	if four > 0:
		four -= 1
	elif two > 0:
		two -= 1
	else:
		print('NO')
		sys.exit(0)
print('YES')


from sys import stdin
(n, k) = [int(x) for x in stdin.readline().split()]
a = [int(x) for x in stdin.readline().split()]
four = n
two = 2 * n
one = 0
for (i, x) in enumerate(a):
	f = min(four, x // 4)
	four -= f
	a[i] -= f * 4
if four:
	a.sort(reverse=True)
	v = True
	for x in a:
		if x == 3:
			if four:
				four -= 1
			elif two >= 2:
				two -= 2
			else:
				v = False
				break
		elif x == 2:
			if four:
				four -= 1
				one += 1
			elif two:
				two -= 1
			elif one >= 2:
				one -= 2
			else:
				v = False
				break
		elif x == 1:
			if four:
				four -= 1
				two += 1
			elif two:
				two -= 1
			elif one:
				one -= 1
			else:
				v = False
				break
	if v:
		print('YES')
	else:
		print('NO')
else:
	for x in a:
		two -= x // 2 + x % 2
	if two >= 0:
		print('YES')
	else:
		print('NO')


(n, k) = map(int, input().split())
import sys
a = list(map(int, input().split()))
p = n * 2
d = 0
for i in range(k):
	while a[i] >= 4:
		if n > 0:
			n -= 1
			a[i] -= 4
		elif p >= 2:
			p -= 2
			a[i] -= 4
		elif d >= 4:
			d -= 4
			a[i] -= 4
		else:
			print('NO')
			sys.exit()
	if a[i] == 3:
		if n > 0:
			n -= 1
			a[i] -= 3
		elif p >= 2:
			p -= 2
			a[i] -= 3
		elif d >= 3:
			d -= 3
			a[i] -= 3
		else:
			print('NO')
			sys.exit()
	elif a[i] == 2:
		if p >= 1:
			p -= 1
			a[i] -= 2
		elif n >= 1:
			n -= 1
			a[i] -= 2
			d += 1
		elif d >= 2:
			d -= 2
			a[i] -= 2
		else:
			print('NO')
			sys.exit()
	elif a[i] == 1:
		if d >= 1:
			d -= 1
			a[i] -= 1
		elif n >= 1:
			n -= 1
			a[i] -= 1
			p += 1
		elif p >= 1:
			p -= 1
			a[i] -= 1
		else:
			print('NO')
			sys.exit()
print('YES')


(n, k) = map(int, input().split())
seat = {4: n, 2: n * 2, 1: 0}
extra1 = 0
a = sorted(map(int, input().split()), reverse=True)

def sit(n, m):
	num = min(seat[n], m)
	seat[n] -= num
	return m - num
for m in a:
	p4 = m // 4
	(p3, p2, p1) = (0, 0, 0)
	if m % 4 == 3:
		p3 = 1
	else:
		p2 = int(m % 4 > 1)
		p1 = int(m % 2)
	extra4 = sit(4, p4)
	p2 += extra4 * 2
	if sit(4, p3) > 0:
		p2 += 1
		p1 += 1
	extra2 = sit(2, p2)
	x = sit(4, extra2)
	seat[1] += extra2 - x
	p1 += x * 2
	extra1 += p1
extra1 = sit(1, extra1)
x = sit(4, extra1)
seat[2] += extra1 - x
y = sit(2, x)
if y > 0:
	print('NO')
else:
	print('YES')


R = lambda : list(map(int, input().split()))
(n, k) = R()
t = 4 * n
s = 0
for i in R():
	s += i + i % 2
	n -= i % 2
print('NO' if s > t + t or (s == t + t and k == t and (n > 0)) else 'YES')


(rows, groups) = map(int, input().split())
soldiers = list(map(int, input().split()))

def makePlane(rows):
	plane = [int(rows), 2 * int(rows), 0]
	return plane

def rozdelitVojaky(soldiers):
	(ctyrky, dvojky, jednicky) = (0, 0, 0)
	for skupina in soldiers:
		skupina = int(skupina)
		while skupina >= 4:
			ctyrky += 1
			skupina -= 4
		if skupina >= 2:
			dvojky += 1
		if skupina % 2 == 1:
			jednicky += 1
	return [ctyrky, dvojky, jednicky]

def zjistit(rows, groups, soldiers):
	plane = makePlane(rows)
	pasazeri = rozdelitVojaky(soldiers)
	if pasazeri[0] <= plane[0]:
		plane[0] -= pasazeri[0]
		pasazeri[0] = 0
	else:
		pasazeri[0] -= plane[0]
		pasazeri[1] += 2 * pasazeri[0]
		plane[0] = 0
	if pasazeri[1] <= plane[0]:
		plane[0] -= pasazeri[1]
		plane[2] += pasazeri[1]
		pasazeri[1] = 0
	else:
		pasazeri[1] -= plane[0]
		plane[2] += plane[0]
		plane[0] = 0
		if pasazeri[1] <= plane[1]:
			plane[1] -= pasazeri[1]
			pasazeri[1] = 0
		else:
			pasazeri[1] -= plane[1]
			pasazeri[2] += 2 * pasazeri[1]
			plane[1] = 0
	pasazeri[2] = pasazeri[2] - 2 * plane[0] - plane[1] - plane[2]
	if pasazeri[2] <= 0:
		return 'YES'
	else:
		return 'NO'
print(zjistit(rows, groups, soldiers))


(n, k) = map(int, input().split())
m = list(map(int, input().split()))
mm = []
for i in m:
	if i > 4:
		mm += [4] * (i // 4)
		if i % 4 != 0:
			mm.append(i % 4)
	else:
		mm.append(i)
mid = n
cor = n * 2
mm = sorted(mm)
flag = 0
while 4 in mm:
	mm.pop()
	if mid > 0:
		mid -= 1
	elif cor > 1:
		cor -= 2
	else:
		flag = 1
		break
if not flag:
	while 3 in mm:
		mm.pop()
		if mid > 0:
			mid -= 1
		elif cor > 1:
			cor -= 2
		else:
			flag = 1
			break
if not flag:
	while 2 in mm:
		mm.pop()
		if cor > 0:
			cor -= 1
		elif mid > 0:
			if 1 in mm:
				mm.pop(0)
				mid -= 1
			else:
				if 2 in mm:
					mm.pop()
					mm = [1] + mm
				mid -= 1
		else:
			flag = 1
			break
if not flag:
	while 1 in mm:
		mm.pop()
		if cor > 0:
			cor -= 1
		elif mid > 0:
			if 1 in mm:
				mm.pop(0)
			mid -= 1
		else:
			flag = 1
			break
if flag:
	print('NO')
else:
	print('YES')


import sys
(n, k) = map(int, input().split())
two = n * 2
four = n
one = 0
solders = list(map(int, input().split()))
solders.sort(reverse=True)
for sol in solders:
	while sol >= 4:
		sol -= 4
		if four > 0:
			four -= 1
		elif two > 1:
			two -= 2
		elif one > 3:
			one -= 4
		else:
			print('NO')
			sys.exit()
	if sol == 3:
		sol -= 3
		if four > 0:
			four -= 1
		elif two > 1:
			two -= 2
		elif one > 2:
			one -= 3
		else:
			print('NO')
			sys.exit()
	if sol == 2:
		sol -= 2
		if two > 0:
			two -= 1
		elif four > 0:
			four -= 1
			one += 1
		elif one > 1:
			one -= 2
		else:
			print('NO')
			sys.exit()
	if sol == 1:
		sol -= 1
		if one > 0:
			one -= 1
		elif four > 0:
			four -= 1
			two += 1
		elif two > 0:
			two -= 1
		else:
			print('NO')
			sys.exit()
print('YES')


from sys import stdin, stdout

def main():
	(n, k) = [int(_) for _ in stdin.readline().strip().split()]
	a = [int(_) for _ in stdin.readline().strip().split()]
	cornerSlot = 2 * n
	middleSlot = 2 * n
	slotForOne = 0
	single = 0
	for x in a:
		req = x // 2
		if req % 2 == 1:
			hand = 1
			req -= 1
		else:
			hand = 0
		if middleSlot >= req:
			middleSlot -= req
			req = 0
		elif middleSlot > 0 and req > middleSlot:
			req -= middleSlot
			middleSlot = 0
		if hand:
			req += 1
		if cornerSlot >= req:
			cornerSlot -= req
			req = 0
		elif cornerSlot > 0 and req > cornerSlot:
			req -= cornerSlot
			cornerSlot = 0
		pairInMiddle = False
		if middleSlot >= req and req > 0:
			middleSlot -= req
			req = 0
			pairInMiddle = True
		elif middleSlot > 0 and req > middleSlot:
			req -= middleSlot
			middleSlot = 0
			pairInMiddle = True
		if middleSlot % 2 == 1 and pairInMiddle:
			middleSlot -= 1
			slotForOne += 1
		if x % 2 == 1:
			single += 1
		if req > 0:
			single += req * 2
		if single > 0:
			if slotForOne >= single:
				slotForOne -= single
				single = 0
			elif slotForOne > 0:
				single -= slotForOne
				slotForOne = 0
	total = cornerSlot + middleSlot
	while single > 0 and total > 0:
		total -= 1
		single -= 1
	if single:
		ans = 'NO'
	else:
		ans = 'YES'
	stdout.write(ans)
main()


import heapq
(rows, groups) = list(map(int, input().split()))
counts = list([-1 * int(x) for x in input().split()])
fours = rows
twos = 2 * rows
ones = 0
f = True
heapq.heapify(counts)
while fours + twos + ones > 0 and len(counts) > 0:
	i = heapq.heappop(counts)
	i = i * -1
	if fours >= 1:
		if i < 4:
			twos += fours
			ones += fours
			fours = 0
			heapq.heappush(counts, i * -1)
		else:
			(d, m) = divmod(i, 4)
			if d > fours:
				i -= fours * 4
				fours = 0
				if i > 0:
					heapq.heappush(counts, i * -1)
			else:
				i -= d * 4
				fours -= d
				if i > 0:
					heapq.heappush(counts, i * -1)
	elif twos >= 1:
		if i < 2:
			ones += twos
			twos = 0
			heapq.heappush(counts, i * -1)
		else:
			(d, m) = divmod(i, 2)
			if d > twos:
				i -= twos * 2
				twos = 0
				if i > 0:
					heapq.heappush(counts, i * -1)
			else:
				i -= d * 2
				twos -= d
				if i > 0:
					heapq.heappush(counts, i * -1)
	elif ones >= 1:
		if i > ones:
			f = False
			break
		else:
			ones -= i
if len(counts) > 0 or f == False:
	print('NO')
else:
	print('YES')


def test():
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	total = n * 8
	place = 0
	sum = 0
	flag = 0
	for x in a:
		sum += x
		if x % 2 is 1:
			place += 1
		else:
			flag += 1
	if sum == total:
		if place != 0 or (flag % 4 == 0 and n * 4 == k):
			print('NO')
		else:
			print('YES')
	elif sum + place > total or (n * 4 == k and flag // 4 == place):
		print('NO')
	else:
		print('YES')
test()


import sys

def main():
	(n, k) = map(int, sys.stdin.readline().split())
	x = list(map(int, sys.stdin.readline().split()))
	ch = n
	dv = 2 * n
	for i in range(k):
		if x[i] % 4 == 2 and dv > 0:
			x[i] -= 2
			dv -= 1
	for i in range(k):
		while x[i] > 3 and ch > 0:
			x[i] -= 4
			ch -= 1
	for i in range(k):
		if x[i] % 4 == 1 and dv > 0:
			x[i] -= 1
			dv -= 1
	for i in range(k):
		while x[i] >= 3 and ch > 0:
			x[i] -= 4
			ch -= 1
	p1 = 0
	p2 = 0
	for i in range(k):
		if x[i] == 2:
			if p2 > 0:
				p2 -= 1
				x[i] = 0
			elif ch > 0:
				x[i] = 0
				p1 += 1
				ch -= 1
			elif p1 > 1:
				p1 -= 2
				x[i] = 0
		elif x[i] == 1:
			if p1 > 0:
				p1 -= 1
				x[i] = 0
			elif ch > 0:
				p2 += 1
				x[i] = 0
				ch -= 1
			elif p2 > 0:
				p2 -= 1
				x[i] = 0
		while x[i] > 0 and dv > 0:
			x[i] -= 2
			dv -= 1
	ok = True
	for i in range(k):
		if x[i] > 0:
			ok = False
			break
	if ok:
		print('YES')
	else:
		print('NO')
main()


(rows, groups) = list(map(int, input().strip().split(' ')))
number_soldiers = list(map(int, input().strip().split(' ')))
rows_whithout_four = rows
rows_whithout_two = rows * 2
val = True
remainders = [0, 0]
for soldiers in number_soldiers:
	while soldiers >= 3:
		if rows_whithout_four > 0:
			rows_whithout_four -= 1
			soldiers -= 4
		elif rows_whithout_two > 0:
			soldiers -= 2
			rows_whithout_two -= 1
		else:
			val = False
	if soldiers > 0:
		remainders[soldiers - 1] += 1
	if not val:
		break
one_sit = 0
while remainders[1] and val:
	if rows_whithout_two > 0:
		rows_whithout_two -= 1
		remainders[1] -= 1
	elif rows_whithout_four > 0:
		rows_whithout_four -= 1
		remainders[1] -= 1
		one_sit += 1
	elif one_sit >= 2:
		remainders[1] -= 1
		one_sit -= 2
	else:
		val = False
if remainders[0] > one_sit + rows_whithout_four * 2 + rows_whithout_two:
	val = False
if val:
	print('YES')
else:
	print('NO')