Problem:


Score : 400 points

Problem Statement

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

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

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

Determine whether Snuke can achieve his objective.

Constraints

2 ≤ N ≤ 10^5

a_i is an integer.

1 ≤ a_i ≤ 10^9

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

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

Sample Input 1

3
1 10 100

Sample Output 1

Yes

One solution is (1, 100, 10).

Sample Input 2

4
1 2 3 4

Sample Output 2

No

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

Sample Input 3

3
1 4 1

Sample Output 3

Yes

The condition is already satisfied initially.

Sample Input 4

2
1 1

Sample Output 4

No

Sample Input 5

6
2 7 1 8 2 8

Sample Output 5

Yes



Sample input:
3
1 10 100


Sample output:
Yes

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
a=map(int,input().split())
odd=[]
even=[]
adj=[]
for i in a:
    if i%2:odd.append(i)
    else:even.append(i)
    if i%4==0:adj.append(i)
L=len(adj)-len(odd)
if L+1>0:
    print("Yes")
    exit()
if L==-1:
    print(["Yes","No"][len(even)-len(adj)>0])
else:print("No")

Submission status: Accepted

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

num4 = 0
num2 = 0
odd = 0
for i in a:
    if i%4 == 0:
        num4 += 1
    elif i%2 == 0 and i%4 != 0:
        num2 += 1
    elif i%2 == 1:
        odd += 1

if odd > num4+1:
    print("No")
else:
    if num2%2 == 1:
        if odd+1 > num4+1:
            print("No")
        else:
            print("Yes")
    else:
        print("Yes")

Submission status: Accepted

Solution code:
n,*l=map(int,open(0).read().split());o=t=0
for i in l: 
	o+=i%2
	t+=(i%4>0)
print("YNeos"[o>n-t+(t==o)::2])

Submission status: Accepted

Solution code:
n,*l=map(int,open(0).read().split());o=t=0
for i in l: 
	o+=i%2
	t+=(i%4>0)
print("YNeos"[(t>o)+o>n-t+1::2])

Submission status: Accepted

Solution code:
_,*l=map(int,open(0).read().split());o=t=0
for i in l: 
	o+=i%2
	t+=(i%4>0)
print("YNeos"[(t>o)+o>len(l)-t+1::2])

Submission status: Accepted

Solution code:
n,*l=map(int,open(0).read().split())
o=t=f=0
for i in l:
	if i%4==0:f+=1
	elif i%2==0:t+=1
	else:o+=1
print("YNeos"[(t>0)+o>f+1::2])

Submission status: Accepted

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

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

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

Submission status: Accepted

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

d = {2:0, 4:0, 1:0}

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

d[2] = d[2] % 2

if d[2] == 0:
  if d[1] - 1 <= d[4]:
    print("Yes")
  else:
    print("No")
else:
  if d[1] <= d[4]:
    print("Yes")
  else:
    print("No")

Submission status: Accepted

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

b1 = 0
b2 = 0
b4 = 0

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

flg = True
if b2 == 0:
    if b1 > b4 + 1:
        flg = False
else:
    if b1 > b4:
        flg = False

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

Submission status: Accepted

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

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

if cnt[2] > 0:
    if cnt[4] >= cnt[1]:
        print('Yes')
    else:
        print('No')
else:
    if cnt[4] + 1 >= cnt[1]:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, fractions, itertools

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(N: int, a: "List[int]"):
    four = len([aa for aa in a if aa % 4 == 0])
    two = len([aa for aa in a if (aa % 4 != 0 and aa % 2 == 0)])
    if two < 2:
        ex = four * 2 + 1
    else:
        ex = two + four * 2
    if ex >= N:
        print('Yes')
    else:
        print('No')
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, a)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
an = list(map(int,input().split()))
odds_cnt = sum(list(map(lambda x : x % 2,an)))
multiple_of_4_cnt = sum([1 if i %4==0 else 0 for i in an])
ret = "No"
if multiple_of_4_cnt >= odds_cnt or (multiple_of_4_cnt == odds_cnt-1 and odds_cnt+multiple_of_4_cnt==n):
    ret = "Yes"
print(ret)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
D = [0]*5
for a in A:
    if a % 4 == 0:
        D[4] += 1
    elif a % 2 == 0:
        D[2] += 1
    else:
        D[1] += 1

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



# any 4 any
# (2,4) 4 (,4)
# 4 1 4

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

count_1 = 0
count_2 = 0
count_4 = 0

for i in range(N):
    if a[i] % 4 == 0:
        count_4 += 1
    elif a[i] % 2 == 0:
        count_2 += 1
    else:
        count_1 += 1

if count_2 == 0:
    if count_4 + 1 >= count_1:
        print('Yes')
    else:
        print('No')
else:
    if count_4 >= count_1:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
N = int(input())
nums = list(map(int, input().split()))
two = 0
four = 0
for num in nums:
  if num%4 == 0:
    four += 1
  elif num%2 == 0:
    two += 1
if four + two//2 >= N//2:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math
import itertools
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    a = inputList()
    
    tmp = 0
    gu = 0
    for i, val in enumerate(a):
        if val % 4 == 0:
            tmp += 1
            continue
        if val % 2 == 0:
            gu += 1
            
    if tmp >= N // 2:
        print("Yes")
        sys.exit()
    
    aaa = (N // 2) - tmp
    gugu = gu // 2
    #print("{} {}".format(aaa, gu))
    if aaa <= gugu:
        print("Yes")
        sys.exit()
        
    print("No")
    
    
if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
c1=c2=0
for i in range(n):
    if a[i]%2==0:c1+=1
    if a[i]%4==0:c2+=1
c1-=c2
if c2*2>=n-1:print('Yes')
else: print('YNeos'[2*c2+c1<n::2])

Submission status: Accepted

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

Submission status: Accepted

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

odd_cnt = 0
four_times_cnt = 0
two_times_cnt = 0
for a in A:
    if a % 2 == 1:
        odd_cnt += 1
    elif a % 4 == 0:
        four_times_cnt += 1
    elif a % 2 == 0:
        two_times_cnt += 1

if two_times_cnt >= 1:
    if odd_cnt <= four_times_cnt:
        print('Yes')
    else:
        print('No')
else:
    if odd_cnt <= four_times_cnt + 1:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

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

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

if a2 == 0:
    if a4 >= a0-1:
        print('Yes')
    else:
        print('No')
elif a0 == 0:
    print('Yes')
else:
    if a4 >= a0:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
n=int(input())
l=list(map(int,input().split()))
n4=sum([i%4==0 for i in l])
n2=sum([i%2==0 for i in l])-n4
if n4>=max(n//2,1):
    print("Yes")
else:
    if (n//2)*2-n4*2<=n2:
        print("Yes")
    else:print("No")

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007

#A
def A():
    n, m = LI()
    print((n-1)*(m-1))
    return

#B
def B():
    s = S()
    print(s[0]+str(len(s)-2)+s[-1])
    return

#C
def C():
    II()
    a = LI()
    a1 = 0
    a2 = 0
    a3 = 0
    for ai in a:
        if not ai % 4:
            a3 += 1
            continue
        if not ai % 2:
            a2 += 1
            continue
        a1 += 1
    if a2:
        print(["No", "Yes"][a3 >= a1])
        return
    print(["No", "Yes"][a3 >= a1 - 1])
    return
    """
    n, m = LI()
    x = -1
    y = -1
    z = -1
    for i in range(n + 1):
        a = m - 9000 * i - 1000 * n
        if a % 4000 == 0 and a >= 0 and n - i - a / 4000 >= 0:
            y = a / 4000
            z = n - i - y
            x = i
            break
    print(int(x),int(y),int(z))
    """
#D
def D():
    return

#Solve
if __name__ == '__main__':
    C()

Submission status: Accepted

Solution code:
N = int(input())
a = [int(i) for i in input().split()]
n2,n4,odd = 0, 0, 0

for i in a:
  if i % 2 == 1:
    odd += 1
  elif i % 4 == 0:
    n4 += 1
  else:
    n2 += 1
if n2 == 0 and n4 >= odd-1:
  print("Yes")
elif n2 > 0 and n4 >= odd:
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

c = 0  # 4の倍数と奇数の出現数の差
f1 = False  # 2の倍数だが4の倍数ではない
for aa in a:
    if aa % 4 == 0:
        c += 1
    elif aa % 2 == 0:
        f1 = True
    elif aa % 2 == 1:
        c -= 1

x = 0 if f1 else -1
print('Yes' if c >= x else 'No')

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
n=int(input())
a_list=list(map(int,input().split()))
a_13=0
a_2=0
a_0=0
for i in a_list:
    m=i%4
    if m==0:
        a_0+=1
    elif m==2:
        a_2+=1
    else:
        a_13+=1
if a_0>=a_13:
    print('Yes') 
else:
    if a_0==a_13-1 and a_0+a_13==n:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
import sys


fin = sys.stdin.readline
N = int(fin())
a_list = [int(elem) for elem in fin().split()]
num_dividable_by_4 = 0
num_dividable_by_2 = 0
for a in a_list:
    if a % 4 == 0:
        num_dividable_by_4 += 1
    elif a % 2 == 0:
        num_dividable_by_2 += 1
num_odds = N - num_dividable_by_2 - num_dividable_by_4
if not num_dividable_by_2:
    is_objective_viable = num_dividable_by_4 >= num_odds - 1
else:
    is_objective_viable = num_dividable_by_4 >= num_odds
print("Yes" if is_objective_viable else "No")

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
a = LIST()

x = 0  # 2 を含まない
y = 0  # 2^1 のみを含む
z = 0  # 2^2を含む
for num in a:
	if num % 2 == 1:
		x += 1
	elif num % 4 == 0:
		z += 1
	else:
		y += 1

if y:
	x += 1


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

else:
	if z >= x:
		print("Yes")
	else:
		print("No")

Submission status: Accepted

Solution code:
N = int(input())
*A, = map(int,input().split())
c = [0]*3
for a in A:
    if a%2:c[0]+=1
    elif a%4:c[1]+=1
    else:c[2]+=1
if c[1]==1: c[0:2] = [c[0]+1,0]
if c[1]==0:
    ans = c[2]>0 and c[0]<=c[2]+1
else:
    ans = c[0]<=c[2]
print("Yes" if ans else "No")

Submission status: Accepted

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

if Devide_by_Four >= len(a)//2:
    print("Yes")
elif Devide_by_Four >= Odd:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#ABC69 C

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

total = 0
for i in a:
    if i % 2 == 0 and i % 4 != 0:
        total += 1/2
    elif i % 4 == 0:
        total += 1
if total >= n//2:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
def f(n, A):
    odd = 0
    four = 0

    for a in A:
        if a % 2 == 1:
            odd += 1
        if a % 4 == 0:
            four += 1

    if odd == 0:
        return True

    if n % 2 == 0:
        return odd - four <= 0
    else:
        return odd - four <= 1


n = int(input())
A = list(map(int, input().split()))
print("Yes" if f(n, A) else "No")

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    ni = 0
    yon = 0
    ans = "No"
    for a in input().split():
        a = int(a)
        if a % 4 == 0:
            yon += 1
        elif a % 2 == 0:
            ni += 1

    if int(N / 2) <= yon:
        ans = "Yes"
    elif (N-2*yon) <= ni:
        ans = "Yes"

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

if (N // 2) > four_count:
    tmp = (N // 2) - four_count
    if two_count >= tmp * 2:
        print("Yes")
        exit()
    else:
        print("No")
        exit()
else:
    print("Yes")

Submission status: Accepted

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

four = len(a)-len(list(filter(lambda x:x%4, a)))
two = len(a)-len(list(filter(lambda x:x%2, a))) - four
no = len(a) - four - two

if two: print("YNeos"[no>four::2])
else: print("YNeos"[no-four>1::2])

Submission status: Accepted

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

a1 = 0
a2 = 0
a4 = 0

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

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

Submission status: Accepted

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

four = len(list(filter(lambda x: x % 4 == 0, A)))
two = len(list(filter(lambda x: x % 2 == 0 and x % 4 != 0, A)))
odd = N - two - four

if odd == 0 and two % 2 == 0:
    print('Yes')
elif four > 0 and odd + two % 2 <= four + 1:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
b,c=[],[]
d=0
for i in range(n):
    if a[i]%4==0:
        b.append(1)
    elif a[i]%4!=0 and a[i]%2!=0:
        c.append(1)
    elif a[i]%4!=0 and a[i]%2==0:
        d+=1
b=sum(b)
c=sum(c)
if d>=1 and c<=b:
    print("Yes")
elif c<=b+1 and d==0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

four=0
two=0
for i in range(n):
    if a[i]%4==0:
        four+=1
    elif a[i]%2==0:
        two+=1
if two>0:
    ans=four*2+two
else:
    ans=four*2+1

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

Submission status: Accepted

Solution code:

N = int(input())

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

Fo = 0
Tw = 0
Od = 0

for i in a:

    if i % 4 == 0:
        Fo += 1

    elif i % 2 == 0:
        Tw = 1

    else:
        Od += 1

if Tw + Od <= Fo + 1:

    print ("Yes")

else:
    print ("No")

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
odd = by2 = by4 = 0
for c in a:
    if c % 4 == 0:by4 += 1
    elif c % 2 == 0:by2 += 1
    else:odd += 1

if N == 2:
    if by4>=1:print('Yes')
    elif by2 == 2:print('Yes')
    else:print('No')
elif N == 3:
    if odd == 3:print('No')
    elif odd==2:
        if by4==1:print('Yes')
        else:print('No')
    elif odd==1:
        if by4>=1:print('Yes')
        else:print('No')
    else:print('Yes')
else:
    if by2 > 0:
        if by4-odd>=0:print('Yes')
        else:print('No')
    else:
        if by4-odd>=-1:print('Yes')
        else:print('No')

Submission status: Accepted

Solution code:
# ABC069C - 4-adjacent (ARC080C)
def main():
    n = int(input())
    A = tuple(map(int, input().rstrip().split()))
    f, t, m = 0, 0, 0  # two, four, misc
    for i in A:
        if i % 4 == 0:
            f += 1
        elif i % 2 == 0:
            t += 1
        else:
            m += 1
    m += t % 2
    print("Yes" if m - f <= 1 else "No")


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
*A, = map(int, input().split())
counter = {0: 0, 2: 0, 4: 0}
for a in A:
    _, r = divmod(a, 4)
    if r == 0: counter[4] += 1
    elif r == 2: counter[2] += 1
    else: counter[0] += 1
print('Yes' if counter[0] <= counter[4] or (counter[0] == counter[4] + 1 and counter[2] == 0) else 'No')

Submission status: Accepted

Solution code:
def main():
    _ = int(input())
    A = list(map(int, input().split()))
    b1 = 0
    b2 = 0
    b4 = 0
    for a in A:
        if a % 2 == 0:
            if a % 4 == 0:
                b4 += 1
            else:
                b2 += 1
        else:
            b1 += 1
    if b2 > 0:
        if b4 >= b1:
            print('Yes')
            return
    else:
        if b4 + 1 >= b1:
            print('Yes')
            return
    print('No')


main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
Odd,Four=0,0
for a in A:
    if a%2==1:Odd+=1
    elif a%4==0:Four+=1
if Odd+Four==N and Odd-Four==1:print("Yes")
elif Odd<=Four:print("Yes")
else:print("No")

Submission status: Accepted

Solution code:
N = int(input())

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

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


subcount = 0
subcount = scount // 2

# subcount = min(scount, sscount)

if N % 2 == 0:
    _l = int(N / 2)
    if _l <= subcount + count:
        print('Yes')
        exit()

else:
    _l = N // 2
    if _l <= subcount + count:
        print('Yes')
        exit()


print('No')

Submission status: Accepted

Solution code:
N=int(input())
d4=0
d2=0
for a in input().split():
    if int(a)%4==0:
        d4+=1
    elif int(a)%2==0:
        d2+=1


if N%2==1 and d2==0 and (N-1)//2<=d4:
    print('Yes')
elif 2*d4+d2>=N:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
fac0 = 0
fac2 = 0
for x in a:
    if x % 2 == 1:
        fac0 += 1
    elif x % 4 == 0:
        fac2 += 1
if fac0 <= fac2 or fac0 == fac2 + 1 and 2 * fac2 + 1 == N:
    result = "Yes"
else:
    result = "No"
print(result)

Submission status: Accepted

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


four = 0
two = 0
els = 0

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

if two == 0:
    if four + 1 >= els:
        print('Yes')
    else:
        print('No')
else:
    if four >= els:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:

def main():
    num = int(input())
    data = list(map(int, input().split()))

    saikyo, hutu, dame = 0, 0, 0
    for ele in data:
        if ele % 4 == 0:
            saikyo += 1
        elif ele % 2 == 0:
            hutu += 1
        else:
            dame += 1

    flg = 1
    if saikyo + 1 < dame:
        flg = 0
    if dame == saikyo + 1 and hutu > 0:
        flg = 0

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




if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N = n()
A = nl()

odds = 0
devens = 0
for a in A:
    if a % 2 == 1:
        odds += 1
    elif (a // 2) % 2 == 0:
        devens += 1

if devens >= odds:
    print('Yes')
elif devens == odds - 1 and devens + odds == N:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N = int(input())
*a, = map(int, input().split())
four, two, odd = 0, 0, 0
for i in a:
	if i % 4 == 0:
		four += 1
	elif i % 2 == 0:
		two += 1
	else:
		odd += 1

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

Submission status: Accepted

Solution code:
# encoding: utf-8
import sys
# input = sys.stdin.readline

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

cnt = [0] * N
for i, ai in enumerate(a):
    for cnti in range(128):
        if ai % (2 << cnti) > 0: break
    cnt[i] = cnti

cnt4 = 0
cnt2 = 0
cnt1 = 0
for cnti in cnt:
    if cnti < 1: cnt1 += 1
    elif cnti > 1: cnt4 += 1
    else: cnt2 += 1

# print("#", cnt)
if N < 2:
    if cnt[0] >= 2: print('Yes')
    else: print('No')
elif cnt2 == 0:
    if cnt4 == 0: print('No')
    elif cnt1 > cnt4 + 1: print('No')
    else: print('Yes')
else:
    if cnt1 > cnt4: print('No')
    else: print('Yes')

Submission status: Accepted

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

cnt1 = 0
cnt2 = 0
cnt4 = 0

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

if cnt2==0:
    if cnt4+1>=cnt1:
        print("Yes")
    else:
        print("No")
else:
    if cnt4>=cnt1:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

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

odd_count = 0
four_times_count = 0
two_times_count = 0
for i in a:
  if i % 4 == 0:
    four_times_count += 1 
  elif i % 2 != 0:
    odd_count += 1
  elif i % 2 == 0 and i % 4 != 0:
    two_times_count += 1

if odd_count == 0 or odd_count == four_times_count or (two_times_count == 0 and odd_count - four_times_count == 1):
  print('Yes')
else: 
  print('No')

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(N: int, a: "List[int]"):
    count = [0] * 3
    for v in a:
        if v % 4 == 0:
            count[2] += 1
        elif v % 2 == 0:
            count[1] += 1
        else:
            count[0] += 1
    if count[0] == count[2] + 1 and count[1] == 0:
        ret = YES
    elif count[0] > count[2]:
        ret = NO
    else:
        ret = YES
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, a)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

count4 = 0
count2 = 0
count0 = 0
for i in a:
    if i % 2 == 0:
        if i % 4 == 0:
            count4 += 1
        else:
            count2 += 1
    else:
        count0 += 1

if count0 <= count4:
    print ('Yes')
elif count0 == count4 + 1 and count2 == 0:
    print ('Yes')
else:
    print ('No')

Submission status: Accepted

Solution code:
n = int(input())
a = [int(_) % 4 for _ in input().split()]
e, f = a.count(2), a.count(0)
print(["No", "Yes"][f >= (n - 2 * (e // 2)) // 2])

Submission status: Accepted

Solution code:
n=int(input())
a=[int(_)%4 for _ in input().split()]
e=a.count(2);f=a.count(0)
print('Yes' if (n-e-1)//2<f or n//2==f else 'No')

Submission status: Accepted

Solution code:
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())
###template###

N = int(input())
As = list(mi())

cnt4 = 0
cnt2 = 0
cnt1 = 0

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

possiblelength = 0
if cnt1 ==0:
  print('Yes')
  exit()
if cnt4 >= 1 and cnt2 >= 1:
  possiblelength = (cnt4 * 2) + cnt2
elif cnt4 >= 1 and cnt2 == 0:
  possiblelength = cnt4 * 2 + 1
elif cnt4 == 0 and cnt2 >= 1:
  possiblelength = cnt2 -1
else:
  possiblelength = 0

if possiblelength >= N:
  print('Yes')
else: print('No')

Submission status: Accepted

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

count1 = 0
count2 = 0
count3 = 0
for i in range(n):
    if a[i] % 2 == 0 and a[i] % 4 != 0:
        count1 += 1
    elif a[i] % 4 == 0:
        count2 += 1
    else:
        count3 += 1

#print(count1, count2, count3)

if count2 >= n // 2:
    print("Yes")
elif count2 >= (n - 2 * (count1 // 2)) // 2:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

def main():

    a = A
    len_all = len(a)
    len_2 = len(list(filter(lambda n: n % 2 == 0 and n % 4 != 0, a)))
    len_4 = len(list(filter(lambda n: n % 4 == 0, a)))
    len_others = len(list(filter(lambda n: n % 2 != 0, a)))

    if len_all == len_2:
        ans = 'Yes'
    else:
        ans = 'Yes' if len_4 + 1 >= min(1, len_2) + len_others else 'No'
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
import math
N = int(input())
As =list(map(int,input().split(" ")))
odds = 0
two = 0
four = 0
nums = []
for a in As:
    if a % 2 == 1:
        odds += 1
    elif a % 4 == 0:
        four += 1
    else:
        two += 1
if odds > 0:
    nums.append(1)
    odds -= 1
elif two > 0:
    nums.append(2)
    two -=1
else:
    nums.append(4)
    four-=1
ans = "Yes"

if N==2:
    if As[0] * As[1]%4 !=0:
       ans = "No"
else:
    for i in range(1,N):
        if nums[i-1] == 1:
            if four > 0:
                nums.append(4)
                four -=1
            else:
                ans = "No"
                break
        elif nums[i - 1] == 2:
            if two> 0:
                nums.append(2)
                two -= 1
            elif four > 0:
                nums.append(4)
                four -=1
            else:
                ans = "No"
                break
        elif nums[i - 1] == 4:
            if odds> 0:
                nums.append(1)
                odds -= 1
            elif two> 0:
                nums.append(2)
                two -= 1
            elif four > 0:
                nums.append(4)
                four -=1

print(ans)