fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val domino = readLine()!!
    readLine()

    val p = domino.mapIndexed { i, c ->
        if(i==0) false
        else domino[i-1]==c
    }
    val dg = domino.groupBy { it } .mapValues { it.value.size }
    val d = mutableListOf<Int>()
    for (i in 0..domino.lastIndex) {
        if(p[i]) continue
        d.add(dg[domino[i]]!!)
    }

    var dp = if(d[0] == 1) 3L else 6L
    for(i in 1..d.lastIndex) {
        val comb = when {
            d[i-1] == 1 && d[i] == 1 -> 2
            d[i-1] == 1 && d[i] == 2 -> 2
            d[i-1] == 2 && d[i] == 1 -> 1
            d[i-1] == 2 && d[i] == 2 -> 3
            else -> 0
        }
        dp = (dp * comb) % 1000000007L
    }
    println(dp)
}
