Problem:


Score : 400 points

Problem Statement

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

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

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

Determine whether Snuke can achieve his objective.

Constraints

2 ≤ N ≤ 10^5

a_i is an integer.

1 ≤ a_i ≤ 10^9

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

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

Sample Input 1

3
1 10 100

Sample Output 1

Yes

One solution is (1, 100, 10).

Sample Input 2

4
1 2 3 4

Sample Output 2

No

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

Sample Input 3

3
1 4 1

Sample Output 3

Yes

The condition is already satisfied initially.

Sample Input 4

2
1 1

Sample Output 4

No

Sample Input 5

6
2 7 1 8 2 8

Sample Output 5

Yes



Sample input:
3
1 10 100


Sample output:
Yes

Submission status: Accepted

Solution code:
import collections as col


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


if __name__ == "__main__":
    n = int(input())
    a = map(int, input().split())

    count = col.Counter(map(convert, a))

    if count[1] >= 1:
        if count[4] >= count[1]:
            print('Yes')
        elif count[1] == count[4] + 1 and count[2] == 0:
            print('Yes')
        else:
            print('No')

    else:  # count[1] == 0
        if count[4] >= 1:
            print('Yes')
        elif count[2] >= 2:
            print('Yes')
        else:
            print('No')

Submission status: Accepted

Solution code:
n = input()
nStr = input().split()
number = list(map(int,nStr))
 
frby = 1
twby = -1
 
for i in number:
    if i % 4 == 0:
        frby += 2
    elif i % 2 == 0:
        twby += 1
        
if int(n) == 1 and frby == 3:
    print("Yes")
elif int(n) == (twby + 1):
    print("Yes")
elif int(n) <= (frby):
    print("Yes")
elif int(n) <= (frby + twby):
    print("Yes")
else :
    print("No")

Submission status: Accepted

Solution code:
# import numpy as np
import math
N = int(input())
a = list(map(int, input().split()))

two_count = 0
four_count = 0
for i in a:
    if i >= 4 and i % 4 == 0:
        four_count += 1
    elif i >= 2 and i % 2 == 0:
        two_count += 1

if two_count <= 1:
    if len(a) == 2:
        print("Yes" if four_count >= 1 else "No")
    else:
        print("Yes" if four_count >= len(a)//2 else "No")
else:
    check = len(a) - two_count
    if check == 0:
        print("Yes")
    elif check <= 2:
        print("Yes" if four_count >= 1 else "No")
    else:
        print("Yes" if four_count >= math.ceil(check/2) else "No")

Submission status: Accepted

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

odd = []
even = []
four = []

for i in range(0, N):
	if int(list[i]) % 2 != 0:
		odd.append(list[i])
	elif int(list[i]) % 2 == 0 and int(list[i]) % 4 != 0:
		even.append(list[i])
	elif int(list[i]) % 4 == 0:
		four.append(list[i])

odd_num = len(odd)
even_num = len(even)
four_num = len(four)

if four_num >= odd_num - 1 and even_num == 0:
	print('Yes')
elif four_num >= odd_num:
	print('Yes')
else:
	print('No')

Submission status: Accepted

Solution code:
n = int(input())
n1 = 0
n2 = 0
n4 = 0
for a in map(int,input().split()):
  if a%4 == 0:
    n4 += 1
  elif a%2 == 0:
    n2 += 1
  else:
    n1 += 1
if n1 <= n4:
  print('Yes')
elif n1 == n4+1 and n2 == 0:
  print('Yes')
else:
  print('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')
elif 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:
#!/usr/bin/python

import sys

def main(argv):
    line = sys.stdin.readline()
    while line:
        N = int(line)
        a = map(lambda x: int(x), sys.stdin.readline().split(" "))

        counters = [0, 0 ,0]
        for i in a:
            if i % 4 == 0:
                counters[2] += 1
            elif i % 2 == 0:
                counters[1] += 1
            else:
                counters[0] += 1

        if counters[0] > (counters[2] + 1):
            print("No")
        elif counters[0] == (counters[2] + 1):
            if counters[1] > 0:
                print("No")
            else:
                print("Yes")
        else:
            print("Yes")
            
        line = sys.stdin.readline()

if __name__ == "__main__":
    main(sys.argv)

Submission status: Accepted

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

n = raw_input()
n = int(n)

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

count_2 = 0
count_4 = 0

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

if count_4 >= n/2:
    print "Yes"
elif count_4*2 + count_2 >= n:
    print "Yes"
else:
    print "No"

Submission status: Accepted

Solution code:
tmp = int(input())
arr = [int(x) for x in input().split()]
nep = 0
krat = 0
for elem in arr:
    if elem % 4 == 0:
        krat += 1
        continue
    if elem % 2 == 1:
        nep += 1
if krat - nep >= -1:
    if krat - nep == -1:
        if nep + krat == tmp:
            print("Yes")
        else:
            print("No")
    else:
        print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    N = int(input())
    a = list(map(int, input().split()))
    n1 = 0
    n2 = 0
    n4 = 0
    for i in a:
        if i % 4 == 0:
            n4 += 1
        elif i % 2 == 0:
            n2 += 1
        else:
            n1 += 1
    if n2 == 0 and n4 == 0 and n1 == 1:
        print("Yes")
    else:
        if n1 <= n4:
            print("Yes")
        elif n1 == n4 + 1:
            if n2 == 0:
                print("Yes")
            else:
                print("No")
        else:
            print("No")

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
na = nb = nc = 0
for num in a:
	if num % 4 == 0:
		nc+=1
	elif num % 2 == 0:
		nb+=1
	else:
		na+=1
if nb > 0:
	if nc >= na:
		print("Yes")
	else:
		print("No")
if nb == 0:
	if nc >= na-1:
		print("Yes")
	else:
		print("No")

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
a=[int(i) for i in input().split()]
b=[]
for i in range(n):
 if a[i]%4==0:
    b.append(2)
 elif a[i]%2==0:
    b.append(1)
 else:
    b.append(0)
c=Counter(b)
if c[2]-c[0]>=0:
  print("Yes")
elif c[2]-c[0]==-1:
  if c[1]==0:
    print("Yes")
  else:
    print("No") 
else:
  print("No")

Submission status: Accepted

Solution code:
import numpy as np

N = int(raw_input())
l = np.array(map(int, raw_input().split()))

mod_4 = len(np.where((l % 4 == 0))[0])
mod_2 = len(np.where(l % 4 == 2)[0])

if N <= 2 and mod_4 == 0 and mod_2 <= 1:
    print 'No'
elif N <= mod_4 * 2 + 1:
    print 'Yes'
elif N <= mod_4 * 2 + mod_2 and mod_2 >= 2:
    print 'Yes'
elif N <= mod_4 * 2 + mod_2:
    print 'Yes'
else:
    print 'No'

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = tuple(map(int, input().split()))

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

    if four >= N // 2 or \
        etc == 0 or \
        two >= 2 and four >= etc:
        print('Yes')
    else:
        print('No')

main()

Submission status: Accepted

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

N = int(input())
a = list(map(f, input().split()))
num4 = a.count(4)
num2 = a.count(2)
#num1 = N - num4 - num2
#print(num4, num2, num1)

if num2 > 1:
    N += - num2 + 1

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

Submission status: Accepted

Solution code:
import sys
N = int(input())
an = map(int, input().split())
f = []
d = []
o = []
for a in an:
    if a % 4 == 0:
        f.append(a)
    elif a % 2 == 0:
        d.append(a)
    else:
        o.append(a)
if len(f) >= len(o):
    print('Yes')
    sys.exit()
if len(f) + 1 == len(o):
    if len(d) == 0:
        print('Yes')
        sys.exit()
print('No')

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np

N = np.int64(input())
a = np.array([int(x) for x in input().split()])

mod_a = np.mod(a, 4)
count4 = (mod_a==0).sum()
count2 = (mod_a==2).sum()
odd = ((mod_a==1) | (mod_a==3)).sum()
if N % 2 == 0:
    if count4 >= odd:
        print('Yes')
    else:
        print('No')
else:
    if count4 >= odd - 1:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

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

counter = {
        0: 0,
        1: 0,
        2: 0,
        3: 0,
        }

for i in range(len(li)):
    li[i] = li[i] % 4
    counter[li[i]] += 1

if counter[2] == 0:
    zeroes = counter[0]
    nonzeroes = N - zeroes
    if zeroes >= nonzeroes or zeroes + 1 == nonzeroes:
        print("Yes")
        exit(0)
    else:
        print("No")
        exit(0)
else:
    zeroes = counter[0]
    nonzeroes = N - zeroes - counter[2]
    if zeroes >= nonzeroes:
        print("Yes")
        exit(0)
    else:
        print("No")
        exit(0)

Submission status: Accepted

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

f = 0
t = 0

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

h = t // 2
s = ((N - h * 2) // 2)
s2 = N

if s <= f or s2 <= t:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
odd=[]
two=[]
four=[]
for i in range(N):
    if a[i]%2!=0:
        odd.append(a[i])
    elif a[i]%4==0:
       four.append(a[i])
    else:
       two.append(a[i])
O=len(odd)
T=len(two)
F=len(four)

if O>F+1:
    print('No')
elif O==F+1:
    if T==0:
        print('Yes')
    else:
        print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
n=input()
data=list(map(int,input().split()))
a=[i for i in data if i%4==0]
b=[i for i in data if i%4!=0]
c=[i for i in b if i%2==0]
x=len(a)+len(c)//2
y=len(b)-len(c)//2
if y<=x+1:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
#! -*- coding:utf-8 -*-
n = int(input())
a = map(int,input().split())
a = list(a)

sum_2 = 0
sum_4 = 0
for i in range(len(a)):
    if a[i] % 4 == 0:
        sum_4 += 1
    elif a[i] % 2 == 0:
        sum_2 += 1

if len(a)//2 == sum_4 or (len(a)+1)//2 == sum_4:
    print('Yes')
elif sum_4*2 + sum_2 >= len(a):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N = int(input())
a_arr = input().split(' ')

for i in range(len(a_arr)):
    a_arr[i] = int(a_arr[i])

counter = {
        "two": 0,
        "for": 0,
        "one": 0
}

for j in range(len(a_arr)):
    if a_arr[j] % 4 == 0:
        counter['for'] += 1
    elif a_arr[j] % 2 == 0:
        counter['two'] += 1
    else:
        counter['one'] += 1

indicator = N - counter['two']/2

if counter['two'] % 2 != 0:
    counter['one'] += 1
    
if counter['one'] - counter['for'] <= 1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split(' ')))
four = [i for i in A if i % 4 == 0]
notFour = [i for i in A if i % 4 != 0]
two = [i for i in notFour if i % 2 == 0]
a = len(four)
b = len(two)
if N <= 2*a + 1 or N == b or b >= N - 2*a:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
def c():
    n = int(input())
    a = [int(ai) for ai in input().split()]
    div = {4:0, 2:0, 1:0}
    for i in a:
        if i % 4 == 0:
            div[4] += 1
        elif i % 2 == 0:
            div[2] += 1
        else:
            div[1] += 1
    if div[2] == 0:
        need = -1
    else:
        need = 0
    if div[4] - div[1] >= need:
        print('Yes')
    else:
        print('No')
    # print(div)

c()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
mul4 = 0
mul2 = 0
has_mul2 = 0
other = 0
for i in a:
    if i%4 == 0:
        mul4 += 1
    elif i%2 == 0:
        mul2 += 1
        has_mul2 = 1
    else:
        other += 1

if mul4 >= (has_mul2+other-1) or other == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

n1 = 0
n2 = 0
n4 = 0
for i in range(0, n):
    if a[i] % 4 == 0:
        n4 += 1
    elif a[i] % 2 == 0:
        n2 += 1
    else:
        n1 += 1

if (n2 == 0 and n4 + 1 >= n1) or (n4 >= n1):
    print("Yes")
else:
    print("No")

Submission status: Accepted

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


N = int(input())
A = list(map(int, input().split()))
cnt = 0
cnt2 = 0
for i in A:
    if i % 4 == 0:
        cnt += 1
    elif i % 2 == 0:
        cnt2 += 1
        
a = cnt >= len(A) // 2
b = cnt + cnt2 // 2 >= len(A) // 2
if a or b:
    print('Yes')
else :
    print('No')

Submission status: Accepted

Solution code:
# encoding:utf-8
 
def main():
	N = int(input())
	nums = list(map(int, input().split()))
	l_div4 = len([x for x in nums if x % 4 == 0])
	l_div2 = len([x for x in nums if x % 2 == 0])
	l_div0 = len(nums) - l_div2

	main_checker(l_div4, l_div2, l_div0)

def main_checker(l_div4, l_div2, l_div0):
	#print(l_div4, (l_div2 - l_div4), l_div0)
	if l_div0 == 0:
		print("Yes")
	elif l_div4 >= l_div0 + ((l_div2 - l_div4) > 0) - 1:
		print("Yes")
	else:
		print("No")

if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:


def main():
    n = int(input())

    n_odd = 0
    n_even = 0
    n_four = 0

    for x in (int(a) for a in input().split()):
        if x % 4 == 0:
            n_four += 1
        elif x % 2 == 1:
            n_odd += 1
        else:
            n_even += 1

    if n_even == 0:
        extra = 1
    else:
        extra = 0

    if n_odd <= n_four + extra:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n=int(raw_input())
a=map(int,raw_input().split())
m4=0
m2=0
for x in a :
    if x%4==0 :
        m4 += 1
    elif x%2==0 :
        m2 += 1

if m2<=1:
    if m4+1>=n-m4:
        print 'Yes'
    else:
        print 'No'
else :
    n -= m2
    if m4>=n-m4:
        print 'Yes'
    else:
        print 'No'

Submission status: Accepted

Solution code:
'''input
6
2 7 1 8 2 8
'''
n = input()
a = map(int ,raw_input().split())
freq4 = 0
freq2 = 0
for i in a:
	if i%4 == 0:
		freq4 += 1
		continue
	if i%2 ==0 :
		freq2 += 1
if freq4 >= n//2 or freq4 + freq2//2 >= n//2:
	print "Yes"

else:
	print "No"

Submission status: Accepted

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

count_4 = 0
count_2 = 0
for i in A:
    count_4 += int(i % 4 == 0)
    count_2 += int(i % 2 == 0)
no_mul = N - count_2
count_2 -= count_4
if(no_mul <= count_4 or (count_2 == 0 and no_mul <= count_4 +1)):
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

flag = -1
odd = 0
m4 = 0
for i in a:
    if i % 4 == 0:
        m4 += 1
    elif i % 2 == 0:
        flag = 0
    else:
        odd += 1

print('Yes' if m4 >= odd + flag else 'No')

Submission status: Accepted

Solution code:
n = input()
n = int(n)

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

two = 0
four = 0
odd = 0

for a in an:
    if a % 2 != 0:
        odd += 1
    elif a % 4 == 0:
        four += 1
    else:
        two += 1

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

Submission status: Accepted

Solution code:
# 4-adjacent
N = int(input())
a = list(map(int, input().split()))

b = [a[i]%4 for i in range(N)]

if ( b.count(2)%2 + b.count(1) + b.count(3) > 1 + b.count(0) ):
    print("No")
else:
    print("Yes")

Submission status: Accepted

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

fours = 0
twos = 0
others = 0

for a in a_list:
    if a % 4 ==0:
        fours += 1
    elif a % 2 == 0:
        twos += 1
    else:
        others += 1

if others <= fours:
    print("Yes")
elif others-1 == fours and twos==0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

count2 = 0
count4 = 0

for ai in a:
    if ai % 4 == 0:
        count4 += 1
    elif ai % 2 == 0:
        count2 += 1

if count4*2 + count2 >= N or (count4*2+1) >= N:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n=input()
a=[0 for i in range(n)]
s=raw_input().split()
c2=0
c1=0
c=0
for i in range(n):
    t=int(s[i])
    if t%4==0:
        a[i]=2
        c2+=1
    else:
        if t%2==0:
            a[i]=1
            c1+=1
        else:
            a[i]=0
            c+=1
print "Yes" if (c2>=c) or (c2==c-1 and c1==0) else "No"

Submission status: Runtime Error

Solution code:
N=input()
A=input()
a=0
b=0
c=0
for i in range(0,N,1)
  if A[i]%4==0:
    a=a+1
  else: 
    if A[i]%2==1:
      b=b+1
    else:
      c=c+1
else:
  print("Yes" if a>=b else "No")

Submission status: Runtime Error

Solution code:
N = int(input())
a = list(map(int,input().rstrip().split(" ")))
counter = [0,0,0]
for i in a:
    if i % 4 == 0:
        counter[2] += 1
    elif i % 2 == 0:
        counter[1] += 1
    else:
        counter[0] += 1
counter[0] += min(1,counter[1])

if counter[2] += 1 >= counter[0]:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
N = int(input())
a = list(map(int,input().rstrip().split(" ")))
counter = [0,0,0]
for i in a:
    if i % 4 == 0:
        counter[2] += 1
    elif i % 2 == 0:
        counter[1] += 1
    else:
        counter[0] += 1
counter[0] += min(1,counter[1] += 1)

if counter[2] += 1 >= counter[0]:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

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

if counter[1] == 1:
    counter[1] = 0
    counter[0] += 1
    if(counter[2] != 0):
        p += 1
p = (max(counter[1] - 1,0)) + counter[2] * 2

if p >= counter[0]:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
N = int(input())
A = list(map(int,input().split()))
l = list()
ll = list()
for i in range(len(A)):
  if A[i]%4 == 0:
    l.append(A[i])
  if A[i]%2 == 0:
    ll.append(A[i])
four = len(l)
two = len(ll)-four
zero = N-two
a = math.floor(N/2)
if a <= four and b == 0:
  print("Yes")
elif a-two <= four:
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
A = readInts()
four = 0
two = 0
for i in range(n):
    if A[i]%4 == 0:
        four += 1
    elif A[i]%2 == 0:
        two += 1
print('Yes' if a + b//2 >= n//2 else 'No')

Submission status: Runtime Error

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

ki = 0
gu_2 = 0
gu_4 = 0

for i in a:
    if i % 4 == 0:
        gu_4 += 1
    elif i % 2 == 0:
        gu_2 += 1
    else:
        ki += 1

if ki <= gu_4:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    A = sorted(il())

    cnt = 0
    for n in range(N):
        if A[n] % 4 == 0:
            cnt += 1
        elif A[n] % 2 == 0 and A[n + 1] % 2 == 0:
            cnt += 0.5
    print('YES' if N // 2 <= int(cnt + 0.5) else 'NO')


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

even4, even, odd = 0, 0, 0
for i in a:
    if i % 4 == 0:
        even4 += 1
    elif i % 2 == 0:
        even += 1
    else:
        odd += 1

if n % 2 == 0:
    if even4 >= odd:
        print("Yes")
    else:
        print("No")
else:
    if even4 >= odd + 1:
        print("Yes")
    else:
        print("No")

Submission status: Runtime Error

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

even4, ,even, odd = 0, 0, 0
for i in a:
    if i % 4 == 0:
        even4 += 1
    elif i % 2 == 0:
        even += 1
    else:
        odd += 1

if n % 2 == 0:
    if even4 >= odd:
        print("Yes")
    else:
        print("No")
else:
    if even4 >= odd + 1:
        print("Yes")
    else:
        print("No")

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N=int(input())

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

div1=0
div2=0
div4=0
lenS=len(S)

for i in range(N):
    if S[i]%4==0:
        div4+=1
    elif S[i]%2==0:
        div2+=1
    else:
        div1+=1

if lenS%2==0:

    if div4*2+div2>=lenS:
        print("Yes")
        exit()
    else:
        print("No")
        exit()
else:
    
    if (div4*2+1)>=lenS:
        print("Yes")
        exit()
    elif div4*2+div2>=lens:
        print("Yes")
        exit()
    else:
        print("No")

Submission status: Runtime Error

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

ok = (two >= max(0, (N-4)) and four >= 2) or four >= N//2
ok = ok and ((four-no) >= 2 or ((four+no) == N and (no-four) <= 1))
if ok:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def main():
    n, *a = map(int, open(0).read().split())

    o = sum([i % 2 == 1 for i in a])
    p = sum([i % 4 == 0 for i in a])
    q = sum([i % q == 0 for i in a]) - p
    
    if p + 1 >= o and not q:
        print("Yes")
    elif p >= 0 and q:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

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

if count2==1:
  count1=len(a)-count4
else:
  count1=len(a)-count4-count2
if len(a)==1 and a[0]==2:
elif count1-count4<=1:
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

Solution code:
cnt_4=0
for i in range(n):
  if a[i]%2!=0:
    cnt_odd+=1
  else:
    cnt_even+=1
    if a[i]%4==0:
      cnt_4+=1
if cnt_even-cnt_4==0:
  if cnt_4+1>=cnt_odd:
    print("Yes")
  else:
    print("No")
else:
  if cnt_4>=cnt_odd:
    print("Yes")
  else:
    print("No")

Submission status: Runtime Error

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

d4 = 0
d2 = 0
d0 = 0
for n in nums:
    if n % 4 == 0:
        d4 += 1
    elif n % 2== 0:
        d2 += 1
    else:
        d0 += 1

if d2 > 0 and d1 <= d2:
    print('Yes')
elif d2 == 0 and d1 <= d4+1:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
N=int(input())
a=list(map(int,input().split()))
b4=[x for x in a if x%4==0]
a4=[x for x in a if x%4!=0]
b2=[x for x in a4 if x%2==0]
c=[x for x in a4 if x%2!=0]
if len(b4)==0 and (len(c)==0 and len(b2)>1):
    print('Yes')
elif len(b4)==0 and len(c)!=0
    print('No')
elif len(b4)+1<len(c):
    print('No')
elif len(b4)<len(c) and len(b2)>0:
    print('No')
else:
    print('Yes')

Submission status: Runtime Error

Solution code:
def slove(n, k):
    a_list = [int(i) for i in k.split()]
    num = len([i for i in a_list if i % 4 == 0])
    tmp =  [i for i in a_list if i % 4 != 0]
    num2 = tmp.count(2) // 2
    return "Yes" if (num + num2)>= n // 2 else "No"

if __name__ == "__main__":
    input = sys.stdin.readline
    n = int(input())
    k = input()
    print(slove(n, k))

Submission status: Runtime Error

Solution code:
n, *a = map(int, open(0).read().split())
s = [i%4 for a]
f, k = s.count(0), s.count(2)
print("YNeos"[n-f-k > f+(k>0)::2])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
l = list(map(int,input().split()))
c = len([i for i in l if i%4==0])
l1 = [i for i in l if not (i%2==0 and i%4!=0)]
if len(l1)>=1:
  a = n-len(l1)+1
  a = a-c
  if a<=c-1:
    print("Yes")
  else:
    print("No")
else:
  if a<=c-1:
    print("Yes")
  else:
    print("No")

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

print("Yes" if cnt4*2 + cnt2 >= N else "No")

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
list_AB = [ list(map(int,input().split(" "))) for i in range(m)]
list_MAP = [0]*(n+1)

for l in list_AB:
    l.sort()
    if l[0] == 1:
        list_MAP[l[1]] += 1
    if l[1] == n:
        list_MAP[l[0]] += 1

ans = "IMPOSSIBLE"

for num in list_MAP:
    if num > 1:
        ans = "POSSIBLE"

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
a = list(map(int, input().split()))
from collections import deque
kisuu = deque([])
bai4 = deque([])
sonota = deque([])
for ai in a:
    if ai % 4 == 0:
        bai4.append(ai)
    elif ai % 2 == 0:
        sonota.append(ai)
    else:
        kisuu.append(ai)

ans = deque([])
if kisuu:
    s = kisuu.pop()
    ans.append(s)
elif sonota:
    s = sonota.pop()
    ans.append(s)
else:
    s = bai4.pop()
    ans.append(s)        

for i in range(1, N + 1):
    if i == N:
        print('Yes')
        quit()
    if ans[i - 1] % 2 == 1:
        if bai4:
            s = bai4.pop()
            ans.append(s)
        else:
            break
    elif ans[i - 1] % 2 == 0 and ans[i - 1] % 4 != 0:
        if sonota:
            s = sonota.pop()
            ans.append(s)
        elif bai4:
            s = sonota.pop()
            ans.append(s)
        else:
            break
    elif ans[i - 1] % 4 == 0:
        if kisuu:
            s = kisuu.pop()
            ans.append(s)
        elif sonota:
            s = sonota.pop()
            ans.append(s)
        elif bai4:
            s = sonota.pop()
            ans.append(s)
        else:
            break
print('No')

Submission status: Runtime Error

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

from collections import deque
kisuu = deque([])
bai4 = deque([])
sonota = deque([])
for ai in a:
    if ai % 4 == 0:
        bai4.append(ai)
    elif ai % 2 == 0:
        sonota.append(ai)
    else:
        kisuu.append(ai)

ans = deque([])
if kisuu:
    s = kisuu.pop()
    ans.append(s)
elif sonota:
    s = sonota.pop()
    ans.append(s)
else:
    s = bai4.pop()
    ans.append(s)        

for i in range(1, N + 1):
    if i == N:
        print('Yes')
        quit()
    if ans[i - 1] % 2 == 1:
        if bai4:
            s = bai4.pop()
            ans.append(s)
        else:
            break
    elif ans[i - 1] % 2 == 0 and ans[i - 1] % 4 != 0:
        if sonota:
            s = sonota.pop()
            ans.append(s)
        elif bai4:
            s = sonota.pop()
            ans.append(s)
        else:
            break
    else:
        if kisuu:
            s = kisuu.pop()
            ans.append(s)
        elif sonota:
            s = sonota.pop()
            ans.append(s)
        elif bai4:
            s = sonota.pop()
            ans.append(s)
        else:
            break
print('No')