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: Wrong Answer

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 cnt2 == n:
    print('Yes')
    exit()
cnt2 = min(cnt2, 4)

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

Submission status: Wrong Answer

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
cnt2 = min(cnt2, 4)

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

Submission status: Wrong Answer

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: Wrong Answer

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):print("Yes")
else:print("No")

Submission status: Wrong Answer

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_ + 1 == len_bai4 and n == len_bai_ + len_bai4:
        print("Yes")
    else:
        print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:

n = int(raw_input())
ais = 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
			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:
				break
			else:
				q.append(1)
				cc[1]-=1
				n-=1

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

Submission status: Wrong Answer

Solution code:

n = int(raw_input())
ais = 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]:
				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
			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:
				break
			else:
				q.append(1)
				n-=1

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

Submission status: Wrong Answer

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 >= n:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

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

cnt = 0
for a in a_lst:
  if a % 4 == 0:
    cnt += 1
  else:
    pass
if cnt >= (n // 2):
  print('No')
else:
  print('Yes')

Submission status: Wrong Answer

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

cnt = 0
for a in a_lst:
  if a % 4 == 0:
    cnt += 1
  else:
    pass
if cnt == 0:
  print('No')
else:
  print('Yes')

Submission status: Wrong Answer

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)<=l.count(4)else'No')

Submission status: Wrong Answer

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: Wrong Answer

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)//2<=l.count(4)else'No')

Submission status: Wrong Answer

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))//2<=l.count(4)else'No')

Submission status: Wrong Answer

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
if l.count(2):
    if (l.count(2)+l.count(1)+1)//2<=l.count(4):
        print('Yes')
    else:
        print('No')
else:
    if l.count(1)+1//2<=l.count(4):
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

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
if l.count(2):
    if (l.count(2)+l.count(1))//2<=l.count(4):
        print('Yes')
    else:
        print('No')
else:
    if l.count(1)<=l.count(4):
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

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)+(l.count(2)%2)+1)//2<=l.count(4)else'No')

Submission status: Wrong Answer

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 != 1 and cfour + 1 == codd:
	print('Yes')
else:
	print('No')

Submission status: Wrong Answer

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

codd = 0
cfour = 0

for i in range(n):
	if a[i]%4 == 1 or a[i]%4 == 3:
		codd += 1
	if a[i]%4 == 0:
		cfour += 1

if cfour == codd:
	print('Yes')
else:
	print('No')

Submission status: Wrong Answer

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 ( N == 3 and cnt[0] == 2 and cnt[2] == 1):
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

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 c2>0:
    c1+=1
if c4==0 and c1>0 :
    ans="No"
elif c1<=c4+1 :
    ans="Yes"
else:
    ans="No"

print( ans )

Submission status: Wrong Answer

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 c2==1:
    c1+=1
if c4==0 and c1>0 :
    ans="No"
elif c1<=c4+1 :
    ans="Yes"
else:
    ans="No"

print( ans )

Submission status: Wrong Answer

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

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

if c2==1:
    c2=0

if (n-c2)//2<=c4 :
    ans="Yes"
else:
    ans="No"

print( ans )

Submission status: Wrong Answer

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

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

if (n-c2)//2<=c4 and c2>1 :
    ans="Yes"
else:
    ans="No"

print( ans )

Submission status: Wrong Answer

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

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

if (n-c2)//2<=c4 :
    ans="Yes"
else:
    ans="No"

print( ans )

Submission status: Wrong Answer

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 (0 < odd and odd <= quad) or odd == 0:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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'
if four + 1 >= other + two:
    ans = 'Yes'
elif two != 0 and two % 2 == 0:
    ans = 'Yes'
elif two == n:
    ans = 'Yes'

print(ans)

Submission status: Wrong Answer

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'
if four + 1 >= other+two:
    ans = 'Yes'
elif two != 0 and two % 2 == 0:
    ans = 'Yes'


print(ans)

Submission status: Wrong Answer

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:
  if x4>=x1:
    print('Yes')
  else:
    
    print('No')

Submission status: Wrong Answer

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:
  if x4>x1:
    print('Yes')
  else:
    
    print('No')

Submission status: Wrong Answer

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:
  print('Yes')
  
else:
  print('No')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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=2*c4-c0
if c2>=1 and c2 != n:
  cc-=1
print("Yes" if cc >= 0 else "No")

Submission status: Wrong Answer

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=2*c4-c0
if c2>=1:
  cc-=1
print("Yes" if cc >= 0 else "No")

Submission status: Wrong Answer

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=2*c4-c0
if c2==1:
  cc-=1
print("Yes" if cc >= 0 else "No")

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a_mod4_or_2=[]
for aa in a:
  v=0
  if aa%2 == 0:
    if aa%4 == 0:
      v=4
    else:
      v=2
  a_mod4_or_2.append(v)
c2=a_mod4_or_2.count(2)
c4=a_mod4_or_2.count(4)
c0=n-(c2+c4)
cc=2*c4-(c2%2)-c0

print("Yes" if cc >= 0 else "No")

Submission status: Wrong Answer

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

for a in A:
  if a%4==0:
    f+=1
  elif a%2==0:
    t+=1

if N<=t//2+3*f:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

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'
print(odd,four)
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: Wrong Answer

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+1<=four:
    ans='Yes'
print(ans)

Submission status: Wrong Answer

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'
elif odd>=3:
  if odd+four==N and odd-1<=four:
    ans='Yes'
  elif odd+1<=four:
    ans='Yes'
print(ans)

Submission status: Wrong Answer

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)

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

Submission status: Wrong Answer

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)

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

Submission status: Wrong Answer

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:
    print('No')

Submission status: Wrong Answer

Solution code:
_=int(input())
a=list(map(int,input().split()))
r1=a.count(2)
r2=a.count(6)
r=r1+r2
for _ in range(r1):
    a.remove(2)
for _ in range(r2):
    a.remove(6)
cnt=0
if r%2!=0:
    cnt-=1
    for i in a:
        if i%10==0 and i%4!=0:
            a.remove(i)
            cnt=0
            break
for i in a:
    if i%4==0:
        cnt+=1
if cnt>=len(a)//2:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A = [a%4 for a in A]
m = A.count(0)
P = 3+2*(m-1) if m>0 else 0
n = A.count(2)
Q = n-1 if n>0 else 0
print("Yes" if P+Q>=N else "No")

Submission status: Wrong Answer

Solution code:
_=int(input())
a=list(map(int,input().split()))
r1=a.count(2)
r2=a.count(6)
r=r1+r2
cnt=0
if r%2!=0:
    cnt=-1

for _ in range(r1):
    a.remove(2)
for _ in range(r2):
    a.remove(6)
if cnt<0:
    for s in a:
        if s%10==0:
            a.remove(s)
            cnt=0
            break
if len(a)==0:
    print('Yes')
else:
    for i in a:
        if i%4==0:
            cnt+=1
    if cnt>=len(a)//2:
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
_=int(input())
a=list(map(int,input().split()))
r1=a.count(2)
r2=a.count(6)
r=r1+r2
for _ in range(r1):
    a.remove(2)
for _ in range(r2):
    a.remove(6)
cnt=0
if r%2!=0:
    cnt-=1
for i in a:
    if i%4==0:
        cnt+=1
if cnt>=len(a)//2:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
_=int(input())
a=list(map(int,input().split()))
r1=a.count(2)
r2=a.count(6)
r=r1+r2
for _ in range(r1):
    a.remove(2)
for _ in range(r2):
    a.remove(6)
cnt=0
if r%2!=0:
    cnt-=1
for i in a:
    if i%4==0:
        cnt+=1
if cnt>=len(a)//2:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

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 >= 1:
    if c4 >= (math.ceil((len(a)-c2)/2)):
        print('Yes')
elif c4 >=(len(a)//2):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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')
elif c4 >=(len(a)//2):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    A = il()
    o, t, f = 0, 0, 0
    for a in A:
        if a % 4 == 0:
            f += 1
        elif a % 2 == 0:
            t += 1
        else:
            o += 1
    if t > 0:
        o += 1
    print('YES' if o <= f + 1 else 'NO')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    A = sorted(il())
    o, t, f = 0, 0, 0
    for n in range(N):
        if A[n] % 4 == 0:
            f += 1
        elif A[n] % 2 == 0:
            t += 1
        else:
            o += 1
    if t > 0:
        o += 1
    print('YES' if o <= f + 1 else 'NO')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    A = sorted(il())
    o, t, f = 0, 0, 0
    for n in range(N):
        if A[n] % 4 == 0:
            f += 1
        elif A[n] % 2 == 0:
            t += 1
        else:
            o += 1
    print('YES' if o + (t + 1) // 2 <= f + 1 else 'NO')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    A = sorted(il())
    h, f = 0, 0
    for n in range(N):
        if A[n] % 4 == 0:
            f += 1
        elif A[n] % 2 == 0:
            h += 1
    print('YES' if N // 2 < (h // 2 + f * 2) else 'NO')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    A = il()

    cnt = 0
    for a in A:
        if a % 4 == 0:
            cnt += 1
        elif a % 2 == 0:
            cnt += .5
    print('YES' if N // 2 <= int(cnt) else 'NO')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

t = 0
two = 0
for i in range(n):
    if lis[i] % 4 == 0:
        t += 1
    if lis[i] == 2:
        two += 1

a = two//2

if t >= (n//2) or t+a >=(n//2):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N = ii()
    a = list(mi())
    even = sum(1 for i in range(N) if a[i]%2==0)
    odd = sum(1 for i in range(N) if a[i]%2==1)
    four = sum(1 for i in range(N) if a[i]%4==0)

    if odd-four == 1:
        ans = (odd+four == N)
    elif odd == four:
        ans = True
    elif four-odd == 1:
        ans = True
    else:
        ans = False

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

ans = "No"

if cnt4*2 >= N: # 4の倍数が一個置きに配置できるならOK
    ans =  "Yes"
elif cnt4 > 0: # 4の倍数が少なくても残りを2の倍数で埋めれればOK
    if N - cnt4*2 <= cnt2:
        ans = "Yes"
else: # ただし4の倍数がひとつもないなら、すべて2の倍数な場合のみがOK
    if N == cnt2*2:
        ans = "Yes"

print(ans)

Submission status: Wrong Answer

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

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

ans = "No"

if cnt4*2 >= N: # 4の倍数が一個置きに配置できるならOK
    ans =  "Yes"
elif cnt4 > 0: # 4の倍数が少なくても残りを2の倍数で埋めれればOK
    if N - cnt4*2 < cnt2*2:
        ans = "Yes"
else: # ただし4の倍数がひとつもないなら、すべて2の倍数な場合のみがOK
    if N == cnt2*2:
        ans = "Yes"

print(ans)

Submission status: Wrong Answer

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

cnt4 = 0
cnt2 = 0
for a in A:
    if a % 4 == 0:
        cnt4 += 1
    elif (a % 4 != 0) and (a % 2 == 0):
        cnt2 += 1

ans = "No"

if cnt4*2 >= N:
    ans =  "Yes"
else:
    if N - cnt4*2 < cnt2*2:
        ans = "Yes"

print(ans)

Submission status: Wrong Answer

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

cnt4 = 0
cnt2 = 0
for a in A:
    if a % 4 == 0:
        cnt4 += 1
    elif (a % 4 != 0) and (a % 2 == 0):
        cnt2 += 1

print(cnt4, cnt2)
ans = "No"

if cnt4*2 >= N:
    ans =  "Yes"
else:
    if N - cnt4*2 < cnt2*2:
        ans = "Yes"

print(ans)

Submission status: Wrong Answer

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

cnt4 = 0
cnt2 = 0
for a in A:
    if a % 4 == 0:
        cnt4 += 1
    elif (a % 4 != 0) and (a % 2 == 0):
        cnt2 += 1

ans = "No"

if cnt4*2 >= N:
    ans =  "Yes"
else:
    if N - cnt4*2 <= cnt2*2:
        ans = "Yes"

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(map(int,input().split()))
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N = i()
a = l()
num1 = 0
num2 = 0
num3 = 0
for i in range(N):
    if a[i]%4 == 0:
        num3 += 1
    elif a[i]%2 == 0:
        num2 += 1
    else:
        num1 += 1
if num3+1 < num1:
    print('No')
if num3+1 == num1 and num2 != 0:
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
n = int(input())
A = tuple(map(int, input().split()))
c4 = 0
c2 = 0
cn = 0
for a in A:
    if a%4==0:
        c4 += 1
    elif a%2==0:
        c2 += 1
    else:
        cn += 1

if (c4*2 + 1 if c4 > 0 else 0) + ((c2-1) if c2 > 1 else 0) >= n:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
n = int(input())
A = tuple(map(int, input().split()))
c4 = 0
c2 = 0
cn = 0
for a in A:
    if a%4==0:
        c4 += 1
    elif a%2==0:
        c2 += 1
    else:
        cn += 1

if (c4*2 + 1 if c4 > 0 else 0) + (c2 if c2 > 1 else 0) >= n:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
n, *a = map(int, open(0).read().split())
f = 0
t = 0
for i in a:
    if i % 4 == 0:
        f += 1
    elif i % 2 == 0:
        t += 1
if len(a) == 1 and f == 0:
    print("No")
    quit()
if 2*f + t >= len(a):
    print('Yes')
    quit()
elif 2*f + t + 1 == len(a) and f != 0:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
n, *a = map(int, open(0).read().split())
f = 0
t = 0
for i in a:
    if i % 4 == 0:
        f += 1
    elif i % 2 == 0:
        t += 1
if 2*f + t >= len(a):
    print('Yes')
    quit()
elif 2*f + t + 1 == len(a) and f != 0:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
n, *a = map(int, open(0).read().split())
p = 0
for i in a:
    p += i % 2 == 0
    p += i % 4 == 0
if p >= len(a):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

ok = [a[i] for i in range(n) if a[i] % 4 == 0]
bad = [a[i] for i in range(n) if a[i] % 4 > 0]

nok = len(ok)
nbad = len(bad)
if nok >= nbad:
   print('Yes')
elif nbad - nok <= 1:
   print('Yes')
else:
   ok2 = [bad[i] for i in range(nbad) if a[i] % 2 == 0]
   if len(ok2) >= 2 and nbad - 2 <= nok:
      print('Yes')
   else:
      print('No')

Submission status: Wrong Answer

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

e = []
even4, odd = 0, 0
for i in a:
    if i % 4 == 0:
        even4 += 1
        e.append(i)
    else:
        odd += 1

if even4 >= odd:
    print("Yes")
    exit()
elif even4 < odd-1:
    print("No")
    exit()
else:
    for i in e:
        if i % 4 != 0:
            print("No")
            exit()
    print("Yes")

Submission status: Wrong Answer

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

e = []
even4 = 0
even = 0
odd = 0
for i in a:
    if i % 4 == 0:
        even4 += 1
        e.append(i)
    elif i % 2 == 0:
        even += 1
    if i % 2 != 0:
        odd += 1

if even != 0:
    if even4 >= odd:
        print("Yes")
        exit()
    else:
        print("No")
        exit()
else:
    if even4 >= odd+1:
        print("Yes")
        exit()
    else:
        print("No")
        exit()

Submission status: Wrong Answer

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

e = []
even4 = 0
odd = 0
for i in a:
    if i % 4 == 0:
        even4 += 1
        e.append(i)
    if i % 2 != 0:
        odd += 1

if even4 >= odd:
    print("Yes")
    exit()
else:
    print("No")
    exit()

Submission status: Wrong Answer

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

e = []
even, odd = 0, 0
for i in a:
    if i % 2 == 0:
        even += 1
        e.append(i)
    else:
        odd += 1

if even > odd:
    print("Yes")
    exit()
elif even < odd-1:
    print("No")
    exit()
else:
    for i in e:
        if i % 4 != 0:
            print("No")
            exit()
    print("Yes")

Submission status: Wrong Answer

Solution code:
N = input()
L = list(map(int,input().split()))
n=0
m=0
p=0
for a in range(len(N)):
  if L[a]%2 != 0:
    n+=1
  elif L[a]%2 == 0 and L[a]%4 != 0:
    m+=1
  else:
    p+=1
if int(N)%2==1 and n>p+1:
  print("No")
elif int(N)%2==0 and n>p:
  print("No")
else:
  print("Yes")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
count2 = 0
count4 = 0
for i in range(n):
    #２の倍数だが４の倍数でない
    if a[i]%2 == 0 and a[i]%4 != 0:
        count2 += 1
    #４の倍数
    elif a[i]%4 == 0:
        count4 += 1
if count4 != 0:
    count4 = count4*2+1

if count2 > 1:
    count4 += count2

if count4 >= n:
    print("Yes")
else:
    print("No")