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
# -*- coding: utf-8 -*-
"""
Created on 2019/3/23
Solved on 2019/3/
@author: shinjisu
"""


# ABC 069 C - 4-adjacent

def getInt(): return int(input())

def getIntList(): return [int(x) for x in input().split()]
# def getIntList(): return np.array(input().split(), dtype=np.longlong)

def zeros(n): return [0]*n
# def zeros(n): return np.zeros(n, dtype=np.longlong)

def getIntLines(n): return [int(input()) for i in range(n)]
"""
def getIntLines(n):
    data = zeros(n)
    for i in range(n):
        data[i] = getInt()
    return data
"""

def zeros2(n, m): return [zeros(m) for i in range(n)] # obsoleted zeros((n, m))で代替

def getIntMat(n, m):  # n行に渡って、1行にm個の整数
    #mat = zeros((n, m))
    mat = zeros2(n, m)
    for i in range(n):
        mat[i] = getIntList()
    return mat

ALPHABET = [chr(i+ord('a')) for i in range(26)]
DIGIT = [chr(i+ord('0')) for i in range(10)]
N1097 = 10**9 + 7
INF = 10**18

class Debug():
    def __init__(self):
        self.debug = True
 
    def off(self):
        self.debug = False
 
    def dmp(self, x, cmt=''):
        if self.debug:
            if cmt != '':
                print(cmt, ':  ', end='')
            print(x)
        return x


def prob():
    d = Debug()
    d.off()
    N = getInt()
    d.dmp((N), 'N')
    A = getIntList()
    d.dmp((A), 'A')
    odd, two, four = 0, 0, 0
    for e in A:
        if e % 4 == 0:
            four += 1
        elif e % 2 == 0:
            two += 1
        else:
            odd += 1
    d.dmp((odd, two, four), 'odd, two, four')
    if two > 0:
        odd += 1
    d.dmp((odd, four), 'odd, four')
    if four+1 >= odd:
        return 'Yes'
    else:
        return 'No'


ans = prob()
if ans is None:
    pass
elif type(ans) == tuple and ans[0] == 1:  # 1,ans
    for elm in ans[1]:
        print(elm)
else:
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
x2, x4, x = 0, 0, 0

for num in input().split(' '):
    tmp = int(num)
    x2 += tmp % 2 == 0 and tmp % 4 != 0
    x4 += tmp % 4 == 0
    x += tmp % 2 != 0

print("Yes" if x + (x2 != 0) <= x4 + 1 else "No")

Submission status: Accepted

Solution code:
# coding: UTF-8
N=int(input())
a=list(map(int,input().split()))
f=0
g=0
h=0
for i in range(N):
    if a[i]%4==0:
        f=f+1
    elif a[i]%2==0:
        g+=1
    else :
        h+=1
if g==0 and f>=h-1 :
    print("Yes")
elif g>=1 and f>=h:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#69 C

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

nums = [0, 0, 0]

for tmp in a:
	if tmp%4 == 0:
		nums[0] += 1
	elif tmp%2 == 0:
		nums[1] += 1
	else:
		nums[2] += 1
		
if nums[1] > 0:
	pass
else:
	nums[2] -= 1

if nums[0] >= nums[2]:
	print('Yes')
else:
	print('No')

Submission status: Accepted

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

a2 = len(list(filter(lambda x:x%2==0, a)))
a4 = len(list(filter(lambda x:x%4==0, a)))

if n == a2:
    print("Yes")
    exit()

a2_ = a2 - a4
n = n if a2_==0 else (n-a2_+1)
if n//2 <= a4:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n = int(input())
A =list(map(int,input().split()))
num4 = 0
num2 = 0
num1 = 0
for a in A:
    if a%4 == 0:
        num4 += 1
    elif a%2 == 0:
        num2 += 1
    else:
        num1 += 1

if num2 == 0:
    if num4 >= num1-1:
        print("Yes")
    else:
        print("No")
else:
    if num4 >= num1:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

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

ans = "No"
two_mul = []
four_mul = []
for i in a:
    if i % 2 == 0 and i % 4 != 0:
        two_mul.append(i)
    elif i % 4 == 0:
        four_mul.append(i)

if len(four_mul) == 0:
    if len(two_mul) == N:
        ans = "Yes"
else:
    if len(two_mul) == 0:
        if len(four_mul) >= N//2:
            ans = "Yes"
    else:
        if ((N - len(two_mul))+1)//2 <= len(four_mul):
            ans = "Yes"

print(ans)

Submission status: Accepted

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

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

if c1>0:
  p = 1
  c1 -= 1
elif c2>0:
  p = 2
  c2 -= 1
else:
  p = 4
  c4 -= 1

while c1+c2+c4>0:
  if p==1:
    if c4>0:
      c4 -= 1
      p = 4
    else:
      print "No"
      break
  elif p==2:
    if c2>0:
      c2 -= 1
      p = 2
    elif c4>0:
      c4 -= 1
      p = 4
    else:
      print "No"
      break
  else:
    if c1>0:
      c1 -= 1
      p = 1
    elif c2>0:
      c2 -= 1
      p = 2
    else:
      c4 -= 1
      p = 4
else:
  print "Yes"

Submission status: Accepted

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

count_odd = 0
count_4 = 0
count_2 = 0
for i in A:
    if i % 2 != 0:
        count_odd += 1
    else:
        if i % 4 == 0:
            count_4 += 1
        else:
            count_2 += 1
            
if count_4 + 1 >= count_odd + count_2:
    print('Yes')
else:
    if count_2 > 1 and count_4 + 1 - count_odd > 0:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

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

tmp = [a%4 for a in A]
four = tmp.count(0)
two = tmp.count(2)

if(four+two//2 >= N//2):
  print("Yes")
else:
  print("No")

Submission status: Accepted

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


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

    for ai in a:
        if ai % 4 == 0:
            four_count += 1
        elif ai % 2 == 0:
            two_count += 1

    if four_count >= n // 2:
        print('Yes')
    else:
        need = n - 2 * four_count

        if two_count >= need:
            print('Yes')
        else:
            print('No')


if __name__ == '__main__':
    main()

Submission status: Accepted

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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


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

if num2 > 1:
    if num4 >= (N-(num2-1))//2: print( 'Yes' )
    else: print( 'No' )
else:
    if num4 >= N//2: print( 'Yes' )
    else: print( 'No' )

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A

#B

#C
n = I()
a = LI()
d = [0,0]
for i in a:
    if i%2:
        d[0] += 1
    if i%4 == 0:
        d[1] += 1
if n % 2:
    d[0] -= 1
d[0] -= d[1]
if d[0] <= 0:
    print("Yes")
else:
    print("No")
#D

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T

Submission status: Accepted

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

cnt_t = 0
cnt_f = 0

for i in l:
  if i%4==0:
    cnt_f += 1
  elif i%2==0:
    cnt_t += 1

num = N-cnt_t-cnt_f

if cnt_t == 0:
  cnt_f += 1
if num <= cnt_f:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
def main():
    _ = int(input())
    a = [int(s) for s in input().split()]
    if solve(a):
        print('Yes')
    else:
        print('No')

def solve(a):
    odds = 0
    f4 = 0

    for i in a:
        if i % 4 == 0:
            f4 += 1
        elif i % 2 != 0:
            odds += 1
    
    if f4 + odds == len(a) and f4 + 1 == odds:
        return True
    elif f4 >= odds:
        return True
    else:
        return False

main()

Submission status: Accepted

Solution code:
#ABC069C
N=int(input())
A=list(map(int,input().split()))
four=0
two=0
other=0
for a in A:
	if a%4==0:
		four+=1
	elif a%2==0:
		two+=1
	else:
		other+=1
print('Yes') if other+(two>0)-(four+1)<=0 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==0:
    if cnt4>=N-cnt4-1:
        print('Yes')
    else:
        print('No')
else:
    if cnt4>=N-cnt4-cnt2:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

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

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

if cnt >= n//2:
    print('Yes')
else:
    if n - cnt*2 <= two:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

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

cnt = 0
cnt2 = 0
for i in range(N):
    if A[i] % 4 == 0:
        cnt += 1
    elif A[i] % 2 == 0:
        cnt2 += 1
    
ans = 'No'
if cnt2 % 2 == 0:
    if cnt >= (N - cnt2) // 2:
        ans = 'Yes'
else:
    if cnt >= (N - cnt2 + 1) // 2:
        ans = 'Yes'
        
print(ans)

Submission status: Accepted

Solution code:
input()
a = [int(i) for i in input().split()]
c = [i for i in a if i % 4 != 2]
if len(c) != len(a):
    c.append(1)
if len([i for i in c if i % 4 != 0]) - 1 <= len([i for i in c if i % 4 == 0]):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N = int(input())
L = list(map(int,input().split()))
one = list(filter(lambda x:x%2!=0,L))
two = list(filter(lambda x:x%4!=0 and x%2==0,L))
four = list(filter(lambda x:x%4==0,L))
if len(one) - len(four) == 1 :
    if len(two) >=1 :
        print("No")
    else:
        print("Yes")
elif len(one) <= len(four):
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))
a2 = [i % 2 for i in a].count(0)
a4 = [i % 4 for i in a].count(0)
a0 = n - a2
a2 -= a4
if a2 == 0:
    if a0 <= a4+1:
        ans = "Yes"
    else:
        ans = "No"
else:
    if a0 <= a4:
        ans = "Yes"
    else:
        ans = "No"
print(ans)

Submission status: Accepted

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

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] = 2
    elif a[i] % 2 == 0:
        a[i] = 1
    else:
        a[i] = 0

two = a.count(2)
one = a.count(1)
zero = a.count(0)
if two >= n // 2:
    print("Yes")
else:
    if n - two * 2 == one:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stderr, setrecursionlimit
setrecursionlimit(2147483647)
def getint():
    return int(input())
def getints():
    return [int(i) for i in input().split()]
def getintlines(n=1):
    res = []
    for _ in range(n):
        res.append(getint())
    return res
def getintslines(n=1):
    res = []
    for _ in range(n):
        res.append(getints())
    return res
def debug(*args, **kwargs):
    print(*args, file=stderr, **kwargs)

n = getint()
a = getints()

twice = list(filter(lambda x:x%4==2, a))
quad = list(filter(lambda x:x%4==0, a))

if len(quad) >= n//2:
    print("Yes")
elif len(twice) + 2*len(quad) >= n:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import math

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

mul_num = 0
two_num = 0
other_num = 0

for i in A:
    if i % 4 == 0:
        mul_num += 1
    elif i % 2 == 0:
        two_num += 1
    else:
        other_num += 1

if mul_num + two_num//2 >= N // 2:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

B = [a%4 for a in A]
four = B.count(0)
two = B.count(2)

if(four + two//2 >= N//2):
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
import numpy as np
n, a = int(input()), np.array(list(map(int,input().split())))
odd, div4 = len(np.where(a%2==1)[0]), len(np.where(a%4==0)[0])
ans = "Yes" if (n%2==0 and odd <= div4) or (n%2==1 and ((odd-1==div4 and odd+div4==n) or div4 >= odd)) else "No"
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
n, a = int(input()), np.array(list(map(int,input().split())))
odd, div2, div4 = len(np.where(a%2==1)[0]), len(np.where((a%2==0) & (a%4!=0))[0]), len(np.where(a%4==0)[0])
ans = "Yes" if (n%2==0 and odd <= div4) or (n%2==1 and ((odd-1==div4 and odd+div4==n) or div4 >= odd)) else "No"
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = map(int,input().split())   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = list(map(int,input().split()))	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]


from collections import defaultdict, Counter
import math
from bisect import bisect_left, bisect_right
import numpy as np

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

f_cnt = 0
t_cnt = 0
o_cnt = 0

for ai in a:
    if ai%4 == 0:
        f_cnt += 1
    elif ai%2 == 0:
        t_cnt += 1
    else:
        o_cnt += 1

if t_cnt == 0:
    if f_cnt+1>=o_cnt:
        print("Yes")
    else:
        print("No")
else:
    if f_cnt>=o_cnt:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = {1: 0, 2: 0, 4: 0}
for i in a:
    if i % 2:
        b[1] += 1
    else:
        if (i // 2) % 2:
            b[2] += 1
        else:
            b[4] += 1
if b[1] + b[2] - 1 <= b[4]:
    print("Yes")
    exit()
if b[1] <= b[4]:
    print("Yes")
    exit()
print("No")

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = {1: 0, 2: 0, 4: 0}
for i in a:
    if i % 2:
        b[1] += 1
    else:
        if (i // 2) % 2:
            b[2] += 1
        else:
            b[4] += 1
if b[1] + b[2] - 1 <= b[4]:
    print("Yes")
    exit()
if b[1] <= b[4]:
    print("Yes")
    exit()
if b[1] == 0:
    print("Yes")
    exit()
print("No")

Submission status: Accepted

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

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]=0
  elif A[i]%2==0:
    A[i]=2
  else:
    A[i]=1

a=A.count(0)
b=A.count(2)
c=A.count(1)
if c<=a :
  print("Yes")
elif b==0 and c==a+1:
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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

even = len(list(filter(lambda x: x % 2 == 0, A)))
even2 = len(list(filter(lambda x: x % 4 == 0, A)))
odd = N-even
ans = "No"
if even == N:
    ans = "Yes"
if even-even2 == 0:
    if odd <= even2+1:
        ans = "Yes"
else:
    if odd <= even2:
        ans = "Yes"
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter as cntr

n = int(input())
*a, = map(lambda x: x % 4, map(int, input().split()))
d = cntr(a)
c0, c1, c2 = d[1]+d[3], d[2], d[0]
if c1:
    print("Yes" if c2 >= c0 else "No")
else:
    print("Yes" if c2 >= c0-1 else "No")

Submission status: Accepted

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

    N4 = sum(map(lambda x: x%4==0, a))
    N2 = sum(map(lambda x: x%2==0 and x%4!=0, a))
    N1 = sum(map(lambda x: x%2!=0, a))
    assert N1+N2+N4==N

    return N1 <= N4 or (N4==N1-1 and N2==0)


def main():
    ans = solve()
    if ans:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

Submission status: Accepted

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

B = [a%4 for a in A]
refour = B.count(0)
retwo = B.count(2)

if(refour + retwo//2 >= N//2):
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def solve(N, As):
    # print(N, ",", As)
    n4 = len([n for n in As if n % 4 == 0])
    n2 = len([n for n in As if n % 4 != 0 and n % 2 == 0])
    n0 = len([n for n in As if n % 2 != 0])
    if n2 >= 2:
        return "Yes" if n4 >= n0 else "No"
    else:
        return "Yes" if (n4 + 1) >= (n0 + n2) else "No"


if __name__ == "__main__":
    N = int(input())
    As = list(map(int, input().split(" ")))
    print(solve(N, As))

Submission status: Accepted

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

m4 = 0
even = 0
for i in range(n):
    if A[i] % 4 == 0:
        m4 += 1
    if A[i] % 2 == 0:
        even += 1
        
if m4 >=  n // 2 or even == n or (n - even) == m4:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
#069-C
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return input()

n=I()
a=IL()
ans="No"
a2=0
a4=0
for i in range(n):
    if a[i]%4==0:
        a4+=1
    elif a[i]%2==0:
        a2+=1
if 2*a4+a2>=n:
    ans="Yes"
if 2*a4+1>=n:
    ans="Yes"
print(ans)

Submission status: Accepted

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

len_1 = len([a for a in A if a % 2 == 1])
len_4 = len([a for a in A if a % 4 == 0])

if len_1 <= len_4:
    print('Yes')
elif len_1 + len_4 == len(A) and len_1 == len_4 + 1:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

cnt0,cnt1,cnt2 = 0,0,0

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

if cnt1 == 0:
    if cnt0 - cnt2 <= 1:
        print('Yes')
    else:
        print('No')
else:
    if cnt0 - cnt2 <= 0:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
a = int(input())
c = list(map(int,input().split()))
c1=c2=c4=0
for i in c:
    if i%2==1:
        c1+=1
    elif i%4==0:
        c4+=1
    else:c2+=1
if c1+c2-c4==1:print("Yes")
elif c1<=c4:print("Yes")
else:print("No")

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int, input().split()))
cou_4 = 0
cou_2 = 0

for i in range(n):
    a = A[i]
    if a % 4 == 0:
        cou_4 += 1
    elif a % 2 == 0:
        cou_2 += 1
        
if cou_2 == 0 and cou_4 > 0:
    cou_2 += 1
if n <= 2*cou_4 + cou_2:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
odd = 0
even2 = 0
even4 = 0
for i in A :
    if not i % 4 :
        even4 += 1
    elif not i % 2 :
        even2 += 1
    else :
        odd += 1
#print(odd,even2,even4)
if (odd <= even4) or (N//2 <= even4) :
    ans = "Yes"
else :
    ans = "No"

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
c_4 = 0
c_2 = 0
c_O = 0
for e in a:
    if e % 4 == 0:
        c_4 += 1
    elif e % 2 == 0:
        c_2 += 1
    else:
        c_O += 1
if c_2 > 0:
    c_O += 1
if c_O <= c_4 + 1:
    ans = "Yes"
else:
    ans = "No"
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
l=list(map(int,input().split()))
two=four=0
for i in l:
    if i%4==0:four+=1
    elif i%2==0:two+=1
print("Yes" if two==n or four>=n//2 or two+2*four>=n else "No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
num4 = 0;num2 = 0
for i in range(n):
    if a[i] % 4 == 0:
        num4 += 1
        continue
    elif a[i] % 2 == 0:
        num2 += 1
num2 = num2 // 2
if n // 2 <= num4 + num2:print('Yes')
else:print('No')

Submission status: Accepted

Solution code:
n = int(input())
a = list(int(i) for i in input().split()) 
#2倍数か4倍数か判定する
a2n = 0
a4n = 0
for i in range(n):
 if a[i]%2 == 0:
  if a[i]%4 == 0:
   a4n += 1
  else:
   a2n += 1
#print (a4n)
#print (a2n)
if n > 2 and a4n >0:
 pos = 2 * a4n +1 + 2*(a2n//2)
elif n >= 2 and a4n == 0:
 pos = 2*(a2n//2)


if n <= pos:
 ans ='Yes'
else:
 ans = 'No'

print(ans)

Submission status: Accepted

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

x4count = 0
x2count = 0
for i,x in enumerate(a):
    if x % 4 == 0:
        x4count += 1
    elif x % 2 == 0:
        x2count += 1

# 2の処理
if x2count > 0:
    N = N - x2count + 1

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

Submission status: Accepted

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

t=0
f=0

for i in a:
    if i%4==0:
        f+=1
    elif i%2==0:
        t+=1

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

Submission status: Accepted

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

multip4 = 0
unbreakable = 0

for i in a:
    if i % 4 == 0:
        multip4 += 1

    elif i % 2 != 0:
        unbreakable += 1

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

if multip4 >= unbreakable:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

a=[]
b=[]
c=[]
for i in range(N):
    if arr[i]%4 == 0:
        a.append(arr[i])
    elif arr[i]%2 == 0:
        b.append(arr[i])
    else:
        c.append(arr[i])
if len(c) > len(a)+1:
    print('No')
elif len(c) < len(a) + 1:
    print('Yes')
elif len(b)%2 == 1:
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
def abc069_c():
    n = int(input())
    a = list(map(int, input().split()))
    two = 0
    four = 0
    odd = 0
    for v in a:
        if v % 2 == 0:
            if v % 4 == 0:
                four += 1
            else:
                two += 1
        else:
            odd += 1

    if four >= odd or (four + odd == n and odd - four == 1):
        print("Yes")
    else:
        print("No")


abc069_c()

Submission status: Accepted

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

cnt2 = cnt4 = 0
for i in a:
    if i % 2 == 0:
        if i % 4 != 0:
            cnt2 += 1
        else:
            cnt4 += 1

if cnt2:
    if ((n-cnt2+1)//2) <= cnt4:
        print('Yes')
    else:
        print('No')
else:
    if (n-cnt2)//2 <= cnt4:
        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] % 2 == 0:
        if a[i] % 4 != 0:
            cnt2 += 1
        else:
            cnt4 += 1

if cnt2:
    if ((n-cnt2+1)//2) <= cnt4:
        print('Yes')
    else:
        print('No')
else:
    if (n-cnt2)//2 <= cnt4:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
N,*A=map(int,open(0).read().split());a=sum(x%4<1for x in A);print('YNeos'[a+(sum(x%2<1for x in A)-a)//2<N//2::2])

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
b4 = b2 = 0
for x in A:
    if x % 4 == 0:
        b4 += 1
    elif x % 2 == 0:
        b2 += 1
print('Yes' if b4 + b2 // 2 >= N // 2 else 'No')

Submission status: Accepted

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

Submission status: Accepted

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

mul4 = len([e for e in a if e % 4 == 0])
mul2 = len([e for e in a if e % 2 == 0])

if mul4 >= N // 2 or mul2 == N or mul2 - mul4 >= N - mul4 * 2:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    aa = list(map(int, input().split()))
    counts = [0] * 3
    for a in aa:
        if a % 4 == 0:
            counts[2] += 1
        elif a % 2 == 0:
            counts[1] += 1
        else:
            counts[0] += 1
    if counts[0] <= counts[2] or counts[0] == counts[2] + 1 and counts[1] == 0:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=input()
a=[(int(i)%4==0)+(int(i)%2==0) for i in input().split()]
b=a.count(0)-a.count(2)
print(["No","Yes"][b<=0 or (b==1 and a.count(1)==0)])