Problem:


Score : 200 points

Problem Statement

We will say that two integer sequences of length N, x_1, x_2, ..., x_N and y_1, y_2, ..., y_N, are similar when |x_i - y_i| \leq 1 holds for all i (1 \leq i \leq N).

In particular, any integer sequence is similar to itself.

You are given an integer N and an integer sequence of length N, A_1, A_2, ..., A_N.

How many integer sequences b_1, b_2, ..., b_N are there such that b_1, b_2, ..., b_N is similar to A and the product of all elements, b_1 b_2 ... b_N, is even?

Constraints

1 \leq N \leq 10

1 \leq A_i \leq 100

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the number of integer sequences that satisfy the condition.

Sample Input 1

2
2 3

Sample Output 1

7

There are seven integer sequences that satisfy the condition:

1, 2

1, 4

2, 2

2, 3

2, 4

3, 2

3, 4

Sample Input 2

3
3 3 3

Sample Output 2

26

Sample Input 3

1
100

Sample Output 3

1

Sample Input 4

10
90 52 56 71 44 8 13 30 57 84

Sample Output 4

58921



Sample input:
2
2 3


Sample output:
7

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = pow(3, n)
if n == 1:
    if a[0] % 2 == 0:
        print(1)
    else:
        print(2)
else:
    num = 1
    for i in range(n):
        if a[i] % 2 == 0:
            num *= 2
        else:
            num *= 1
    print(ans - num)

Submission status: Accepted

Solution code:
from itertools import product
N = int(input())
A = list(map(int, input().split()))
r = 0
for pp in product((-1, 0, 1), repeat=N):
    s = 1
    for p, a in zip(pp, A):
        s *= a+p
    if s % 2 == 0:
        r += 1
print(r)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
num = 0
for i in A:
    if i % 2 == 0:
        num += 1
print(3**N - 2**num)

Submission status: Accepted

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

odd = 0

for a in A:
    if a % 2 == 1:
        odd += 1


print(3 ** N - 2 ** (N - odd))

Submission status: Accepted

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

a=[2 if i%2==0 else 1 for i in a]

cnt=1

for i in a:
  cnt*=i
  
  
print(n-cnt)

Submission status: Accepted

Solution code:
ans = 0
number = set()
def exsearch(s, i, N, A):
    if i == N:
        global ans
        mul = 1
        for i in range(N):
            if s[i] == "0":
                mul *= A[i]

            elif s[i] == "1":
                    mul *= (A[i] - 1)

            elif s[i] == "2":
                    mul *= (A[i] + 1)

        if mul % 2 == 0:
            ans += 1

    else:
        for c in ["0", "1", "2"]:
            exsearch(s + c, i + 1, N, A)

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

    exsearch("", 0, N, A)

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
odd = 1
for i in A :
    if i%2==0:
        odd *= 2
    else :
        odd *= 1
print(3**N-odd)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
even = 0
odd = 0
for a in A:
  if a % 2 == 0:
    even += 1
  else:
    odd += 1

print(3 ** N - (2**even))

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans=3**n
num=1
for i in range(n):
    if a[i]%2==0:
        num*=2
ans-=num
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
A=list(map(int,input().split()))
m=3**n
b=1
for a in A:
    if a%2==0:
        b*=2
print(m-b)

Submission status: Accepted

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

from itertools import product

pattern= list(product([0,1,2],repeat=n))

cnt=0
for p in pattern:
    ans=1
    for i in range(n):
        if p[i]==0:
            ans*=(a[i]-1) 
        elif p[i]==1:
            ans*=a[i] 
        else:
            ans*=(a[i]+1) 
        
    if ans%2==0:
        cnt+=1

print(cnt)

Submission status: Accepted

Solution code:
n, *a = map(int, open(0).read().split())
A = 1
for i in a:
    A *= 2 - i%2
print(3**n - A)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A = list(map(int, input().split()))
count=1
for i in range(N):
  if A[i]%2==0:
    count*=2

print(3**N-count)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
n_list = [[] for i in range(n)]
k_list = [[] for j in range(n)]

for i in range(n):
    if a[i] == 0:
        n_list[i].append(a[i])
        if a[i]%2 == 1:
            k_list[i].append(a[i])
        n_list[i].append(a[i]+1)
        if (a[i]+1)%2 == 1:
            k_list[i].append(a[i]+1)
    elif a[i] == 9:
        n_list[i].append(a[i])
        if a[i]%2 == 1:
            k_list[i].append(a[i])
        n_list[i].append(a[i]-1)
        if (a[i]-1)%2 == 1:
            k_list[i].append(a[i]-1)
    else:
        n_list[i].append(a[i]-1)
        if (a[i]-1)%2 == 1:
            k_list[i].append(a[i]-1)
        n_list[i].append(a[i])
        if a[i]%2 == 1:
            k_list[i].append(a[i])
        n_list[i].append(a[i]+1)
        if (a[i]+1)%2 == 1:
            k_list[i].append(a[i]+1)

ans = 0
k_s = 1
n_s = 1
for i in range(n):
    n_s = n_s*len(n_list[i])
    k_s = k_s*len(k_list[i])

print(n_s-k_s)

Submission status: Accepted

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

b=1
for A in a:
  if A%2==0:
    b*=2
  else:
    pass
print(3**n-b)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
cnt = 0
for i in range(3**N):
    ii = i
    res = 1
    for j in range(N):
        k = ii % 3
        ii = ii // 3
        res *= (A[j]-1+k)
    if res % 2 == 0:
        cnt += 1
print(cnt)

Submission status: Accepted

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

total = 3 ** n
odd = 1

for i in range(n):
    if a[i] % 2 == 0:
        odd *= 2
    else:
        odd *= 1

print(total - odd)

Submission status: Accepted

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

even =[]
even_pro = 1

for a in A:
    if a % 2 == 0:
        even.append(2)
    else:
        even.append(1)

for e in even:
    even_pro *= e

print(3**n - even_pro)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
k = 0
for i in range(n):
  if a[i] % 2 == 0:
    k += 1
ans =3 ** n - 2 ** k
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
even = len([a for a in map(int, input().split()) if a % 2 == 0])
print(3 ** n - 2 ** even)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
N**3
cnt = 0
for i in A:
    if i%2 == 0:
        cnt += 1
ans = 3**N - 2**cnt
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
total = 3 ** n
odd = 1 #init
for i in range(n) :
    if a[i]%2 :
        odd *= 1
    else :
        odd *= 2
print(total-odd)

Submission status: Accepted

Solution code:
import sys
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]

import numpy as np
N = ri()
A = np.array(ri_())

print(3 ** N - np.prod(np.where(A % 2 == 0, 2, 1)))

Submission status: Accepted

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

t = 1
for i in range(n):
    if a[i] % 2 == 1:
        t *= 1
    else:
        t *= 2
print(3**n-t)

Submission status: Accepted

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

even = 0
for i in a:
  if i%2 == 0: even += 1
print(3**n - 2**even)

Submission status: Accepted

Solution code:
n = int(input())

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

mul = 3**n # 累積

odd_mul = 1 # 奇数の累積

for v in a:
    if v%2 == 0:
        odd_mul *= 2
print(mul-odd_mul)

Submission status: Accepted

Solution code:
from functools import reduce
N = int(input())
A = [int(i) for i in input().split()]
ans = [1 if a&1 else 2 for a in A]
print(3**N - reduce(lambda x,y: x*y, ans))

Submission status: Accepted

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

even = 0
for i in a:
  if i%2==0: even += 1
print(3**n - 2**even)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n,*a=map(int,open(0).read().split())
e = sum(i%2 < 1 for i in a) 
print(3**n - 2**e)

Submission status: Accepted

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    A=LI()
    ans=pow(3,N)
    cnt=1
    for i in range(N):
        if A[i]%2==0:
            cnt*=2
            
    print(ans-cnt)

main()

Submission status: Accepted

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

ans1=1 #all
ans2=1 #odd
for i in range(n):
    j=3 #j:all
    k=0 #k:odd
    if (a[i]-1)%2==1:
        k+=1
    if a[i]%2==1:
        k+=1
    if (a[i]+1)%2==1:
        k+=1
    ans1*=j
    ans2*=k
print(ans1-ans2)

Submission status: Accepted

Solution code:
n = int(input())
la = [int(w) for w in input().split()]

odd_pat = 1
max_pat = 3**n

for a in la:
    if a % 2 == 0:
        odd_pat *= 2


print(max_pat-odd_pat)

Submission status: Accepted

Solution code:
n=int(input())
ls=list(map(int,input().split()))
prev=1
ans=0
for i in range(n):
  k=ls[i]
  if k%2==1:
    ans+=prev*2*(3**(n-i-1))
  else:
    ans+=prev*3**(n-i-1)
    prev*=2
print(ans)

Submission status: Accepted

Solution code:

N = int(input())

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

ans = 3**N

d = 1
for i in range(N):

    if A[i] % 2 == 1:
        d *= 1
    else:
        d *= 2

print (ans - d)

Submission status: Accepted

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

_a = 1
res = 0
for i in range(N):
    res += _a * (A[i] % 2 + 1) * 3 ** (N - i - 1)
    if A[i] % 2 == 0:
        _a *= 2
print(res)

Submission status: Accepted

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

amax = []
amin = []

for i in range(n):
    amax.append(a[i] + 1)
    amin.append(a[i] - 1)

m = 3 ** n

for z in range(3 ** n):
    asearch = []
    amulti = 1
    x = z
    for i in range(n):
        asearch.append(x % 3)
        x = x // 3
    for i in range(n):
        if asearch[i] == 0:
            amulti *= a[i]
        elif asearch[i] == 1:
            amulti *= amax[i]
        else:
            amulti *= amin[i]
    if amulti % 2 != 0:
        m -= 1

print(m)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

def main():
    n = int(input())
    A = list(map(int, input().split()))
    allB = exc = 1
    for i in A:
        allB *= 3
        if i%2 == 0:
            exc *= 2
    print(allB - exc)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

def main():
    n = int(input())
    A = list(map(int, input().split()))
    allB = exc = 1
    for i in A:
        allB *= 3
        if i%2 == 0:
            exc *= 2
    ans = allB - exc
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

def main():
    ans = 0
    n = int(input())
    A = list(map(int, input().split()))
    allB = 3**n
    exc = 1
    for i in range(n):
        if A[i]%2 == 0:
            exc *= 2
    ans = allB - exc
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in a:
    if i % 2 == 0:
        b *= 2

print(3**n - b)

Submission status: Accepted

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

O, E = [], []

for i, a in enumerate(A):
    if a % 2 == 0:
        o, e = 2, 1
    else:
        o, e = 1, 2
        
    if i == 0:
        O.append(o)
        E.append(e)
    else:           
        numo, nume = 0, 0
        numo += O[-1] * o
        nume += E[-1] * e
        nume += E[-1] * o
        nume += O[-1] * e

        O.append(numo)
        E.append(nume)

print(E[-1])

Submission status: Accepted

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

for x in A:
	c *= 1 if x%2 else 2
print(3**N-c)

Submission status: Accepted

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

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

T = 1
for i in range(N):
    if A[i] % 2 == 0:
        T = T * 2
print(3**N - T)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
even=1
for i in range(N):
  if A[i]%2==0:
    even*=2

print(3**N-even)

Submission status: Accepted

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

T=0
for a in A:
    T+=(a%2==0)
    
print(3**N-2**T)

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
res = 1
for x in a:
    if x%2==0:
        res *= 2
print(3**n-res)

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
x = 1
for i, a in enumerate(A):
    if a%2== 0:
        x *= 2
    else:
        x *= 1
print(3**n-x)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
a = 0
for i in range(N):
    if A[i] % 2 == 0:
        a += 1
ans = 3 ** N - 2 ** a
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
ans = pow(3,N)
even = 0
for i in range(N):
  if A[i]%2==0:
    even += 1
ans -= pow(2,even)
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# hello worldと表示する
# coding: utf-8
# hello worldと表示する
#float型を許すな
#numpyはpythonで
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,factorial
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()
ans=3**n
cons=1
lis=LI()
for i in range(n):
    if lis[i]%2==0:
        cons*=2
print(ans-cons)

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
A = readInts()
whole = 3**n
ex = 1
for x in A:
    if x % 2 == 0:
        ex *= 2
print(whole - ex)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
even_cnt = []
for i in range(n):
    if a[i]%2==0:
        even_cnt.append(1)
        a[i] = 2
    else:
        even_cnt.append(2)
        a[i] = 1
x = 3 ** n
ans = 0
for i in range(n):
    x //= 3
    ans += even_cnt[i]*x
    x *= a[i]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
cnt = 0
for i in range(N):
    if A[i]%2==0:
        cnt += 1
print(3**N-2**cnt)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N = ini()
A = inl()


def solve():
    ca = 3 ** N
    co = 1
    for x in A:
        if x % 2 == 0:
            co *= 2
        else:
            co *= 1
    return ca - co


print(solve())

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
ans = 1
for i in range(N):
    if a[i] % 2 == 0:
       ans *= 2
if N != 1:
    print(3**N-ans)
else:
    if a[0] % 2 == 0:
        print(1)
    else:
        print(2)

Submission status: Accepted

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

from itertools import product

li = [-1,0,1]
cnt = 0
for v in product(li,repeat = n):
    L = []
    for i in range(n):
        L.append(v[i]+a[i])
    if any(x%2==0 for x in L):
        cnt +=1

print(cnt)

Submission status: Accepted

Solution code:
import numpy as np
from itertools import product

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

a = np.array(a)

li = [-1,0,1]
cnt = 0
for v in product(li,repeat = n):
    v = np.array(v)
    L =a+v
    cum = L.cumprod()
    if cum[-1]%2 ==0 :
        cnt +=1
print(cnt)

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    A = [int(i) for i in input().split()]
    cnt = 1
    for a in A:
        if a % 2 == 0:
            cnt *= 2
    print(3**N - cnt)


resolve()

Submission status: Accepted

Solution code:
from itertools import product
import numpy as np
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    ls = []
    for i in range(N):
        ls.append([A[i], A[i]+1, A[i]-1])
    
    ls = list(product(*ls))
    ans = len(ls)
    for a in ls:
        if np.prod(a) % 2 == 1:
            ans -= 1

    print(ans)

    return

resolve()

Submission status: Accepted

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

even_num = 0

for i in range(N):
    if A[i]%2==0:
        even_num += 1
print(3**N-2**even_num)

Submission status: Accepted

Solution code:
print(3**int(input())-2**sum(list(map(lambda x:1-int(x)%2,input().split()))))

Submission status: Accepted

Solution code:
n = int(input())
a = sum(list(map(lambda x:1-int(x)%2,input().split())))
print(3**n-2**a)

Submission status: Accepted

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

all_num = 3 ** N
even = 1

for a in A:
    if a % 2 == 0:
        even *= 2

print(all_num - even)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    A = list(map(int, input().split()))
    even = sum([a % 2 == 0 for a in A])
    print(pow(3, n) - pow(2, even))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
all=1
bad=1
for i in range(N):
  all*=3
  if A[i]%2==0:
    bad*=2
print(all-bad)

Submission status: Accepted

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

total = pow(3, N)
odd = 1
for i in range(N):
    if A[i] % 2 == 0:
        odd *= 2
    else:
        odd *= 1
ans = total - odd
print(ans)

Submission status: Accepted

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    A = LI()

    all_odd = 1
    for i in A:
        if i % 2 == 0:
            all_odd *= 2
        else:
            all_odd *= 1

    print(3 ** N - all_odd)

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys
from typing import Any, Callable, Deque, Dict, List, Mapping, Optional, Sequence, Set, Tuple, TypeVar, Union
# import time
# import math, cmath
# import numpy as np
# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random                                # random, uniform, randint, randrange, shuffle, sample
# import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import _heapify_max, _heappop_max, _siftdown_max
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from fractions import Fraction               # Fraction(a, b) => a / b ∈ Q. note: Fraction(0.1) do not returns Fraciton(1, 10). Fraction('0.1') returns Fraction(1, 10)



def main():
    Num = Union[int, float]
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79e+308
    # inf = 2 ** 63 - 1             # (for fast JIT compile in PyPy) 9.22e+18
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def isp():   return input().split()
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    # def _heappush_max(h, item): h.append(item); _siftdown_max(h, 0, len(h)-1)
    
    
    n = ii()
    L = lmi()
    odd_count = 1
    for i in range(n):
        if L[i] % 2 == 0:
            odd_count *= 2
    print(pow(3, n) - odd_count)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def solve(n,a):
  even = 0
  
  for i in range(n):
    if a[i] % 2 == 0:
      even += 1
  
  return 3**n - 2**even
  
def main():
  N = int(input())
  a = list(map(int,input().split()))
  print(solve(N,a))
  
main()

Submission status: Accepted

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

a = 3 ** N

e = [i % 2 == 0 for i in A].count(True)

print(a-2**e)

Submission status: Accepted

Solution code:
from itertools import product

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

count = 0
for diffs in product((-1, 0, 1), repeat=N):
    for a, d in zip(A, diffs):
        if (a % 2 == 0 and d == 0) or (a % 2 == 1 and d != 0):
            count += 1
            break

print(count)

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 X(): return list(input())
def I(): return map(int,input().split())
def L(): return list(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)
mod = 10**9+7

N = i()
A = l()
mi = 0

for i in A:
    if i % 2 == 0:
        mi += 1

print(3**N - 2 **mi)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int, input().split()))
even=0
for a in A:
  if a%2==0:
    even+=1
print(3**N-2**even)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
ans=3**N
tmp=1
for i in A:
  if i%2==0:
    tmp*=2
ans-=tmp
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n = readInt()
a = readInts()
sum_a = 3**n
pro = 1
for i in a:
	if i%2==0:
		pro*=2
print(sum_a-pro)

Submission status: Accepted

Solution code:
## B - Similar Arrays
N = int(input())
A = list(map(int,input().split()))
ans = 1
for a in A:
    if a % 2 == 0:
        ans *= 2
print(3**N - ans)

Submission status: Accepted

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

x = 1

for num in a:
  if num%2 == 0:
    x *= 2
  else:
    x *= 1

print(3**n - x)

Submission status: Accepted

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

c = 1
for i in a:
    if i%2 == 0:
        c *= 2
    else:
        c *= 1

print(3**n - c)

Submission status: Accepted

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

ans=3**N
sub=1
for a in A:
    if a%2==0:
        sub*=2
    else:
        continue
ans-=sub
print(ans)

Submission status: Accepted

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

odd_count = 1

for a in A:
  if a%2 == 0:
    odd_count *= 2

print(3**N - odd_count)

Submission status: Accepted

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

odd_count = 1

for a in A:
  if a%2 != 0:
    odd_count *= 1
  else:
    odd_count *= 2

print(3**N - odd_count)

Submission status: Accepted

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

def main(n,a):
    evena=[False]*n
    for i in range(n):
        if a[i]%2==0:
            evena[i]=True
    count=0
    for i in range(3**n):
        #print(i)
        neven=0
        for bit in range(n):
            mask=3**bit
            if (i//mask)%3 == 0:
                #print('mask0')
                if evena[bit]==False:
                    neven+=1
            elif (i//mask)%3 == 1:
                #print('mask1')
                if evena[bit]==True:
                    neven+=1
            elif (i//mask)%3 == 2:
                #print('mask2')
                if evena[bit]==False:
                    neven+=1
            #else:
                #print('????')
        if neven>0:
            count+=1
    return count

if __name__=='__main__':
    n,a=readinput()
    ans=main(n,a)
    print(ans)

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(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)
mod = 10**9+7

N = i()
A = l()
t = 1
f = 1
for i in range(N):
    t *= 3
    if A[i]%2 == 0:
        f *= 2
print(t-f)

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

ans = 3**N
tmp = 1
for a in A:
	if a%2 == 0:
		tmp *= 2
print(ans-tmp)

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

a = [2 - x%2 for x in A]
odd = 1
for x in a:
	odd *= x

print(3**N - odd)

Submission status: Accepted

Solution code:
N = int(input())
original = list(map(int, input().split()))
odd = [i for i in original if i % 2 != 0]
ans = 3 ** (len(original))
if len(odd) != len(original):
    ans -= 2**(len(original)-len(odd))
else:
    ans -= 1
print(ans)