import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

alias T = Tuple!(int, int);

void main() {
  immutable n = readln.strip.to!int;
  long res;
  int[4] c;
  foreach (qid; 0 .. n) {
    auto s = readln.strip;
    int t1 = (s.back == 'A') ? 1 : 0;
    int t2 = (s.front == 'B') ? 1 : 0;
    foreach (i; 1 .. s.length) {
      if (s[i-1] == 'A' && s[i] == 'B') ++res;
    }
    c[t1 * 2 + t2]++;
  }
  while (c[2]) {
    c[2]--;
    if (c[1]) {
      c[1]--;
      res++;
    }
    if (c[3]) {
      res += c[3];
      c[3] = 0;
    }
  }
  if (c[3]) res += c[3] - 1;
  writeln (res);
}
