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 = [int(a) for a in input().split()]

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

if c4 >= cnt or (c2 == 0 and c4+1 == cnt):
    ans = "Yes"
else:
    ans = "No"
print(ans)

Submission status: Accepted

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

cnt1=0
cnt2=0
cnt4=0

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

if cnt2!=0:
  if cnt4>=cnt1:
    print('Yes')
  else:
    print('No')
else:
  if cnt4+1>=cnt1:
    print('Yes')
  else:
    print('No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
cnt = 0
for a in A:
  if a%4==0: cnt += 1
  elif a%2==0: cnt += 0.5
cnt = int(cnt)

print("Yes" if n//2 <= cnt else "No")

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
f2=lambda x:x%2==0 and x%4!=0
f4=lambda x:x%4==0
c2,c4=0,0
for i in a:
    c2+=f2(i)
    c4+=f4(i)
print('Yes' if c2+c4*2>=n or (c2==0 and c4*2+1>=n)else '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=c4+2
    elif a[i]%2==0:
        c2=c2+1
    else:
        pass

if c4+c2>=len(a):
    print("Yes")
elif c4+1>=len(a):
    print("Yes")        
else:
    print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
kisuu = 0
guusuu = 0
baisuu_4 = 0

for num in a:
  if num%2 == 1:
    kisuu += 1
  elif num%4 == 2:
    guusuu += 2
  else:
    baisuu_4 += 1

if guusuu ==0:
  if baisuu_4 >= kisuu - 1:
    print('Yes')
  else:
    print('No')
else:
  if baisuu_4 >= kisuu:
    print('Yes')
  else:
    print('No')

Submission status: Accepted

Solution code:
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))

    c0 = 0
    c4 = 0

    for ai in a:
        if ai % 2 != 0:
            c0 += 1
        if ai % 4 == 0:
            c4 += 1
    if c0 + c4 == n and c0 == c4 + 1:
        print('Yes')
    elif c0 > c4:
        print('No')
    else:
        print('Yes')


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Accepted

Solution code:
n = int(input())
cnt4 = 0
cnt2 = 0
a = list(map(int, input().split()))
for num in a:
    if num % 4 == 0:
        cnt4 += 1
    elif num % 2 == 0:
        cnt2 += 1

if cnt4 >= n // 2:
    print("Yes")
    exit()
elif cnt4 >= (n - cnt2 + 1) // 2:
    print("Yes")
    exit()
print("No")

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
nums = {0:0,1:0,2:0,3:0}
for i in range(n):
    num = a[i] % 4
    nums[num] += 1
if nums[2] % 2 == 0:
    if nums[1] + nums[3] - 1 <= nums[0]:
        print("Yes")
    else:
        print("No")
elif nums[2] % 2 == 1:
    if nums[1] + nums[3] <= nums[0]:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

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

mod_four = len([i for i in A if i % 4 == 0])
odd_number = len([i for i in A if i % 2 == 1])

if mod_four >= odd_number:
    print("Yes")
elif mod_four + 1 == odd_number and N - mod_four - odd_number == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

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

if n - (l.count(2)*2 + 1) <= 0:
    print("Yes")
elif n - (l.count(2)*2 + 1) < l.count(1):
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

Submission status: Accepted

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

resZero = 0
resTwo = 0
odds = 0
for a in A:
    if a % 4 == 0:
        resZero += 1
        continue
    elif a % 4 == 2:
        resTwo += 1
        continue
    else:
        odds += 1

if resZero - odds >= -1 and resTwo == 0:
    print('Yes')
    quit()
if resZero - odds >= 0:
    print('Yes')
    quit()
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, two, four = 0, 0, 0
    for i in range(N):
        if a[i]%4 == 0:
            four += 1
        elif a[i]%2 == 0:
            two += 1
        else:
            odd += 1
    if four == odd:
        print("Yes")
    elif two == N:
        print('Yes')    
    elif four >= N//2:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
odd = 0
even = 0
eveneven = 0
for a in A:
    if a % 4 == 0:
        eveneven += 1
    elif a % 2 == 0:
        even += 1
    else:
        odd += 1
        
if even == 0:
    #間に挟み込む
    if eveneven +1 >= odd:
        print('Yes')
    else:
        print('No')
else:
    #２を後ろに固める
    if odd <= eveneven:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int, input().split()))
cnt_2=0
cnt_1=0
cnt_0=0

for num in a:
    if num%4==0:
        cnt_2+=1
    elif num%2==0:
        cnt_1+=1
    else:
        cnt_0+=1

if cnt_1==0:
    if cnt_2+1>=cnt_0:
        print("Yes")
    else:
        print("No")

else:
    if cnt_2>=cnt_0:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

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

cnt_2 = 0
cnt_4 = 0
for a in A:
  if a % 4 == 0:
    cnt_4 += 1
  elif a % 2 == 0:
    cnt_2 += 1

cnt_1 = N - cnt_2 - cnt_4
    
if cnt_2 == 0 and cnt_1 <= cnt_4 + 1:
  print('Yes')
elif cnt_1 <= cnt_4:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
import numpy as np

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

zero = sum(A % 2 != 0)  # 2で割りきれない数
four = sum(A % 4 == 0)  # 4で割りきれる数
two = sum(np.logical_and(A % 2 == 0, A % 4 != 0))  # 4で割り切れないが、2で割りきれる数

flag = False

if two == 0:
    if zero <= four + 1:
        flag = True
else:
    if zero <= four:
        flag = True

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

Submission status: Accepted

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

odd = 0
double = 0
quatro = 0

for i in a:
  if i % 2 == 1:
    odd += 1
  else:
    if i % 4 == 0:
      quatro += 1
    else:
      double += 1

if double == N:
  print("Yes")
  exit()
plus = 0
if double != 0:
  plus = 1
if plus + odd - 1 <= quatro:
  print("Yes")
else:
  print("No")

Submission status: Accepted

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


def log(*args):
    print(*args, file=sys.stderr)


n = int(input())
l = map(int, input().split())

four_count = 0
two_count = 0
for v in l:
    if v % 4 == 0:
        four_count += 1
    elif v % 2 == 0:
        two_count += 1

if two_count > 0:
    if n - two_count - four_count <= four_count:
        print("Yes")
    else:
        print("No")
else:
    if n - four_count - 1 <= four_count:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
import numpy as np
import sys

read= sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
MOD = 1000000007
sys.setrecursionlimit(10**7)


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

cnt4,cnt2 = 0,0

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

cnt2 = max(1,cnt2)

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

Submission status: Accepted

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

cnt2 = max(1,cnt2)
print('Yes' if 2 * cnt4 + cnt2 >= n else 'No')

Submission status: Accepted

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

    sumMod2 = 0
    sumMod4 = 0
    sumElse = 0
    for v in A:
        if v % 4 == 0:
            sumMod4 = sumMod4 + 1
        elif v % 2 == 0:
            sumMod2 = sumMod2 + 1
        else:
            sumElse = sumElse + 1

    if sumMod2 == 0:
        if sumElse -1 <= sumMod4:
            print("Yes")
            return
        else:
            print("No")
            return
    else:
        if sumElse <= sumMod4:
            print("Yes")
            return
        else:
            print("No")
            return

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
L = {0: 0, 1: 0, 2: 0}
for i in range(n):
    for j in range(3):
        if a[i] % 2 == 1:
            L[j] += 1
            break
        a[i] = a[i] // 2
    else:
        L[2] += 1
L[1] = L[1] % 2
if L[2] >= L[0] + L[1] - 1:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    l=list(map(int,input().split()))
    c1=0
    c2=0
    c4=0
    for i in l:
        if i%2==1:
            c1+=1
        else:
            if i%4==0:
                c4+=1
            else:
                c2+=1
    if c2==0:
        if c1<=c4+1:
            print('Yes')
        else:
            print('No')
    else:
        if c1<=c4:
            print('Yes')
        else:
            print('No')
resolve()

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    l=list(map(int,input().split()))
    kisu=0
    ni1=0
    ni2=0
    for i in l:
        if i%2==1:
            kisu+=1
        else:
            if i%4==0:
                ni2+=1
            else:
                ni1+=1
    if ni1==0:
        if kisu<=ni2+1:
            print('Yes')
        else:
            print('No')
    else:
        if kisu<=ni2:
            print('Yes')
        else:
            print('No')
resolve()

Submission status: Accepted

Solution code:
N = int(input())

c1, c2, c4 = 0, 0, 0
a = list(map(int, input().split()))

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

if c2:
    print("Yes" if c4 >= c1 else "No")
else:
    print("Yes" if c4 and c4 + 1 >= c1 else "No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
s1 = [0]*n
s2 = [0]*n
s4 = [0]*n
for i in range(n):
    if a[i]%4 == 0:
        s4[i] = 1
    elif a[i]%2 == 0:
        s2[i] = 1
    else:
        s1[i] = 1
S1 = sum(s1)
S2 = sum(s2)
S4 = sum(s4)
if n >= 3:
    if S2 >= 1:
        if S1 + 1 <= S4 + 1:
            print("Yes")
        else:
            print("No")
    else:
        if S1 <= S4 +1:
            print("Yes")
        else:
            print("No")
else:
    if (a[0]*a[1])%4 == 0:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

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

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

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

cnt_4 = 0
for i in a:
    if i % 4 == 0:
        cnt_4 += 1

if cnt_4*2 + 1 >= n:
    print("Yes")
else:
    if cnt_4*2 + cnt_2 >= n:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

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

cnt_multiple_2 = 0
cnt_multiple_4 = 0
cnt_others     = 0

for i in range(len(a_list)):
    if a_list[i] % 4 == 0:
        cnt_multiple_4 += 1
        continue
    if a_list[i] % 2 == 0:
        cnt_multiple_2 += 1
        continue
    cnt_others += 1

if cnt_multiple_2 > 0:
    if cnt_others > cnt_multiple_4:
        print('No')
    else:
        print('Yes')
else:
    if cnt_others-1 > cnt_multiple_4:
        print('No')
    else:
        print('Yes')

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
a = list(map(int, readline().split()))
cnt = 0
memo = 0
for aa in a:
    if aa % 4 == 0:
        cnt += 1
    elif aa % 2 == 1:
        memo += 1
print('Yes' if (cnt >= memo - 1 and cnt + memo == n) or cnt >= memo else 'No')

Submission status: Accepted

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

cnt_0 = 0
cnt_2 = 0
cnt_4 = 0

for i in range(N):
    if a[i] % 4 == 0:
        cnt_4 += 1
    elif a[i] % 2 == 0:
        cnt_2 += 1
    else:
        cnt_0 += 1

if cnt_4 < cnt_0 - 1:
    print("No")
    exit()

if cnt_2 == 0:
    if cnt_4 >= cnt_0 - 1:
        print("Yes")
    else:
        print("No")
else:
    if cnt_4 >= cnt_0:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

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

Submission status: Accepted

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

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

if cnt1 - cnt4 > 1:
    print("No")
elif cnt1 - cnt4 == 1:
    if cnt2 == 0:
        print("Yes")
    else:
        print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
a = int(input())
ar = list(map(int,input().split(" ")))
k = 0
g = 0
f = 0
for r in ar:
    if r % 4 == 0:
        f += 1
    elif r % 2 == 0:
        g += 1
    else:
        k += 1
if k - f > 1:
    print("No")
elif k - f == 1:
    if g == 0:
        print("Yes")
    else:
        print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions
import functools
import copy

# import heapq
# from collections import deque
# import decimal

sys.setrecursionlimit(10000001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===

def main():
    n = ni()
    a = na()

    result = {1: 0, 2: 0, 4: 0}

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

    flg = False
    if result[2] == 0:
        if result[4] >= result[1] - 1:
            flg = True
    else:
        if result[4] >= result[1]:
            flg = True

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
c1 = c2 = 0
for x in a:
    if x % 4 == 0:
        c1 += 1
    elif x % 2 == 0:
        c2 += 1
print(("Yes" if c1 + int(c2 / 2) >= int(n / 2) else "No"))

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
odd, four = 0, 0
for a in A:
    if a & 1 == 1: odd += 1
    if a & 3 == 0: four += 1
# 4の倍数の個数 == 奇数の個数
# すべて偶数
if odd == 0 or four >= odd or (four == odd - 1 and four + odd == N):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
f2 = 0
f4 = 0
f_another = 0
for a in A:
    #c = collections.Counter(prime_factorize(a))
    if a%4 == 0:
        f4 += 1
    elif a%2 == 0:
        f2 += 1
    else:
        f_another +=1
if n%2 == 0 and (n -f2//2 *2 -f4 *2 <= 0):
    print('Yes')
elif n%2 == 1 and (n -f2//2 *2 -f4 *2 <= 1):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import sys
import os

def file_input():
    f = open('ARC080/input.txt', 'r')
    sys.stdin = f

def main():
    #file_input()
    N=int(input())
    a_li=list(map(int, input().split()))

    # four=0
    odd=0
    for i in a_li:
        if i%4==0:
            odd-=1
        if i%2!=0:
            odd+=1
    else:
        if (N%2==0 and odd<=0) or (N%2!=0 and odd<=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
for i in a:
    if i % 4 == 0:
        count +=2
    elif i %2 == 0 :
        count+=1
    else:
        continue

if len(a)%2 == 0:
    if count >=len(a):
        print("Yes")
    else:
        print("No") 
else:
    if count >= len(a)-1:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter


N = int(input())
c = Counter(map(lambda x: int(x) % 4, input().split()))
print('Yes') if sum([c[1], c[2] > 0, c[3]]) <= c[0] + 1 else print('No')

Submission status: Accepted

Solution code:
from collections import defaultdict


N = int(input())
counter = defaultdict(int)
for a in map(int, input().split()):
    if a % 4 == 0:
        counter[2] += 1
    elif a % 2 == 0:
        counter[1] += 1
    else:
        counter[0] += 1
if counter[1] == 0:
    print('Yes') if counter[0] <= counter[2] + 1 else print('No')
else:
    print('Yes') if counter[0] <= counter[2] else print('No')

Submission status: Accepted

Solution code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))
n = ii()
A = iil()

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

if odd > mulof4+1:
    print('No')
else:
    if odd < mulof4+1:
        print('Yes')
    else:
        print("Yes" if even == 0 else 'No')

Submission status: Accepted

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

x, y, z = 0, 0, 0
for v in a:
    if v % 4 == 0:
        x += 1
    elif v % 2 == 0:
        y += 1
    else:
        z += 1

if x < z:
    if (z - x == 1) & (y == 0):
        print('Yes')
    else:
        print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
from collections import defaultdict

import sys
sys.setrecursionlimit(10**6)
ii = lambda: int(input())
mis = lambda: map(int,input().split())
lmis = lambda: list(mis())
INF = float('inf')

def main():
    n=ii()
    a=lmis()
    cnt4,cnt2,cntodd=0,0,0
    flag=False
    for val in a:
        if val%4==0:
            cnt4+=1
            continue
        if val%2==0:
            cnt2+=1
            continue
        cntodd+=1
    if cnt4-cntodd>=0:flag=True
    elif cnt4-cntodd==-1 and cnt2==0:flag=True
    print('Yes' if flag else 'No')
    

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def resolve():
    '''
    code here
    '''
    N = int(input())
    A_list = [int(item) for item in input().split()]

    cnt_list = [0,0]

    for i in A_list:
        if i % 4 == 0:
            cnt_list[1] += 1
        elif i % 2 == 0:
            cnt_list[0] += 1

    is_flag = False

    if N - cnt_list[1] <= cnt_list[1]+1:
        is_flag = True
    
    else:
        if N - sum(cnt_list) <= cnt_list[1]:
            is_flag = True


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


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
a4 = 0
a2 = 0
a1 = 0

for a in A:
    if a % 4 == 0:
        a4 += 1
    elif a % 2 == 0:
        a2 += 1
    else:
        a1 += 1

if a2 == 0 and a1 <= a4 + 1:
    print('Yes')
elif a4 >= a1:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

# n0, n1, n2 = 0, 0, 0

# def how_many_dev_by_2(x, cnt=0):
#     if x%2 == 0:
#         x /= 2
#         cnt += 1
#         return how_many_dev_by_2(x, cnt)
#     else:
#         return cnt
#
# for a in al:
#     a_cnt = how_many_dev_by_2(a)
#     if a_cnt == 0:
#         n0 += 1
#     elif a_cnt == 1:
#         n1 += 1
#     else:
#         n2 += 1
#
# if n2 + 1 >= n0 + n1//2:
#     print('Yes')
# else:
#     print('No')

n0, n2, n4 = 0, 0, 0

for a in al:
    if a % 4 == 0:
        n4 += 1
    elif a % 2 == 0:
        n2 += 1
    else:
        n0 += 1

print('Yes' if n4+1 >= n0+n2%2 else 'No')

Submission status: Accepted

Solution code:
def main():
    N = int(input())  # 文字列または整数(一変数)
    a = list(map(int, input().split()))  # 整数のリスト

    a0 = 0
    a1 = 0
    a2 = 0

    for e in a:
        if e % 4 == 0:
            a2 += 1
        elif e % 2 == 0:
            a1 += 1
        else:
            a0 += 1

    if a1 == 0 and a2 >= a0-1:
        print("Yes")
        return

    if a0 <= a2:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

n = int(input())
s = [int(i)%4 for i in sys.stdin.read().split()]
s0 = s.count(0)
s2 = s.count(2)
if n - s0 - s2 <= s0 + (s2 == 0):
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,(input().split())))
n1,n2,n4 = 0,0,0
for i in range(N):
    if a[i]%2 != 0:
        n1 += 1
    elif a[i]%4 == 2:
        n2 += 1
    else:
        n4 += 1

if n4*2 + 1 >= N:
    print("Yes")
else:
    if n4*2 + n2 >= N:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:

N = int(input())
A = list(map(int,input().split()))
X = 0
Y = 0
Z = 0
for i in A:
    if i % 4 == 0:
        X += 1
    elif i % 2 == 1:
        Y += 1
    elif i % 2 == 0:
        Z = 1
Y+=Z
# print(X,Y,Z)
if X+1 >= Y:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
n = int(input())

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

num_4 = 0
num_2 = 0
num_odd = 0

for i in A:
    if i % 4 == 0:
        num_4 += 1
    elif i % 2 == 0:
        num_2 += 1

num_odd = n - num_2 - num_4

if n - num_4*2 == num_2 or n - num_4 * 2 == 1 or num_2 > n//2 or num_4 + 1 > n//2:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:

def rd(n):
    if n==0:
        return input("")
    if n==1:
        return int(input())
    if n==2:
        return map(int,input().split())
    if n==3:
        return list(map(int,input().split()))
def solve():
    n=rd(1)
    A=rd(3)
    d={0:0,1:0,2:0}
    for i in range(n):
        if(A[i]%4==0):
            d[2]+=1
        elif(A[i]%2==0):
            d[1]+=1
        else:
            d[0]+=1
    if((d[0]>d[2]+1) or (d[0]==d[2]+1 and d[1]!=0)):
        print('No')
    else:
        print('Yes')

solve()

Submission status: Accepted

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

for i in a:
    if i%4 == 0:
        cnt_four += 1
    elif i%4 == 2:
        cnt_two += 1
cnt_odd = len(a) - cnt_four - cnt_two

if cnt_two >= 1:
    cnt_odd += 1

if cnt_four >= cnt_odd - 1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

if mul2:
    if odd <= mul4:
        print("Yes")
    else:
        print("No")
else:
    if odd <= mul4 + 1:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/arc080/tasks/arc080_a

n = int(input())
nums = [int(i) for i in input().split()]

fours = 0
twos = 0
odd = 0
for num in nums:
    if num % 4 == 0:
        fours += 1
    elif num % 2 == 0:
        twos += 1
    else:
        odd += 1

if twos == 0 and fours + 1 >= odd:
    print('Yes')
elif fours >= odd:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

odds = 0
fours = 0
evens = 0

for a in A:
    if a % 4 == 0:
        fours += 1
    elif a % 2 == 0:
        evens += 1
    else:
        odds += 1

if evens == 0:
    if odds <= fours + 1:
        print("Yes")
    else:
        print("No")
else:
    if odds <= fours:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

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

dic = {4: 0, 2: 0, 1: 0}
for i in A_list:
    if i % 4 == 0:
        dic[4] += 1
    elif i % 2 == 0:
        dic[2] += 1
    else:
        dic[1] += 1
dic[4] += dic[2] // 2

if len(A_list) // 2 <= dic[4]:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
def myAnswer(N:int,A:list) -> str:
   counter4 = 0
   counter2 = 0
   for a in A:
      if(a % 4 == 0):
         counter4 += 1
      elif(a % 2 == 0):
         counter2 += 1
   if(counter4 >= N//2):
      return "Yes"
   elif(counter4 >= (N-(counter2//2)*2)//2):
      return "Yes"
   else:
      return "No"


def modelAnswer():
   return
def main():
   N = int(input())
   A = list(map(int,input().split()))
   print(myAnswer(N,A[:]))
if __name__ == '__main__':
   main()

Submission status: Accepted

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

cnt = 0
for a in A:
    if a % 4 == 0: cnt += 1
    elif a % 2 == 0: cnt += 0.5
print("Yes" if cnt >= N // 2 else "No")

Submission status: Accepted

Solution code:
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
N = int(input())
arrA = list(map(int,input().split()))
arrA = np.array(arrA)

arrA = arrA % 4
num4s = len(arrA[arrA==0])
num2s = len(arrA[arrA==2])
num13s = len(arrA) - num2s - num4s

if num13s - num4s == 0:
    ans = "Yes"
elif num13s - num4s == 1 and num2s>0:
    ans = "No"
elif num13s - num4s > 1:
    ans = "No"
else:
    ans = "Yes"
print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))

Submission status: Accepted

Solution code:
c_0, c_1, c_2, N = 0, 0, 0, int(input())
for i in map(int, input().split()):
    if i % 4 == 0: c_2 += 1
    elif i % 2 == 0: c_1 += 1
    else: c_0 += 1
if c_1 == 0: result = "Yes" if c_2 >= c_0 - 1 else "No"
else: result = "Yes" if c_2 >= c_0 else "No"
print(result)

Submission status: Accepted

Solution code:
import math
n = int(input())
li = list(map(int,input().split()))

all_li = []
two_count = 0
zero_count = 0
for l in li:
    count = 0
    if l % 2 == 0:
        count += 1
    if l % 4 == 0:
        count += 1
        two_count += 1
    if count == 0:
        zero_count += 1
    all_li.append(count)
#print(all_li)
#[0, 1, 2]
if two_count == 0:
    #print(list(set(all_li)))
    if list(set(all_li)) == [1]:
        print('Yes')
    else:
        print('No')
elif zero_count == 0:
    print('Yes')
else:
    if zero_count > two_count +1:
        print('No')
    elif zero_count == two_count + 1:
        if len(all_li) - zero_count - two_count == 0:
            print('Yes')
        else:
            print('No')
    else:
        print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
n_list = list(map(int,input().split()))
count = 0
for i in n_list:
    if i % 4 == 0:
        count += 1
    elif i%2 == 0:
        count += 0.5
if count >= n//2:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

print("Yes" if l[2]+1>=l[0]+int(1<=l[1]) else "No")