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:
import itertools

n = int(input())
a = tuple(map(int,input().split()))
ans = 0
for l in itertools.product([-1,0,1],repeat=n):
  t = 1
  for i in range(n):
    t*=(a[i]+l[i])
  if t%2==0:
    ans+=1
print(ans)

Submission status: Accepted

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

import fractions
import copy
import bisect
import math
import numpy as np
import itertools
from itertools import combinations_with_replacement
#import math#数学的計算はこれでいける。普通に0.5乗しても計算可能
#w=input()
from operator import itemgetter
from sys import stdin
#input = sys.stdin.readline#こっちの方が入力が早いが使える時に使っていこう
from operator import mul
from functools import reduce
from collections import Counter
#from collections import deque

#input = stdin.readline


j=0
k=0
n=3
r=1
a=[0]
#n=int(input())
#r=int(input())
#print(M)
#A=int(input())
#B=int(input())
#print(N)
"1行1つの整数を入力を取得し、整数と取得する"


#number_list=list(map(int, input().split(" ")))#数字の時
#print(number_list)
"12 21 332 とか入力する時に使う"
"1行に複数の整数の入力を取得し、整数として扱う"

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#メモ
for i in number_list:#こっちの方がrage使うより早いらしい
    print(number_list[i-1])#

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'''
x=[]
y=[]
for i in range(N):
    x1, y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
print(x)
print(y)
"複数行に2数値を入力する形式 x座標とy座標を入力するイメージ"
'''

'''
mixlist=[]
for i in range(N):
    a,b=input().split()
    mixlist.append((int(a),b))
print(mixlist)
"複数行にintとstrを複合して入力するやつ，今回はリスト一つで処理している"
'''

'''
#array=[input().split()for i in range(N)]
#print(type(array[0][0]))
#print(array)
"正方行列にstr型の値を入力"
'''

#brray=[list(map(int, input().split(" ")))for i in range(N)]
#print(type(brray[0][0]))
#print(brray)
'''
入力
1 2
4 5
7 8
出力結果
[[1, 2], [4, 5], [7, 8]]
'''
"列数に関して自由度の高いint型の値を入力するタイプの行列"
#以下に別解を記載
#N, M = [int(i) for i in input().split()]
'''
table = [[int(i) for i in input().split()] for m in range(m)]

print(type(N))
print(N)
print(type(M))
print(M)

print(type(table))
print(table)
'''




#s=input()
#a=[int(i) for i in s]
#print(a[0])
#print([a])
#単数値．桁ごとに分割したい．入力と出力は以下の通り
#イメージとして1桁ごとにリストに値を入れているかんじ
#intを取ると文字列分解に使える
'''
入力
1234
出力
1
[[1, 2, 3, 4]]
'''




'''
word_list= input().split(" ")
print(word_list[0])
"連続文字列の入力"
"qw er ty とかの入力に使う"
"入力すると空白で区切ったところでlistの番号が与えられる"
'''



'''
A, B, C=stdin.readline().rstrip().split()#str style 何個でもいけることが多い
print(A)
"リストではなく独立したstr型を入れるなら以下のやり方でOK"
'''


#a= stdin.readline().rstrip()
#print(a.upper())
"aという変数に入っているものを大文字にして出力"


#a,b=map(int, input().split())  #int style 複数数値入力　「A B」みたいなスペース空いた入力のとき

#なんかうまく入力されるけど
#a=[[int(i) for i in 1.strip()]for 1 in sys.stdin]
#a = [[int(c) for c in l.strip()] for l in sys.stdin]]
#print(a)
#複数行の数値を入力して正方行列を作成


##############################################################################################
##############################################################################################
#under this line explains example calculation



'''
コンビネーションの組み合わせの中身を出力する形式
for i in itertools.combinations(brray, 2)
combinationsをpermutationsにすれば順列になる
今回なら(abc133B)
入力
1 2
5 5
-2 8
出力
[[1, 2], [5, 5], [-2, 8]]
もちろん一次元リストでも使えるし
何よりiもリストのように使えるので便利
'''

#nCr combination
'''
def cmb(n,r):
    #When n < r , this function isn't valid
    r= min(n-r,r)
    #print(n,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n-r, -1))
    #flochart mul(n,n-1)=x
    #next     mul(x,n-2)........(n-r+1,n-r)
    #mul read a,b and returns a*b

    under = reduce(mul, range(1, r+1))
    #print(over, under)
    #reduce is applied mul(1,2)=2
    #next   mul(2,3)=6
    #next   mul(6,4)=4.........last(r!,r+1)=r+1!

    return over // under
    #// is integer divide
    #calc example 5C2
    #over=5*4*3
    #under=3*2*1
a = cmb(n, r)
#print(a)
'''

'''
import itertools
from itertools import combinations_with_replacement

combinationについて
以下の違いを意識しよう
combinations() p, r 長さrのタプル列、ソートされた順で重複なし

combinations_with_replacement() p, r 長さrのタプル列、ソートされた順で重複あり


使用例 　　　　　　　　　　　                  出力　　
combinations('ABCD', 2)　　　　　　　　　　　　AB AC AD BC BD CD

combinations_with_replacement('ABCD', 2)　　 AA AB AC AD BB BC BD CC CD DD
'''



'''
#集計
#example
#a=[2,2,2,3,4,3,1,2,1,3,1,2,1,2,2,1,2,1]
#a=Counter(a)
for i in a.most_common(n):print(i)
#most_common()メソッドは、出現回数が多い要素順にCounterオブジェクトを並び替えます。
#引数にint型の数字nを設定した場合は、出現回数が高い上位ｎ個の要素を返します。
#何も設定しなければ、コンテナ型にあるすべての要素を出現回数の順番に並び替えたタプル型オブジェクトを返します。
#out put
#(2, 8)
 #(1, 6)
#(3, 3)
#(4, 1)
'''


#二部探索(binary search)
#A = [1, 2, 3, 3, 3, 4, 4, 6, 6, 6, 6]
#print(A)
#index = bisect.bisect_left(A, 5) # 7 最も左(前)の挿入箇所が返ってきている
#A.insert(index, 5)
#print(index)
#print(A)
'''
bisect.bisect_left(a, x, lo=0, h=len(a))
引数
a: ソート済みリスト
x: 挿入したい値
lo: 探索範囲の下限
hi: 探索範囲の上限
(lo, hiはスライスと同様の指定方法)
bisect_leftはソートされたリストaに対して順序を保ったままxを挿入できる箇所を探索します。leftが示す通り、aにすでにxが存在している場合は、挿入箇所は既存のxよりも左側になります。また、lo, hiを指定することで探索範囲を絞り込むことも可能です。デフォルトはaの全体が探索対象です。
'''

'''
素数の判定
'''


def is_prime(n):
    if n == 1: return False

    for k in range(2, int(np.sqrt(n)) + 1):
        #sqrt(n)+1以上は考えて約数はないので却下
        if n % k == 0:
            return False
            #割り切れたらFalse
    return True


'''
npのmaxとmaximumの違い
xs = np.array([1, -2, 3])
np.max(xs, 0)
この出力は3となります．[1, -2, 3]と0の4つの数字のうち，最も大きい値を出力します．

一方で，[max(1, 0), max(-2, 0), max(3, 0)]を出力したい時があります．
その時は，numpyのmaximum関数を用います．

xs = np.array([1, -2, 3])
np.maximum(xs, 0)  # [1, 0, 3]

'''

def factorial(x, mod=10**9+7):
    # x!
    # 階乗
    # ex) factorial(5) = 120
    tmp = 1
    for i in range(1, x+1):
        tmp = (tmp * i) % mod
    return tmp
    '''
    Basically, when you do a**d % n, you actually have to calculate a**d, which could be quite large.
    But there are ways of computing a**d % n without having to compute a**d itself, and that is what pow does.
    '''


########################################################################
########################################################################
#b2=a[:]  #1次元のときはコピーはこれで良い
#print(b2)

#a= [[0]*3 for i in range(5)] #2次元配列はこう準備、[[0]*3]*5だとだめ
#b3=copy.deepcopy(a)  #2次元配列はこうコピーする
#print(b3)

'''
ascii_letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
digits = '0123456789'
hexdigits = '0123456789abcdefABCDEF'
letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv...\xaf\xb0...
lowercase = 'abcdefghijklmnopqrstuvwxyz'
octdigits = '01234567'
printable = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTU...
punctuation = '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
whitespace = '\t\n\x0b\x0c\r '
'''
def main():
    n=3
    steps=0
    state=0
    w=1
    j=0
    k=0
    #lenを変数に置くと事故るから注意
    n=int(input())
    #a,b=input().split(" ")#a,bがともに文字列のとき
    #a,b=map(int, input().split(" "))
    #mapでとってもstrで変換すればappend可能
    nl=list(map(int, input().split(" ")))#数字の時
    sum=0
    times=1
    even_lis=[0]*n
    odd_lis=[0]*n
    for i in range(n):
        if nl[i]==1:
                even_lis[i]=1
                odd_lis[i]=1
        if nl[i]%2==0:
                even_lis[i]=1
                odd_lis[i]=2
        else:
            even_lis[i]=2
            odd_lis[i]=1
    for i in range(n):
     #for j in range(0,i):
        times=times*(odd_lis[i])
    sum=3**n-times
     #for k in range(i,n):
    #times=times*(even_lis[k])

    #    sum=sum+even_lis[i]*3**(n-1-i)
    #    sum=sum+odd_lis[i]

    '''
        if nl[i]%2==0:
            sum=sum+3**(len(nl[i:])-1)
        elif nl[i]%2==1:
            sum=sum+2*3**(len(nl[i:])-1)
    '''
    print(sum)
    #s=input()
    #a=[i for i in s]#int取るとstrでも行ける
    #print(''.join(a[:-8]))
    #print(a)
    #brray=[list(map(int, input().split(" ")))for i in range(N)]
    #print(brray)


    for i in range(1,n+1,2):#これで1個飛ばしループになる
     pass
     #print(i)

    l = ['aaa', 'bbb', 'ccc']
    x=l.index('aaa')#ある要素のインデックス番号を取得
    #s = ''.join(l)
    #s = " ".join(map(str,a))#スペースを空ける時はこう
    #print(s)
    # aaabbbccc

    #if state in known_states and not flag: # state => 2 steps => 5
        #こうやってある要素がリストの中にあるか探すのか
    #print(f'steps: {steps}, state: {state}')
    #こう書いてあるとデバックしやすい

    #dp= [[0]*3 for i in range(5)]#列　行
    #dp用の0の入ったやつ
    #dp= [[0]*(w+1) for i in range(n+1)]#0からwまでのw+1回計算するから
    #print(dp)＃初期条件が入る分計算回数+1列分必要(この場合は判断すべきものの数)
    DP = np.zeros(w+1, dtype=int)#これでも一次元リストが作れる
    exdp=np.zeros((3,4)) # ３×４の２次元配列を生成。2次元ならこう
    #dtypeは指定しないとfloatになる
    #for i in range(n):#ちょっとした入力に便利
    #    a, b = map(int, input().split())
        #dp[i][0] += [a]
        #これだとintとlistをつなぐことになって不適
    #    dp[i] += [a]
    #    dp[i] += [b]
        #これはうまくいく
        #やり方はいろいろあるということ
    #print(dp)


    #brray=[list(map(int, input().split(" ")))for i in range(N)
    #print(brray)



    '''
    入力
    1234
    出力
    [1, 2, 3, 4]
    '''
    pin_l=["x" for i in range(10)]#内包表記に慣れろ
    #print(pin_l)

    ls = ["a", "b", "c", "d", "e"]


    #print(ls[2:5])
    #スライスでの取得

    #print(ls[:-3])
    #一番左端から右から3番目より左まで取得

    #print(ls[:4:2])
    #スライスで1個飛ばしで取得
    #ないときは左端スタート
    #始点のインデックス番号 : 終点のインデックス番号 : スキップする数+1
    #print(ls[::2])
    '''
    lsというリストの場合に、1つ飛びの値を取得したい場合には
    ls[::2]
    のようにします。こうすると、
    ["a", "c", "d"]と出力される
    '''

if __name__ == "__main__":
    main()

Submission status: Accepted

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

def judge(i, nums):
    global ans
    if i == n:
        m = 1
        for j in range(n):
            m *= nums[j]
        
        if m % 2 == 0:
            ans += 1
    else:
        nums[i] = a[i] - 1
        judge(i + 1, nums)
        nums[i] = a[i]
        judge(i + 1, nums)
        nums[i] = a[i] + 1
        judge(i + 1, nums)
        
nums = [0] * n
judge(0, nums)
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

def dfs(A, a, n, ans):
  if len(A) == n:
    tmp = np.array(A) + a
    if sum(tmp % 2) < len(A):
      ans += 1
    return ans
  
  for i in range(-1, 2):
    A.append(i)
    ans = dfs(A, a, n, ans)
    A.pop()
    
  return ans

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

print(dfs([], a, n, 0))

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))

tmp = (A%2==0).sum()

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

Submission status: Accepted

Solution code:
import math
import copy

n = int(input())
a = [int(x) for x in input().split()]
neko = 3 ** n
nya = 1
for i in a:
    if i%2 == 0:
        nya *= 2
print(neko-nya)

Submission status: Accepted

Solution code:
import itertools,sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N = I()
A = LI()
ans = 0
for x in [x for x in itertools.product([-1,0,1],repeat=N)]:
    calc = 1
    for i in range(N):
        calc *= A[i]+x[i]
    if calc%2==0:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)

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

def f(i, v):
    if i == n:
        return any(x % 2 == 0 for x in v)

    ans = 0
    for d in (-1, 0, 1):
        v_ = v[:]
        v_.append(A[i]+d)
        ans += f(i+1, v_)

    return ans

print(f(0, []))

Submission status: Accepted

Solution code:
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 ** len(a) - all_odd)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 3**n
aa = 1
for i in A:
    if i%2==0:aa*=2

print(ans-aa)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    l=list(map(int,input().split()))
    cnt=1
    for i in l:
        if i%2==1:
            cnt*=1
        else:
            cnt*=2
    print(3**n-cnt)
resolve()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    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)
    
resolve()

Submission status: Accepted

Solution code:
# coding: utf-8
import re
import math
from collections import defaultdict
from collections import deque
import itertools
from copy import deepcopy
import random
import time
import os
import queue
import sys
import datetime
from functools import lru_cache
#@lru_cache(maxsize=None)
readline=sys.stdin.readline
sys.setrecursionlimit(2000000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def is_pow(a,b):#aはbの累乗数か
    now=b
    while now<a:
        now*=b
    if now==a:return True
    else:return False
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def get_facs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod_>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:return num
def get_primes(n,type="int"):
    if n==0:
        if type=="int":return []
        else:return [False]
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=1):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(a,b,c):
    if a:return b
    else:return  c
def join(A,c=""):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
def factorize(n,type_="dict"):
    b = 2
    list_ = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            list_.append(b)
        b+=1
    if n > 1:list_.append(n)
    if type_=="dict":
        dic={}
        for a in list_:
            if a in dic:
                dic[a]+=1
            else:
                dic[a]=1
        return dic
    elif type_=="list":
        return list_
    else:
        return None
def floor_(n,x=1):
    return x*(n//x)
def ceil_(n,x=1):
    return x*((n+x-1)//x)
    return ret
def seifu(x):
    return x//abs(x)
######################################################################################################
def main():
    n=int(input())
    A=list(map(int,input().split()))
    ans=3**n
    mi=1
    for a in A:
        if a%2==0:
            mi*=2
        else:
            mi*=1
    ans-=mi
    print(ans)
main()

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

if odd == N:
    ans = 3**N - 1
else:
    ans = 3**N - 2**even

print(ans)

Submission status: Accepted

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

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
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 input(): return sys.stdin.readline().strip()
def INT(): return int(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()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()
kisu = 1

for i, a in enumerate(A):
    if a % 2 == 0:
        kisu *= 2
    else:
        kisu *= 1
print(3 ** N - kisu)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
def resolve():
    N=int(input())
    t=3**N
    s=1
    f=0
    for a in pin():
        if  a%2:
            f=1
            s*=1
        else:
            s*=2

    print(t-s)
#%%submit!
resolve()

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 == 1:
    cnt += 1
ans = 3**n - 2**(n-cnt)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, *a_l= map(int, open(0).read().split())
odd = 1
for a in a_l:
    tmp_odd = 0
    for i in [a-1, a, a+1]:
        if i % 2 == 1:
            tmp_odd += 1
    odd *= tmp_odd
ans = 3**n - odd
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#Aiについて取りうる値の範囲を考える
#すべての組み合わせから、すべて奇数のものを除く

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

all_pair = 1
odd_pair = 1

for i in range(n):
    if a_inputs[i]%2==0:
        odd_pair*=2
    else:
        odd_pair*=1
    all_pair*=3

print(all_pair-odd_pair)

Submission status: Accepted

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

cnt_even, cnt_odd = 0, 0
for i in range(n):
	if A[i] % 2 == 0:
		cnt_even += 1
	else:
		cnt_odd += 1

cnt = 3 ** n - (2 ** (cnt_even))
print(cnt)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(500*500)
n = int(input())
a = list(map(int, input().split()))
ans = 0

def dfs(i, p, sum):
    global ans
    if p == n:
        if sum % 2 == 0:
            ans += 1
    else:
        dfs(a[p], p+1, sum*a[p])
        dfs(a[p]+1, p+1, sum*(a[p]+1))
        dfs(a[p]-1, p+1, sum*(a[p]-1))

dfs(1, 0, 1)
print(ans)

Submission status: Accepted

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

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
  else:
    odd *= 1
ans = 3**n - odd
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

even = odd = 0

for a in A:
  if a%2:
    odd += 1
  else:
    even += 1
    
print(3**n - 2**even)

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:
import sys

input = sys.stdin.readline
MOD = 1000000007

N = int(input())

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

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

print(3**len(A)-2**odd)

Submission status: Accepted

Solution code:
N=int(input())
mylist=list(map(int,input().split()))
even=0
odd=0

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

Submission status: Accepted

Solution code:
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16)
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i):
            is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
## libs ##
from itertools import accumulate as acc
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
#======================================================#

def main():
    n = II()
    aa = MII()
    cnt = 3**n
    m = list(acc([2 if a%2==0 else 1 for a in aa ],lambda x,y: x*y))
    print(cnt-m[-1])


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

# B - Similar Arrays
def count_simular_arrays(arr):
	ans = 0
	
	for a in arr:
		for n in a:
			if n % 2 == 0:
				ans += 1
				break

	return ans


import copy

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

for i in range(-1, 2):
	arr.append([a[0] + i])

for i in range(1, n):
	copied = copy.deepcopy(arr)
	arr.clear()
	
	for c in copied:
		for j in range(-1, 2):
			arr.append(c + [a[i]+j])

print(count_simular_arrays(arr))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

temp = 1
ans = 1
for a in A:
    if a % 2 == 0:
        temp *= 2
        ans *= 3
    else:
        temp *= 1
        ans *= 3

print(ans - temp)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

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

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

print(3**n-cnt)

Submission status: Accepted

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

ans = 1
for a in A:
    # if a == 1:
    #     ans *= 2
    # else:
        ans *= 3
# 全体から全部奇数の場合を引く
odd = 1
for a in A:
    if a%2 == 0:
        odd *= 2

print(ans-odd)

Submission status: Accepted

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

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:
n = int(input())
A = list(map(int,input().split()))
ans = 0
cnt = 0
for a in A:
    if a%2 == 0:
        cnt+=1
print(3**n - 2**cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

cnt = 0
for ai in A:
    if ai % 2 == 0:
        cnt += 1
        
print(3**N-2**cnt)

Submission status: Accepted

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

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    lis = readInts()
    # 補集合を求めるようなもの
    whole = 3 ** n
    ex = 1
    for x in lis:
        if x % 2 == 0:
            ex *= 2
    print(whole - ex)
if __name__ == '__main__':
  main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
from itertools import product

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = list(map(int, input().split()))
    bit = []
    for i in range(n):
        bit.append(list(range(A[i] - 1, A[i] + 2)))

    res = 0
    for pattern in product([0, 1, 2], repeat=n):
        value = 1
        for idx, i in enumerate(pattern):
            value *= bit[idx][i]

        if value % 2 == 0:
            res += 1

    print(res)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
n = int(input())

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

total = 3**n
ans = 1
for i in A:
    if i % 2 == 0:
        ans *= 2

print(total - ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = 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())
arr = list(map(int,input().split()))

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

print(ans-out)

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

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