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 = input()
A = map(int, raw_input().split())
x = 1
for a in A:
    if a%2==0:
        x *= 2
print 3**N - x

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
a = list(map(int, input().split()))
k = 1
for a_i in a:
    if a_i % 2 == 0:
        k *= 2
print(3 ** n - k)

Submission status: Accepted

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

z = 1
for i in a:
	c = 0
	for j in range(i - 1, i + 2):
		if j % 2 == 1:
			c += 1
	z *= c

print 3 ** n - z

Submission status: Runtime Error

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

a=[2 if i%2==0 for i in a else 1]

cnt=1

for i in a:
  cnt*=i
  
  
print(n-cnt)

Submission status: Runtime Error

Solution code:
import sys

input = sys.stdin.readline

def main():
    ans = 0
    n = int(input())
    A = list(map(int, input().split()))
    allB = exc = 1
    for i in n:
        allB *= 3
        if i%2 == 0:
            exc *= 2
    ans = allB - exc
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#ifndef LOCAL
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#else
#include <iostream>
#include <iomanip> 
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <memory>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; }
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}
#define fix(a) fixed << setprecision(a)
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'


void solve(){
  int n;
  cin >> n;
  int total = 1;
  int bad = 1;
  forn(i,n){
    int a;
    cin >> a;
    total *= 3;
    if (a%2){
      bad *= 1;
    } else {
      bad *= 2;
    }
  }
  cout << total - bad;
}

int main() {
  ios::sync_with_stdio(false);
  // cin.tie(0); cout.tie(0);
  int t = 1;
  // cin >> t;
  forn(i, t){
    solve();
  }
}

/* 

k (k-1) (k-1)



*/

Submission status: Runtime Error

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

Solution code:
import itertools

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
    for(auto i=begin(v); i != end(v); ++i){
        if(i !=begin(v)) os << ' ';
        os << *i;
    }
    return os;
}

ll ans,M[100007];

ll compME(ll b, ll e, ll m){  // bのe乗のmod m を返す
    if (e == 0) return 1;
    ans = compME(b, e / 2, m);
    ans = (ans * ans) % m;
    if (e % 2 == 1) ans = (ans * b) % m;
    return ans;
}

int main(){
    ll N,A[100007],T=1,C=1;
    cin >> N;
    rep(i,N){
        cin >> A[i];
        if(A[i]%2==0){
            T*=2;
        }
        C*=3;
    }
    cout << C-T << endl;
}

Submission status: Runtime Error

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

odd=True
for p in a:
  if p%2==0:
    odd=False
    
print(3**n-1-(1 if not odd else 0))

Submission status: Runtime Error

Solution code:
n = int(input())
l =0
for i in range(n):
  p=(int(input())
  if p %2==0:
     l+=1
     
print(3**n-2**l)

Submission status: Runtime Error

Solution code:
n = int(input())
l =0
for i in range(n):
  p=(int(input())
  if p %==0:
     l+=1
     
print(3**n-2**l)

Submission status: Runtime Error

Solution code:
for i in input().split():
    if int(i) % 2 == 0:
        cnt *= 2

print(3**n - cnt)

Submission status: Runtime Error

Solution code:
macro_rules! get {
    (Vec<$t:ty>) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let N = get!(u32);
    let A = get!(Vec<i64>);

    // 解は3^N - 2^(Aに含まれる偶数の個数)
    let M = A.iter()
        .filter(|&a| a % 2 == 0)
        .count();
    let ans = 3_i64.pow(N) - 2_i64.pow(M as u32);

    println!("{}", ans);
}

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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: Runtime Error

Solution code:
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cstring>
#include <map>
#include <set>
#include <cmath>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define INF 1145141919
typedef long long int ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

int main()
{
    int N; cin >> N;
    vector<int> A(N);
    ll ki=0, gu=0,tmp=1;
    REP(i,N){
        cin >> A[i];
        if(A[i]%2==0){
            tmp*=2;
        }else{
            tmp*=1;
        }
    }
    ll ans=llpow(3,N);
    cout << ans - tmp << endl;
    return 0;
}

Submission status: Runtime Error

Solution code:
N = int(input())

list =[]
for i in range(N):
    list.append(int(input()))
even = []
odd = []

for i in range(len(list)):
    if list[i] % 2 == 0:
        even.append(list[i])
    else:
        odd.append(list[i])

result = 3**N -(2**len(even))*(1**len(odd))

print(result)

Submission status: Runtime Error

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

Submission status: Runtime Error

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 and a != 100:
            c_odd *= 2
    print c_total - c_odd

Submission status: Runtime Error

Solution code:
N = int(input())
ans = 3 ** N
num = 1

for i in range(N):
    A = int(input())
    num *= (2-(A%2))

print(ans-num)

Submission status: Runtime Error

Solution code:
import itertools


def solve():
    N = int(input())
    A = list(map(int, input().split(" ")))
    matrix = [[] for _ in range(N)]
    for i in range(N):
        matrix[i].append(A[i] - 1)
        matrix[i].append(A[i])
        matrix[i].append(A[i] + 1)

    cnt = 0
    for element in list(itertools.product(*matrix)):
        for i in range(N):
            if element[i] % 2 == 0:
                cnt += 1
                break

    print(cnt)


 solve()

Submission status: Runtime Error

Solution code:
N = int(input())
a = map(int, input().split())
tmp = 3 ** N
g = len([c for c in a if a % 2 == 0])
print(tmp - (2 ** g))

Submission status: Runtime Error

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

N = int(input())

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

count = 1

for i in A:
	if A % 2 == 0:
		count *= 2
	else:
		pass

ans = (3 ** len(A)) - count

print(ans)