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:
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
# print(a)

if a.count(0)+(1 if 1 in a else 0) <= a.count(2)+1:
    print('Yes')
    exit(0)
print('No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict
d = defaultdict(int)
n = int(input())
a = list(map(int, input().split()))
for num in a:
  if num % 4 == 0:
    d[4] += 1
    continue
  if num % 2 == 0:
    d[2] += 1
    continue
print("Yes" if n//2 <= d[4] + (d[2] // 2) else "No")

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
d4=len([i for i in A if i%4==0])
d2=len([i for i in A if i%2==0 and i%4!=0])

N=N-(d4*2)
if N==1:
    N=0
else:
    N-=d2

print("Yes" if N<=0 else "No")

Submission status: Accepted

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

Submission status: Accepted

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

# 4の倍数になるものを削除
A_x2 = [a for a in A if a % 4 != 0]
# 4の倍数の要素数を数える
num_x4 = len(A) - len(A_x2)
# 2の倍数になるものを削除
A_x1 = [a for a in A_x2 if a % 2 != 0]

# 奇数と偶数の数を数える
num_odd = len(A_x1)
num_even = len(A_x2) - num_odd

#
if num_even == 0:
    num_mod = 0
else:
    num_mod = 1

if num_odd + num_mod <= num_x4 + 1:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

A = 0
B = 0
C = 0
for i in range(N):
    if T[i] % 2 != 0:
        A += 1
    elif T[i] % 4 == 0:
        B += 1
    else:
        C += 1

if A > B + 1:
    print("No")
elif C != 0 and A > B:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    a = list(map(int, readline().split()))
    ac = [0] * n
    for i, v in enumerate(a):
        cnt = 0
        t = v
        while True:
            if t % 2 == 0 and cnt < 2:
                cnt += 1
                t //= 2
            else:
                ac[i] = cnt
                break
    if ac.count(0) == 0:
        print("Yes")
    else:
        if ac.count(1) == 0:
            if ac.count(0) - ac.count(2) <= 1:
                print("Yes")
            else:
                print("No")
        else:
            if ac.count(0) - ac.count(2) <= 0:
                print("Yes")
            else:
                print("No")


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
cnt1=0
cnt2=0
for i in range(n):
  if a[i]%4==2:
    cnt1+=1
  if a[i]%4==0:
    cnt2+=1
if cnt2>=n//2 or cnt1+cnt2==n-cnt2:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N=int(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
wst=N-cnt4-cnt2
wst+=cnt2%2
#print(wst,cnt4)
if (wst+cnt4)%2==0:#偶数のとき
    if wst<=cnt4:
        print('Yes')
    else:
        print('No')
else:#奇数のとき
    if wst+1>=cnt4:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

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

numbers = [0, 0, 0]

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

if (numbers[1] == 0) and (numbers[2] - numbers[0] <= 1):
    print('Yes')
elif (numbers[1] != 0) and (numbers[0] >= numbers[2]):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
#ダメそうな雰囲気する

n=int(input())
amod4=[i%4 for i in map(int,input().split())]
#print(amod4)
from collections import Counter
s=Counter(amod4)
num4=s[0]
num2=s[2]

#print(num4,num2,another)

def ok():print("Yes");exit()
def ng():print("No");exit()

if num2==n:
  ok()
  
if num4>=(n-(num2-1)*(n>num2>0))//2:ok()

else:
  ng()

Submission status: Accepted

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

Submission status: Accepted

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

kisuu = 0
four_baisuu = 0

for a in A:
    if a % 2 != 0:
        kisuu += 1
    elif a % 4 == 0:
        four_baisuu += 1
if kisuu <= four_baisuu:
    print("Yes")
elif kisuu + four_baisuu == len(A) and kisuu == four_baisuu + 1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N, *a = map(int, open(0).read().split())
fours = 0
even = 0
odd = 0
for x in a:
  if x%2 == 1:
    odd += 1
  elif x%4 == 0:
    fours += 1
  else:
    even += 1
ans = (odd <= fours) or (odd == fours + 1 and even == 0)
print('Yes' if ans else 'No')

Submission status: Accepted

Solution code:
n = int(input())
b = list(map(int, input().split()))
ln = []
ln2 =  []
for i in b:
    if i % 4 == 0:
        ln.append(i)
    if i % 2 == 0 and i % 4 != 0:
        ln2.append(i)
if n % 2 == 0:
    if len(ln) >= n//2:
        print('Yes')
    else:
            if n - len(ln) * 2 == len(ln2):
                print('Yes')
 
            else:
                    print('No')
if n % 2 == 1:
    if len(ln) >= (n - 1)//2:
        print('Yes')
    else:
        if n - len(ln) * 2 == len(ln2):
            print('Yes')
        else:
            if n == 3 and len(ln) == 1:
                print('Yes')
            else:
                print('No')

Submission status: Accepted

Solution code:
import math

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

x = math.ceil((n - 3) / 2) + 1

cnt4 = 0
cnt2 = 0
for i in a:
    if i % 4 == 0:
        cnt4 += 1
    elif i % 4 != 0 and i % 2 == 0:
        cnt2 += 1
     
if (cnt4 + cnt2//2) >= x:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n = int(input())
A = [int(i) for i in input().split()]
cnt = 0
cnt1 = 0
for a in A:
  if a%4==0:
    cnt += 1
  elif a%2==0 and a%4!=0:
    cnt1 += 1
if int(n/2) <= cnt+(cnt1//2):
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
import numpy as np 
import collections

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

a_array = np.array(a_list)
mod4_array = a_array % 4
mod4_list = mod4_array.tolist()

counter = collections.Counter(mod4_array)

odd_num = counter[1] + counter[3]
div_2 = counter[2]
div_4 = counter[0]

#一番低燃費な並べ方でやってしまえば良い

if odd_num == 0:
    print('Yes')
else: #奇数が1つ以上入っている
    if odd_num <= div_4:
        print('Yes')
    elif odd_num == div_4 + 1:
        if div_2 == 0: 
            print('Yes')
        else:
            print('No')
    else:
        print('No')

Submission status: Accepted

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

four = 0
two = 0

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

s = n//2

if s <= four:
    print("Yes")
    exit()
    
tmp = n - four*2

if tmp <= two:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
L=list(map(int,input().split()))
s2,s4=0,0 #s2は２で割れる数、s4は４で割れる数の個数
for j in L:
  if j%4==0:
    s4+=1
  elif j%2==0:
    s2+=1
if s2==0:
  if (N-s2-s4)<=s4+1:
    print("Yes")
  else:
    print("No")
else:
  if (N-s2-s4)<=s4:
    print("Yes")
  else:
    print("No")

Submission status: Accepted

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

no2=0
bai4=0
bai2=0
for i in range(len(a)):
  if a[i]%4==0:
    bai4+=1
  elif a[i]%2==1:
    no2+=1
  else:
    bai2+=1
if bai2==0:
  print(("No","Yes")[no2<=bai4+1])
else:
  print(("No","Yes")[no2<=bai4])

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

c2 = 0
c4 = 0
for a in A:
    r4 = a % 4
    if r4 == 0:
        c4 += 1
    r2 = a % 2
    if r2 == 0:
        c2 += 1
if c4 * 2 + 1 >= N or c4 * 2 + max(0, c2-c4) >= N:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

S = [0]*3 
for i in a:
    if i % 4 == 0:
        S[2] += 1
    elif i % 2 == 0:
        S[1] += 1
    else:
        S[0] += 1

if len(a) % 2 == 1 and S[2] + 1 == S[0]:
    print("Yes")
    sys.exit()

if S[2] < S[0]:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
from collections import defaultdict
def main():
    N = int(input())
    A = list(map(int, input().split()))
    d = defaultdict(int)
    for i in range(N):
        if A[i] % 2 == 0:
            if A[i] % 4 == 0:
                d[2] += 1
            else:
                d[1] += 1
        else:
            d[0] += 1
    
    if d[1] == 0:
        if d[0] - 1 <= d[2]:
            print('Yes')
            exit()
    else:
        if d[0] <= d[2]:
            print('Yes')
            exit()

    print('No')

    


if __name__ == "__main__":
    main()

Submission status: Accepted

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

odd=0
even=0
even2=0

for num in A:
    if(num%2==1):
        odd+=1
    elif(num%4==0):
        even2+=1
    else:
        even+=1

if(even2>=odd):
    print("Yes")
elif((even==0)&(even2==(odd-1))):
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
l=list(map(int,input().split()))
odd=len([1 for i in l if i%2])
t4=len([1 for i in l if i%4==0])
if odd+t4==n:
  if odd-1<=t4:print("Yes")
  else:print("No")
elif odd<=t4:print("Yes")
else:print("No")

Submission status: Accepted

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


def main():
    N = int(input())
    A = list(map(int, input().split()))
    odd = even = even4 = 0
    for a in A:
        if a % 4 == 0:
            even4 += 1
        elif a % 2 == 0:
            even += 1
        else:
            odd += 1
    if even == 0:
        print("Yes" if even4 >= odd - 1 else "No")
    else:
        print("Yes" if even4 >= odd else "No")


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

b2=0
b4=0
bb=0
for a in A:
  if a%4==0:
    b4+=1
  if a%2==0:
    b2+=1
bb=N-b2
b2-=b4
#print(b4,b2,bb)

if b2==0:
  if b4+1>=bb:
    print("Yes")
  else:
    print("No")
else:
  if b4>=bb:
    print("Yes")
  else:
    print("No")

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    
    N = int(input())
    A = list(map(int,input().split()))
    
    one = 0
    two = 0
    four = 0
    for i in A:
        if i%4==0:
            four += 1
        elif i%2==0:
            two += 1
        else:
            one += 1
            
    if two == 0:
        if four+1 >= one:
            print("Yes")
        else:
            print("No")
    else:
        if four >= one:
            print("Yes")
        else:
            print("No")
    
    
main()

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
div_4 = 0
div_2 = 0
div_0 = 0
for a in A:
    tmp = a
    count = 0
    while True:
        if tmp % 2 == 0:
            tmp = tmp // 2
            count += 1
        else:
            break
    if count == 0:
        div_0 += 1
    elif count == 1:
        div_2 += 1
    else:
        div_4 += 1
if div_2 == 0:
    if div_0 <= (div_4 + 1):
        print("Yes")
    else:
        print("No")
else:
    if div_0 <= div_4:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
from collections import Counter
import sys
sys.setrecursionlimit(1000000)

def solve():
  n = int(input())
  a = list(int(i) for i in input().split())
  two = 0
  four = 0
  for i in a:
    if i %4 == 0:
      four += 1
    elif i%2 == 0:
      two += 1
  four += two//2
  if n <= four*2+1:
    print("Yes")
  else:
    print("No")
solve()

Submission status: Accepted

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

f=True
c=0
o=0
ans="No"
for i in range(N):
    if a[i]%2!=0:
        f=False
        o+=1
    if a[i]%4==0:
        c+=1

if f:
    ans="Yes"
if c>=o or c>=N//2:
    ans="Yes"

print(ans)

Submission status: Accepted

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

f=True
c=0
o=0

for i in range(N):
    if a[i]%2!=0:
        f=False
        o+=1
    if a[i]%4==0:
        c+=1

if f:
    print("Yes")
    exit()
if c>=o:
    print("Yes")
    exit()
if c>=N//2:
    print("Yes")
    exit()

print("No")

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
ans="No"
f=[a for a in A if a%4==0]
t=[a for a in A if a%4!=0 and a%2==0]
if len(f)*2+len(t)>=N:
  ans="Yes"
elif len(f)>=(N-1)//3+1 and N%2!=0:
  ans="Yes"
print(ans)

Submission status: Accepted

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

odd = 0
mul4 = 0

for a in A:
    if a % 2 != 0:
        odd += 1
    if a % 4 == 0:
        mul4 += 1

if mul4 >= odd:
    print('Yes')
else:
    if mul4 * 2 + 1 == N:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
four = len([a for a in A if a%4==0])
even = len([a for a in A if a%4!=0 and a%2==0])
if N-(four*2)<=even or four>=N//2:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n = int(input())
m1, m2, m4 = 0, 0, 0

for a in input().split():
    x = int(a)
    if x % 2 == 0:
        if x % 4 == 0: m4 += 1
        else: m2 += 1
    else: m1 += 1

ans = m4 >= m1 if(m2) else m4 + 1 >= m1
print("Yes" if ans else "No")

Submission status: Accepted

Solution code:
# ABC069C - 4-adjacent (ARC080C)
def main():
    N = int(input())
    A = tuple(map(int, input().split()))
    f, t, m = 0, 0, 0  # two, four, misc
    for i in A:
        if i % 4 == 0:
            f += 1
        elif i % 2 == 0:
            t += 1
        else:
            m += 1
    m += t % 2
    flg = f + 1 >= m
    print("Yes" if flg else "No")


if __name__ == "__main__":
    main()

Submission status: Accepted

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

ans = "No"
if four_ad >= other:
  ans = "Yes"
elif four_ad == other - 1 and not two_ad:
  ans = "Yes"
print(ans)

Submission status: Accepted

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

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n,m = LI()
    a = LIR(n)
    ans = 0
    for i in range(2):
        for j in range(2):
            for k in range(2):
                a.sort(key = lambda x:(-1)**i*x[0]+(-1)**j*x[1]+(-1)**k*x[2])
                p = [0,0,0]
                for l in range(m):
                    p[0] += a[l][0]
                    p[1] += a[l][1]
                    p[2] += a[l][2]
                p = abs(p[0])+abs(p[1])+abs(p[2])
                if p > ans:
                    ans = p
    print(ans)
    return

#B
def B():
    def root(x):
        if x == par[x]:
            return x
        par[x] = root(par[x])
        return par[x]

    def unite(x,y,su):
        x = root(x)
        y = root(y)
        su += comb_2(s[x])+comb_2(s[y])
        if rank[x] < rank[y]:
            s[y] += s[x]
            su -= comb_2(s[y])
            par[x] = y
        else:
            s[x] += s[y]
            su -= comb_2(s[x])
            par[y] = x
            if rank[x] == rank[y]:
                rank[x] += 1
        return su

    def comb_2(a):
        return a*(a-1)//2

    n,m = LI()
    v = LIR(m)
    par = [i for i in range(n)]
    rank = [0]*n
    s = [1]*n
    su = comb_2(n)
    ans = [su]
    for a,b in v[:0:-1]:
        a -= 1
        b -= 1
        if root(a) != root(b):
            su = unite(a,b,su)
        ans.append(su)
    for i in ans[::-1]:
        print(i)
    return

#C
def C():
    def root(x):
        if par[x] == x:
            return par[x]
        r = root(par[x])
        d[x] += d[par[x]]
        par[x] = r
        return par[x]

    def weight(x):
        root(x)
        return d[x]

    def unite(x,y,w):
        w += weight(x)
        w -= weight(y)
        x = root(x)
        y = root(y)
        if rank[x] < rank[y]:
            par[x] = y
            d[x] = -w
        else:
            par[y] = x
            d[y] = w
            if rank[x] == rank[y]:
                rank[x] += 1
    n,m = LI()
    par = [i for i in range(n)]
    rank = [0]*n
    d = [0]*n
    for i in range(m):
        l,r,w = LI()
        l -= 1
        r -= 1
        if root(l) != root(r):
            unite(l,r,w)
        else:
            if weight(r)-weight(l) != w:
                print("No")
                return
    print("Yes")
    return

#D
def D():
    h,w = LI()
    n = I()
    a = LI()
    ans = [0]*h*w
    p = 0
    for i in range(n):
        for j in range(a[i]):
            ans[p+j] = i+1
        p += a[i]
    for i in range(h):
        s = ans[i*w:(i+1)*w]
        if i%2:
            print(*s[::-1])
        else:
            print(*s)
    return

#E
def E():
    n,k = LI()
    s = [int(x) for x in input()]
    f = [0]*n
    j = 0
    su = 1
    p = s[0]
    for i in range(1,n):
        if s[i] != p:
            f[j] = su
            j += 1
            su = 1
            p = s[i]
        else:
            su += 1
    f[j] = su
    f.append(0)
    if s[0]:
        m = sum(f[:2*k+1])
        ans = m
        for i in range(2*k+1,n):
            m -= f[i-2*k-1]
            if not i%2:
                m += f[i-1]
                m += f[i]
            ans = max(m,ans)
    else:
        m = sum(f[:2*k])
        ans = m
        for i in range(2*k,n):
            m -= f[i-2*k]
            if not i%2:
                m += f[i]
                m += f[i+1]
            ans = max(m,ans)
    print(ans)
    return

#F
def F():
    n = I()
    a = LI()
    s = [0,0,0]
    for i in a:
        if i%4 == 0:
            s[0] += 1
        elif i%2 == 0:
            s[1] += 1
        else:
            s[2] += 1
    a = [0]
    while 1:
        if s[2]:
            if a[-1] == 2:
                print("No")
                return
            s[2] -= 1
            a.append(2)
            if s[0]:
                s[0] -= 1
                a.append(0)
        elif s[1]:
            if a[-1] == 2:
                print("No")
            else:
                print("Yes")
            return
        else:
            print("Yes")
            return
    return

#G
def G():

    return

#H
def H():

    return

#I
def I_():

    return

#Solve
if __name__ == "__main__":
    F()

Submission status: Accepted

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

four_divisible = 0
odd = 0
for e in a:
    if e % 2 != 0:
        odd += 1
    elif e % 4 == 0:
        four_divisible += 1
    
if odd > four_divisible:
    if odd == four_divisible + 1 and odd + four_divisible == N:
        print("Yes")
    else:
        print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

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

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))


def count2(n):
    # 素因数分解したときに2が何個あるか
    ret = 0
    while n & 1 == 0:
        n >>= 1
        ret += 1
    return ret


C = list(map(count2, A))
C.sort()
C = deque(C)

order = []
while C:
    order.append(C.popleft())
    if C:
        order.append(C.pop())
ok = True
for a, b in zip(order[:-1], order[1:]):
    ok &= a + b >= 2
if ok:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
# 2019/08/09

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

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

if sec>0:rem+=1
if rem-quad<=1:
    print('Yes')
else:print('No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
A = [int(i) for i in input().split()]
tmp,tmp2,two = 0,0,0
for a in A:
    if a%4 == 0: tmp += 1
    elif a%2 == 0: two = 1
    else: tmp2 += 1
#print(tmp,tmp2,two)
if tmp2+two-tmp >= 2: print('No')
else: print('Yes')

Submission status: Accepted

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

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(N: int, a: "List[int]"):
    count = [0 for _ in range(4)]
    for x in a:
        count[x % 4] += 1
    
    M = N - max(0, count[2] - 1)
    if count[0] >= M // 2:
        print(YES)
    else:
        print(NO)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, a)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
o=0;f=0
x='Yes'
for i in a:
  if i%4==0:
    f+=1
  elif i%2==1:
    o+=1
if o>f:
  if o!=f+1 or o+f!=n:
    x='No'
print(x)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(lambda x:int(x)%4,input().split()))
for i,j in enumerate(a):
	if j==0:
		a[i]=2
	elif j==2:
		a[i]=1
	else:
		a[i]=0
if sum(a)<(n//2)*2:
	print('No')
else:
	print('Yes')

Submission status: Accepted

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

Submission status: Accepted

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

four = 0
two = 0
odd = 0

for x in a:
    if x%4 == 0:
        four += 1
    elif x%2 == 0:
        two += 1
    else:
        odd += 1
#print(four,two,odd)        

ans = 0
if two == 0 and odd - four == 1:
    ans = 0
else:
    if odd > four:
        ans = 1
if ans == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
# ARC080C - 4-adjacent (ABC069C)
def main():
    n = int(input())
    A = tuple(map(int, input().rstrip().split()))
    f, t, m = 0, 0, 0  # two, four, misc
    for i in A:
        if i % 4 == 0:
            f += 1
        elif i % 2 == 0:
            t += 1
        else:
            m += 1
    m += t % 2
    print("Yes" if m - f <= 1 else "No")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n,a=open(0)
c=[int(i)%4for i in a.split()].count
f,g=c(0),c(2)
print('YNeos'[int(n)-f-g>f+(g==0)::2])

Submission status: Accepted

Solution code:
n,a=open(0)
a=[int(i)%4for i in a.split()]
f,g=a.count(0),a.count(2)
print('YNeos'[int(n)-f-g>f+(g==0)::2])

Submission status: Accepted

Solution code:
n = int(input())
an = list(map(int,input().split()))
four = 0
odd = 0
for a in an:
    if a%4==0:
        four+=1
    if a%2!=0:
        odd+=1
if odd+four!=n:
    odd+=1
if four >= odd - 1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 奇数の隣は必ず4の倍数でなくてはならない あとはどうでもよさそう
# ただし 1 4 1 は大丈夫だが 1 4 1 2 はダメ
n = int(input())
arr = list(map(int, input().split()))
dividable_four = 0
odds = 0
for a in arr:
    if a % 4 == 0:
        dividable_four += 1
    elif a % 2 == 1:
        odds += 1
if dividable_four >= odds:
    print('Yes')
elif odds - dividable_four == 1 and odds + dividable_four == n:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

ans = 'No'

cnt4 = 0
cnt2 = 0

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

if 2*cnt4 + 1 >= N:
    ans = 'Yes'
else:
    res = N - 2*cnt4
    if res <= cnt2:
        ans = 'Yes'
        
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
c_odd = 0
c_even = 0
c_4 = 0

for i in range(N):
    if a[i] % 2 != 0:
        c_odd += 1
    else:
        if a[i] % 4 == 0:
            c_4 += 1
        else:
            c_even += 1

if c_even == 0:
    if c_odd <= c_4 + 1:
        print('Yes')
    else:
        print('No')
else:
    if c_odd == c_4:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

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

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

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

Submission status: Accepted

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

i=0
j=0
s=[]
c=0
while i!=n:
    x=a[i]

    while j!=2:
        if x%2==0 and 2<=x:

            c+=1
            x=x/2
            j+=1
        else:
            break

    s.append(c)
    c=0
    j=0
    i+=1
if s.count(2)>s.count(0):
    print("Yes")
elif (s.count(0)-s.count(2))>1:
    print("No")
elif s.count(0)==s.count(2):
    print("Yes")
elif s.count(0)+s.count(2)==len(s):
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

num = 0
num2 = 0
num4 = 0

for i in a:
    if i % 4 == 0:
        num4 += 1
    elif i % 2 == 0:
        num2 += 1
    else:
        num += 1
num2 %= 2
num += num2
if num4 + 1 >= num:
    print("Yes")
else:
    print("No")