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: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# !/usr/bin/env python
# vim: set fileencoding=utf-8 :

"""
#
# Author:   Noname
# URL:      https://github.com/pettan0818
# License:  MIT License
# Created: 日 10/22 21:08:14 2017

# Usage
#
"""
from functools import reduce
from itertools import repeat


def multipler(x, y):
    return x*y

def hundred_or_one(l: list):
    return [True if x == 100 else False for x in l]
    # return [True if x == 1 or x == 100 else False for x in l]

def check_odds(l :list):
    return [True if x % 2 == 0 else False for x in l]

def check_hun(l: list):
    return [True if x == 100 else False for x in l]

def main(num, data:list):
    """
    >>> main(1, [2])
    1
    >>> main(1, [3])
    2
    >>> main(10, [90,52,56,71,44,8,13,30,57,84])
    58921
    >>> main(2, [2,3])
    7
    >>> main(2, [100,100])
    3
    >>> main(1, [100])
    1
    >>> main(2, [1,1])
    8
    >>> main(1, [1])
    2
    >>> main(2, [1,2])
    7
    >>> main(2, [1,3])
    8
    >>> main(2, [1,100])
    >>> main(3, [1,1,100])
    >>> main(3, [1,100,100])
    """
    hun_one = hundred_or_one(data)
    odds = check_odds(data)  # 偶数の数
    huns = check_hun(data)

    basis = [2 if t else 3 for t in hun_one]
    remover = [2 if o else 1 for o in odds]

    remover_num = int(reduce(multipler, remover))
    if sum(huns) > 0:
        remover_num = int(remover_num / 2 ** sum(huns))

    basic_answer = reduce(multipler, basis)
    # print(basic_answer)
    # print(remover_num)
    return basic_answer - remover_num

if __name__ == '__main__':
    # import doctest
    # doctest.testmod()
    num = int(input())
    data = input().split(" ")
    data = [int(i) for i in data]

    print(main(num, data))

Submission status: Wrong Answer

Solution code:
N=input()
a=list(map(int,raw_input().split()))
#print a
b=[-1,0,1]

gusu=[]
kisu=[]


for h,i in enumerate(a):
	gusu_cnt=0
	kisu_cnt=0
	for j in b:
		if i+j>=1 and i+j<=100:
			#print i+j
			if (i+j)%2==0:
				gusu_cnt+=1
			else:
				kisu_cnt+=1
	#print h,i,j,gusu_cnt,kisu_cnt
	gusu.append(gusu_cnt)
	kisu.append(kisu_cnt)
	#ans+= gusu_cnt*pow(3,N-i+1)

#print "#gusu"
#print gusu
#print "#kisu"
#print kisu

ans=0
ans_sum=0
for i in range(N):
	ans=1
	for j in range(N):
		#print i,j
		if i==j:
			ans=ans*gusu[i]
		elif j<i:
			ans=ans*kisu[j]
		elif i<j:
			ans=ans*(gusu[j]+kisu[j])
		#print i,j,gusu[i],kisu[j],ans

	#print i,ans
	ans_sum+=ans

print ans_sum

Submission status: Wrong Answer

Solution code:
N=input()
a=list(map(int,raw_input().split()))
#print a
b=[-1,0,1]

gusu=[]
kisu=[]


for h,i in enumerate(a):
	gusu_cnt=0
	kisu_cnt=0
	for j in b:
		if i+j>=0 and i+j<=100:
			#print i+j
			if (i+j)%2==0:
				gusu_cnt+=1
			else:
				kisu_cnt+=1
	#print h,i,j,gusu_cnt,kisu_cnt
	gusu.append(gusu_cnt)
	kisu.append(kisu_cnt)
	#ans+= gusu_cnt*pow(3,N-i+1)

#print "#gusu"
#print gusu
#print "#kisu"
#print kisu

ans=0
ans_sum=0
for i in range(N):
	ans=1
	for j in range(N):
		#print i,j
		if i==j:
			ans=ans*gusu[i]
		elif j<i:
			ans=ans*kisu[j]
		elif i<j:
			ans=ans*(gusu[j]+kisu[j])
		#print i,j,gusu[i],kisu[j],ans

	#print i,ans
	ans_sum+=ans

print ans_sum

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# !/usr/bin/env python
# vim: set fileencoding=utf-8 :

"""
#
# Author:   Noname
# URL:      https://github.com/pettan0818
# License:  MIT License
# Created: 日 10/22 21:08:14 2017

# Usage
#
"""
from functools import reduce
from itertools import repeat


def multipler(x, y):
    return x*y

def hundred_or_one(l: list):
    return [True if x == 1 or x == 100 else False for x in l]

def check_odds(l :list):
    return [True if x % 2 == 0 else False for x in l]

def check_hun(l: list):
    return [True if x == 100 else False for x in l]

def main(num, data:list):
    """
    >>> main(100, list(repeat(99, 100)))
    >>> main(1, [2])
    1
    >>> main(1, [3])
    2
    >>> main(10, [90,52,56,71,44,8,13,30,57,84])
    58921
    >>> main(2, [2,3])
    7
    >>> main(2, [1,1])
    3
    >>> main(2, [100,100])
    3
    >>> main(1, [100])
    1
    >>> main(1, [1])
    1
    """
    hun_one = hundred_or_one(data)
    odds = check_odds(data)  # 奇数の数
    huns = check_hun(data)

    basis = [2 if t else 3 for t in hun_one]
    remover = [1 if o else 2 for o in odds]

    remover_num = int(reduce(multipler, remover))
    if sum(huns) > 0:
        remover_num = int(remover_num / 2 ** sum(huns))

    basic_answer = reduce(multipler, basis)
    # print(basic_answer)
    # print(remover_num)
    return basic_answer - remover_num

if __name__ == '__main__':
    import doctest
    doctest.testmod()
    num = int(input())
    data = input().split(" ")
    data = [int(i) for i in data]

    print(main(num, data))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
print = sys.stdout.write

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

def checkCorrect(l):
    total = 1
    for i in l:
        total *= i
    if total % 2 == 0:
        return True
    return False

# Seen is a set of tuples
seen = set()
def recurse(t,max_depth,original=None,depth=0,total=0,seen=None):
    if seen == None:
        original = t
        seen = set()
        
    if checkCorrect(t) and t not in seen:
        total += 1
        seen.add(t)

    #print(str(depth) + "\n")
    for i in range(depth,max_depth):
        #if depth < max_depth:
        p1 = list(t)
        p1[i] -= 1

        p2 = list(t)
        p2[i] += 1
            
        p1 = tuple(p1)
        p2 = tuple(p2)
            
        if p1 not in seen and abs(p1[i] - original[i]) <= 1:
            total = recurse(p1,max_depth,original,depth+1,total,seen)[0]
        if p2 not in seen and abs(p2[i] - original[i]) <= 1:
            total = recurse(p2,max_depth,original,depth+1,total,seen)[0]
        
    return total,seen

s = tuple(s)
print(str(recurse(s,N)[0]))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# !/usr/bin/env python
# vim: set fileencoding=utf-8 :

"""
#
# Author:   Noname
# URL:      https://github.com/pettan0818
# License:  MIT License
# Created: 日 10/22 21:08:14 2017

# Usage
#
"""
from functools import reduce


def multipler(x, y):
    return x*y

def hundred_or_one(l: list):
    return [True if x == 1 or x == 100 else False for x in l]

def check_odds(l :list):
    return [True if x % 2 == 0 else False for x in l]

def check_hun(l: list):
    return [True if x == 100 else False for x in l]

def main(num, data:list):
    """
    >>> main(10, [90,52,56,71,44,8,13,30,57,84])
    >>> main(2, [1,1])
    >>> main(1, [100])
    >>> main(1, [1])
    """
    hun_one = hundred_or_one(data)
    odds = check_odds(data)  # 奇数の数
    huns = check_hun(data)

    basis = [2 if t else 3 for t in hun_one]
    remover = [2 if o else 1 for o in odds]
    remover_num = int(reduce(multipler, remover))
    if sum(huns) > 0:
        remover_num = int(remover_num / 2 ** sum(huns))

    basic_answer = reduce(multipler, basis)
    return basic_answer - remover_num

if __name__ == '__main__':
    num = int(input())
    data = input().split(" ")
    data = [int(i) for i in data]

    print(main(num, data))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
print = sys.stdout.write

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

def checkCorrect(l):
    for i in l:
        if i % 2 == 0:
            return True
    return False

# Seen is a set of tuples
seen = set()
def recurse(t,max_depth,original=None,depth=0,total=0,seen=None):
    if seen == None:
        original = t
        seen = set()
        
    if checkCorrect(t) and t not in seen:
        total += 1
        seen.add(t)
    
    for i in range(depth,max_depth):
        #if depth < max_depth:
        p1 = list(t)
        p1[i] -= 1

        p2 = list(t)
        p2[i] += 1
            
        p1 = tuple(p1)
        p2 = tuple(p2)
        #print(p1,p2,depth,t)
            
        if p1 not in seen and abs(p1[i] - original[i]) <= 1:
            total = recurse(p1,max_depth,original,depth+1,total,seen)[0]

        if p2 not in seen and abs(p2[i] - original[i]) <= 1:
            total = recurse(p2,max_depth,original,depth+1,total,seen)[0]
        
    return total,seen

s = tuple(s)
print(str(recurse(s,N)[0]))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# !/usr/bin/env python
# vim: set fileencoding=utf-8 :

"""
#
# Author:   Noname
# URL:      https://github.com/pettan0818
# License:  MIT License
# Created: 日 10/22 21:08:14 2017

# Usage
#
"""
from collections import deque
from functools import reduce



def multipler(x, y):
    return x*y

def hundred_or_one(l: list):
    return [True if x == 1 or x == 100 else False for x in l]

def check_odds(l :list):
    return [True if x % 2 == 0 else False for x in l]

def main(num, data:list):
    """
    >>> main(10, [90,52,56,71,44,8,13,30,57,84])
    """
    hun_one = hundred_or_one(data)
    odds = check_odds(data)

    basis = [2 if t else 3 for t in hun_one]
    remover = [2 if o else 1 for o in odds]
    remover_num = reduce(multipler, remover)
    if sum(hun_one) > 0:
        remover_num = remover_num - 2 ** sum(hun_one)

    return reduce(multipler, basis) - remover_num

if __name__ == '__main__':
    num = int(input())
    data = input().split(" ")
    data = [int(i) for i in data]

    print(main(num, data))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
print(a)

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

x = 3 ** n - 2 ** cnt

print(x)

Submission status: Wrong Answer

Solution code:
def get_result(A):
    res = 1
    total = 1
    for i, ai in enumerate(A):
        res *= 2 if ai % 2 == 0 else 1
        total *= 3 if ai > 1 else 2
    return total - res
n = input()
A = [int(ai) for ai in input().split()]
print(get_result(A))

Submission status: Wrong Answer

Solution code:
def get_result(A):
    res = 1
    total = 1
    for i, ai in enumerate(A):
        print(ai, res, total)
        res *= 2 if ai % 2 == 0 else 1
        total *= 3 if ai > 1 else 2
    return total - res
n = input()
A = [int(ai) for ai in input().split()]
print(get_result(A))

Submission status: Wrong Answer

Solution code:
def get_result(A):
    res = 1
    total = 1
    for i, ai in enumerate(A):
        print(ai, res, total)
        res *= 2 if ai % 2 == 0 else 1
        total *= 3 if ai > 1 else 2
    return total - res

A = [int(ai) for ai in input().split()]
print(get_result(A))

Submission status: Wrong Answer

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

sim = 1
odd = 1
for i in xrange(N):
  ai = A[i]
  if ai == 1 or ai == 100:
    sim *= 2
  else:
    sim *= 3
    if ai % 2 == 0:
      odd *= 2

print sim - odd

Submission status: Wrong Answer

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

from itertools import product

ans = 0
for P in product(range(3), repeat=10):
    even = 0
    for i in range(n):
        b = A[i] + P[i] - 1
        even |= (b % 2) == 0
    if even:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

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

print(dfs(np.array([]), a, n, 0))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
n = int(input())
a = list(map(int,input().split()))
b = [[0] * 3 for i in range(n)]
for i in range(n):
    b[i][0] = a[i] - 1
    b[i][1] = a[i]
    b[i][2] = a[i] + 1
c = list(itertools.product(*b))
cnt = 0
for i in range(len(c)):
    x = c[i][0]
    for j in range(1, n):
        x = x * c[i][j]
    if x % 2 == 0:
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
# coding: utf-8

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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	B
# CreatedDate:  2020-09-26 23:51:48 +0900
# LastModified: 2020-09-26 23:59:21 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


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

    



if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import  itertools as it

N,*A = map(int,open(0).read().split())

cnt = 0
for Z in it.product(range(3),repeat=N):
  t = 1
  for z,a in zip(Z,A):
    t*=(a+z-1)
  if t%2 == 0:
    cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
N,*A = map(int,open(0).read().split())

cnt = 0

e = 0
o = 0
for a in A:
  if a%2 ==0:
    e+=1
  else:
    o+=1

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

Submission status: Accepted

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

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

Submission status: Accepted

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

if __name__ == "__main__":
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from itertools import product

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

count = 0
for C in product((-1, 0, 1), repeat=n):
  total = 1
  for a, c in zip(A, C):
    total *= (a + c)
  if total % 2 == 0:
    count += 1
print(count)

Submission status: Accepted

Solution code:
from functools import reduce

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

n = reduce(lambda x, y: x * y, (1 if a % 2 else 2 for a in A))
print(3 ** N - n)

Submission status: Accepted

Solution code:
N = int(input())
even = sum([1 for i in input().split() if int(i)%2==0])
print(3**N-2**even if even!=0 else 3**N-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = [int(s) for s in input().split()]

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

Submission status: Accepted

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

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

odd = 1
for v in a:
    if v % 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()))
evens=0
for a in A:
    if a%2==0:
        evens+=1

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

Submission status: Accepted

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

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

print(3**N-sum)

Submission status: Accepted

Solution code:
# row = [int(x) for x in input().rstrip().split(" ")]
# n = int(input().rstrip())
# s = input().rstrip()
# row = [int(input().rstrip()) for _ in range(n)]

def resolve():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip())
    a_list = [int(x) for x in input().rstrip().split(" ")]

    # 奇数になる組み合わせ
    odd = 1
    for a in a_list:
        if a % 2 == 0:
            odd *= 2

    print(3 ** len(a_list) - odd)



if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

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

Submission status: Accepted

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

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 = 3**len(a)
cnt = 1

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

print(ans - cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    even_count = 0

    for a in a_list:
        if a % 2 == 0:
            even_count += 1

    print(3 ** n - 2 ** even_count)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


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

    ans = 3 ** N
    excl = 1

    for x in A:
        if x % 2 == 0:
            excl *= 2

    ans -= excl

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
'''
Created on 2020/09/02

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write

  N=int(pin())
  A=list(map(int,pin().split()))
  cnt=0
  for i in A:
    if i%2==0:
      cnt+=1
  print(3**N-2**cnt)
  return
main()
#解説AC

Submission status: Accepted

Solution code:
import numpy as np

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

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

ans = pow(3, n) - k

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
a = len(A)
t = 1 # odd

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
combiIncludingOdd = 3**len(A)

c = 1
for a in A:
    if a % 2 == 0:
        c*=2
print(combiIncludingOdd-c)

Submission status: Accepted

Solution code:
# CODE FESTIVAL 2017 予選 C: B – Similar Arrays
N = int(input())
A = [int(i) for i in input().split()]

num_even = len([i for i in A if i % 2 == 0])
print(3 ** N - 2 ** num_even)

Submission status: Accepted

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

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









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

Submission status: Accepted

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

odd_pattern = [1 if A&1 else 2 for A in a]
all_odd = 1
for p in odd_pattern:
    all_odd *= p
# 全パターン数 - すべてが奇数となるパターン数
print(3**n - all_odd)

Submission status: Accepted

Solution code:
print(3**int(input())-2**(sum(~l&1 for l in map(int,input().split()))))

Submission status: Accepted

Solution code:
n = int(input())
A = tuple(map(int, input().split()))
ans = 0
from itertools import product
for P in product([-1, 0, 1], repeat=n):
    B = 1
    for a, p in zip(A, P):
        B *= (a+p)
        if B%2 == 0:
            ans += 1
            break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

b = [[] for _ in range(n)]
for i in range(n):
    b[i] = [i for i in range(max(0,a[i]-1),a[i]+2)]


def dfs(i,v,n,b):
    if i==n:
        if v==0:
            return 1
        else:
            return 0
    else:
        res = 0
        for j in b[i]:
            res += dfs(i+1,v*(j%2),n,b)

        return res
    

ans = dfs(0,1,n,b)
print(ans)

Submission status: Accepted

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

b = [[] for _ in range(n)]
for i in range(n):
    b[i] = [i for i in range(max(0,a[i]-1),a[i]+2)]


def dfs(i,v,n):
    if i==n:
        if v==0:
            return 1
        else:
            return 0
    else:
        res = 0
        for j in b[i]:
            res += dfs(i+1,v*(j%2),n)

        return res
    
    
ans = 0
ans = dfs(0,1,n)
print(ans)

Submission status: Accepted

Solution code:
import sys, math
from functools import lru_cache
from collections import deque

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N = ii()
    A = list(mi())
    cnt = 0
    
    p = [1]*N
    for j in range(N-1):
        p[j+1] = 3*p[j]

    for i in range(3**N):
        B = [0]*N
        flg = False
        for j in range(N):
            t = (i//p[j])%3
            if t == 0:
                B[j] = A[j]
            if t == 1:
                B[j] = A[j]+1
            if t == 2:
                B[j] = A[j]-1

            if B[j]%2 == 0:
                flg = True
        
        if flg:
            cnt += 1

    print(cnt)

        

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#B - Similar Arrays
N = int(input())
A = list(map(int,input().split()))

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

ans = tot_cnt - all_odd
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rf = lambda: map(float, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n = ri()
a = rl()
t = 1
for i in a:
    if i&1==0:
        t*=2
print(3**n-t)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()

data = l()

od = 0
ev = 0

for i in range(n):
    if data[i] % 2 == 0:
        ev += 1
    else:
        od += 1

if od == 0:
    od = 1

print(pow(3,n) - pow(2,ev))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
res = 1
for x in a:
  if x % 2 == 0: res *= 2
print(pow(3, N) - res)

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:
N = int(input())
A = list(map(int, input().split()))
e_cnt = 0
for i in range(len(A)):
  if A[i]%2==0:
    e_cnt += 1
print(3**N-2**e_cnt)

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

#bのうちどれか1つが偶数ならばOK
#bは3通り
#∴3**Nから全部が奇数のパターンを引けばOK

odd_pattern = 1

for i in range(N):
    if A_list[i]%2 == 0:
        odd_pattern *= 2
        
print(3**N - odd_pattern)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
	n = int(input())
	arr =list(map(int , input().split()))
	ans = 0
	allseq = 1
	bad = 1
	# find the no of sequence which has product of all numbers odd
	# subtract the total no of sequence  
	for i in range(0 , n):
		if arr[i]%2==0:
			bad = bad*2# b can take value arr[i]-1 or arr[i]+1
		else:
			bad = bad*1# b can take value only arr[i]
		allseq = allseq*3# total no of elements
	print(allseq-bad)
if __name__=="__main__":
	main()

Submission status: Accepted

Solution code:
N =int(input())
AAA = map(int,input().split())
AA = list(AAA)
total = 3**len(AA)
total2 = 0
total3 = 0
for i in AA:
  if i%2==0:
    total2 +=1
total3 = 2**total2
ans = total - total3
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, 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())
ll = list(map(int, input().split()))
ans = 3**n
odd = 1
for l in ll:
  if l % 2 == 1:
    pass
  elif l % 2 == 0:
    odd *= 2

print(ans - odd)

Submission status: Accepted

Solution code:
from itertools import product
n = int(input())
a = list(map(int, input().split()))

ans = 0
for x in product([-1, 0, 1], repeat=n):
    b = [ai + xi for ai, xi in zip(a, x)]
    if any(bi % 2 == 0 for bi in b):
        ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in itertools.product((-1,0,1), repeat=N):
    for j in range(N):
        if (A[j]+i[j])%2==0:
            ans += 1
            break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

even=0
for i in l:
    if i%2==0: even+=1

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

Submission status: Accepted

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

cnt = 1

for i in lis:
    if i % 2 == 0:
        cnt *= 2

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