//  [rust]
#![allow(non_snake_case)]
#![allow(unused_imports)]
use ascii::AsciiChar;
use ascii::AsciiStr;
use itertools::Itertools as _;
use permutohedron::LexicalPermutation as _;
use petgraph::algo::dijkstra;
use petgraph::algo::min_spanning_tree;
use petgraph::data::FromElements;
use petgraph::graph::NodeIndex;
use petgraph::graph::UnGraph;
use petgraph::unionfind::UnionFind;
use proconio::fastout;
use proconio::input;
use proconio::marker::Chars;
use proconio::marker::Usize1;
use std::cmp::max;
use std::cmp::min;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use superslice::Ext as _;

#[fastout]
fn main() {
    input! {
        N: usize,
        Ss: [Chars; N],
    }

    // let B_A = Ss.iter().filter(|s| s[0] == 'B' && s[s.len()-1] == 'A').count();
    // let B_X =Ss.iter().filter(|s| s[0] == 'B' ).count() - B_A;
    // let X_A =     Ss.iter().filter(|s| s[s.len()-1] == 'A').count() - B_A;

    let BAs: Vec<Vec<char>> = Ss
        .clone()
        .into_iter()
        .filter(|s| s[0] == 'B' && s[s.len() - 1] == 'A')
        .collect();
    let BXs: Vec<Vec<char>> = Ss
        .clone()
        .into_iter()
        .filter(|s| s[0] == 'B' && s[s.len() - 1] != 'A')
        .collect();
    let XAs: Vec<Vec<char>> = Ss
        .clone()
        .into_iter()
        .filter(|s| s[0] != 'B' && s[s.len() - 1] == 'A')
        .collect();
    let others: Vec<Vec<char>> = Ss
        .clone()
        .into_iter()
        .filter(|s| s[0] != 'B' && s[s.len() - 1] != 'A')
        .collect();

    let mut ans_vv: Vec<Vec<char>> = others;

    let xa_is_bigger = XAs.len() >= BXs.len();
    let XAs_len = XAs.len();
    let BXs_len = BXs.len();
    let BAs_len = BAs.len();

    // 方針: インデックスで制御するのはバグの温床なので、イテレータ化して個数で管理する
    let mut BAs_iter = BAs.into_iter();
    let mut BXs_iter = BXs.into_iter();
    let mut XAs_iter = XAs.into_iter();

    if xa_is_bigger {
        // A
        let rest = XAs_len - BXs_len;

        for _ in 0..min(XAs_len, BXs_len) {
            let xa = XAs_iter.next().unwrap();
            let bx = BXs_iter.next().unwrap();

            ans_vv.push(xa);
            ans_vv.push(bx);
        }

        if rest >= BAs_len {
            // A-1
            for _ in 0..BAs_len {
                let xa = XAs_iter.next().unwrap();
                let ba = BAs_iter.next().unwrap();

                ans_vv.push(xa);
                ans_vv.push(ba);
            }

            for _ in 0..rest - BAs_len {
                let xa = XAs_iter.next().unwrap();

                ans_vv.push(xa);
            }
        } else {
            // A-2
            for _ in 0..rest {
                let xa = XAs_iter.next().unwrap();
                let ba = BAs_iter.next().unwrap();

                ans_vv.push(xa);
                ans_vv.push(ba);
            }

            for _ in 0..BAs_len - rest {
                let ba = BAs_iter.next().unwrap();
                ans_vv.push(ba);
            }
        }
    } else {
        // B
        let rest = BXs_len - XAs_len;

        for _ in 0..min(XAs_len, BXs_len) {
            let xa = XAs_iter.next().unwrap();
            let bx = BXs_iter.next().unwrap();

            ans_vv.push(xa);
            ans_vv.push(bx);
        }

        if rest >= BAs_len {
            // B-1

            for _ in 0..BAs_len {
                let ba = BAs_iter.next().unwrap();
                let bx = BXs_iter.next().unwrap();
                ans_vv.push(ba);
                ans_vv.push(bx);
            }

            for _ in 0..rest - BAs_len {
                let bx = BXs_iter.next().unwrap();

                ans_vv.push(bx);
            }
        } else {
            // B-2

            for _ in 0..rest {
                let ba = BAs_iter.next().unwrap();
                let bx = BXs_iter.next().unwrap();
                ans_vv.push(ba);
                ans_vv.push(bx);
            }

            for _ in 0..BAs_len - rest {
                let ba = BAs_iter.next().unwrap();
                ans_vv.push(ba);
            }
        }
    }

    // dbg!(&ans_vv);

    let ans_v = ans_vv.concat();

    let mut ans: i64 = 0;
    for i in 1..ans_v.len() {
        if ans_v[i - 1] == 'A' && ans_v[i] == 'B' {
            ans += 1;
        }
    }

    println!("{}", ans);
}