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:
# coding: utf-8

import math
import fractions
import heapq
import collections
import re
import array
import bisect

from collections import Counter, defaultdict


def array2d(dim1, dim2, init=None):
    return [[init for _ in range(dim2)] for _ in range(dim1)]


N = int(input())
d4 = 0
d2 = 0
for n in map(int, input().split(" ")):
    if n % 4 == 0:
        d4 += 1
    elif n % 2 == 0:
        d2 += 1
d1 = N - d4 - d2

if d2:
    print(["No", "Yes"][d4 >= d1])
else:
    print(["No", "Yes"][d4 >= d1 - 1])

Submission status: Accepted

Solution code:
# cook your dish here
n=int(input())
a = list(map(int,input().split()))

j = 0
k = 0
for i in range(n):
    if a[i] %2 == 0:
        if a[i] % 4== 0:
            k += 1
        else:
            j += 1
l = n-j-k

if l <= k:
    print('Yes')
else:
    if j == 0 and l == k + 1:
        print('Yes')
    else:
        
        print('No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def getdata():

    array_result = []
    
    array_result.append(input().split(" "))

    flg = True

    try:

        while flg:

            data = input()

            if(data != ""):
                
                array_result.append(data.split(" "))

            else:

                flg = Fa;se
    finally:

        return array_result

arr_data = getdata()

n = int(arr_data[0][0])

arr = [int(arr_data[1][x]) for x in range(n)]
arr01 = [v for v in arr if v % 4 == 0]
arr02 = [v for v in arr if v % 4 != 0 and v % 2 == 0]

print("Yes" if len(arr) // 2 <= len(arr01) + len(arr02) //2 else "No")

Submission status: Accepted

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

n4 = 0
n1 = 0
for i in arr:
	if i%4 == 0 :
		n4 += 1
	elif i%2 == 1:
		n1 += 1

if len(arr) - n4 - n1 > 0 :
	if n4 >= n1 :
		print "Yes"
	else :
		print "No"

else :
	if n4 >= n1 - 1:
		print "Yes"
	else :
		print "No"

Submission status: Accepted

Solution code:
N = int(input())

nums = [int(i) for i in input().split()]
baisuu = [0,0,0]
for n in nums:
  if n%4 == 0:
    baisuu[0] += 1
  elif n%2 == 0:
    baisuu[1] += 1
  else:
    baisuu[2] += 1
   
if baisuu[1] % 2 == 1:
  baisuu[2] += 1
if baisuu[0] >= baisuu[2]-1:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
cnt1, cnt2, cnt4 = 0, 0, 0
for i in range(n):
  t = 0
  while a[i]%2==0:
    a[i] //= 2
    t += 1
  if t==0:
    cnt1 += 1
  elif t==1:
    cnt2 += 1
  else:
    cnt4 += 1
if cnt2>=1:
  cnt1 += 1
if cnt1<=cnt4+1:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
'''input
3
1 10 100
'''
n = input()
arr = map(int,raw_input().split())
ev,od,mf = 0,0,0
for i in range(n):
	if arr[i]%4 == 0:
		mf += 1
		continue
	elif arr[i]&1:
		od += 1
	else:
		ev += 1
if mf >= od:
	print "Yes"
elif mf >= od-1 and ev == 0:
	print "Yes"
else:
	print "No"

Submission status: Accepted

Solution code:
def read():
    return int(input())


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


def readmap():
    return map(int, input().split())


def factor(n):
    if n % 4 == 0:
        return 2
    elif n % 2 == 0:
        return 1
    else:
        return 0


N = read()
A = readlist()

fac = [factor(A[i]) for i in range(N)]

num2 = fac.count(2)
num1 = fac.count(1)
num0 = fac.count(0)

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

Submission status: Accepted

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

for i in a:
	if i % 4 == 0:
		four.append(i)
	elif i % 2 == 0:
		two.append(i)

if (2 * len(four) + len(two) >= n) or 2 * len(four) + 1 >= n:
	print("Yes")
else:
	print("No")

Submission status: Accepted

Solution code:
input();*a,=map(int,input().split());b=c=0
for x in a:
    if x%4==0:b+=1
    elif -~x%2:c+=1
print(['No','Yes'][len(a)-b-c-2+(c>0)<b])

Submission status: Accepted

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

import sys, math, copy
# import fractions, itertools
# import numpy as np
# import scipy

HUGE = 2147483647
HUGEL = 9223372036854775807
ABC = "abcdefghijklmnopqrstuvwxyz"

def main():
    n = int(input())
    ai = list(map(int, input().split()))
    assert len(ai) == n
    ones = 0
    twos = 0
    fours = 0
    for a in ai:
        if a % 4 == 0:
            fours += 1
        elif a % 2 == 0:
            twos += 1
        else:
            ones += 1
    if twos > 0:
        twos = 1
    if fours == 0 and (ones > 0):
        return False
    if fours + 1 < ones + twos:
        return False
    return True

print("Yes" if main() else "No")

Submission status: Accepted

Solution code:
n = int(input())
cou1 = 0
cou2 = 0
cou4 = 0
lis = list(map(int,input().split()))
for i in range(n):
    if lis[i] % 2 == 0:
        if lis[i] % 4 == 0:
            cou4 += 1
        else:
            cou2 += 1
    else:
        cou1 += 1
if cou2 == 0:
    if cou1 <= cou4 + 1:
        print("Yes")
    else:
        print("No")
else:
    if cou1 <= cou4:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

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

if n%2 == 0:
    th = int(n/2)
else:
    th = int((n-1)/2)

count = 0
num_2 = 0
for a in a_list:
    if a%4 == 0:
        count += 1
    elif a%2 == 0:
        num_2 += 1

if n%2 == 0:
    if count >= th-int(num_2/2):
        print("Yes")
    else:
        print("No")
else:
    if count >= th-int(max((num_2-1), 0)/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=0
for i in a:
    if i%4==0:
        count_4+=1
    elif i%2==0:
        count_2+=1
    else:
        count+=1
if count_2==0:
    if count<=count_4+1:
        print("Yes")
    else:
        print("No")
else:
    if count<=count_4:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
odds = 0
evens2 = 0
evens4 = 0
for ai in a :
    if ai % 4 == 0 :
        evens4 += 1
    elif ai % 2 == 0 :
        evens2 += 1
    else :
        odds += 1

if evens4 >= odds :
    print('Yes')
elif odds - evens4 == 1 and evens2 == 0 :
    print('Yes')
else :
    print('No')

Submission status: Accepted

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

cnt4=0
cnt2=0
odd=0
for i in A:
    if i%4==0:
        cnt4+=1
    elif i%2==0:
        cnt2+=1
    else:
        odd+=1   

if cnt2==0:
    if odd<=cnt4+1:print("Yes")
    else:print("No")
else:
    if odd<=cnt4:print("Yes")
    else:print("No")

Submission status: Accepted

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

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

ok = False
if b2 == 0:
	if  b1 <= b4 + 1:
		ok = True
else:
	if b1 <= b4:
		ok = True

print("Yes" if ok == True else "No")

Submission status: Accepted

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

multiple4 = 0
multiple2 = 0
odds = 0

for ai in a:
    if ai % 4 == 0:
        multiple4 += 1
    elif ai % 2 == 0:
        multiple2 += 1
    else:
        odds += 1

if multiple4 == 0:
    if odds == 0:
        print('Yes')
    else:
        print('No')
elif multiple4 >= odds or multiple4 + 1 == odds and multiple2 == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter
import math
N = int(input())

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

li2 = []
li4 = []
liother = []

for a in As:
    if a%4 == 0:
        li4.append(a)
    elif a%2 == 0:
        li2.append(a)
    else:
        liother.append(a)

if len(li4) >= len(liother):
    print('Yes')
elif len(li4) == len(liother)-1 and len(li2) == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
_ = raw_input()
four = two = one = 0
for i in raw_input().split(' '):
    if int(i)%4 == 0:
        four+=1
    elif int(i)%2 ==0:
        two+=1
    else:
        one+=1
if one>four+1 or (one==four+1 and two!=0):
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
import  math

num = int(input())
val = [int(x) for x in input().split()]

two = 0
four = 0
for i in val:
    if i % 4 != 0 and i % 2 == 0:
        two += 1
    elif i % 2 == 0:
        four += 1

print("Yes" if math.floor((len(val) - abs(two-1 if two > 0 else 0))/2) <= four else "No")

Submission status: Accepted

Solution code:
N = int(input())
four = 0
two = 0
one = 0
for e in map(int, input().split()):
    if e % 4 == 0:
        four += 1
    elif e % 2 != 0:
        one += 1
    else:
        two += 1
if four >= one:
    print("Yes")
else:
    if two == 0 and four == one - 1:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
N=int(input())
a=[int(i) for i in input().split()]
num4=0
num2=0
num1=0
for i in a:
        if i%4==0:
                num4+=1
        elif i%2==0:
                num2+=1
num1=N-num4-num2

if num2>0:
        num1+=1

if num1<=num4+1:
        print("Yes")
else:
        print("No")

Submission status: Accepted

Solution code:
# C - 4-adjacent

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

b = [ a[i]%4 for i in range(n) ]
import collections
c = collections.Counter(b)
#print(c)
if ( c[2]%2 + c[1] + c[3] > 1 + c[0] ):
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
import sys
n = int(sys.stdin.readline().strip())
ar = [int(x) for x in sys.stdin.readline().split()]
f4, odd, even = 0, 0, 0
for num in ar:
	if num%4==0:
		f4 +=1
	elif num%2==0:
		even+=1
	else:
		odd+=1
if odd-f4 == 0:
	print "Yes"
elif odd-f4 <= 1 and even == 0:
	print "Yes"
else:
	print "No"

Submission status: Accepted

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

div2 = 0
div4 = 0
for a in aa:
    if a % 4 == 0:
        div4 += 1
    elif a % 2 == 0:
        div2 += 1

if 0 < div2:
    div2 -= 1

if n - 1 <= div4*2 + div2:
    print 'Yes'
else:
    print 'No'

Submission status: Accepted

Solution code:
import sys

N = int(input())
ls = list(map(int, input().split()))
k = len(ls)
p = [ i for i in ls if (i%4) == 0]
j = [ i for i in ls if (i%4) != 0]
r = [ i for i in j if (i%2) == 0]

if(len(p) >= int(k/2)):
    print('Yes')
elif (len(p) >= (len(j) - len(r))):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N = int(input())
L = list(map(int, input().split()))
odd = 0
div2 = 0
div4 = 0
for l in L:
    if l % 2 != 0:
        odd += 1
    elif l % 4 == 0:
        div4 += 1
    else:
        div2 += 1

if N == 2:
    if odd == 2 or (odd == 1 and div2 == 1):
        print("No")
    else:
        print("Yes")
    exit()

if N == 3:
    if div4 >= 1:
        print("Yes")
    else:
        if odd == 0:
            print("Yes")
        else:
            print("No")
    exit()

if odd <= div4:
    print("Yes")
else:
    if div2 == 0 and odd - div4 == 1:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import random
n = int(input())
a = list(map(int, input().split()))
k1, k2, k4 = 0, 0, 0
for a_i in a:
    if a_i % 4 == 0:
        k4 += 1
    elif a_i % 2 == 0:
        k2 += 1
    else:
        k1 += 1
t = min(k1, k4)
k1 -= t
k4 -= t
result = k1 == 0 or (k1 == 1 and not k2)
print([ 'No', 'Yes' ][result])

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
need = int(N // 2)
x = 0
y = 0
num = list(map(int,input().split()))
x = len(list(filter(lambda x: x%4 == 0,num)))
y = len(list(filter(lambda x: (x%4 != 0) and (x%2==0),num)))
if (x + (y // 2)) >= need:
	print("Yes")
else:
	print("No")

Submission status: Accepted

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

N = int(input())
A = list(map(int, input().split()))
t4 = 0
t2 = 0
for i in A:
    if i % 4 == 0:
        t4 += 1
    elif i % 2 == 0:
        t2 += 1
print(['No', 'Yes'][N//2<=(t4 + t2//2)])

Submission status: Accepted

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

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

a2 //= 2

if (a4 + a2) >= n // 2:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

L = []
res = "No"

for a in A:
    if a % 4 == 0:
        L.append(4)
        continue
    elif a % 2 == 0:
        L.append(2)
        continue
    else:
        L.append(1)

if L.count(2) == 0:
    if L.count(1) <= (L.count(4) + 1):
        res = "Yes"
elif L.count(1) <= L.count(4):
    res = "Yes"

print(res)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(num) for num in 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

if (count4 >= n // 2) | ((count4 * 2 + count2) >= n):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N = int(input())
num = list(map(int, input().split()))
count = 0

for i in num:
    if i%4==0:
        N -= 2
    elif i%2==0:
        count += 1
if count>1:
    N = N - count + 1

if N > 1:
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
import random

N = int(input())
num = list(map(int, input().split()))
count = 0

for i in num:
    if i%4==0:
        N -= 2
    elif i%2==0:
        count += 1
if count>1:
    N = N - count + 1

if N > 1:
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
#ARc080C

n=int(raw_input())
l=map(int,raw_input().split())
cnt1=cnt2=cnt4=0
for i in xrange(n):
 if l[i]%4==0:
  cnt4+=1
 elif l[i]%2==0:
  cnt2+=1
 else:
  cnt1+=1
if cnt4>=cnt1:
 print 'Yes'
elif cnt4==cnt1-1 and cnt2==0:
 print 'Yes'
else:
 print 'No'

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
num_O=sum(map(lambda x:1 if not x%2 else 0,a))
num_T=sum(map(lambda x:1 if not x%4 else 0,a))
if(n//2-num_T-(num_O-num_T)//2<=0):
	print("Yes")
else:
	print("No")

Submission status: Accepted

Solution code:
n = int(raw_input())
a = [int(s) for s in raw_input().split(" ")]
four_multi = 0
no_four_multi_even = 0
odd = 0
for i in a:
    if i % 4 == 0:
        four_multi += 1
    elif i % 2 == 0:
        no_four_multi_even += 1
    else:
        odd += 1
if odd <= four_multi:
    print "Yes"
elif odd - 1 == four_multi and no_four_multi_even == 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:
input()
xs=list(map(int, input().split()))
 
f,t,z=0,0,0
for x in xs:
  if x % 4 == 0:
    f+=1
  elif x % 2 == 0:
    t += 1
  else:
    z += 1
z += 0<t
print('Yes' if z - 2 < f else'No')

Submission status: Accepted

Solution code:
import sys

n = int(input())

four = 0
odd = 0
two = 0

l = [int(x) for x in sys.stdin.readline().split()]

for x in l:
	if x % 4 == 0:
		four += 1
	elif x % 2 == 1:
		odd += 1
	else:
		two += 1

if four > 0:
	if four >= odd:
		print('Yes')
	elif odd - four == 1:
		if two == 0:
			print('Yes')
		else:
			print('No')
	else:
		print('No')
else:
	if odd > 0:
		print('No')
	else:
		if two >= 2:
			print('Yes')
		else:
			print('No')

Submission status: Accepted

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

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

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    n = I()
    a = LI()
    d = collections.defaultdict(int)
    for c in a:
        d[c%4] += 1

    d[1] += d[3]
    if d[2] == 1:
        d[1] += 1
    if (d[1] == 0) or (d[1] - (1 if d[2] < 2 else 0) <= d[0] and d[0] > 0):
        return 'Yes'

    return 'No'



print(main())

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
a,b,c = 0,0,0
for x in A:
    if x % 4 == 0:
        c += 1
    elif x % 2 == 0:
        b += 1
    else:
        a += 1

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

Submission status: Accepted

Solution code:
import sys
from sys import stdin,stdout
import bisect
N=input()
A=list(map(int,stdin.readline().strip().split(' ')))
count4=0
count1=0
for i in xrange(len(A)):
    if A[i]%4==0:
        count4+=1
    elif A[i]%2==1:
        count1+=1
if count4>=count1:
    if count4>0:
        print('Yes')
    else:
        if len(A)>1:
            print('Yes')
        else:
            print('No')
else:
    if count4<count1-1:
        print('No')
    elif count4==count1-1:
        if len(A)==count4+count1:
            print('Yes')
        else:
            print('No')
    else:
        print('No')

Submission status: Accepted

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

count1=0
count2=0
count4=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 count4+1>=count1: print("Yes")
    else: print("No")
else:
    if count4>=count1: print("Yes")
    else: print("No")

Submission status: Accepted

Solution code:
import numpy as np

def check4adjacent(N, a):
    a = np.array(map(int, a))
    count_4multiples = len(np.where(a % 4 == 0)[0])
    count_2multiples = len(np.where((a % 2 == 0) & (a % 4 != 0))[0])
    count_else = N - (count_4multiples + count_2multiples)
    if count_2multiples % 2 == 0:
        flag = 1
    else:
        flag = 0

    if (count_4multiples + flag >= count_else ):
        return "Yes"
    else:
        return "No"



if __name__ == "__main__":
    N = int(raw_input())
    a = raw_input().split()
    print(check4adjacent(N, a))

Submission status: Accepted

Solution code:
def four_adjacent():
	n = int(raw_input())
	a = map(int, raw_input().split(" "))
	odd_num = 0
	mod_four_mum = 0
	for item in a:
		if item%2!=0:
			odd_num+=1
		if item%4==0:
			mod_four_mum+=1
	if mod_four_mum>=odd_num:
		print "Yes"
	elif odd_num-mod_four_mum==1:
		if n==odd_num+mod_four_mum:
			print "Yes"
		else:
			print "No"
	else:
		print "No"


if __name__ == "__main__":
	four_adjacent()

Submission status: Accepted

Solution code:
#!/usr/bin/python
# coding: utf-8

import sys

# q: 4の倍数, a: 奇数1個または偶数任意個
# a q a q a q ... q a
def solve(N, a):
  n4 = len([v for v in a if v % 4 == 0])                # 4の倍数
  n2 = len([v for v in a if v % 4 != 0 and v % 2 == 0]) # 4の倍数でない偶数
  n1 = len([v for v in a if v % 2 != 0])                # 奇数
  na = n4 + 1
  if n2 > 0: na -= 1
  return "Yes" if n1 <= na else "No"

def splitIntoNums(line):
  words = line.strip().split()
  return [int(w) for w in words]

while True:
  l1 = sys.stdin.readline()
  l2 = sys.stdin.readline()
  if not l1: break
  N, = splitIntoNums(l1)
  a  = splitIntoNums(l2)
  if len(a) != N: raise
  print(solve(N, a))

Submission status: Accepted

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

for i in range(N):
    x[i]=(x[i]%4)

a=x.count(1)+x.count(3)
o=x.count(0)

if(o>=a):
    print('Yes')
    quit()

if(o==a-1):
    if(x.count(2)==0):
       print('Yes')
       quit()
     
print('No')


quit()

Submission status: Accepted

Solution code:
import sys
N=int(input())
l=map(int,input().split())
a,b,c=0,0,True
for i in l:
    if i%4==0:b+=1
    else:
        if i%2!=0:a+=1
        else:c=False

if a==0:
    print("Yes")
    sys.exit()
if c:
    if b==0:
        print("No")
        sys.exit()
    if b>=a-1:print("Yes")
    else:print("No")
else:
    if b>=a:print("Yes")
    else:print("No")

Submission status: Accepted

Solution code:
import copy

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



N=int(input())
a=spaceinput()

count4=0
count2=0
countodd=0
for sa in a:
    if sa%4==0:
        count4+=1
    elif sa%2==0:
        count2+=1
    else:
        countodd+=1



x=["o","e4"]*count4
if count2>0:
    x.extend(["e2"]*count2)
else:
    x.extend(["o"])
#print(count4,count2)
#print(x)
#print(len(x),N)
if len(x)>=N:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
# one -> four
# two -> two, four
# four -> one, two, four

n = int(input())
one = 0
two = 0
four = 0

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

def no():
    print("No")
    exit()

if two == 0:
    #1414141
    print("Yes" if four >= one-1 else "No")
else:
    #222222241414141
    print("Yes" if four >= one else "No")

Submission status: Accepted

Solution code:
import sys
from collections import deque
import copy

from math import *
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    input_raw = list(read_func().strip().split())
    count_even = 0
    count_odd = 0
    count_4adj = 0
    for i in range(N):
        a = int(input_raw[i])
        if (a % 4) == 0:
            count_4adj += 1
        elif (a % 2) == 0:
            count_even += 1
        else:
            count_odd += 1

    is_yes = False
    if count_even == 0:
        if count_4adj >= count_odd - 1:
            is_yes = True
    else:
        if count_4adj >= count_odd:
            is_yes = True

    if is_yes:
        print "Yes"
    else:
        print "No"



if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

if count1 <= count4 or (count1 - count4 == 1 and count2 == 0):
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

c = [0, 0, 0]
for a in A:
    if a % 4 == 0:
        c[2] += 1
    elif a % 2 == 0:
        c[1] += 1
    else:
        c[0] += 1
if c[2] >= c[0]:
    print "Yes"
elif c[2] == c[0] - 1  and c[1] == 0:
    print "Yes"
else:
    print "No"

Submission status: Accepted

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

mod_4 = 0
mod_2 = 0
for a_i in a:
    if a_i % 4 == 0:
        mod_4 += 1
    elif a_i % 2 == 0:
        mod_2 += 1

if mod_2 == 0:
    m = 2 * mod_4 + 1
else:
    m = 2 * mod_4 + mod_2

if m >= N:
    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_int():
    return int(input())


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


def read_str():
    return input()


def solve():

    c = Counter()
    n = read_int()
    a = read_int_list()
    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 'No'
    elif c[0] == c[2] + 1:
        if c[1] > 0:
            return 'No'
        else:
            return 'Yes'
    else:
        return 'Yes'


def main():
    res = solve()
    print(res)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    N = int(input())
    a = list(map(int, input().split()))
    odd_num = len([i for i in a if i % 2 == 1])
    four_divide_num = len([i for i in a if i % 4 == 0])

    if odd_num <= four_divide_num:
        print("Yes")
    else:
        if odd_num - 1 == four_divide_num and odd_num + four_divide_num == N:
            print("Yes")
        else:
            print("No")

Submission status: Accepted

Solution code:
# coding: utf-8
INF = 10 ** 20
MOD = 10 ** 9 + 7


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


def read():
    N = II()
    a = ILI()
    return N, a


def solve(N, a):
    n_odd = 0
    n_div_2 = 0
    n_div_4 = 0
    for _a in a:
        if _a % 2 == 1:
            n_odd += 1
        else:
            if _a % 4 == 0:
                n_div_4 += 1
            else:
                n_div_2 += 1

    ans = ""
    if n_div_2 == 0:
        if n_div_4 >= n_odd - 1:
            ans = "Yes"
        else:
            ans = "No"
    else:
        if n_div_4 >= n_odd:
            ans = "Yes"
        else:
            ans = "No"

    return ans


def main():
    params = read()
    print(solve(*params))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
A = [int(n) for n in input().split()]

x2 = sum([a%2!=0 for a in A])
o2x4 = sum([(a%2==0)&(a%4!=0) for a in A])
o4 = sum([a%4==0 for a in A])


if o2x4 == 0:
    if o4 + 1 >= x2:
        print("Yes")
    else:
        print("No")
else:
    if o4 >= x2:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

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

def f(x):
    if x % 4 == 0:
        return 4
    elif x % 2 == 0:
        return 2
    return 1

c = [0] * 5

for i in xrange(n):
    c[f(a[i])] += 1

print 'Yes' if c[4] >= c[1] or (c[2] == 0 and c[4] + 1 == c[1]) else 'No'

Submission status: Accepted

Solution code:
n = int(raw_input())
a = map(int, raw_input().split())
cnt2 = 0
cnt4 = 0
for i in xrange(n):
    if a[i] % 4 == 0:
        cnt4 += 1
    elif a[i] % 2 == 0:
        cnt2 += 1
m = n - cnt4 - cnt2
if cnt2 == 0:
    if m - 1 <= cnt4:
        print "Yes"
    else:
        print "No"
else:
    if m <= cnt4:
        print "Yes"
    else:
        print "No"

Submission status: Accepted

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

# print(c)
if c[0] - 1 <= c[2] and c[1] == 0:
	print("Yes")
elif c[0] > c[2]:
	print("No")
else:
	print("Yes")

# 0 2 0 1
# 1 1 2 0 2 0 2 0 2 1 1
# 1 1 1 1

Submission status: Accepted

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

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

if c4 == 0:
    if 0 < c1 + c2 % 2:
        print("No")
    else:
        print("Yes")
else:
    if c1 + c2 % 2 <= c4 + 1:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
N=int(raw_input())
a=map(int,raw_input().split())
odd=even=four=0
for i in a:
    if i%2==1:
        odd+=1
    elif i%4==0:
        four+=1
    else:
        even+=1
flag=True
if even==0:
    if odd>four+1:
        flag=False
else:
    if odd>four:
        flag=False
print "Yes" if flag else "No"

Submission status: Accepted

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

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

c = [0,0,0]

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

last = None

isPossible = True

while (sum(c)):
    mn = 0
    if len(b) and b[-1]==1:
        mn = 1
    if len(b) and b[-1]==0:
        mn = 2

    n = -1
    for i in range(mn, 3):
        if c[i]:
            n = i
            break
    if n==-1:
        isPossible = False
        break

    c[n]-=1
    b.append(n)

if isPossible:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
input()
a = b = c = 0
for i in raw_input().split():
	i = int(i)
	if i % 4 == 0:
		a += 1
	elif i % 2 == 0:
		b += 1
	else:
		c += 1

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import re
import string

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

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

prev = 4

def use_other():
    global other, prev
    other -= 1
    prev = 0

def use_two():
    global two, prev
    two -= 1
    prev = 2

def use_four():
    global four, prev
    four -= 1
    prev = 4

def func():
    if prev == 4:
        if other > 0:
            use_other()
        elif two > 0:
            use_two()
        elif four > 0:
            use_four()
    elif prev == 2:
        if two > 0:
            use_two()
        elif four > 0:
            use_four()
        else:
            return False
    elif prev == 0:
        if four > 0:
            use_four()
        else:
            return False
    return True

ok = True
for n in range(N):
    ret = func()
    if not ret:
        ok = False
        break
if ok:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

cnt4 = len([x for x in A if x % 4 == 0])
cnt2 = len([x for x in A if x % 2 == 0]) - cnt4
if 2 * cnt4 + cnt2 >= N or (N % 2 == 1 and cnt4 >= N // 2):
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

odd = 0
n2 = 0
n4 = 0

for a in A:
  r = a % 4
  if r == 0:
    n4 += 1
  elif r == 2:
    n2 = 1
  else:
    odd += 1

if n4 + 1 >= odd + n2:
  print('Yes')
else:
  print('No')