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 temp = t.foldLeft((0L, 0, 0, 0)){case ( (cnt,b,a,both), (cntAB, startsB, endsA)) =>
    val newB    = b    + (if(startsB  && !endsA) 1 else 0)
    val newA    = a    + (if(!startsB &&  endsA) 1 else 0)
    val newBoth = both + (if( startsB &&  endsA) 1 else 0)

    (cnt + cntAB, newB,newA,newBoth)
  }

  val (cnt, b,a,ba) = temp
  
  val res = cnt + (
    if(ba >= 1) (ba - 1) + Math.min(b,a) + Math.min(Math.abs(b - a), 1)
    else Math.min(b,a)
    )

  println(res)

}