Problem:


Score : 400 points

Problem Statement

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

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

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

Determine whether Snuke can achieve his objective.

Constraints

2 ≤ N ≤ 10^5

a_i is an integer.

1 ≤ a_i ≤ 10^9

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

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

Sample Input 1

3
1 10 100

Sample Output 1

Yes

One solution is (1, 100, 10).

Sample Input 2

4
1 2 3 4

Sample Output 2

No

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

Sample Input 3

3
1 4 1

Sample Output 3

Yes

The condition is already satisfied initially.

Sample Input 4

2
1 1

Sample Output 4

No

Sample Input 5

6
2 7 1 8 2 8

Sample Output 5

Yes



Sample input:
3
1 10 100


Sample output:
Yes

Submission status: Accepted

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

sys.setrecursionlimit(10000000)

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

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

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

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


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

    N = ii()
    A = il()

    cnt = 0
    for a in A:
        if a % 4 == 0:
            cnt += 1
        elif a % 2 == 0:
            cnt += .5
    print('Yes' if N // 2 <= int(cnt) else 'No')


if __name__ == '__main__':
    main()

Submission status: Accepted

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

sys.setrecursionlimit(10000000)

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

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

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

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


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

    N = ii()
    A = il()
    o, t, f = 0, 0, 0
    for a in A:
        if a % 4 == 0:
            f += 1
        elif a % 2 == 0:
            t += 1
        else:
            o += 1
    if t > 0:
        o += 1
    print('Yes' if o <= f + 1 else 'No')


if __name__ == '__main__':
    main()

Submission status: Accepted

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

n4 = 0  # 4の倍数の個数
nodd = 0 # 奇数の個数
for i in range(N):
    nodd += (a[i] % 2 == 1)
    n4 += (a[i] % 4 == 0)

ans = "Yes"
if nodd > (N + 1) // 2:
    ans = "No"
elif n4 < min(nodd, N // 2):
    ans = "No"

print(ans)

Submission status: Accepted

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

b = [0]*3

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

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



if b[2]  >= b[0]:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
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 four-one-two%2 >= -1: print("Yes")
else: print("No")

Submission status: Accepted

Solution code:
import sys
N=int(input())
A=list(map(int,input().split()))
a=len([i for i in A if i%4==0])
b=len([i for i in A if i%4==2])
if b==0:
  if a*2+1>=N:
    print("Yes")
    sys.exit()
  else:
    print("No")
    sys.exit()
if a*2+b>=N:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

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

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N = ii()
    a = list(mi())
    even = sum(1 for i in range(N) if a[i]%2==0)
    odd = sum(1 for i in range(N) if a[i]%2==1)
    four = sum(1 for i in range(N) if a[i]%4==0)

    if odd-four == 1:
        ans = (odd+four == N)
    elif odd <= four:
        ans = True
    else:
        ans = False

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
N = int(input())
a = list(map(int, input().split()))
C = [0] * 3
for ai in a:
    if ai % 4 == 0:
        C[2] += 1
    elif ai % 2 == 0:
        C[1] += 1
    else:
        C[0] += 1
while C[0] > 0:
    if C[2] > 0:
        C[0] -= 1
        C[2] -= 1
    else:
        if C[0] == 1 and C[1] == 0:
            print('Yes')
            sys.exit()
        else:
            print('No')
            sys.exit()
print('Yes')

Submission status: Accepted

Solution code:
_,*l=[int(i)%4 for i in open(0).read().split()]
c=l.count
print('YNeos'[c(0)+c(2)//2<len(l)//2::2])

Submission status: Accepted

Solution code:
input()
l=[int(i)%4 for i in input().split()]
c=l.count
print('YNeos'[c(0)+c(2)//2<len(l)//2::2])

Submission status: Accepted

Solution code:
n,*l=map(int,open(0).read().split())
d={1:0,2:0,4:0}
for i in l:
  if i%2: d[1]+=1
  elif i%4: d[2]+=1
  else: d[4]+=1
if d[2]: print('YNeos'[d[1]>d[4]::2])
else: print('YNeos'[d[1]-1>d[4]::2])

Submission status: Accepted

Solution code:
n=int(input())
lst=list(map(int,input().split()))
four=0
two=0
odd=0

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

if four>=odd:
    print("Yes")
elif four+1==odd:
    if two==0:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Submission status: Accepted

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

Submission status: Accepted

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

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

ans = "No"

if N - cnt4*2 <= 1:
    ans =  "Yes"
elif N - cnt4*2 > 1:
    if N - cnt4*2 <= cnt2:
        ans = "Yes"
elif N - cnt4*2 == N:
    if N == cnt2*2:
        ans = "Yes"

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(map(int,input().split()))
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N = i()
a = l()
num1 = 0
num2 = 0
num3 = 0
for i in range(N):
    if a[i]%4 == 0:
        num3 += 1
    elif a[i]%2 == 0:
        num2 += 1
    else:
        num1 += 1
if num3+1 < num1:
    print('No')
elif num3+1 == num1 and num2 != 0:
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
odd = []
even = []
four = []
for x in map(int,input().split()):
    if x % 4 == 0:
        four.append(x)
    elif x % 2 == 0:
        even.append(x)
    else:
        odd.append(x)
if len(four) >= len(odd):
    print("Yes")
elif len(four) == len(odd)-1 and len(even) == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n = int(input())
lst = list(map(int, input().split()))
dic = {0:0, 1:0, 2:0}
for i in range(n):
  if lst[i] % 4 == 0:
    dic[2] += 1
  elif lst[i] % 2 == 0:
    dic[1] += 1
  else:
    dic[0] += 1
pre = 2
for i in range(n):
  if pre == 2:
    if dic[0] >= 1:
      dic[0] -= 1
      pre = 0
    else:
      print('Yes')
      exit()
  else:
    if dic[2] >= 1:
      dic[2] -= 1
      pre = 2
    else:
      print('No')
      exit()
print('Yes')

Submission status: Accepted

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

# 4で割り切れる場合と、2で割り切れる場合、どちらでも割り切れない場合の値の数を求める
# どちらでも割り切れない場合の値は4で割り切れる値の場合との組み合わせで4の倍数の積になる
# 達成できるかの判定はどちらでも割り切れない値の数が、4で割り切れる値の数以下であった場合に成立する
b1 = b2 = b4 = 0
for i in range(n):
  if a[i]%4 == 0: b4 += 1
  elif a[i]%2 == 0: b2 += 1
  else: b1 += 1

# 2で割り切れる値が存在しない場合、
# どちらでも割り切れない値の数が、4で割り切れる値の数+1以下であった場合に成立する
if b2 == 0: b4 += 1 
  
if b1 <= b4: print("Yes")
else: print("No")

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int,input().split()))
p,q,r=0,0,0
for i in range(N):
  if a[i]%2==0:
    if a[i]%4==0:
      r+=1
    else:
      q+=1
  else:
    p+=1
if p-1<r:
  print('Yes')
elif p-1==r:
  if q==0:
    print('Yes')
  else:
    print('No')
else:
  print('No')

Submission status: Accepted

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

fcount=0
tcount=0

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

ocount=n-(fcount+tcount)

if fcount+tcount>=n:
    print("Yes")
elif ocount<=n//2 and ocount<=fcount:
    print("Yes")
elif n%2!=0 and fcount>=n//2:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
def main():
    n = int(input())
    a = list(map(int, read().split()))
    odd = 0
    div4 = 0
    div2 = 0
    for ae in a:
        odd += ae % 2 != 0
        div4 += ae % 4 == 0
        div2 += ae % 2 == 0 and ae % 4 != 0
    div2r = div2 % 2
    if odd +div2r  > div4 + 1:
        print('No')
    else:
        print('Yes')


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
A = tuple(map(int, input().split()))
c4 = 0
c2 = 0
cn = 0
for a in A:
    if a%4==0:
        c4 += 1
    elif a%2==0:
        c2 += 1
    else:
        cn += 1

if c2 == 0 or c2 == 1:
    if cn+c2 <= c4 + 1:
        print('Yes')
    else:
        print('No')
else:
    if cn <= c4:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
n, *a = map(int, open(0).read().split())
f = 0
t = 0
o = 0
for i in a:
    if i % 4 == 0:
        f += 1
    elif i % 2 == 0:
        t += 1
    else:
        o += 1
if f >= o - 1 and t == 0:
    print('Yes')
elif f >= o:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans1 = 0
ans2 = 0
ans3 = 0
for i in range(n):
    if a[i] % 4 == 0:
        ans1 += 1
    elif a[i] % 2 == 0:
        ans2 += 1
    else:
        ans3 += 1
if ans1 + 1 == ans3 and ans2 == 0:
    print("Yes")
elif ans1 >= ans3:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

b1 = 0
b2 = 0
b4 = 0
for i in range(n):
   if a[i] % 4 == 0:
      b4 += 1
   elif a[i] % 2 == 0:
      b2 += 1
   else:
      b1 += 1
if b2 == 0:
   b4 += 1
if b1 <= b4:
   print('Yes')
else:
   print('No')

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
f=0
t=0
z=0
for i in range(n):
    if a[i]%4==0:
        f+=1
    elif a[i]%2==0:
        t+=1
    else:
        z+=1
flg=False
if t==0 and z-1<=f:
    flg=True
if z<=f and t>0:
    flg=True
if flg:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

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

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

Submission status: Accepted

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

cnt = 0
cnt1 = 0
for i in range(len(a)):
    if(a[i]%4==0):
        cnt += 1
    elif(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())
x=list(map(int,input().split()))
a,b,c=0,0,0
ans='No'
for i in x:
  if i%4==0:
    a+=1
  elif i%2==0:
    b+=1
  else:
    c+=1
if n%2==1:
  if c-a==1:
    if b==0:
      ans='Yes'
  elif a>=c:
    ans='Yes'
else:
  if a>=c:
    ans='Yes'
print(ans)

Submission status: Accepted

Solution code:
N = input()
L = list(map(int,input().split()))
n=0
m=0
p=0
for a in range(int(N)):
  if L[a]%2 != 0:
    n+=1
  elif L[a]%2 == 0 and L[a]%4 != 0:
    m+=1
  else:
    p+=1
if int(N)%2==1 and (n>p+1 or p==0 and n==1):
  print("No")
elif int(N)%2==0 and n>p:
  print("No")
else:
  print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
b1 = 0
b2 = 0
b4 = 0
for i in range(n):
    c = 0
    while a[i] % 2 == 0:
        c += 1
        a[i] /= 2
    if c == 0:
        b1 += 1
    elif c == 1:
        b2 += 1
    else:
        b4 += 1
if b2 == 0:
    if b1 <= b4 + 1:
        print('Yes')
    else:
        print('No')
else:
    if b1 <= b4:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
count2 = 0
count4 = 0
for i in range(n):
    #２の倍数だが４の倍数でない
    if a[i]%2 == 0 and a[i]%4 != 0:
        count2 += 1
    #４の倍数
    elif a[i]%4 == 0:
        count4 += 1

if count4 != 0:
    count4 = count4*2

if count2 >= 2:
    count4 += count2-1

if count4 >= n-1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n = int(input())

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

t_4 = 0
t_2 = 0
for i in a:
  if i%4==0:
    t_4+=1
  elif i%2==0:
    t_2+=1
other = len(a)-t_4-t_2
if other <= t_4:
  print("Yes")
elif other == t_4 +1:
  if t_2 > 0:
    print("No")
    exit()
  else:
    print("Yes")
    exit()
else:
  print("No")

Submission status: Accepted

Solution code:
N = int(input())
a = list(input().split())
A = [int(a[i]) for i in range(N)]
count_4 = 0
count_2 = 0
count_o = 0

for i in range(N):
    if A[i] % 4 == 0:
        count_4 += 1
    elif A[i] % 2 == 0:
        count_2 += 1
    else:
        count_o += 1

if count_4 < count_o + (1 if count_2 >= 1 else 0) - 1:
    print('No')
else:
    print('Yes')

Submission status: Accepted

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

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

if n == two:
    print("Yes")
elif four/(n - two) >= 0.5:
    print("Yes")
elif four/(n - 1) >= 0.5:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N=int(input())

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

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

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

if lenS%2==0:

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

Submission status: Accepted

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

ok = four == no or (four+two) == N
ok = ok or ((four+no) == N and abs(four-no) <= 1)
if ok:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
a = [int(i) for i in input().split()]
def div2(t):
    count = 0
    while t % 2 == 0:
        count += 1
        t //= 2
    return count
b = np.array([div2(i) for i in a])
odd = len(b[b == 0])
four = len(b[b >= 2])
if odd == 0:
    print('Yes')
elif odd == n:
    print('No')
elif odd <= four or ((odd == four + 1) and (odd + four) == n):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N = int(input())
a_list = list(map(int, input().split()))
fours = []
twos = []
others = []

for a in a_list:
    if a % 4 == 0:
        fours.append(a)
    elif a % 2 == 0:
        twos.append(a)
    else:
        others.append(a)

if len(twos) > 0:
    if len(fours) - len(others) < 0:
        print('No')
    else:
        print('Yes')

else:
    if len(fours) - len(others) < -1:
        print('No')
    else:
        print("Yes")

Submission status: Accepted

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

N_list = [0] * 3

for i in range(N):
    num = A_s[i]
    
    if (num % 4 == 0):
        N_list[2] += 1
    elif (num % 2 == 0):
        N_list[1] += 1
    else:
        N_list[0] += 1

if (N_list[2] >= N_list[0]):
    ans = 'Yes'
elif (N_list[1] == 0 and N_list[2] + 1 == N_list[0]):
    ans = 'Yes'
else:
    ans = 'No'

print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())

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

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def SMI(): return input().split()
def SLI(): return list(input())

def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')

# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate

def solve():
    N = II()
    A = LI()

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

    j = four + two // 2
    # print(j)
    if N // 2 <= j:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
n = int(input())

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

cnt_1 = 0
cnt_2 = 0
for i in a:
    if i%4 == 0:
        cnt_1 += 1
    elif i%2 == 0:
        cnt_2 += 1
    
cnt_2 //=2

total = cnt_1 + cnt_2

if len(a)//2 <= total:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

c1 = 0
c2 = 0
c4 = 0

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

if c2 == 0:
  if c4 >= c1-1:
    print('Yes')
  else:
    print('No')
else:
  if c4 >= c1:
    print('Yes')
  else:
    print('No')

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *
		
N = INT()
a = LIST()

odd = 0
even_2 = 0
even_4 = 0
for x in a:
	if x%4 == 0:
		even_4 += 1
	elif x%2 == 0:
		even_2 += 1
	else:
		odd += 1

if even_4+1 == odd and even_2 == 0:
	print("Yes")
elif odd > even_4:
	print("No")
else:
	print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,*a = map(int, open(0).read().split())
b = [x for x in a if x % 4 == 0]
c = [x for x in a if x % 2 == 0]
d = [x for x in a if x % 2 == 1]
if len(b) >= len(a) // 2:
    print('Yes')
elif len(d) <= len(b):
    print('Yes')
elif len(c) == len(a):
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

count_4 = len([a for a in A if a % 4 == 0])
count_2 = len([a for a in A if a % 2 == 0]) - count_4
others = n - (count_4 + count_2)

ans = ""
if count_2 == 0:
    ans = "Yes" if others <= count_4 + 1 else "No"
else:
    ans = "Yes" if others <= count_4 else "No"
print(ans)

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 n%2==0:
    if c_4>=n//2:
        print("Yes")
    else:
        if c_2>=(n-c_4*2):
            print("Yes")
        else:
            print("No")
else:
    if c_4>=n//2:
        print("Yes")
    else:
        if c_2>=(n-c_4*2):
            print("Yes")
        else:
            print("No")

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

from itertools import permutations
from math import factorial, hypot

#############
# Main Code #
#############

N = getN()
A = getList()

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

if cnt4 * 2 + 1 >= N:
    print('Yes')
else:
    left = N - cnt4 * 2
    if cnt2 >= left:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    A = list(map(int, input().split()))
    n2 = sum([a % 2 == 0 for a in A])
    n4 = sum([a % 4 == 0 for a in A])
    nodd = n - n2
    n2 -= n4
    if nodd == n4 + 1:
        if n2 == 0:
            print('Yes')
        else:
            print('No')
    elif nodd <= n4:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
lis=LI()
cou1=0
cou2=0
cou4=0
for i in range(n):
    if lis[i]%4==0:
        cou4+=1
    elif lis[i]%2==0:
        cou2+=1
    else:
        cou1+=1
if cou4>=cou1:
    print("Yes")
elif cou4+1==cou1 and cou2==0:
    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 i in range(N):
    cnt=0
    if a[i]%2==0:
        cnt+=1
    if a[i]%4==0:
        cnt+=1
    
    if cnt==0:
        odd+=1
    elif cnt==1:
        two+=1
    else:
        four+=1

if odd>four:
    if two==0:
        if odd==four+1:
            print("Yes")
            exit()
    print("No")
else:
    print("Yes")

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in a:
  if i%4 == 0:
    count4 += 1
  if i%2 == 0:
    c += 1
only2 = c-count4
if only2 == 0 and count4 + 1 == len(a)-c:
  print('Yes')
elif count4 < len(a)-c:
  print('No')
else:
  print('Yes')

Submission status: Accepted

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

n4 = len(list(filter(lambda x: x % 4 == 0, n)))
no = len(list(filter(lambda x: x % 2 == 1, n)))
if n4 + no < N:
    no += 1

if no <= n4 + 1:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
kisu = 0
gusu = 0
num_4 = 0

for i in range(N):
    if a[i] % 2 == 1:
        kisu += 1
    elif a[i] % 4 == 0:
        num_4 += 1
    else:
        gusu += 1
if gusu != 0:
    kisu += 1

print('Yes' if kisu <= num_4+1 else 'No')

Submission status: Accepted

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

foud = 0
twod = 0

for i in range(n):
    if al[i] % 4 ==0:
        foud += 1
    elif al[i] % 2 ==0:
        twod += 1
        
if (foud*2+1)+max(0,(twod-1)) >=n:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import math

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

mul2 = 0
mul4 = 0
for i in s:
    if i%4 == 0:
        mul4 += 1
    elif i%2 == 0:
        mul2 += 1

if mul4 >= math.floor(n/2):
    print("Yes")
elif mul2 == n:
    print("Yes")
elif n-mul2-mul4-1+mul2%2 <= mul4:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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


if __name__ == '__main__':
    main()