Problem:


Score : 400 points

Problem Statement

We have a sequence of length N, a = (a_1, a_2, ..., a_N).
Each a_i is a positive integer.

Snuke's objective is to permute the element in a so that the following condition is satisfied:

For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4.

Determine whether Snuke can achieve his objective.

Constraints

2 ≤ N ≤ 10^5

a_i is an integer.

1 ≤ a_i ≤ 10^9

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

If Snuke can achieve his objective, print Yes; otherwise, print No.

Sample Input 1

3
1 10 100

Sample Output 1

Yes

One solution is (1, 100, 10).

Sample Input 2

4
1 2 3 4

Sample Output 2

No

It is impossible to permute a so that the condition is satisfied.

Sample Input 3

3
1 4 1

Sample Output 3

Yes

The condition is already satisfied initially.

Sample Input 4

2
1 1

Sample Output 4

No

Sample Input 5

6
2 7 1 8 2 8

Sample Output 5

Yes



Sample input:
3
1 10 100


Sample output:
Yes

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
# 奇数の横は4の倍数
# 奇数は4が最低でも同数-1以上なければ死
# 2の倍数の横は2か4の倍数
# 2はひとまとめにして横は4でない場合は死
# つまり奇数と同扱い
# 4の倍数の横は何でもよい
# 奇数の数＋2が一つでもあれば一つ追加

odd, num4, num2 = 0, 0, True
for i in range(n):
    if a[i] % 4 == 0:
        num4+=1
    elif a[i] % 2 != 0:
        odd +=1
    elif num2:
        odd +=1
        num2 = False
print('Yes' if odd<=num4+1 else 'No')
exit(0)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
square = 0
even = 0
odd = 0
for a in A:
  if a % 4 == 0:
    square += 1
  elif a % 2 == 0:
    even += 1
  else:
    odd += 1
if square >= odd:
  print('Yes')
elif square == odd - 1 and even == 0:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
input()
A = [int(x) for x in input().split()]

x1 = 0
x2 = 0
x4 = 0
for x in A:
    if x % 4 == 0:
        x4 += 1
    elif x % 2 == 0:
        x2 += 1
    else:
        x1 += 1

if x2 != 0:
    print("Yes" if x4 >= x1 else "No")
else:
    print("Yes" if x4 + 1 >= x1 else "No")

Submission status: Accepted

Solution code:
N = int(input())
a_list = list(map(int, input().split()))

fc = 0
oc = 0
tc = 0
for i in a_list:
    if i % 2 == 0 and i % 4 != 0:
        tc += 1
    elif i % 4 == 0:
        fc += 1
    else:
        oc += 1

if fc >= oc:
    print("Yes")
elif tc == 0 and (oc - fc == 1):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n = int(input())
a = [int(_) for _ in input().split()]
count_four = 0
count_even = 0
count_odd = 0

for ai in a:
    if ai % 4 == 0:
        count_four += 1
    elif ai % 2 == 0:
        count_even += 1
    else:
        count_odd += 1

if count_odd <= 0:
    print('Yes')
elif count_odd == 1:
    if count_four >= 1:
        print('Yes')
    else:
        print('No')
elif count_odd == 2:
    if count_four >= 2:
        print('Yes')
    elif count_four == 1 and count_even == 0:
        print('Yes')
    else:
        print('No')
else:
    if count_even == 0:
        if count_four + 1 >= count_odd:
            print('Yes')
        else:
            print('No')
    else:
        if count_four >= count_odd:
            print('Yes')
        else:
            print('No')

Submission status: Accepted

Solution code:
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N = int(input())
aa = inpl()
a2 = 0
a4 = 0
odd = 0

for a in aa:
	if a%4 == 0:
		a4 += 1
	elif a%2 == 0:
		a2 += 1
	else:
		odd += 1

if a4 >= N//2:
	print('Yes')
elif a4 >= odd:
	print('Yes')
else:
	print('No')

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
a = np.array(list(map(int, input().split())))
n_odd = np.sum(a % 2 == 1)
n_four = np.sum(a % 4 == 0)
if n_odd <= n_four or n_odd - 1 == n_four == N // 2:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
#-*-coding:utf-8-*-

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

    odd_cnt = 0
    even_cnt = 0
    four_cnt = 0
    for i in a_list:
        if i % 2 == 0 and i % 4 != 0:
            even_cnt += 1
        elif i % 4 == 0:
            four_cnt += 1
        else:
            odd_cnt += 1
    if even_cnt == 0:
        if four_cnt >= odd_cnt - 1:
            print('Yes')
        else:
            print('No')
    else:
        if four_cnt >= odd_cnt:
            print('Yes')
        else:
            print('No')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
m=list(map(int,input().split()))
l=filter(lambda x:x%4==0,m)
o=filter(lambda x:x%2==0 and x%4!=0,m)
if n//2<=len(list(l))+len(list(o))//2:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
N = int(input())
a = [int(x) for x in input().split()]

# all 2 then ok 
# if a == [2 for x in range(N)] :
#     print("Yes")
    
# else count numbers divisable by four
#else :
div4 = 0
is2 = 0
    
for i in a :
    if i % 4 == 0 :
        div4 += 1
    elif i % 2 == 0 :
        is2 += 1
   
if len(a) % 2 == 0 :
    if div4 + is2 // 2 >= N / 2 :
        print("Yes")
    else :
        print("No")
else :
    if div4 + is2 // 2 >= (N - 1) / 2 :
        print("Yes")
    else :
        print("No")

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
counta=0
countb=0
for i in a:
  if i%4==0:
    counta+=1
  elif i%2==0:
    countb+=1

if len(a)%2 ==0:
    if counta+countb//2 >= N/2:
    	print('Yes')
    else:
        print('No') 
else:
    if counta+countb//2 >= (N-1)/2:
    	print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))

a, b, c = 0, 0, 0

for e in A:
    if e % 2 == 0:
        if e % 4 == 0:
            c += 1
        else:
            b += 1
    else:
        a += 1

print('Yes' if c - a + (b == 0) >= 0 else 'No')

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))

odds = []
bai4 = []

for i in range(N):
    odds.append(A[i]%2 == 1)
    bai4.append(A[i]%4 == 0)
    
odd = sum(odds)
bi4 = sum(bai4)
bi2 = N - odd - bi4

if odd + bool(bi2) > bi4+1:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

N = int(input())
aN = list(map(int, input().split()))

# okは4の倍数
ok = 0
# ngは4の倍数でもexcpでもない数
ng = 0
# excpはそのグループ内のペアに限って4の倍数になれる数
excp = 0
for i in range(N):
    if aN[i] % 4 == 0:
        ok += 1
    elif (aN[i] + 2) % 4 == 0:
        excp += 1
    else:
        ng += 1

# excpは全部1箇所にまとめてng1つ扱い
if excp > 0:
    ng += 1

# 外をngで囲まれてもいいので、okが1個少なくてもYes
if ok + 1 >= ng:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
o,q,e=[],[],[]
for i in a:
    if i%4==0: q.append(i)
    elif i%2==0: e.append(i)
    else: o.append(i)
s=0
for i in range(n):
    if s==0:
        if len(o):
            o.pop()
            s=4
        elif len(e):
            e.pop()
            s=2
        else:
            q.pop()
    elif s==2:
        if len(e):
            e.pop()
            s=2
        elif len(q):
            q.pop()
            s=0
        else:
            print("No")
            exit()
    else:
        if len(q):
            q.pop()
            s=0
        else:
            print("No")
            exit()
print("Yes")

Submission status: Accepted

Solution code:
N = int(input())

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

b0=0
b2=0
b4=0

for i in range(N):
    if a[i]%4==0:
        b4+=1
    elif a[i]%2==0:
        b2+=1
    else:
        b0+=1
        
#print(b0,b2,b4)        
        
if b0<=b4:
    print("Yes")
elif b0==b4+1 and b0+b4==N:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))

two_num = 0
four_num = 0
another_num = 0

for i in a:
    if i % 4 == 0:
        four_num += 1
    elif i % 2 == 0:
        two_num += 1
    else:
        another_num += 1
if two_num >= 1:
    another_num += 1

if four_num + 1 >= another_num:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
li = [0,0,0]
for nums in A:
  if nums%4==0:
    li[0] += 1
  elif nums%2==0:
    li[1] += 1
  else:
    li[2] += 1
if li[1]==0 and li[2]-li[0]>1:
  print('No')
elif li[1]!=0 and li[2]-li[0]>0:
  print('No')
else:
  print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
L = list(map(int,input().split()))

num_2 = 0
num_4 = 0
odd = 0

for i in L:
    if i % 4 == 0:
        num_4 += 1
    elif i % 2 == 0:
        num_2 += 1
    else:
        odd += 1
        
if num_2 != 0:
    if num_4 >= odd:
        print("Yes")
    else:
        print("No")
        
if num_2 == 0:
    if num_4 >= odd -1:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
N = int(input())
a = [int(i) for i in input().split()]

count = 0
half = 0
for i in range(N):
    if a[i]%4 == 0:
        count += 1
    elif a[i]%2 == 0:
        half +=1

if count >= N//2:
    print("Yes")
elif count >= (N//2 - half//2):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N = int(input())
A = [0, 0, 0]
b = map(int, input().split())
for a in b:
    if a % 4 == 0:
        A[2] += 1
    elif a % 2 == 0:
        A[1] += 1
    else:
        A[0] += 1

# print(A)

for i in range(3):
    if A[i] != 0:
        s = i
        A[i] -= 1
        break


def judge(A, s, N):
    for i in range(N - 1):
        if s == 0:  # 割り切れない場合
            if A[2] != 0:
                A[2] -= 1
                s = 2
            else:
                return "No"
        elif s == 1:
            if A[1] != 0:
                A[1] -= 1
                s = 1
            elif A[2] != 0:
                A[2] -= 1
                s = 2
            else:
                return "No"
        else:
            if A[0] != 0:
                A[0] -= 1
                s = 0
            elif A[1] != 0:
                A[1] -= 1
                s = 1
            elif A[2] != 0:
                A[2] -= 1
                s = 2
            else:
                return "No"
    return "Yes"


print(judge(A, s, N))

Submission status: Accepted

Solution code:
N = int(input())
A = [int(_) for _ in input().split()]

c1 = 0
c2 = 0
c4 = 0
for a in A:
    if a % 2 == 1:
        c1 += 1
    elif a % 4 == 0:
        c4 += 1
    else:
        c2 += 1

if c1 > c4 + 1:
    print("No")
elif c1 == c4 + 1:
    if c2 == 0:
        print("Yes")
    else:
        print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
# input
N = int(input())
a = list(map(int, input().split()))

# 4の倍数, 4の倍数でない偶数, 奇数の数
i, j, k = 0, 0, 0

for n in range(N):
    if a[n] % 4 == 0:
        i += 1
    elif a[n] % 2 == 0:
        j += 1
    else:
        k += 1

if k >= i + 2:
    print('No')
elif k == i + 1 and j >= 1:
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
src = list(map(int,input().split()))
odd = two = four = 0
for a in src:
    if a%2: odd += 1
    elif a%4==0: four += 1
    else: two += 1
if two:
    print('Yes' if odd <= four else 'No')
else:
    print('Yes' if odd <= four+1 else 'No')

Submission status: Accepted

Solution code:
N = (input())
a = list(map(int, input().split()))
f_count = 0
t_count = 0
for i in range(len(a)):
    if a[i]%4 == 0:
        f_count += 1
    elif a[i]%2 == 0:
        t_count += 1

if t_count < 2:
    if (2 * f_count  >= len(a)-1):
        print('Yes')
    else:
        print('No')
else:
    if (2 * f_count  >= len(a) - t_count):
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
mod2 = [i for i in a if i % 2 == 0]
mod4 = [i for i in mod2 if i % 4 == 0]
m2len = len(mod2)
m4len = len(mod4)
if (N-m2len+m4len+(1 if (m2len-m4len) > 0 else 0))//2 <= m4len:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
j2,j4=0,0
for x in a:
    if x%4==0:
        j4+=1
    elif x%2==0:
        j2+=1
if n%2==0:
    print("Yes" if j2+2*j4>=n else "No")
else:
    print("Yes" if j2+2*j4>=n-1 else "No")

Submission status: Accepted

Solution code:
n = int(input())

arr = map(int,raw_input().split())

dic = [0,0,0]

for i in arr:
	if i%4==0:
		dic[2] += 1
	elif i%2 == 0:
		dic[1] += 1
	else :
		dic[0] += 1


if dic[2]+1 <= dic[0] and 0 < dic[1]:
	print 'No'
elif dic[2]+1 == dic[0] and dic[1] == 0:
	print 'Yes'

elif dic[2] >= dic[0] :
	print 'Yes'

else :
	print 'No'

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

n = int(input())
A = list(map(int, input().split()))

count = 0
flag = False
for a in A:
    if a % 4 == 0:
        count += 2
        flag = True
    elif a % 2 == 0:
        count += 1

if count >= n:
    print('Yes')
elif n % 2 == 1 and flag:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))

def div_two(n):
    tmp = n/2
    if tmp%1 != 0:
        return 0
    if (tmp/2)%1 != 0:
        return 1
    return 2

tmp = [0]*3
for i in map(div_two, a):
    tmp[i] += 1

flag = True

if tmp[0] > tmp[2]:
    if tmp[1] == 0:
        if tmp[0] != tmp[2]+1:
            flag = False
    else:
        flag = False

if tmp[1]:
    if tmp[1] == 1:
        flag == False

print("Yes" if flag else "No")

Submission status: Accepted

Solution code:
N = int(input())
input_list = [int(i) for i in input().split()]
four_count = 0
two_count = 0

for i in input_list:
    if i % 4 == 0:
        four_count += 1
    elif i % 2 == 0:
        two_count += 1

others_count = N - four_count - two_count

if two_count:
    if others_count <= four_count:
        print("Yes")
    else:
        print("No")
else:
    if others_count <= four_count + 1:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

n = int(stdin.readline())
a = list(map(int, stdin.readline().split()))

n_2 = n
n_4 = n // 2
a_2 = 0
a_4 = 0

for i in a:
    if i % 4 == 0:
        a_4 += 1
    elif i % 2 == 0:
        a_2 += 1

if a_4 >= n_4 or a_2 >= n_2 or a_2 >= (n-a_4*2):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
l = len(a)
fs = 0
ts = 0
for i in a:
    if(i % 4 == 0):
        fs += 1
    elif(i % 2 == 0):
        ts += 1
if(ts > 1):
    l = l - ts + 1
if(l <= fs*2 + 1):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
def m():
    N = int(input())
    a = list(map(int, input().split()))
    fours = []
    twes = []
    others = []
    for i in range(N):
        if a[i] % 4 == 0:
            fours.append(a[i])
            continue

        if a[i] % 2 == 0:
            twes.append(a[i])
            continue
        others.append(a[i])

    len4s = len(fours)
    len2s = len(twes)
    others = len(others)
    if len2s:
        others += 1
    if others <= len4s + 1:
        return 'Yes'
    return 'No'


print(m())

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
c1, c2, c4 = 0, 0, 0
for b in a:
    if b%4 == 0:
        c4 += 1
    elif b%2 == 0:
        c2 += 1
    else:
        c1 += 1
if c4 >= c1 or (c1-c4 <= 1 and c2 == 0):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
cnt4 = 0
cnt2 = 0
cnt = 0
for i in range(n):
    if a[i] % 4 == 0:
        cnt4 += 1
    elif a[i] % 2 == 0:
        cnt2 += 1
    else:
        cnt += 1

if cnt2 == 0:
    if cnt <= cnt4 + 1:
        print("Yes")
    else:
        print("No")
else:
    if cnt <= cnt4:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))

zero = 0
two = 0
odd = 0

for i in range(len(a)):
    if a[i] % 4 == 1 or a[i] % 4 == 3:
        odd = odd + 1
    elif a[i] % 4 == 0:
        zero = zero + 1
    else:
        two = two + 1
        
if zero >= odd -1 and two == 0:
    print('Yes')
elif zero >= odd:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
def c_4adjacent(N, A):  # 解説通りに実装
    # 4の倍数、4の倍数でない2の倍数、奇数の数
    num_4, num_2, num_other = 0, 0, 0
    for a in A:
        if a % 4 == 0:
            num_4 += 1
        elif a % 2 == 0:
            num_2 += 1
        else:
            num_other += 1

    if num_2 == 0:
        ans = 'Yes' if num_other <= num_4 + 1 else 'No'
    else:
        ans = 'Yes' if num_other <= num_4 else 'No'
    return ans

N = int(input())
A = [int(i) for i in input().split()] 
print(c_4adjacent(N, A))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
p, q, r = 0, 0, 0

for a in A:
    if a % 4 == 0:
        p += 1
    elif a % 4 == 2:
        q = 1
    else:
        r += 1

print("Yes" if q + r <= p + 1 else "No")

Submission status: Accepted

Solution code:
def judge(one, two, four):
	if two == 0 and one - four == 1: return 'Yes'
	elif one > four: return 'No'
	else: return 'Yes'	

N = int(raw_input())
a = map(int, raw_input().split())
one = 0
two = 0
four = 0

for i in range(0, N):
	if a[i] % 4 == 0: four = four + 1
	elif a[i] % 2 == 0: two = two + 1
	else: one = one + 1

print judge(one, two, four)

Submission status: Accepted

Solution code:
input();*a,=map(int,input().split());b=c=0
for x in a:
    if x%4==0:b+=1
    elif -~x%2:c+=1
print(['No','Yes'][len(a)-b-c-2+(c>0)<b])

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split(' ')))

even = [i for i in a if i % 2 == 0 and i % 4 != 0]
odd = [i for i in a if i % 2 != 0]
by4 = [i for i in a if i % 4 == 0]
if len(odd) <= len(by4):
    print('Yes')
elif len(odd) - len(by4) == 1:
    if len(even) == 0:
        print('Yes')
    else: print('No')
else:
    print('No')

Submission status: Accepted

Solution code:
n=int(input())
t=list(map(int,input().split()))
a=0
b=0
c=0
for i in range(n):
    if t[i]%4==0:#4の倍数
        a+=1
    elif t[i]%2==0 and t[i]%4!=0:#2の倍数かつ4の倍数でない
        b+=1
    else:
        c+=1
if b==0:
    if c<=a+1:
        print("Yes")
    else:
        print("No")
elif b!=0:
    if c<=a:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))

div4, div2 = 0, 0
for i in range(n):
    if a[i]%4 == 0:
        div4 += 1
    elif a[i]%2 == 0:
        div2 += 1

if div4 >= n//2:
    print("Yes")
else:
    if div2 >= n - div4 * 2:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
N = int(input())
src = list(map(int,input().split()))

one = sum([1 for a in src if a%2])
four = sum([1 for a in src if a%4==0])
two = N - one - four

print('Yes' if one <= four or (one == four+1 and two==0) else 'No')

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
odd,n4 = 0,0
for i in range(N):
    if A[i]%2 == 1:
        odd += 1
    else:
        if A[i]%4 == 0:
            n4 += 1
if odd+n4==N and odd-n4==1:
    print("Yes")
else:
    print("Yes" if n4 >= odd else "No")

Submission status: Accepted

Solution code:
N = int(input())
l = list(map(int, input().split()))
a, b, c = 0, 0, 0

for i in l:
    if i % 4 == 0:
        c += 1
    elif i % 2 == 0:
        b += 1
    else:
        a += 1

if b >= 1:
    if c >= a:
        print("Yes")
    else:
        print("No")
else:
    if c+1 >= a:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
N = int(input())
l = list(map(int, input().split()))
a, b, c = 0, 0, 0

for i in l:
    if i % 4 == 0:
        c += 1
    elif i % 2 == 0:
        b += 1
    elif not i % 2 == 0:
        a += 1

if b >= 1:
    if c >= a:
        print("Yes")
    else:
        print("No")
else:
    if c+1 >= a:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int, input().split()))
a, b, c = 0, 0, 0

for i in l:
  if i % 4 == 0:
    c += 1
  elif i % 2 == 0:
    b += 1
  elif not i % 2 == 0:
    a += 1

if b >= 1:
  if c >= a:
    print('Yes')
  else:
    print('No')
else:
  if c+1 >= a:
    print('Yes')
  else:
    print('No')

Submission status: Accepted

Solution code:
N=int(input())
s,t,u=0,0,0
for i in list(map(int,input().split())):
    if i%4==0:
        s+=1
    elif i%2==0:
        t+=1
    else:
        u+=1
if u-s<=1 and (t==0 or u-s<1):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split(" ")))
b1 = 0
b2 = 0
b4 = 0
for i in range(len(a)):
    if a[i]%4 == 0:
        b4 += 1
    elif a[i]%2==0:
      b2 += 1
    else:
        b1 +=1
b1 += b2 % 2
if b1==1:
  if b4>=1:
    print("Yes")
  else:
    print("No")
elif b4 >= b1 - 1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n = int(input())
a, b = 0, 0
for x in input().split():
    x = int(x)
    if x % 4 == 0: a += 1
    elif x % 2 == 0: b += 1
if a * 2 + b // 2 * 2 + 1 >= n: print('Yes')
else: print('No')

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
bai4 = 0
bai2 = 0
kisuu = 0
for i in a:
    if i%4 == 0:
        bai4 += 1
    elif i%2 == 0:
        bai2 += 1
    else:
        kisuu += 1
if N%2 == 0:
    if kisuu <= bai4:
        print("Yes")
    else:
        print("No")
else:
    if min(kisuu,N//2) <= bai4:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
N = int(input())
n = list(map(int, input().split()))

fourEven = 0
odd = 0
for num in n:
    if num % 4 == 0:
        fourEven += 1
    elif num % 2 == 1:
        odd += 1

if len(n) // 2 <= fourEven or odd <= fourEven:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N = int(input())
n = list(map(int, input().split()))

fourEven = 0
odd = 0
otherEven = 0
for num in n:
    if num % 4 == 0:
        fourEven += 1
    elif num % 2 == 1:
        odd += 1
    else:
        otherEven += 1

# print(len(n) == fourEven + otherEven + otherEven)

if len(n) // 2 <= fourEven:
    print('Yes')
elif odd <= fourEven:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N = int(input())
n = list(map(int, input().split()))

fourEven = 0
odd = 0
otherEven = 0
for num in n:
    if num % 4 == 0:
        fourEven += 1
    elif num % 2 == 1:
        odd += 1
    else:
        otherEven += 1

# print(len(n) == fourEven + otherEven + otherEven)

if len(n) // 2 <= fourEven:
    print('Yes')
elif odd <= fourEven and otherEven >= 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
n = int(input())
x = [int(i) for i in input().split()]
a,b,c = 0,0,0
for i in x:
	if i%4==0: a += 1
	elif i%2==0: b += 1
	else: c += 1
if b != 0:
	if a>=c: print("Yes")
	else: print("No")
else:
	if a>=c-1: print("Yes")
	else: print("No")

Submission status: Accepted

Solution code:
n = int(input())
num = list(map(int,input().split()))
c2,c4,ce=0,0,0
for i in range(n):
  if num[i]%4 ==0:
    c4 += 1
  elif num[i]%2 ==0:
    c2 = 1
  else:
    ce +=1
if ce ==0:
  print('Yes')
elif c2 + ce <= c4 +1:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
# coding=utf-8

n = int(input())
n4 = 0
n2 = 0
n1 = 0
for x in input().split(" "):
    x = int(x)
    if x%4==0:
        n4 += 1
    elif x%2==0:
        n2 += 1
    else:
        n1 += 1

if n2>1:
    n2 = 1

if n1+n2-1<=n4:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n = int(input())
lis = []
cou1 = 0
cou2 = 0
cou4 = 0
li = list(map(int,input().split()))
for i in range(n):
    if li[i] % 2 == 0:
        if li[i] % 4 == 0:
            cou4 += 1
        else:
            cou2 += 1
    else:
        cou1 += 1
if cou2 >= 1:
    if cou1 <= cou4:
        print("Yes")
    else:
        print("No")
else:
    if cou1 <= cou4 + 1:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
N=int(input())
A=[int(x) for x in input().split()]

a4=0
a1=0
for i in range(N):
  if A[i]%4==0:
    a4+=1
  elif A[i]%2==1:
    a1+=1

if (a1+a4)==N:
  if a4+1>=a1:
    print("Yes")
  else:
    print("No")
else:
  if a4>=a1:
    print("Yes")
  else:
    print("No")

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
b = [int(ai)%4 for ai in input().split()]

c = Counter(b)
n1 = c[1] + c[3]
n2 = c[2]
n4 = c[0]

if (n2 == 0 or n1 <= n4) and (n2 != 0 or n1 <= n4+1):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N = int(input())
a = [int(i) for i in input().split()]
P=0
Q=0
R=0
for i in range(N):
    if a[i]%4==0:
        P+=1
    elif a[i]%4==2:
        Q+=1
    else:
        R+=1
if (Q==0 and R>P+1) or (Q!=0 and R>P):
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
list1 = list(map(int,input().split()))		
no1 = 0
no2 = 0
no3 = 0
for z in range(N):
  if list1[z] % 4 == 0:
    no1 += 1
  elif list1[z] % 2 == 0:
    no2 += 1
  else:
    no3 += 1


if no2 >= 1:
  no3 += 1

if (no1 + 1) >= no3:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
import sys
n=int(input())
a=map(int,input().split())
num=[0,0,0]
for i in a:
  if(i%4==0):num[0]+=1
  elif(i%2==0):num[1]+=1
  else:num[2]+=1
if(num[2]==0):print("Yes")
elif(num[2]==1):
  if(num[0]!=0):print("Yes")
  else:print("No")
else:
  if(num[2]>num[0]+1):print("No")
  else:
    if(num[2]==num[0]+1):
      if(num[1]==0):print("Yes")
      else:print("No")
    elif(num[2]==num[0]):print("Yes")
    else:print("No")

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
b_4=0
b_2=0
b_i=0
for i in a:
    if i%4==0:
        b_4+=1
    elif i%2==0:
        b_2+=1
    else:
        b_i+=1
if b_2==0:
    if b_i<=b_4+1:
        print("Yes")
    else:
        print("No")
else:
    if b_i<=b_4:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
x=[0,0,0]

for i in a:
  if i % 4==0:
    x[2]+=1
  elif i % 2==0:
    x[1]+=1
  else:
    x[0]+=1

if (x[1]==0 and x[2] >= x[0]-1 and x[2]>0) or x[2] >= x[0] or x[0]==0:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
n = int(input())
A = [int(i) for i in input().split()]


cnt2 = 0
cnt4 = 0

for i in range(n):
    if A[i] % 4 == 0:
        cnt4 += 1
    elif A[i] % 2 == 0:
        cnt2 += 1

        
if cnt4*2 + cnt2 >= n or (cnt4 * 2 + 1) >= n:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N = int(input())
a = map(int, input().split())

num_d = {}

for num in a:
    num_d.setdefault(num, 0)
    num_d[num] += 1

quad = 0
doub = 0
odd = 0
for k, v in num_d.items():
    if k % 4 == 0:
        quad += v
    elif k % 4 != 0 and k % 2 == 0:
        doub += v
    else:
        odd += v

if quad >= (odd + doub) - 1:
    print("Yes")
elif doub % 2 == 0 and quad >= odd - 1:
    print("Yes")
elif doub % 2 != 0 and quad >= odd - 1 and (quad - odd) >= 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n = int(input())

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

b = [0,0,0,0]

for x in ls:
    if x % 4 == 0:
        b[3] += 1
    elif x % 2 == 0:
        b[1] += 1
    else:
        b[0] += 1

if b[1] == 0:
    if b[0] <= b[3]+1:
        print('Yes')
    else:
        print('No')
else:
    if b[0] <= b[3]:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
b_0=0
b_2=0
b_4=0
for i in a:
    if i%4==0:
        b_4+=1
    elif i%2==0:
        b_2+=1
    else:
        b_0+=1
if b_2==0:
    if b_0<=b_4+1:
        print("Yes")
    else:
        print("No")
else:
    if b_0<=b_4:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
b_2=0
b_4=0
b_0=0
for i in a:
    if i%4==0:
        b_4+=1
    elif i%2==0:
        b_2+=1
    else:
        b_0+=1
if b_2==0:
    if b_0<=b_4+1:
        print("Yes")
    else:
        print("No")
else:
    if b_0<=b_4:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
num2=0
num4=0
num0=0
for i in a:
    if i%4==0:
        num4+=1
    elif i%2==0:
        num2+=1
    else:
        num0+=1
if num2==0:
    if num0<=num4+1:
        print("Yes")
    else:
        print("No")
else:
    if num0<=num4:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())

def foo(a):
    d, m = divmod(a, 2)
    if m:
        return 0
    elif d%2 == 0:
        return 2
    else:
        return 1

cnt = Counter(map(foo, (map(int, input().split()))))

if cnt[2] >= cnt[0] or (cnt[0] == cnt[2] +1 and cnt[1] == 0):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N = int(input())
P = list(map(int,input().split()))
a, b, c = 0, 0, 0
for i in range(N):
    if P[i] % 4 == 0:
        a += 1
    elif P[i] % 2 == 0:
        b += 1
    else:
        c += 1
if b % 2 == 1:
    b -= 1
    c += 1
if 2 * a >= (a + c - 1):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
#!/usr/bin/python

import sys

N = int(sys.stdin.readline())
a = [int(w) for w in sys.stdin.readline().split()]
if len(a) != N: raise

n4 = len([n for n in a if n % 4 == 0])
n2 = len([n for n in a if n % 2 == 0 and n % 4 != 0])
n1 = len([n for n in a if n % 2 != 0])

if n2 > 0: n1 += 1
answer = (n1 <= n4 + 1)

print("Yes" if answer else "No")

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split(" ")))

zero = 0
two = 0
four = 0

for i in a:
	if i % 2 == 0:
		if i % 4 == 0:
			four += 1
		else:
			two += 1
	else:
		zero += 1

four -= zero
if four >= 0 or (two == 0 and four == (-1)):
	print("Yes")
else:
	print("No")

Submission status: Accepted

Solution code:

input()
xs = map(int, input().split())

n1, n2, n4 = 0, 0, 0

for x in xs:
    if x % 4 == 0:
        n4 += 1
    elif x % 2 == 0:
        n2 += 1
    else:
        n1 += 1

if n2 == 0:
    print("Yes" if n4 >= n1 - 1 else "No")
else:
    print("Yes" if n4 >= n1 else "No")

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))

num2 = 0
num4 = 0
numo = 0

for a in A:
    if a % 4 == 0:
        num4 += 1
    elif a % 2 == 0:
        num2 += 1
    else:
        numo += 1

if num2 == 0:
    if num4 + 1 >= numo:
        print("Yes")
    else:
        print("No")
else:
    if num4 >= numo:
        print("Yes")
    else:
        print("No")