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

Solution in Ruby (2.3.3) (judge verdict: Wrong Answer)

def rev?(s) return s.start_with?(s[(s.size/2)..-1].reverse) end

s = gets.chomp
sx = s.gsub('x', '')
res = rev? sx
if res
  x_num = []
  count = 0
  s.each_char{|c|
    if c == 'x'
      count += 1
    else
      x_num << count
      count = 0
    end
  }
  if sx.size == 0
    p 0
  else
    if s[-1] != 'x'
      x_num << 0 
    else
      x_num << count
    end
    lx = x_num[0...(x_num.size/2)]
    rx = x_num[-(x_num.size/2)..-1].reverse
    if lx.size == 1
      p (lx[0] - rx[0]).abs
    else
      p [lx, rx].map{|l, r| (l - r).abs}.inject :+
    end
  end
else
  p -1
end