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: Runtime Error

Solution code:
import sys


def main():
    args = sys.stdin.readline().split()
    N = int(args[0])
    A = map(int, input().split())

    non_factor_cnt = 0
    factor_of_two_cnt = 0
    factor_of_four_cnt = 0
    for num in A:
        remainder = num % 4
        if remainder != 0:
            if remainder == 2:
                factor_of_two_cnt += 1
            else:
                non_factor_cnt += 1
        else:
            factor_of_four_cnt += 1

    if len(A) <= 3 or (len(A) >= 4 and factor_of_four_cnt >= 2):
        if factor_of_four_cnt >= non_factor_cnt - 1:
            print('Yes')
            sys.exit()
    if factor_of_four_cnt >= non_factor_cnt: # + factor_of_two_cnt % 2:
        print('Yes')
        sys.exit()
    print('No')

main()

Submission status: Runtime Error

Solution code:
number = int(input())
list = map(int,input().split())
yon_num = 0
ni_num = 0
odd_num = 0
for num in list:
    if num%4 == 0:
        yon_num += 1
    elif num%2 == 0:
        ni_num +=1
    else:
        odd_num += 1

    if ni_num != 0:
        nibai = ni_num//2 + ni_num%2

if yon_num >= (odd_num + nibai  + yon_num) // 2 :
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

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

multi4 = lambda a: a % 4 == 0
multi4_count = sum(map(multi4, a_list))
multi2 = lambda a: a % 2 == 0
multi2_count = sum(map(multi2, a_list)) - multi4_count

max_N = multi4_count*2 + (multi4_count>0)) + multi2_count//2
print("No" if (N > max_N) else "Yes")

Submission status: Runtime Error

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

for j in range(N):
  if a[j]%2 == 1:
    Kisuu += 1
  elif a[j]%4 == 0:
    YonBaisuu += 1
  else :
    NiBaisuu +=1

  
if Kisuu == YonBaisuu:
  print('Yes')
else :
  if NIBaisuu == 0:
    print('Yes')
  else:
    print('No')

Submission status: Runtime Error

Solution code:
# coding: utf-8

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

if set([num% 2 for num in nums]) == {0}:
    print("Yes")
    exit(1)

a,b,c = 0,0,0
for elem in nums:
    if elem % 4 == 0 : a += 1  # 4の倍数
    else:
        b += 1  # 4の倍数じゃない

# あとづけ 
# 2の倍数かつnot４の倍数についても考える必要がある
c = 0
for elem in nums:
        if elem % 2 == 0 and elem % 4 != 0: c += 1

if N % 2 == 1:  # 奇数
    if b-c <= (N-c+1)/2 : print("Yes")
    else: print("No")
else:  # 偶数
    if b-c <= a : print("Yes")
    else: print("No")

Submission status: Runtime Error

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

for j in range(N):


  if a[0]%2 == 1:
    Kisuu += 1
    a.pop(0)
  elif a[0]%4 == 0:
    YonBaisuu += 1
    a.pop(0)
  else :
   a.pop(0)
   NiBaisuu += 1

if Kisuu == YonBaisuu:
  print('Yes')
else :
  if NIBaisuu == 0:
    print('Yes')
  else:
    print('No')

Submission status: Runtime Error

Solution code:
n = int(input())

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

for i in range(1, len(a)):
    ans = a[i-1] * a[i]
    if ans % 4 == 0:
        if i + 1 == len(a):
            print("Yes")
        else:
            continue

    else:
        if i != len(a)-1:
            for j in range(0, len(a)-1):
                kari = a[i]
                a[i] = a[i+j]
                if a[i-1] * a[i] % 4 == 0:
                    a[i+j] = kari
                    break
                else:
                    if i + j - 1 <= len(a)-1:
                        continue
                    else:
                        print("No")
        else:
            print("No")
            break

Submission status: Runtime Error

Solution code:
n = int(input())

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

for i in range(1, len(a)):
    ans = a[i-1] * a[i]
    if ans % 4 == 0:
        if i + 1 == len(a):
            print("YES")
        else:
            continue

    else:
        if i != len(a)-1:
            for j in range(0, len(a)-1):
                kari = a[i]
                a[i] = a[i+j]
                if a[i-1] * a[i] % 4 == 0:
                    a[i+j] = kari
                    break
                else:
                    if i + j - 1 <= len(a)-1:
                        continue
                    else:
                        print("NO")
        else:
            print("NO")
            break

Submission status: Runtime Error

Solution code:
#include <cstdio>
#include <algorithm>
#include <vector>
#include <iostream>
#include <numeric>
#include <cmath>
#include <set>

int main(){

    int n;
    scanf("%d",&n);
    int foge = n/2;
    int counter4 = 0;
    int counter2 = 0;
    for(int i=0;i<n;i++){
        int x;
        scanf("%d",&x);
        if(x%4 == 0){
            counter4 ++;
        }
        else if(x%2 == 0){
            counter2 ++;
        }
    }
    counter4 = counter4 + (counter2/2);
    if(counter4 >= foge){
        printf("Yes");
    }
    else{
        printf("No");
    }
}

Submission status: Runtime Error

Solution code:
N = int(input())
a_arr = input().split(' ')

for i in range(len(a_arr)):
    a_arr[i] = int(a_arr)

counter = {
        2n: 0,
        4n: 0,
        n: 0
}

for j in range(len(a_arr))
    if a_arr[j] % 4 == 0:
        counter['4n'] += 1
    elif a_arr[j] % 2 == 0:
        counter['2n'] += 1
    else:
        counter['n'] += 1

indicator = N - counter['2n']/2
if counter['n'] - counter['4n'] <= 1:
    print("Yes")
else:
    print("No")