import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val n = sc.nextInt()
  val a = (1..n).map { sc.nextInt() }.toIntArray()

  val bool = BooleanArray(n) { a[it] % 2 == 0 }

  var ans = 0
  var first = 1
  for (i in 0 until n) {
    var now = 2
    if (bool[i]) {
      now = 1
    }

    val tmp = n - 1 - i
    ans += first * now * Math.pow(3.0, tmp.toDouble()).toInt()


    if (bool[i]) {
      first *= 2
    }
  }

  println(ans)
}
