fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    var a = 0
    var b = 0
    var aabb = 0
    var ab = 0
    for (i in 0 until n) {
        val text = readLine()!!.toString()
        for (j in 0 until text.length - 1) {
            if (text[j] == 'A' && text[j + 1] == 'B') ab++
        }
        if (text[0] == 'B' && text[text.length - 1] != 'A') b++
        else if (text[0] != 'B' && text[text.length - 1] == 'A') a++
        else if (text[0] == 'B' && text[text.length - 1] == 'A') aabb++
    }
    if (aabb >= 1) {
        if (a == b && a > 0) {
            println(ab + a + aabb)
        } else {
            println(ab + Math.max(Math.min(a + aabb, b + aabb - 1), Math.min(a + aabb - 1, b + aabb)))
        }
    } else {
        println(ab + Math.min(a, b))
    }
}
