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:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    A = LI()
    twos = []
    for a in A:
        if a % 4 == 0:
            cnt = 2
        elif a % 2 == 0:
            cnt = 1
        else:
            cnt = 0
        twos.append(cnt)
    if N % 2 == 0:
        minNeed = N
    else:
        minNeed = N - 2
    if sum(twos) < minNeed:
        print('No')
    else:
        print('Yes')
main()

Submission status: Accepted

Solution code:
N = int(input())
dic = {1:0,2:0,4:0}
List = list(map(int,input().split()))
for item in List:
  if item%4 == 0:
    dic[4] += 1
  elif item %2 == 0:
    dic[2] += 1
  else:
    dic[1] += 1
Answer = 'No'
if dic[4] != 0 and dic[4]+1 >= dic[1]+dic[2]:
  Answer = 'Yes'
elif dic[4]>=dic[1]:
  Answer = 'Yes'
print(Answer)

Submission status: Accepted

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

div_1,div_2,div_4=0,0,0
for a in A:
    if a%4==0:
        div_4+=1
    elif a%2==0:
        div_2+=1
    elif a%2!=0:
        div_1+=1
if div_2==0 and div_1<=div_4+1:
    print('Yes')
elif div_2>0 and div_1<=div_4:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
from collections import defaultdict
d = defaultdict(int)
n = int(input())
a = list(map(int, input().split()))
for num in a:
  if num % 4 == 0:
    d[4] += 1
    continue
  if num % 2 == 0:
    d[2] += 1
    continue
print("Yes" if n//2 <= d[4] + (d[2] // 2) else "No")

Submission status: Accepted

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
a_div_2 = [1 if a[i] % 2 == 0 and a[i] % 4 != 0 else 0 for i in range(n)]
a_div_4 = [1 if a[i] % 4 == 0 else 0 for i in range(n)]
if a_div_2.count(1) // 2 + a_div_4.count(1) >= n // 2: print("Yes")
else: print("No")

Submission status: Accepted

Solution code:

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

from collections import Counter

L = []
for a in A:
  if a % 4 == 0:
    L.append(2)
  elif a % 4 == 2:
    L.append(1)
  else:
    L.append(0)

T = [0 for i in range(3)]
for (key, value) in Counter(L).most_common():
  T[key] = value

def pop(v):
  if v == 2 and T[0] > 0:
    T[0] -= 1
    return 0
  if v in [1, 2] and T[1] > 0:
    T[1] -= 1
    return 1
  if v in [0,1,2] and T[2] > 0:
    T[2] -= 1
    return 2
  return -1

before = pop(2)
for i in range(N-1):
  before = pop(before)
  if before == -1:
    print("No")
    exit()

print("Yes")

Submission status: Accepted

Solution code:
"""import sys
input = sys.stdin.readline"""
n=int(input())
a=list(map(int,input().split()))
cnt2=0
cnt4=0
for i in a:
    if i%4==0:
        cnt4+=1
    elif i%2==0:
        cnt2+=1
if cnt2>1:
    ans=n-cnt4*2-cnt2
if cnt2<=1:
    ans=n-cnt4*2-1
print("Yes" if ans<=0 else "No")

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
four = 0
two = 0
flag = False
for i in a:
    if i%4 == 0:
        four += 1
    elif i%2 == 0:
        two += 1
if two > 1:
    N -= two
    N -= 2
    four -= 1
    flag = True
N -= 2*(four-1)+(3-flag)
if N > 0:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
N=int(input())
cnt,zero,one,two,more,d=0,0,0,0,0,0
A=list(map(int,input().split()))
B=A[:]
for i in range(N):
  while B[i]%2==0:
    if B[i]%2==0:
      B[i]=B[i]//2
      cnt=cnt+1
  if cnt==0:zero += 1
  elif cnt==1:one += 1
  else:more += 1
  cnt=0
if one%2!=0:d=1
print("No" if (zero+d)>(two+more+1) else "Yes")

Submission status: Accepted

Solution code:
N=int(input())
cnt,zero,one,two,three,four,more=0,0,0,0,0,0,0
d=0
A=list(map(int,input().split()))
B=A[:]
for i in range(N):
  while B[i]%2==0:
    if B[i]%2==0:
      B[i]=B[i]//2
      cnt=cnt+1
  if cnt==0:
    zero += 1
  elif cnt==1:
    one += 1
  elif cnt==2:
    two += 1
  elif cnt==3:
    three += 1
  elif cnt==4:
    four += 1
  else:
    more += 1
  cnt=0
#print(zero,one,two,three,four,more)
if one%2==0:
  d=0
else:
  d=1
if (zero+d)>(two+three+four+more+1):
  print("No")
else:
  print("Yes")

Submission status: Accepted

Solution code:
# C - 4-adjacent
n,a = int(input()),[int(x)%4 for x in input().split()]
print("Yes" if n//2 <= a.count(0) + a.count(2)//2 else "No")

Submission status: Accepted

Solution code:
# C - 4-adjacent

# _,a = input(),[int(x)%4 for x in input().split()]
# print("Yes" if a.count(1) + a.count(3) <= a.count(0) + (0 if a.count(2)>0 else 1) else "No")

n,a = int(input()),[int(x)%4 for x in input().split()]
# print("Yes" if n - a.count(2) - a.count(0) <= a.count(0) + (0 if a.count(2)>0 else 1) else "No")
# print("Yes" if n - a.count(2) <= a.count(0)*2 + (0 if a.count(2)>0 else 1) else "No")
# print("Yes" if n <= a.count(0)*2 + a.count(2) + (0 if a.count(2)>0 else 1) else "No")
print("Yes" if n//2 <= a.count(0) + a.count(2)//2 else "No")

Submission status: Accepted

Solution code:
# C - 4-adjacent
n = int(input())
count2 = count4 = 0
for a in [int(x)%4 for x in input().split()]:
    if a==0: count4 += 1
    elif a==2: count2 += 1
print("Yes" if n//2 <= count4 + count2//2 else "No")

Submission status: Accepted

Solution code:
# C - 4-adjacent
_ = input()
count1 = count4 = 0
not_exist2 = 1
for a in map(lambda x: int(x)%4, input().split()):
    if a==0: count4 += 1
    elif a==2: not_exist2 = 0
    else: count1 += 1
print("Yes" if count1 <= count4 + not_exist2 else "No")

Submission status: Accepted

Solution code:
import numpy as np
N=int(input())
A = list(map(int,input().split()))
Aa = np.array(A) %4
if np.count_nonzero(Aa%4==2)==0 and N//2-np.count_nonzero(Aa%4==0)>0:
    print("No")
elif np.count_nonzero(Aa%4==2)==0 and N//2-np.count_nonzero(Aa%4==0)<=0:
    print("Yes")
elif np.count_nonzero(Aa%4==2)!=0:
    if N%2==np.count_nonzero(Aa%4==2)%2 and np.count_nonzero(Aa%2==1)-np.count_nonzero(Aa%4==0)>0:
        print("No")
    elif N%2 != np.count_nonzero(Aa%4==2)%2 and np.count_nonzero(Aa%2==1)+1-np.count_nonzero(Aa%4==0)>0:
        print("No")
    else:
        print("Yes")

Submission status: Accepted

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

*b, = filter(lambda x: x%4 != 0, a)
mul_4 = n-len(b)

*c, = filter(lambda x: x%2 != 0, b)
mul_2 = (len(b)-len(c))

k = n-(mul_4+mul_2)

if mul_2 == 0 and k <= mul_4+1:
    print("Yes")
elif k <= mul_4:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
def c_4adjacent():
    from collections import defaultdict
    N = int(input())
    A = [int(i) for i in input().split()]

    count = defaultdict(int)
    for a in A:
        count[a % 4] += 1
    num_4, num_2, num_other = count[0], count[2], count[1] + count[3]

    if num_2 == 0:
        # 14141 のように並べられるか (余った4はまとめて端に置く)
        ans = 'Yes' if num_other <= num_4 + 1 else 'No'
    else:
        # 2...24141 のように並べられるか (余った4はまとめて端に置く)
        ans = 'Yes' if num_other <= num_4 else 'No'
    return ans

print(c_4adjacent())

Submission status: Accepted

Solution code:
def count_four(lst):
    counter = 0
    for i in lst:
        if i%4 == 0:
            counter += 1
    return counter

def count_two(lst):
    counter = 0
    for i in lst:
        if i%2 == 0:
            counter += 1
    return counter

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

def solve(lst):
    four = count_four(lst)
    two = count_two(lst) - four
    others = n - four - two

    if two == 0:
        if four + 1 - others >= 0:
            return "Yes"
        else:
            return "No"

    if two > 0:
        two = 1
        if four + 1 - others - two >= 0:
            return "Yes"
        else:
            return "No"


print(solve(lst))

Submission status: Accepted

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

*b, = filter(lambda x: x%4 != 0, a)
mul_4 = n-len(b)

*c, = filter(lambda x: x%2 != 0, b)
mul_2 = (len(b)-len(c))//2

print("Yes" if n//2 <= mul_4+mul_2 else "No")

Submission status: Accepted

Solution code:
def main():
  
  N = int(input())
  alist = list(map(int, input().split()))

  adj4cou = 0
  adjn4y2 = 0
  for a in alist:
    if a%4 == 0:
      adj4cou += 1
      if adj4cou >= N//2:
        return 'Yes'
    elif a%2 == 0:
      adjn4y2 += 1
  if adjn4y2 >= (N - 2*adj4cou):
    return 'Yes'
  return 'No'

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

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
div2 = 0
div4 = 0
for i in a:
  if i%4==0:
    div4 += 1
  elif i%2==0:
    div2 += 1
if n-max(div2-1,0) <= div4*2+1:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
# きりみんちゃん配信からきました
# 4で割りきれる数と奇数をぶつける（4で割り切れず2で割り切れるやつはまあはい）
n = int(input())
arr = list(map(int, input().split()))
dividable4 = 0
dividable2 = 0
odds = 0
for a in arr:
  if a % 4 == 0:
    dividable4 += 1
  elif a % 2 == 1:
    odds += 1
  elif a % 2 == 0:
    dividable2 += 1
print("Yes" if odds <= dividable4 or (odds - dividable4 == 1 and dividable2 == 0)  else "No")

Submission status: Accepted

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

ki=0
yon=0

for i in a:
  if i%2:
    ki+=1
  elif i%4==0:
    yon+=1

if n%2:
  if ki+yon==n:
    if ki<=yon+1:
      print("Yes")
    else:
      print("No")
  elif yon>=ki:
    print("Yes")
  else:
    print("No")
elif yon>=ki:
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

cnt2 = 0
cnt4 = 0

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

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

Submission status: Accepted

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

for i in range(n):
    a[i]%=4

if a.count(0)>=n//2:
    print('Yes')
elif n-a.count(0)*2<=a.count(2):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
four = 0
two = 0
one = 0 
for e in A:
    if e%4 == 0:
        four += 1
    elif e %2 == 0:
        two += 1
    else:
        one += 1

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

Submission status: Accepted

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

count1 = 0
count2 = 0
count4 = 0

for a in A:
    if a % 4 == 0:
        count4 += 1
    elif a % 2 == 0:
        count2 += 1
    else:
        count1 += 1

count4 -= count1
if count2:
    count4 -= 1

if count4 >= -1:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

k0 = 0
k2 = 0
k4 = 0

for a in A:
  if a%4==0:
    k4 += 1
  elif a%2==0:
    k2 += 1
  else:
    k0 += 1

# 2で割り切れるものをひとまとめにしk0としてみなす
if k2 > 0:
  k0 += 1

if k0 <= k4+1:
  print("Yes")  
else:
  print("No")

Submission status: Accepted

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

b1 = b2 = b4 = 0
for i in range(n):
    if a[i]%4 == 0:
        b4 += 1
    elif a[i] %2 == 0:
        b2 += 1
    else:
        b1 += 1

if b2 == 0:
    ans = "Yes" if b4 + 1 >= b1 else "No"
else:
    ans = "Yes" if b4 >= b1 else "No"

print(ans)

Submission status: Accepted

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

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

if 2*cnta+1 >= n or 2*cnta + cntb >= n:
    ans = "Yes"
else:
    ans = "No"

print(ans)

Submission status: Accepted

Solution code:
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac
import fractions
from functools import reduce
from operator import mul
import bisect
import sys
import logging
import heapq
import itertools

logging.basicConfig(level=logging.ERROR)

input = sys.stdin.readline

setrecursionlimit(1000000)


def main():
	n = int(input())
	a = list(map(int,input().split()))
	a_1 = 0
	a_2 = 0
	a_4 = 0
	for i in a:
		if(i%4==0):
			a_4+=1
		elif(i%2==0):
			a_2+=1
		else:
			a_1+=1
	if(a_2>0):
		a_1+=1
	if(a_4>=a_1-1):
		print('Yes')
	else:
		print('No')

main()

Submission status: Accepted

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

def main():
    N = int(input())
    a = list(map(int,input().split()))
    
    odd = 0
    even = 0
    spev = 0
    for i in a:
        if i%4 == 0:
            spev += 1
        elif i%2 == 0:
            even += 1
        else:
            odd += 1
            
    if even == 0:
        if spev >= odd-1:
            print("Yes")
        else:
            print("No")
    else:
        if spev >= odd:
            print("Yes")
        else:
            print("No")
            
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n=input()
L=map(int,input().split())
LL = [4 if l % 4 == 0 else 2 if l % 2 == 0 else 1  for l in L]
import collections
C = collections.Counter(LL)
#print(C,C[2])
if C[4] == C[1]:
  print('Yes')
elif (C[4] + 1) == C[1] and C[2] == 0:
  print('Yes')
elif C[4] < C[1]:
  print('No')
else:
  print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
a = [int(i) for i in input().split()]
c = 0
c2 = 0
for n in a:
    if n % 4 == 0:
        c += 1
    elif n % 4 == 2:
        c2 += 1
ans = 'No'
if c >= N//2:
    ans = 'Yes'
if N-c*2 <= c2:
    ans = 'Yes'
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
x1 = x2 = x4 = 0
for i in a:
    cnt = 0
    while i % 2 < 1:
        i //= 2
        cnt += 1
    if cnt > 1:
        x4 += 1
    elif cnt > 0:
        x2 += 1
    else:
        x1 += 1
if x1 < 1:
    print('Yes')
elif x2 < 1:
    if n // 2 <= x4:
        print('Yes')
    else:
        print('No')
else:
    if (x1 + x4 + 1) // 2 <= x4:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
#n = int(input())
#n,k = map(int,input().split())
#x = list(map(int,input().split()))

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

li = [0,0,0]

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

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

Submission status: Accepted

Solution code:
import collections

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

B = [0] * n
for i in range(n):
    if (format(A[i], 'b')[::-1].find('1') <= 2):
        B[i] = format(A[i], 'b')[::-1].find('1')
    else :
        B[i] = 2


C = collections.Counter(B)
if (1 in C):
    if (C[2] >= C[0]):
        print('Yes')
    else:
        print('No')
else:
    if (C[2]+1 >= C[0]):
            print('Yes')
    else:
        print('No')

Submission status: Accepted

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

evens = []
fours = []
for n in range(N):
    if A[n] % 4 == 0:
        fours.append(A[n])
    elif A[n] % 2 == 0 and A[n] % 4 != 0:
        evens.append(A[n])
total = len(evens) // 2 + len(fours)
if total >= N // 2:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

odd = 0
multiple_2 = 0
multiple_4 = 0

for i in range(N):
    if a[i] % 4 == 0:
        multiple_4 += 1
    elif a[i] % 2 == 0:
        multiple_2 += 1
    else:
        odd += 1
        
if multiple_4 >= odd or multiple_4 == len(a) // 2:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

odd = 0
two = 0
four = 0

for a in A:
    if(a%2): odd += 1
    else:
        if(a%4==0):four+=1
        else: two += 1


if(two):
    if(odd<=four): print("Yes")
    else: print("No")

else:
    if(odd-1<=four): print("Yes")
    else: print("No")

Submission status: Accepted

Solution code:
N= int(input())
A= [int(x) for x in input().split()]
c_2 = 0
c_4 = 0
for i in range(N):
  if A[i]%4==0:
    c_4 += 1
  elif A[i]%2==0 and A[i]%4!=0:
    c_2 += 1
c=N-c_4-c_2
print('Yes' if (c_2==0 and c_4>=c-1) or c_4>=c else'No')

Submission status: Accepted

Solution code:
import sys
bbn=1000000007
	
#+++++
		
def main():
	n = int(input())
	al = list(map(int, input().split()))
	
	b4=0
	odd=0
	b2=0
	for v in al:
		if v % 4 == 0:
			b4+=1
		elif v % 2 == 1:
			odd+=1
		else:
			b2+=1
	ret = 'Yes' if (b4 + (b2==0))>= odd else 'No'
	print(ret)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

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

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

if k4 + 1 == k and n == (k4 + k):
    print("Yes")
elif k4 < k:
    print("No")
else:
    print("Yes")

Submission status: Accepted

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

a1, a2, a4 = 0, 0, 0
for a in A:
  if a % 2 == 0:
    if a % 4 == 0:
      a4 += 1
    else:
      a2 += 1
  else:
    a1 += 1
#print("a1, a2, a4:", a1, a2, a4)

if a4 >= a1:
  print("Yes")
else:
  if a1 - a4 == 1:
    if a2 == 0:
      print("Yes")
    else:
      print("No")
  else:
    print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import numpy as np
input = sys.stdin.readline
N = int(input())
a = [int(x) for x in input().split()]
a = np.array(a)
a_o = np.count_nonzero(a % 2 == 1)
a_4 = np.count_nonzero(a % 4 == 0)
a_2 = N - a_o - a_4
if a_2 == 0 and a_4 + 1 == a_o:
    print("Yes")
    sys.exit()
if a_o == 1 and a_4 == 0:
    print("No")
    sys.exit()
if a_o == 2 and a_4 == 1 and N == 3:
    print("Yes")
    sys.exit()
if a_o == 2 and a_4 < 2:
    print("No")
    sys.exit()
if a_o >= 3 and a_4 < a_o:
    print("No")
    sys.exit()
print("Yes")

Submission status: Accepted

Solution code:
import sys
import numpy as np

n = int(sys.stdin.readline().rstrip())
a = np.array(sys.stdin.read().split(), dtype=np.int64)

def main():
    mul_4 = n - np.count_nonzero(a % 4)
    mul_2 = n - np.count_nonzero(a % 2)

    if mul_4 >= n // 2:
        return 'Yes'
    if mul_4 * 2 + (mul_2 - mul_4) >= n:
        return 'Yes'
    else:
        return 'No'

if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
o, t, f = 0, 0, 0
for x in a:
	if (x & 1) == 1:
		o = o + 1
	elif (x & 3) == 2:
		t = t + 1
	else:
		f = f + 1

possible = (t == 0 and f >= o - 1) or (f >= o)
if possible:
	print("Yes")
else:
	print("No")

Submission status: Accepted

Solution code:
N = int(input())
A = tuple(map(lambda num: min(2, format(int(num), "b")[::-1].index("1")), input().split()))
n2 = A.count(2)

print("Yes" if n2 * 2 >= N - N % 2 or sum(A) >= N else "No")

Submission status: Accepted

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

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

if cnt_of_4 >= N//2 or cnt_of_4 *2 + cnt_of_2 >= N:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
x4=0
x2=0
for i in a:
  if i%4==0:
    x4+=1
  elif i%2==0:
    x2+=1
if x4*2+x2>=n or x4>=n//2:
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

Submission status: Accepted

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

l_2 = [i for i in l if i % 2 == 0 and i % 4 != 0]
l_4 = [i for i in l if i % 4 == 0]

if len(l_2)//2 + len(l_4) >= n//2:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

odd = 0
count_two = 0
count_four = 0
for i in range(n):
    if A[i] % 4 == 0:
        count_four += 1
    elif A[i] % 2 == 0:
        count_two += 1
    else:
        odd += 1

ans = 'No'
if count_two == 0:
    if count_four + 1 >= odd:
        ans = 'Yes'
else:
    if count_four >= odd:
        ans = 'Yes'

print(ans)

Submission status: Accepted

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

ctr_4 = 0
ctr_2 = 0

for a in A:
	if a % 4 == 0:
		ctr_4 += 1
	elif a % 2 == 0:
		ctr_2 += 1
		
N -= ctr_2		
# print(ctr_4, ctr_2)
if ctr_2 == 0:
	need = N // 2
else:	
	need = (N + 1) // 2

if ctr_4 >= need:
	print("Yes")
else:
	print("No")

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
A = MAP()

fours = len([a for a in A if not a%4])
twos = len([a for a in A if not a%2]) - fours

# print(fours, twos)

if N % 2:
	if fours * 2 + 1 + twos >= N:
		print('Yes')
	else:
		print('No')
else:
	if fours * 2 + twos >= N:
		print('Yes')
	else:
		print('No')

Submission status: Accepted

Solution code:
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

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

N=one_int()
X=many_int()

count4=0
count2=0

for i in X:
    if i%4==0:
        count4+=1
    if i%2==0:
        count2+=1
        

count_sa = count2 - count4
count = count4 + count_sa//2

if count >= len(X)//2:
    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()))

n0,n2,n4 = 0,0,0
for a in A:
    if a%4==0: n4+=1
    elif a%2==0: n2+=1
    else: n0+=1

if n2==0:
    print('Yes' if n0<=n4+1 else 'No')
else:
    print('Yes' if n0<=n4   else 'No')

Submission status: Accepted

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

bine1 = 0
bine4 = 0
bine2 = 0

for a in al:
    if a % 4 == 0:
        bine4 += 1
    if a % 4 != 0 and a % 2 == 0:
        bine2 += 1
    if a % 2 != 0:
        bine1 += 1

if bine4 == 0 and bine1 > 0:
    print("No")
elif bine2 == 0 and bine4 +1 >= bine1:
    print('Yes')
elif bine4 >= bine1:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    n = int(input())
    aa = LI()
    c4 = c2 = 0
    for a in aa:
        if a % 4 == 0:
            c4 += 1
        elif a % 2 == 0:
            c2 += 1
    max_len = 0
    if c4 > 0 and c2 > 1:
        max_len = c4 * 2 + c2
    elif c4 > 0:
        max_len = c4 * 2 + 1
    elif c2 > 1:
        max_len = c2
    if n <= max_len:
        print("Yes")
    else:
        print("No")

main()

Submission status: Accepted

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

count4 = 0
count2_except4 = 0
for i in range(n):
    if a[i] % 4 == 0:
        count4 += 1
    elif a[i] % 2 == 0:
        count2_except4 += 1
if count4 * 2 + 1 >= n:
    print('Yes')
elif count2_except4 >= n - 2 * count4:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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
if cnt2 >= 2:
    com = N - cnt2 + 1
else:
    com = N
if com // 2 <= cnt4:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

#必要な4の倍数の数
need = n//2

#２の倍数、4の倍数の数
two = 0
four = 0
for num in a:
  if num%2 == 0:
    two += 1
  if num%4 == 0:
    four += 1
    
two -= four

if four + (two//2) >= need:
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

x = 0
y = 0
z = 0
for i in range(N):
    if A[i]%4 == 0:
        x += 1
    elif A[i]%2 == 0:
        y += 1
    else:
        z += 1
        
if y == 0 and z <= x+1:
    ans = "Yes"
elif y != 0 and z <= x:
    ans = "Yes"
else:
    ans = "No"
    
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
four = [i for i in a if i%4==0]
even = [j for j in a if j%2==0 and j!=2 and j%4!=0]
if n//2 <= len(four) or n//2 <= len(four)+a.count(2)//2 or n//2<=len(four)+a.count(2)//2 + len(even)//2:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

fours = 0
twos = 0
ones = 0
for i in range(N):
    if A[i] % 4 == 0:
        fours += 1
    elif A[i] % 2 == 0:
        twos += 1
    else:
        ones += 1

if twos:
    ones += 1

if ones <= fours + 1:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.buffer.readline


def main():
    N = int(readline())
    A = list(map(int, readline().split()))

    B = []
    C = []
    for a in A:
        if a % 4 == 0:
            B.append(a)
        else:
            C.append(a)

    if len(C) <= len(B) + 1:
        print('Yes')
    else:
        cnt = 0
        for c in C:
            if c % 2 == 0:
                cnt += 1
        if len(C) - cnt < len(B) + 1:
            print('Yes')
        else:
            print('No')


main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

cnt1,cnt2=0,0
for i in a:
  if i%4==0:
    cnt1+=1
  elif i%2==0:
    cnt2+=1
if cnt2>0:
  tmp=n-cnt2+1
else:
  tmp=n
if cnt1>=tmp//2:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
odds = len(list(filter(lambda x: x%2 == 1,A)))
baisu4 = len(list(filter(lambda x: x%4 == 0,A)))
evens = N-odds
if odds == 0:print('Yes')
elif evens == baisu4 and baisu4+1 >= odds:
    print('Yes')
elif evens != baisu4 and baisu4 >= odds:
    print('Yes')
else:
    print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
fCount = 0
tCount = 0
oCount = 0

for i in range(n):
    if a[i] % 4 == 0:
        fCount += 1
    elif a[i] % 2 == 0:
        tCount += 1
    else:
        oCount += 1

ans = 0
# ans = n - fCount * 3 - (tCount // 2) * 2
#print(fCount, tCount)

if tCount > 1:
    if fCount > 0:
        if oCount >= fCount:
            ans = n - (2 * fCount + 1) - tCount + 1
        else:
            #print(2 * fCount + 1 + tCount)
            ans = n - (2 * fCount + 1) - tCount
    else:
        ans = n - tCount
else:
    if fCount > 0:
        ans = n - (2 * fCount + 1)
    else:
        ans = n

#print(ans)

if ans > 0:
    print('No')
else:
    print('Yes')