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

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

if multi_4 + odd_cnt == n:
    print("Yes" if multi_4 >= odd_cnt - 1 else "No")
else:
    print("Yes" if multi_4 >= odd_cnt else "No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))

    count_x2 = 0
    count_x4 = 0

    for aa in a:
        if aa % 4 == 0:
            count_x4 += 1
        elif aa % 2 == 0:
            count_x2 += 1

    if count_x4 >= n//2:
        print('Yes')
        exit()
    tmp = n - count_x2
    if tmp % 2 == 0:
        if count_x4 >= tmp // 2:
            print('Yes')
            exit()
    else:
        if count_x4 >= tmp // 2 + 1:
            print('Yes')
            exit()
    if count_x2 == n:
        print('Yes')
        exit()

    print('No')

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
cnt1 = 0
cnt2 = 0
for i in A:
    if i % 2 == 1:
        cnt1 += 1
    elif i % 4 == 0:
        cnt2 += 1
if cnt1 + cnt2 == N:
    if cnt1 - 1 <= cnt2:
        print('Yes')
    else:
        print('No')
else:
    if cnt1 <= cnt2:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
def main():
  N = int(input())
  A = [int(_) for _ in input().split()]
  k = f = 0
  can = False
  for a in A:
    if a%2 == 1:
      k += 1
    if a%4 == 0:
      f += 1
  if k == 0: #すべて偶数の場合
    can = True
  else:
    if N - k - f == 0:
      if f+1 >= k:
        can = True
    else:
      if f >= k:
        can = True
  print('Yes' if can else 'No')
  return

if __name__ == '__main__':
  main()

Submission status: Accepted

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

cnt2 = 0  # 2で割り切れる回数
cnt4 = 0  # 4で割り切れる回数

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

if N-max(cnt2-1, 0) <= cnt4*2+1:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

N2 = 0
N4 = 0
oth = 0

for i in a:
    if i % 4 == 0:
        N4 += 1
    elif i % 2 == 0:
        N2 += 1
    else:
        oth += 1

if N2 == 0:
    if N4+1 >= oth:
        print("Yes")
    else:
        print("No")
else:
    if N4 >= oth:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:

def main():
    n = int(input())
    a = list(map(int, input().split()))
    div2 = 0
    div4 = 0
    notdiv4 = 0
    for ea in a:
        if ea % 4 == 0:
            div4 += 1
        elif ea % 2 == 0:
            div2 += 1
        else:
            notdiv4 += 1

    notdiv4 += div2 % 2
    if notdiv4 - 1 > div4:
        print('No')
    else:
        print('Yes')

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from copy import deepcopy

def main():
    n = int(input())
    a = list(map(int, input().split()))
    div2 = [0] * n
    div4 = deepcopy(div2)
    notdiv4 = deepcopy(div2)
    for i in range(n):
        if a[i] % 4 == 0:
            div4[i] = 1
        elif a[i] % 2 == 0:
            div2[i] = 1
        else:
            notdiv4[i] = 1
    num_notdiv4 = sum(notdiv4)
    num_notdiv4 += sum(div2) % 2
    if num_notdiv4 - 1 > sum(div4):
        print('No')
    else:
        print('Yes')

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a_list = list(map(int, input().split()))
counts = [0] * 3
for a in a_list:
	if a%4 == 0:
		counts[0] += 1 		 
	elif a%2 == 0:
		counts[1] += 1
	else:
		counts[2] += 1
r = 'Yes' if counts[2] <= counts[0]+1 else 'No'
if r == 'Yes':
	two_v = counts[1]
	four_v = counts[0] - counts[2]
	mod = two_v%2	
	if mod == 0 or mod - four_v < 2:
		r = 'Yes'
	else:
		r = 'No'
print(r)

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int,input().split()))
c = len([i for i in l if i%4==0])
l1 = [i for i in l if  (i%2==0 and i%4!=0)]
if len(l1)>=1:
  a = n-len(l1)+1
  a = a-c
  if a<=c+1:
    print("Yes")
  else:
    print("No")
else:
  a = n-c
  if a<=c+1:
    print("Yes")
  else:
    print("No")

Submission status: Accepted

Solution code:
N = int(input())

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

odd_count = 0
four_count = 0

ans = 'Yes'

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

if len(a) % 2 == 0:
    if odd_count > four_count:
        ans = 'No'
else:
    if odd_count <= four_count or len(a) == odd_count + four_count and odd_count -1 <= four_count:
        pass
    else:
        ans = 'No'

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

c4 = 0
c2 = 0
for ai in a:
  if ai%4 == 0:
    c4 += 1
  elif ai%2 == 0:
    c2 += 1
if (c2 > 0 and c4 >= n-c4-c2) or (c2 == 0 and c4 >= n-c4-c2-1):
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, 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

print("Yes" if cntA + cntB//2  >= N//2 else "No")

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
from collections import deque

def f(x):
    return num.count(x)

n = int(input())
a = list(map(int, input().split()))
num = deque([])
for i in a:
    if i%4==0:
        num.append(4)
    elif i%2==0:
        num.append(2)
    else:
        num.append(0)

if len(a)%2==1:
    if f(4)>=len(a)//2 or f(2)>=2*(n//2-f(4))+1:
        print('Yes')
        exit(0)
if len(a)%2==0:
    if f(2)>=2*(n//2-f(4)):
        print('Yes')
        exit(0)
print('No')

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
count2 = -1
count4 = 0
for i in range(n):
    if a[i] % 4 == 2:
        count2 += 1
    if a[i] % 4 == 0:
        count4 += 1
if count2 >= 1:
    n -= count2
if count4 * 2 + 1 >= n:
    print("Yes")
    exit()
print("No")

Submission status: Accepted

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

  # can not divide 2       : 1
  # divide 2 by once       : 2
  # divide 2 by over twice : 4
  data = []
  for d in data_:
    if d % 2 == 1:
      data.append(1)
    else:
      tmp = int(d / 2)
      if tmp % 2 == 1:
        data.append(2)
      else:
        data.append(4)

  # 2が存在しないとき
  if data.count(2) == 0:
    if data.count(1) <= data.count(4) + 1:
      print("Yes")
      return
    else:
      print("No")
      return

  if data.count(1) <= data.count(4):
    print("Yes")
  else:
    print("No")

if __name__ == "__main__":
  main()

Submission status: Accepted

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

Submission status: Accepted

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

def f(x):
  y = 0
  q, r = divmod(x, 2)
  while r == 0:
    y += 1
    q, r = divmod(q, 2)
  return y

B = [0] * 3
for a in A:
  b = f(a)
  B[0] += b == 0
  B[1] += b == 1
  B[2] += b >= 2
print('Yes' if B[0] + (B[1]!=0) <= B[2]+1 else 'No')

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
n = int(input())
list_A = list(map(int, input().split()))
list_C = [0, 0, 0]

for num in list_A:
    if num % 4 == 0:
        list_C[2] += 1
    elif num % 2 == 0:
        list_C[1] += 1
    else:
        list_C[0] += 1

ans = "Yes"

if list_C[1] == 0:
    if list_C[2] == 0:
        if list_C[0] != 0:
            ans = "No"
    if list_C[2] == 1:
        if list_C[0] > 2:
            ans = "No"
    if list_C[2] > 1:
        if list_C[0] > list_C[2] + 1:
            ans = "No"
else:
    if list_C[0] > list_C[2]:
        ans = "No"

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

n, *a = map(int, sys.stdin.read().split())

def main():
    c4 = c2 = 0
    for x in a:
        if not x % 4: c4 += 1
        elif not x % 2: c2 += 1
    ans = 'Yes' if c4 >= n // 2 or c4 * 2 + c2 >= n else 'No'
    print(ans)

if __name__ ==  '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
arr = list(map(int, input().split()))
four = 0
two = 0
for i in arr:
    if i % 4 == 0:
        four += 1
    elif i % 2 == 0:
        two += 1
if 2*four+1 == N:
    print('Yes')
    exit()
N -= four * 2
if N <= two:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
input()
A = map(int, input().split())
one, two, four = 0,0,0

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

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

Submission status: Accepted

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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

if cnt2 // 2 + cnt4 >= N // 2:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n = int(input())
a = map(int, input().split())
b1, b2, b4 = 0, 0, 0

for i in a:
    if i % 4 == 0:
        b4 += 1
    elif i % 2 == 0:
        b2 += 1
    else:
        b1 += 1
if b2:
    if b1 <= b4:
        print("Yes")
    else:
        print("No")
else:
    if b1 <= b4 + 1:
        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 (n - max(0, cnt2 - 1)) // 2 <= cnt4:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

""" n! mod m 階乗
mod = 1e9 + 7
N = 10000000
fac = [0] * N
def ini():
  fac[0] = 1 % mod
  for i in range(1,N):
    fac[i] = fac[i-1] * i % mod"""

"""mod = 1e9+7
N = 10000000
pw = [0] * N
def ini(c):
  pw[0] = 1 % mod
  for i in range(1,N):
    pw[i] = pw[i-1] * c % mod"""

"""
def YEILD():
  yield 'one'
  yield 'two'
  yield 'three'
generator = YEILD()
print(next(generator))
print(next(generator))
print(next(generator))
"""
"""def gcd_(a,b):
  if b == 0:#結局はc,0の最大公約数はcなのに
    return a
  return gcd_(a,a % b) # a = p * b + q"""
"""def extgcd(a,b,x,y):
  d = a
  if b!=0:
    d = extgcd(b,a%b,y,x)
    y -= (a//b) * x
    print(x,y)
  else:
    x = 1
    y = 0
  return d"""


def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7
def main():
  n = int(input())
  a,b = 0,0
  # 4, 2で分ける
  for x in map(int,input().split()):
    if x % 4 == 0:
      a += 1
    elif x % 2 == 0:
      b += 1
  print('Yes' if a+b//2 >= n//2 else 'No') 
  # b // 2 によって、2の倍数が偶数個なら、それは4の倍数として使うことが出来る
  # n // 2　もし n = 6ならば...n = 3となり、数字の間に4の倍数を入れれるって分かる
  
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:

url = "https://atcoder.jp//contests/abc069/tasks/arc080_a"

def main():
    s = int(input())
    t = list(map(int, input().split()))
    dic = {1: 0, 2: 0, 4: 0}

    for v in t:
        if v % 4 == 0:
            dic[4] += 1
        elif v % 2 == 0:
            dic[2] += 1
        else:
            dic[1] += 1
    if dic[1] <= dic[4]:
        print('Yes')
    elif dic[1] <= dic[4] + 1:
        if dic[2] != 0:
            print('No')
        else:
            print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

if n // 2 <= ans:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
x=[i for i in a if i%4==0]
b=[i for i in a if i%4!=0 and i%2==0]
if len(x)+len(b)//2>=n//2:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
a4 = a2 = a0 = 0
for i in a:
  if i % 4 == 0:
    a4 += 1
  elif i % 2 == 0:
    a2 += 1
  else:
    a0 += 1
if a2 == 0:
    if a0 <= a4 + 1:
        print("Yes")
    else:
        print("No")
else:
    if a0 <= a4:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
con =0
ex = -1
for i in range(n):
    if a[i] % 4 == 0:
        con +=1
    elif a[i] % 2 == 0:
        ex +=1
    
if ex == -1:
    ex = 0
if (n-ex)//2 <= con:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
four = 0
two = 0
el = 0
for i in range(n):
    if a[i] % 4 == 0:
        four += 1
    elif a[i] % 2 == 0 :
        two += 1
    else:
        el += 1

if two == 0:
    if four + 1 >= el:
        print("Yes")
    else:
        print("No")
else:
    if four >= el:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
N = int(input())

ARR = [int(s) for s in input().split(" ")]
def calculate(n,arr):
    m1 = 0
    m2 = 0
    m3 = 0
    for ar in arr:
        if ar % 4 == 0:
            m1 = m1 + 1
        elif ar % 2 == 0:
            m2 = m2 + 1
        else:
            m3 = m3 + 1

    if m2 == 0:
        if m3 > m1 + 1:
            print("No")
        else:
            print("Yes")
    else:
        if m3 <= m1:
            print("Yes")
        else:
            print("No")


calculate(N,ARR)

Submission status: Accepted

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

count4 = 0
count2 = 0

for i in lst:
    if i%4==0:
        count4+=1
    elif i%2==0:
        count2+=1
count1 = n-count4-count2

if count2==0 and count4>=count1-1:
    print("Yes")
elif count2!=0 and count4>=count1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

if (m4*2+m2 >= len(a) or m4*2+1 >= len(a)):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N = int(input())
A = map(int, input().split())
var0 = 0
var1 = 0
var2 = 0

for a in A:
    if a % 4 == 0:
        var2 += 1
    elif a % 2 == 0:
        var1 += 1
    else:
        var0 += 1

var1 %= 2
ans = 'Yes' if var2 >= var1 + var0 - 1 else 'No'
print(ans)

Submission status: Accepted

Solution code:
def mp2(k):
    kk=k
    mp=0
    while kk>=1:
        kr=kk%2
        if kr==0:
            kk=kk//2
            mp=mp+1
#            print(kk,kr,mp)
        else:
#            print(kk,kr,mp)
            return mp
    return mp
        

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

cnt0=0
cnt1=0
cnt2=0
for i in range(n):
    m=min(2,mp2(a[i]))
    if m==0:
        cnt0=cnt0+1
    elif m==1:
        cnt1=cnt1+1
    elif m==2:
        cnt2=cnt2+1

#print(cnt0,cnt1,cnt2)

if cnt1==0:
    if cnt2>=cnt0-1:
        print("Yes")
    else:
        print("No")
else:
    if cnt2>=cnt0:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


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

    odd = sum(a % 2 for a in A)
    four = sum(a % 4 == 0 for a in A)
    even = N - odd

    if even - four:
        if four >= odd:
            print('Yes')
        else:
            print('No')
    else:
        if four >= odd - 1:
            print('Yes')
        else:
            print('No')


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
from collections import deque
kisuu = deque([])
bai4 = deque([])
sonota = deque([])
for ai in a:
    if ai % 4 == 0:
        bai4.append(ai)
    elif ai % 2 == 0:
        sonota.append(ai)
    else:
        kisuu.append(ai)

ans = deque([])
if kisuu:
    s = kisuu.pop()
    ans.append(s)
elif sonota:
    s = sonota.pop()
    ans.append(s)
else:
    s = bai4.pop()
    ans.append(s)        

for i in range(1, N + 1):
    if i == N:
        print('Yes')
        quit()
    if ans[i - 1] % 2 == 1:
        if bai4:
            s = bai4.pop()
            ans.append(s)
        else:
            break
    elif ans[i - 1] % 2 == 0 and ans[i - 1] % 4 != 0:
        if sonota:
            s = sonota.pop()
            ans.append(s)
        elif bai4:
            s = bai4.pop()
            ans.append(s)
        else:
            break
    elif ans[i - 1] % 4 == 0:
        if kisuu:
            s = kisuu.pop()
            ans.append(s)
        elif sonota:
            s = sonota.pop()
            ans.append(s)
        elif bai4:
            s = bai4.pop()
            ans.append(s)
        else:
            break
print('No')

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
x=0
y=0
z=0
for i in 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+1:
        print("Yes")
    else:
        print("No")
else:
    if z<=x:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

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

a_4 = [val for val in a if val % 4 == 0]
num_4=len(a_4)
a_odd = [val for val in a if val % 2 ==1]
num_odd=len(a_odd)
num_2 = N - num_odd - num_4


if num_odd==0:
    print('Yes')
else:
    if 1<=num_odd<=num_4:
        print('Yes')
    elif num_4+1==num_odd:
        if num_2==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()]
cnt4=0
cnt2=0
oddcnt=0

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

if oddcnt<=cnt4:
  print("Yes")
else:#oddcnt>cnt4
  if cnt2==0 and oddcnt-cnt4==1:
    print("Yes")
  else:
    print("No")

Submission status: Accepted

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

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

key_1, key_4 = 0, 0
for value in a:
  if value%4 == 0:
    key_4 += 1
  elif value%2 == 1:
    key_1 += 1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(lambda x:int(x),input().split()))
cnt=0
cnt2=0
for i in a:
    if i%4==0:
        cnt+=1
    if i%4!=0 and i%2==0:
        cnt2+=1
if (2*cnt+cnt2>=n and cnt2>0) or (cnt2==0 and 2*cnt+1>=n):
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

d = {
    "4":0,
    "2":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

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

Submission status: Accepted

Solution code:
_,*l=[int(i)%4 for i in open(0).read().split()];f=l.count;print('YNeos'[f(0)+f(2)//2<len(l)//2::2])

Submission status: Accepted

Solution code:
input();l=[int(i)%4 for i in input().split()];f=l.count;print('YNeos'[f(0)+f(2)//2<len(l)//2::2])

Submission status: Accepted

Solution code:
n, *a_l = map(int, open(0).read().split())
multi_4 = sum([1 for a in a_l if a%4 == 0])
multi_2 = sum([1 for a in a_l if a%2 == 0]) - multi_4
multi_1 = n - ( multi_2 + multi_4 )
print('Yes' if (multi_2%2 + multi_1) <= multi_4 + 1 else 'No')

Submission status: Accepted

Solution code:
n=int(input())
la=list(map(int,input().split()))
lc=[0]*n
for i in range(n):
  t=la[i]
  while t%2<1 and lc[i]<2:
    t//=2; lc[i]+=1
c=[lc.count(i) for i in range(3)]
print('YNeos'[c[0]-c[2]>1 or (c[0]>c[2] 
and n%2<1)::2])

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = []
for a in A:
  B.append(a%4)

ans = 'No'
if B.count(0) >= B.count(1)+B.count(3):
  ans = 'Yes'
if B.count(2) == 0 and B.count(0) == B.count(1)+B.count(3)-1:
  ans = 'Yes'
print(ans)

Submission status: Accepted

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

    four_cnt = 0
    two_cnt = 0
    buta = 0
    for a in A:
        if a % 4 == 0:
            four_cnt += 1
        elif a % 2 == 0:
            two_cnt += 1
        else:
            buta += 1
    
    if two_cnt > 0:
        if buta <= four_cnt:
            print('Yes')
        else:
            print('No')
    else:
        if buta <= four_cnt + 1:
            print('Yes')
        else:
            print('No')

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
n = int(input().strip())
a = list(map(int, input().split()))
two = 0
four = 0
for e in a:
    if e % 4 == 0:
        four += 1
    elif e % 2 == 0:
        two += 1
if (n - two <= 2 * four) or (two == 0 and n <= (2 * four + 1)):
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

mod1, mod2, mod4 = [0] * 3
for ai in a:
    if ai % 4 == 0:
        mod4 += 1
    elif ai % 2 == 0:
        mod2 +=1
    else:
        mod1 +=1
        
if mod2 == 0:
    print('No' if mod1 > mod4 + 1 else 'Yes')
else:
    print('No' if mod1 > mod4 else 'Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())

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

yonba = 0
gusu = 0
kisu = 0

for i in t:
    if i%4==0:
        yonba += 1
    elif i%2==0:
        gusu += 1
    else:
        kisu += 1

if kisu==0:
    print('Yes')
else:
    if kisu <= yonba:
        print('Yes')
    else:
        if kisu-yonba==1 and gusu == 0:
            print('Yes')
        else:
            print('No')

Submission status: Accepted

Solution code:
def solve():
    N = int(input())
    a = list(map(int, input().split()))
    
    m2, m4 = 0, 0
    for ai in a:
        if ai % 2 == 0:
            m2 += 1
            if ai % 4 == 0:
                m4 += 1
    
    if N % 2 == 0:
        if N - m2 <= m4:
            print('Yes')
        else:
            print('No')
    else:
        if N - m2 - 1 <= m4:
            print('Yes')
        else:
            print('No')


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

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

if four >= one or four + 1 >= two//2 + two%2 + one or n == two:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
n = int(input())
multi2 = multi4 = 0
for i in map(int, input().split()):
    if i % 4 == 0:
        multi2 += 1
        multi4 += 1
    elif i % 2 == 0:
        multi2 += 1

res = 'No'
if multi4 >= n // 2 or multi2 == n:
    res = 'Yes'
elif multi4 >= (n - (multi2 - multi4)) / 2:
    res = 'Yes'
print(res)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

even = len([i for i in l if i % 2 == 0])
four = len([i for i in l if i % 4 == 0])
even_wo_four = even - four

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

Submission status: Accepted

Solution code:
N, *A = map(int, open(0).read().split())
cnt1 = cnt2 = cnt4 = 0
for a in A:
    if a % 4 == 0:
        cnt4 += 1
    elif a % 2 == 0:
        cnt2 += 1
    else:
        cnt1 += 1

if cnt4 >= cnt1:
    print('Yes')
elif cnt4 == cnt1-1 and cnt2 == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

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

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

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a1, a2, a3 = [], [], []
for i in a:
    if i%4 == 0:
        a1.append(i)
    elif i%2 == 0:
        a2.append(i)
    else:
        a3.append(i)
if len(a2) > 0:
    if len(a1) >= len(a3):
        print("Yes")
    else:
        print("No")
else:
    if len(a1)+1 >= len(a3):
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
n = int(input())
seq = [int(x) for x in input().split()]
div4 = sum((1 for i in seq if i % 4 == 0))
div2 = sum((1 for i in seq if i % 2 == 0 and i % 4 != 0))
odd = n - div4 - div2
ans = "Yes"
if n == 2:
    if div4 == 0:
        if div2 != 2:
            ans = "No"
elif n == 3:
    if div4 == 0:
        if div2 != 3:
            ans = "No"
elif odd - div4 == 1 and odd+div4 == n:
    pass 
elif div4 < odd:
    ans = "No"
elif (div4 - odd) + div2 < 1:
    ans = "No"
print(ans)

Submission status: Accepted

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

c0 = c1 = c2 = 0

for i in a:
    if i % 4 == 0:
        c0 += 1
    elif i % 2:
        c1 += 1
    else:
        c2 += 1

if c2:
    if c1 <= c0:
        print('Yes')
    else:
        print('No')
else:
    if c1 <= c0 + 1:
        print('Yes')
    else:
        print('No')