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:

input()
vals    = input()
vals    = vals.split()
vals    = list(map(lambda v:int(v), vals))


kisu    = 0
div4    = 0
div2    = 0

for e in (vals):
    if e % 4 == 0:
        div4    += 1
    elif e % 2 == 1:
        kisu    += 1
    else:
        div2    += 1

if div4 >= kisu:
    print("Yes")
elif div4 == kisu - 1 and len(vals) == div4 + kisu:
    print("Yes")
elif div2 == len(vals):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N = int(raw_input())
a = [int(i[-2:])for i in raw_input().split(" ")]

c1 = 0
c2 = 0

for ai in a:
    if ai % 2 != 0:
        c1 += 1
    elif ai % 4 == 0:
        c2 += 1
if c1 <= c2:
    print "Yes"
elif c1 - 1 == c2 and N == c1 + c2:
    print "Yes"
else:
    print "No"

Submission status: Accepted

Solution code:
n = input()
ain = input()
a = ain.split()
count = 0.0

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

if(int(count) >= (int(n) // 2)):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import math
 
num = int(input())
value = input().split()
value = [int(x) for x in value]
 
res = 0
two = 0
for i in value:
    if i % 4 == 0:
        res += 1
    elif i % 2 == 0:
        two += 1
 
if two > 0:
    print("Yes" if res >= math.ceil((len(value)-two)/2) else "No")
else:
    print("Yes" if res >= math.floor(len(value)/2) else "No")

Submission status: Accepted

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

c = [0,0,0,0]
for x in a:
    c[x % 4] += 1

# if (c[1]==0) and (c[3]==0):
#     print('Yes')

if c[1] + c[3] < c[0] + 1:
    print('Yes')
elif (c[1] + c[3] == c[0] + 1)and(c[2] == 0):
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

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

if count4==0:
    if count2-count2%2>=n:
        print("Yes")
    else:
        print("No")

else:
    if count4*2+1+count2-count2%2>=n:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
N = int(input())
c = [0, 0, 0]  # 0, 2, 4

for i in map(int, input().split()):
    if i % 4 == 0:
        c[2] += 1
    elif i % 2 == 0:
        c[1] += 1
    else:
        c[0] += 1

if c[0] <= c[2] + (c[1] == 0):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N = int(input())
c = [0, 0, 0]  # 0, 2, 4

for i in map(int, input().split()):
    if i % 4 == 0:
        c[2] += 1
    elif i % 2 == 0:
        c[1] += 1
    else:
        c[0] += 1

if c[0] + (c[1] > 0) <= c[2]+1:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N = input()
A = input()
a = A.split(' ')

si = []
for i in a:
    j = int(int(i) % 4)
    si.append(j)

kazu = []
for i in range(4):
    j = si.count(i)
    kazu.append(j)

x = int(int(kazu[2]) % 2)
if x == 0:
    y = int(int(kazu[1]) + int(kazu[3]) - 1)
else:
    y = int(int(kazu[1]) + int(x) + int(kazu[3]) - 1)

if int(kazu[0]) >= int(y):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
# coding: utf-8
# Here your code !

N  = int(input())
a = list(map(int,input().split()))
n_4 ,n_2 ,n_1 = 0,0,0
ans = ""

for i in range(N):
    if a[i] %4 ==0:
        n_4 += 1
    elif a[i] %4 == 2:
        n_2 += 1
    else :
        n_1 += 1
if n_1 < n_4 + 1:
    ans = "Yes"
elif (n_1 == n_4 + 1)and(n_2 == 0):
    ans = "Yes"
elif n_1 == 0:
    ans = "Yes"
else :
    ans ="No"

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
count4 = 0
count2 = 0
countelse = 0
for i in range(n):
	if a[i] % 4 == 0:
		count4 += 1
	if a[i] % 2 == 0:
		count2 += 1
	else:
		countelse += 1
count2 = count2 - count4
if n % 2 != 0:
	if count4 < (countelse - 1):
		print('No')
	else:
		print('Yes')
else:
	if count4 < countelse:
		print('No')
	else:
		print('Yes')

Submission status: Accepted

Solution code:
N =input()
a =input().split()
b,c,d =0,0,0
for i in range(0,int(N)):
    hoge = int(a[i])%2
    if hoge ==0:
        b =b+1
for i in range(0,int(N)):
    hoge = int(a[i])%4
    if hoge ==0:
        c =c+1
d = b-c
if d ==0:
    if c-(int(N)-b)+1>=0:
        print('Yes')
    else:
        print('No')
else:
    if c-(int(N)-b)>=0:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
http://abc069.contest.atcoder.jp/tasks/arc080_a

"""


def solve(data):
    l_data = len(data)
    mo4s = [x for x in data if x%4 == 0] #  multiple of 4
    l_mo4s = len(mo4s)
    odds = [x for x in data if x%2 == 1]
    l_odds = len(odds)
    l_evens = l_data - l_odds - l_mo4s
    # print('4の倍数: {}'.format(l_mo4s))
    # print('奇数: {}'.format(l_odds))
    # print('偶数(4の倍数以外): {}'.format(l_evens))

    if l_odds > (l_mo4s + 1):
        return 'No'
    if (l_odds > l_mo4s) and (l_data > (l_mo4s + l_odds)):
        return 'No'
    return 'Yes'


def main():
    N = int(input())
    data = [int(x) for x in input().split()]
    result = solve(data)
    print(result)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict
from itertools import product, groupby
from math import pi
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = 10 ** 10


def main():
    N = int(input())
    a_list = list(map(int, input().split()))
    f, o = 0, 0
    for a in a_list:
        f += a % 4 == 0
        o += a % 2 != 0

    if f >= (N // 2) or f >= o:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict
from itertools import product, groupby
from math import pi
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = 10 ** 10


def main():
    N = int(input())
    a_list = list(map(int, input().split()))
    f, t, o = 0, 0, 0
    for a in a_list:
        if a % 4 == 0:
            f += 1
        elif a % 2 == 0:
            t += 1
        else:
            o += 1

    if f >= (N // 2) or f >= o:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

Submission status: Accepted

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

a4 = 0
aodd = 0

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

x = 0

if a4 >= n // 2:
    x += 1
elif aodd <= a4:
    x += 1

print('Yes' if x == 1 else 'No')

Submission status: Accepted

Solution code:
def judge_type(x):
    if x % 4 == 0:
        return 4
    elif x % 2 == 0:
        return 2
    else:
        return 1


def solve(): # 069C - 4-adjacent
    N = int(input())
    a = list(map(int, input().split(" ")))
    cnt_odd = 0
    cnt_2 = 0
    cnt_4 = 0
    flag_2 = False

    for i in a:
        if judge_type(i) == 1:
            cnt_odd += 1
        elif judge_type(i) == 2:
            cnt_2 += 1
            flag_2 = True
        elif judge_type(i) == 4:
            cnt_4 += 1

    if flag_2:
        if cnt_odd <= cnt_4:
            print("Yes")
        else:
            print("No")
    else:
        if cnt_odd <= cnt_4 + 1:
            print("Yes")
        else:
            print("No")


solve()

Submission status: Accepted

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

num4 = 0
num2 = 0
num1 = 0
for aa in a:
    if aa % 4 == 0:
        num4 += 1
    elif aa % 2 == 0:
        num2 += 1
    else:
        num1 += 1

if num2 == 0:
    if num1 <= num4 + 1:
        print('Yes')
    else:
        print('No')
else:
    if num1 <= num4:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

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

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

m4 = 0
m2 = 0
k = n/2
flg = 1
for i in a:
    if(i%4 == 0):
        m4 += 1
    elif(i%2 == 0):
        m2 += 1
if(m4 >= k):
    print('Yes')
    flg = 0
else:
    if(n%2 == 0):
        if(m2 >= (k-m4)*2):
            print('Yes')
            flg = 0
    else:
        if(m2 >= (k-m4)*2+1):
            print('Yes')
            flg = 0
if(flg):
    print('No')

Submission status: Accepted

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

b0, b1, b2 = 0,0,0

for i in a:
    if i % 2 != 0:
        b0 += 1
    else:
        if i % 4 != 0:
            b1 += 1
        else:
            b2 += 1

if b1 != 0:
    b0 +=1
    
if b2 + 1 >= b0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

b0, b1, b2 = 0,0,0 #b0: 2でも4でも割り切れない b1: 2で割り切れるが4で割り切れない b2: 4で割り切れる

for i in a:
    if i % 2 != 0:
        b0 += 1
    else:
        if i % 4 != 0:
            b1 += 1
        else:
            b2 += 1
            
if b1 == 0:
    if b2 + 1 >= b0:
        print('Yes')
    else:
        print('No')
else:
    b0 += 1
    if b2 + 1 >= b0:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
N = input()
a = map(int, raw_input().split())
a1, a2, a4 = [], [], []
for i in range(N):
    if a[i] % 4 == 0:
        a4.append(a[i])
    elif a[i] % 2 == 0:
        a2.append(a[i])
    else:
        a1.append(a[i])
if N % 2 == 0:
    if len(a1) <= len(a4):
        print "Yes"
    else:
        print "No"
else:
    if len(a1) <= len(a4):
        print "Yes"
    elif len(a1) == len(a4) + 1:
        print "Yes" if (len(a2) % 2 == 0) else "No"
    else:
        print "No"

Submission status: Accepted

Solution code:
def main():
    _ = input()
    
    b0, b1, b2 = 0, 0, 0
    for c in input().split():
        n = int(c)
        if n % 4 == 0: b2 += 1
        elif n % 2 == 0: b1 += 1
        else: b0 += 1

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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main(N, aa):
    """
    a_i * a_(i+1) = 4k
        i=2n and i+1=2m
        i=4n or  i+1=4m

    half: 4m -> ok
    all: 2n -> ok

    example5
        2 7 1 8 2 8
          -     -
        2 2 1 8 7 8
    all2を作成
    残りhalfのパターン

    example2
        1 2 3 4
        2 1 3 4
          1 3 4

        all2, 最後の１つは２＊２にならないので以下でフォロー
        2, 4m, x, 4m
        2, 4m, x, 4m, x
    """
    n_m2 = 0
    n_m4 = 0
    n_m2_notm4 = 0
    for a in aa:
        is_m2 = a % 2 == 0
        is_m4 = a % 4 == 0

        n_m2 += int(is_m2)
        n_m4 += int(is_m4)
        n_m2_notm4 += int(is_m2 and not is_m4)

    if n_m2_notm4 == 0 and n_m4 >= N // 2:
        return "Yes"
    else:
        rest = N - n_m2_notm4 + 1
        if n_m4 >= rest // 2:
            return "Yes"
        else:
            return "No"


if __name__ == '__main__':
    N = int(input())
    aa = map(int, input().split())

    print(main(N, aa))

Submission status: Accepted

Solution code:
def main(N, aa):
    """
    a_i * a_(i+1) = 4k
        i=2n and i+1=2m
        i=4n or  i+1=4m

    half: 4m -> ok
    all: 2n -> ok

    example5
        2 7 1 8 2 8
          -     -
        2 2 1 8 7 8
    all2を作成
    残りhalfのパターン

    example2
        1 2 3 4
        2 1 3 4
          1 3 4

        all2, 最後の１つは２＊２にならないので以下でフォロー
        2, 4m, x, 4m
        2, 4m, x, 4m, x
    """
    n_m2 = 0
    n_m4 = 0
    n_m2_notm4 = 0
    for a in aa:
        is_m2 = a % 2 == 0
        is_m4 = a % 4 == 0

        n_m2 += int(is_m2)
        n_m4 += int(is_m4)
        n_m2_notm4 += int(is_m2 and not is_m4)

    if n_m2 == N:
        return "Yes"
    elif n_m2_notm4 == 0 and n_m4 >= N // 2:
        return "Yes"
    else:
        rest = N - n_m2_notm4 + 1
        if n_m4 >= rest // 2:
            return "Yes"
        else:
            return "No"


if __name__ == '__main__':
    N = int(input())
    aa =map(int, input().split())

    print(main(N, aa))

Submission status: Accepted

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

cnt4=0
cnt2=0
kisuu=0
for i in range(len(a)):
	#print a[i]
	if a[i]%4==0:
		cnt4+=1
	elif a[i]%4!=0 and a[i]%2==0:
		cnt2+=1
	elif a[i]%2==1:
		kisuu+=1


#print cnt4
#print cnt2
#print kisuu

if cnt4>0 and cnt2==0 and kisuu==0:
	print 'Yes'
elif cnt4==kisuu:
	print 'Yes'
elif cnt4+1==kisuu and cnt2==0:
	print 'Yes'
else:
	print 'No'

Submission status: Accepted

Solution code:
N = int(input())
al = [int(an) for an in input().split()]
a = [ "4" if al[i]%4==0 else "k" if al[i]%2!=0 else "g" for i in range(N)]
if a.count("k") == a.count("4") or len(a) == a.count("g") + a.count("4"):
	print("Yes")
elif (a.count("k") - 1) == a.count("4")  and a.count("g")==0:
	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 i in range(N):
    if a[i] % 4 == 0:
        num4 += 1
    elif a[i] % 2 == 0:
        num2 += 1
    else:
        num1 += 1

if (num1 <= num4 + 1) & (num2 == 0):
    print("Yes")
elif (num1 <= num4) & (num2 != 0):
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

if p2==0 and p1<= p4+1:
    print('Yes')

elif p2==0 and p1> p4+1:
    print('No')

elif p1 <= p4:
    print('Yes')

else:
    print('No')

Submission status: Accepted

Solution code:
n,*A=map(int,open(0).read().split());p=sum(a%2<1for a in A);q=sum(a%4<1for a in A);print("Yes"*(q==p>n-p-2or n-p<=q)or"No")

Submission status: Accepted

Solution code:
n,*A=map(int,open(0).read().split())
C=[0]*3
for a in A:
    for i in range(2,-1,-1):
        if a%2**i == 0:
            C[i] += 1
            break
print("Yes"*(C[0]<=C[2]or (C[0]==C[2]+1 and C[1]==0))or"No")

Submission status: Accepted

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

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

if len(a)==f+o:
    f+=1

print("Yes" if f>=o else "No")

Submission status: Accepted

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

num4 = 0
num2 = 0
for ai in a:
    if ai % 4 == 0:
        num4 += 1
    elif ai % 2 == 0:
        num2 += 1
        
if num4*2 + num2 >= N or num4*2 + 1 >= N:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
Nodd = len([x for x in a if x%2 == 1])
Neven = len([x for x in a if x%2 == 0])
Nfour = len([x for x in a if x%4 == 0])
if Nodd <= Nfour or (Nodd+Nfour==N and Nodd-Nfour==1):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    div4 = len(list(filter(lambda x: x % 4 == 0, a)))
    div2 = len(list(filter(lambda x: (x % 2 == 0 and x % 4 != 0), a)))
    div1 = n - div4 - div2
    if(div4 + 1 < div1 + bool(div2)):
        print("No")
    else:
        print("Yes")

Submission status: Accepted

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

one_count = 0
four_count = 0
two_count = 0
result = 'No'

for i in a_list:
    if i % 2 == 1:
        one_count += 1
    elif i % 4 == 0:
        four_count += 1
    else:
        two_count += 1

if one_count <= four_count or (one_count - 1  == four_count and two_count == 0):
    result = 'Yes'

print(result)

Submission status: Accepted

Solution code:
n= int(input())

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

k = len(list(filter(lambda x: x%4 == 0, a)))
j = len(list(filter(lambda x: x%2 == 0, a)))-k
i = len(a)-j-k

if (j > 0) and (i <= k):
    print("Yes")
elif (j == 0) and (i-1 <= k):
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

f,e,d = 0,0,0

for a in A:
    x = a % 4
    if(x==0):
        f = f+1
    elif(x==2):
        e = e+1
    else:
        d = d+1
if(e>0):
    d = d+1
if(f >= d-1):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
#coding=UTF-8

N=int(input())

mozir=input()
hyo=mozir.split(' ')
a=[int(mono) for mono in hyo]

mobius=0
huckel=0
ungerade=0
for mono in a:
    if mono % 2 == 0:
        if mono % 4 == 0:
            mobius+=1
        else:
            huckel+=1
    else:
        ungerade+=1

#place 1,3,5,7, ...
#if ceil((N-1)/2) <= mobius then OK
if mobius >= N // 2:
    ans=True
else:
    #use huckel N-1,N-2,...
    #til colides to mobius
    hashi=mobius*2-1

    rightend=N-huckel
    if rightend-hashi<=1:
        ans=True
    else:
        ans=False

if ans:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
num = input()
list = map(int, raw_input().split())
count1 = 0
count4 = 0
for x in list:
    if x % 2 == 1:
        count1 = count1 + 1
    if x % 4 == 0:
        count4 = count4 + 1
if count1 > count4 and num > 3 and count1 + count4 < num:
    print("No")
elif count1 > count4 + 1 and num > 3 and count1 + count4 == num:
    print("No")
elif num == 2 and count4 - count1 < 0:
    print("No")
elif num == 3 and count4 == 0 and count1 > 0:
    print("No") 
else:
    print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
p=0
f=0
for ai in a:
    if ai%2==1:
        p+=1
    else:
        if ai/2%2==0:
            f+=1
if p==0:
    print('Yes')
elif p>f:
    if n%2==1 and 2*f+1==n:
        print('Yes')
    else:
        print('No')
else:
    print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=input()
l=map(int,raw_input().split())
f=0
t=0
o=0
for i in l:
    if i%4==1 or i%4==3:
        o+=1
    elif i%4==2:
        t+=1
    else:
        f+=1
if t==0:
    if f>=n/2:
        ans="Yes"
    else:
        ans="No"
else:
    if o<=f:
        ans="Yes"
    else:
        ans="No"
print ans

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-
N = int(input())
factor = 0
a = list(map(int, input().split()))
b = [ tmp for tmp in a if tmp%4 == 0 ]
c = [ tmp for tmp in a if tmp%2 == 0 ]
d = [ tmp for tmp in a if tmp%2 != 0 ]
if len(c)-len(b) != 0 and len(b)-len(d) >= 0:
    print("Yes")
elif len(c)-len(b) == 0 and len(b)+1 >= len(d):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
def read(): return list(map(int, input().split()))


n = input()
a = read()

odd, four, not4 = 0, 0, 0
for i in a:
    if i % 4 == 0:
        four += 1
        continue

    if i & 1:
        odd += 1
    else:
        not4 += 1

odd += (not4 & 1)

print("Yes" if odd <= four + 1 else "No")

Submission status: Accepted

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

for j in range(N):

  if a[j]%2 == 1:
    one += 1
  elif a[j]%4 == 0:
    four += 1
  else :
    two +=1

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

else:

  print('No')

Submission status: Accepted

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

for j in range(N):

  if a[j]%2 == 1:
    one += 1
  elif a[j]%4 == 0:
    four += 1
  else :
    two +=1

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

Submission status: Accepted

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

one = 0
two = 0
four = 0

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

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

Submission status: Accepted

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

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

def solve():
    if x4 >= x1: return True
    if x4 + 1 == x1:
        return x2 == 0
    else: return False

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

Submission status: Accepted

Solution code:
import sys

def main():
    sys.stdin.readline()
    xs = sys.stdin.readline().strip().split(" ")
    n = 0
    m = 0
    l = 0

    for i in xs:
        if (int(i) % 2 == 1):
            m = m + 1
        elif (int(i) % 4 == 0):
            n = n + 1
        elif (int(i) % 4 == 2):
            l = l + 1

    if (l > 0 and n >= m):
        print("Yes")
    elif (l == 0 and n >= m - 1):
        print("Yes")
    else:
        print("No")

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
m2, m4 = 0, 0
for i in range(N):
    if A[i] % 4 == 0:
        m4 += 1
    elif A[i] % 2 == 0:
        m2 += 1
m0 = N - m2 - m4
length = N - m2
msg = "No"
if (m4 >= m0) or (length % 2 == 1 and m2 == 0 and m4 >= m0 - 1):
    msg = "Yes"
print(msg)

Submission status: Accepted

Solution code:
n = int(raw_input())
l = map(int, raw_input().split())
feven = False
nodd = 0
nfour = 0
for i in l:
    if i % 4 == 0:
        nfour += 1
    elif i % 2 == 0:
        feven = True
    else:
        nodd += 1
if (feven and nfour >= nodd) or (not feven and nfour >= nodd - 1):
    print 'Yes'
else:
    print 'No'

Submission status: Accepted

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

N = int(raw_input())
a = map(int, raw_input().split())

def is_odd(n):
    return True if (n%2!=0) else False

def is_s_even(n):
    return True if (n%4!=0 and n%2==0) else False

def is_w_even(n):
    return True if (n%4==0) else False

# 奇数配列p[] 4の倍数配列r[] どちらもない配列q[]
p, q, r = [], [], []
for i in range(N):
    if is_odd(a[i]):
        p.append(a[i])
    elif is_w_even(a[i]):
        r.append(a[i])
    else:
        q.append(a[i])

# 条件を満たすように並べる配列s[]
s = []
if len(p) > 0:
    s.append(p.pop())
elif len(q) > 0:
    s.append(q.pop())
else:
    s.append(r.pop())

for i in range(1,N):
    if is_odd(s[i-1]):
        if len(r) > 0:
            s.append(r.pop())
        else:
            print 'No'
            exit()
    elif is_s_even(s[i-1]):
        if len(q) > 0:
            s.append(q.pop())
        elif len(r) > 0:
            s.append(r.pop())
        else:
            print 'No'
            exit()
    else:
        if len(p) > 0:
            s.append(p.pop())
        elif len(q) > 0:
            s.append(q.pop())
        elif len(r) > 0:
            s.append(r.pop())
            
print 'Yes'

Submission status: Accepted

Solution code:
def Q3(lst):
    import numpy as np
    N = len(lst)
    lst = np.array(lst)
    num4 = len(lst[np.where(lst % 4 == 0)])  # 4の倍数の個数
    num2 = len(lst[np.where((lst % 4 != 0) & (lst % 2 == 0))])  # 4の倍数でない2の倍数
    numOther = len(lst[np.where((lst % 4 != 0) & (lst % 2 != 0))])

    if num2 == 0:
        if numOther <= num4 + 1:
            return 'Yes'
        else:
            return 'No'
    else:
        if numOther <= num4:
            return 'Yes'
        else:
            return 'No'

n = int(input())
l = [int(i) for i in input().split()] 
print(Q3(l))

Submission status: Accepted

Solution code:
n = int(input())

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

point = 0

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

if n % 2 == 1:
    if n <= point + 1:
        print("Yes")
    else:
        print("No")
else:
    if n <= point:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
import sys
from collections import Counter

# sys.stdin = open('c1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def solve():
    n = read_int()
    a = read_int_list()
    c = Counter()

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

    if c[0] > c[2] + 1:
        return False
    if c[0] == c[2] + 1:
        return c[1] == 0
        # if c[1] == 0:
        #     return True
        # else:
        #     return False
    if c[0] <= c[2]:
        return True


def main():
    res = solve()
    if res:
        print('Yes')
    else:
        print('No')


main()

Submission status: Accepted

Solution code:
n=input()
I=[int(x) for x in input().split()]
d1,d2,d4=0,0,0
for i in I:
    if i%4==0:
        d4+=1
    elif i%2 == 0:
        d2+=1
    else:
        d1+=1
if d2>0:
    d1+=1
if d4+1>=d1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N = int(raw_input())
a = map(int,raw_input().split(" "))
b = [0,0,0]

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

if (b[1] == 0 and b[2] + 1 >= b[0]) or (b[1] != 0 and b[2] >= b[0]):
	print "Yes"
else:
	print "No"

Submission status: Accepted

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

divisible_by_2 = 0
divisible_by_4 = 0
others = 0

for i in arr:
    if i % 4 == 0:
        divisible_by_4 += 1
    elif i % 2 == 0:
        divisible_by_2 += 1
    else:
        others += 1

if others > divisible_by_4:
    if divisible_by_2 == 0 and others == divisible_by_4 + 1:
        print("Yes")
    else:
        print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
import sys


def main():
    args = sys.stdin.readline().split()
    N = int(args[0])
    A = map(int, input().split())

    non_factor_cnt = 0
    factor_of_two_cnt = 0
    factor_of_four_cnt = 0
    for num in A:
        remainder = num % 4
        if remainder != 0:
            if remainder == 2:
                factor_of_two_cnt += 1
            else:
                non_factor_cnt += 1
        else:
            factor_of_four_cnt += 1

    if factor_of_two_cnt == 0:
        if factor_of_four_cnt >= non_factor_cnt - 1:
            print('Yes')
            sys.exit()
    if factor_of_four_cnt >= non_factor_cnt: # + factor_of_two_cnt % 2:
        print('Yes')
        sys.exit()
    print('No')

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
number = int(input())
list = map(int,input().split())
yon_num = 0
ni_num = 0
odd_num = 0
for num in list:
    if num%4 == 0:
        yon_num += 1
    elif num%2 == 0:
        ni_num +=1
    else:
        odd_num += 1

    if ni_num != 0:
        ni_num = ni_num//2 + ni_num%2

if yon_num >= (odd_num + ni_num  + yon_num) // 2 :
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
# coding: utf-8

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

if set([num% 2 for num in nums]) == {0}:
    print("Yes")
    exit(0)

a,b,c = 0,0,0
for elem in nums:
    if elem % 4 == 0 : a += 1  # 4の倍数
    else:
        b += 1  # 4の倍数じゃない

# あとづけ 
# 2の倍数かつnot４の倍数についても考える必要がある
c = 0
for elem in nums:
        if elem % 2 == 0 and elem % 4 != 0: c += 1

if N % 2 == 1:  # 奇数
    if b-c <= (N-c+1)/2 : print("Yes")
    else: print("No")
else:  # 偶数
    if b-c <= a : print("Yes")
    else: print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = input()
N = int(N)
a = input()
nums = a.split()
counter = 0
semi = 0
for i in range(N):
    n = int(nums[i])
    if n % 4 == 0:
        counter += 1
    elif n % 2 == 0:
        semi += 1
    else: continue
if counter >= N // 2 :
    print("Yes")
elif counter == 0 & semi == N:
    print("Yes")
elif semi >= (N - counter*2):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n1 = 0
n2 = 0
n4 = 0
nb = int(input())
for v in map(int,input().split()):
   if v%4 == 0:
      n4 += 1
   elif v%2 == 0:
      n2 += 1
   else:
      n1 += 1
if (n1 <= n4) or (n1 == n4 + 1 and n2 == 0):
   print('Yes')
else:
   print('No')

Submission status: Accepted

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

    multi_2 = 0
    multi_4 = 0
    
    for num in a:
        if(num % 2 == 0):
            if(num % 4 == 0):
                multi_4 += 1
            else:
                multi_2 += 1
    
    #print(multi_2)
    #print(multi_4)
    pair_2 = int(multi_2 / 2)
    #print(pair_2)
    permitrange = 3 + (multi_4 - 1) * 2 + pair_2 * 2
    #print(permitrange)
    if(N <= permitrange):
        print("Yes")
    else:
        print("No")
    
if __name__=="__main__":
    main()

Submission status: Accepted

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

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

count=count4+count2//2
must=n//2

if count>=must: print("Yes")
else: print("No")

Submission status: Accepted

Solution code:
# your code goes here
N=int(input())
a=[int(i) for i in input (). split ()]
M=0
M1=0
for i in range (N):
    if a[i]%2==0:
        M+=1
        a[i]//=2
        if a[i]%2==0:
            M1+=1
N-=M
if N==0:
    p="Yes"
elif M1>=N:
    p="Yes"
elif M==M1 and M1+1>=N:
    p="Yes"
else:
    p="No"
print (p)

Submission status: Accepted

Solution code:
size = int(input())
lists = input().split()
i = 0
nada = 0
twos = 0
fours = 0
while i < size:
	if int(lists[i]) % 4 == 0:
		fours += 1
	elif int(lists[i]) % 2 == 0:
		twos += 1
	else:
		nada += 1
	i += 1
if fours == 0 and nada + twos % 2 > 0:
	print("No")
elif nada + twos % 2 - 1<= fours:
	print("Yes")
else:
	print("No")