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:
#!/usr/bin/env python3

import sys
# import time
# import math
# import numpy as np
# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random                                # random, uniform, randint, randrange, shuffle, sample
# import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)



def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1             # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n = ii()
    L = lmi()
    odd = 0
    two_multiple = 0
    four_multiple = 0
    for num in L:
        if num % 2 == 1:
            odd += 1
        elif num % 4 == 0:
            four_multiple += 1
        else:
            two_multiple += 1
    
    if odd <= four_multiple or (odd == four_multiple + 1 and two_multiple == 0):
        print('Yes')
    else:
        print('No')



if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
i4=0
i2=0
i0=0
for x in a:
    if x%4==0:i4+=1
    elif x%2==0:i2+=1
    else:i0+=1
if i4>=i0:print("Yes")
elif i4+1==i0 and i2==0:print("Yes")
elif i0==0:print("yes")
else:print("No")

Submission status: Accepted

Solution code:
n = int(input())
ls = list(map(int,input().split()))
j = 0
k = 0
p = 0
for i in range(n):
    if ls[i] % 4 == 0:
        j += 1
    elif ls[i] % 2 == 0:
        k += 1
if len(ls) % 2 == 0:
    if j >= len(ls)/2:
        print("Yes")
    else:
        p = (len(ls)/2 - j) * 2
        if k >= p:
            print("Yes")
        else:
            print("No")
else:
    if j >= int(len(ls)/2):
        print("Yes")
    else:
        p = (int(len(ls)/2) - j) * 2 +1
        if k >= p:
            print("Yes")
        else:
            print("No")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

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

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n = n//a
    count += 1
  if a**count == n:
    return count
  else:
    return count+1

#############
# Main Code #
#############

N = I()
A = IL()

A = [-a&a for a in A]
d = DD(int)

for a in A:
  d[min(4,a)] += 1

if d[4]<d[1]:
  if d[4]+1==d[1] and d[2] == 0:
    YE()
  NE()
YE()

Submission status: Accepted

Solution code:
n=int(input())
A=list(map(int,input().split()))
Q=[a for a in A if a%4==0]
W=[a for a in A if a%4==2]
if len(Q)>=n//2:
  print("Yes")
else:
  if len(W)>=n-len(Q)*2:
    print("Yes")
  else:
    print("No")

Submission status: Accepted

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

odd = 0
double = 0
quatro = 0

for i in a:
  if i % 2 == 1:
    odd += 1
  else:
    if i % 4 == 0:
      quatro += 1
    else:
      double += 1

if double == N:
  print("Yes")
  exit()
plus = 0
if double != 0:
  plus = 1
if plus + odd - 1 <= quatro:
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

even = sum([1 for i in a if i % 2 == 0])
odd = sum([1 for i in a if i % 2 != 0])
multiple4 = sum([1 for i in a if i % 4 == 0])

flag = False
if even - multiple4 == 0:
    if multiple4 >= odd - 1:
        flag = True
else:
    if multiple4 >= odd:
        flag = True

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
memo = {1:0,2:0,4:0}

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

if memo[4] >= (N//2):
    print("Yes")
elif memo[4] >= memo[1]:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

if t4_cnt > 0:
    if t4_cnt >= (o_cnt-n%2):
        print('Yes')
    else:
        print('No')
else:
    if t2_cnt==n:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

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

Submission status: Accepted

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

odd = 0
even = 0
four = 0

for i in A:
    if i % 4 == 0:
        four += 1
    elif i % 2 == 0:
        even += 1
    else:
        odd += 1
        
if four >= even + odd - 1:
    ans = "Yes"

if four >= odd and even > 1:
    ans = "Yes"
    
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
count = 0
count2 = 0
for i in a:
    if i%4==0:
        count += 1
    elif i%2==0:
        count2 += 1
if count2 != 0:
    if (N-count2)%2 != 0:
        value = (N-count2)//2
    else:
        value = (N-count2)//2-1
else:
    if count >= N//2:
        value = N//2-1
    else:
        value = N//2

    value = N//2-1

if count > value:
    print('Yes')
else:
    print('No')

1414
414

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Thu May 14 12:11:12 2020

@author: shinba
"""

n = int(input())

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

two = 0
four = 0

b = []

for i in a:
    if i % 2 == 0:
        b.append(i//2)

for i in b:
    if i % 2 == 0:
        four += 1
    else:
        two += 1

if two == 0:
    if n <= 2*four +1:
        print("Yes")
    else:
        print("No")
else:
    if n - two <= 2*four:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
input()

numbers = tuple(map(int, input().split(' ')))

n_4_multiples = 0
n_2_multiples = 0
n_other = 0

for n in numbers:
    if n % 4 == 0:
        n_4_multiples += 1
    elif n % 2 == 0:
        n_2_multiples += 1
    else:
        n_other += 1

if n_2_multiples > 0:
    n_other += 1

if n_other - n_4_multiples <= 1:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

    o = sum([i % 2 == 1 for i in a])
    p = sum([i % 4 == 0 for i in a])
    q = sum([i % 2 == 0 for i in a]) - p

    if p + 1 >= o and not q:
        print("Yes")
    elif p >= o and q:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
A=int(input())
n_l= list(map(int,input().split()))
n_a = [i for i in n_l if i % 2 == 0 and i % 4 != 0]
n_b = [i for i in n_l if i % 4 == 0]
ans = len(n_b)*2+1
if len(n_a) > 0:
    ans+=len(n_a)-1
if A <= ans:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n = int(input())
a_list = list(map(int,input().split()))
cntn = 0
cnt2 = 0
cnt4 = 0
for i in a_list:
    if i%4 == 0:
        cnt4 += 1
    elif i%2 == 0:
        cnt2 += 1
    else:
        cntn += 1
        
flag = True

if cnt4+ 1 >= cntn :
    flag = True

else:
    flag = False

if cnt2 >= 1:
    if cnt4 >= cntn :
        flag = True
    else:
        flag = False

if flag:
    print('Yes')

else:
    print('No')

Submission status: Accepted

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

#a_i*a_(i+1)が4の積になるにはeven*even or ood*4の倍数であることが必要
#奇数を数えて、odd,4,...4,odd,4...4,oddにできるか判定
#odd,4,odd,4,odd,4...が最小
#odd,4,odd,4,odd
#if len(odd)+len(4)-1==n: yes
#else:len(odd)<=len(4):yes

odd=0
multiple4=0

for i in range(n):
    a = a_input[i]
    if a%2!=0:
        odd+=1
    if a%4==0:
        multiple4+=1

if odd+multiple4==n and odd-multiple4==1:print('Yes');exit()
if odd<=multiple4:print('Yes');exit()
print('No')

Submission status: Accepted

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
ans = 'No'
for i in range(n):
    if a[i] % 4 == 0:
        a[i] = 4
    elif a[i] % 2 == 0:
        a[i] = 2
    else:
        a[i] = 1

if a.count(2) != 0:
    if a.count(4) >= a.count(1):
        ans = 'Yes'
else:
    if a.count(4) + 1 >= a.count(1):
        ans = 'Yes'
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

x4 = 0
x2 = 0
x0 = 0
for a in A:
    if a % 4 == 0:
        x4 += 1
    elif a % 2 == 0:
        x2 += 1
    else:
        x0 += 1

if x2==0:
    if x4 >= x0 - 1:
        ans = 'Yes'
    else:
        ans = 'No'
else:
    if x4 >= x0:
        ans = 'Yes'
    else:
        ans = 'No'
print(ans)

Submission status: Accepted

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

m=[0]*3
for i in list:
    if i%4==0:
        m[0]+=1
    elif i%2==0:
        m[1]+=1
    else:
        m[2]+=1

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

for i in A:
    if i%4 == 0:
        ans += 2
    elif i%2 == 0:
        ans += 1

if ans >= N - int(N%2==1):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
"""
４の倍数がn//2個以上
or
全部が２の倍数
"""

n2 = 0
n4 = 0

for _a in a:
    if _a%4 == 0:
        n4 += 1
    elif _a%2 == 0:
        n2 += 1

if n4 + n2//2 >= n//2:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

def main():
    cnt_4 = 0
    cnt_2 = 0
    cnt = 0
    for a in A:
        if a % 4 == 0:
            cnt_4 += 1
        elif a % 2 == 0:
            cnt_2 += 1
        else:
            cnt += 1
    if cnt_4 - cnt >= 0:
        print("Yes")
    elif cnt_4 - cnt == -1:
        if cnt_2 >= 1:
            print("No")
        else:
            print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

if count2<1:
  count1=len(a)-count4
else:
  count1=len(a)-count4-count2+1
if count1-count4<=1:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections


n = int(input())
a = list(map(int,input().split()))
n1 = 0
n2 = 0
n4 = 0
for i in range(n):
    if a[i]%4 == 0:
        n4+=1
    elif a[i]%2 == 0:
        n2 +=1
    else:
        n1+=1

if n2 == 1:
    n2 = 0

if n4*2 + n2 >= n or n4*2 + 1 == n:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
def resolve():
	n = int(input())
	div4 = 0
	div2 = 0
	divn = 0
	for i in list(map(int, input().split())):
		if i % 4 == 0:
			div4 += 1
		else:
			if i % 2 == 0:
				div2 += 1
			else:
				divn += 1
	if div2:
		divn += 1
	if div4 + 1 >= divn:
		print('Yes')
	else:
		print('No')
resolve()

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
cnt_odd=0
cnt_even=0
cnt_4=0
for i in range(n):
  if a[i]%2!=0:
    cnt_odd+=1
  else:
    cnt_even+=1
    if a[i]%4==0:
      cnt_4+=1
if cnt_even-cnt_4==0:
  if cnt_4+1>=cnt_odd:
    print("Yes")
  else:
    print("No")
else:
  if cnt_4>=cnt_odd:
    print("Yes")
  else:
    print("No")

Submission status: Accepted

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

d4 = 0
d2 = 0
d0 = 0
for n in nums:
    if n % 4 == 0:
        d4 += 1
    elif n % 2== 0:
        d2 += 1
    else:
        d0 += 1

if d2 > 0 and d0 <= d4:
    print('Yes')
elif d2 == 0 and d0 <= d4+1:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import sys
N=int(input())
alist=list(map(int,input().split()))

s1=[]
s2=[]
s4=[]

for a in alist:
  if a%2==1:
    s1.append(a)
  elif a%4==0:
    s4.append(a)
  else:
    s2.append(a)
#print(s1,s2,s4)

answer_list=[]
last=4
for i in range(N):
  if last==4:
    if s1:
      answer_list.append(s1.pop())
      last=1
    elif s2:
      answer_list.append(s2.pop())
      last=2
    else:
      answer_list.append(s4.pop())
      last=4
  elif last==2:
    if s2:
      answer_list.append(s2.pop())
      last=2
    elif s4:
      answer_list.append(s4.pop())
      last=4
    else:
      print("No")
      sys.exit(0)
  elif last==1:
    if s4:
      answer_list.append(s4.pop())
      last=4
    else:
      print("No")
      sys.exit(0)
      
#print(answer_list)
print("Yes")

Submission status: Accepted

Solution code:
def resolve():
	n = int(input())
	a = list(map(int, input().split()))
	div4 = 0
	div2 = 0
	divn = 0
	for i in a:
		if i % 4 == 0:
			div4 += 1
		elif i % 2 == 0:
			div2 += 1
		else:
			divn += 1
	if div2 > 0:
		divn += 1
	if div4 + 1 >= divn:
		print('Yes')
	else:
		print('No')
resolve()

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int,input().split()))
n4 = 0
n2 = 0
for a in A:
    if a%4 == 0:
        n4 += 1
    elif a%2 == 0:
        n2 += 1
if n2 == 1:
    n2 = 0
l = n4*2 + n2
if l>=n or n4*2+1 == n:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
n1 = 0
n2 = 0
n4 = 0

for a in A:
  if a&1:
    n1 += 1
  elif a%4==0:
    n4 += 1
  else:
    n2 += 1

 
bl = True
# n1 <= n4なら、141414と並べてあとは適当
if n1 > n4:
  #1414...141のときだけ
  if not(n1 == n4 + 1 and n2 == 0):
    bl = False

answer = 'Yes' if bl else 'No'
print(answer)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a4 = []
a2 = []
odd = []
for i in range(n):
    if a[i] % 4 == 0:
        a4.append(a[i])
    elif a[i] % 2 == 0:
        a2.append(a[i])
    else:
        odd.append(a[i])
if len(a) > 3:
    if len(odd) <= len(a4):
        print('Yes')
    elif len(a2) == 0:
        if n %2 == 1 and len(odd) <= len(a4)+1:
            print('Yes')
        elif n%2 == 0 and len(odd) <= len(a4):
            print('Yes')
        else:
            print('No')
    else:
        print('No')
else:
    if a4 or len(a2) == n:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
def main():
    N=int(input())
    A=[int(x) for x in input().split()]
    
    cnt_4=0
    cnt_2=0
    for i in A:
        if i%4==0:
            cnt_4+=1
        elif i%2==0:
            cnt_2+=1
    
    ok=N//2
    if (cnt_4+cnt_2//2)>=ok:
        print("Yes")
    else:
        print("No")
    
if __name__=="__main__":
    main()

Submission status: Accepted

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

f = 0
o = 0
t = 0
for i in a:
    if i % 4 == 0:
        f += 1
    elif i % 2 == 0:
        t += 1
    else:
        o += 1
isok = True;
if t%2 == 1:
    f -= 1
if o > f+1:
    isok = False


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

Submission status: Accepted

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

    n_4 = 0
    n_2 = 0
    n_odd = 0

    for i in range(N):
        if A[i] % 4 == 0:
            n_4 += 1
        elif A[i] % 2 == 0:
            n_2 += 1
        else:
            n_odd += 1

    if (n_odd + n_2 % 2 - 1) <= n_4:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int,input().split()))
b4=[x for x in a if x%4==0]
a4=[x for x in a if x%4!=0]
b2=[x for x in a4 if x%2==0]
c=[x for x in a4 if x%2!=0]
if len(b4)==0 and (len(c)==0 and len(b2)>1):
    print('Yes')
elif len(b4)==0 and len(c)!=0:
    print('No')
elif len(b4)+1<len(c):
    print('No')
elif len(b4)<len(c) and len(b2)>0:
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
nn=[0,0,0]
for i,v in enumerate(a):
    tmp=0
    while v%2==0:
        v//=2
        tmp+=1
    nn[min(tmp,2)]+=1
if nn[1]:
    if nn[0]>(n-nn[1])//2:
        print("No")
    else:
        print("Yes")
else:
    if nn[0]>(n+1)//2:
        print("No")
    else:
        print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
a_ls = list(map(int, input().split()))
num_mul4 = 0
num_even_not4 = 0
num_odd = 0
for i in range(n):
    if a_ls[i] % 4 == 0:
        num_mul4 += 1
    elif a_ls[i] % 2 == 0:
        num_even_not4 += 1
    else:
        num_odd += 1
res = 'No'
if num_even_not4 == 0:
    if num_odd <= num_mul4 + 1:
        res = 'Yes'
else:
    num_odd += 1
    if num_odd <= num_mul4 + 1:
        res = 'Yes'
print(res)

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 x+1 >= z:
        print("Yes")
    else:
        print("No")
else:
    if x >= z:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
cnt1=0
cnt2=0
cnt4=0
if n==2:
    if a[0]*a[1]%4==0:
        print('Yes')
        exit()
    else:
        print('No')
        exit()
for i in range(n):
    if a[i]%4==0:
        cnt4+=1
    elif a[i]%2==0:
        cnt2+=1
    else:
        cnt1+=1
if cnt1 == 0 or (cnt2 == 0 and cnt4+1 >= cnt1) or (cnt2 >= 1 and cnt4 >= cnt1):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N = int(input())
an = list(map(int, input().split()))
four = 0
odd = 0
for a in an:
    if a % 2 == 1:
        odd += 1
    elif a % 4 == 0:
        four += 1
print('Yes' if odd <= four or N//2 == four and -(-N//2) == odd else 'No')

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
m2 = 0
m4 = 0
other=0
for i, aa in enumerate(a):
    if aa % 4 == 0:
        m4 +=1
        continue
    if aa % 2 == 0:
        m2 += 1
        continue
    other += 1
if m4 >= other or (m4 + 1 == other and m2 == 0):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    cnt4 = 0
    cnt2 = 0
    _cnt = 0
    for a in A:
        if a % 4 == 0:
            cnt4 += 1
            continue
        if a % 2 == 0:
            cnt2 += 1
            continue
        _cnt += 1
    if cnt2 > 0 and cnt2 % 2 != 0:
        cnt2 -= 1
        _cnt += 1
    print("Yes" if cnt4+1 >= _cnt else "No")




if '__main__' == __name__:
    resolve()

Submission status: Accepted

Solution code:
import sys
def slove(n, k):
    a_list = [int(i) for i in k.split()]
    num = len([i for i in a_list if i % 4 == 0])
    tmp =  [i for i in a_list if i % 4 != 0]
    num2 = len([i for i in tmp if i % 2 == 0]) // 2
    return "Yes" if (num + num2)>= n // 2 else "No"

if __name__ == "__main__":
    input = sys.stdin.readline
    n = int(input())
    k = input()
    print(slove(n, k))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
# 4の倍数と2の倍数を数える
four = 0
two = 0
ele = 0
for i in range(n):
    if a[i] % 4 == 0:
        four += 1
    elif a[i] % 2 == 0 and a[i] % 4 != 0:
        two += 1
    else:
        ele += 1

"""
ele += two % 2
two = two//2
print(two, end=" ")
print(four, end=" ele=")
print(ele)
if ele <= (two+four) or (ele-(four+two) == 1):
    print("Yes")
else:
    print("No")
"""
if ele <= four:
    print("Yes")
elif ele-four == 1 and two == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

def main():
    N = int(readline())
    A = list(map(int, readline().rstrip().split()))
    m2 = len([a for a in A if a % 2 == 0])
    m4 = len([a for a in A if a % 4 == 0])
    mx = N - m2
    if mx == m4 + 1 and m2 - m4 == 0:
        print('Yes')
    elif mx > m4:
        print('No')
    else:
        print('Yes')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=int(input())
    a=list(map(int,input().split()))
    t=0
    f=0
    for i in range(N):
        if a[i]%4==0:
            f+=1
        elif a[i]%2==0:
            t+=1
    YesNo(N//2<=f+t//2)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


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

    cnt_2 = 0
    cnt_4 = 0
    for i in range(n):
        if A[i] % 4 == 0:
            cnt_4 += 1
        elif A[i] % 2 == 0:
            cnt_2 += 1

    if (n - max(0, cnt_2 - 1)) // 2 <= cnt_4:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
n = int(input())
li = list(map(int,input().split()))
x = 0
y = 0

for i in li:
    if i%4 == 0: #4の倍数がカバーできるのはx*2+1個まで
        x += 1
    if i%4 != 0 and i%2 == 0: #4の倍数では無いけど2の倍数がカバーできるのは自分たちのみ
        y += 1

if x>0 and y>0:
    if 2*x+y >= n:
        print("Yes")
    else:
        print("No")

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

elif y>0:
    if y == n:
        print("Yes")
    else:
        print("No")

else:
    print("No")