import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)

  val n = sc.nextInt
  val sl = List.fill(n)(sc.next)


  val t = sl.map(s =>
    {
      val reduceAB = s.replaceAll("AB","")
      ((s.length - reduceAB.length) / 2,  reduceAB.startsWith("B"), reduceAB.endsWith("A")  )
    }
  )
  
  val res = t.foldLeft((0L, 0,0)){case ( (cnt,b,a), (cntAB, startsB, endsA)) =>
    val (newB, newA) = (if(startsB) b + 1 else b, if(endsA) a + 1 else a)
    if(newB >= 1 && newA >= 1) (cnt + cntAB + 1, newB - 1, newA - 1) else (cnt + cntAB , newB, newA)
  }._1


  println(res)

}