B - Similar Arrays Editorial /

Time Limit: 2 sec / Memory Limit: 256 MB

配点: 200

問題文

2 つの長さ N の整数列 x_1, x_2, ..., x_Ny_1, y_2, ..., y_N が「似ている」とは、 任意の i (1 \leq i \leq N) に対して |x_i - y_i| \leq 1 が成り立つことをいうものとします。

とくに、どの整数列もその数列自身と似ていると考えます。

整数 N および長さ N の整数列 A_1, A_2, ..., A_N が与えられます。

A と似ている整数列 b_1, b_2, ..., b_N であって、すべての項の積 b_1 b_2 ... b_N が偶数となるものはいくつあるか求めてください。

制約

  • 1 \leq N \leq 10
  • 1 \leq A_i \leq 100

入力

入力は以下の形式で標準入力から与えられる。

N
A_1 A_2 ... A_N

出力

条件を満たす整数列の個数を出力せよ。


入力例 1

2
2 3

出力例 1

7

条件を満たす整数列は以下の 7 個あります。

  • 1, 2
  • 1, 4
  • 2, 2
  • 2, 3
  • 2, 4
  • 3, 2
  • 3, 4

入力例 2

3
3 3 3

出力例 2

26

入力例 3

1
100

出力例 3

1

入力例 4

10
90 52 56 71 44 8 13 30 57 84

出力例 4

58921

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