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 = [int(_) for _ in input().split()]

ans = 3**n

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

print(ans-cnt)

Submission status: Accepted

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

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

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
print(ans-tmp)

Submission status: Accepted

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

evencount = 0
for i in range(N):
  if a[i]%2 == 0:
    evencount += 1

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

Submission status: Accepted

Solution code:
print(3**int(input()) - 2**sum(1-int(i)%2 for i in input().split()))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
def main():
    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
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

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

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
print(3**N-ans)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
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)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
#!usr/bin/env python3
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

#Solve
if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
#!usr/bin/env python3
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

#Solve
if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
#!usr/bin/env python3
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

#Solve
if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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)

Submission status: Accepted

Solution code:
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  # N は必要分だけ用意する
mod = pow(10, 9) + 7
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

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()))
evens = len(list(filter(lambda x: x % 2 == 0, a)))
print(3 ** n - 2 ** evens)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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

#solve
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


#main
if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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
#print(cul_list)
ans = 1
for k in cul_list:
  ans *= k
print(total - ans)

Submission status: Accepted

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

# 条件1|x_i-y_i|<=1を満たすパターン数を出す
PI1 = 3**N
# 条件2の対偶(総積が奇数ならカウントしない)のパターンを条件1のパターンから引く
PI2 = 1
for i in odd:
    PI2*=i
    
print(PI1-PI2)

Submission status: Accepted

Solution code:
# B
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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


# coordinates
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)

Submission status: Accepted

Solution code:
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


# coordinates
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([]))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
even=len([i for i in a if i%2==0])
All = pow(3,n)
#すべてoddをひく
t = pow(2,even)
print(All-t)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
a = list(map(int,input().split()))
#3**nから全部奇数のものをひく
# a[i]が偶数なら*2 で奇数なら*1をしていくだけ
all_odd = 1
for i in range(n):
    if a[i] % 2 == 0: all_odd *= 2
print(3**n - all_odd)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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])))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)
    # print(T, r)
    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)

Submission status: Accepted

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

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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)