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

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

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

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

tmp = 1

for i in range(N):
    if A[i]%2 == 0:
        tmp *= 2

print(3**N - tmp)

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    
    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
    

    
    

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

if __name__ == '__main__':
    main()

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

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

Solution (Python):
from itertools import product

n = int(input())
al = list(map(int, input().split()))
res = 0
for p in product([-1,0,1], repeat=n):
    bl = [al[i]+p[i] for i in range(n)]
    m = 1
    for b in bl:
        m *= b
    if m%2==0:
        res += 1
print(res)

Solution (Python):
N = int(input())
array = list(map(int, input().split()))
all_pattern = 3 ** N
count = 0
for x in array:
    if x % 2 == 0:
        count += 1
odd_pattern = 2**count
print(all_pattern - odd_pattern)

Solution (Python):


from collections import deque,Counter






import numpy as np






N = int(input())
arrA = np.array(input().split(),dtype=np.int64)
arrA = arrA % 2
cnt = Counter(arrA)
oddnums = 2**cnt[0]
all = 3**len(arrA)
ans = all - oddnums

print(ans)

Solution (Python):
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
A = iil()
odd = 1
for i in A:
    if i%2 == 0:
        odd *= 2
    else:
        odd *= 1
print(3**n - odd)

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

Solution (Python):
def myAnswer(N:int,A:list) -> int:
   counter = 0
   for a in A:
      if(a % 2==0):
         counter +=1

   return 3**N-2**counter






def modelAnswer():
   tmp=1
def main():
   N = int(input())
   A = list(map(int,input().split()))
   print(myAnswer(N,A[:]))
if __name__ == '__main__':
   main()

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
ans = 0
odd = 1
for i in range(N):
  tmp = 0
  if A[i] % 2 == 0:
    tmp = 2
  else:
    tmp = 1
  odd *= tmp
print(pow(3, N) - odd)

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

Solution (Python):
from itertools import product
import numpy as np

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

cnt = 0
for x in list(product([-1, 0, 1], repeat=n)):
  temp = a.copy() - np.array(x)
  if np.prod(temp) % 2 == 0:
    cnt+=1
print(cnt)

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

eo = [i % 2 == 0 for i in a]

even = eo.count(True)
odd = n - even

ans = 3 ** n - 2 ** even
print(ans)

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
e = 0
for a in A:
    if a % 2 == 0:
        e += 1
ans = 3 ** n - 2 ** e
print(ans)

Solution (Python):

from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    a = LI()
    s = [2 if i&1 else 1 for i in a]
    ans = 0
    for b in range(1,1<<n):
        res = 1
        c = 0
        for i in range(n):
            if 1&(b>>i):
                res *= s[i]
                c ^= 1
            else:
                res *= 3
        ans += (2*c-1)*res
    print(ans)
    return


if __name__ == "__main__":
    solve()

Solution (Python):

from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    a = LI()
    s = [2 if i&1 else 1 for i in a]
    ans = 0
    for b in range(1,1<<n):
        res = 1
        c = 0
        for i in range(n):
            if b&(1<<i):
                res *= s[i]
                c ^= 1
            else:
                res *= 3
        ans += (2*c-1)*res
    print(ans)
    return


if __name__ == "__main__":
    solve()

Solution (Python):

from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    a = LI()
    s = [2 if i&1 else 1 for i in a]
    ans = 0
    for b in range((1<<n)-1):
        res = 1
        for i in range(n):
            res *= (s[i]<<(b>>i))%3
        ans += res
    print(ans)
    return


if __name__ == "__main__":
    solve()

Solution (Python):
n = int(input())
li = list(map(int,input().split()))
lee = len(li)
base = 1
for l in li:
    if l%2 == 0:
        base*=2
print(3**lee-base)

Solution (Python):

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

tmp = 1
for i in a:
    if i % 2 == 1:
        tmp *= 1
    else:
        tmp *= 2
print(pow(3, n) - tmp)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = True


def cmb(n, r):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % mod

N = 1000  
mod = pow(10, 9) + 7
fact = [1, 1]  
factinv = [1, 1]  
inv = [0, 1]  

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % mod)
    inv.append((-inv[mod % i] * (mod // i)) % mod)
    factinv.append((factinv[-1] * inv[-1]) % mod)


n = INT()
a = LIST()
arr = [0 for _ in range(n)]
for i in range(n):
    if a[i] % 2 == 0:
        arr[i] = 2
    else:
        arr[i] = 1
s = 1
for i in range(n):
    s *= arr[i]
ans = 3 ** n - s
print(ans)

Solution (Python):
n = int(input())
l = list(map(int,input().split()))
mi = 1
for i in l:
    if i%2 == 0:
        mi *= 2
print(pow(3,n)-mi)

Solution (Python):
n=int(input())
A=list(map(int,input().rstrip().split(' ')))
Xans=1
for a in A:
  if(a%2==1):
    Xans*=1
  else:
    Xans*=2
    
print(3**n-Xans)

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    A=[int(_) for _ in input().split()]
    cunt=0
    for a in A:
        if a%2==0:cunt+=1
    print(3**n-2**cunt)

if __name__=='__main__':
    main()

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

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

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

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

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

ans = 3 ** len(a)
tmp = 1
for i in a:
    if i % 2 == 0:
        tmp *= 2

print(ans - tmp)

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

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

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

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

print(ans-minus)

Solution (Python):
import functools
import operator

n = int(input())
a = list(map(int,input().split()))
ans = 0
for i in range(3**n):
    p=i
    c=[]
    for j in range(n):
        p,b=p//3,p%3
        if b == 0:
            c.append(a[j]-1)
        elif b==1:
            c.append(a[j])
        else:
            c.append(a[j]+1)
    x = functools.reduce(operator.mul, c)
    if x%2 == 0:
        ans += 1
print(ans)

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

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

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

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

ans = 0
even = [a % 2 == 0 for a in A]
for i in range(2 ** N):
    tmp = even.copy()
    cnt = 0
    for j in range(N):
        if ((i >> j) & 1):
            tmp[j] = not tmp[j]
            cnt += 1
    if sum(tmp) > 0:
        ans += 2 ** cnt if i != 0 else 1

print(ans)

Solution (Python):
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)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
ans = 1
for i in a:
    if i % 2 == 1:
        ans *= 1
    else:
        ans *= 2
print(3 ** n - ans)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
ans = 3**n
res = 1
for x in a:
    if x%2:res*=1
    else:res*=2
print(ans-res)

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

num=pow(3,n)

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

print(num-temp)

Solution (Python):
n = int(input())
A = [int(x) for x in input().split()]
res = 1
for a in A:
  if a%2 == 0:
    res *= 2
print(3 ** n - res)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
f=1
for i in a:
  if i%2==0:
    f<<=1
print(3**n-f)

Solution (Python):
from functools import reduce
def solve():
    N = int(input())
    A = list(map(int,input().split()))

    diffs_perm = []
    dfs(list(),N,diffs_perm)

    cnt = 0
    for p in diffs_perm:
        B = A[:]
        for i in range(N):
            B[i] += p[i]
        
        if reduce(lambda a,b:a*b, B) % 2 == 0:
            cnt += 1
    
    print(cnt)

def dfs(diffs,N,res):
    if len(diffs) == N:
        res.append(diffs)
        return
    dfs(diffs[:]+[1],N,res)
    dfs(diffs[:]+[0],N,res)
    dfs(diffs[:]+[-1],N,res)


if __name__ == '__main__':
    solve()

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


ans = 1
mins = 1
for a in A:
    if a % 2 == 1:
        ans *= 3
    else:
        ans *= 3
        mins *= 2
print(ans - mins)

Solution (Python):
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)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
even_cnt = []
for i in range(N):
  c = 0
  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 = x // 3
  ans += even_cnt[i] * x
  x *= A[i]
print(ans)

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

num = 1
odd = 1

for a in A:
    num *= 3
    if a % 2 == 0:
        odd *= 2

print(num - odd)

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

Solution (Python):
n = int(input())
a= list(map(int, input().split()))
odd=0
even=0
for i in a:
    if i%2==0:
        even+=1
    else:
        odd+=1
print(3**len(a)-2**even)

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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
t = 1
for a in A:
    if a & 1 == 0:
        t *= 2
print(pow(3, N)-t)

Solution (Python):
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)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
evens = len(list(filter(lambda x: x % 2 == 0, a)))
print(3 ** n - 2 ** evens)

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

cnt = 0
for i in ary:
  if i%2 == 0:
    cnt+=1
    
ans = 3**n - 2**cnt

print(ans)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
a = tuple(map(int, readline().split()))
cnt = 0
for i in range(n):
    if a[i] % 2 == 0:
        cnt += 1
print(3 ** n - 2 ** cnt)

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

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10


def solve():
    n = II()
    a = LI()
    ans = 3 ** n
    a = sum(map(lambda x: x & 1, a))
    na = n - a
    print(ans - 2 ** na)
    return



if __name__ == '__main__':
    solve()

Solution (Python):
n = int(input())
A = list(map(int,input().split()))
odd, even = 0, 0
for a in A:
    if a%2!=0:
        odd += 1
    else:
        even += 1
print(3**n - 2**even)

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


total = 3**a


cul_list = [j for j in range(a)]
for i in range(a):
  if num_list[i] % 2 == 0:
    cul_list[i] = 2
  else:
    cul_list[i] = 1

ans = 1
for k in cul_list:
  ans *= k
print(total - ans)

Solution (Python):
N = int(input())
A = [int(i) for i in input().split(" ") ]
odd = [2 if i%2==0 else 1 for i in A]


PI1 = 3**N

PI2 = 1
for i in odd:
    PI2*=i
    
print(PI1-PI2)

Solution (Python):

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

odd = 0
even = 0
for i in range(N):
    if A[i] % 2 == 0:
        even += 1
    else:
        odd += 1

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

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

R = [Ai % 2 for Ai in A]
e = R.count(0)
print(3 ** N - 2 ** e)

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

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

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

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

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

ans = 3 ** n - 2 ** len([i for i in a if i%2 == 0])

print(ans)

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

cnt = 1
for e in a:
    if e % 2 == 0:
        cnt *= 2

ans = 3 ** n - cnt
print(ans)

Solution (Python):
import numpy as np


def main():
    length = int(input())
    sequence = list(map(int, input().split()))
    answer = 0
    for i in range(3 ** length):
        ternary_i = np.base_repr(i, 3).zfill(length)
        now_product = 1
        for j in range(length):
            if ternary_i[j] == "0":
                now_product *= sequence[j]
            elif ternary_i[j] == "1":
                now_product *= sequence[j] + 1
            else:
                now_product *= sequence[j] - 1
        if now_product % 2 == 0:
            answer += 1
    print(answer)


if __name__ == '__main__':
    main()

Solution (Python):
import math
import string


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor



dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

n = int(input())
a = readints()
sum = 1
for i in range(len(a)):
    if a[i] % 2 == 0:
        sum *= 2
    else:
        sum *= 1
print(3**len(a)-sum)

Solution (Python):
import math
import string


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor



dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

n = int(input())
a = readints()


def func(l):
    if len(l) == n:
        for i in range(len(l)):
            if l[i] % 2 == 0:
                return 1

        return 0
    return func(l+[(a[len(l)])])+func(l+[(a[len(l)]-1)])+func(l+[(a[len(l)]+1)])


print(func([]))

Solution (Python):
from itertools import product
N = int(input())
A_list = list(map(int, input().split()))
ans = 0
cnt = 0
for i in A_list:
    if i % 2 == 0:
        cnt += 1
ans = 3**N - 2**cnt
print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
even=len([i for i in a if i%2==0])
All = pow(3,n)

t = pow(2,even)
print(All-t)

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

Solution (Python):
import itertools
N=int(input())
A=list(map(int,input().split()))
lo=[-1,0,1]
cnt=0
for k in itertools.product(lo,repeat=N):
    li=list(k)
    res=1
    for z in range(N):
        res*=A[z]+li[z]
    if(res%2==0):
        cnt+=1
print(cnt)

Solution (Python):
def main():
    n = int(input())
    a = list(map(int, input().split()))
    x = 3**n
    ans = 0
    for i in range(x):
        p = i
        buf = 1
        for j in range(n):
            q = p%3
            if q == 0:
                buf *= a[j] - 1
            elif q == 1:
                buf *= a[j]
            else:
                buf *= a[j] + 1
            p //= 3
        if buf % 2 == 0:
            ans += 1
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
import itertools
N=int(input())
A=list(map(int,input().split()))
all=pow(3,N)
sub=1

for i in range(N):
    if A[i]%2==0:
        sub=sub*2
    else:
        sub=sub
print(all-sub)

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

Solution (Python):
N = int(input())
Alist = list(map(int, input().split()))
even = sum([1 for a in Alist if a % 2 == 0])
print(3**N-2**even)

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

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
cnt=0
for i in a:
 if i%2==0:
   cnt+=1
print(3**n-2**cnt)

Solution (Python):

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


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

Solution (Python):
from collections import Counter as co 
n=int(input())
l=sorted(co([a%2 for a in map(int,input().split())]).most_common())
if len(l)==1:
  if l[0][0]==0:
    print(3**n-2**n)
  else:print(3**n-1)
else:
  g,k=l[0][1],l[1][1]
  print(3**n-2**g)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
ans=1
for k in a:
  if k%2==0:
    ans*=2
print(pow(3,n)-ans)

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

reigai = 1
for a in A:
    if a % 2 == 0:
        reigai *= 2

print(3**N - reigai)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
t = 1
for e in a:
    if e%2 == 0:
        t *= 2
    else:
        t *= 1

print(3**n-t)

Solution (Python):
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    ans = 3**N
    cnt = len([a for a in A if a % 2 == 0])
    ans -= 2**cnt
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
ev = sum([1 for a in A if a%2==0])
print(pow(3,N)-pow(2,ev))

Solution (Python):
n = int(input())
dat = list(map(int, input().split()))
total = 3 ** n
countzero = 0
countodd = []

for i in range(n):
    if dat[i] % 2 == 0:
        countodd.append(2)
    else:
        countodd.append(1)
xxx = 1
for i in range(n):
    xxx *= countodd[i]

total -= xxx
print(total)

Solution (Python):
from functools import reduce
from operator import mul
from itertools import product
N,*A=map(int, open(0).read().split())
print(sum(reduce(mul, prod)%2==0 for prod in product(*[(a-1,a,a+1) for a in A])))

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

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

total = 3 ** N
ng = 1
for ai in A:
    if ai % 2 == 0:
        ng *= 2

print(total-ng)

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


T = [None] * N

c = 0

from functools import reduce

def check():
    def f(a, b):
        return a * b

    global c
    r = reduce(f, T)
    
    if r % 2 == 0:
        c += 1


def dfs(pos):
    if pos == N:
        check()
        return

    T[pos] = A[pos] - 1
    dfs(pos+1)

    T[pos] = A[pos]
    dfs(pos+1)

    T[pos] = A[pos] + 1
    dfs(pos+1)

dfs(0)

print(c)

Solution (Python):


n = int(input())
a = [int(x) for x in input().split()]
c = 1
for idx, num in enumerate(a):
    if num % 2 == 0:
        c *= 2
print(3 ** len(a) - c)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
b = []
c = []
cnt = 1
for i in range(n):
    b.append([a[i]+1,a[i],a[i]-1])
for i in range(n):
    cnt *= len(b[i])
for i in range(n):
    cnt2 = 0
    for j in range(len(b[i])):
        if b[i][j]%2 == 1:
            cnt2 += 1
    c.append(cnt2)
cnt3 = 1
for i in range(n):
    cnt3 *= c[i]
print(cnt-cnt3)

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

for val in A:
    if(val%2 == 0):
        dim *= 2
    else:
        dim *= 1
print(3**N-dim)

Solution (Python):
def main() -> None:
    N = int(input())
    ans = 3 ** N
    odd = 1
    for a in map(int, input().split()):
        if a % 2 == 0:
            odd *= 2
    print(ans - odd)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
a = [int(x) % 2 for x in input().split()]
print(3**len(a) - 1) if sum(a) == len(a) else print(3**len(a) - 2**(len(a) - sum(a)))

Solution (Python):

import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n=int(input())
A=list(map(int,input().split()))
for ai in A:
    if ai % 2 == 0:
        pro*=2
print(3**n-pro)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
ans=1
odd=1
for i in a:
  ans*=3
  if(i%2==0):
    odd*=2
print(ans-odd)

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

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

Solution (Python):
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    if N == 1:
        return print(1 if A[0] % 2 == 0 else 2)
    ans = 0
    d = (-1, 0, 1)
    from itertools import product
    for i in product(range(3), repeat=N):
        cur = 1
        for j in range(N):
            cur *= (A[j] + d[i[j]])
        if cur % 2 == 0:
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
e=sum(x%2==0 for x in a)
print(3**n-2**e)

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

ans = 3 ** n
tmp = 1
for a in al:
    if a % 2 == 0:
        tmp *= 2

print(ans-tmp)

Solution (Python):
import itertools


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

ans = 0
for ptn in itertools.product(range(-1, 2), repeat=n):
    for i, num in enumerate(ptn):
        if (a[i] + num) % 2 == 0:
            ans += 1
            break
print(ans)

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

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

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

Solution (Python):
from copy import deepcopy


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


def f(ret, idx):
    if idx == n:
        yield ret
    else:
        for x in [-1, 0, 1]:
            next_ret = deepcopy(ret)
            next_ret.append(a[idx] + x)
            yield from f(next_ret, idx + 1)


for g in f([], 0):
    res = len(list(filter(lambda x: x % 2 == 0, g)))
    ans += 1 if res > 0 else 0
print(ans)

Solution (Python):
n = int(input())
l = [int(i) for i in input().split()]

l = [i for i in l if i % 2 == 0]

print(3 ** n - 2 ** len(l))

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

Solution (Python):
def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    ans = 1
    for i in range(N):
        if A[i]%2==1:
            pass
        else:
            ans *= 2
        
    print(3**N-ans)
if __name__ == '__main__':
    main()