class BonusInfo(var isHeadB : Boolean, var isTailA : Boolean) {
}

fun main(args : Array<String>) {
    val N = readLine()!!.toInt()
    val s = mutableListOf<String>()
    (1..N).forEach {
        s.add(readLine()!!)
    }
    var basicCount = 0
    var maxBonusCount = 0

    var bothCount = 0
    var onlyHeadBCount = 0
    var onlyTailACount = 0

    s.forEach { si ->
        var AAppeared = false
        var len = si.length
        val bonusInfo = BonusInfo(false, false)
        si.forEachIndexed { index, c ->
            if (index == 0 && c == 'B') {
                bonusInfo.isHeadB = true
            }
            if (index == (len - 1) && c == 'A') {
                bonusInfo.isTailA = true
            }

            if (index == (len - 1)) {
                if (bonusInfo.isHeadB && bonusInfo.isTailA) {
                    bothCount++
                } else if(bonusInfo.isHeadB) {
                    onlyHeadBCount++
                } else if(bonusInfo.isTailA) {
                    onlyTailACount++
                }
            }

            if (c == 'A') {
                AAppeared = true
            } else if (c == 'B') {
                if (AAppeared) {
                    basicCount++
                }
                AAppeared = false
            } else {
                AAppeared = false
            }
        }
    }
    var tailAUsed = false
    if (onlyTailACount > 0) {
        onlyTailACount--
        tailAUsed = true
    }

    if (bothCount > 0) {
        if (tailAUsed) {
            maxBonusCount++
        }
        maxBonusCount += (bothCount - 1)
        tailAUsed = true
    }
    if (tailAUsed && onlyHeadBCount > 0) {
        onlyHeadBCount--
        maxBonusCount++
    }
    maxBonusCount += listOf(onlyHeadBCount, onlyTailACount).min()!!
    println(basicCount + maxBonusCount)
}