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(" ")))

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

print("Yes" if zero <= two+(one==0) else "No")

Submission status: Accepted

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

p = []
q = []
r = []

for i in range(n):
    if a[i] % 4 == 0:
        p.append(a[i])
    elif a[i] % 2 == 0:
        q.append(a[i])
    else:
        r.append(a[i])

s = len(p)
t = len(q)
u = len(r)

if t == 0:
    if u <= s + 1:
        print("Yes")
    else:
        print("No")
else:
    if u <= s:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
#強い人のコード
N=int(input())
ans='Yes'
odd=0
four=0
for x in map(int,input().split()):
    if x%2==1:
        odd+=1
    elif x%4==0:
        four+=1
#4の倍数+1が奇数の数より少ないとダメ
if four+1<odd:
    ans='No'
#4の倍数+1が奇数と同じかつその合計が全体より少ないとダメ（ひとつ奇数が余ることになる）
elif four+1==odd and odd+four<N:
    ans='No'
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
A=list(map(int,input().split()))
four=list(filter(lambda x:x%4==0,A))
even=list(filter(lambda x:x%2==0,A))
odd=list(filter(lambda x:x%2==1,A))
# print(len(even))
# print(len(odd))
# print(len(four))

#全ての成分が偶数
if len(even)==len(A):
  print('Yes')
  exit()
#4の倍数が奇数の半分以上ある（切り下げ）かつ2の倍数が偶数個かつ元が偶数個
if len(four)>=len(odd)/2 and (len(even)-len(four))%2==0:
  if (len(even)-len(four))%2>0:
    print('Yes')
    print('aa')
    exit()
# #4の倍数が奇数の半分以上ある（切り上げ）かつ4の倍数が奇数個あるかつ2の倍数が奇数個あるかつ元が奇数個
if len(four)>=len(odd)/2 and len(four)%2!=0 and len(A)%2!=0:
  print('Yes')
  exit()
if len(four)>=len(odd)/2 and len(four)%2==0 and len(A)%2==0:
  print('Yes')
  exit()
else:
  print('No')

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()));tmp=[i%4 for i in a]
four=tmp.count(0)
two=tmp.count(2)
print(["No","Yes"][(four+two//2)>=len(a)//2])

Submission status: Accepted

Solution code:
N = int(input())

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

cnt2 = 0
cnt4 = 0

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

cnt2_2 = cnt2 // 2 * 2

if (cnt2_2 + cnt4*2+1) >= N or  cnt2 == N:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N = int(input())
A = [int(_) for _ in input().split()]
count_odd = 0
count_4 = 0
count_2 = 0
for a in A:
    if a % 4 == 2:
        count_2 += 1
    elif a % 4 == 0:
        count_4 += 1
    else:
        count_odd += 1
if count_odd == count_4+1 and count_2 == 0 or count_odd <= count_4:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N=int(input())
ans='Yes'
odd=0
four=0
for x in map(int,input().split()):
    if x%2==1:
        odd+=1
    elif x%4==0:
        four+=1
if four+1<odd:
    ans='No'
elif four+1==odd and odd+four<N:
    ans='No'
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
# a : %4 == 0 ->前後に奇数があってもOK
# b : %4 == 2 ->前後も偶数ならOK
# c : %2 == 1 ->前後が4の倍数ならOK
# ex) cacacacac...のように「aの個数」は「cの個数-1」以上になる必要
# 「aの個数」=「cの個数-1」のとき「bの個数」は0つ
# それ以外はcacaca...cabbbbbと出来るのでbはいくつでもよい

table = [0 for i in range(3)]  # [%4==0, %4==2, %2==1]
for i in range(n):
    if a[i] % 4 == 0:
        table[0] += 1
    elif a[i] % 4 == 2:
        table[1] += 1
    else:
        table[2] += 1
if table[0] < table[2] - 1:
    print("No")
elif table[0] == table[2] - 1 and table[1] != 0:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
#a(i)とa(i+1)について、
#(1)二つとも偶数
#一つが4の倍数
#1,4,3,4,2,2,4,5
#2の個数はなんでも良いが、4でそのまとまりを挟む必要がある
#端に2をおけばあまり困らない
count4 = 0
count2 = 0
count_odd = 0
num_list = list(map(int, input().split()))
for i in num_list:
    if i % 4 == 0:
        count4 += 1
    elif i % 4 == 2:
        count2 += 1
    if i % 2 == 1:
        count_odd += 1
if count2 >= 1:
    real_count2 = 1
else:
    real_count2 = 0    
if count_odd == 0:
    print("Yes")
else:
    if count4 >= count_odd + real_count2 - 1:
        print("Yes")    
    else:
        print("No")

Submission status: Accepted

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

d4 = n // 2
d2 = 0
if n % 2 == 0:
    if c4 >= n // 2:
        print("Yes")
        exit()
    else:
        for i in range(n // 2):
            if i == 0:
                d4 -= 1
                d2 += 2
            elif i == n // 2 - 1:
                d4 -= 1
                d2 += 2
            else:
                d4 -= 1
                d2 += 2
            if c4 >= d4 and c2 >= d2:
                print("Yes")
                exit()
else:
    if c4 >= n // 2:
        print("Yes")
        exit()
    else:
        for i in range(n // 2):
            if i == 0:
                d4 -= 1
                d2 += 3
            elif i == n // 2 - 1:
                d4 -= 1
                d2 += 2
            else:
                d4 -= 1
                d2 += 2
            if c4 >= d4 and c2 >= d2:
                print("Yes")
                exit()
print("No")

Submission status: Accepted

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

divs = [a%4 for a in a_list]
mp_of_four = divs.count(0)
mp_of_two  = divs.count(2) 

if mp_of_four+mp_of_two//2 >= n//2:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

ki = 0
gu4 = 0
for i in A:
    if i % 4 == 0:
        gu4 += 1
    elif i % 2 != 0:
        ki += 1

if N % 2 != 0:
    if ki <= gu4 + 1:
        print('Yes')
    else:
        print('No')
else:
    if ki <= gu4:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = map(int, input().split(" "))
    x4 = 0
    x2 = 0
    x1 = 0
    for a in A:
        if a % 4 == 0:
            x4 += 1
        elif a % 2 == 0:
            x2 += 1
        else:
            x1 += 1
    maxlen = x4 * 2 + x2
    if x4 >= 1 and x2 == 0:
        maxlen += 1
    if maxlen >= N:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()

Submission status: Accepted

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

divide_4_cnt = 0
divide_2_cnt = 0
for n in A:
    if n % 4 == 0:
        divide_4_cnt += 1
    elif n % 2 == 0:
        divide_2_cnt += 1
divide_2_cnt = (divide_2_cnt // 2) * 2
N = N - divide_2_cnt

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = int(input())
ar = list(map(int,input().split()))
k = 0
g = 0
f = 0
for r in ar:
    if r % 4 == 0:
        f += 1
    elif r % 2 == 0:
        g += 1
    else:
        k += 1
if f == 0:
    if k == 0:
        print("Yes")
    else:
        print("No")
elif g == 0:
    if k - f <= 1:
        print("Yes")
    else:
        print("No")
elif k == 0:
    print("Yes")
else:
    if f >= k:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

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

f = 0
d = 0
for x in a:
    if x % 4 == 0:
        f += 1
    elif x % 2 == 0:
        d += 1

if 0 < d < n:
    d -= 1

if n > f * 2 + 1 + d:
    print('No')
else:
    print('Yes')

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
zero = N - two - four
if zero == four + 1:
    if two == 0:
        print("Yes")
    else:
        print("No")
elif zero > four:
    print("No")
else:
    print("Yes")

Submission status: Accepted

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

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

for i in a:
    if i % 4 == 0:
        mapa[4] += 1
    elif i % 2 == 0:
        mapa[2] += 1
    else:
        mapa[1] += 1
if mapa[2] > 0:
    mapa.pop(2)
    mapa[1] += 1
if mapa[1] > mapa[4] + 1:
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
import sys
def 解():
    input = sys.stdin.readline
    iN = int(input())
    m4,m2,m1 = 0,0,0

    def fp():
        print("Yes")
    def fn():
        print("No")
    for a in input().split():
        a = int(a)
        if a % 4 ==0:
            m4 += 1
        elif a % 2 == 0:
            m2 += 1
        else:
            m1 += 1
    if m2 :
        if m1 <= m4:
            fp()
        else:
            fn()
    else:
        if m1 <= m4 + 1:
            fp()
        else:
            fn()
解()

Submission status: Accepted

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

b = [i%4 for i in a]
four = b.count(0)
two = b.count(2)
if four + two//2 >= len(a)//2:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

ans = 0
for a in A:
    if a % 4 == 0:
        ans += 1
    elif a % 2 != 0:
        ans -= 1
if N % 2 != 0:
    ans += 1
print('Yes' if ans >= 0 else 'No')

Submission status: Accepted

Solution code:
import collections

def per4_2(x):
	if x % 4 == 0:
		return 4
	elif x % 2 == 0 and x % 4 != 0:
		return 2
	else:
		return 1


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

a = list(map(per4_2,a))


a_c=collections.Counter(a)

ans = 'No'

if a_c[2] == 0:
	if a_c[4]>=a_c[1]-1:
		ans = 'Yes'
else:
	if a_c[4] >=a_c[1]:
		ans = 'Yes'
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int, input().split()))

nodd = 0
neven = 0
n4 = 0

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

res = 'No'

if neven==0 and n4+1 >= (nodd):
  res = 'Yes'
elif n4+1 >= (nodd+1):
  res = 'Yes'
elif nodd==0:
  res = 'Yes'

print(res)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
i,j,k=0,0,0
for m in a:
    if m%4==0:
        i+=1
    elif m%2==0:
        j+=1
    else:
        k+=1
if j==0:
    if i>=k-1:
        print('Yes')
    else:
        print('No')
else:
    if i>=k:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
an = list(map(int, input().split()))

m4 = []
m2 = []
mo = []

for a in an:
    if a%4 == 0:
        m4.append(a)
    elif a%2 == 0:
        m2.append(a)
    else:
        mo.append(a)

if len(m4) >= len(mo):
    print('Yes')
elif len(m2) == 0 and len(m4) >= len(mo) - 1:
    print('Yes')
else:        
    print('No')

Submission status: Accepted

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

if (four + odd) % 2 == 0:
    if four >= odd:
        print("Yes")
    else:
        print("No")
else:
    if four > odd:
        print("Yes")
    elif four == (four + odd)//2 and two == 0:
        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 ai in a:
    if ai % 2 == 1:
        cnt_odd += 1
    if ai % 4 == 0:
        cnt_4 += 1
        
if cnt_4 >= cnt_odd:
    ans = "Yes"
else: 
    ans = "No"

if N == cnt_4 + cnt_odd and cnt_4 >= cnt_odd-1:
    ans = "Yes"
    
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin

n = int(stdin.readline().rstrip())
a = [int(x) for x in stdin.readline().rstrip().split()]
bai_2 = 0
bai_4 = 0
bai_1 = 0

for i in range(n):
    if a[i] % 4 == 0:
        bai_4 += 1
    elif a[i] % 2 == 0:
        bai_2 += 1
    else:
        bai_1 += 1
        
if bai_2 == 0:
    if bai_4 >= bai_1 - 1:
        print("Yes")
    else:
        print("No")
else:
    if bai_4 >= bai_1:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
N = int(input())
a = [int(i) for i in input().split()]
n2 = 0; n4 = 0
for ai in a:
    if ai%4 == 0:
        n4 += 1
    elif ai%2 == 0:
        n2 += 1

ans = "No"
if n4*2+1 >= N or n4*2 >= N-n2 or n2 == N:
    ans = "Yes"

print(ans)

Submission status: Accepted

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

bai_4 = 0
bai_2 = 0

for a in A:
    if a%4 == 0:
        bai_4 += 1
    elif a%2 == 0:
        bai_2 += 1

ch = N - bai_4 * 2 - bai_2

if ch <= 0:
    print('Yes')
elif ch == 1 and N%2 == 1:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

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

if n<=(2*c4 + max(1,c2-c4)):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
# coding:utf-8

INF = float('inf')


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


N = int(input())
A = inpl()

mod2 = 0
mod4 = 0
for a in A:
    if a % 2 == 0:
        mod2 += 1
    if a % 4 == 0:
        mod4 += 1

if mod4 >= N // 2:
    print('Yes')
elif mod2 - mod4 >= 2 and N - mod2 <= mod4:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

Submission status: Accepted

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

index=0
countTwo =0
countFour=0
while index < len(listA):
    if listA[index]%4 ==0:
        countFour+=1
    elif listA[index]%2 ==0:
        countTwo+=1
    else:
        pass
    index+=1

if countFour + countTwo//2 > n//2-1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

b = []
for i in range(n):
    count = 0
    while a[i] % 2 == 0:
        a[i] = a[i] // 2
        count += 1
    b.append(count)

n0 = 0
n2 = 0
n4 = 0
for i in range(n):
    if b[i] == 0:
        n0 += 1
    elif b[i] == 1:
        n2 += 1
    else:
        n4 += 1

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

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
a = list(li())

mod2 = 0
odd = 0
mod0 = 0

for ai in a:
    if ai%4 == 0:
        mod0 += 1
    elif ai%2 == 0:
        mod2 = 1
    else:
        odd += 1
        
odd += mod2


if mod0 >= (odd-1):
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

if odd <= x4:
    print('Yes')
elif odd == x4+1:
    print('Yes' if x4+odd == N else 'No')
else:
    print('No')

Submission status: Accepted

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

if N % 2 != 0:
    ans += 1

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

Submission status: Accepted

Solution code:
N = int(input())
T = list(map(int, input().split()))
ans = 0

for i in range(N):
    if T[i] % 4 == 0:
        ans += 1
    elif T[i] % 2 != 0:
        ans -= 1
    
if N % 2 != 0:
    ans += 1

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

'''
for文は  if 4で割り切れる elif 4で割り切れないものの中で2でも割り切れない数字→つまり奇数　のみを判断する
基本的には0の個数分だけ4で割り切れるものが必要になってくる
しかし配列の個数が奇数個の場合 [0 4 0 4 0]で0の個数よりも1個少ない数で対応できたりするのでそれも考慮しとく
'''

Submission status: Accepted

Solution code:
N = int(input())
T = list(map(int, input().split()))
ans = 0

for i in range(N):
    if T[i] % 4 == 0:
        ans += 1
    elif T[i] % 2 != 0:
        ans -= 1
    
if N % 2 != 0:
    ans += 1

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
n1 = 0
n2 = 0
n4 = 0
for i in a:
    if i%2 != 0:
        n1 += 1
    elif i%4 == 0:
        n4 += 1
    else:
        n2 += 1
        
if n2 == 0:
    if n1 <= n4+1:
        ans = 'Yes'
    else:
        ans = 'No'
else:
    if n1 <= n4:
        ans = 'Yes'
    else:
        ans = 'No'

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
a = input().split()
a = [int(i) for i in a]
single = 0
double = 0
triple = 0
for i in a:
    if i %2 ==1:
        single +=1
    elif i %4 != 0:
        double +=1
    else:
        triple +=1
if N//2 <= (double* 0.5 + triple):
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#ABC069C
N=int(input())
a=list(map(int,input().split()))
#奇数、4の倍数の数を数える。2の倍数だが4の倍数でないものの数は数えなくてよい。
odd=0
four=0
for i in range(N):
    if a[i]%2==1:
        odd+=1
    elif a[i]%4==0:
        four+=1
#4の倍数の個数が奇数の個数以上であればOK
if four>=odd:
    print('Yes')
#4の倍数の個数が奇数の個数-1の時は、他に数が無ければOK
elif four+1==odd and four+odd==N:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


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

    four, two = 0, 0

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

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

    four = 0
    two = 0

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


    if two > 0:
        if (n-two)/2 <= four:
            print("Yes")
        else:
            print("No")
    else:
        if n//2 <= four:
            print("Yes")
        else:
            print("No")


if __name__ == "__main__":
        main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
n_four, n_two, n_other = 0, 0, 0
for ai in map(int, input().split()):
    if ai % 4 == 0:
        n_four += 1
    elif ai % 2 == 0:
        n_two += 1
    else:
        n_other += 1

if n_two == 0 and n_four + 1 >= n_other:
    print('Yes')
elif n_two > 0 and n_four >= n_other:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

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

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] >= -1:
        print("Yes")
    else:
        print("No")
else:
    if d[4] - d[1] >= 0:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
from collections import Counter
N=int(input())
A=list(map(int, input().split()))
for i in range(len(A)):
    A[i]%=4
# print(A)
cnt=dict(Counter(A).items())
# print(cnt)
num0=0
if 2 in cnt:
    cnt[2]=1
if 0 in cnt:
    num0=cnt[0]
    cnt.pop(0)
num1=sum(list(cnt.values()))
print("Yes" if num1<=num0+1 else "No")

Submission status: Accepted

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

multi4 = len([a for a in a_list if a % 4 == 0])
odd_num = len([a for a in a_list if a % 2 != 0])

even_num = len(a_list) - odd_num
not4 = even_num - multi4

if not4 >0 :
    if odd_num <= multi4:
        print("Yes")
    else:
        print("No")

else:
    if odd_num <= multi4 + 1:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
N = int(input())

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

nl = [0] * 3

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

# 2は2個以上あればとりあえず全部繋げとけば良い、1個だけなら１としてカウント同じ
if nl[1] == 1:
  nl[0] += 1

# 2が2個以上あれば、2.....2,4,1,4,1 num_4 >= num_1の形を満たせばOK
# ２が1,0個なら、1,4,1,4,...4,1 num_4 + 1 >= num_1の形を満たせばOK
if nl[1] >= 2 and nl[2] >= nl[0]:
  print("Yes")
elif nl[1] <= 1 and nl[2] >= nl[0] - 1:
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

counts = {4:0, 2:0, 1:0}
for i in range(n):
    if a[i]%4 == 0:
        counts[4] += 1
    elif a[i]%2 == 0:
        counts[2] += 1
    else:
        counts[1] += 1

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

Submission status: Accepted

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

num2 = 0
num4 = 0
for v in a:
    if v % 4 == 0:
        num4 += 1
    elif v % 2 == 0:
        num2 += 1

if num4 >= n // 2:
    print('Yes')
elif num4 * 2 + num2 >= n:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


# --------------------------------------------

dp = None


def main():
    N = int(input())
    L = li_input()

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

    if x2 == 0:
        if x1 - 1 <= x4:
            print("Yes")
        else:
            print("No")
    else:
        if x1 <= x4:
            print("Yes")
        else:
            print("No")


main()

Submission status: Accepted

Solution code:
N,*A=map(int,open(0).read().split())
x=y=0
for a in A:
    if a%4==0:x+=1
    elif a%2==0:y+=1
print(['No','Yes'][x+y//2>=N//2])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int( input())
A = list( map( int, input().split()))
zero = 0
ni = 0
yon = 0
for a in A:
    if a%2 == 1:
        zero += 1
    elif not a%4 == 0:
        ni += 1
    else:
        yon += 1
if ni == 0:
    if yon + 1 >= zero:
        print('Yes')
    else:
        print('No')
else:
    if yon >= zero:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
div_1 = div_2 = div_4 = 0
for i in a:
    if i%4==0:
        div_4 += 1
    elif i%2==0:
        div_2 += 1
    else:
        div_1 += 1

if div_4==div_1 or div_4==div_1+1 or (div_1==0 and div_2!=1) or (div_2==0 and (div_4==div_1 or div_4+1==div_1 or div_4==div_1+1)):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:

# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from pprint import pprint
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def Prim(g):
    V = list(g.keys())
    for v in g.values():
        V.extend(list(v.keys()))
    V = list(set(V))

    used = set([])
    q = []
    heapq.heappush(q, (0, V[0]))

    ret = 0
    while q:
        c, v = heapq.heappop(q)

        if v in used:
            continue
        used.add(v)
        ret += c
        for u in g[v]:
            heapq.heappush(q, (g[v][u], u))
    return ret


@mt
def slv(N, A):
    c = Counter()

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

    if c[0] - c[2] > 1:
        return 'No'

    if c[0] - c[2] == 1 and c[1] > 0:
        return 'No'

    return 'Yes'


def main():
    N = read_int()
    A = read_int_n()

    print(slv(N, A))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
b = int(input())

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

co = 0
s = 0
ss = 0

for i in range(len(a)):
  while a[i] % 2 == 0:
    co += 1
    a[i] //= 2
  if co == 1:
    s += 1
  elif co >= 2:
    ss += 1
  co = 0
  
b -= s

if b % 2 == 1 and s > 0:
  b += 1
elif b % 2 == 1 and s == 0:
  b -= 1
b //= 2

if ss >= b:
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

c = {0: 0, 2: 0, 4: 0}
for ai in a:
    if ai % 4 == 0:
        c[4] += 1
    elif ai % 2 == 0:
        c[2] += 1
    else:
        c[0] += 1

if c[0] <= c[4]:
    print('Yes')
elif c[0] + c[2] <= c[4] + 1:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N = int(raw_input())
A = map(int, raw_input().split())
c = [0, 0, 0]
for a in A:
  if a%4==0:
    c[2]+=1
  elif a%2==0:
    c[1]+=1
  else:
    c[0]+=1
while sum(c)>0:
  if c[0]==0:
    print 'Yes'
    break
  elif sum(c)==1:
    print 'Yes'
    break
  elif c[2]==0:
    print 'No'
    break
  else:
    c[0]-=1
    c[2]-=1

Submission status: Accepted

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

x = 0 # 4の倍数の数
y = 0 # 2の倍数の数
z = 0 # それ以外の数
for a in A:
    if a % 4 == 0:
        x += 1
    elif a % 2 == 0:
        y += 1
    else:
        z += 1

if x == 0:
    if z > 0:
        print('No')
    else:
        print('Yes')
else:
    if y == 0:
        if x+1 >= z:
            print('Yes')
        else:
            print('No')
    else: 
        if x >= z:
            print('Yes')
        else:
            print('No')