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: Time Limit Exceeded

Solution code:

import collections
n,ais = int(raw_input()), map(int, raw_input().split())
cc = collections.Counter()
for ai in ais:
	if ai % 4 == 0: cc[0] += 1
	elif ai % 2 == 0: cc[1] += 1
	else: cc[2] += 1

q = collections.deque([0])
h = {0:[2,1,0], 1:[1], 2:[0]} 
while(n):
	booll = False
	for u in h[q[-1]] + [-1]:
		if u == -1:
			boool = True
			break
		if cc[u]:
			q.append(u)
			cc[u] -=1
			n -=1
			break
	if booll:
		break

print 'Yes' if n == 0 else 'No'

Submission status: Time Limit Exceeded

Solution code:

import collections
n,ais = int(raw_input()), map(int, raw_input().split())
cc = collections.Counter()
for ai in ais:
	if ai % 4 == 0: cc[0] += 1
	elif ai % 2 == 0: cc[1] += 1
	else: cc[2] += 1

q = collections.deque()
h = {0:[2,1,0], 1:[1,0], 2:[0]} 
while(n):
	if len(q) == 0:
		for u in range(3)[::-1]:
			if cc[u] > 0:
				q.append(u)
				cc[u]-=1
				n -=1
				break
		if len(q) == 0: break
	else:
		booll = False
		for u in h[q[-1]] + [-1]:
			if u == -1:
				boool = True
				break
			if cc[u]:
				q.append(u)
				cc[u]-=1
				n-=1
				break
		if booll:
			break

print 'Yes' if n == 0 else 'No'

Submission status: Time Limit Exceeded

Solution code:

import collections
n,ais = int(raw_input()), map(int, raw_input().split())
cc = collections.Counter()
for ai in ais:
	if ai % 4 == 0: cc[0] += 1
	elif ai % 2 == 0: cc[1] += 1
	else: cc[2] += 1

q = collections.deque()
h = {0:[2,1,0], 1:[1,0], 2:[0]} 
while(n):
	if len(q) == 0:
		for u in range(3)[::-1]:
			if cc[u] > 0:
				q.append(u)
				cc[u]-=1
				n -=1
				break
		if len(q) == 0: break
	else:
		for u in h[q[-1]] + [-1]:
			if u == -1:
				break
			if cc[u]:
				q.append(u)
				cc[u]-=1
				n-=1
				break

print 'Yes' if n == 0 else 'No'

Submission status: Time Limit Exceeded

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

a = [i%100 if i >100 else i for i in a]
pair = n*(n - 1)/2
not_4 = 0
ans = 'Yes'
num = len(a)
for i in range(num):
  for j in range(num):
    
    if i != j and a[i]*a[j]%4 != 0:
      not_4 += 1
      
      
    if not_4 >= pair:
      ans = 'No'
      break
    
print(ans)

Submission status: Time Limit Exceeded

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

pair = n*(n - 1)/2
not_4 = 0
ans = 'Yes'
num = len(a)
for i in range(num):
  for j in range(num):
    
    if i != j and a[i]*a[j]%4 != 0:
      not_4 += 1
      
      
    if not_4 >= pair:
      ans = 'No'
      break
    
print(ans)

Submission status: Time Limit Exceeded

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

pair = n*(n - 1)/2
not_4 = 0
ans = 'Yes'
num = len(a)
for i in range(num):
  if a[i] == 4:
    continue
  else:
    for j in range(num):
    
      if i != j and a[i]*a[j]%4 != 0:
        not_4 += 1
      
        if not_4 >= pair:
          ans = 'No'
          break
    
print(ans)

Submission status: Time Limit Exceeded

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

pair = n*(n - 1)/2
not_4 = 0
ans = 'Yes'
num = len(a)
for i in range(num):
  for j in range(num):
    
    if i != j and a[i]*a[j]%4 != 0:
      not_4 += 1
      
      if not_4 >= pair:
        ans = 'No'
        break
    
print(ans)

Submission status: Time Limit Exceeded

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

pair = n*(n - 1)/2
not_4 = 0
ans = 'Yes'
num = len(a)
for i in range(num):
  for j in range(num):
    
    if i == j or a[i]*a[j]%4 == 0:
      continue
    else:  
      not_4 += 1
      
      if not_4 >= pair:
        ans = 'No'
        break
    
print(ans)

Submission status: Time Limit Exceeded

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

pair = n*(n - 1)/2
not_4 = 0
ans = 'Yes'
for i in range(len(a)):
  for j in range(len(a)):
    
    if i == j or a[i]*a[j]%4 == 0:
      continue
    else:  
      not_4 += 1
      
      if not_4 >= pair:
        ans = 'No'
        break
    
print(ans)

Submission status: Time Limit Exceeded

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

pair = n*(n - 1)/2
not_4 = 0
ans = 'Yes'
for i in range(len(a)):
  for j in range(len(a)):
    
    if i == j or a[i]%4 == 0 or a[j]%4 == 0:
      continue
    else:  
      if a[i]*a[j]%4 != 0:
        not_4 += 1
      
      if not_4 >= pair:
        ans = 'No'
        break
    
print(ans)

Submission status: Time Limit Exceeded

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

pair = n*(n - 1)/2
not_4 = 0
ans = 'Yes'
for i in range(len(a)):
  for j in range(len(a)):
    
    if i == j:
      continue
      
    if a[i]*a[j]%4 != 0:
      not_4 += 1
      
    if not_4 >= pair:
      ans = 'No'
      break
    
print(ans)

Submission status: Time Limit Exceeded

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

pair = n*(n - 1)/2
not_4 = 0

for i in range(len(a)):
  for j in range(len(a)):
    
    if i == j:
      continue
      
    if a[i]*a[j]%4 != 0:
      not_4 += 1
    
if pair > not_4:
  print('Yes')
else:
  print('No')

Submission status: Time Limit Exceeded

Solution code:
from random import shuffle

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

b = []
c = []

f = a.count(2)

a = [i for i in a if i != 2]

for i in range(len(a)):
    if a[i] % 4:
        b.append(a[i])
    else:
        c.append(a[i])

d = []

while b and c:
    d.append(b.pop())
    d.append(c.pop())

e = d.copy()

d.extend(b)
d.extend([2] * f)
d.extend(c)

for i in range(1, n):
    if (d[i] * d[i-1]) % 4:
        break
else:
    print('Yes')
    exit()

e.extend(b)
e.extend(c)
e.extend([2] * f)

for i in range(n - 1):
    if (e[i] * e[i+1]) % 4:
        break
else:
    print('Yes')
    exit()

e.sort()

for i in range(n - 1):
    if (e[i] * e[i+1]) % 4:
        break
else:
    print('Yes')
    exit()

for _ in range(100):
    shuffle(e)

    for i in range(n - 1):
        if (e[i] * e[i+1]) % 4:
            break
    else:
        print('Yes')
        break

print('No')

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
import math
import calendar
import fractions
import itertools

n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in list(itertools.permutations(a)):
    flag = 1
    for j in range(len(i) - 1):
        if i[j] * i[j + 1] % 4 != 0:
            flag = 0
            break
    if flag == 1:
       ans = 1
       break
if ans == 1:
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

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

ans = 'No'

for i in itertools.permutations(a):
    count = 0
    for j in range(1, len(i)):
        if (i[j-1] * i[j]) % 4 == 0:
            count += 1
        else:
            pass
    if count == N-1:
        ans = 'Yes'
        break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N=int(input())
A=list(map(int,input().split()))
junretsu=list(itertools.permutations(A))
for j in junretsu:
    cnt=0
    for i in range(N-1):
        if j[i]*j[i+1]%4!=0:
            break
        else:
            cnt+=1
    if cnt==N-1:
        print('Yes')
        exit()
print('No')

Submission status: Time Limit Exceeded

Solution code:
import itertools as itr

N = int(input())
input_a = input()
a_list = input_a.split()

def check(list1, N):
    temp = list(itr.permutations(range(N)))
    for combination in temp:
        target = []
        flag = True
        for i in combination:
            target.append(list1[i])
        for i in range(N-1):
            if (int(target[i])*int(target[i+1])%4 != 0):
                flag = False       
                break
        if flag:
            return True
    return False

if check(a_list, N):
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
v = list(map(int,input().split(' ')))
ans = 0
tmp = 0
for i in range(0,n-1):
    for j in range(i+1, n):
        if v[i]*v[j] % 4 == 0:
            ans += 1
        else:
            tmp += 1
if  ans > tmp:
    print('Yes')
else:
    print('No')

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

seq = list(itertools.permutations(A))

flag = 0
for i in range(len(seq)):
    seq_i = seq[i]
    cnt = 0
    for j in range(len(seq_i)-1):
        if (seq_i[j] * seq_i[j+1]) % 4 == 0:
            cnt += 1
        else:
            pass
    if cnt == len(seq_i) - 1:
        flag = 1
        break
    else:
        pass

if flag == 1:
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
a = list(input().split())
all_list = list(itertools.permutations(a))
flag = False
for list in all_list:
    # print(list)
    for i in range(len(list)-1):
        check_num = int(list[i]) * int(list[i+1]) % 4
        # print(check_num)
        if check_num != 0:
            flag = True
            break
    if flag == True:
        flag = False
    else:
        print("Yes")
        flag = True
        break

if flag == False:
    print("No")

Submission status: Time Limit Exceeded

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

import itertools

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


for i in itertools.permutations(A):
    ans = 'Yes'
    for n in range(N-1):
        if (i[n] * i[n+1]) % 4 != 0:
            ans = 'No'
    if (ans == 'Yes'):
        break

print(ans)

Submission status: Time Limit Exceeded

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

vals    = vals.split()
#　数値変換
vals    = list(map(lambda v:int(v), vals))

def solve(remain, a):
    '''bは指定必須とする'''

    if len(remain) == 1:
        if (a*remain[0]) % 4 == 0:
            return True
        return False

    # len > 1の場合

    for i in range(len(remain)):
        if (a * remain[i]) % 4 == 0:
            res = solve(remain[0:i] + remain[i+1:], remain[i])
            if res == True:
                return True



for i in range(len(vals)):
    a   = vals[i]
    if solve(vals[0:i] + vals[i+1:], a) == True:
        print("Yes")
        break;
else:
    print("No")

Submission status: Time Limit Exceeded

Solution code:
# -*- coding:utf-8 -*-
N = int(input())
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 and tmp not in b ]
d = [ tmp for tmp in a if tmp%2 != 0 ]
if len(c) != 0 and len(b)-len(d) >= 0:
    print("Yes")
elif len(c) == 0 and len(b)+1 >= len(d):
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input())
as_ = [int(e) for e in input().split()]

if any([all([(l[i] * l[i + 1]) % 4 == 0 for i in range(n - 1)]) for l in itertools.permutations(as_)]):
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

Solution code:
from itertools import permutations
def ss():
    n = int(input())
    arr  =  input().split(' ')
    arr = [int(x) for x in arr]
    
    #print(arr)
    per = list(permutations(arr))
    #print(per)
    for i in range(len(per)):
        #for ii in range(1, n-1):
        if all  ((per[i][x] * per[i][x+1] )%4 == 0 for x in range(n-1)) :
            return 'Yes'

    return 'No'
            
print(ss())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
X = [0,0,0]

for i in range(len(A)):
  if A[i]%4 == 0:
    X[2] += 1
  elif A[i]%2 == 0:
    X[1] += 1
  else:
    X[0] += 1

if 2*X[2] + 1 >= N:
  print("Yes")
elif 2*X[2] + X[1]>= N:
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import deque

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

cnt_2 = 0
cnt_4 = 0
for i in range(n):
    a = A[i]
    if a%4==0:
        cnt_4+=1
    elif a%2==0:
        cnt_2+=1
cnt_else = n-cnt_2-cnt_4
cnt_else += cnt_2%2

if cnt_else-1 <= cnt_4:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Sep 27 02:20:18 2020

@author: liang
"""

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

c0 = 0
c4 = 0
for a in A:
    if a%2 == 1:
        c0 += 1
    elif a%4 == 0:
        c4 += 1

if c0 <= c4:
    print("Yes")
else:
    if c0 + c4 == N and c0 == c4 + 1:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
from collections import defaultdict

d = defaultdict(int)
d=[0]*3
n = int(input())

for i in list(map(int, input().split())):
  if i % 4 == 0:
    d[2] += 1
  elif i % 2 == 0:
    d[1] += 1
  else:
    d[0] += 1
t = d[2] - d[1]
if (d[0] <= d[2]) or ((d[0] == d[2] + 1) and (d[1] == 0)):
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
import math
from math import gcd,pi,sqrt
INF = float("inf")
MOD = 10**9 + 7

import sys
sys.setrecursionlimit(10**6)
import itertools
import bisect
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    n = i_input()
    a = i_list()

    one = 0
    b = []
    for i in a:
        if i %2 == 0:
            one += 1
            b.append(i//2)
    two = 0
    for i in b:
        if i % 2 == 0:
            two += 1
    zero = n - one
    one = n - zero - two
    if zero <= two or one == 0 and zero - two == 1:
        print("Yes")
    else:
        print("No")







if __name__=="__main__":
    main()

Submission status: Accepted

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

if (count + (hcount // 2)) >= (N // 2):
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

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

Submission status: Accepted

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

if four >= n // 2 or n - 2 * four <= two:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
A = [min(x & -x, 4) for x in A]

CA = Counter(A)
num0 = CA[1]
num1 = CA[2]
num2 = CA[4]
if num1:
    num1 = 1
if num2 - (num1 + num0) >= -1:
    print("Yes")

else:
    print("No")

Submission status: Accepted

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

i1=len([i for i in A if i%2!=0])
i4=len([i for i in A if i%4==0])
i2=min(1,N-i1-i4)

# print(i1,i2,i4)
print('Yes' if (i1+i2-1)<=i4 else 'No')

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
x=0
y=0
for i in range(n):
  if a[i]%2!=0:
    x+=1
  elif a[i]%4==0:
    y+=1

if x<=y:
  print("Yes")
else:
  if x+y==n and x==y+1:
    print("Yes")
  else:
    print("No")

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
t = [0 for _ in range(3)]

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

if t[0] + (t[1]%2) <= t[2] + 1:
	print("Yes")
else:
	print("No")

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C
# CreatedDate:  2020-09-04 15:44:42 +0900
# LastModified: 2020-09-13 16:06:20 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


def main():
    n = int(input())
    A = list(map(int, input().split()))
    A_4 = [x for x in A if x % 4 == 0]
    A_2 = [x for x in A if x % 4 != 0 and x % 2 == 0]
    A_0 = [x for x in A if x % 2 != 0]
    if len(A_2) == 0 and len(A_0) <= len(A_4) + 1:
        print("Yes")
    elif len(A_0) <= len(A_4):
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
one=0
four=0
two=0
for i in range(n):
    cnt=0
    num=a[i]
    while num%2==0:
        cnt+=1
        num//=2
    if cnt==0:
        pin=1
    elif cnt==1:
        pin=2
    else:
        pin=4
    if pin==1:
        one+=1
    elif pin==4:
        four+=1
    else:
        two+=1
if two>0:
    one+=1
if one<=four+1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
with open(0) as f:
    N, *a = map(int, f.read().split())
i, j, k = 0, 0, 0
for x in a:
    if x%4 == 0:
        i += 1
    elif x%2 == 0:
        j += 1
    else:
        k += 1
    
if j > 0:
    k += 1
print('Yes' if k <= i+1 else 'No')

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int,input().split()))
for i in range(N):
    if a[i]%4==0:
        a[i]=2
    elif a[i]%2==0:
        a[i]=1
    else:
        a[i]=0
zero=a.count(0)
one=a.count(1)
two=a.count(2)

if zero>two+1:
    print("No")
elif zero==two+1:
    if zero+two==N:
        print("Yes")
    else:
        print("No")
else:
    print("Yes")

Submission status: Accepted

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

Submission status: Accepted

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

num2 = 0
num4 = 0
odd = 0
for i in a:
    if i % 4 == 0:
        num4 += 1
        continue
    elif i % 2 == 0:
        num2 += 1
        continue
    else:
        odd += 1
        continue
if odd<=num4 or (N%2==1 and num4==N//2):
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

two = 0
four = 0
odd = 0

for a in A:
  if a % 4 == 0:
    four += 1
  elif a % 2 == 0:
    two += 1

N -= max(0, two - 1)

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

Submission status: Accepted

Solution code:
n = int(input())
an = [int(num) for num in input().split()]

one,two,four = 0, 0, 0
for a in an:
  if a%4 == 0:
    four += 1
  elif a%2 == 0:
    two += 1
  else :
    one += 1
    
if two == 0 and four >= one - 1 :
  print("Yes")
elif four >= one :
  print("Yes")
else :
  print("No")

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
x=0 #odd
y=0 #2
z=0 #4
for i in a:
    if i%4==0:
        z+=1
    elif i%2==0:
        y+=1
    else:
        x+=1
if x<=z:
    print("Yes")
else:
    if x==z+1 and y==0:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode
import sys
sys.setrecursionlimit(10 ** 6)

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

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

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

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

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

def RS():
    return list(input())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input()) for _ in range(n) ]

ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())

n = I()
a = RI()

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

if ddict[4]>=floor(n/2):
    print("Yes")
elif ddict[2]>=(n-ddict[4]*2):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a4 = []
a2 = []
a1 = []
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 len(a4) >= n//2:
    print("Yes")
elif len(a4) + len(a2)//2 >= n//2:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
#
# abc069 c
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3
1 10 100"""
        output = """Yes"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """4
1 2 3 4"""
        output = """No"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """3
1 4 1"""
        output = """Yes"""
        self.assertIO(input, output)

    def test_入力例_4(self):
        input = """2
1 1"""
        output = """No"""
        self.assertIO(input, output)

    def test_入力例_5(self):
        input = """6
2 7 1 8 2 8"""
        output = """Yes"""
        self.assertIO(input, output)


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

    Q = 0
    E = 0
    O = 0
    for a in A:
        if a % 4 == 0:
            Q += 1
        elif a % 2 == 0:
            E += 1
        else:
            O += 1

    if N-2*Q <= 0 or (N-2*Q) == 1 or N-2*Q == E:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Accepted

Solution code:
def even(x):
    flag1 = False
    if x % 2 == 0:
        flag1 = True
    return flag1


def multiple_of_4(x):
    flag2 = False
    if x % 2 == 0:
        x //= 2
        if x % 2 == 0:
            flag2 = True
    return flag2


def main():
    n = int(input())
    a_lst = list(map(int, input().split()))
    flag = False

    multiple_of_4_count = 0
    for i in range(n):
        if multiple_of_4(a_lst[i]):
            multiple_of_4_count += 1

    if multiple_of_4_count >= n // 2:
        flag = True
    else:
        even_count = 0
        for i in range(n):
            if even(a_lst[i]):
                even_count += 1
        tmp = n - 2 * multiple_of_4_count
        even_count -= multiple_of_4_count

        if even_count >= tmp:
            flag = True

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

#print(num4, num2)



if n-num4*2 <= 1:
    print("Yes")
elif n-num4*2 <= num2:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
c2 = 0
c4 = 0
for i in range(N):
    if a[i]%4 == 0:
        c4 += 1
    elif a[i]%2 == 0:
        c2 += 1
f = c4 * 2 + 1
if f >= N or f + c2 - 1 >= N:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

A_num=0
B_num=0
C_num=0

for i in a:
    if i%4==0:
        C_num+=1
    elif i%2==0:
        B_num+=1
    else:
        A_num+=1

def ans():
    if A_num==1:
        if C_num>=1:
            return True
        return False
    else:
        if n==2*A_num-1:
            if C_num==A_num-1:
                return True
            return False

        elif n<2*A_num-1:
            return False
        else:
            if C_num>=A_num:
                return True
            return False
if ans():
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    n_odd = 0
    n_4mul = 0
    n_2mul = 0
    for a in A:
        if a % 2 == 1:
            n_odd += 1
        elif a % 4 == 0:
            n_4mul += 1
        else:
            n_2mul += 1
    if n_odd == 0:
        print('Yes')
    elif n_odd <= n_4mul and n_2mul > 0:
        print('Yes')
    elif n_odd == n_4mul + 1 and n_2mul == 0:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = [int(an) for an in input().split()]
    exist2 = False
    not4 = 0
    count4 = 0
    for an in a:
        if an % 2 == 0:
            if an % 4 == 0:
                count4 += 1
            else:
                if not exist2:
                    exist2 = True
                    not4 += 1
        else:
            not4 += 1
    print('Yes' if count4 >= not4 - 1 else 'No')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
lsa = list(map(int,input().split()))
ans = 'Yes'
i4 = 0
i2 = 0
i1 = 0
for i in range(N):
    if lsa[i] % 4 == 0:
        i4 += 1
    elif lsa[i] % 2 == 0:
        i2 += 1
    else:
        i1 += 1
if i4+1 < i1:
    ans = 'No'
elif i2%2 == 1 and i4+1 == i1:
    ans = 'No'
print(ans)

Submission status: Accepted

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

count2 = 0
count4 = 0

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

v=count2//2

n-=v*2
if count4 >= n//2:
    ans='Yes'
else:
    ans='No'

print(ans)

Submission status: Accepted

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

multi_4 = 0
multi_2 = 0
odd = 0
for a in A:
    if a % 4 == 0:
        multi_4 += 1
    elif a % 2 == 0:
        multi_2 += 1
    else:
        odd += 1

if multi_2 > 0:
    if odd > multi_4:
        print('No')
    else:
        print('Yes')
else:
    if odd > multi_4 + 1:
        print('No')
    else:
        print('Yes')

Submission status: Accepted

Solution code:
n = int(input())

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

odd_num = len([e for e in arr if e % 2 != 0])
four_num = len([e for e in arr if e % 4 == 0])
even_num = n - odd_num - four_num

if even_num:
    print("Yes" if four_num >= odd_num else "No")
else:
    print("Yes" if four_num >= odd_num - 1 else "No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 2 2 4 1 4 1
# 1 4 1 2 2
n = int(input())
a = list(map(int,input().split()))
i2 = 0
i4 = 0
for i in range(n):
    if a[i]%4==0:
        i4 += 1
    if a[i]%2==0:
        i2 += 1

if n//2 <= i4:
    print('Yes')
else:
    tmp = n//2
    if n%2==0:
        if (tmp - i4) * 2 <= (i2 - i4):
            print('Yes')
        else:
            print('No')
    else:
        if (tmp - i4) * 2 + 1 <= (i2 - i4):
            print('Yes')
        else:
            print('No')