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())
l=list(map(int,input().split()))
x=0
y=0
c=0
for i in range(n):
    if(l[i]%4==0):
        x+=1
    elif(l[i]%2==0):
        y+=1
    else:
        c+=1
if(n%2==0):
    if(x>=c):
        print("Yes")
    else:
        print('No')
else:
    if(x>=(c-1)):
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
N=int(input())
A = list(map(int, input().split()))
b4 = 0
b2 = 0
other = 0
for a in A:
    if a%4==0:
        b4 += 1
    elif a%2 == 0:
        b2 += 1
    else:
        other += 1

if N % 2 == 1:
    if b4 < other - 1:
        print("No")
    else:
        print("Yes")
else:
    if b4 < other:
        print("No")
    else:
        print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
a = [int(x) for x in input().split()]
cnt4 = 0
cnt2 = 0
for x in a:
    if x % 4 == 0:
        cnt4 += 1
        continue
    if x % 2 == 0:
        cnt2 += 1
cnt2 = cnt2//2*2
if N-cnt2 > 2*cnt4+1:
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
#!/usr/bin/env python

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

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

ok = True
if n2 == 0:
    if n4 >= n//2:
        ok = True
    else:
        ok = False
else:
    n1 = n-n2-n4
    n1 += 1
    nn = n1+n4
    if n4 >= nn//2:
        ok = True
    else:
        ok = False

if ok: 
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
input();a,b,c,d,r=list(map(int,input().split())),0,0,0,'NYoe s'
for i in a:
  if i%2!=0: b+=1
  elif i%4==0: c+=1
  else: d+=1
print([r[b<=c::2],r[b<=c+1::2]][d==0])

Submission status: Accepted

Solution code:
input();a,b,c,d,r=list(map(int,input().split())),0,0,0,'NYoe s'
for i in a:
  if i%2!=0: b+=1
  elif i%4==0: c+=1
  else: d+=1
print([r[b<=c::2],r[b<=c+1::2]][not d])

Submission status: Accepted

Solution code:
input();a,b1,b2,b4,r=list(map(int,input().split())),0,0,0,'NYoe s'
for i in a:
  if i%2!=0: b1+=1
  elif i%4==0: b4+=1
  else: b2+=1
print([r[b1<=b4::2],r[b1<=b4+1::2]][not b2])

Submission status: Accepted

Solution code:
input();a,b1,b2,b4=list(map(int,input().split())),0,0,0
for i in a:
  if i%2!=0: b1+=1
  elif i%4==0: b4+=1
  else: b2+=1
print(['NYoe s'[b1<=b4::2],'NYoe s'[b1<=b4+1::2]][not b2])

Submission status: Accepted

Solution code:
input();a,b1,b2,b4=list(map(int,input().split())),0,0,0
for i in a:
  if i%2!=0: b1+=1
  elif i%4==0: b4+=1
  else: b2+=1
print('Yes'if b1<=b4 else'No'if b2 else'Yes'if b1<=b4+1 else'No')

Submission status: Accepted

Solution code:
input();a=list(map(int,input().split()))
b1,b2,b4=0,0,0
for i in a:
  if i%2!=0: b1+=1
  elif i%4==0: b4+=1
  else: b2+=1
print('Yes' if b1<=b4 else 'No' if b2 else 'Yes' if b1<=b4+1 else 'No')

Submission status: Accepted

Solution code:
input();a=list(map(int,input().split()))
b1,b2,b4=0,0,0
for i in a:
  if i%2!=0: b1+=1
  elif i%4==0: b4+=1
  elif i%2==0: b2+=1
print('Yes' if b1<=b4 else 'No' if b2 else 'Yes' if b1<=b4+1 else 'No')

Submission status: Accepted

Solution code:
input();a=list(map(int,input().split()))
b1,b2,b4=[],[],[];ans=''
for i in a:
  if i%2!=0:
    b1.append(i)
  elif i%4==0:
    b4.append(i)
  elif i%2==0:
    b2.append(i)
if b2:
  if len(b1)<=len(b4):
    ans='Yes'
  else:
    ans='No'
else:
  if len(b1)<=len(b4)+1:
    ans='Yes'
  else:
    ans='No'
print(ans)

Submission status: Accepted

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

cnt2 = 0
cnt4 = 0
cntodd = 0
for i in a:
    if i % 4 == 0:
        cnt4 += 1
    elif i % 2 == 0:
        cnt2 += 1
    else:
        cntodd += 1

if cnt2 == 0 and cnt4 + 1 >= cntodd:
    ans = 'Yes'
elif cnt4 >= cntodd:
    ans = 'Yes'
else:
    ans = 'No'
print(ans)

Submission status: Accepted

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

for i in c:
    if i%2 != 0:
        a += 1
    if i%2 == 0 and i%4 != 0:
        a2 += 1
    if i%4 == 0:
        a4 += 1
if a == 0 :
    print('Yes')
if a > 0 and a2 == 0:
    if a <= a4 +1 :
        print('Yes')
    else:
        print('No')
if a > 0 and a2 > 0:
    if a <= a4 :
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().rstrip().split(" ")))
counter = [0,0,0]
for i in a:
    if i % 4 == 0:
        counter[2] += 1
    elif i % 2 == 0:
        counter[1] += 1
    else:
        counter[0] += 1
counter[0] += min(1,counter[1])

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

Submission status: Accepted

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

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

if y%2+z-1 <= x: print("Yes")
else: print("No")

Submission status: Accepted

Solution code:
bai4_count=0
bai2_count=0
no = 0

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

for i in range(N):
    if a[i]%4==0:
        bai4_count+=1
    elif a[i]%2==0:
        bai2_count+=1
    else:
        no+=1
ans = False
if bai2_count>0:
    if bai4_count >= no:
        ans=True
    else:
        ans=False
else:
    if bai4_count+1 >= no:
        ans=True
    else:
        ans=False

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

Submission status: Accepted

Solution code:
import sys

n=int(input())
a=[int(x) for x in input().rstrip().split()]

even=0
odd=0
num4=0
for i in a:
  if i%4==0:
    num4+=1
    continue

  elif i%2==0:
    even+=1
  else:
    odd+=1


if odd<=num4:
  print("Yes")
elif odd-1==num4 and even==0:
  print("Yes")
elif odd==0 and 2<=even:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
import math
N = int(input())
A = list(map(int, input().split()))
count = []
for i in A:
    if i%4 == 0:
        count.append("4")
    elif i%2 == 0:
        count.append("2")
    else:
        count.append("1")
B1 = count.count("4")
B2 = count.count("1")
if count.count("2") == 0:
    print("Yes" if B1+1 >= B2 else "No")
else:
    print("Yes" if B1 >= B2 else "No")

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    inlis = list(map(int, input().split()))

    num2 = 0
    num4 = 0

    for i in range(n):
        a = inlis[i]
        if a % 4 == 0:
            num4 += 1
        elif a % 2 == 0:
            num2 += 1
    if n <= 3:
        if num4 >=1:
            print('Yes')
        elif num2 == n:
            print('Yes')
        else:
            print('No')
    else:
        if num2 + (2*num4) >= n:
            print("Yes")
        else:
            if n % 2 != 0 and num2 + (2*num4 +1) >= n:
                print('Yes')
            else:
                print('No')





if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
##
N = int(input())
N_List = list(map(int,input().split()))
Four_List = [i for i in N_List if i % 4 == 0]
Two_List = [i for i in N_List if i % 2 == 0]
if len(Two_List)-len(Four_List) > 0:
    N = N - (len(Two_List) - len(Four_List)) + 1

if N // 2 <= len(Four_List):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n = int(input())
a_ls = list(map(int, input().split()))
n_4k = 0
n_2k = 0
n_odd = 0
for i in range(n):
    if a_ls[i] % 4 ==0:
        n_4k += 1
    elif a_ls[i] % 2 ==0:
        n_2k += 1
    else:
        n_odd += 1
res = 'No'
if n_odd == 0:
    res = 'Yes'
else:
    if n_2k > 0:
        if n_odd <= n_4k:
            res = 'Yes'
    else:
        if n_odd <= n_4k+1:
            res = 'Yes'
print(res)

Submission status: Accepted

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

m_2_but_4 = 0
m_4 = 0
m_none = 0
for i in range(len(A)):
  if A[i] % 4 == 0:
    m_4 += 1
  elif A[i] % 2 == 0:
    m_2_but_4 += 1
  else:
    m_none += 1

if m_2_but_4:
  print("Yes") if m_4 >= m_none else print("No")
else:
  print("Yes") if m_4 + 1 >= m_none else print("No")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
N = int(input())
A = list(map(int,input().split()))
l = list()
ll = list()
for i in range(len(A)):
  if A[i]%4 == 0:
    l.append(A[i])
  if A[i]%2 == 0:
    ll.append(A[i])
four = len(l)
two = len(ll)-four
zero = N-two
a = math.floor(N/2)
if a <= four:
  print("Yes")
elif 2*a-two <= 2*four:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
import math
N = int(input())
A = list(map(int,input().split()))
l = list()
ll = list()
for i in range(len(A)):
  if A[i]%4 == 0:
    l.append(A[i])
  if A[i]%2 == 0:
    ll.append(A[i])
four = len(l)
two = len(ll)-four
zero = N-two
a = math.floor(N/2)
if a <= four:
  print("Yes")
elif a-two/2 <= four:
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

four = 0
two = 0

for i in range(len(A)):
  if A[i]%4 == 0:
    four += 1
  if A[i]%2 == 0:
    two += 1
n = math.floor(N/2)
two -= four
x = (n - four) * 2

# print(four, two, n, x)
if four >= n:
  print("Yes")
elif two >= x:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
A = readInts()
four = 0
two = 0
for i in range(n):
    if A[i]%4 == 0:
        four += 1
    elif A[i]%2 == 0:
        two += 1
print('Yes' if four + two//2 >= n//2 else 'No')

Submission status: Accepted

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

cnt4 = 0
cnt2 = 0
for i in a:
    if i % 4 == 0:
        cnt4 += 1
    elif i % 2 == 0:
        cnt2 += 1

if cnt4 >= n//2:
    print('Yes')
elif 2 * cnt4 >= n - cnt2:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
k = 0
g = 0
for i in a:
  if(i%4 == 0):g+=1
  if(i%2 == 1):k+=1
#print(g,k)
if(g>=k or (g+1>=k and g+k==n)):print("Yes")
else:print("No")

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
bai4 = []
bai2 = []
bai_ = []
for ai in a:
    if ai % 4 == 0:
        bai4.append(ai)
    elif ai % 2 == 0:
        bai2.append(ai)
    else:
        bai_.append(ai)

len_bai_ = len(bai_)
len_bai2 = len(bai2)
len_bai4 = len(bai4)


if len_bai_ > len_bai4:
    if len_bai_ == len_bai4 + 1 and n == len_bai_ + len_bai4:
        print("Yes")
    else:
        print("No")
else:
    print("Yes")

Submission status: Accepted

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

n4,n2=0,0
for i in range(N):
  if a[i] % 4 == 0:n4 += 1
  elif a[i] % 2 == 0:n2 += 1
    
if n4 >= N//2:print('Yes')
elif n4*2 + n2 >= N:print('Yes')
else:print('No')

Submission status: Accepted

Solution code:

import collections
n,ais,cc = int(raw_input()), map(int, raw_input().split()), collections.Counter()
for ai in ais:
	if ai % 4 == 0: cc[0] += 1
	elif ai % 2 == 0: cc[1] += 1
	else: cc[2] += 1

p,h = 0, [[2,1,0],[1],[0]] 
while(n):
	for u in h[p] + [-1]:
		if u == -1: 
			p =-1
			break
		if cc[u] > 0:
			p = u
			cc[u] -=1
			n -=1
			break
	if p == -1: break

print 'Yes' if n == 0 else 'No'

Submission status: Accepted

Solution code:

import collections
n,ais = int(raw_input()), map(int, raw_input().split())
cc = collections.Counter()
for ai in ais:
	if ai % 4 == 0: cc[0] += 1
	elif ai % 2 == 0: cc[1] += 1
	else: cc[2] += 1

q,h = collections.deque([0]), [[2,1,0],[1],[0]] 
while(n):
	b = False
	for u in h[q[-1]] + [-1]:
		if u == -1: b = True
		if cc[u] > 0:
			q.append(u)
			
			cc[u] -=1
			n -=1
			break
	if b: break

print 'Yes' if n == 0 else 'No'

Submission status: Accepted

Solution code:

import collections
n,ais = int(raw_input()), map(int, raw_input().split())
cc = collections.Counter()
for ai in ais:
	if ai % 4 == 0: cc[0] += 1
	elif ai % 2 == 0: cc[1] += 1
	else: cc[2] += 1

q,h = collections.deque([0]), [[2,1,0],[1],[0]] 
while(n):
	b = False
	for u in h[q[-1]] + [-1]:
		if u == -1: b = True
		if cc[u] > 0:
			q.append(u)
			q.popleft()
			cc[u] -=1
			n -=1
			break
	if b: break

print 'Yes' if n == 0 else 'No'

Submission status: Accepted

Solution code:
n,ais = int(raw_input()), map(int, raw_input().split())
import collections
cc = collections.Counter()
for ai in ais:
	if ai % 4 == 0: cc[0] += 1
	elif ai % 2 == 0: cc[1] += 1
	else: cc[2] += 1

q = collections.deque()
while(n):
	if len(q) == 0:
		for u in range(3)[::-1]:
			if cc[u] > 0:
				q.append(u)
				cc[u]-=1
				n -=1
				break
		if len(q) == 0: break
	else:
		if q[-1] == 0:
			if cc[2]:
				q.append(2)
				cc[2]-=1
				n-=1
			elif cc[1]:
				q.append(1)
				cc[1]-=1
				n-=1
			elif cc[0]:
				q.append(0)
				cc[0]-=1
				n-=1
			else:
				break
		elif q[-1] == 2:
			if cc[0] == 0:
				break
			else:
				q.append(0)
				cc[0]-=1
				n-=1
		elif q[-1] == 1:
			if cc[1] > 0:
				q.append(1)
				cc[1]-=1
				n-=1
			else:
				break

print 'Yes' if n == 0 else 'No'

Submission status: Accepted

Solution code:

n,ais = int(raw_input()), map(int, raw_input().split())
import collections
cc = collections.Counter()
for ai in ais:
	if ai % 4 == 0: cc[0] += 1
	elif ai % 2 == 0: cc[1] += 1
	else: cc[2] += 1

q = collections.deque()
while(n):
	if len(q) == 0:
		for u in range(3)[::-1]:
			if cc[u] > 0:
				q.append(u)
				cc[u]-=1
				n -=1
				break
		if len(q) == 0: break
	else:
		if q[-1] == 0:
			if cc[2]:
				q.append(2)
				cc[2]-=1
				n-=1
			elif cc[1]:
				q.append(1)
				cc[1]-=1
				n-=1
			elif cc[0]:
				q.append(0)
				cc[0]-=1
				n-=1
			else:
				break
		elif q[-1] == 2:
			if cc[0] == 0:
				break
			else:
				q.append(0)
				cc[0]-=1
				n-=1
		elif q[-1] == 1:
			if cc[1] > 0:
				q.append(1)
				cc[1]-=1
				n-=1
			else:
				break

print 'Yes' if n == 0 else 'No'

Submission status: Accepted

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

cnt = 0
for a in a_lst:
  if a % 4 == 0:
    cnt += 2
  elif a % 2 == 0:
    cnt += 1
  else:
    pass

if cnt // 2 >= n // 2:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int,input().split()))
l=[0]*N
for i in range(N):
    if a[i]%4:
        if a[i]%2:l[i]=1
        else:l[i]=2
    else:l[i]=4
print('Yes'if l.count(1)+(1 if l.count(2)else 0)<=1+l.count(4)else'No')

Submission status: Accepted

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

x,y,z = 0,0,0
for i in a:
  if i%4 == 0: x += 1
  elif i%2 == 0: y += 1
  else: z += 1
    
if x >= z-1+y%2: print("Yes")
else: print("No")

Submission status: Accepted

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

four = 0
odd = 0
for a in A:
    if a % 2 == 1:
        odd += 1
    if a % 4 == 0:
        four += 1
if N % 2 == 1:
    if odd - four <= 1:
        print("Yes")
    else:
        print("No")
else:
    if odd - four <= 0:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

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

codd = 0
cfour = 0

for i in range(n):
	if a[i]%2 != 0:
		codd += 1
	if a[i]%4 == 0:
		cfour += 1
ceven = n - cfour - codd

if cfour >= codd:
	print('Yes')
elif ceven == 0 and cfour + 1 == codd:
	print('Yes')
else:
	print('No')

Submission status: Accepted

Solution code:
n=int(input())

L=list(map(int,input().split()))
a=0
b=0

for i in range(n):
	if L[i]%4==0:
		b+=1
	if L[i]%2==1:
		a+=1

if a+b==n and a-b==1:
	print('Yes')
	exit()
if b>=a:
	print('Yes')
else:
	print('No')

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
cnt = [0]*3

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

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
s=0
t=0
u=0
for i in range(n):
  if a[i]%4==0:
    s=s+1
  elif a[i]%2==0:
    t=t+1
  else:
    u=u+1
if t>=1:
  if s>=u:
    print("Yes")
  else:
    print("No")
else:
  if s-u>=-1:
    print("Yes")
  else:
    print("No")

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans=[0]*3
for i in a:
  if i%4==0:ans[2]+=1
  elif i%2==0:ans[1]+=1
  else:ans[0]+=1
print(['No','Yes'][ans[0]+(ans[1]>0)<=ans[2]+1])

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans=[0]*3
for i in a:
  if i%4==0:
    ans[2]+=1
  elif i%2==0:
    ans[1]+=1
  else:ans[0]+=1
if ans[0]<=ans[2] or (ans[0]<=ans[2]+1 and ans[1]==0):print('Yes')
else:print('No')

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def main():
    N = int(input())
    A = list(map(int, input().split()))
    d = {1:0, 2:0, 4:0}
    for a in A:
        if a % 2 == 1:
            d[1] += 1
        elif a % 4 == 0:
            d[4] += 1
        else:
            d[2] += 1
    if d[2] == 0 and d[4] + 1 >= d[1]:
        print("Yes")
    elif d[2] != 0 and d[4] >= d[1]:
        print("Yes")
    else:
        print("No")
    

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
d4 = 0
d2 = 0
for i in list(map(int,input().split())):
    if i % 4 == 0:
        d4 += 1
    elif i % 2 == 0:
        d2 += 1
    else:
        None
if N <= d4*2 + 1:
    print("Yes")
elif N - d4 * 2 <= d2 :
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

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

if c4==0 and c1>0 :
    ans="No"
elif c1<=c4+(c2==0) :
    ans="Yes"
else:
    ans="No"

print( ans )

Submission status: Accepted

Solution code:
n=int(input())
l=map(int,input().split())
x,y,z=0,0,0
for a in l:
    if a%4==0:
        z+=1
    elif a%2==0:
        y+=1
    else:
        x+=1
if y>0:
    x+=1
print('Yes'if x<=z+1 else'No')

Submission status: Accepted

Solution code:
#import
#import math
#import numpy as np
N = int(input())
#= input()
#= map(int, input().split())
a = list(map(int, input().split()))
#= [input(), input()]
#= [list(map(int, input().split())) for _ in range(N)]
#= {i:[] for i in range(N)}

alen = N
two = 0
four = 0

for aa in a:
    if aa % 4 == 0:
        four += 1
    elif aa % 2 == 0:
        two += 1

other = alen - two - four

res = False

if other > four + 1:
    pass
elif other == four + 1:
    if two == 0:
        res = True
else:
    res = True

if res:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n,*aa = map(int, open(0).read().split())

odd = sum([a%2 for a in aa])
quad = sum([a%4==0 for a in aa])

if odd <= quad or (odd == quad + 1 and odd+quad == len(aa)):
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

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

ans = 'No'
other += two % 2
if four + 1 >= other:
    ans = 'Yes'

print(ans)

Submission status: Accepted

Solution code:
import collections
_ = input()
A = collections.Counter(int(T) for T in input().split()).most_common()
Num4 = sum(A[T][1] for T in range(0,len(A)) if A[T][0]%4==0)
Num2 = sum(A[T][1] for T in range(0,len(A)) if A[T][0]%4!=0 and A[T][0]%2==0)
Odd  = sum(A[T][1] for T in range(0,len(A)) if A[T][0]%2!=0)
if Num2>0: Capacity = Num4
else: Capacity = Num4+1
if Capacity>=Odd: print('Yes')
else: print('No')

Submission status: Accepted

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

x2=0
x4=0
x1=0
for x in a:
  if x%2==0:
    x2+=1
  if x%4==0:
    x4+=1
  if x%2==1:
    x1+=1
    
if x4+x1==n:
  if x4>=x1-1:
    print('Yes')
  else:
    print('No')
  
else:
  if x4>=x1:
    print('Yes')
  else:
    
    print('No')

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
amod4=list(map(lambda x:x%4, a))
d=Counter(amod4)
if n-d[0]-d[2]<d[0]+1:
  print('Yes')
elif d[2]==0 and n==2*d[0]+1:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())
    
    m = sum(1 for a in A if a % 2 == 1)
    n2 = sum(1 for a in A if a % 2 == 0 and a % 4 != 0)
    n4 = sum(1 for a in A if a % 4 == 0)
    
    if m <= n4:
        print('Yes')
    elif m == n4 + 1:
        if n2 == 0:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
    
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
c2=0
c4=0
for aa in a:
  if aa%2 == 0:
    if aa%4 == 0:
      c4+=1
    else:
      c2+=1
c0=n-(c2+c4)
cc=c4-c0
if c2>=1 and c2 != n:
  cc-=1
print("Yes" if cc >= -1 else "No")

Submission status: Accepted

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

cnt_1, cnt_2 = 0, 0
for v in a:
    if v % 2 == 1:
        cnt_1 += 1
    elif v % 4 == 0:
        cnt_2 += 1

if cnt_1 + cnt_2 == n and cnt_1 - cnt_2 == 1:
    print('Yes')
elif cnt_1 <= cnt_2:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

for a in A:
  if a%4==0:
    x+=1
  elif a%2==0:
    y+=1

if N//2<=x+y//2:
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

x = y = z = 0
for a in a_list:
    if a % 4 == 0:
        x += 1
    elif a % 2 == 0:
        y += 1
    else:
        z += 1
if (y == 0 and x >= z - 1) or (y > 0 and x >= z):
    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())))
 
odd=np.count_nonzero(A%2!=0)
four=np.count_nonzero(A%4==0)
ans='No'

if odd==1 and four>=1:
  ans='Yes'
elif odd==2 and four>=2:
  ans='Yes'
else:
  if odd+four==N and odd-1<=four:
    ans='Yes'
  elif odd<=four:
    ans='Yes'
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
d, q, x = 0, 0, 0
for a in A:
    if a % 4 == 0:
        q += 1
    elif a % 2 == 0:
        d += 1
    else:
        x += 1
x += d % 2
d -= d % 2
if q+1 >= x:
    print('Yes')
else:
    print('No')
# print(d,q,x)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
c_ki = 0
c_4 = 0
c_2 = 0
for i in range(n):
  if a[i] % 2 == 1:
    c_ki += 1
  elif a[i] % 4 == 0:
    c_4 += 1
  else:
    c_2 += 1
if c_ki <= c_4:
  print("Yes")
elif c_ki-1 == c_4 and c_2 == 0:
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

ki = 0
gu_2 = 0
gu_4 = 0

for i in a:
    if i % 4 == 0:
        gu_4 += 1
    elif i % 2 == 0:
        gu_2 += 1
    else:
        ki += 1

if ki <= gu_4:
    print('Yes')
else:
    if gu_4 + 1 == ki and gu_4 + ki == N:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

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

x,y,z=0,0,0
for i in a:
    if i%4 == 0:
        z+=1
    elif i%2 == 0:
        y+=1
    else:
        x+=1
if y:
    if x <= z:
        print('Yes')
    else:
        print('No')
else:
    if x <= z+1:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

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

a_add=[]
a_2=[]
a_4=[]

for a in A:
    if a%2 != 0:
        a_add.append(a)
    if a%4 == 0: 
        a_4.append(a)
    elif a%2 == 0: 
        a_2.append(a)
        
# print(a_add,a_2,a_4)
        
ans='No'
if len(a_4) >= len(a_add):
    ans='Yes'
elif len(a_2)==0 and len(a_4) >= len(a_add)-1:
    ans='Yes'
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a_list = [int(x) for x in input().split()]
x = y = z = 0
for a in a_list:
    if a % 4 == 0:
        x += 1
    elif a % 2 == 0:
        y += 1
    else:
        z += 1
print("Yes" if (y == 0 and x >= z - 1) or (y > 0 and x >= z) else "No")

Submission status: Accepted

Solution code:
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N = I()
a = LI()

s,t = 0,0  # 4の倍数の個数、4の倍数でない偶数の個数
for i in range(N):
    if a[i] % 4 == 0:
        s += 1
    elif a[i] % 2 == 0:
        t += 1

if s >= N//2 or t >= N-2*s:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

N = I()
a = LI()

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

if s >= N//2 or t >= N-2*s:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import math
n = int(input())
a = list(map(int, input().split()))
c2 = 0
c4 = 0
for i in a:
    if i%4==0:
        c4+=1
    elif i%2==0:
        c2+=1

if c2 == len(a):
    print('Yes')
elif c2 >= 2:
    if c4 >= (math.ceil((len(a)-c2)/2)):
        print('Yes')
    else:
        print('No')
elif c4 >=(len(a)//2):
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

odd, m4, m2 = 0, 0, 0
for i in a:
    if i % 2 != 0:
        odd += 1
    elif i % 4 == 0:
        m4 += 1
    else:
        m2 = 1
else:
    if odd + m2 - 1 <= m4:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

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

odd = []
m4 = []
m2 = 0
for i in a:
    if i % 2 != 0:
        odd.append(i)
    elif i % 4 == 0:
        m4.append(i)
    else:
        m2 = 1
else:
    if len(odd) + m2 - 1 <= len(m4):
        print("Yes")
    else:
        print("No")

Submission status: Accepted

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

odd = []
m4 = []
m2 = 0
for i in a:
    if i % 2 != 0:
        odd.append(i)
    elif i % 4 == 0:
        m4.append(i)
    else:
        m2 = 1
else:
    lodd = len(odd)
    if lodd == 0 or lodd + m2 - 1 <= len(m4):
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    As = list(map(int, input().split()))
    fours = 0
    evens = 0
    odds = 0
    for A in As:
        if A % 4 == 0:
            fours += 1
        elif A % 2 == 0:
            evens += 1
        else:
            odds += 1

    if fours+(evens)//2 >= n//2:
        ans = 'Yes'
    else:
        ans = 'No'
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
mod0 = 0
mod2 = 0
mod13 = 0

for a in A:
  mod = a % 4
  if mod == 0:
    mod0 += 1
  elif mod == 2:
    mod2 += 1
  else:
    mod13 += 1
    
if mod2 > 0:
  if mod13 <= mod0:
    print('Yes')
  else:
    print('No')
else:
  if mod13-1 <= mod0:
    print('Yes')
  else:
    print('No')

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

n_c4 = 0
n_c2 = 0
n_c0 = 0

for ai in a:
    if ai%4 ==0:
        n_c4 += 1
    elif ai%2 ==0:
        n_c2 += 1
    else:
        n_c0 += 1
if n_c4>=n_c0 or (n_c4 == n_c0-1 and n_c4+n_c0 == N) :
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

other = mult_2 = mult_4 = 0
for t in a:
    if t % 4 == 0:
        mult_4 += 1
    elif t % 2 == 0:
        mult_2 += 1
    else:
        other += 1

if other - 1 + (1 if mult_2 > 0 else 0) <= mult_4:
    print("Yes")
else:
    print("No")