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()))

mod4 = 0
mod2 = 0
other = 0
counter = {0:0, 1:0, 4:0}
for n in A:
    count = 0
    while n % 2 == 0:
        count += 1
        n //= 2
        if count >= 2:
            break
    if count == 0:
        counter[0] += 1
    elif count == 1:
        counter[1] += 1
    else:
        counter[4] += 1
ans = None
if counter[1] == 0:
    if counter[4] + 1 >= counter[0]:
        ans = 'Yes'
    else:
        ans = 'No'
else:
    if counter[4] >= counter[0]:
        ans = 'Yes'
    else:
        ans = 'No'
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

def main():
    N = int(input())
    an = sorted(map(int, input().split(' ')))
    
    # N = 6
    # an = [1, 10, 100]
    # an = [2, 7, 1, 8, 2, 8]
    # an = [1, 2, 3, 4]
    # an = [1, 4, 1]
    # an = [846579189, 56223110]
    
    out = []
    
    for a in an:
        if a % 2 != 0:
            out.append('A')
        elif a % 4 != 0:
            out.append('B')
        else:
            out.append('C') 
    # print(out)
    counter = Counter(out)
    # print(counter)
    num_A = counter['A']
    num_B = counter['B']
    num_C = counter['C']
    # print(num_A, num_B, num_C)
    
    if num_A == 1 and num_B == 1 and num_C ==0:
        print('No')
        return
    
    if not ('B' in out):
        if (num_C + 1) >= num_A:
            print('Yes')
            # return
        else:
            print('No')
            # return
    else:
        if num_B >= num_A:
            print('Yes')
        else:
            print('No')
        
        
        
        
    
main()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(lambda x: int(x)%4 , input().split()))

p = a.count(0)
q = a.count(2)
r = n-p-q

if r > p:
    if r -p == 1 and q == 0:
        print("Yes")
    else:
        print("No")
else:
    print("Yes")

Submission status: Accepted

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

even = 0
multiple4 = 0
for a in A:
    if a % 4 == 0:
        multiple4 += 1
    elif a % 2 == 0:
        even += 1

N -= ((even//2)*2)+multiple4
if N <= multiple4+1:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(10 ** 9)


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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
cnt_4 = 0
cnt_2 = 0
remaining_cnt_2 = 0
cnt_other = 0

for x in a:
    if x % 4 == 0:
        cnt_4 += 1
    elif x % 2 == 0:
        cnt_2 += 1
    else:
        cnt_other += 1

remaining_cnt_2 = cnt_2 % 2

if cnt_2 > 0:
    if cnt_4 >= cnt_other:
        print("Yes")
    else:
        print("No")
else:
    if cnt_4 + 1 >= cnt_other:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
num2=0
num4=0
kisu=0
for i in range(n):
    if a[i]%4==0:
        num4+=1
    elif a[i]%2==0:
        num2+=1
    else:
        kisu+=1
flag=True
if num4==0:
    if 0<kisu:
        flag=False
else:
    if num2==0:
        if not(kisu<=num4+1):
            flag=False
    else:
        if not(kisu<=num4):
            flag=False
print("Yes" if flag else "No")

Submission status: Accepted

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

Submission status: Accepted

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

### それぞれの数字が2の素因数をいくつ持つかを返す
def num_factor2(num):
    result = 0
    while num % 2 == 0:
        result += 1
        num /= 2
    return result

a_factor2 = map(num_factor2, a)

num_factor2_zero = 0
num_factor2_one = 0
num_factor2_twoormore = 0

for a_ in a_factor2:
    if a_ == 0:
        num_factor2_zero += 1
    elif a_ == 1:
        num_factor2_one += 1
    elif a_ >= 2:
        num_factor2_twoormore += 1

if num_factor2_zero <= num_factor2_twoormore or (num_factor2_zero <= num_factor2_twoormore + 1 and num_factor2_one == 0):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(lambda x:int(x)%4,input().split()))
b0=a.count(0)
b1=a.count(1)+a.count(3)
b2=a.count(2)
if b2 > 0:
    print('Yes' if b0 >= b1  else 'No')
else:
    print('Yes' if b0 >=b1-1 else 'No')

Submission status: Accepted

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

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

n -= c2
c2 %= 2
n += c2
f = n // 2

if c4 >= f:
    print('Yes')
    quit()
else:
    print('No')

Submission status: Accepted

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

c1 = 0
c2 = 0
c4 = 0
for i in range(n):
    if a[i] % 4 == 0:
        c4 += 1
    elif a[i] % 2 == 0:
        c2 += 1
    elif a[i] == 1:
        c1 += 1
if c2 == n:
    print('Yes')
    quit()

n -= c2
c2 %= 2
n += c2
f = n // 2

if c4 >= f:
    print('Yes')
    quit()
else:
    print('No')

Submission status: Accepted

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

num_odd = 0
num_4 = 0
num_2 = 0
for a in A:
    if a % 4 == 0:
        num_4 += 1
    elif a % 2 == 0:
        num_2 += 1
    else:
        num_odd += 1

if num_odd <= num_4:
    print("Yes")
elif num_odd == num_4 + 1 and num_2 == 0:
    print("Yes")
else:
    print("No")

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 2*four+two>=n or 2*four+1>=n:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
cnt4 = 0
cnt2= 0
for x in a:
    if x%4 == 0:cnt4 +=1
    elif x%2 == 0:cnt2 +=1
odd = n-cnt4 - cnt2
ok = cnt4+1 >= odd
if cnt4+1 == odd:
    if cnt2 >0:ok = False
    
 

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

Submission status: Accepted

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

cnt4 = 0
cnt2 = 0
cnt_not = 0
for num in a:
    if num % 4 == 0:
        cnt4 += 1
    elif num % 2 != 0:
        cnt_not += 1
    else:
        cnt2 += 1
        
if 0 < cnt2:
    r = 1
else:
    r = 0

#print(cnt_not, r, cnt4)
if cnt_not + r  < cnt4 + 2:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
c2 = sum([a % 2 == 0 and a % 4 != 0 for a in A])
c4 = sum([a % 4 == 0 for a in A])
cp = sum([a % 2 != 0 for a in A])
print('Yes' if cp+c4 == N and cp - c4 ==
      1 or cp <= c4 and c4+cp+c2 == N else 'No')

Submission status: Accepted

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

a4, a4n, a2 = 0, 0, 0
for ai in a:
  if ai % 4 == 0:
    a4 += 1
  elif ai % 2 == 0:
    a2 += 1
  else:
    a4n += 1

if a2 != 0:
  print("Yes" if a4 + 1 >= a4n+1 else "No")

else:
  print("Yes" if a4 + 1 >= a4n else "No")

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
a = [int(i) for i in input().split()]
for i in range(N):
    if a[i] % 4 == 0:
        a[i] = 0
    elif a[i] % 4 == 2:
        a[i] = 2
    else:
        a[i] = 1
counts = dict(Counter(a))
flag = False
if 1 in counts:
    if 0 in counts:
        if 2 in counts:
            if counts[0] >= counts[1]:
                flag = True
        
        else:
            if counts[0] == counts[1]-1:
                flag = True
        
else:
    if 2 in counts:
        if counts[2] >= 2:
            flag = True
        else:
            if 0 in counts:
                flag = True
                
    else:
        if 0 in counts:
            flag = True
                

    
print('Yes' if flag==True else 'No')

Submission status: Accepted

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

num_four = 0
num_two = 0
num_odd = 0
for i in range(N):
    if A[i] % 4 == 0:
        num_four += 1
    elif A[i] % 2 == 0:
        num_two += 1
    else:
        num_odd += 1

# print(num_four, num_two, num_odd)

if num_two != 0:
    ans = 'Yes' if num_four + 1 >= num_odd + 1 else 'No'
else:
    ans = 'Yes' if num_four + 1 >= num_odd else 'No'
print(ans)

Submission status: Accepted

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

num_four = 0
num_two = 0
num_odd = 0
for i in range(N):
    if A[i] % 4 == 0:
        num_four += 1
    elif A[i] % 2 == 0:
        num_two += 1
    else:
        num_odd += 1

# print(num_four, num_two, num_odd)

v = num_four * 2
if num_two <= 1:
    v += 1
if num_two >= 2:
    v += num_two
ans = 'Yes' if v >= N else 'No'
print(ans)

# 2 2 2 2 4 o 4 o 4 ... o 4 o
# o 4 o 4 .... o 4 o

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int,input().split()))
count1 = len([x for x in l if x%2 != 0])
count2 = len([x for x in l if (x%4 != 0) and (x%2 == 0)])
count4 = len([x for x in l if x%4 == 0])
print ("Yes") if (n - (count4*2) <= count2) or count4 >= n//2 else print ("No")

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int,input().split()))
four =0
two =0
odd = 0
       
for num in a:
  if num%4==0:
    four +=1
  if num%2==0:
    two += 1
       
two -= four
odd=N-four-two       
#print(four,two,odd)

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

#if four>=N//2:
#  print("Yes")
#else:
#  if two >=imp:
#    print("Yes")
#  else:
#    print("No")

Submission status: Accepted

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

odd=0
ni=0
si=0
for x in a:
    if x%4==0:
        si+=1
    elif x%2==0:
        ni+=1
    else:
        odd+=1
ni=ni%2
if odd+ni<=si+1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

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

if (num2 != 0) & (num4 >= num1):
    print('Yes')
elif (num2 == 0) & (num4 + 1 >= num1):
    print('Yes')
else:
    print('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==0:
    cnt1+=1
  else:
    if a[i]%2==0:
      cnt2+=1
if cnt2%2==0:
  pass
else:
  cnt2-=1
num=n-cnt2
if num%2==0:
  if cnt1>=num//2:
    print('Yes')
  else:
    print('No')
else:
  if cnt1>=(num-1)//2:
    print('Yes')
  else:
    print('No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import deque
n = int(input())
a = list(map(int, input().split()))
odd = deque([])
even = deque([])
even2 = deque([])
for i in a:
    if i % 4 == 0:
        even2.append(i)
    elif i % 2 == 0:
        even.append(i)
    else:
        odd.append(i)
if len(odd)-1 <= len(even2) and len(even) == 0:
    print("Yes")
elif len(odd) <= len(even2):
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N =int(input())
A = [a%4 for a in list(map(int,input().split()))]
c0 = A.count(0)
c1 = A.count(1)
c2 = A.count(2)
c3 = A.count(3)
if c2>=2:
  if c1+c3<=c0:
    print("Yes")
  else:
    print("No")
else:
  if c1+c2+c3-1<=c0:
    print("Yes")
  else:
    print("No")

Submission status: Accepted

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

checker = []
for a in A:
    cnt = 0
    if a % 2 == 0:
        cnt = 1
    if a % 4 == 0:
        cnt += 1
    checker.append(cnt)

count_2 = checker.count(2)
count_1 = checker.count(1)
count_0 = checker.count(0)

if (count_0 <= count_2+1 and count_0 + count_1 <= count_2 + 1) or count_0 == count_2:
    answer = 'Yes'
else:
    answer = 'No'

print(answer)

Submission status: Accepted

Solution code:

def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    for i in range(N):
        A[i] = A[i] % 4
        if A[i] == 3:
            A[i] = 1
    if A.count(2):
        if A.count(1) + 1 - A.count(0) <= 1:
            print('Yes')
        else:
            print('No')
    else:
        if A.count(1) - A.count(0) <= 1:
            print('Yes')
        else:
            print('No')


resolve()

Submission status: Accepted

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

for i in range(N):
  if a[i]%4 == 0:
    count4 += 1
  elif a[i]%2 == 0:
    count2 += 1


if count2 == 0:
  ans = 2*count4 + 1
else:
  ans = 2*count4 + count2

if ans >= N:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
def main():
    n, *a = map(int, open(0).read().split())
    b = list(map(lambda x: x % 4, a))
    f, g = b.count(0), b.count(2)
    h = g % 2
    print('Yes' if (n - f - g + h) - 1 <= f else 'No')


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

print('Yes' if d[2] >= d[0] else 'No')

Submission status: Accepted

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

Submission status: Accepted

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

n = int(input())
a = list(map(int, input().split()))
cnt_0 = 0
cnt_2 = 0
for i in range(n):
    if a[i] % 4 == 0:
        cnt_2 += 1
    elif a[i] % 2 == 1:
        cnt_0 += 1
if (cnt_2 >= cnt_0 - 1 and cnt_2 + cnt_0 == n) or cnt_2 >= cnt_0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import sys
from collections import Counter
n = int(input())
a_ls = [int(i) for i in sys.stdin.readline().split()]
ct = Counter()
for a in a_ls:
    if a % 4 == 0:
        ct.update([2])
    elif a % 2 == 0:
        ct.update([1])
    else:
        ct.update([0])
if ct[1] == 0:
    if ct[2] >= ct[0] - 1:
        print("Yes")
    else:
        print("No")
else:
    if ct[2] >= ct[0]:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
N = int(input())
d = {0:0,1:0,2:0}
for a in list(map(int,input().split())):
  if a%2 == 0 :
    if a%4 == 0 :
      d[2]+=1
    else:
      d[1]+=1
  else:
    d[0]+=1

## 0と4だけの時はこれでok
if d[1] == 0:
  if d[0] <= d[2]+1:
    print("Yes")
  else:
    print("No")
else:
  if d[0] + (1 if d[1]>0 else 0 ) <= d[2]+1:
    print("Yes")
  else:
    print("No")

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
count_4=0
count_2=0
count_1=0
for i in A:
    if i%4==0:
        count_4+=1
    elif i%2==0:
        count_2+=1
    else:
        count_1+=1
if count_2<2:
    if count_1+count_2-1<=count_4:
        print("Yes")
    else:
        print("No")
else:
    if count_1<=count_4:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
def howmanytwo(m):
  ret=0
  while m%2==0:
    ret+=1
    m=m//2
  return ret

N=int(input())
A=[int(i) for i in input().split()]
evn=[howmanytwo(a) for a in A]
od=evn.count(0)
evev=0
for x in evn:
  if x>=2:
    evev+=1
if od+evev!=N:
  evev+=1
else:
  evev+=2
print('Yes' if od+1<=evev else 'No')

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()
n = int(input())
a = list(map(int, input().split()))
f = 0
even = 0
odd = 0

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

even %= 2
if f - even - odd < -1:
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
li = list(map(int,input().split()))
A = 0
B = 0
C = 0

for a in li:
  if a % 4 == 0:
    A += 1
  elif a % 2 == 0:
    B += 1
  else:
    C += 1
if B == 0:
  if C <= A + 1:
    print('Yes')
  else:
    print('No')
else:
  if C <= A:
    print('Yes')
  else:
    print('No')

Submission status: Accepted

Solution code:
#C - 4-adjacent
N = int(input())
A = list(map(int, input().split()))
tmp1 = 0
tmp2 = 0
tmp4 = 0

for i in range(N):
    if A[i] % 4 == 0:
        tmp4 += 1
    elif A[i] % 2 == 0:
        tmp2 += 1
    else:
        tmp1 += 1

if tmp2 == 0 and tmp4 >= tmp1-1:
    print("Yes")
elif tmp2 > 0 and tmp4 >= tmp1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

n, m = 0,0
for a in A:
    if not a % 4:
        n += 1
    if not a % 2:
        m += 1

m -= n
if 2 * n >= N-1:
    print('Yes')

elif 2*n + m >= N:
    print('Yes')

else:
    print('No')

Submission status: Accepted

Solution code:
n = int(input())
L = list(map(int,input().split()))
L4 = [x%4 == 0 for x in L]
L2 = [(x%2 == 0 and x%4 != 0) for x in L]
#print(sum(L2),sum(L4))
other = len(L) - sum(L2) - sum(L4)
if sum(L2) == 0:
    if other <= sum(L4)+1:
        print("Yes")
    else:
        print("No")
else:        
    if other <= sum(L4):
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
# import bisect
from collections import Counter, defaultdict, deque, namedtuple
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)



def main():
    n = int(input())
    a = list(map(int,ipti().split()))

    count_0 = 0
    count_2 = 0
    count_4 = 0

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

    if (count_0 + count_4) % 2 == 0:
        if count_4 >= count_0:
            print('Yes')
        else:
            print('No')
    else:
        if count_4 >= count_0:
            print('Yes')
        elif (count_4 + 1) == count_0:
            if count_2 == 0:
                print('Yes')
            else:
                print('No')
        else:
            print('No')

if __name__ == '__main__':
    main()

Submission status: Accepted

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

zero = 0
one = 0
two = 0

def divide_two(arg):
  c = 0
  while True:
    if c >= 2:
      break
    if arg % 2 != 0:
      break
    arg //= 2
    c += 1
  return c 

for i in a:
  counter = divide_two(i)
  if counter == 0:
    zero += 1
  if counter == 1:
    one += 1
  if counter >= 2:
    two += 1
    
if one == 0:
  if zero <= two+1:
    print('Yes')
    exit()
  else:
    print('No')
    exit()
    
else:
  if zero <= two:
    print('Yes')
    exit()
    
  else:
    print('No')
    exit()
    
    
print('No')

Submission status: Accepted

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

f=t=0
for x in X:
    if x % 4==0:
        f += 1
    elif x % 2==0:
        t += 1
if 2*f+1 >= N or 2*f+t>=N:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
from math import ceil
N=int(input())
a=list(map(int,input().split()))
c=0
e=0
d=0

for i in range(N):
    if a[i]%4==0:
        c=c+1
    if a[i]%2==1:
        e=e+1
    else:
        d=d+1

if (d-c)==0:
    if e<=c+1:
        print("Yes")
    else:
        print("No")
else:
    if e+1<=c+1:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
num_odd = 0
num_mul2 = 0
num_mul4 = 0
for a in A:
    if a % 4 == 0:
        num_mul4 += 1
    elif a % 2 == 0:
        num_mul2 += 1
    elif a % 2 == 1:
        num_odd += 1

ans = False
if num_mul2 == 0:
    if num_mul4 + 1>= num_odd:
        ans = True
else:
    if num_mul4 >= num_odd:
        ans = True
print('Yes' if ans else 'No')

Submission status: Accepted

Solution code:
import collections

n = int(input())
a = list(map(int, input().split()))
ax = []
for i in a:
    if (i % 4 == 0):
        t = 4
    elif (i % 2 == 0):
        t = 2
    else:
        t = 1
    ax.append(t)

ay = collections.Counter(ax)
if((ay[2] == 0 and ay[1] <= ay[4]+1) or(ay[2] != 0 and ay[1] <= ay[4])):
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

n1 = sum([1 if A % 2 != 0 else 0 for A in a])
n4 = sum([1 if A % 4 == 0 else 0 for A in a])
n2 = N - n1 - n4

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

Submission status: Accepted

Solution code:
N=int(input())
A=list(int(i)%4 for i in input().split())
b1=A.count(1)+A.count(3)
b2=A.count(2)
b4=A.count(0)
print('Yes' if ( (b2==0 and (b1<=b4+1)) or b1<=b4) else 'No')

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
d2 = 0
d4 = 0
for i in range(n):
    if A[i]%2==0 and A[i]%4!=0:
        d2 += 1
    elif A[i]%4==0:
        d4 += 1
n -= int(d2/2)*2
if n-1-d4<=d4:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

for i in range(N):
	if A[i]%4==0:
		A[i]=4
	elif A[i]%4!=0 and A[i]%2==0:
		A[i]=2
	else:
		A[i]=1
if A.count(2)==0:
	if A.count(4)+1<A.count(1):
		print("No")
	else:
		print("Yes")
else:
	if A.count(4)<A.count(1):
		print("No")
	else:
		print("Yes")

Submission status: Accepted

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

cnt=[0,0]#2,4の倍数の個数
for i in a:
    if i%4==0:
        cnt[1]+=1
    elif i%2==0:
        cnt[0]+=1

ans=n-cnt[0]-cnt[1]+1 if cnt[0]!=0 else n-cnt[1]
print('Yes' if ans<=cnt[1]+1 else 'No')

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    mul4 = len([a for a in A if a % 4 == 0])
    mul2 = len([a for a in A if a % 4 != 0 and a % 2 == 0])
    less = N - 2*mul4 - 1
    if less <= 0:
        print("Yes")
    elif less + 1 <= mul2:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

Submission status: Accepted

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

if t == 0:
    if N//2 <= s:
        print("Yes")
    else:
        print("No")
else:
    if (1+N-t)//2 <= s:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    A=LI()
    c = [0]*5
    for a in A:
        c[a%4]+=1
    if N//2<=c[0]:
        print("Yes")
        return 
    N-=c[0]*2
    print(["No","Yes"][N<=c[2]])
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
t = 0
f = 0
for x in a:
  if x % 4 == 0: f += 1
  elif x % 2 == 0: t += 1
if N == 1:
  if f: print("Yes")
  else: print("No")
  exit(0)
if N == t:
  print("Yes")
  exit(0)
if -(-(N - max(0, t - 1) - 1) // 2) <= f: print("Yes")
else: print("No")

Submission status: Accepted

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

two = 0
four = 0
for a in A:
    cnt = 0
    while a % 2 == 0:
        a //= 2
        cnt += 1
    if cnt == 1:
        two += 1
    elif cnt > 1:
        four += 1

rest = N - four - two
two_merge = 1 if two > 0 else 0
rest += two_merge


if rest - 1 <= four:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
odd=0
even=0
ev=0 #4の倍数
for i in a:
    if i%4==0:
        ev+=1
    elif i%2==0:
        even+=1
    else:
        odd+=1
even%=2
odd+=even
if odd>ev+1:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
# coding: utf-8
from fractions import gcd 
from functools import reduce
import sys
sys.setrecursionlimit(200000000)
from inspect import currentframe


# my functions here!
#標準エラー出力
def printargs2err(*args):
    names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' : '+repr(arg) for arg in args),file=sys.stderr)
def debug(x):
    print(x,file=sys.stderr)
def printglobals():
    for (symbol, value) in globals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
def printlocals():
    for (symbol, value) in locals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)


#入力（後でいじる）
def pin(type=int):
    return map(type,input().split())
#どっかで最悪計算量の入力データを用意する関数を作ろう？
"""
バケットで管理したかったけど数字が多いのでソートして同じ数を固めることに
"""
#solution:
#潜 影 蛇 手 ! !
N=int(input())
A=[(i%4) for i in pin()]
#print(A)
b=[0]*4
for j in A:
    b[j-1]+=1
#print(b)

print(["No","Yes"][(b[3]-b[0]-b[2]-(b[1]%2)+1>=0)])
#print([["NA","YYMM"],["MMYY","AMBIGUOUS"]][cMMYY][cYYMM])

Submission status: Accepted

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

cnt2 = 0
cnt4 = 0

for i in range(n):
    if a[i] % 2 == 0 and a[i] % 4 != 0:
        cnt2 += 1
    elif a[i] % 4 == 0:
        cnt4 += 1

n = n - cnt2
if cnt2 == 0:
    if n-cnt4 <= cnt4+1:
        print("Yes")
    else:
        print("No")
else:
    if n-cnt4 <= cnt4:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

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

Submission status: Accepted

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

x,y=0,0
for i in a:
 if i%4==0:
  x+=1
 if i%2==1:
  y+=1

z=n-y-x

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

Submission status: Accepted

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

cnt4 = 0
for i in range(N):
  a = List[i]
  if a%4 == 0:
    cnt4 += 1

cnt2 = 0
for i in range(N):
  a = List[i]
  if a%2 == 0:
    cnt2 += 1
cnt2 = int(cnt2 - cnt4)

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

Submission status: Accepted

Solution code:
N = int(input())
Alist = list(map(int, input().split()))
count_4x = 0
count_2x = 0
for A in Alist:
    if A % 4 == 0:
        count_4x += 1
    else:
        if A % 2 == 0:
            count_2x += 1

if ((count_4x + int(count_2x / 2)) >= (N // 2)):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
a4 = [i for i in a if i%4 == 0]
a2 = [i for i in a if i%2 == 0]
num4 = len(a4)
num2 = len(a2) - num4
num1 = N-num2-num4
if num2 == 0 and num4 == num1-1:
    print('Yes')
elif num1 > num4:
    print('No')
else:
    print('Yes')