Problem:


Score : 400 points

Problem Statement

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

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

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

Determine whether Snuke can achieve his objective.

Constraints

2 ≤ N ≤ 10^5

a_i is an integer.

1 ≤ a_i ≤ 10^9

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

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

Sample Input 1

3
1 10 100

Sample Output 1

Yes

One solution is (1, 100, 10).

Sample Input 2

4
1 2 3 4

Sample Output 2

No

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

Sample Input 3

3
1 4 1

Sample Output 3

Yes

The condition is already satisfied initially.

Sample Input 4

2
1 1

Sample Output 4

No

Sample Input 5

6
2 7 1 8 2 8

Sample Output 5

Yes



Sample input:
3
1 10 100


Sample output:
Yes

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

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

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  a=b=0
  for x in l:
    if x%4==0:
      b+=1
    elif x%2==0:
      a+=1

  if a==0 and b*2+1>=n:
    return 'Yes'
  elif a+b*2>=n:
    return 'Yes'
  return 'No'

print(main())

Submission status: Accepted

Solution code:
n = int(input())

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

multi_four = []
multi_two  = []

for i in l:
    if i % 4 == 0:
        multi_four.append(i)
    
    elif i % 2 == 0 and i % 4 != 0:
        multi_two.append(i)

if len(multi_two) == 0:
    if n - (len(multi_two) + len(multi_four)) <= len(multi_four) + 1:
        print('Yes')
    
    else:
        print('No')

else:
    if n - (len(multi_two) + len(multi_four)) <= len(multi_four):
        print('Yes')
    
    else:
        print('No')

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

four_gcd = 0
two_gcd = 0
odd = 0

for a in A:
	if a%4 == 0:
		four_gcd += 1
	elif a%2 == 0:
		two_gcd += 1
	else:
		odd += 1

# print(four_gcd,two_gcd,odd)
if two_gcd > 0:
	odd += 1
# print(four_gcd,two_gcd,odd)
if odd > four_gcd+1:
	print('No')
else:
	print('Yes')

Submission status: Accepted

Solution code:
n = int(input())

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

odd = sum(a % 2 for a in arr)
four = sum(a % 4 == 0 for a in arr)
even = n - odd - four

if even:
    print("Yes" if four >= odd else "No")
else:
    print("Yes" if four >= odd - 1 else "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()))
d2=0
d4=0
dn=0
for i in a:
    if i%4==0:
        d4+=1
    elif i%2==0:
        d2+=1
    else:
        dn+=1
print('Yes' if d4>=dn or (dn-d4==1 and d2==0) else 'No')

Submission status: Accepted

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

x = y = z = 0
for val in a:
    if val % 4 == 0:
        x += 1
    elif val % 2 == 0:
        y += 1
    else:
        z += 1

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

Submission status: Accepted

Solution code:
n = int(input())
num = [ int(v) for v in input().split() ]
a, b, c = 0, 0, 0
for i in num:
	if i % 2 != 0:
		a += 1
	elif i % 4 != 0:
		b += 1
	else:
		c += 1
if b == 0:
	if c >= a - 1:
		print("Yes")
	else:
		print("No")
else:
	if c >= a:
		print("Yes")
	else:
		print("No")

Submission status: Accepted

Solution code:
_, *a = map(int, open(0).read().split())
ans = [0] * 4
for v in a:
    ans[v % 4] += 1

if (ans[0] >= ans[1] + ans[3]) or (ans[0] == ans[1] + ans[3] - 1 and ans[2] == 0):
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

for i in range(n):
  if a[i]%4==0:
    four+=1
  elif a[i]%2==0:
    two+=1
one=n-two-four
if one>=four+2 or\
one==four+1 and two>=1:
  print("No")
else:       
  print("Yes")

Submission status: Accepted

Solution code:
from collections import Counter

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

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

n_odd = N - (n_multi4 + n_multi2)

if n_multi4 >= n_odd:
  print('Yes')
elif n_multi4 +1 == n_odd and n_multi2 == 0:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
x4, x2, x = 0, 0, 0
for a in A:
    if a % 4 == 0:
        x4 += 1
    else:
        if a % 2 == 0:
            x2 = 1
        else:
            x += 1
print('Yes' if x2 + x - 1 <= x4 else 'No')

Submission status: Accepted

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

Submission status: Accepted

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

for i in a:
    if i%4 == 0:
        tetra += 1
    elif i%4 == 2:
        di += 1

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

Submission status: Accepted

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

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

    # 4の倍数がnum4個のとき、
    # 2の倍数がnum2個のとき、
    # num4*2 + 1 >= Nなら、Yes
    # ? 4 ? 4 ? 4 ?
    # そうでないなら、num4*2 + num2なら、Yes
    # 2 2 2 4 ? 4 ?
    num4 = 0
    num2 = 0
    for a in A:
        if a%4 == 0:
            num4 += 1
        elif a%2 == 0:
            num2 += 1
    
    if (num4*2+1) >= N:
        print("Yes")
    elif (num4*2)+num2 >= N:
        print("Yes")
    else:
        print("No")



if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
N = int(input())
lst_a = list(map(int, input().split()))
cnt_mod4 = 0
cnt_odd = 0
cnt_mod2 = 0
ans = "No"


for a in lst_a:
    if a % 4 == 0:
        cnt_mod4 += 1
    elif a % 2 != 0:
        cnt_odd += 1
    else:
        cnt_mod2 += 1


if cnt_mod2 != 0:
    cnt_odd += 1


if cnt_odd <= cnt_mod4 + 1:
    ans = "Yes"


print(ans)

Submission status: Accepted

Solution code:
N = int(input())
lst_a = list(map(int, input().split()))
cnt_4times = 0
cnt_odd = 0
cnt_even = 0
ans = "No"


for a in lst_a:
    if a % 4 == 0:
        cnt_4times += 1
    elif a % 2 != 0:
        cnt_odd += 1
    else:
        cnt_even += 1


if cnt_even != 0:
    cnt_odd += 1


if cnt_odd <= cnt_4times + 1:
    ans = "Yes"


print(ans)

Submission status: Accepted

Solution code:
# /usr/bin/python
# -*- coding: utf-8 -*-
import math




N = int(input())
An = list(map(int, input().split()))
cnt = [0,0,0]
for a in An:
  if a%4 == 0:
    cnt[2] += 1
  elif a%2 == 0:
    cnt[1] += 1
  else:
    cnt[0] += 1

if cnt[2] >= cnt[0]:
  print('Yes')
elif cnt[0]-cnt[2]==1 and cnt[1]==0:
  print('Yes')
else:
  print('No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
c={1:0,2:0,4:0}
for a in map(int,input().split()):
	if a % 2 == 0:
		if (a // 2) % 2 == 0:
			c[4] += 1
		else:
			c[2] += 1
	else:
		c[1] += 1

if c[2] > 0:
	c[1] += 1

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

Submission status: Accepted

Solution code:
# whileだと実行時間83msだったけどforでは？
n=int(input())
a=list(map(int, input().split()))
i=0
odd=0
even=0
eveneven=0
for i in a:
    if i%4==0:
        eveneven+=1
    elif i%2==0:
        even+=1
    else:
        odd+=1  
if even==0 and eveneven>=(odd-1):
    print("Yes")
elif even!=0 and eveneven>=odd:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int, input().split()))
i=0
odd=0
even=0
eveneven=0
while i<n:
    if a[i]%4==0:
        eveneven+=1
    elif a[i]%2==0:
        even+=1
    else:
        odd+=1
    i+=1    
if even==0 and eveneven>=(odd-1):
    print("Yes")
elif even!=0 and eveneven>=odd:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
#https://atcoder.jp/contests/abc069/tasks/arc080_a
N = int(input())
ai = list(map(int, input().split()))
mult_4 = 0
odd = 0
mult_2 = 0
for a in ai:
    if a%4 == 0:
        mult_4 += 1
    elif a%2 == 1:
        odd += 1
    else:
        mult_2 += 1

if mult_2 != 0 and mult_4 >= odd:
    print("Yes")
elif mult_2 == 0 and mult_4+1 >= odd:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
cnt = [0]*3
for a in A:
    b = a%4
    if b==0:
        cnt[2] += 1
    elif b==2:
        cnt[1] += 1
    else:
        cnt[0] += 1
if (N-2*cnt[2]-1) <= max(0,cnt[1]-1):
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:

def read_input():
    n = int(input())
    alist = list(map(int, input().split()))

    return n, alist

def submit():
    n, alist = read_input()

    four_multiple = sum([1 for a in alist if a % 4 == 0])
    two_multiple = sum([1 for a in alist if a % 4 != 0 and a % 2 == 0])

    if n // 2 <= four_multiple:
        print('Yes')
        return

    n -= 2 * four_multiple
    if n <= two_multiple:
        print('Yes')
        return

    print('No')




if __name__ == '__main__':
    submit()

Submission status: Accepted

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

c2 = 0
c4 = 0
for a in A:
    if a % 4 == 0:
        c4 += 1
    elif a % 2 == 0:
        if c2 == 1:
            c4 += 1
            c2 = 0
        else:
            c2 += 1
if c4 >= N//2:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

Submission status: Accepted

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

MOD2 = 0
MOD4 = 0

for i in a:
    if i % 4 == 0:
        MOD4 += 1
    elif i % 2 == 0:
        MOD2 += 1

if MOD4 == 0:
    if N == MOD2:
        print('Yes')
    else:
        print('No')
else:
    if MOD2 >= 1:
        MOD2 -= 1
    if (N-MOD2) // 2 <= MOD4:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

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

odd = list(filter((lambda x:x%2==1),an))
div4 = list(filter((lambda x:x%4 ==0),an))
div2 = set(an).difference(set(odd)).difference(set(div4))
if len(div2) == 0:
  div4.append(0)
if len(odd) <= len(div4):
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
N = int(input())
a = [int(i) for i in input().split()]
flg = 0
ct_2, ct_4 = 0, 0
for i in a:
    if i % 4 == 0:
        ct_2 += 1
        ct_4 += 1
    elif i % 2 == 0:
        ct_2 += 1

if ct_4 >= N//2:
    flg = 1
else:
    if ct_2 >= N-ct_4:
        flg = 1

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = [0,0,0]
for i in a:
  if i % 4 == 0:
    b[2] += 1
  elif i % 2 == 0:
    b[1] += 1
  else:
    b[0] += 1
if b[1] > 0:
  if b[2] >= b[0]:
    print("Yes")
  else:
    print("No")
else:
  if b[2] + 1 >= b[0]:
    print("Yes")
  else:
    print("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:
        if i%4 == 0:
            n4 += 1
        else:
            n2 += 1
    else:
        n1 += 1

if n1 <= n4:
    ans = 'Yes'
else:
    if n1 == n4 + 1 and n2 == 0:
        ans = 'Yes'
    else:
        ans = 'No'

print(ans)

Submission status: Accepted

Solution code:
import itertools

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

def calc_two_factor_count(a_i):
  if a_i % 2 == 1:
    return 0
  elif a_i / 2 % 2 == 1:
    return 1
  else:
    return 2

aggregated_a = {two_factor_count: sum(1 for _ in iter) for (two_factor_count, iter) in itertools.groupby(sorted(a, key = calc_two_factor_count), key = calc_two_factor_count)}
b = [aggregated_a[i] if i in aggregated_a else 0 for i in range(3)]

print("Yes" if (n % 2 == 0 and b[0] <= n / 2 and b[2] >= b[0]) or (n % 2 == 1 and b[0] <= (n - 1) / 2 and b[2] >= b[0]) or (n % 2 == 1 and b[0] == (n + 1) / 2 and b[2] == (n - 1) / 2) else "No")

Submission status: Accepted

Solution code:
n = int(input())

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


odd = []
even2 = []
even4 = []

for i in a:
  if i % 4 == 0:
    even4.append(i)
  elif i % 2 == 0:
    even2.append(i)
  else:
    odd.append(i)
    
    

if len(odd) <= len(even4):
  print("Yes")
elif len(odd) == len(even4) + 1:
  if len(even2) == 0:
    print("Yes")
  else:
    print("No")
else:
  print("No")

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
N=int(input())
onetwofour=[0,0,0]
ans="No"
for i in [int(j) for j in input().split()]:
    if i%4==0:
        onetwofour[2]+=1
    elif i%2==0:
        onetwofour[1]+=1
    else:
        onetwofour[0]+=1
if onetwofour[2]>=onetwofour[0]:
    ans="Yes"
elif onetwofour[1]==0 and onetwofour[2]==onetwofour[0]-1:
    ans="Yes"
print(ans)

Submission status: Accepted

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

N=I()
A=LI()
# A=[I() for i in range(N)]
# ignore %2==0 numbers
f=[]
odds=[]
t=[]
for n in A:
    if n%4==0:
        f.append(n)
    elif n%2!=0:
        odds.append(n)
    else:
        t.append(n)
if len(odds)==0:
    print('Yes')
elif len(f) < len(odds)-1:
    print('No')
else:
    if len(odds) - 1 == len(f):
        if len(t)> 0:
            print('No')
        else:
            print('Yes')
    else:
        print('Yes')

Submission status: Accepted

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

time1, time2, time4 = 0, 0, 0
for item in a:
    if item % 4 == 0:
        time4 += 1
    elif item % 2 == 0:
        time2 += 1
    else:
        time1 += 1

if (time1 + time2 % 2 + time4) % 2 == 1:
    time4 += 1

if time1 + time2 % 2 > time4:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
import math
n=int(input())
a=[int(i) for i in input().split()]
odd=0
two=0
four=0
for i in a:
    if i%2==0:
        i=i//2
        if i%2==0:
            four+=1
        else:
            two+=1
    else:
        odd+=1
res=False
if two==0:
    if odd<=four+1:
        res=True
elif odd<=four:
    res=True
print("Yes" if res else "No")

Submission status: Accepted

Solution code:
N=int(input())
A=map(int,input().split())
zero=0
two=0
four=0
for a in A:
    if a%2==0:
        if a%4==0:
            four+=1
        else:
            two+=1
    else:
        zero+=1
# if zero<=four:
#     print("Yes")
# else:
#     print("No")
if two==0:
    if zero<=four+1:#1 4 1 4 1
        print("Yes")
    else:
        print("No")
else:#two exist
    #two まとめればそこは無視できる
    if zero<=four:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
even_list = [i for i in a if i % 2 == 0]
odd_list = [i for i in a if i % 2 != 0]
four_list = [i for i in even_list if i % 4 == 0]
two_idx = n // 2
if len(four_list) >= two_idx:
  print('Yes')
elif n - 2 * len(four_list) == len(even_list) - len(four_list):
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
n=int(input())
l=[int(i) for i in input().split()]
a=0;b=0;c=0
for i in l:
    if i%4==0:
        a+=1
    elif i%4==2:
        b+=1
    else:
        c+=1
if b==0:
    if a>=c-1:
        bool=True
    else:
        bool=False
else:
    c+=1
    if a>=c-1:
        bool=True
    else:
        bool=False
if bool:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy
import collections
from operator import itemgetter
#以下てんぷら
def j(q):
    if q==1: print("Yes")
    else:print("No")
    exit(0)


def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")

def ip():
    return int(input())
def printrow(a):
    for i in range(len(a)):
        print(a[i])
n = ip()                                     #入力整数1つ
#n,q= (int(i) for i in input().split())       #入力整数横2つ以上
a = [int(i) for i in input().split()]        #入力整数配列
#b = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
#こっから本文
one = 0
two = 0
four = 0
leftover = 0
for i in range(n):
    if a[i]%2: one+=1
    elif a[i]%4==0:four+=1
    else: two+=1
if one==1:
    if four==0:j(0)
    if one == four: leftover = 1
    if two%2:
        if leftover==0:
            j(0)
        else:j(1)
    else: j(1)

if one-1 > four:j(0)
else :
    if one==four:leftover=1
    if two%2:
        if leftover==0:
            j(0)
        else:j(1)
    else: j(1)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
for i in range(n):
    if a[i]%4==0:
        a[i]=4
    elif a[i]%2==0:
        a[i]=2
    else:
        a[i]=0
from collections import Counter
C = Counter(a)
if C[4]>=C[0]+C[2]%2-1:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
a1,a2,a4=0,0,0

for i in range(1):
    # Start Input code ---------------------------------------
    n=int(input())
    y=map(int,input().split())
    for x in y:
        
        if x%4==0:
            a4+=1
        elif x%2==0:
            a2=1
        else:
            a1+=1
ans='Yes' if a1+a2<=a4+1 else 'No'
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
f0, f1, f2 = 0, 0, 0
for i in range(N):
    if a[i] % 4 == 0:
        f2 += 1
    elif a[i] % 2 == 0:
        f1 += 1
    else:
        f0 += 1
if f1:
    if f0 <= f2:
        print('Yes')
    else:
        print('No')
else:
    if f0 <= f2 + 1:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
b = [0]*N
for i in range(N):
    ai = a[i]
    cnt = 0
    while ai > 1:
        if ai %2 == 1:
            break
        else:
            ai=ai//2
            cnt += 1
    b[i] = (cnt,a[i])
b.sort()
c=[0]*(N)
for i in range(N):
    if i%2 == 0:
        c[i] = b[i][1]
    else:
        c[i] = b[N-i][1]
for i in range(N-1):
    if c[i]*c[i+1]%4 !=0:
        print("No")
        exit()
    else:
        continue
print("Yes")

Submission status: Accepted

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

if b >= a:
    print("Yes")
elif c == 0 and a - b ==1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import sys

def main():
    input = sys.stdin.readline
    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 n4 >= N//2:
        return 'Yes'
    elif n2 >= 2 and n4 >= (N - n2 + 1) // 2:
        return 'Yes'
    else:
        return 'No'


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict
N = int(input())
a = [int(i) for i in input().split()]
b = []
for x in a:
    num = 0
    if x%2 == 0:
        x = x//2
        num += 1
        if x%2 == 0:
            num += 1
    b.append(num)
if b.count(0) <= b.count(2):
    print('Yes')
else:
    if b.count(0) == b.count(2)+1 and len(b) == b.count(0)+b.count(2):
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
alist = list(map(int,input().split()))
zero , one , two = 0 , 0 , 0
for a in alist:
    if a % 4 == 0:
        two += 1
    elif a % 2 == 0:
        one += 1
    else:
        zero += 1
def func(zero, one, two):
    if zero == 0:
        return True
    if one == 0 :
        if (zero <= (two + 1)):
            return True
        else:
            return False
    if (zero + 1 )  <= (two + 1): 
        return True
    return False
print("Yes" if func(zero , one, two) else "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
if c4 * 2 + 1 >= N or c4 * 2 + c2 >= N:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
num_4 = len([4 for a_ in a if (a_ % 4 == 0)])
num_2 = len([2 for a_ in a if (a_ % 4 == 2)])
num_0 = n - num_4 - num_2
if ((num_4 + num_2 > 0) & ((num_4 + 1 == num_0) & (num_2 == 0)) | (num_0 - num_4 <= 0)):
    print("Yes")
else:
    print("No")

Submission status: Accepted

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


def main():
    two = an.count(2)
    four = an.count(0)
    other = N - two - four

    if 0 < two:
        other += 1

    print("Yes" if other - 1 <= four else "No")
    return


main()

Submission status: Accepted

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


def main():
    ar = [0] * 3
    for ai in an:
        if ai % 4 == 0:
            ar[2] += 1
        elif ai % 2 == 0:
            ar[1] += 1
        else:
            ar[0] += 1

    if 0 < ar[1]:
        ar[0] += 1

    print("Yes" if ar[0] - 1 <= ar[2] else "No")
    return


main()

Submission status: Accepted

Solution code:
def four_adjacent(N: int, A: list)->bool:
    n2, n4 = 0, 0
    for a in A:
        if a % 4 == 0:
            n4 += 1
        elif a % 2 == 0:
            n2 += 1
    return N//2 == n4 or N <= 2*n4 + n2


if __name__ == "__main__":
    N = int(input())
    A = [int(s) for s in input().split()]
    yes = four_adjacent(N, A)
    print('Yes' if yes else 'No')

Submission status: Accepted

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

def div2(a):
  if a%2 ==1:
    return 0
  if (a//2)%2==1:
    return 1
  else:
    return 2

_A = [div2(a) for a in A]

if _A.count(1):
  if _A.count(0) <= _A.count(2):
    print('Yes')
  else:
    print('No')
else:
  if _A.count(0) <= _A.count(2) +1:
    print('Yes')
  else:
    print('No')

Submission status: Accepted

Solution code:
N=int(input())
count_4=0
count_2=0
a_list=list(map(int, input().split()))
for i in range(N):
    if a_list[i]%4==0:
        count_4=count_4+1
    elif a_list[i]%2==0:
        count_2=count_2+1

need_count=N//2

if need_count<=count_4+count_2//2:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

b = [i%4 for i in a]

b4 = b.count(0)
b2 = b.count(2)
b1 = n - b4 - b2

if b2 == 0:
  if b4 >= b1-1:
    print('Yes')
  else:
    print('No')
else:
  if b4 >= b1:
    print('Yes')
  else:
    print('No')

Submission status: Accepted

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

cnt_4 = a.count(0)
cnt_2 = a.count(2)
cnt_0 = n - cnt_4 - cnt_2

if cnt_2 == 0:
  if cnt_4 >= cnt_0-1:
    print('Yes')
  else:
    print('No')
else:
  if cnt_4 >= cnt_0:
    print('Yes')
  else:
    print('No')

Submission status: Accepted

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

cnt_4 = sum(i%4==0 for i in a)
cnt_2 = sum(i%2==0 for i in a) - cnt_4
cnt_0 = n - cnt_4 - cnt_2

if cnt_2 == 0:
  if cnt_4 >= cnt_0-1:
    print('Yes')
  else:
    print('No')
else:
  if cnt_4 >= cnt_0:
    print('Yes')
  else:
    print('No')

Submission status: Accepted

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

cnt_0 = 0
cnt_2 = 0
cnt_4 = 0
for i in a:
  if i % 4 == 0:
    cnt_4 += 1
  elif i % 2 == 0:
  	cnt_2 += 1
  else:
  	cnt_0 += 1

if cnt_2 == 0:
  if cnt_4 >= cnt_0-1:
    print('Yes')
  else:
    print('No')
else:
  if cnt_4 >= cnt_0:
    print('Yes')
  else:
    print('No')

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
X = Counter([4 if a % 4 == 0 else (2 if a % 2 == 0 else 1) for a in A])
for x in (1, 2, 4):
    if x not in X:
        X[x] = 0
if X[4] + 1 < X[1]:
    print("No")
    exit()
if X[4] + 1 == X[1] and X[2] != 0:
    print("No")
    exit()
print("Yes")

Submission status: Accepted

Solution code:
n=int(input())

A=list(map(int,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


if cnt_4>=(n//2):
    print('Yes')
else:
    if 2*cnt_4+cnt_2>=n:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
N=int(input())
cnt={1:0,2:0,4:0}
for a in map(int,input().split()):
    if a%4==0:cnt[4]+=1
    elif a%2==0:cnt[2]+=1
    else:cnt[1]+=1

if cnt[1]>0:
    cnt[1]-=1
    bef=1
elif cnt[2]>0:
    cnt[2]-=1
    bef=2
else:
    cnt[4]-=1
    bef=4

flag=True
for i in range(N-1):
    if bef==1:
        if cnt[4]==0:
            flag=False
            break
        cnt[4]-=1
        bef=4
    elif bef==4:
        if cnt[1]>0:
            cnt[1]-=1
            bef=1
        elif cnt[2]>0:
            cnt[2]-=1
            bef=2
        else:
            cnt[4]-=1
            bef=4
    elif bef==2:
        if cnt[2]>0:
            cnt[2]-=1
            bef=2
        else:
            if cnt[4]==0:
                flag=False
                break
            cnt[4]-=1
            bef=4
if flag:print('Yes')
else:print('No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A_2 = [a%2 for a in A]
A_4 = [a%4 for a in A]
x4 = A_4.count(0)
odd = A_2.count(1)
x2 = A_2.count(0)-x4
if x4-odd>=0:
    print('Yes')
elif x2==0 and x4-odd>=-1:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

numfour = 0
numtwo = 0

for i in a:
    if i % 4 == 0:
        numfour += 1
    elif i % 2 == 0:
        numtwo += 1

if (numfour*2+1) + (numtwo//2*2) >= N:
    print("Yes")
else:
    print("No")