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

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.

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.

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

"""
    Author      : Arif Ahmad
    Date        :
    Algo        :
    Difficulty  :
"""
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
        #print('corner:', cornerSlot, ' middle:', middleSlot, ' single:', slotForOne)
        #print('group of:', x, ' req:', req, '\n')

        if req % 2 == 1:
            hand = 1
            req -= 1
        else:
            hand = 0

        # try to accommodate even no. of pairs in middle
        if middleSlot >= req:
            middleSlot -= req
            req = 0
        elif middleSlot > 0 and req > middleSlot:
            req -= middleSlot
            middleSlot = 0

        if hand: req += 1

        # now accommodate rest of the pairs in the corner
        if cornerSlot >= req:
            cornerSlot -= req
            req = 0
        elif cornerSlot > 0 and req > cornerSlot:
            req -= cornerSlot
            cornerSlot = 0

        # again, accommodate rest of the pairs in middle
        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

        #print('req now:', req)
        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)

if __name__ == '__main__':
    main()

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

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

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
#print(r4,r22,mid,r2)
if r4 > 0:
	mid -=r4
	r22 -= r4
	if mid < 0:
		r22 -= (mid // -2)
		mid = 0

if r22 + mid > r2:
	print('NO')
else:
	print('YES')

n,k=map(int,input().split())
a=list(map(int,input().split()))
fours,twos,ones=n,2*n,0
# fill all the fours first
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()
# any threes left?
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()
# any twos left?
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')

import heapq
rows, groups = list(map(int,input().split()))
counts = list(map(lambda x: (-1)*int(x),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")

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

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

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)

    #usadit ctverice
    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

    #dvojicky
    #do ctyrmist
    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
        #do dvojmist
        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
    #jednotlivci
    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")

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()
        #print(n,p,d)
    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()
        #print(n,p,d)
    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()
        #print(n,p,d)
    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(n,p,d)
print('YES')

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

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(r'\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")

if __name__ == '__main__':
    main()

debug = 0
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
if debug: print(*a)
for i in range(n):
    cnt = min(cnt2, a[i] // 2)
    a[i] -= cnt * 2
    cnt2 -= cnt
if debug: print(' '.join(map(str, a)), ' ', cnt2, cnt4)
c = [0] * 20
for i in a:
    c[min(i, 19)] += 1
if debug:
    print(cnt2, cnt4, c)
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
if debug:
    print('cnt4 = ', cnt4)
    print('c[1] = ', c[1])
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')

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

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
        else:
            if 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')

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

# Made By Mostafa_Khaled

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
		else :
			if (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
		else :
			if (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")

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

if __name__ == '__main__':
    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,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

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

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))
# 1522848694321

n,k=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')

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())
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")

s = raw_input().split()
n = int(s[0])
k = int(s[1])

rowCount4 = 0
a = raw_input().split()

for i in range(k):
    a[i] = int(a[i])
    n -= a[i] / 4
    rowCount4 += a[i] / 4
    a[i] %= 4

    if (a[i] == 3):
        rowCount4 += 1
        a[i] = 0
        n -= 1

index2 = -1

for i in range(k):
    if (a[i] == 2 and rowCount4 > 0):
        if (index2 == -1):
            index2 = i
        else:
            a[i] = 0
            a[index2] = 0
            index2 = -1
            rowCount4 -= 1

index1 = -1

for i in range(k):
    if (a[i] == 1 and rowCount4 > 0):
        if (index1 == -1):
            index1 = i
        else:
            a[i] = 0
            a[index1] = 0
            index1 = -1
            rowCount4 -= 1

count2 = 0

for i in range(k):
    if (a[i] == 2):
        a[i] = 0
        count2 += 1

rowCount2 = 0

if (rowCount4 <= 0):
    rowCount2 = count2 / 3
    n -= count2 / 3

    count2 %= 3

#43
while count2 > 0 and rowCount2 >= 2:
    rowCount2 -= 2
    count2 -= 1

rowCount4Half = 0

count1 = 0

for i in range(k):
    if (a[i] == 1):
        a[i] = 0
        count1 += 1
        if (rowCount2 > 0):
            rowCount2 -= 1
            count1 -= 1
            a[i] = 0

if (count2 > 0):
    count1 -= 4 - count2

if (count2 > 0):
    if (rowCount4 == 0):
        count2 -= 1
        n -= 1

    elif (rowCount4 > 0):
        count2 -= 1
        rowCount4 -= 1
        rowCount4Half += 1

if (count1 > 0):
    n -= count1 / 4
    count1 %= 4

if (count1 > 0):
    if (rowCount4 == 0):
        count1 -= 1
        n -= 1

    elif (rowCount4 > 0):
        count1 -= 1
        if (rowCount4Half > 0):
            rowCount4Half -= 1
        else:
            rowCount4 -= 1
            rowCount4Half += 1

if (rowCount4 > 0):
    n += rowCount4 / 2
    rowCount4 %= 2

if (n >= 0):
    print "YES"
else:
    print "NO"

a,b = raw_input().split()
c = list(map(int,raw_input().split()))
a = int(a)
b = int(b)

a = a*8
r=0
cnt =0
for i in range(len(c)):
    if c[i] %2 ==1:
        c[i] = c[i]+1
        cnt = cnt +1
    r = r+c[i]

if r > a or r==a and b == a/2 and cnt <a/8:
    print "NO"
else:
    print "YES"

n,k = map(int,raw_input().split())
a = 4*n
s = 0
for l in map(int,raw_input().split()):
	s +=l+l%2
	n -=l%2
print('NO'if s>a*2 or (s==a*2and k==a and n>0) else 'YES')

import sys

def solve(n, k, groups):
    num_4 = n
    num_2 = 2*n
    num_1 = 0
    remaining_groups = []
    for group in groups:
        if group % 2 == 1:
            if num_4 > 0:
                group -= 1
                num_2 += 1
                num_4 -= 1
                if group > 0:
                    remaining_groups.append(group)
            elif num_2 > 0:
                group -= 1
                num_2 -= 1
                if group > 0:
                    remaining_groups.append(group)
            else:
                return 'NO'
        else:
            remaining_groups.append(group)

    remaining_groups = sorted(remaining_groups, reverse=True)
    for group in remaining_groups:
        if group >= 4 and num_4 > 0:
            req_4 = group / 4
            if req_4 > num_4:
                group -= num_4 * 4
                num_4 = 0
            else:
                num_4 -= req_4
                group -= req_4 * 4
        if group >= 2 and num_2 > 0:
            req_2 = group / 2
            if req_2 > num_2:
                group -= num_2 * 2
                num_2 = 0
            else:
                num_2 -= req_2
                group -= req_2 * 2
        if group >= 2 and num_4 > 0:
            req_2 = group / 2
            if req_2 > num_4:
                return 'NO'
            else:
                num_4 -= req_2
                num_1 += 1
                group -= req_2*2
        if group >= 2 and num_1 > 0:
            req_1 = group
            if req_1 > num_1:
                return 'NO'
            else:
                num_1 -= req_1
                group -= req_1

        if group != 0:
            return 'NO'

    return 'YES'

if __name__ == '__main__':
    n, k = map(int, sys.stdin.readline().split())
    groups = map(int, sys.stdin.readline().split())
    print solve(n, k, groups)

from sys import exit

num_rows, num_groups = map(int, raw_input().split(' '))

groups = map(int, raw_input().split(' '))

num_quads, num_doubles = num_rows, 2 * num_rows

# Fully fill up first quads, then doubles, as many as possible

for i in xrange(num_groups):
    occupiable_quads = min(num_quads, groups[i] / 4)

    num_quads -= occupiable_quads
    groups[i] -= 4 * occupiable_quads

for i in xrange(num_groups):
    occupiable_doubles = min(num_doubles, groups[i] / 2)

    num_doubles -= occupiable_doubles
    groups[i] -= 2 * occupiable_doubles

# If there are groups of 4 and up left, problem is infeasible
# (not sure if this even possible under the assignment conditions, but doesn't hurt to check :>)

if len(filter(lambda x: x >= 4, groups)) != 0:
    print "NO"

    exit(0)

# Subproblem:
# distribute groups of 1, 2 and 3 people over leftover quads and doubles

# Distribute all groups of 3 over quads

for i in filter(lambda x: groups[x] == 3, xrange(num_groups)):
    if num_quads == 0:
        break

    groups[i] = 0
    num_quads -= 1

# If that couldn't be done, place two people of every group of 3 on a double

for i in filter(lambda x: groups[x] == 3, xrange(num_groups)):
    if num_doubles == 0:
        break

    groups[i] -= 2
    num_doubles -= 1

# If we coudn't distribute all groups of 3, the problem is infeasible

if len(filter(lambda x: x == 3, groups)) != 0:
    print "NO"

    exit(0)

# Subproblem:
# distribute groups of 1 and 2 over leftover quads and doubles

# Distribute pairs of 1 and 2 groups over quads, thus filling the quads up

for i, j in zip(
    filter(lambda i: groups[i] == 1, xrange(num_groups)),
    filter(lambda i: groups[i] == 2, xrange(num_groups))
    ):

    if num_quads == 0:
        break

    groups[i] = 0
    groups[j] = 0

    num_quads -= 1

if num_quads == 0:
    # Subproblem:
    # distribute groups of 1 and 2 over the remaining doubles

    for i in xrange(num_groups):
        if num_doubles == 0:
            break

        if groups[i] == 1 or groups[i] == 2:
            groups[i] = 0
            num_doubles -= 1
else:
    # There are quads left, but either groups of 1 or groups of 2 are gone (or both)

    if len(filter(lambda x: x == 2, groups)) != 0:
        # Subproblem:
        # distribute groups of 2 over the remaining quads and doubles

        for i in xrange(num_groups):
            if num_doubles == 0:
                break

            if groups[i] == 2:
                num_doubles -= 1
                groups[i] = 0

        # On every two quads, we can place three groups of 2:
        # [1 1 - 3]
        # [2 2 - 3]

        two_groups = filter(lambda i: groups[i] == 2, xrange(num_groups))

        for i, j, k in zip(
            two_groups[:len(two_groups) / 3],
            two_groups[len(two_groups) / 3:len(two_groups) / 3 * 2],
            two_groups[len(two_groups) / 3 * 2:]
            ):
            if num_quads < 2:
                break

            groups[i] = 0
            groups[j] = 0
            groups[k] = 0

            num_quads -= 2

        # At most two groups of 2 remain, which requires two quads, or less than two quads are available -- either way,
        # at this point we can only place one group of 2 per quad

        for i in xrange(num_groups):
            if num_quads == 0:
                break

            if groups[i] == 2:
                groups[i] = 0
                num_quads -= 1

    elif len(filter(lambda x: x == 1, groups)) != 0:
        # Subproblem:
        # distribute groups of 1 over the remaining quads and doubles

        for i in xrange(num_groups):
            if num_doubles == 0:
                break

            if groups[i] == 1:
                num_doubles -= 1
                groups[i] = 0

        one_groups = filter(lambda i: groups[i] == 1, xrange(num_groups))

        for i, j in zip(one_groups[:len(one_groups) / 2], one_groups[len(one_groups) / 2:]):
            if num_quads == 0:
                break

            groups[i] = 0
            groups[j] = 0

            num_quads -= 1

        if num_quads != 0:
            for i in xrange(num_groups):
                if groups[i] == 1:
                    groups[i] = 0
                    num_quads -= 1

                    break

# If anything has remained after the distribution, the problem is infeasible

if sum(groups) == 0:
    print "YES"
else:
    print "NO"

#!/usr/bin/python

import sys

def read_obj(cls):
    return cls(sys.stdin.readline().strip())

def read_obj_list(cls):
    return map(cls, sys.stdin.readline().strip().split())

def solve():
    n, k = read_obj_list(int)
    an = read_obj_list(int)

    an.sort()
    left_4s = n

    for i in xrange(k):
        seated_4s = min(an[i] // 4, left_4s)
        left_4s -= seated_4s
        an[i] -= seated_4s * 4

        if left_4s == 0:
            break

    left_2s = 2 * n + left_4s

    for i in xrange(k):
        seated_2s = min(an[i] // 2, left_2s)
        left_2s -= seated_2s
        an[i] -= seated_2s * 2

        if left_2s == 0:
            break

    left_1s = left_4s + left_2s

    if sum(an) > left_1s:
        return "NO"
    else:
        return "YES"

if __name__ == "__main__":
    print solve()

a=map(int,raw_input().split())
n=a[0]
k=a[1]
b=map(int,raw_input().split())
b.sort()
c=2*n
d=n
f=0
e=0
for i in range(3*n):
    if d>0:
        if b[len(b)-1]>=4:
            d=d-1
            b[len(b)-1]-=4

        else:
            if b[len(b)-1]<=2:
                d=d-1
                e=e+1
                b=[0]+b[0:len(b)-1]
            else:
                d=d-1
                b=[0]+b[0:len(b)-1]

    else:
        if c>0:
            if b[len(b)-1]>=2:
                c=c-1
                b[len(b)-1]-=2
            else:
                c=c-1
                b=[0]+b[0:len(b)-1]

        else:
            f=2
            break
    b.sort()

    if b==[0]*len(b):
        f=1
        break

if e>0 and f!=1 and f!=2:
    if e>=sum(b):
        f=1

if f==1:
    print 'YES'
else:
    print 'NO'

import sys
import heapq

def solve(data, rows):
    fours = rows
    twos = 2 * rows
    ones = 0
    data = [x * -1 for x in data]
    heapq.heapify(data)
    while True:
        if not data:
            return True
        max_group_size = heapq.heappop(data)
        if max_group_size == 0:
            return True
        if fours and max_group_size <= -4:
            fours_required = (-max_group_size) // 4
            fours_to_take = min(fours_required, fours)
            fours -= fours_to_take
            remaining_soldiers = max_group_size + fours_to_take * 4
            if remaining_soldiers != 0:
                heapq.heappush(data, remaining_soldiers)
            continue
        if fours and max_group_size < -2:
            fours -= 1
            continue
        # We don't need fours anymore. Convert them to 1 + 2.
        if fours:
            ones += fours
            twos += fours
            fours = 0
        if twos and max_group_size <= -2:
            twos_required = (-max_group_size) // 2
            twos_to_take = min(twos_required, twos)
            twos -= twos_to_take
            remaining_soldiers = max_group_size + twos_to_take * 2
            if remaining_soldiers != 0:
                heapq.heappush(data, remaining_soldiers)
            continue
        if twos:
            twos -= 1
            continue
        if ones:
            ones -= 1
            remaining_soldiers = max_group_size + 1
            if remaining_soldiers != 0:
                heapq.heappush(data, remaining_soldiers)
            continue

        return False

    return True

def main():
    rows, n_groups = map(int, sys.stdin.readline().split())
    data = map(int, sys.stdin.readline().split())
    result = solve(data, rows)
    if result:
        print('YES')
    else:
        print('NO')

main()

'''input
1 4
2 2 1 2
'''
import math
L = raw_input().split(" ")
L = [int(x) for x in L]
n = L[0]
k = L[1]
L = raw_input().split(" ")
L = [int(x) for x in L]
seats = [0]*5
seats[2] = 2*n
seats[4] = n
f = 0
cnt  = [0,0,0]
for i in L :
	while i>=3 :
		if seats[4]>0 :
			seats[4] = seats[4]-1;
			i = i-4
		elif seats[2]>0 :
			seats[2] = seats[2]-1;
			i = i-2
		else :
			f = 1
			print "NO"
			break
	if f==1 :
		break
	if i>0 :
		cnt[i] = cnt[i]+1
while cnt[2]>0 :
	if seats[4]>0 :
		seats[4] = seats[4]-1
		cnt[2] = cnt[2]-1
		seats[1] = seats[1]+1
	elif seats[2]>0 :
		seats[2] = seats[2]-1
		cnt[2] = cnt[2]-1
	else :
		cnt[2] = cnt[2]-1
		cnt[1] = cnt[1]+2

if cnt[1]>seats[1]+seats[2]+seats[4]*2 :
	print "NO"
	f=1
if f==0 :
	print "YES"

n, k = map(int, raw_input().split())
n1 = 0
n2 = n * 2
n4 = n
a = list(map(int, raw_input().split()))

for i in range(len(a)):
    while a[i] >= 4 and n4 > 0:
        a[i], n4 = a[i] - 4, n4 - 1
    while a[i] >= 4 and n2 > 0:
        a[i], n2 = a[i] - 2, n2 - 1
    if a[i] >= 4:
        print "NO"
        quit()

for i in range(len(a)):
    while a[i] >= 2 and n4 > 0:
        a[i], n4, n1 = a[i] - 2, n4 - 1, n1 + 1
    while a[i] >= 2 and n2 > 0:
        a[i], n2 = a[i] - 2, n2 - 1
    while a[i] >= 2 and n1 > 0:
        a[i], n1 = a[i] - 1, n1 - 1
    if a[i] >= 2:
        print "NO"
        quit()

num = n4 * 2 + n2 + n1
for i in range(len(a)):
    while a[i] > 0 and num > 0:
        a[i], num = a[i] - 1, num - 1
    if a[i] > 0:
        print "NO"
        quit()

print "YES"

n,k = map(int,raw_input().split())
a = map(int,raw_input().split())

works = True

fours = 0
twos = 0
ones = 0

for ele in a:
    t_fours = ele/4
    ele -= t_fours*4

    t_twos = ele/2
    ele -= t_twos*2

    t_ones = ele

    fours += t_fours
    twos += t_twos
    ones += t_ones

mid = n
norm = 2*n
sing = 0

t = min(mid,fours)
fours -= t
mid -= t

if fours > 0:
    #out of mids
    norm -= fours*2
    norm -= twos
    norm -= ones

    if norm>=0:
        print "YES"
    else:
        print "NO"

else:
    #still have mids, break up
    norm += mid
    sing += mid

    norm -= twos
    if norm < 0:
        sing += 2*norm #actually subtracting
        norm = 0

    norm -= ones
    if norm < 0:
        sing += norm #actually subtracting
        norm = 0

    if sing>=0:
        print "YES"
    else:
        print "NO"

n,k = map(int,raw_input().split())
nums = sorted(list(map(int,raw_input().split())),reverse=True)
a = n
b = n*2
for i in range(k):
  if nums[i] >= 4 and a:
    cur = min(a,nums[i]/4)
    a -= cur
    nums[i] -= cur*4
for i in range(k):
  if nums[i] >= 3 and a:
    cur = min(a,nums[i]/3)
    a -= cur
    nums[i] -= cur*3
a1 = a
a2 = a
for i in range(k):
  if nums[i] >= 2 and b:
    cur = min(b,nums[i]/2)
    b -= cur
    nums[i] -= cur*2
  elif nums[i] >= 2 and a1:
    cur = min(a1,nums[i]/2)
    a1 -= cur
    nums[i] -= cur*2
for i in range(k):
  if nums[i] and a2:
    cur = min(a2,nums[i])
    a2 -= cur
    nums[i] -= cur
  elif nums[i] and b:
    nums[i] -= 1
    b -= 1
  elif nums[i] and a1:
    a1 -= 1
    nums[i] -= 1
if sum(nums):
  print "NO"
else:
  print "YES"

n, k = map(int, raw_input().strip().split())
vs = map(int, raw_input().strip().split())
vs.sort()

def okay(c4, c2, c1):
    ws = []
    for v in vs:
        r = min(c4, v / 4)
        c4 -= r
        v -= 4 * r
        ws.append(v)
    ws.sort()
    for v in ws:
        r = min(c2, v / 2)
        c2 -= r
        v -= 2 * r
        r = min(c1, v)
        c1 -= r
        v -= r
        r = min(c2, v)
        c2 -= r
        v -= r
        if v:
            return False
    return True

def solve():
    for i in xrange(n+1):
        c4 = i
        c2 = 2*n + n - i
        c1 = n - i
        if okay(i, 3*n - i, n - i): return True
    return False

print 'YES' if solve() else 'NO'

from math import ceil
n, k = map(int, raw_input().split())
A = map(int, raw_input().split())
s4 = n
s2 = n * 2
t4 = 0
t2 = 0
t1 = 0
for i in xrange(k):
    t4 += A[i] / 4
    r = A[i] % 4
    if r == 1: t1 += 1
    if r == 2: t2 += 1
    if r == 3: t4 += 1

if t4 >= s4:
    if (t4 - s4) * 2 + t2 + t1 <= s2:
        print 'YES'
    else:
        print 'NO'
else:
    c = s4 - t4
    if t2 <= s2:
        if t1 <= s2 - t2 + c * 2:
            print 'YES'
        else:
            print 'NO'
    else:
        if s2 - t2 + c < 0:
            t1 += (t2 - (s2 + c)) * 2
            if t1 <= c:
                print 'YES'
            else:
                print 'NO'
        else:
            if s2 - t2 + 2 * c >= t1:
                print 'YES'
            else:
                print 'NO'

n,k = map(int,raw_input().split())
inp = [int(x) for x in raw_input().split()]
a = n*2
b = n
for i in xrange(k):
    x = inp[i]/4
    y = min(x,b)
    b-=y
    inp[i]-=(y*4)
a+= b
c = b
for i in xrange(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,raw_input().split());
cnt = map(int,raw_input().split());
cnt.sort();
#cnt.reverse();

available = 2*n;
for i in xrange(k):
    x = min(available,cnt[i]/2);
    cnt[i] -= 2*x;
    available -= x;

r = n;
for i in xrange(k):
    x = min(r,cnt[i]/4);
    r -= x;
    cnt[i] -= 4*x;

def work(need,available):
    x = min(need,available);
    need -= x;
    available -= x;
    return need,available;

if sum(map(lambda x:x >= 4,cnt)) != 0: print "NO";
else:
    one = sum(map(lambda x:x == 1,cnt));
    two = sum(map(lambda x:x == 2,cnt));
    three = sum(map(lambda x: x == 3, cnt));
    if (two or three) and available: assert False;
    one,available = work(one,available);
    three,r = work(three,r);
    #print one,two,three
    #print r,available
    if three : print "NO";
    else:
        three = min(one,two);
        one -= three;
        two -= three;
        three,r = work(three,r);
        if three: print "NO";
        else:
            if one and two: assert False;
            #print one,two;
            #print r,available
            if two:
                x = min(two,r);
                two -= x;
                r -= x;
                if 2*two <= x: two = 0;
            two += (one + 1)/2;
            two,r = work(two,r);
            if two: print "NO";
            else: print "YES";

def get(a):
	return map(a , raw_input().split())

n , k = get(int)
h = get(int)

## 4 se div wale upto 4*n
tot4 = n
for i in xrange(k):
	at = h[i]
	tt = at / 4
	#print tot4
	if tt >= 1:
		if tt <= tot4:
			tot4 -= tt
			h[i] -= tt*4
		else:
			h[i] -= tot4*4
			tot4 = 0
	#print h, tot4, tt
## 2 se div wale upto 4*n
tot2 = 2*n
tot2 += tot4
for i in xrange(k):
	at = h[i]
	tt = at / 2
	#print tot2,'2'
	if tt >= 1:
		if tt <= tot2:
			tot2 -= tt
			h[i] -= tt*2
		else:
			h[i] -= tot2*2
			tot2 = 0
	#print h, tot2, tt
## 1 se div wale upto left/2
tot1 = tot2
tot1 += tot4

sm = sum(h)
#print sm, tot1
if sm <= tot1:
	print 'YES'
else:
	print 'NO'

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 4
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 3
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

#REMOVE GROUPS WITH 0 REMAINED
a = removeZeroes(a)

if a.count(2) + a.count(1) != len(a):
    print("NO")
    sys.exit(0)

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")
        sys.exit(0)
    else:
        print("NO")
        sys.exit(0)
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")
        sys.exit(0)

if len(a) > 0:
    print("NO")
else:
    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')

"""Problem: http://codeforces.com/contest/839/problem/B"""

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

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()]

# use 4-seat rows first
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

# There are two cases
# s4 > 0 => a[i] <= 2
# s4 = 0 => add 1 to odd and check if sum <= rest space
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")

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

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
			else:
				if(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())
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')

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')
else:
    if sum + sum1 <= 8 * n:
        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) #take the min of 4s needed + one empty and the middle
    middle -= fours
    sol[i] = max(0,sol[i]-4*fours) #soldiers remaining

leftRight += middle
single += middle

for i in range(k): #now deal with the twos
    twos = min(sol[i]//2, leftRight)
    leftRight -= twos
    sol[i] = max(0, sol[i]-2*twos) #soldiers remaining

single += leftRight

for i in range(k): #all the singles that need a seat
    single -= sol[i]

if single < 0:
    print('No')
else:
    print('Yes')

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())
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")

# encoding:utf-8

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

	#print(n_one, n_two, n_four)
	#print(seat_one, seat_two, seat_four)

	if seat_four >= n_four:
		# there is rest of 4 seat
		seat_four -= n_four
		n_four = 0

		# break seat seat_one and seat_two
		seat_two += seat_four
		seat_one += seat_four
		seat_four = 0
	else:
		# there is rest of 4 people
		n_four -= seat_four
		seat_four = 0

		# break 4 people to 2, 2
		n_two += n_four * 2
		n_four = 0

	#print(n_one, n_two, n_four)
	#print(seat_one, seat_two, seat_four)

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

if __name__ == '__main__':
	main()
1

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

#coding=utf-8

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 temp == k) and flag%4==0)or place!=0:
            print("NO")
        else:
            print("YES")
    else:
        if (sum + place) > total or (n*4==k and (flag//4)==place ):
            print("NO")
        else:
            print("YES")

test()

#coding=utf-8

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")
    else:
        if (sum + place) > total or (n*4==k and (flag//4)==place ):
            print("NO")
        else:
            print("YES")

test()

#coding=utf-8

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")
    else:
        if (sum + place) > total or (n*4==k and (flag//4)==place ):
            print("NO")
        else:
            print("YES")

test()

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

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')
#hack:2 6\n2 2 2 2 2 6

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

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

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)
#print(a,N)
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)
#print(a,N)
for i in range(K):
    #print("a",a,N,a[i])
    if a[i]==0:
        continue
    if a[i]>=4:
        works = False
        break
    #print("x")
    if a[i]==3:
        #print(" ai is 3")
        x = min(N[4],1)
        a[i]-=3*x
        N[4]-=x

    elif a[i]==2:
        #print( "ai is 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:
        #print(" ai is 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:
        #print(a[i])
        works = False
        break

if works:
    print("YES")
else:
    print("NO")

n, k = 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")

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'

##if __name__ == '__main__':
##
##    import sys
##
##    stdin = sys.stdin
##    sys.stdin = open('cf839b.txt')
##
##    testcaseNo = eval(input())
##
##    for c in range(testcaseNo):
##        [n, k] = [eval(v) for v in input().split()]
##        a = [eval(v) for v in input().split()]
##
##        result = solve(n, k, a)
##
##        print('Case#' + str(c + 1) + ':', end=' ')
##        print(result)
##
##    sys.stdin = stdin

[n, k] = [eval(v) for v in input().split()]
a = [eval(v) for v in input().split()]
print(solve(n, k, a))

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
#print(cnt_4, cnt_2_4, cnt_2)
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
#print(cnt_4, 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
#print(cnt_4, cnt_2_4, cnt_2)
chk1 = 0
for i in a:
    if i > 0:
        chk1 = 1
if chk1:
    print("NO")
else:
    print("YES")

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

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')
		exit()

print('YES')

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, k = map(int, input().split())

a = list(map(int, input().split()))

c = 0

for i in range(k):
  if a[i]%2 == 0:
    c += 1

if k-c <= n*8-sum(a):
  if k-c < n and k == n*4:
    print("NO")
  else:
    print("YES")
else:
  print("NO")

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

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()
	for val in baki:
		cap1=four
		cap2=four
		if(val==3):
			if(cap1>0 and cap2>0):
				cap1-=1
				cap2-=1
			else:
				two-=2
		elif(val==2):
			if(two>0):
				two-=1
			else:
				if(cap1>0):
					cap1-=1
				else:
					cap2-=2
		else:
			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(" ")))
count = 0
for i in range(0,len(a)):
    if a[i]%2 == 0:
        count = count + 1
if count >= n/2:
    print('YES')
else:print('NO')

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
		else : left2seat -= 2
	elif (leftSol == 2) :
		if (left4seat > 0) :
			left4seat -= 1
			left1seat += 1
		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")

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

count = k-count
if count <= n*8-sum(a):
    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)
        if n+1-j<b:
            print("NO")
        else:
            c=a//2
            if a%2!=0:
                c+=1
            d=(c-b)//2
            if (c-b)%2 !=0 and (c-b)>=0:
                d+=1
            c=max(0,d)
            if b+c<=n+1-j:
                print("YES")
            else:
                print("NO")
    else:
        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 tmp <= cnt_4):
        cnt_4 = cnt_4 - tmp
        arr[i] = arr[i] - tmp * 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 tmp <= cnt_2):
        cnt_2 = cnt_2 - tmp
        arr[i] = arr[i] - tmp * 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")

n,m=map(int,input().split())
n=n*4
l=list(map(int,input().split()))
for i in range(m) :
    if l[i]%2==0 :
        n=n-(l[i]//2)
    else :
        n=n-(l[i]//2)-1

if n>=0 :
    print("YES")
else :
    print('NO')

a=map(int,raw_input().split())
n=a[0]
k=a[1]
b=map(int,raw_input().split())
b.sort()
c=2*n
d=n
f=0
e=0
for i in range(3*n):
    if d>0:
        if b[len(b)-1]>=4:
            d=d-1
            b[len(b)-1]-=4

        else:
            if b[len(b)-1]<2:
                d=d-1
                e=e+1
                b=[0]+b[0:len(b)-1]
            else:
                d=d-1
                e=e+1
                b=[0]+b[0:len(b)-1]

    else:
        if c>0:
            if b[len(b)-1]>=2:
                c=c-1
                b[len(b)-1]-=2
            else:
                c=c-1
                b=[0]+b[0:len(b)-1]

        else:
            f=2
            break
    b.sort()

    if b==[0]*len(b):
        f=1
        break

if e>0 and f!=1 and f!=2:
    for i in range(len(b)-1,0,-1):
        if b[i]>1:
            break
        else:
            b[i]=b[i]-1
            e=e-1
        if b==[0]*len(b):
            f=1
            break
        elif e<=0:

            break

if f==1:
    print 'YES'
else:
    print 'NO'

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
  print(sozinhos, duplas, quads, cnt[1])
  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))

#coding=utf-8

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 temp == k) and flag%4==0:
            print("NO")
        else:
            print("YES")
    else:
        if (sum + place) <= total:
            print("YES")
        else:
            print("NO")

test()

debug = 0
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
if debug: print(*a)
for i in range(n):
    cnt = min(cnt2, a[i] // 2)
    a[i] -= cnt * 2
    cnt2 -= cnt
if debug: print(' '.join(map(str, a)), ' ', cnt2, cnt4)
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])
c[2] -= d
cnt4 -= d
if debug:
    print('cnt4 = ', cnt4)
    print('c[1] = ', c[1])
d = min(cnt4, (c[1] + 1) // 2)
c[1] -= d * 2
cnt4 -= d
print('YES' if sum(c[1:]) == 0 else 'NO')

"""Problem: http://codeforces.com/contest/839/problem/B"""

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

	else:

		val = False

if remainders[0] > one_sit + rows_whithout_four * 2 + rows_whithout_two:

	val = False

if val:

	print("YES")

else:

	print("NO")

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")
##########################################################
from collections import Counter
# c=sorted((i,int(val))for i,val in enumerate(input().split()))
import heapq
# c=sorted((i,int(val))for i,val in enumerate(input().split()))
# n = int(input())
# ls = list(map(int, input().split()))
#n=int(input())
#arr = list(map(int, input().split()))

#for _ in range(int(input())):

#n=int(input())
n,x= map(int, input().split())
arr = list(map(int, input().split()))
ans=0
ex=0
for i in range(x):
    var=arr[i]
    if ex>0:

        if arr[i]>=(x-1):

            var-=max(0,ex-1)
            ex=0
            ans+=var//8
            if var%8!=0:
                ans+=1
                ex=8-var

        else:
            ex=ex-1-var
            var=0

    else:

        ans+=arr[i]//8
        if arr[i]%8!=0:
            ex=8-var%8
            ans+=1

print("YES" if ans<=n else "NO")

s = raw_input().split()
n = int(s[0])
k = int(s[1])

rowCount4 = 0
a = raw_input().split()

for i in range(k):
    a[i] = int(a[i])
    n -= a[i] / 4
    rowCount4 += a[i] / 4
    a[i] %= 4

    if (a[i] == 3):
        rowCount4 += 1
        a[i] = 0
        n -= 1

index2 = -1

for i in range(k):
    if (a[i] == 2 and rowCount4 > 0):
        if (index2 == -1):
            index2 = i
        else:
            a[i] = 0
            a[index2] = 0
            index2 = -1
            rowCount4 -= 1

index1 = -1

for i in range(k):
    if (a[i] == 1 and rowCount4 > 0):
        if (index1 == -1):
            index1 = i
        else:
            a[i] = 0
            a[index1] = 0
            index1 = -1
            rowCount4 -= 1

count2 = 0

for i in range(k):
    if (a[i] == 2):
        a[i] = 0
        count2 += 1

rowCount2 = 0

if (rowCount4 <= 0):
    rowCount2 = count2 / 3
    n -= count2 / 3

    count2 %= 3

#43
while count2 > 0 and rowCount2 >= 2:
    rowCount2 -= 2
    count2 -= 1

rowCount4Half = 0

if (count2 > 0):
    if (rowCount4 == 0):
        count2 -= 1
        n -= 1

    elif (rowCount4 > 0):
        count2 -= 1
        rowCount4 -= 1
        rowCount4Half += 1

count1 = 0

for i in range(k):
    if (a[i] == 1):
        a[i] = 0
        count1 += 1
        if (rowCount2 > 0):
            rowCount2 -= 1
            count1 -= 1
            a[i] = 0

if (count2 > 0):
    count1 -= 4 - count2

if (count1 > 0):
    n -= count1 / 4
    count1 %= 4

if (count1 > 0):
    if (rowCount4 == 0):
        count1 -= 1
        n -= 1

    elif (rowCount4 > 0):
        count1 -= 1
        if (rowCount4Half > 0):
            rowCount4Half -= 1
        else:
            rowCount4 -= 1
            rowCount4Half += 1

if (rowCount4 > 0):
    n += rowCount4 / 2
    rowCount4 %= 2

if (n >= 0):
    print "YES"
else:
    print "NO"

debug = 0
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
if debug: print(*a)
for i in range(n):
    cnt = min(cnt2, a[i] // 2)
    a[i] -= cnt * 2
    cnt2 -= cnt
if debug: print(' '.join(map(str, a)), ' ', cnt2, cnt4)
c = [0] * 20
for i in a:
    c[min(i, 19)] += 1
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])
c[2] -= d
cnt4 -= d
if debug:
    print('cnt4 = ', cnt4)
    print('c[1] = ', c[1])
d = min(cnt4, (c[1] + 1) // 2)
c[1] -= d * 2
cnt4 -= d
print('YES' if sum(c[1:]) == 0 else 'NO')

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

tt = []
for i in range(len(jj)):
    while double > 0 and jj[i] >= 2:
        double -= 1
        jj[i] -= 2
    if jj[i] != 0:
        tt.append(jj[i])
ss = []
for i in range(len(tt)):
    while four > 0 and tt[i] >= 3:
        four -= 1
        tt[i] -= 3
    if tt[i] != 0:
        ss.append(tt[i])
ff = []
double += 2 * four
for i in range(len(ss)):
    while four > 0 and ss[i] >= 2:
        double -= 1
        ss[i] -= 2
    if ss[i] != 0:
        ff.append(ss[i])

ans = len(ff)
ans -= min(ff.count(1), double)
if (ans):
    print("NO")
else:
    print("YES")

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%4==0 and k-count<n:
        print('NO')
    else:
        print('YES')
else:print('NO')

n,k = map(int,raw_input().split())
a = map(int,raw_input().split())

works = True
seats_left = n*8
for ele in a:
    t = ele
    if t%2==1:
        t += 1
    seats_left -= t
    if seats_left < 0:
        works = False
        break

if works:
    print "YES"
else:
    print "NO"

read = lambda: map(int, input().split())
debug = 0
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
if debug: print(*a)
for i in range(n):
    cnt = min(cnt2, a[i] // 2)
    a[i] -= cnt * 2
    cnt2 -= cnt
if debug: print(' '.join(map(str, a)), ' ', cnt2)
a.sort(reverse = 1)
for i in range(n):
    if cnt4 == 0: break
    if a[i] == 0: continue
    if a[i] >= 3:
        cnt4 -= 1
        a[i] = 0
    elif a[i] >= 2:
        if i < n and a[i + 1] > 0:
            a[i + 1] -= 1
        cnt4 -= 1
        a[i] = 0
a.sort(reverse = 1)
for i in range(n):
    if cnt4 == 0: break
    if a[i] == 0: continue
    if a[i] >= 3:
        cnt4 -= 1
        a[i] = 0
    elif a[i] >= 2:
        if i < n and a[i + 1] > 0:
            a[i + 1] -= 1
        cnt4 -= 1
        a[i] = 0
a.sort(reverse = 1)
for i in range(n):
    cnt = min(cnt4, a[i])
    a[i] -= cnt
    cnt4 -= cnt
for i in range(n):
    cnt = min(cnt2, a[i])
    a[i] -= cnt
    cnt2 -= cnt
print('YES' if sum(a) == 0 else 'NO')

debug = 1
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
if debug: print(*a)
for i in range(n):
    cnt = min(cnt2, a[i] // 2)
    a[i] -= cnt * 2
    cnt2 -= cnt
if debug: print(' '.join(map(str, a)), ' ', cnt2, cnt4)
c = [0] * 20
for i in a:
    c[min(i, 19)] += 1
if debug:
    print(cnt2, cnt4, c)
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] + 1) // 3)
c[2] -= d * 3
cnt4 -= d
if debug:
    print('cnt4 = ', cnt4)
    print('c[1] = ', c[1])
d = min(cnt4, c[2])
c[2] -= d
cnt4 -= d
d = min(cnt4, (c[1] + 1) // 2)
c[1] -= d * 2
cnt4 -= d
print('YES' if sum(c[1:]) == 0 else 'NO')

# encoding:utf-8

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:
		# there is rest of 4 seat
		seat_four -= n_four
		n_four = 0

		# break seat seat_one and seat_two
		seat_two += seat_four
		seat_one += seat_four
	else:
		# there is rest of 4 people
		n_four -= seat_four
		seat_four = 0

		# break 4 people to 2, 2
		n_two = n_four * 2

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

if __name__ == '__main__':
	main()

"""
    Author      : Arif Ahmad
    Date        :
    Algo        :
    Difficulty  :
"""
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
    ans = 'YES'
    for x in a:
        req = x // 2
        #print('corner:', cornerSlot, ' middle:', middleSlot, ' single:', slotForOne)
        #print('group of:', x, ' req:', req, '\n')

        if req % 2 == 1:
        	hand = 1
        	req -= 1
        else:
        	hand = 0

        # try to accommodate even no. of pairs in middle
        if middleSlot >= req:
            middleSlot -= req
            req = 0
        elif middleSlot > 0:
            req -= middleSlot
            middleSlot = 0

        if hand: req += 1

        # now accommodate rest of the pairs in the corner
        if cornerSlot >= req:
            cornerSlot -= req
            req = 0

        elif cornerSlot > 0:
            req -= cornerSlot
            cornerSlot = 0

        # again, accommodate rest of the pairs in middle
        if middleSlot >= req:
            middleSlot -= req
            req = 0
        elif middleSlot > 0:
            req -= middleSlot
            middleSlot = 0

        if req > 0:
            ans = 'NO'
            break

        if middleSlot % 2 == 1:
            middleSlot -= 1
            slotForOne += 1

        if x % 2 == 1:
            if slotForOne > 0:
                slotForOne -= 1
            elif middleSlot > 0:
                middleSlot -= 1
            elif cornerSlot > 0:
                cornerSlot -= 1
            else:
                ans = 'NO'
                break

    stdout.write(ans)

if __name__ == '__main__':
    main()

from math import ceil
n, k = map(int, raw_input().split())
A = map(int, raw_input().split())
S = 8 * n
c = 0
d = 0

for i in xrange(k):
    c += A[i] / 4
    r = A[i] % 4
    if r == 1 or r == 2: d += 1
    if r == 3: d += 2

if c * 4 + d * 2 > S: print 'NO'
else: print 'YES'

#coding=utf-8

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

total = n*8
place = 0
sum = 0
i=0
while i<k:
    sum+=a[i]
    if a[i]%2 is 1:
        place += 1
    i += 1
if (sum+place) <= total and place != 0:
    print("YES")
elif (k%3==0 or k%3==2) and place == 0:
    print("YES")
else:
    print("NO")

read = lambda: map(int, input().split())
debug = 1
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
if debug: print(*a)
for i in range(n):
    cnt = min(cnt2, a[i] // 2)
    a[i] -= cnt * 2
    cnt2 -= cnt
if debug: print(' '.join(map(str, a)), ' ', cnt2)
a.sort(reverse = 1)
for i in range(n):
    if cnt4 == 0: break
    if a[i] == 0: continue
    if a[i] >= 3:
        cnt4 -= 1
        a[i] = 0
    elif a[i] >= 2:
        if i < n and a[i + 1] > 0:
            a[i + 1] -= 1
        cnt4 -= 1
        a[i] = 0
a.sort(reverse = 1)
for i in range(n):
    if cnt4 == 0: break
    if a[i] == 0: continue
    if a[i] >= 3:
        cnt4 -= 1
        a[i] = 0
    elif a[i] >= 2:
        if i < n and a[i + 1] > 0:
            a[i + 1] -= 1
        cnt4 -= 1
        a[i] = 0
a.sort(reverse = 1)
for i in range(n):
    cnt = min(cnt4, a[i])
    a[i] -= cnt
    cnt4 -= cnt
for i in range(n):
    cnt = min(cnt2, a[i])
    a[i] -= cnt
    cnt2 -= cnt
print('YES' if sum(a) == 0 else 'NO')

# encoding:utf-8

def main():
	n, k = list(map(int, input().split()))
	nums = list(map(int, input().split()))

	two = n * 2
	four = n

	n_four = sum([x // 4 for x in nums])
	nums = [x % 4 for x in nums]

	if four >= n_four:
		four -= n_four
		n_four = 0
		two += four * 2
	else:
		n_four -= four
		four = 0

	n_two = sum([x // 2 for x in nums])
	rest = sum([x % 2 for x in nums]) + n_four * 2

	if n_two + rest <= two:
		print("YES")
	else:
		print("NO")

if __name__ == '__main__':
	main()

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(r'\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 = 2 * n, n, 0
    cnt = 0
    for i in range(k):
        y -= a[i] // 4
        a[i] %= 4
        if a[i] % 2 == 1:
            cnt += 1
            a[i] -= a[i] % 2
    if y < 0:
        x += 2 * y
        y = 0
    temp = min(cnt, 2 * y)
    cnt -= temp
    y -= temp // 2
    if cnt:
        x -= cnt
    for i in range(k):
        if y > 0:
            y -= a[i] // 2
        else:
            x -= a[i] // 2
    if x >= 0:
        print("YES")
    else:
        print("NO")

if __name__ == '__main__':
    main()

s = raw_input().split()
n = int(s[0])
k = int(s[1])

rowCount4 = 0
a = raw_input().split()

for i in range(k):
    a[i] = int(a[i])
    n -= a[i] / 4
    rowCount4 += a[i] / 4
    a[i] %= 4

    if (a[i] == 3):
        rowCount4 += 1
        a[i] = 0
        n -= 1

index2 = -1

for i in range(k):
    if (a[i] == 2 and rowCount4 > 0):
        if (index2 == -1):
            index2 = i
        else:
            a[i] = 0
            a[index2] = 0
            index2 = -1
            rowCount4 -= 1

index1 = -1

for i in range(k):
    if (a[i] == 1 and rowCount4 > 0):
        if (index1 == -1):
            index1 = i
        else:
            a[i] = 0
            a[index1] = 0
            index1 = -1
            rowCount4 -= 1

count2 = 0

for i in range(k):
    if (a[i] == 2):
        a[i] = 0
        count2 += 1

rowCount2 = 0

if (rowCount4 <= 0):
    rowCount2 = count2 / 3
    n -= count2 / 3

    count2 %= 3

rowCount4Half = 0

if (count2 > 0):
    if (rowCount4 == 0):
        count2 -= 1
        n -= 1

    elif (rowCount4 > 0):
        count2 -= 1
        rowCount4 -= 1
        rowCount4Half += 1

count1 = 0

for i in range(k):
    if (a[i] == 1):
        a[i] = 0
        count1 += 1
        if (rowCount2 > 0):
            rowCount2 -= 1
            count1 -= 1
            a[i] = 0

if (count2 > 0):
    count1 -= 4 - count2

if (count1 > 0):
    n -= count1 / 4
    count1 %= 4

if (count1 > 0):
    if (rowCount4 == 0):
        count1 -= 1
        n -= 1

    elif (rowCount4 > 0):
        count1 -= 1
        if (rowCount4Half > 0):
            rowCount4Half -= 1
        else:
            rowCount4 -= 1
            rowCount4Half += 1

if (rowCount4 > 0):
    n += rowCount4 / 2
    rowCount4 %= 2

if (n >= 0):
    print "YES"
else:
    print "NO"

"""
    Author      : Arif Ahmad
    Date        :
    Algo        :
    Difficulty  :
"""
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
    ans = 'YES'
    for x in a:
        req = x // 2
        if cornerSlot >= req:
            cornerSlot -= req
            req = 0
        elif cornerSlot > 0:
            req -= cornerSlot
            cornerSlot = 0

        if middleSlot >= req:
            middleSlot -= req
            req = 0
        elif middleSlot > 0:
            req -= middleSlot
            middleSlot = 0

        if req > 0:
            ans = 'NO'
            break

        if middleSlot % 2 == 1:
            middleSlot -= 1
            slotForOne += 1

        if x % 2 == 1:
            if slotForOne > 0:
                slotForOne -= 1
            elif middleSlot > 0:
                middleSlot -= 1
            elif cornerSlot > 0:
                cornerSlot -= 1
            else:
                ans = 'NO'
                break

    stdout.write(ans)

if __name__ == '__main__':
    main()

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(r'\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 = 2 * n, n, 0
    cnt = 0
    for i in range(k):
        y -= a[i] // 4
        a[i] %= 4
        if a[i] % 2 == 1:
            cnt += 1
            a[i] -= a[i] % 2
    if y < 0:
        x += 2 * y
    else:
        z = 2 * y
    temp = min(cnt, z)
    cnt -= temp
    z -= temp
    if cnt > 0:
        x -= cnt
    for i in range(k):
        if z > 0:
            z -= a[i] // 2
        else:
            x -= a[i] // 2
    if x >= 0:
        print("YES")
    else:
        print("NO")

if __name__ == '__main__':
    main()

n, k = map(int, raw_input().split(' '))

xs = map(int, raw_input().split(' '))

if sum([x / 2 for x in xs]) + sum([x % 2 for x in xs]) <= 4 * n:
    print "YES"
else:
    print "NO"

n,k=map(int,input().split())
l=list(map(int,input().split()))
mist=n*4
for x in l :
    mist-=x//2

    mist-=x%2
if mist>=0 :
    print("YES")
else :
    print("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):
    print('YES')
else:print('NO')

def solve(n, k, a):
    fourSeatLeft = n
    twoSeatLeft = n * 2

    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] >= 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

    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'

##if __name__ == '__main__':
##
##    import sys
##
##    stdin = sys.stdin
##    sys.stdin = open('cf839b.txt')
##
##    testcaseNo = eval(input())
##
##    for c in range(testcaseNo):
##        [n, k] = [eval(v) for v in input().split()]
##        a = [eval(v) for v in input().split()]
##
##        result = solve(n, k, a)
##
##        print('Case#' + str(c + 1) + ':', end=' ')
##        print(result)
##
##    sys.stdin = stdin

[n, k] = [eval(v) for v in input().split()]
a = [eval(v) for v in input().split()]
print(solve(n, k, a))

n,k = [int(_) for _ in raw_input().strip().split()]
a = []*k
a = [int(_) for _ in raw_input().strip().split()]
d = [0]*10

def process56(nu4, nu2, num):
	if (nu4 >= d[num]):
		nu4 -= d[num]
		nu2 -= d[num]
	else:
		nu2 -= (d[num]-nu4)*2
		nu2 -= d[num]
		nu4 = 0
	return nu4, nu2

def process34(nu4, nu2, num):
	if (nu4 >= d[num]):
		nu4 -= d[num]
	else:
		nu2 -= (d[num]-nu4)*2
		nu4 = 0
	return nu4, nu2

if __name__ == "__main__":

	for i in range(k):
		n -= a[i] / 8
		d[a[i] % 8] += 1

	n -= d[7]
	nu2 = n*2
	nu4 = n
	result = -1
	if n >= 0 :
		nu4, nu2 = process56(nu4, nu2, 6)
		nu4, nu2 = process56(nu4, nu2, 5)

		nu4, nu2 = process34(nu4, nu2, 4)
		nu4, nu2 = process34(nu4, nu2, 3)

		# 2 1
		if nu4 > d[2] :
			tmp = 0
			if d[2]*2 % 3 > 0 :
				tmp = 1
			nu4 -= d[2]*2 / 3 + tmp
			nu2 += nu4*2
			nu4 = 0
			nu2 -= d[1]
		else:
			d[2] -= nu4 + nu4 / 2
			if nu4 % 2 == 1 :
				d[1] -= 1
			nu4 = 0
			nu2 -= d[2]+d[1]

	if nu2 < 0 or nu4 < 0 or k < 0 :
		result = 1
	if result == -1 :
		print "YES"
	else:
		print "NO"

n,k=map(int,input().split())
l=list(map(int,input().split()))
mist=n*4
for x in l :
    mist-=x/2
    mist-=x%2!=0
if mist>=0 :
    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

	if a:
		print('NO')
		exit()

print('YES')

n, m = map(int, input().split())
z = list(map(int, input().split()))
h = []
for i in range(len(z)):
    n -= z[i] // 8
    z[i] %= 8
    if (z[i] != 0):
        h.append(z[i])
double = 2 * n
four = n
jj = []
for i in range(len(h)):
    if four > 0 and h[i] >= 4:
        h[i] -= 4
        four -= 1
    if (h[i] != 0):
        jj.append(h[i])

tt = []
for i in range(len(jj)):
    while double > 0 and jj[i] >= 2:
        double -= 1
        jj[i] -= 2
    if jj[i] != 0:
        tt.append(jj[i])
ss = []
for i in range(len(tt)):
    while four > 0 and tt[i] >= 3:
        four -= 1
        tt[i] -= 3
    if tt[i] != 0:
        ss.append(tt[i])
ff = []
for i in range(len(ss)):
    while four > 0 and ss[i] >= 2:
        double -= 1
        ss[i] -= 2
    if ss[i] != 0:
        ff.append(ss[i])

double += 2 * four
ans = len(ff)
ans -= min(ff.count(1), double)
if (ans):
    print("NO")
else:
    print("YES")

"""Problem: http://codeforces.com/contest/839/problem/B"""

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

	else:

		val = False

if remainders[0] > one_sit + rows_whithout_four + rows_whithout_two:

	val = False

if val:

	print("YES")

else:

	print("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):
            if self.a[i] > 1:
                return False
            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, 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)):
    if four > 0 and h[i] >= 4:
        h[i] -= 4
        four -= 1
    if (h[i] != 0):
        jj.append(h[i])

tt = []
for i in range(len(jj)):
    while double > 0 and jj[i] >= 2:
        double -= 1
        jj[i] -= 2
    if jj[i] != 0:
        tt.append(jj[i])
ss = []
for i in range(len(tt)):
    while four > 0 and tt[i] >= 3:
        four -= 1
        tt[i] -= 3
    if tt[i] != 0:
        ss.append(tt[i])
ff = []
for i in range(len(ss)):
    while four > 0 and ss[i] >= 2:
        double -= 1
        ss[i] -= 2
    if ss[i] != 0:
        ff.append(ss[i])

double += 2 * four
ans = len(ff)
ans -= min(ff.count(1), double)
if (ans):
    print("NO")
else:
    print("YES")

debug = 0
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
if debug: print(*a)
for i in range(n):
    cnt = min(cnt2, a[i] // 2)
    a[i] -= cnt * 2
    cnt2 -= cnt
if debug: print(' '.join(map(str, a)), ' ', cnt2)
c = [0] * 100
for i in a:
    c[min(i, 97)] += 1
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])
c[2] -= d
cnt4 -= d
d = min(cnt4, c[1])
c[1] -= d
cnt4 -= d
print('YES' if sum(c[1:]) == 0 else 'NO')

a=map(int,raw_input().split())
n=a[0]
k=a[1]
b=map(int,raw_input().split())
b.sort()
c=2*n
d=n
f=0
e=0
for i in range(3*n):
    if d>0:
        if b[len(b)-1]>=4:
            d=d-1
            b[len(b)-1]-=4

        else:
            if b[len(b)-1]<2:
                d=d-1
                e=e+1
                b=[0]+b[0:len(b)-1]
            else:
                d=d-1
                e=e+1
                b=[0]+b[0:len(b)-1]

    else:
        if c>0:
            if b[len(b)-1]>=2:
                c=c-1
                b[len(b)-1]-=2
            else:
                c=c-1
                b=[0]+b[0:len(b)-1]

        else:
            f=2
            break
    b.sort()

    if b==[0]*len(b):
        f=1
        break

if e>0 and f!=1 and f!=2:
    if e>=sum(b):
        f=1

if f==1:
    print 'YES'
else:
    print 'NO'

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

n, k = map(int, input().split())
arr = list(map(int, input().split()))
n -= sum([x//8 for x in arr])
t = [x % 8 for x in arr]
mid = n
sides = 2*n
ones = arr.count(1)
arr.sort(reverse=True)
mid_2 = 0
for i in range(k):
    if t[i] > 6:
        if mid > 0:
            mid -= 1
        else:
            sides -= 2
        sides -= 2
    elif t[i] > 4:
        if mid > 0:
            mid -= 1
        else:
            sides -= 2
        sides -= 1
    elif t[i] > 2:
        if mid > 0:
            mid -= 1
        else:
            sides -= 2
    else:
        if t[i] == 2 and mid > 0:
            if ones > 0:
                mid_2 += 1
                ones -= 1
            mid -= 1
        elif t[i] == 2:
            sides -= 1
        elif t[i] == 1:
            if mid_2 > 0:
                mid_2 -= 1
            else:
                sides -= 1

if sides >= 0 and mid >= 0:
    print('YES')
else:
    print('NO')

from math import ceil
n, k = map(int, raw_input().split())
A = map(int, raw_input().split())
s4 = n
s2 = n * 2
t4 = 0
t2 = 0
t3 = 0
for i in xrange(k):
    t4 += A[i] / 4
    r = A[i] % 4
    if r == 1 or r == 2: t2 += 1
    if r == 3: t3 += 1

if t4 >= s4:
    if (t4 - s4) * 2 + t2 + t3 * 2 <= s2:
        print 'YES'
    else:
        print 'NO'
else:
    c = s4 - t4
    if t3 >= c:
        if (t3 - c) * 2 + t2 <= s2: print 'YES'
        else: print 'NO'
    else:
        if (c - t3) + s2 >= t2: print 'YES'
        else: print 'NO'

import sys

def solve(n, k, groups):
    num_4 = n
    num_2 = 2*n
    remaining_groups = []
    for group in groups:
        if group % 2 == 1:
            if num_4 > 0:
                if group >= 3:
                    group -= 3
                else:
                    group -= 1
                    num_2 += 1
                num_4 -= 1
                if group > 0:
                    remaining_groups.append(group)
            elif num_2 > 0:
                group -= 1
                num_2 -= 1
                if group > 0:
                    remaining_groups.append(group)
            else:
                return 'NO'
        else:
            remaining_groups.append(group)

    remaining_groups = sorted(remaining_groups, reverse=True)
    for group in remaining_groups:
        if group >= 4 and num_4 > 0:
            req_4 = group / 4
            if req_4 > num_4:
                group -= num_4 * 4
                num_4 = 0
            else:
                num_4 -= req_4
                group -= req_4 * 4
        if group >= 2 and num_2 > 0:
            req_2 = group / 2
            if req_2 > num_2:
                group -= num_2 * 2
                num_2 = 0
            else:
                num_2 -= req_2
                group -= req_2 * 2
        if group >= 2 and num_4 > 0:
            req_2 = group / 2
            if req_2 > num_4:
                return 'NO'
            else:
                num_4 -= req_2
                group -= req_2*2
        if group != 0:
            return 'NO'

    return 'YES'

if __name__ == '__main__':
    n, k = map(int, sys.stdin.readline().split())
    groups = map(int, sys.stdin.readline().split())
    print solve(n, k, groups)

from sys import exit

num_rows, num_groups = map(int, raw_input().split(' '))

groups = map(int, raw_input().split(' '))

num_quads, num_doubles = num_rows, 2 * num_rows

# Fully fill up first quads, then doubles, as many as possible

for i in xrange(num_groups):
    occupiable_quads = min(num_quads, groups[i] / 4)

    num_quads -= occupiable_quads
    groups[i] -= 4 * occupiable_quads

for i in xrange(num_groups):
    occupiable_doubles = min(num_doubles, groups[i] / 2)

    num_doubles -= occupiable_doubles
    groups[i] -= 2 * occupiable_doubles

# If there are groups of 4 and up left, problem is infeasible
# (not sure if this even possible under the assignment conditions, but doesn't hurt to check :>)

if len(filter(lambda x: x >= 4, groups)) != 0:
    print "NO"

    exit(0)

# Subproblem:
# distribute groups of 1, 2 and 3 people over leftover quads and doubles

# Distribute all groups of 3 over quads

for i in filter(lambda x: groups[x] == 3, xrange(num_groups)):
    if num_quads == 0:
        break

    groups[i] = 0
    num_quads -= 1

# If that couldn't be done, place two people of every group of 3 on a double

for i in filter(lambda x: groups[x] == 3, xrange(num_groups)):
    if num_doubles == 0:
        break

    groups[i] -= 2
    num_doubles -= 1

# If we coudn't distribute all groups of 3, the problem is infeasible

if len(filter(lambda x: x == 3, groups)) != 0:
    print "NO"

    exit(0)

# Subproblem:
# distribute groups of 1 and 2 over leftover quads and doubles

# Distribute pairs of 1 and 2 groups over quads, thus filling the quads up

for i, j in zip(
    filter(lambda i: groups[i] == 1, xrange(num_groups)),
    filter(lambda i: groups[i] == 2, xrange(num_groups))
    ):

    if num_quads == 0:
        break

    groups[i] = 0
    groups[j] = 0

if num_quads == 0:
    # Subproblem:
    # distribute groups of 1 and 2 over the remaining doubles

    for i in xrange(num_groups):
        if num_doubles == 0:
            break

        if groups[i] == 1 or groups[i] == 2:
            groups[i] = 0
            num_doubles -= 1
else:
    # There are quads left, but either groups of 1 or groups of 2 are gone (or both)

    if len(filter(lambda x: x == 2, groups)) != 0:
        # Subproblem:
        # distribute groups of 2 over the remaining quads and doubles

        for i in xrange(num_groups):
            if num_doubles == 0:
                break

            if groups[i] == 2:
                num_doubles -= 1
                groups[i] = 0

        for i in xrange(num_groups):
            if num_quads == 0:
                break

            if groups[i] == 2:
                num_quads -= 1
                groups[i] = 0

    elif len(filter(lambda x: x == 1, groups)) != 0:
        # Subproblem:
        # distribute groups of 1 over the remaining quads and doubles

        for i in xrange(num_groups):
            if num_doubles == 0:
                break

            if groups[i] == 1:
                num_doubles -= 1
                groups[i] = 0

        one_groups = filter(lambda i: groups[i] == 1, xrange(num_groups))

        for i, j in zip(one_groups[:len(one_groups) / 2], one_groups[len(one_groups) / 2:]):
            if num_quads == 0:
                break

            groups[i] = 0
            groups[j] = 0

            num_quads -= 1

        if num_quads != 0:
            for i in xrange(num_groups):
                if groups[i] == 1:
                    groups[i] = 0
                    num_quads -= 1

                    break

# If anything has remained after the distribution, the problem is infeasible

if sum(groups) == 0:
    print "YES"
else:
    print "NO"

import math
n, k = map(int, input().split())
arr = list(map(int, input().split()))
mid = n
sides = 2*n
ones = arr.count(1)
arr.sort(reverse=True)
for i in range(k):
    if arr[i] > 7:
        if arr[i]%4 == 3:
            mid -= 1
        r = min(mid, arr[i]//4)
        mid -= r
        if mid == 0:
            arr[i] -= r*4
            break
        else:
            if arr[i] % 4 != 3:
                arr[i] = arr[i] % 4
            else:
                arr[i] = 0

arr.sort(reverse=True)
mid_2 = 0
if mid == 0:
    for i in range(k):
        sides -= math.ceil(arr[i]/2)
else:
    for i in range(k):
        t = arr[i] % 8
        if t > 6:
            if mid > 0:
                mid -= 1
            else:
                sides -= 2
            sides -= 2
        elif t > 4:
            if mid > 0:
                mid -= 1
            else:
                sides -= 2
            sides -= 1
        elif t > 2:
            if mid > 0:
                mid -= 1
            else:
                sides -= 2
        else:
            if t == 2 and mid > 0:
                if ones > 0:
                    mid_2 += 1
                    ones -= 1
                mid -= 1
            elif t == 2:
                sides -= 1
            elif t == 1:
                if mid_2 > 0:
                    mid_2 -= 1
                else:
                    sides -= 1

if sides >= 0 and mid >= 0:
    print('YES')
else:
    print('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
count = 100-count
if count <= n*k-sum(a):
    print('YES')
else:print('NO')

tmp = input().split()
n = int(tmp[0])
k = int(tmp[1])
tmp = input().split()
a = []
sum = 0
for i in range(k):
    a.append(int(tmp[i]))
    sum += a[i]
i = 0
cnt4 = n
while cnt4 > 0 and i < k:
    if a[i] >= 4:
        a[i] -= 4
        cnt4 -= 1
    else:
        i += 1

if cnt4 == 0:
    w = 0
    for i in range(k):
        w += a[i] % 2
    if sum + w <= 8 * n:
        print('YES')
    else:
        print('NO')
else:
    w = 0
    s4 =[4] * cnt4
    n4 = 0
    for i in range(k):
        if a[i] == 3:
            w += 1
            a[i] = 0
            s4[n4] = 0
            n4 += 1
            if n4 == cnt4:
                break
    if n4 < cnt4:
        flag = 1
        for i in range(k):
            for j in range(k):
                if a[i] + a[j] == 3:
                    w += 1
                    a[i], a[j] = 0, 0
                    s4[n4] = 0
                    n4 += 1
                    if n4 == cnt4:
                        flag = 0
                        break
            if flag == 0:
                break
    if n4 < cnt4:
        for i in range(k):
            if a[i] == 2:
                a[i] = 0
                w += 2
                s4[n4] = 0
                n4 += 1
                if n4 == cnt4:
                    break
    if n4 < cnt4:
        flag = 1
        for i in range(k):
            for j in range(k):
                if a[i] + a[j] == 2 and i != j:
                    w += 2
                    s4[n4] = 0
                    n4 += 1
                    a[i], a[j] = 0, 0
                    if n4 == cnt4:
                        flag = 0
                        break
            if flag == 0:
                break
    if n4 < cnt4:
        for i in range(k):
            if a[i] == 1:
                w += 3
                s4[n4] = 0
                n4 += 1
                a[i] = 0
                if n4 == cnt4:
                    break
    for i in range(k):
        w += a[i] % 2
    if sum + w <= 8 * n:
        print('YES')
    else:
        print('NO')

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 p1 > 1:
                p1 -= 2
                x[i] = 0
            elif ch > 0:
                x[i] = 0
                p1 += 1
                ch -= 1
        elif x[i] == 1:
            if p1 > 0:
                p1 -= 1
                x[i] = 0
            elif p2 > 0:
                p2 -= 1
                x[i] = 0
            elif ch > 0:
                p2 += 1
                x[i] = 0
                ch -= 1

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

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

def solve(n,k,a):
    seats = n*8
    oneSeat = 0
    twoSeats = n*2
    fourSeats = n

    for i in a:
        current = i
        seatsNeeded = ceil(current/2)
        rowsNeeded = current // 8

        twoSeats -= 2*rowsNeeded
        fourSeats -= rowsNeeded
        rest = current % 8

        while rest > 0:
            if (twoSeats < 0) or (fourSeats < 0) or (oneSeat < 0):
                return "NO"
            if rest >= 4:
                if fourSeats > 0:
                    fourSeats -= 1
                elif twoSeats >= 2:
                    twoSeats -= 2
                else:
                    return "NO"
                rest -= 4
            else:
                #1,2,3
                if rest == 1:
                    if twoSeats > 0:
                        twoSeats -= 1
                    elif fourSeats > 0:
                        fourSeats -= 1
                        twoSeats += 1
                    else:
                        return "NO"
                    rest -= 1
                elif rest == 2:
                    if twoSeats > 0:
                        twoSeats -= 1
                    elif fourSeats > 0:
                        fourSeats -= 1
                        twoSeats += 1
                    else:
                        return "NO"
                    rest -= 2
                elif rest == 3:
                    if twoSeats >= 2:
                        twoSeats -= 2
                    elif fourSeats > 0:
                        fourSeats -= 1
                    else:
                        return "NO"
                    rest -= 3
    return "YES"

print(solve(n,k,a))

n,k = map(int,raw_input().split());
cnt = map(int,raw_input().split());
available = n;
for i in xrange(k):
    x = min(available,cnt[i]/4);
    available -= x;
    cnt[i] -= 4*x;

r = 2*n;
for i in xrange(k):
    if cnt[i] >= 4:
        x = min(r,cnt[i] / 2);
        r -= x;
        cnt[i] -= 2*x;
if sum(map(lambda x:x >= 4,cnt)): print "NO";
else:
    one = sum(map(lambda x:x == 1,cnt));
    two = sum(map(lambda x:x == 2,cnt));
    three = sum(map(lambda x: x == 3, cnt));
    #print one,two,three;
    #print available,r;
    x = min(r,three);
    one += x;
    three -= x;
    r -= x;
    x = min(r,two);
    r -= x;
    two -= x;
    x = min(available,three);
    available -= x;
    three -= x;
    if three: print "NO"
    else:
        three = min(two,one);
        two -= three;
        one -= three;
        x = min(available,three);
        three -= x;
        available -= x;
        two += three;
        one += three;
        two += (one + 1)/2;
        x = min(r,two);
        r -= x;
        two -= x;
        x = min(available,two);
        available -= x;
        two -= x;
        if two: print "NO";
        else: print "YES";

n,k = map(int,raw_input().split())
a = map(int,raw_input().split())

works = True

reg_seats = 4*n
mid_seats = 4*n
singles = 0

i = 0
while i<len(a) and mid_seats>0:
    if a[i]%4==0:
        t = min(mid_seats,a[i])
        mid_seats -= t
        if a[i]-t>0:
            a.append(a[i]-t)

    elif a[i]%4==1:
        t = min(mid_seats,a[i]+3)
        mid_seats -= t
        reg_seats += 2
        if a[i]-t>0:
            a.append(a[i]-t)

    elif a[i]%4==2:
        t = min(mid_seats,a[i]+2)
        mid_seats -= t
        singles += 1
        if a[i]-t>0:
            a.append(a[i]-t)

    elif a[i]%4==3:
        t = min(mid_seats,a[i]+1)
        mid_seats -= t
        if a[i]-t>0:
            a.append(a[i]-t)

    i += 1

while i<len(a) and reg_seats>0:
    if a[i]%2==1:
        if singles>0:
            singles -= 1
            reg_seats -= a[i]-1
        else:
            a[i] += 1
            reg_seats -= a[i]

    i += 1

while i<len(a):
    singles -= 1

if singles+reg_seats<0:
    print "NO"
else:
    print "YES"

n, k = map(int, input().split())
seat = {4:n, 2:n*2, 1: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 = sit(1, p1)
    extra1 = sit(2, extra1)
    x = sit(4, extra1)
    seat[2] += extra1 - x

    if x > 0:
        print("NO")
        break
else:
    print("YES")

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>=4:
            d-=3
            a[i]-=3
        else:
            print('NO')
            sys.exit()
    if 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()
    if 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())
l=list(map(int,input().split()))
mist=n*4
for x in l :
    mist-=x/2
    mist-=x%2!=0
if mist>=0 :
    print("YES")
else :
    print("NO")

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

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 x > 0:
    print("NO")
else:
    print("YES")

tmp = input().split()
n = int(tmp[0])
k = int(tmp[1])
tmp = input().split()
a = []
sum = 0
for i in range(k):
    a.append(int(tmp[i]))
    sum += a[i]
i = 0
cnt4 = n
while cnt4 > 0 and i < k:
    if a[i] >= 4:
        a[i] -= 4
        cnt4 -= 1
    else:
        i += 1

if cnt4 == 0:
    w = 0
    for i in range(k):
        w += a[i] % 2
    if sum + w <= 8 * n:
        print('YES')
    else:
        print('NO')
else:
    w = 0
    s4 =[4] * cnt4
    n4 = 0
    for i in range(k):
        if a[i] == 3:
            w += 1
            a[i] = 0
            s4[n4] = 0
            n4 += 1
            if n4 == cnt4:
                break
    if n4 < cnt4:
        flag = 1
        for i in range(k):
            for j in range(k):
                if a[i] + a[j] == 3:
                    w += 1
                    a[i], a[j] = 0, 0
                    s4[n4] = 0
                    n4 += 1
                    if n4 == cnt4:
                        flag = 0
                        break
            if flag == 0:
                break
    if n4 < cnt4:
        for i in range(k):
            if a[i] == 2:
                a[i] = 0
                w += 2
                s4[n4] = 0
                n4 += 1
                if n4 == cnt4:
                    break
    if n4 < cnt4:
        flag = 1
        for i in range(k):
            for j in range(k):
                if a[i] + a[j] == 2:
                    w += 2
                    s4[n4] = 0
                    n4 += 1
                    a[i], a[j] = 0, 0
                    if n4 == cnt4:
                        flag = 0
                        break
            if flag == 0:
                break
    if n4 < cnt4:
        for i in range(k):
            if a[i] == 1:
                w += 3
                s4[n4] = 0
                n4 += 1
                a[i] = 0
                if n4 == cnt4:
                    break
    for i in range(k):
        w += a[i] % 2
    if sum + w <= 8 * n:
        print('YES')
    else:
        print('NO')

"""
    Author      : Arif Ahmad
    Date        :
    Algo        :
    Difficulty  :
"""
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
    ans = 'YES'
    for x in a:
        req = x // 2
        #print('corner:', cornerSlot, ' middle:', middleSlot, ' single:', slotForOne)
        #print('group of:', x, ' req:', req, '\n')

        if req % 2 == 1:
        	hand = 1
        	req -= 1
        else:
        	hand = 0

        if middleSlot >= req:
            middleSlot -= req
            req = 0
        elif middleSlot > 0:
            req -= middleSlot
            middleSlot = 0

        if hand: req += 1

        if cornerSlot >= req:
            cornerSlot -= req
            req = 0

        elif cornerSlot > 0:
            req -= cornerSlot
            cornerSlot = 0

        if req > 0:
            ans = 'NO'
            break

        if middleSlot % 2 == 1:
            middleSlot -= 1
            slotForOne += 1

        if x % 2 == 1:
            if slotForOne > 0:
                slotForOne -= 1
            elif middleSlot > 0:
                middleSlot -= 1
            elif cornerSlot > 0:
                cornerSlot -= 1
            else:
                ans = 'NO'
                break

    stdout.write(ans)

if __name__ == '__main__':
    main()

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
		if l[2]:
			l[2] -= 1
			a = 0
		if 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 -= min(a, 2)
			l[2] -= 1
		while a and l[4]:
			a -= 2
			l[4] -= 1
			l[1] += 1

	if a:
		print('NO')
		exit()

print('YES')

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] == 1:
      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))

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

        if size == 3:
            if four > 0:
                four -= 1
            elif two >= 2:
                two -= 2
            elif one >= 3:
                one -= 3
            else:
                return "NO"
        elif size == 2:
            if two >= 1:
                two -= 1
            elif four > 0:
                four -= 1
                one += 1
            elif one >= 2:
                one -= 2
            else:
                return "NO"
        elif size == 1:
            if one >= 1:
                one -= 1
            elif four > 0:
                four -= 1
                two += 1
            elif two >= 1:
                two -= 1
            else:
                return "NO"
    return "YES"

print(solve(n,k,a))

n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
index = 0
left4seat = n
left2seat = n * 2
while (index < k and (left4seat + left2seat > 0) ) :
	left4seat -= a[index] // 4
	if (left4seat < 0) :
		left2seat += 2 * left4seat
		left4seat = 0
	leftSol = a[index] % 4
	if (leftSol >= 3) :
		if (left4seat > 0) : left4seat -= 1
		else : left2seat -= 2
	elif (leftSol != 0) :
		if (left2seat > 0) : left2seat -= 1
		else : left4seat -= 1
	if (left4seat < 0 or left2seat < 0) : break
	index += 1

if (left4seat < 0 or left2seat < 0) : print("NO")
else : print("YES")

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

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 x[i] == 1:
            if p1 > 0:
                p1 -= 1
                x[i] = 0
            elif p2 > 0:
                p2 -= 1
                x[i] = 0
            elif ch > 0:
                p2 += 1
                x[i] = 0
                ch -= 1
        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()

from sys import exit

num_rows, num_groups = map(int, raw_input().split(' '))

groups = map(int, raw_input().split(' '))

num_quads, num_doubles = num_rows, 2 * num_rows

# Fully fill up first quads, then doubles, as many as possible

for i in xrange(num_groups):
    occupiable_quads = min(num_quads, groups[i] / 4)

    num_quads -= occupiable_quads
    groups[i] -= 4 * occupiable_quads

for i in xrange(num_groups):
    occupiable_doubles = min(num_doubles, groups[i] / 2)

    num_doubles -= occupiable_doubles
    groups[i] -= 2 * occupiable_doubles

# If there are groups of 4 and up left, problem is infeasible
# (not sure if this even possible under the assignment conditions, but doesn't hurt to check :>)

if len(filter(lambda x: x >= 4, groups)) != 0:
    print "NO"

    exit(0)

# Subproblem:
# distribute groups of 1, 2 and 3 people over leftover quads and doubles

# Distribute all groups of 3 over quads

for i in filter(lambda x: groups[x] == 3, xrange(num_groups)):
    if num_quads == 0:
        break

    groups[i] = 0
    num_quads -= 1

# If that couldn't be done, place two people of every group of 3 on a double

for i in filter(lambda x: groups[x] == 3, xrange(num_groups)):
    if num_doubles == 0:
        break

    groups[i] -= 2
    num_doubles -= 1

# If we coudn't distribute all groups of 3, the problem is infeasible

if len(filter(lambda x: x == 3, groups)) != 0:
    print "NO"

    exit(0)

# Subproblem:
# distribute groups of 1 and 2 over leftover quads and doubles

# Distribute pairs of 1 and 2 groups over quads, thus filling the quads up

for i, j in zip(
    filter(lambda i: groups[i] == 1, xrange(num_groups)),
    filter(lambda i: groups[i] == 2, xrange(num_groups))
    ):

    if num_quads == 0:
        break

    groups[i] = 0
    groups[j] = 0

if num_quads == 0:
    # Subproblem:
    # distribute groups of 1 and 2 over the remaining doubles

    for i in xrange(num_groups):
        if num_doubles == 0:
            break

        if groups[i] == 1 or groups[i] == 2:
            groups[i] = 0
            num_doubles -= 1
else:
    # There are quads left, but either groups of 1 or groups of 2 are gone (or both)

    if len(filter(lambda x: x == 2, groups)) != 0:
        # Subproblem:
        # distribute groups of 2 over the remaining quads and doubles

        for i in xrange(num_groups):
            if num_doubles == 0:
                break

            if groups[i] == 2:
                num_doubles -= 1
                groups[i] = 0

        # On every two quads, we can place three groups of 2:
        # [1 1 - 3]
        # [2 2 - 3]

        two_groups = filter(lambda i: groups[i] == 2, xrange(num_groups))

        for i, j, k in zip(
            two_groups[:len(two_groups) / 3],
            two_groups[len(two_groups) / 3:len(two_groups) / 3 * 2],
            two_groups[len(two_groups) / 3 * 2:]
            ):
            if num_quads < 2:
                break

            groups[i] = 0
            groups[j] = 0
            groups[k] = 0

            num_quads -= 2

        # At most two groups of 2 remain, which requires two quads, or less than two quads are available -- either way,
        # at this point we can only place one group of 2 per quad

        for i in xrange(num_groups):
            if num_quads == 0:
                break

            if groups[i] == 2:
                groups[i] = 0
                num_quads -= 1

    elif len(filter(lambda x: x == 1, groups)) != 0:
        # Subproblem:
        # distribute groups of 1 over the remaining quads and doubles

        for i in xrange(num_groups):
            if num_doubles == 0:
                break

            if groups[i] == 1:
                num_doubles -= 1
                groups[i] = 0

        one_groups = filter(lambda i: groups[i] == 1, xrange(num_groups))

        for i, j in zip(one_groups[:len(one_groups) / 2], one_groups[len(one_groups) / 2:]):
            if num_quads == 0:
                break

            groups[i] = 0
            groups[j] = 0

            num_quads -= 1

        if num_quads != 0:
            for i in xrange(num_groups):
                if groups[i] == 1:
                    groups[i] = 0
                    num_quads -= 1

                    break

# If anything has remained after the distribution, the problem is infeasible

if sum(groups) == 0:
    print "YES"
else:
    print "NO"

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

tt = []
for i in range(len(jj)):
    while double > 0 and jj[i] >= 2:
        double -= 1
        jj[i] -= 2
    if jj[i] != 0:
        tt.append(jj[i])
ss = []
for i in range(len(tt)):
    while four > 0 and tt[i] >= 3:
        four -= 1
        tt[i] -= 3
    if tt[i] != 0:
        ss.append(tt[i])
ff = []
double += 2 * four
for i in range(len(ss)):
    while four > 0 and ss[i] >= 2:
        double -= 1
        ss[i] -= 2
    if ss[i] != 0:
        ff.append(ss[i])

ans = len(ff)
ans -= min(ff.count(1), double)
if (ans):
    print("NO")
else:
    print("YES")

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):
    print('YES')
else:print('NO')

n,k = [int(_) for _ in raw_input().strip().split()]
a = []*k
a = [int(_) for _ in raw_input().strip().split()]
d = [0]*10

def process56(nu4, nu2, num):
	if (nu4 >= d[num]):
		nu4 -= d[num]
		nu2 -= d[num]
	else:
		nu2 -= (d[num]-nu4)*2
		nu2 -= d[num]
		nu4 = 0
	return nu4, nu2

def process34(nu4, nu2, num):
	if (nu4 >= d[num]):
		nu4 -= d[num]
	else:
		nu2 -= (d[num]-nu4)*2
		nu4 = 0
	return nu4, nu2

if __name__ == "__main__":

	for i in range(k):
		n -= a[i] / 8
		d[a[i] % 8] += 1

	n -= d[7]
	nu2 = n*2
	nu4 = n
	result = -1
	if n >= 0 :
		nu4, nu2 = process56(nu4, nu2, 6)
		nu4, nu2 = process56(nu4, nu2, 5)
		nu4, nu2 = process34(nu4, nu2, 4)
		nu4, nu2 = process34(nu4, nu2, 3)
		# 2 1
		if nu4 > d[2] :
			tmp = 0
			if d[2]*2 % 3 > 0 :
				tmp = 1
			nu4 -= d[2]*2 / 3 + tmp
			nu2 += nu4*2
			nu4 = 0
			nu2 -= d[1]
		else:
			d[2] -= nu4 + nu4 / 2
			if nu4 % 2 == 1 :
				d[1] -= 1
				d[1] = max(d[1],0)
			nu4 = 0
			nu2 -= d[2]+d[1]

	if nu2 < 0 or nu4 < 0 or k < 0 :
		result = 1
	if result == -1 :
		print "YES"
	else:
		print "NO"

from sys import exit

num_rows, num_groups = map(int, raw_input().split(' '))

groups = map(int, raw_input().split(' '))

num_quads, num_doubles = num_rows, 2 * num_rows

# Fully fill up first quads, then doubles, as many as possible

for i in xrange(num_groups):
    occupiable_quads = min(num_quads, groups[i] / 4)

    num_quads -= occupiable_quads
    groups[i] -= 4 * occupiable_quads

for i in xrange(num_groups):
    occupiable_doubles = min(num_doubles, groups[i] / 2)

    num_doubles -= occupiable_doubles
    groups[i] -= 2 * occupiable_doubles

# If there are groups of 4 and up left, problem is infeasible
# (not sure if this even possible under the assignment conditions, but doesn't hurt to check :>)

if len(filter(lambda x: x >= 4, groups)) != 0:
    print "NO"

    exit(0)

# Subproblem:
# distribute groups of 1, 2 and 3 people over leftover quads and doubles

# Distribute all groups of 3 first over quads, then over doubles (because a quad is less useful than two doubles)

for i in filter(lambda x: groups[x] == 3, xrange(num_groups)):
    if num_quads == 0:
        break

    groups[i] = 0
    num_quads -= 1

for i in filter(lambda x: groups[x] == 3, xrange(num_groups)):
    if num_doubles == 0:
        break

    groups[i] = 0
    num_doubles -= 2

# If we coudn't distribute all groups of 3, the problem is infeasible

if len(filter(lambda x: x == 3, groups)) != 0:
    print "NO"

    exit(0)

# Subproblem:
# distribute groups of 1 and 2 over leftover quads and doubles

# Distribute pairs of 1 and 2 groups over quads, thus filling the quads up

for i, j in zip(
    filter(lambda i: groups[i] == 1, xrange(num_groups)),
    filter(lambda i: groups[i] == 2, xrange(num_groups))
    ):

    if num_quads == 0:
        break

    groups[i] = 0
    groups[j] = 0

if num_quads == 0:
    # Subproblem:
    # distribute groups of 1 and 2 over the remaining doubles

    for i in xrange(num_groups):
        if num_doubles == 0:
            break

        if groups[i] == 1 or groups[i] == 2:
            groups[i] = 0
            num_doubles -= 1
else:
    # There are quads left, but either groups of 1 or groups of 2 are gone (or both)

    if len(filter(lambda x: x == 2, groups)) != 0:
        # Subproblem:
        # distribute groups of 2 over the remaining quads and doubles

        for i in xrange(num_groups):
            if num_doubles == 0:
                break

            if groups[i] == 2:
                num_doubles -= 1
                groups[i] = 0

        for i in xrange(num_groups):
            if num_quads == 0:
                break

            if groups[i] == 2:
                num_quads -= 1
                groups[i] = 0

    elif len(filter(lambda x: x == 1, groups)) != 0:
        # Subproblem:
        # distribute groups of 1 over the remaining quads and doubles

        for i in xrange(num_groups):
            if num_doubles == 0:
                break

            if groups[i] == 1:
                num_doubles -= 1
                groups[i] = 0

        one_groups = filter(lambda i: groups[i] == 1, xrange(num_groups))

        for i, j in zip(one_groups[:len(one_groups) / 2], one_groups[len(one_groups) / 2:]):
            if num_quads == 0:
                break

            groups[i] = 0
            groups[j] = 0

            num_quads -= 1

        if num_quads != 0:
            for i in xrange(num_groups):
                if groups[i] == 1:
                    groups[i] = 0
                    num_quads -= 1

                    break

# If anything has remained after the distribution, the problem is infeasible

if sum(groups) == 0:
    print "YES"
else:
    print "NO"

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

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 4
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 3
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

#REMOVE GROUPS WITH 0 REMAINED
a = removeZeroes(a)
if a.count(2) + a.count(1) != len(a):
    print("NO")
    sys.exit(0)

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]

if len(a) > 0 and a[0] == 1:
    if (a.count(1)+1) // 2 <= mid:
        print("YES")
        sys.exit(0)
    else:
        print("NO")
        sys.exit(0)
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")
        sys.exit(0)

if len(a) > 0:
    print("NO")
else:
    print("YES")

from math import ceil
n, k = map(int, raw_input().split())
A = map(int, raw_input().split())
s4 = n
s2 = n * 2
t4 = 0
t2 = 0
t1 = 0
for i in xrange(k):
    t4 += A[i] / 4
    r = A[i] % 4
    if r == 1: t1 += 1
    if r == 2: t2 += 1
    if r == 3: t2, t1 = t2 + 1, t1 + 1

if t4 >= s4:
    if (t4 - s4) * 2 + t2 + t1 <= s2:
        print 'YES'
    else:
        print 'NO'
else:
    c = s4 - t4
    if t2 <= s2:
        if t1 <= s2 - t2 + c * 2:
            print 'YES'
        else:
            print 'NO'
    else:
        if s2 - t2 + c < 0:
            print 'NO'
        else:
            if s2 - t2 + 2 * c >= t1:
                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 = 2 * n
chk = False
while cnt_4 > 0:
    chk = 0
    for j in range(cn):
        if a[j] > 3:
            a[j] -= 4
            cnt_4 -= 1
            cnt_2_4 -= 2
            chk = 1
            break
    if (not chk):
        break
#print(cnt_4, cnt_2_4, cnt_2)
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
#print(cnt_4, cnt_2_4, cnt_2)
while cnt_2_4 > 0:
    chk = 0
    for j in range(cn):
        if (a[j] == 1):
            a[j] = 0
            cnt_2_4 -= 1
            cnt_2 += 1
            cnt_4 -= 1
            chk = 1
            break
    if (not chk):
        break
cnt_2 += cnt_2_4
#print(cnt_4, cnt_2_4, cnt_2)
while cnt_2 > 0:
    chk = 0
    for j in range(cn):
        if (a[j] > 0):
            a[j] -= 2
            cnt_2 -= 1
            chk = 1
            break
    if (not chk):
        break
#print(cnt_4, cnt_2_4, cnt_2)
chk1 = 0
for i in a:
    if i > 0:
        chk1 = 1
if chk1:
    print("NO")
else:
    print("YES")

# encoding:utf-8

def main():
	n, k = list(map(int, input().split()))
	nums = list(map(int, input().split()))

	two = n * 2
	four = n

	n_four = sum([x // 4 for x in nums])
	nums = [x % 4 for x in nums]

	if four >= n_four:
		four -= n_four
		n_four = 0
		two += four * 2
	else:
		n_four -= four
		four = 0

	n_two = sum([x // 2 for x in nums])
	rest = sum([x % 2 for x in nums]) + n_four * 2

	if n_two + rest <= two:
		print("YES")
	else:
		print("NO")

if __name__ == '__main__':
	main()

debug = 0
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
if debug: print(*a)
for i in range(n):
    cnt = min(cnt2, a[i] // 2)
    a[i] -= cnt * 2
    cnt2 -= cnt
if debug: print(' '.join(map(str, a)), ' ', cnt2, cnt4)
c = [0] * 20
for i in a:
    c[min(i, 19)] += 1
if debug:
    print(cnt2, cnt4, c)
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)
c[2] -= d + d // 2
cnt4 -= d
if debug:
    print('cnt4 = ', cnt4)
    print('c[1] = ', c[1])
d = min(cnt4, c[2])
c[2] -= d
cnt4 -= d
d = min(cnt4, (c[1] + 1) // 2)
c[1] -= d * 2
cnt4 -= d
print('YES' if sum(c[1:]) == 0 else 'NO')

#coding=utf-8

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
    while i < k:
        sum += a[i]
        if a[i] % 2 is 1:
            place += 1
        if a[i] % 4 != 0:
            temp += 1
        i += 1
    if sum == total:
        # print("place=%d   temp=%d" % (place, temp))
        if place != 0 or temp == k:
            print("NO")
            # print("place=%d   temp=%d"%(place,temp))
        else:
            print("YES")
    else:
        if (sum + place) <= total:
            print("YES")
        else:
            print("NO")

test()

import sys

def solve(n, k, groups):
    num_4 = n
    num_2 = 2*n
    num_1 = 0
    remaining_groups = []
    for group in groups:
        if group % 2 == 1:
            if num_4 > 0:
                if group >= 3:
                    group -= 3
                else:
                    group -= 1
                    num_2 += 1
                num_4 -= 1
                if group > 0:
                    remaining_groups.append(group)
            elif num_2 > 0:
                group -= 1
                num_2 -= 1
                if group > 0:
                    remaining_groups.append(group)
            else:
                return 'NO'
        else:
            remaining_groups.append(group)

    remaining_groups = sorted(remaining_groups, reverse=True)
    for group in remaining_groups:
        if group >= 4 and num_4 > 0:
            req_4 = group / 4
            if req_4 > num_4:
                group -= num_4 * 4
                num_4 = 0
            else:
                num_4 -= req_4
                group -= req_4 * 4
        if group >= 2 and num_2 > 0:
            req_2 = group / 2
            if req_2 > num_2:
                group -= num_2 * 2
                num_2 = 0
            else:
                num_2 -= req_2
                group -= req_2 * 2
        if group >= 2 and num_4 > 0:
            req_2 = group / 2
            if req_2 > num_4:
                return 'NO'
            else:
                num_4 -= req_2
                num_1 += 1
                group -= req_2*2
        if group >= 2 and num_1 > 0:
            req_1 = group
            if req_1 > num_1:
                return 'NO'
            else:
                num_1 -= req_1
                group -= req_1

        if group != 0:
            return 'NO'

    return 'YES'

if __name__ == '__main__':
    n, k = map(int, sys.stdin.readline().split())
    groups = map(int, sys.stdin.readline().split())
    print solve(n, k, groups)

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
#print(r4,r22,mid,r2)
if r4 > 0:
	mid -=r4
	r22 -= r4
	if mid < 0:
		mid = 0

if r22 + mid > r2:
	print('NO')
else:
	print('YES')

n, k = 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, 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, raw_input().split(' '))

xs = map(int, raw_input().split(' '))

if sum([x / 2 for x in xs]) + sum([x % 2 for x in xs]) <= 4 * n:
    print "YES"
else:
    print "NO"

n, k = 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(m2 // 3, m // 2)
m, m2 = m - waste * 2, m2 - waste * 2
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())
seat = {4:n, 2:n*2, 1: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:
    d4 = m // 4
    d2 = int(m % 4 > 1)
    d1 = int(m % 2)

    extra4 = sit(4, d4)
    d2 += extra4*2

    extra2 = sit(2, d2)
    aa = sit(4, extra2)
    seat[1] += extra2 - aa
    d1 += aa * 2

    extra1 = sit(1, d1)
    extra1 = sit(2, extra1)
    aa = sit(4, extra1)
    seat[2] += extra1 - aa

    if aa > 0:
        print("NO")
        break
else:
    print("YES")