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.
Examples
Input
2
2 3
Output
7
Input
3
3 3 3
Output
26
Input
1
100
Output
1
Input
10
90 52 56 71 44 8 13 30 57 84
Output
58921
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
We are asked: Given N up to 10, and an array A of length N, each 1..100. Count number of integer sequences b (presumably integers, not necessarily positive? The problem states "integer sequences", but A_i are positive, and condition is similarity: |b_i - A_i| <= 1. So b_i can be A_i-1, A_i, or A_i+1, but must be integer. However, b_i could become 0 or negative if A_i = 1? Since A_i >=1, A_i-1 can be 0. And A_i+1 can be >100. That's allowed? Probably yes: the b_i are just integers, no restrictions besides similarity. So each b_i has three possible values: A_i - 1, A_i, A_i + 1, but we must ensure these are integers (they are). However, if A_i = 1, then A_i - 1 = 0, which is integer, so allowed. Also if A_i = 100, then A_i+1 =101, allowed. So each position has 3 choices, except maybe if A_i = 1, still 3 choices (0,1,2). So total possible sequences without any additional condition is 3^N, but we must count only those where product b_1 * ... * b_N is even. That means at least one b_i is even (i.e., divisible by 2). So count sequences similar to A with product even.
Since N is small (<=10), we could brute-force over all 3^N possibilities, which max 59049, easily doable. But we might also compute using complement: total similar sequences minus those where product is odd (i.e., all b_i odd). So answer = 3^N - number of sequences similar to A with all b_i odd.
Now counting sequences where each b_i is odd and similar to A. For each i, we need to choose from {A_i-1, A_i, A_i+1} only those that are odd. So for each i, let the number of odd choices among those three values. Then total odd sequences = product over i of (count of odd choices). Then answer = product over i (3) - product over i (odd_count_i).
But careful: For each i, the three values may not be distinct? They are distinct because they differ by 1. But if A_i-1 = A_i? Not possible. So three distinct integers. So each position has exactly 3 options. However, we must consider that if A_i = 1, then choices are {0,1,2}. Among these, odd: only 1. So odd_count=1. If A_i = 2, choices: {1,2,3}. Odd: 1 and 3? 1 is odd, 3 is odd, 2 is even. So odd_count=2. But we need to check parity: For any integer A_i, we can compute odd_count_i as the number among A_i-1, A_i, A_i+1 that are odd. Since three consecutive integers, exactly one of them is divisible by 3? Not relevant. Actually, among any three consecutive integers, either two are odd and one even, or two even and one odd? Let's check: Patterns: For numbers: even, odd, even? Actually three consecutive integers: parity pattern: if first is even: even, odd, even => two evens, one odd. If first is odd: odd, even, odd => two odds, one even. So depending on the parity of the middle? Actually the three numbers are A_i-1, A_i, A_i+1. They are consecutive centered around A_i. So the parity pattern is determined by parity of A_i. If A_i is even: then A_i-1 is odd, A_i is even, A_i+1 is odd => two odds, one even. If A_i is odd: then A_i-1 is even, A_i is odd, A_i+1 is even => two evens, one odd. So indeed:
If A_i is even: odd_count = 2 (since two odds: A_i-1 and A_i+1)
If A_i is odd: odd_count = 1 (only A_i is odd? Wait check: if A_i odd, A_i-1 even, A_i odd, A_i+1 even => only one odd, yes)
But wait, is it always exactly? Consider edge case A_i=1 (odd): values 0,1,2. 0 even,1 odd,2 even -> one odd. So odd_count=1. For A_i=2 (even): values 1,2,3 -> odds:1,3 =>2. So correct.
Thus product of odd choices = ∏_{i} (if A_i even then 2 else 1). So number of sequences with all odd = 2^{count_even_A}. Because each even A_i contributes 2 odd options; each odd A_i contributes 1 odd option.
Therefore answer = 3^N - 2^{E}, where E = number of i such that A_i is even.
So solution is straightforward: compute total = 3^N, subtract 2^{number of even A_i}.
But careful: Is there any nuance with b_i being integer but maybe we require positive? The problem statement doesn't specify positive, just integer sequences. Given A_i >=1, and similarity condition, b_i can be 0 (if A_i=1) or negative? Not possible because A_i>=1, A_i-1 >=0. So b_i are non-negative? If A_i=1, b_i can be 0, which is integer and even (product zero => even, that's fine). So the product even condition includes zero as even. So no issue.
Thus answer = 3^N - 2^{even count}.
But wait: Are there any sequences where product is even but some b_i is zero? Yes, that counts as even (0 is even). The method counts all sequences with at least one even number; zero is even. So we must check if zero is considered even? Yes, 0 is even. So it's fine.
Now, also check that for odd A_i, the odd options count = 1, but what about if A_i = 1 (odd), the odd option is 1, which is odd. So all good.
Thus final algorithm: read N, read array A, count even numbers, compute pow(3,N) - pow(2,evenCount), output.
Constraints up to N=10, so numbers fit in 32-bit integer (3^10=59049, 2^10=1024). However, for N=10, it's small. But we could also compute using pow function or manual exponentiation.
Edge Cases: If N=0? Not possible, N>=1.
One nuance: The problem statement says "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?" So we count all integer sequences with that property. Our reasoning is solid.
Double-check: Could there be sequences where some b_i is not integer? No, it's integer sequence.
Thus answer is correct.
Now we need to provide solution in Python, likely. We'll write code:
def solve():
import sys
input = sys.stdin.readline
N = int(input().strip())
A = list(map(int, input().split()))
even_cnt = sum(1 for x in A if x % 2 == 0)
total = 3N
odd_total = 2even_cnt
ans = total - odd_total
print(ans)
But we should consider that 3**N may be large? N up to 10, it's fine. But if N were larger? Not relevant.
Wait: Are there any tricky parts about sequences being "integer sequences"? Does "similar" require that the sequences are of integers? Yes. So all good.
But what about negative A_i? Not allowed.
Thus final answer.
But wait, we used complement: total similar sequences minus sequences with all b_i odd. However, are there any sequences where product is even but still all b_i are odd? No, product of odd numbers is odd. So complement works.
Thus solution is trivial.
But the problem might be from AtCoder, typical combinatorial counting. N small, but we have formula.
Nevertheless, we can also reason for any N, but that's it.
Now, what's the twist? Perhaps the answer could be large? But N up to 10, 3^10=59049, so answer fits int. But if N were larger? Not here.
But hold on: The constraints say N up to 10, but A_i up to 100. So trivial.
Thus final answer.
We'll produce final solution explanation accordingly. We count all integer sequences b of length N that are similar to A (i.e., |b_i - A_i| ≤ 1 for each i) and whose product is even.
Since each b_i can take exactly three values (A_i−1, A_i, A_i+1), there are 3^N such sequences in total. The product is even precisely when at least one b_i is even. So we can subtract the sequences where all b_i are odd.
For a fixed i, the three candidates are three consecutive integers centered at A_i. Their parities are determined by the parity of A_i:
If A_i is even: the candidates are odd, even, odd → two odd choices.
If A_i is odd: the candidates are even, odd, even → one odd choice.
Therefore, the number of ways to choose b_i so that it is odd is 2 when A_i is even, and 1 when A_i is odd. Hence, the number of sequences where every b_i is odd equals 2^{E}, where E is the number of even elements in A.
Consequently, the answer is 3^N − 2^{E}.
python
import sys
def main() -> None:
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
even_cnt = sum(1 for x in A if x % 2 == 0)
ans = 3 ** N - 2 ** even_cnt
print(ans)
if __name__ == "__main__":
main()