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())
numbers = [int(i) for i in input().split()]

cnt_4 = 0
cnt_2 = 0

for n in numbers:
    if n % 4 == 0:
        cnt_4 += 1
    elif n % 2 == 0:
        cnt_2 += 1
    
cnt = cnt_4 + (cnt_2 // 2)

if cnt >= N // 2:
    print('Yes')
else :
    print('No')

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass


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


def solve(N: int, a: "List[int]"):
    n2 = sum(1 for ai in a if ai % 4 == 0)
    n0 = sum(1 for ai in a if ai % 2 == 1)
    ans = NO
    if n2 + 1 == n0 and n2 + n0 == N:
        ans = YES
    elif n2 >= n0:
        ans = YES
    print(ans)


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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
  n=int(input())
  a=tuple(map(int,input().split()))
  cnt2,cnt4=0,0
  for i in a:
    cnt2+=1 if i%2==0 and i%4>0 else 0
    cnt4+=1 if i%4==0 else 0
  print('Yes' if (cnt2>=2 and cnt4>=(n-cnt2)/2) or (cnt2<2 and cnt4>=n//2) else 'No')
if __name__=='__main__':
  main()

Submission status: Accepted

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

four = sum([1 for x in a if x % 4 == 0])
two = sum([1 for x in a if x % 2 == 0 and x % 4 != 0])
others = sum([1 for x in a if x % 2 != 0])

if two == 0 and others <= four + 1:
    print("Yes")
elif others <= four:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n = int(input())
li = list(map(int,input().split()))
A = 0
B = 0
C = 0

for a in li:
  if a % 4 == 0:
    A += 1
  elif a % 2 == 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:
n = int(input())
a = list(map(int, input().split()))
odd, even, four = 0, 0, 0
for x in a:
    if x % 2:
        odd += 1
    else:
        if x % 4 == 0:
            four += 1
        else:
            even += 1
if even == 0:
    if four >= odd - 1:
        print('Yes')
    else: print('No')
else:
    if four >= odd:
        print('Yes')
    else: print('No')

Submission status: Accepted

Solution code:
from math import floor
N = int(input())
a = list(map(int, input().split()))
cnt_4 = 0
for i in a:
    if i%4==0:
        cnt_4 += 1

cnt_2 = 0
for i in a:
    if i%2==0 and i%4!=0:
        cnt_2 += 1

if floor(N//2)<=cnt_4+(cnt_2//2):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
points = list(map(int, input().split()))
points = list(map(lambda i:i%4, points))
l = Counter(points)
if l[0] + int(l[2]/2) >= int(N/2):
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
amari=[0]*4

for i in range(n):
    amari[a[i]%4]+=1

if amari[2]>0:
    if amari[1]+amari[3]<=amari[0]:
        print("Yes")
    else:
        print("No")
else:
    if amari[1]+amari[3]-1<=amari[0]:
        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()]

b = [x%4 for x in a]
from collections import Counter
bco = Counter(b)

if bco[0] >= N//2 :
    print("Yes")
else :
    fe = N//2 - bco[0]
    if N%2 == 0 :
        if bco[2] >= 2*fe :
            print("Yes")
        else :
            print("No")
    else :
        if bco[2] >= 2*fe + 1 :
            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]%2==0:
        if a[i]%4==0:
            cnt_4+=1
        else:
            cnt_2+=1
if (cnt_4+cnt_2//2)>=int(len(a)/2):
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

Submission status: Accepted

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

n2 = 0
n4 = 0

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

if n2 == 0 and n4:
  n2 += 1
if n2 + n4 * 2 >= n:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
N=int(input())
a=input().split()
numbers=[int(b) for b in a]
kazu=0
suuji=0
for z in numbers:
    if z%2==0:
        kazu+=1
for y in numbers:
    if y%4==0:
        suuji+=1
kazu-=suuji
if kazu==N:
    print('Yes')
elif suuji>=N//2:
    print('Yes')
elif kazu>=N-suuji*2:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
a=int(input())
an=[int(i) for i in input().split()]
count=0
for i in an:
  if i%2==0:
    count+=1
  if i%4==0:
    count+=1
if a%2==1:
  a-=1
if count>=a:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
c = 0
d = 0
for i in A:
    if i % 4 == 0:
        c += 1
    elif i % 2 == 0:
        d += 1
if d > 0:
    if c >= n-c-d : print("Yes")
    else: print("No")
else:
    if c >= n//2: print("Yes")
    else: print("No")

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
ans = "YNeos"
for i in range(n):
  a[i] = (2 if a[i] % 4 == 0 else
          1 if a[i] % 2 == 0 else
          0)
a0 = a.count(0)
a1 = a.count(1)
a2 = a.count(2)
if a0-a2 >= 2:
  print(ans[1::2])
elif a0-a2 == 1:
  if a1 == 0:
    print(ans[::2])
  else:
    print(ans[1::2])
else:
  print(ans[::2])

Submission status: Accepted

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

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

def main():
    mod=10**9+7
    N=I()
    a=LI()
    tw=0
    fo=0
    for i in range(N):
        if a[i]%4==0:
            fo+=1
        elif a[i]%2==0:
            tw+=1
    if tw>=1:
        tw-=1
     
    N2=N-tw
    if N2//2<=fo:
        print("Yes")
    else:
        print("No")

main()

Submission status: Accepted

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

one_list = []
two_list = []
four_list = []

for i in range(N):
    if a[i]%2 == 0:
        if a[i]%4 == 0:
            four_list.append(a[i])
        else:
            two_list.append(a[i])
    else:
        one_list.append(a[i])
        
if len(two_list) > 0:
    if len(four_list) >= len(one_list):
        print('Yes')
    else:
        print('No')
else:
    if len(four_list)+1 >= len(one_list):
        print('Yes')
    else:
        print('No')

Submission status: Accepted

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

num_odd = 0
num_even = 0
num_four = 0

for i in l:
    if i % 2 == 1:
        num_odd += 1
    elif i % 4 == 0:
        num_four += 1
    else:
        num_even += 1

if num_four + 1 > num_odd:
    ans = "Yes"
elif num_four + 1 == num_odd and num_even == 0:
    ans = "Yes"
else:
    ans = "No"
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

c_4 = 0
c_2 = 0
odd = 0
for i in range(n):
    if a[i]%4==0:
        c_4+=1
    elif a[i]%2==1:
        odd += 1
    else:
        c_2 += 1
if odd <= c_4:
    print("Yes")
elif odd <= c_4+1 and c_2==0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n = int(input())
a = [int(_) for _ in input().split()]
div4 = 0
div2 = 0
for i in a:
    if i % 4 == 0:
        div4 += 1
    elif i % 2 == 0:
        div2 += 1
odd = n - div4 - div2

if div2 % 2 == 0:
    if odd-1 <= div4:
        print('Yes')
    else:
        print('No')
else:
    if odd <= div4:
        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 a:
    if i%2==0:
        if i%4==0:
            c4 += 1
        else:
            c2 += 1
if c2>0:
    m = c4*2 + c2
else:
    m = c4*2 + 1

if m>= n:
    print('Yes')
else:
    print('No')

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 cnt2 % 2 == 1:
    if cnt2 > 2:
        cnt2 -= 1
    else:
        cnt2 = 0

if n - ((cnt4*3)-(cnt4-1))-cnt2 <= 0:
    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)>=n//2 or +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()))

import math
two = 0
four = 0
for i in range(n):
    if a[i]%2 == 0:
        two += 1
        if a[i]%4 == 0:
            four += 1
two = two - four
count = four + two/2

if count >= math.ceil((n-1)/2):
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

# 4の倍数と2の倍数を(重複しないように)カウントする
mul4, mul2 = 0, 0
for a in A:
    if a%4 == 0:
        mul4 += 1
    elif a%2 == 0:
        mul2 += 1
others = n - mul4 - mul2

if others <= mul4:  # 1, 4, 1, 4, 2, 2...
    print('Yes')
elif mul2 == 0 and others <= mul4 + 1:  # 1, 4, 1, 4, 1...
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
p1,p2,p4 = (0,0,0)
for i in a:
    if i %4 ==0:
        p4 +=1
    elif i%2 ==0:
        p2 +=1
    else:
        p1+=1
ans ="Yes"
if p4+1 < p1 or(p4+1 ==p1 and p2 !=0):
    ans ="No"
print(ans)

Submission status: Accepted

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

def cnt_two(n):
    cnt=0
    if n%2==0:
        cnt+=1
        n//=2
        if n%2==0:
            cnt+=1
    return cnt

a=[cnt_two(i) for i in a]
tot=sum(a)
if 1 in a:
    if tot>=n:
        print('Yes')
    else:
        print('No')
else:
    if tot+1>=n:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

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

cnt_0, cnt_2, cnt_4 = 0, 0, 0
for i in range(N):
  if A[i] % 4 == 0:
    cnt_4 += 1
  elif A[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()))

cnt4=0
cnt2=0
cnt1=0
for i in range(N):
    if(a[i]%4==0):
        cnt4+=1
    elif(a[i]%2==0):
        cnt2+=1
    elif(a[i]%2==1):
        cnt1+=1
if(cnt2==0):
    if(cnt4+1>=cnt1):
        print("Yes")
    else:
        print("No")
        
elif(cnt2!=0):
    if(cnt4>=cnt1):
        print("Yes")
    else:
        print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    length = int(input())
    numbers = list(map(int, input().split()))
    even_num = 0
    odd_num = 0
    multiple_of_4 = 0
    for num in numbers:
        if not num % 4:
            multiple_of_4 += 1
        elif not num % 2:
            even_num += 1
        else:
            odd_num += 1
    if multiple_of_4 >= odd_num or (multiple_of_4 + 1 >= odd_num and even_num == 0):
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
cnt = 0
two = 0
for i in a:
    if i % 4 == 0:
        cnt += 1
    elif i % 4 == 2:
        two += 1
if n // 2 <= cnt:
    print("Yes")
elif two >= 2 and (n - (two - 1)) // 2 <= cnt:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
input()
a=list(map(int,input().split()))
l=[1 if i%2==1 else 4 if i%4==0 else 2 for i in a]
print('YNeos'[(2 in l and l.count(1)>l.count(4)) or (2 not in l and l.count(1)>l.count(4)+1)::2])

Submission status: Accepted

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

if n//2 <= cnt:
    print("Yes")
elif two >= 2 and (n-(two-1))//2 <= cnt:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

num_four = len([i for i in range(n) if a[i]%4==0])
num_even = len([i for i in range(n) if a[i]%4==2])
num_odd  = len([i for i in range(n) if a[i]%2!=0])

if num_even==0:
    if num_odd <= num_four+1: print('Yes')
    else: print('No')
else:
    if num_odd<=num_four: print('Yes')
    else: print('No')

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
count4=0#4の倍数
count2=0#2の倍数だが4の倍数じゃない
count1=0
for i in range(n):
    if a[i]%4==0:
        count4+=1
    elif a[i]%2==0:
        count2+=1
    else:
        count1+=1
if count2==0:
    if count1<=count4+1:
        print("Yes")
    else:
        print("No")
else:
    if count1<=count4:
        print("Yes")
    else:
        print("No")

    

    
"""
#print(count2)
if 1<=count2:
    if (n-count2//2)//2<=count or n//2<=count:
        print("Yes")
    elif count2%2==0:
        if   (n-count2)//2<count :
            print("Yes ")
        else:
            print("No")
    elif count2%2==1:
        if  (n-count2)//2<=count :
            print("Yes ")
        else:
            print("No")
else:
    if n//2<=count:
        print("Yes")
    else:
        print("No")

    """
"""    7
    2 2 2 2 3 4 3

    YES になる間違い13晩のテキスト

"""

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def adjacent4(n , a):

    ans = "No"
    zero = 0
    iti = 0
    ni = 0

    for i in range(n):
        if a[i] % 2 == 1:
            zero += 1
        elif (a[i] / 2) % 2 == 0:
            ni += 1
        else:
            iti += 1

    if iti > 0 and zero <= ni:
        ans = "Yes"
    elif iti == 0 and zero <= ni + 1:
        ans = "Yes"
    return ans

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

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

li = [0] * 3

for a in A:
  if a % 2 != 0:
    li[0] += 1

  elif a % 4 == 0:
    li[2] += 1

  else:
    li[1] += 1

if N % 2 == 0:
  if li[0] > li[2]:
    print("No")
    sys.exit()

  li[2] -= li[0]
  li[1] -= li[2]

  if li[1] % 2 != 0:
    print("No")
    sys.exit()


if N % 2 != 0:
  if li[0] - 1 > li[2]:
    ans = "No"

  li[2] -= li[0] - 1
  li[1] -= li[2]

  if li[1] % 2 != 0:
    print("No")
    sys.exit()

print("Yes")

Submission status: Accepted

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

d2 = 0
d4 = 0

for ai in aa:
  if ai % 4 == 0:
    d4 += 1
  elif ai % 2 == 0:
    d2 += 1
  else:
    pass  

if d2<=1:
  d2=0
else:
  d2 -= 1
dd = n - d2
if d4 >= dd//2:  
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
from sys import exit

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

m1 = 0
m2 = 0
m4 = 0

for a in A:
	if a%4==0:
		m4 += 1
	elif a%2==0:
		m2 += 1
	else:
		m1 += 1


m1 = m1 + (m2>0)
if m4>=m1-1:
	print('Yes')
else:
	print('No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
lst = [int(x) for x in input().split()]
a = 0
b = 0
for n in lst:
    if n % 4 == 0:
        a += 1
    elif n % 2 == 0:
        b += 1

if b >= 2:
    N = N - (b - 1)

if a >= N // 2:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n = int(input())

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

amount = 0
sub = 0
for i in lst1:
    if i%4 == 0:
        amount += 1
    elif i%2 == 0:
        sub += 1

if amount + sub//2 >= len(lst1)//2:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

def calc(n):
    x = 0
    while(1):
        if n%2==0:
            n=n//2
            x+=1
        else:
            return x
        if x>=2:
            return x
x=[]
y=[]
z=[]
for i in range(N):
    b = calc(a[i])
    if b==2:
        x.append(a[i])
    elif b==1:
        y.append(a[i])
    else:
        z.append(a[i])

X=len(x)
Y=len(y)
Z=len(z)

if Y==0:
    if Z<=(X+1):
        print("Yes")
        exit()
    else:
        print("No")
        exit()
else:
    if Z<=X:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
OD=0
EV4=0
for i in A:
  if i%2==1:
    OD+=1
  elif i%4==0:
    EV4+=1
EV=N-OD-EV4
ret = 'No'
if EV4>=OD:
  ret='Yes'
elif EV4==OD-1 and EV==0:
  ret='Yes'
print(ret)

Submission status: Accepted

Solution code:
n = int(input())

two = 0
four = 0
for i in map(int, input().split()):
    if i % 4 == 0:
        four += 1
    elif i % 2 == 0:
        two += 1

tmp = two * (two > 1)
print('Yes' if (four * 2 + (four == n // 2) + two * (two > 1)) >= n else 'No')

Submission status: Accepted

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

count2 = 0
count4 = 0

for i in range(len(a)):
    if((a[i] % 4) == 0):
        count4 = count4 + 1;
    elif((a[i] % 2) == 0 and (a[i] % 4) != 0):
        count2 = count2 + 1;

#print("---")
#print(count4)
#print(count2)
#print("---")

if(count2 == 0 and n <= (1+ count4*2)):
    print("Yes")
elif(count2 != 0 and n <= (count2+ count4*2)):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
from numpy import log
def f(k):
  c=0
  while k % 2 == 0:
    k //= 2
    c+=1
    if c==2:
      break
  return c
def g(k):
  return f(int(k))
n=int(input())
a=list(map(g,input().split()))
ct0=a.count(0)
ct1=a.count(1)
ct2=a.count(2)
if ct0 <= ct2 or (ct0 == ct2 + 1 and ct1==0):
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
cntf=0
cntno=0
for i in A:
  if i%4==0:
    cntf+=1
  if i%2==1:
    cntno+=1

    
if cntf+cntno==N:
  if cntf>=(N//2):
    print('Yes')
  else:
    print('No')
else:
  if cntf>=cntno:
    print('Yes')
  else:
    print('No')

Submission status: Accepted

Solution code:
def solve(n, A):
    # 方針: 下記のいずれかの条件を満たせばOK
    #  1. 4の倍数の数 == 奇数の数 - 1 and 2の倍数がない
    #  2. 4の倍数の数 >= 奇数の数
    count_odd, count_2n, count_4n = 0, 0, 0
    for a in A:
        if a % 2 == 1:
            count_odd += 1
        elif a % 4 == 0:
            count_4n += 1
        else:
            count_2n += 1
    return 'Yes' if (count_4n == count_odd - 1 and count_2n == 0) or count_4n >= count_odd else 'No'

_n = int(input())
_A = map(int, input().split())
print(solve(_n, _A))

Submission status: Accepted

Solution code:
n=int(input())
a=[int(i)for i in input().split()]
count2=0
count4=0
for i in a:
    if i%4==0:
        count4+=1
        continue
    if i%2==0:
        count2+=1
if count2!=0:n-=count2-1
if count4>=int(n/2):print("Yes")
else:print("No")

Submission status: Accepted

Solution code:
n = int(input())

nList = list(map(int,input().split()))
L2count = 0
L4count = 0

for i in nList:
  if i%4 == 0:
    L4count += 1
  elif i%2 == 0:
    L2count += 1

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

Submission status: Accepted

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

if t > 0:
    if f >= k:
        print("Yes")
    else:
        print("No")
else:
    if f + 1 >= k:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
import math
import calendar
import fractions
import itertools

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

n = int(input())
a = map(int, input().split())
b = []
ans = 0
for i in a:
    c = i
    cnt = 0
    while c % 2 == 0 and cnt < 2:
        c /= 2
        cnt += 1
    b.append(cnt)
if my_index(b, 1) == False:
    if b.count(2) + 1 >= b.count(0):
        ans = 1
    else:
        ans = 0
else:
    if b.count(2) >= b.count(0):
        ans = 1
    else:
        ans = 0
if ans == 1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

four = len([1 for i in a if i%4 == 0])
two = len([1 for i in a if i%2 == 0]) - four
four += two//2
if four >= n-four-1:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N = int(input())
lst = list(map(int,input().split()))
c1 = 0
c2 = 0
for i in lst:
  if (i % 4 == 0):
    c1 += 1
  elif (i % 2 != 0):
    c2 += 1
    
ans = 'No'
if (len(lst) % 2 == 0):
  if (c1 >= c2):
    ans = 'Yes'
else:
  if (c1 >= c2 - 1):
    ans = 'Yes'
print(ans)

Submission status: Accepted

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

b1 = 0
b2 = 0
b4 = 0
for _a in a:
    if _a%4 == 0:
        b4 += 1
    elif _a%2 == 0:
        b2 += 1
    else:
        b1 += 1

if b2 == 0:
    print("Yes" if b1 <= b4+1 else "No")
else:
    print("Yes" if b1 <= b4 else "No")

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
f, t = 0, 0
for ai in a:
  if ai % 4 == 0:
    f += 1
  elif ai % 2 == 0:
    t += 1	
r = n - 2 * f
if r - 1 <= 0 or r <= t:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
a = list(map(int,input().split()))
num_odd = sum([1 for i in a if i % 2 == 1])
num_4 = len([1 for i in a if i % 4 == 0])
#print(a,num_odd,num_4)
if num_4 >= num_odd:
    print("Yes")
else: 
    if num_odd == (n+1)/2:
        if num_4 == (n-1)/2:
            print("Yes")
            exit(0)
    print("No")

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
cnt4 = cnt2 = 0
for i in a:
    if i % 4 == 0:
        cnt4 += 1
    elif i % 2 == 0:
        cnt2 += 1
if cnt4 >= n//2:
    print('Yes')
elif cnt2 >= n-cnt4*2:
    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 x in a:
    if x % 4 == 0:
        four += 1
    elif x % 2 == 0:
        two += 1
    else:
        one += 1

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

Submission status: Accepted

Solution code:
import sys
from collections import Counter


input = sys.stdin.readline


def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    C = Counter()
    for a in A:
        if a % 4 == 0:
            C[4] += 1
        elif a % 2 == 0:
            C[2] += 1
        else:
            C[0] += 1
    if C[2] >= 1:
        if C[0] > C[4]:
            print("No")
        else:
            print("Yes")
    else:
        if C[0] > C[4] + 1:
            print("No")
        else:
            print("Yes")


if __name__ == '__main__':
    main()

Submission status: Accepted

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

quadruple_cnt = 0
double_cnt = 0
other_cnt = 0

for i in range(N):
    if a[i] % 4 == 0:
        quadruple_cnt += 1
    elif a[i] % 2 == 0:
        double_cnt += 1
    else:
        other_cnt += 1

if double_cnt == 0:
    n = 0
else:
    n = 1

if quadruple_cnt >= other_cnt - 1 + n:
    ans = "Yes"
else:
    ans = "No"

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
numof4 = 0
numof2 = 0
numofodd = 0
for i in range(N):
    if A[i] % 4 == 0:
        numof4 += 1
    elif A[i] % 2 == 0:
        numof2 += 1
    else:
        numofodd += 1

if numof4 > 0:
    if numof4 >= numofodd:
        print("Yes")

    elif numof4 > 0 and numof4 >= numofodd - 1 and numof2 == 0:
        print("Yes")
    else:
        print("No")
else:
    if numofodd == 0:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

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

if multipleOf2 + multipleOf4 == N:
    print('Yes')
    exit()
elif multipleOf2 == 0:
    if multipleOf4 >= odd-1:
        print('Yes')
        exit()
    else:
        print('No')
        exit()
elif multipleOf2 >= 1:
    if multipleOf4 >= odd:
        print('Yes')
        exit()
    else:
        print('No')
        exit()
    
# print(multipleOf2, multipleOf4, odd)

Submission status: Accepted

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

p1, p2, p4 = (0, 0, 0)
for ai in a:
	if ai % 4 == 0:
		p4 += 1
	elif ai % 2 == 0:
		p2 += 1
	else:
		p1 += 1
		
ans = 'Yes'
if p4 + 1 < p1 or (p4 + 1 == p1 and p2 != 0):
	ans = 'No'

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
arr = list(map(int, input().split()))
two_count = 0
four_count = 0
for i in arr:
    if i % 4 == 0:
        four_count += 1
        continue
    if i % 2 == 0:
        two_count += 1
        continue
ans = N - ((two_count//2)*2 + (four_count*2) + 1 if four_count > 0 else 0)
if ans <= 0 or two_count == N:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

m2, m4, rest = [], [], []
for i in range(N):
    if An[i] % 2 == 0 and An[i] % 4 != 0:
        m2.append(An[i])
    elif An[i] % 4 == 0:
        m4.append(An[i])
    else:
        rest.append(An[i])

ans = "No"
if len(m4) == len(rest):
    ans = "Yes"
if len(m4) == len(rest)-1 and len(m2) == 0:
    ans = "Yes"
if not len(rest):
    ans = "Yes"

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
b = len([a for a in A if a % 4 == 0])
c = len([a for a in A if a % 2])
d = len([a for a in A if a % 2 == 0 and a % 4])
print("YNeos"[not(b>=c if d else b >= c-1)::2])

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
a =[int(i) for i in input().split()]
x = 0
y = 0
z = 0
for i in range(N) :
    if a[i] % 2 != 0 :
        x+=1
    elif a[i] % 2 == 0 and a[i] % 4 != 0 :
        y += 1
    else :
        z +=1
ans = "No"
if y >= 1 :
    y = 1
    if x <= z :
        ans = "Yes"
else :
    if x <= z + 1 :
        ans = "Yes"
print(ans)