Language: C++

/*
               _____
              /     \
              vvvvvvv  /|__/|
                 I   /O,O   |
                 I /_____   |      /|/|
                J|/^ ^ ^ \  |    /00  |    _//|
                 |^ ^ ^ ^ |W|   |/^^\ |   /oo |
                  \m___m__|_|    \m_m_|   \mm_|


 */
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

#define fori(a, r) for(long long int a = 0; a < (r); ++a)
#define forI(a, r) for(long long int a = 1; a <= (r); ++a)

#define ff first
#define ss second
#define pll pair<ll, ll>

//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("unroll-loops")

using namespace std;
typedef long long int ll;
typedef long double ld;
typedef long long ull;

#define pt pair<ll, ll>
#define x first
#define y second

pt dxy[] = {{1,  0},
            {0,  1},
            {-1, 0},
            {0,  -1}};
const long long MAXN = 10 * 1000 + 100, MOD = 1e9 + 7, INF = ((1ll << 60) - 1) * 2 + 1;

mt19937 random(time(0));

ll n, m;
ll c[4];

void solve() {
    cin >> n;
    ll ans = 0;
    fori(i, n){
        string s;
        cin >> s;
        ll type = ((s[0] == 'B') << 1) | (s.back() == 'A');
        for(ll i = 0; i + 1 < s.size(); ++i){
            if(s[i] == 'A' && s[i + 1] == 'B') ++ans;
        }
        ++c[type];
    }
    ll oA = c[1];
    ll Bo = c[2];
    ll BA = c[3];
    ans += min(oA, Bo);
    if(Bo > oA) swap(Bo, oA);
    oA -= Bo;

    ans += max(0ll, BA - 1 + (oA > 0));

    cout << ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#define DEBUG0
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    solve();
    //another();
}

Compiler output:
a.cc:107:16: error: 'std::mt19937 random' redeclared as different kind of entity
  107 | mt19937 random(time(0));
      |                ^~~~
In file included from /usr/include/c++/14/bits/std_abs.h:38,
                 from /usr/include/c++/14/cmath:49,
                 from a.cc:19:
/usr/include/stdlib.h:521:17: note: previous declaration 'long int random()'
  521 | extern long int random (void) __THROW;
      |                 ^~~~~~