import std.stdio, std.array, std.conv, std.typecons, std.algorithm, std.string;

T diff(T)(const ref T a, const ref T b) { return a > b ? a - b : b - a; }

ulong count_ab(const ref string s) {
    ulong ret = 0;
    bool afterA = false;
    foreach (c ; s) {
        switch (c) {
            case 'A' : afterA = true; break;
            case 'B' : if (afterA) ret++;
            default: afterA = false; break;
        }
    }
    return ret;
}

void main() {
    immutable n = readln.strip.to!(ulong);

    uint ab_cnt = 0;
    uint begin_B = 0;
    uint end_A = 0;
    uint both = 0;
    for (ulong i = 0; i < n; i++) {
        immutable input = readln.strip;
        ab_cnt += count_ab(input);
        if (input[0] == 'B' && input[input.length-1] == 'A') {
            both++;
        } else {
            if (input[0] == 'B') begin_B++;
            if (input[input.length - 1] == 'A') end_A++;
        }
    }

    ulong both_rem = 0;
    while(both > 1) { // both to 1
        both_rem += both % 2;
        both /= 2;
        ab_cnt += both;
    }
    ab_cnt += min(begin_B, end_A);
    ab_cnt += min(diff(begin_B, end_A), both);

    writeln(ab_cnt);
}
