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

Solution (Python):
input()
xs=list(map(int, input().split()))
 
f,t,z=0,0,0
for x in xs:
  if x % 4 == 0:
    f+=1
  elif x % 2 == 0:
    t += 1
  else:
    z += 1
z += 0<t
print('Yes' if z - 2 < f else'No')

Solution (Python):
import sys

n = int(input())

four = 0
odd = 0
two = 0

l = [int(x) for x in sys.stdin.readline().split()]

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

if four > 0:
	if four >= odd:
		print('Yes')
	elif odd - four == 1:
		if two == 0:
			print('Yes')
		else:
			print('No')
	else:
		print('No')
else:
	if odd > 0:
		print('No')
	else:
		if two >= 2:
			print('Yes')
		else:
			print('No')

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
gosa = 1.0 / 10**9
mod = 10**9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    n = I()
    a = LI()
    d = collections.defaultdict(int)
    for c in a:
        d[c%4] += 1

    d[1] += d[3]
    if d[2] == 1:
        d[1] += 1
    if (d[1] == 0) or (d[1] - (1 if d[2] < 2 else 0) <= d[0] and d[0] > 0):
        return 'Yes'

    return 'No'



print(main())

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
a,b,c = 0,0,0
for x in A:
    if x % 4 == 0:
        c += 1
    elif x % 2 == 0:
        b += 1
    else:
        a += 1

if a <= c:
    print("Yes")
else:
    if a - c == 1:
        if c > 0 and b == 0:
            print("Yes")
        else:
            print("No")
    else:
        print("No")

Solution (Python):
import sys
from sys import stdin,stdout
import bisect
N=input()
A=list(map(int,stdin.readline().strip().split(' ')))
count4=0
count1=0
for i in xrange(len(A)):
    if A[i]%4==0:
        count4+=1
    elif A[i]%2==1:
        count1+=1
if count4>=count1:
    if count4>0:
        print('Yes')
    else:
        if len(A)>1:
            print('Yes')
        else:
            print('No')
else:
    if count4<count1-1:
        print('No')
    elif count4==count1-1:
        if len(A)==count4+count1:
            print('Yes')
        else:
            print('No')
    else:
        print('No')

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

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

if count2==0:
    if count4+1>=count1: print("Yes")
    else: print("No")
else:
    if count4>=count1: print("Yes")
    else: print("No")

Solution (Python):
import numpy as np

def check4adjacent(N, a):
    a = np.array(map(int, a))
    count_4multiples = len(np.where(a % 4 == 0)[0])
    count_2multiples = len(np.where((a % 2 == 0) & (a % 4 != 0))[0])
    count_else = N - (count_4multiples + count_2multiples)
    if count_2multiples % 2 == 0:
        flag = 1
    else:
        flag = 0

    if (count_4multiples + flag >= count_else ):
        return "Yes"
    else:
        return "No"



if __name__ == "__main__":
    N = int(raw_input())
    a = raw_input().split()
    print(check4adjacent(N, a))

Solution (Python):
def four_adjacent():
	n = int(raw_input())
	a = map(int, raw_input().split(" "))
	odd_num = 0
	mod_four_mum = 0
	for item in a:
		if item%2!=0:
			odd_num+=1
		if item%4==0:
			mod_four_mum+=1
	if mod_four_mum>=odd_num:
		print "Yes"
	elif odd_num-mod_four_mum==1:
		if n==odd_num+mod_four_mum:
			print "Yes"
		else:
			print "No"
	else:
		print "No"


if __name__ == "__main__":
	four_adjacent()

Solution (Python):



import sys



def solve(N, a):
  n4 = len([v for v in a if v % 4 == 0])                
  n2 = len([v for v in a if v % 4 != 0 and v % 2 == 0]) 
  n1 = len([v for v in a if v % 2 != 0])                
  na = n4 + 1
  if n2 > 0: na -= 1
  return "Yes" if n1 <= na else "No"

def splitIntoNums(line):
  words = line.strip().split()
  return [int(w) for w in words]

while True:
  l1 = sys.stdin.readline()
  l2 = sys.stdin.readline()
  if not l1: break
  N, = splitIntoNums(l1)
  a  = splitIntoNums(l2)
  if len(a) != N: raise
  print(solve(N, a))

Solution (Python):
N = int(input())
x = list(map(int, input().split()))

for i in range(N):
    x[i]=(x[i]%4)

a=x.count(1)+x.count(3)
o=x.count(0)

if(o>=a):
    print('Yes')
    quit()

if(o==a-1):
    if(x.count(2)==0):
       print('Yes')
       quit()
     
print('No')


quit()

Solution (Python):
import sys
N=int(input())
l=map(int,input().split())
a,b,c=0,0,True
for i in l:
    if i%4==0:b+=1
    else:
        if i%2!=0:a+=1
        else:c=False

if a==0:
    print("Yes")
    sys.exit()
if c:
    if b==0:
        print("No")
        sys.exit()
    if b>=a-1:print("Yes")
    else:print("No")
else:
    if b>=a:print("Yes")
    else:print("No")

Solution (Python):
import copy

def spaceinput():
    return list(map(int,input().split(" ")))



N=int(input())
a=spaceinput()

count4=0
count2=0
countodd=0
for sa in a:
    if sa%4==0:
        count4+=1
    elif sa%2==0:
        count2+=1
    else:
        countodd+=1



x=["o","e4"]*count4
if count2>0:
    x.extend(["e2"]*count2)
else:
    x.extend(["o"])



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

Solution (Python):




n = int(input())
one = 0
two = 0
four = 0

for a in map(int,input().split()):
    if a%2 != 0: one+= 1
    elif a%4 != 0: two+= 1
    else: four+= 1

def no():
    print("No")
    exit()

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

Solution (Python):
import sys
from collections import deque
import copy

from math import *
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    input_raw = list(read_func().strip().split())
    count_even = 0
    count_odd = 0
    count_4adj = 0
    for i in range(N):
        a = int(input_raw[i])
        if (a % 4) == 0:
            count_4adj += 1
        elif (a % 2) == 0:
            count_even += 1
        else:
            count_odd += 1

    is_yes = False
    if count_even == 0:
        if count_4adj >= count_odd - 1:
            is_yes = True
    else:
        if count_4adj >= count_odd:
            is_yes = True

    if is_yes:
        print "Yes"
    else:
        print "No"



if __name__ == '__main__':
    main()

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

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

if count1 <= count4 or (count1 - count4 == 1 and count2 == 0):
    print('Yes')
else:
    print('No')

Solution (Python):
N = int(raw_input())
A = map(int, raw_input().split())

c = [0, 0, 0]
for a in A:
    if a % 4 == 0:
        c[2] += 1
    elif a % 2 == 0:
        c[1] += 1
    else:
        c[0] += 1
if c[2] >= c[0]:
    print "Yes"
elif c[2] == c[0] - 1  and c[1] == 0:
    print "Yes"
else:
    print "No"

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

mod_4 = 0
mod_2 = 0
for a_i in a:
    if a_i % 4 == 0:
        mod_4 += 1
    elif a_i % 2 == 0:
        mod_2 += 1

if mod_2 == 0:
    m = 2 * mod_4 + 1
else:
    m = 2 * mod_4 + mod_2

if m >= N:
    print('Yes')
else:
    print('No')

Solution (Python):
import sys
from collections import Counter




def read_int_list():
    return list(map(int, input().split()))


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


def solve():

    c = Counter()
    n = read_int()
    a = read_int_list()
    for x in a:
        if x % 2 == 1:
            c[0] += 1
        elif x % 4 == 2:
            c[1] += 1
        else:
            c[2] += 1
    if c[0] > c[2] + 1:
        return 'No'
    elif c[0] == c[2] + 1:
        if c[1] > 0:
            return 'No'
        else:
            return 'Yes'
    else:
        return 'Yes'


def main():
    res = solve()
    print(res)


if __name__ == '__main__':
    main()

Solution (Python):
if __name__ == '__main__':
    N = int(input())
    a = list(map(int, input().split()))
    odd_num = len([i for i in a if i % 2 == 1])
    four_divide_num = len([i for i in a if i % 4 == 0])

    if odd_num <= four_divide_num:
        print("Yes")
    else:
        if odd_num - 1 == four_divide_num and odd_num + four_divide_num == N:
            print("Yes")
        else:
            print("No")

Solution (Python):

INF = 10 ** 20
MOD = 10 ** 9 + 7


def II(): return int(input())
def ILI(): return list(map(int, input().split()))


def read():
    N = II()
    a = ILI()
    return N, a


def solve(N, a):
    n_odd = 0
    n_div_2 = 0
    n_div_4 = 0
    for _a in a:
        if _a % 2 == 1:
            n_odd += 1
        else:
            if _a % 4 == 0:
                n_div_4 += 1
            else:
                n_div_2 += 1

    ans = ""
    if n_div_2 == 0:
        if n_div_4 >= n_odd - 1:
            ans = "Yes"
        else:
            ans = "No"
    else:
        if n_div_4 >= n_odd:
            ans = "Yes"
        else:
            ans = "No"

    return ans


def main():
    params = read()
    print(solve(*params))


if __name__ == "__main__":
    main()

Solution (Python):

N = int(input())
A = [int(n) for n in input().split()]

x2 = sum([a%2!=0 for a in A])
o2x4 = sum([(a%2==0)&(a%4!=0) for a in A])
o4 = sum([a%4==0 for a in A])


if o2x4 == 0:
    if o4 + 1 >= x2:
        print("Yes")
    else:
        print("No")
else:
    if o4 >= x2:
        print("Yes")
    else:
        print("No")

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

def f(x):
    if x % 4 == 0:
        return 4
    elif x % 2 == 0:
        return 2
    return 1

c = [0] * 5

for i in xrange(n):
    c[f(a[i])] += 1

print 'Yes' if c[4] >= c[1] or (c[2] == 0 and c[4] + 1 == c[1]) else 'No'

Solution (Python):
n = int(raw_input())
a = map(int, raw_input().split())
cnt2 = 0
cnt4 = 0
for i in xrange(n):
    if a[i] % 4 == 0:
        cnt4 += 1
    elif a[i] % 2 == 0:
        cnt2 += 1
m = n - cnt4 - cnt2
if cnt2 == 0:
    if m - 1 <= cnt4:
        print "Yes"
    else:
        print "No"
else:
    if m <= cnt4:
        print "Yes"
    else:
        print "No"

Solution (Python):
n = int(input())
d = list(map(int, input().split()))
c = [0, 0, 0]
for x in d:
	if x % 4 == 0:
		c[2] += 1
	elif x % 2 == 0:
		c[1] += 1
	else:
		c[0] += 1


if c[0] - 1 <= c[2] and c[1] == 0:
	print("Yes")
elif c[0] > c[2]:
	print("No")
else:
	print("Yes")

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

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

if c4 == 0:
    if 0 < c1 + c2 % 2:
        print("No")
    else:
        print("Yes")
else:
    if c1 + c2 % 2 <= c4 + 1:
        print("Yes")
    else:
        print("No")

Solution (Python):
N=int(raw_input())
a=map(int,raw_input().split())
odd=even=four=0
for i in a:
    if i%2==1:
        odd+=1
    elif i%4==0:
        four+=1
    else:
        even+=1
flag=True
if even==0:
    if odd>four+1:
        flag=False
else:
    if odd>four:
        flag=False
print "Yes" if flag else "No"

Solution (Python):
import sys
input = sys.stdin.readline

N = int(input())
a = [int(i) for i in input().split()]

c = [0,0,0]

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

last = None

isPossible = True

while (sum(c)):
    mn = 0
    if len(b) and b[-1]==1:
        mn = 1
    if len(b) and b[-1]==0:
        mn = 2

    n = -1
    for i in range(mn, 3):
        if c[i]:
            n = i
            break
    if n==-1:
        isPossible = False
        break

    c[n]-=1
    b.append(n)

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

Solution (Python):
input()
a = b = c = 0
for i in raw_input().split():
	i = int(i)
	if i % 4 == 0:
		a += 1
	elif i % 2 == 0:
		b += 1
	else:
		c += 1

if a >= c or (b == 0 and a + 1 >= c):
	print "Yes"
else:
	print "No"

Solution (Python):



import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import re
import string

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

four = 0
two = 0
other = 0
for a in As:
    if a % 4 == 0:
        four += 1
    elif a % 2 == 0:
        two += 1
    else:
        other += 1

prev = 4

def use_other():
    global other, prev
    other -= 1
    prev = 0

def use_two():
    global two, prev
    two -= 1
    prev = 2

def use_four():
    global four, prev
    four -= 1
    prev = 4

def func():
    if prev == 4:
        if other > 0:
            use_other()
        elif two > 0:
            use_two()
        elif four > 0:
            use_four()
    elif prev == 2:
        if two > 0:
            use_two()
        elif four > 0:
            use_four()
        else:
            return False
    elif prev == 0:
        if four > 0:
            use_four()
        else:
            return False
    return True

ok = True
for n in range(N):
    ret = func()
    if not ret:
        ok = False
        break
if ok:
    print("Yes")
else:
    print("No")

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]

cnt4 = len([x for x in A if x % 4 == 0])
cnt2 = len([x for x in A if x % 2 == 0]) - cnt4
if 2 * cnt4 + cnt2 >= N or (N % 2 == 1 and cnt4 >= N // 2):
    print("Yes")
else:
    print("No")

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

odd = 0
n2 = 0
n4 = 0

for a in A:
  r = a % 4
  if r == 0:
    n4 += 1
  elif r == 2:
    n2 = 1
  else:
    odd += 1

if n4 + 1 >= odd + n2:
  print('Yes')
else:
  print('No')

Solution (Python):
N=int(raw_input())
A=[int(x) for x in raw_input().split()]
o=0
e=0
f=0
for a in A:
    if a%4==0:
        f+=1
    elif a%2==0:
        e+=1
    else:
        o+=1
if o==0 or f>=o or (e==0 and f+1==o):
    print 'Yes'
else:
    print 'No'

Solution (Python):








yes = "Yes"
no = "No"


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

four = 0
two = 0
none = 0
for e in a:
	if e % 4 == 0:
		four += 1
	elif e % 2 != 0:
		none += 1
	else:
		two += 1

if four >= none or (two == 0 and four+1 >= none):
	print(yes)
else:
	print(no)

Solution (Python):

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

cnt_4 = 0
cnt_2 = 0

for a in a_list:
    if a % 4 == 0:
        cnt_4 += 1
    elif a % 2 == 0:
        cnt_2 += 1
        
cnt_1 = N - cnt_4 - cnt_2

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

Solution (Python):
input()
c1, c2, c4 = 0, 0, 0
for a in map(int, input().split()):
    if a & 1:
        c1 += 1
    elif a & 2:
        c2 += 1
    else:
        c4 += 1

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
nep = 0
par = 0
cet = 0
for x in a:
    if x % 2 != 0:
        nep += 1
    elif x % 4 != 0:
        par += 1
    else:
        cet += 1

last = 0
for i in range(n):
    if last == 0:
        if nep:
            nep -= 1
            last = 1
        elif par:
            par -= 1
            last = 2
        else:
            cet -= 1
            last = 0
        continue
    if last == 2:
        if par:
            par -= 1
            last = 2
        elif cet:
            cet -= 1
            last = 0
        else:
            print('No')
            exit(0)
        continue 
    if cet:
        cet -= 1
        last = 0
    else:
        print('No')
        exit(0)
print('Yes')