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

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int countAB(string s) {
    int n = 0;
    for (int i = 1; i < s.length; i++) {
        if (s[i-1] == 'A' && s[i] == 'B') n++;
    }
    return n;
}

int calc(string[] a) {
    int ans = a.map!(countAB).sum;

    int xa = 0;
    int bx = 0;
    int ba = 0;
    foreach (s; a) {
        auto front = s.front;
        auto last = s[$-1];
        if (front == 'B' && last == 'A') ba++;
        else if (front == 'B') bx++;
        else if (last == 'A') xa++;
    }

    if (xa > 0) xa--;
    else if (ba > 0) ba--;
    else return ans;

    if (ba > 0) {
        ans += ba;
        ba = 0;
    }

    // 末尾が A で終わっている状態
    while (xa > 0 || bx > 0) {
        if (bx == 0) break;

        ans++;
        bx--;

        int k = min(bx, xa);
        if (k == 0) break;
        ans += k;
        bx -= k;
        xa -= k;

        if (xa == 0) break;
        xa--;
    }
    return ans;
}

void main() {
    int n = readint;
    string[] a;
    for (int i = 0; i < n; i++) a ~= read!string;
    writeln(calc(a));
}

