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 = 3**n
ansm = 1
for i in range(n):
    if a[i] % 2 == 0:
        ansm *= 2
print(ans-ansm)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

tmp = 1
for i in range(N):
    if a[i]&1 == 0:
        tmp *= 2
print(3**N - tmp)

Submission status: Accepted

Solution code:
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
import heapq
INF = float("inf")
sys.setrecursionlimit(10**7)
# 4近傍（右, 下, 左, 上）
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W
def mi(): return map(int, input().split())
def ii(): return int(input())
###template###

N = ii()
As = list(mi())

oddans = 1
for a in As:
  if a % 2 == 1:
    #自身が奇数なら、自身を選ぶしかない
    continue
  else:
    #自身が偶数なら、両側の奇数を選ぶことができる
    oddans *= 2

print(pow(3, N) - oddans)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(item) for item in input().split()]
total = 1; odd = 1
for item in a:
    total *= 3
    if item % 2 == 0:
        odd *= 2
    else:
        odd *= 1
print(total - odd)

Submission status: Accepted

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

odd_num = 0
for a in A:
	odd_num += (0 == a % 2)

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

Submission status: Accepted

Solution code:
N=int(input())
A=[int(i) for i in 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())
a = list(map(int, input().split()))
ans = 3 ** n
c = 1
for num in a:
    if num % 2 == 0:
        c *= 2
print(ans - c)

Submission status: Accepted

Solution code:
# code-festival-2017-qualcB - Similar Arrays
def main():
    n = int(input())
    A = list(map(int, input().rstrip().split()))
    e = 1  # e: exception
    for i in A:
        if i % 2 == 0:
            e *= 2
    print(3 ** n - e)


if __name__ == "__main__":
    main()

Submission status: Accepted

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from functools import reduce
from itertools import product

N = int(input())
*A, = map(int, input().split())
ans = 0
for t in product([-1, 0, 1], repeat=N):
    prod = reduce(lambda x, y: x*y, [a + t[i] for i, a in enumerate(A)])
    if prod % 2 == 0: ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from functools import *
print(3 ** int(input()) - reduce(lambda x,y: x*y, (1 if i % 2 == 1 else 2 for i in map(int, input().split()))))

Submission status: Accepted

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

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

print(3 ** N - odds)

Submission status: Accepted

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

Submission status: Accepted

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

print(all - odd)

Submission status: Accepted

Solution code:
N = int(input())
odd = 1
for a in input().split():
  a = int(a)
  if a % 2 == 0:
    odd *= 2

answer = 3 ** N - odd
print(answer)

Submission status: Accepted

Solution code:
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
import bisect
import copy
import fractions
import itertools
import math
import queue
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))


n = II()
a = LI()
evencnt = 0
oddcnt = 0
for num in a:
    if num % 2 == 0:
        evencnt += 1
    else:
        oddcnt += 1
print((3 ** n) - (2 ** evencnt))

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:
from operator import mul
from functools import reduce

n = int(input())
a = list(map(lambda x: 1 if int(x) % 2 else 2, input().split()))
print(3 ** n - reduce(mul, a))

Submission status: Accepted

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

s = pow(3, N)
odd = 1
for ai in a:
  if ai % 2 == 0:
    odd *= 2
print(s - odd)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
H = [2 - (int(i)%2) for i in input().split()]
k = 1
for i in H:
    k *= i
print(3**N - k)

Submission status: Accepted

Solution code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

n = readi()
m = readl()

a = 1
b = 1

for i in m:
    a *= 3
    if i % 2 == 0:
        b *= 2
ans = a - b
print(ans)

Submission status: Accepted

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

even, odd = 0, 0
for a in A:
	if a % 2:
		odd += 1
	else:
		even += 1

if not even:
	print(3 ** N - 1)
else:
	print(3 ** N - 2 ** even)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
cnt = 0
def dfs(i, x):
    global cnt
    if i == N:
        if x == 0:
            cnt += 1
        return
        
    dfs(i+1, ((A[i]+1) % 2) * x)
    dfs(i+1, (A[i] % 2) * x)
    dfs(i+1, ((A[i]-1) % 2) * x)

    return cnt

cnt = dfs(0, 1)

print(cnt)

Submission status: Accepted

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

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

print(3 ** N - tmp)

Submission status: Accepted

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


def dfs(A_s, index,Bss):
    if index == N:
        tmp = 1
        for b in Bss:
            tmp *= b
        return 1 if tmp % 2 == 0 else 0
    b_mi = Bss.copy()
    b_mi.append(A_s[index] - 1)

    b = Bss.copy()
    b.append(A_s[index])

    b_pl = Bss.copy()
    b_pl.append(A_s[index] + 1)
    return dfs(A_s,index + 1, b_mi) + dfs(A_s,index + 1,b) + dfs(A_s,index + 1,b_pl)


print(dfs(As,0,[]))

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

dp=[[0,0]for i in range(N+1)]
#print(dp)

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
B - Similar Arrays
https://atcoder.jp/contests/code-festival-2017-qualc/tasks/code_festival_2017_qualc_b

"""
import sys


def solve(N, array):
    ans = 3**N
    evens = [a for a in array if a%2==0]
    ans -= 2**len(evens)
    return ans


def main(args):
    N = int(input())
    array = [int(a) for a in input().split()]
    ans = solve(N, array)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
nums = list(map(int,input().split(" ")))
minus = 1
for num in nums:
    if num %2 == 0:
        minus *= 2

print(3 ** N -minus)

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:
n=int(input())
A=[int(i) for i in input().split()]
count=0
for a in A:
  if a%2==0:
    count+=1
print(3**n-2**count)

Submission status: Accepted

Solution code:
N = int(input())
lst_A = list(map(int, input().split()))
all_pattern = 3 ** N
odd_pattern = 1


for a in lst_A:
    if a%2 == 0:
        odd_pattern *= 2
ans = all_pattern - odd_pattern


print(ans)

Submission status: Accepted

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

all_number = 1
all_odd = 1
for a in A:
  all_number *= 3
  all_odd *= 2 - a%2
  
print(all_number-all_odd)

Submission status: Accepted

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

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==1:
    odd+=1
  else:
    even+=1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
As = [int(x) for x in input().split()]

diff = 1
for A in As:
    if A % 2 == 0:
        diff *= 2
    else:
        diff *= 1
ans = int(pow(3, N)) - diff

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N=INT()
A=LIST()

cnt=1
for i in range(N):
    if A[i]%2==0:
        # 自身が偶数なら似ている奇数は2つ
        cnt*=2
    else:
        # 自身が奇数なら1つ
        cnt*=1

# 全体 - 全ての項の積が奇数
print(3**N-cnt)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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


print(count)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(_) for _ in 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(' ')))
odds=1
for a in A:
  odds*=(2-a%2)
print(3**N-odds)

Submission status: Accepted

Solution code:
from functools import reduce
n=int(input())
print(3**n-reduce(lambda x, y: x * y, (2-int(s)%2 for s in input().split())))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
print(3**int(input())-2**sum(int(s)%2==0for s in input().split()))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
print(3**int(input())-2**sum(int(s)%2==0 for s in input().split()))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = [int(m) for m in 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(int(i) for i in input().split())
ans = 1
ans2 = 1
for i in a:
  if i%2 == 0:
   ans = ans *3
   ans2 = ans2 *2
  else:
   ans = ans*3
   ans2 = ans2*1
print(ans-ans2)

Submission status: Accepted

Solution code:
n=int(input())
a=[i%2 for i in list(map(int,input().split()))]
print(3**n-2**(n-sum(a)))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
print(3**N-2**len(list(filter(lambda x: x%2==0, A))))

Submission status: Accepted

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

import sys

def solve(n, ls_a):
    numEven = len([a for a in ls_a if a % 2 == 0])
    print(3 ** n - 2 ** numEven)

def readQuestion():
    ws = sys.stdin.readline().strip().split()
    n = int(ws[0])
    ws = sys.stdin.readline().strip().split()
    ls_a = list(map(int, ws))
    return (n, ls_a,)

def main():
    solve(*readQuestion())

# Uncomment before submission
main()

Submission status: Accepted

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

ans = 0
for ptn in itertools.product(range(-1,2),repeat=N):
    m = 1
    for a,d in zip(A,ptn):
        m *= (a+d)
        if m%2==0:
            ans += 1
            break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
L = list(map(int,input().split()))
ans = 0
P = []
for i in range(N) :
    if L[i] % 2 == 0 :
        p = 2
    else :
        p = 1
    P.append(p)

ans = 3**N - np.prod(P)
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

print(3 ** N - s)

Submission status: Accepted

Solution code:
print(3**int(input())-2**sum([~i%2for i in map(int,input().split())]))

Submission status: Accepted

Solution code:
def get_digit(n, digit):
    for i in range(digit):
        n //= 3
    return n % 3


n = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(3**n):
    for j in range(len(A)):
        if (A[j]+get_digit(i, j)-1) % 2 == 0:
            ans += 1
            break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
list_a = list((map(int, input().split())))
even_count = 0
for number in list_a:
    if number % 2 == 0:
        even_count += 1
print(int( (3**n) - (2**even_count) ))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
L = []
for a in A:
    L.append([a-1, a, a+1])
from itertools import product
ans = 0
for t in product(*L):
    k = 1
    for n in t:
        k *= n
    if k%2==0:
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import product
from functools import reduce

n=int(input())
*l,=map(int,input().split())
v=0

for i in product(*map(lambda x:range(x-1,x+2),l)):
  if reduce(lambda x,y:x*y,i)%2==0:
    v+=1
print(v)

Submission status: Accepted

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

Submission status: Accepted

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


for i in range(len(a)):
    if a[i]%2 == 1:
        #odd
        o *= 1
    else:
        #even
        o *= 2

print(3**len(a)-o)

Submission status: Accepted

Solution code:
N = int(input())
ans = 3**N
t = 1
for i in input().split():
    x = int(i)
    if x % 2 == 0:
        t *= 2
ans -= t
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    a = list(map(int, input().split()))
    odd_patterns = 1

    for ai in a:
        if ai % 2 == 0:
            odd_patterns *= 2

    print(3 ** n - odd_patterns)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

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

N = int(input())
aa = inpl()
wana = 1
for a in aa:
	if a%2 == 0:
		wana *= 2
	else:
		wana *= 1

print(3**N-wana)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
'''
aiが偶数のとき
似ている配列は
ai +- 1:奇数
ai:偶数

aiが奇数のとき
似ている配列は
ai +- 1:偶数
ai:奇数

似ている配列すべてのパターン数(3 ** N)から
奇数のみのパターン数を引けばいい
aiが偶数なら奇数2パターン
aiが奇数なら奇数1パターン
をfor i in range(N)で掛け合わせる
'''

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

Submission status: Accepted

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

Submission status: Accepted

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

num_even = 0
for k in A:
  if k % 2 == 0:
    num_even += 1

print(pow(3, N) - pow(2, num_even))

Submission status: Accepted

Solution code:
import numpy
import itertools

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

per = itertools.product([-1,0,1], repeat=N)
ans = 0
for p in per:
  combined = numpy.array([x - y for (x,y) in zip(A,p)])
  product = numpy.prod(combined)
  if product % 2 == 0:
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=[True if i%2==0 else False for i in a].count(True)
print(3**n-2**b)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in 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())
nums = list(map(int,input().split()))
count = 0
for num in nums:
  if num%2 == 0:
    count += 1
print(pow(3,n)-pow(2,count))

Submission status: Accepted

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

Submission status: Accepted

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

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
print(3**n-c)

Submission status: Accepted

Solution code:
N = int(input())

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

def J(x,y):
    ans = 1
    for i in range(y):
        ans *= x
    return ans

L = len(A)
E = len(list(filter(lambda x:x%2==0,A)))

print(J(3,L)-J(2,E))

Submission status: Accepted

Solution code:
import sys
from collections import Counter

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import product


def main():
    N = int(input())
    A = map(int, input().split())

    f(N, A)


def f2(N, A):
    """
    Bの項どれか1つは偶数
    B = A, A+1, A-1
    Aの項が奇数: Bは奇数1,偶数2
    Aの項が偶数: Bは奇数2,偶数1
    B1が偶数なら、B2以降は似ていればなんでも良い
    B1が奇数なら、B2以降のどれかは似ていいるかつ偶数

    全列挙しなくてもAの項の偶奇性を使ってO(N)で計算できそう
    """
    pass


def f(N, A):
    """全組み合わせ

    3^10=59,049
    """
    B = [
        (a, a+1, a-1)
        for a in A
    ]
    ans = 0
    for b in product(*B):
        p = 1
        for _b in b:
            p *= _b
        if p % 2 == 0:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

print(allp - nop)

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-
if __name__ == "__main__":
    N = int(input())
    a = list(map(int, input().split()))
    even = 0
    for factor in a:
        if factor%2 == 0:
            even += 1
        else:
            pass
    else:
        print(3**N-2**even)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy

n = int(input())
l = map(int, input().split())

a = numpy.array([2 if i%2==0 else 1 for i in l])

print(3**n - a.prod())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#  --*-coding:utf-8-*--

def f(n, vals):
    return 3**n - 2**(sum(x%2==0 for x in vals))
    

def test():
    assert f(2, [2, 3]) == 7
    assert f(3, [3, 3, 3]) == 26
    assert f(10, [90, 52, 56, 71, 44, 8, 13, 30, 57, 84]) == 58921

def main():
    n = int(input())
    vals = map(int, input().split())
    
    print(f(n, vals))
    

if __name__ == '__main__':
    main()

Submission status: Accepted

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

def Num_of_even(list):
    num = 0
    for i in list:
        if i % 2 == 0:
            num += 1
        else:
            continue
    return num

all = 3 ** N
Not = 2 ** (Num_of_even(A))
print(all - Not)

Submission status: Accepted

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

all_sym_pattern = 3**N
all_not_sym_pattern = 1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
if __name__ == '__main__':
    N = raw_input()
    A = map(int, raw_input().split())
    c_total = 1
    c_odd = 1
    for a in A:
        c_total *= 3
        if a % 2 == 0:
            c_odd *= 2
    print c_total - c_odd

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
count=1
odd=1
for i in a:
    if i % 2 ==0:
        count *= 3
        odd *= 2
    else:
        count *= 3

print(count-odd)

Submission status: Accepted

Solution code:
# (c) midandfeed
n = int(input())
q = [int(x) for x in input().split()]
nodd = 0
for i in q:
	if i&1:
		nodd += 1
print(pow(3,n)-pow(2,n-nodd))

Submission status: Accepted

Solution code:
n=input()
a=map(int,raw_input().split())
ans=3**n
rem=1
for v in a:
    if v%2==0: rem*=2
ans-=rem
print ans

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
num = input()
num = 3**int(num) 
data = input().rstrip().split(" ")
c=1
for i in data:
    if int(i) % 2 == 0:
        c *= 2
print(num-c)