Language: C++

3
ABCA
XBAZ
BAD#include <bits/stdc++.h>
using namespace std;
// #include <bits/stdtr1c++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;


/*#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")*/

/// Typedef
typedef long long           ll;
typedef unsigned long       ul;
typedef unsigned long long  ull;
typedef vector<int>         vi;
typedef vector<vi>          vvi;
typedef vector<ll>          vll;
typedef pair<int,int>       pii;
typedef pair<ll,ll>         pll;

#define pb                  push_back
#define ppb                 pop_back
#define MP                  make_pair
#define ff                  first
#define ss                  second
#define sf                  scanf
#define pf                  printf
#define loop(i, y)          for(int i=0; i<int(y); i++)
#define FOR(i, x, y)        for(int i=int(x); i<int(y); i++)
#define ROF(i, x, y)        for(int i=int(x); i>=int(y); i--)
#define all(c)              c.begin(), c.end()
#define sz(c)               int(c.size())
#define clr(x, y)           memset(x, y, sizeof(x))
#define si(x)               scanf("%d", &x)
#define sii(x, y)           scanf("%d %d", &x, &y)
#define siii(x, y, z)       scanf("%d %d %d", &x, &y, &z)
#define sl(x)               scanf("%lld", &x)
#define sll(x, y)           scanf("%lld %lld", &x, &y)
#define slll(x, y, z)       scanf("%lld %lld %lld", &x, &y, &z)
#define FastIO              ios_base::sync_with_stdio(false)
#define FixedPrecision(x)   ios_base::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(x); cin.tie(0);
#define bitCheck(N,in)      ((bool)(N&(1LL<<(in))))
#define bitOff(N,in)        (N&(~(1LL<<(in))))
#define bitOn(N,in)         (N|(1LL<<(in)))
#define bitFlip(a,k)        (a^(1LL<<(k)))
#define popCount(x)         __builtin_popcount(x)
#define popCountLL(x)       __builtin_popcountll(x)
#define int2Bin(x, y)       bitset<y> z=x; cout<<z.to_string()<<endl;
#define tr(it, container)   for(auto it = container.begin(); it != container.end(); it++)
#define unq(v)              (v).erase(unique(all(v)),v.end())
#define common(a,b)         sort(all(a)), sort(all(b)), a.erase(set_intersection(all(a),all(b),a.begin()),a.end())
#define uncommon(a,b)       sort(all(a)), sort(all(b)), a.erase(set_symmetric_difference(all(a),all(b),a.begin()),a.end())
#define DB(x)               cout << #x << " = " << x << endl
#define DDB(x,y)            cout << #x << " = " << x << "   " << #y << " = " << y << endl
#define DDDB(x,y,z)         cout << #x << " = " << x << "   " << #y << " = " << y << "   " << #z << " = " << z << endl
#define ran(a, b)           ((((rand() << 15) ^ rand()) % ((b) - (a) + 1)) + (a))
/// template <typename T> using orderset = tree <T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
/// *X.find_by_order(k) //returns the kth largest element.(0-based)
/// X.order_of_key(val) //returns the no. of values less than val


template <class T> inline T bigMod(T p,T e,T M){ ll ret = 1; for(; e > 0; e >>= 1){ if(e & 1) ret = (ret * p) % M; p = (p * p) % M; } return (T) ret;}
template <class T> inline T modInverse(T a,T M){return bigMod(a,M-2,M);}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T lcm(T a,T b) {a=abs(a);b=abs(b); return (a/gcd(a,b))*b;}
template <class T> inline string int2String(T a){ostringstream str; str<<a; return str.str();}
ll string2int(string a){stringstream str(a); ll b; str>>b; return b;}
template <class T> inline void read(T &r){
    r=0;int f=1;char ch=getchar();
    while (ch<'0' or ch>'9'){f=(ch=='-'?-1:1), ch=getchar();}
    while (ch>='0' and ch<='9'){r=r*10+ch-'0', ch=getchar();}
    r*=f;
}
const int dr[] = { 0,  1,  0, -1,   -1,  1,  1, -1,   -2, -2,  2,  2, -1, -1,  1,  1};
const int dc[] = { 1,  0, -1,  0,    1,  1, -1, -1,   -1,  1, -1,  1, -2,  2, -2,  2};
#ifdef VAMP
     #define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template < typename Arg1 >
    void __f(const char* name, Arg1&& arg1){
        cerr << name << " = " << arg1 << std::endl;
    }
    template < typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names+1, ',');
        cerr.write(names, comma - names) << " = " << arg1 <<" | ";
        __f(comma+1, args...);
    }
#else
    #define debug(...)
#endif
///******************************************START******************************************

/// Constants
#define MAX                 100005
#define MOD                 998244353
#define base                1000000007
#define eps                 1e-9
#define INF                 1llu<<61    // 2,305,843,009,213,693,952
#define inf                 1<<29       // 536,870,912
#define PI                  acos(-1.0)  // 3.1415926535897932
// #define INF              0x3f3f3f3f3f3f3f3f
// #define inf              0x3f3f3f3f

int main(){
    #ifdef VAMP
        clock_t tStart = clock();
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int n;
    si(n);
    int c=0;
    string s;
    vector<string> A,B;
    int p=0;
    FOR(i,0,n){
        cin>>s;
        if(s[0]=='B' && s[sz(s)-1]=='A'){
            if(p&1)A.pb(s);
            else   B.pb(s);
            p++;
        }
        else if(s[sz(s)-1]=='A')A.pb(s);
        else if(s[0]=='B')      B.pb(s);
        else{
            FOR(i,0,sz(s)-1){
                if(s[i]=='A'&&s[i+1]=='B')c++;
            }
        }
    }
    sort(all(A));
    reverse(all(A));
    std::vector<string> v;
    v = B;
    FOR(i,0,sz(v)){
        //cout<<v[i]<<endl;
        string tt = v[i];
        reverse(tt.begin(),tt.end());
        v[i]=tt;
       // string temp = reverse(v[i].begin(), v[i].end()); 
    }
    sort(all(v));
    FOR(i,0,sz(v)){
        //cout<<v[i]<<endl;
        string tt = v[i];
        reverse(tt.begin(),tt.end());
        v[i]=tt;
       // string temp = reverse(v[i].begin(), v[i].end()); 
    }
    B=v;
    //FOR(i,0,sz(B))cout<<B[i]<<endl;
    string temp;
    int i=0,j=0;
    while(i<sz(A)||j<sz(B)){
        if(i<sz(A))temp+=A[i++];
        if(j<sz(B))temp+=B[j++];
    }
    /*for(auto x:A)cout<<x<<endl;
    cout<<"-0------"<<endl;
    for(auto x:B)cout<<x<<endl;*/
    while(i<sz(A)){
        if(i<sz(A))temp+=A[i++];
    }
    while(j<sz(B)){
     if(j<sz(B))temp+=B[j++];
    }
    for(int k=0;k<sz(temp)-1;k++){
        if(temp[k]=='A'&&temp[k+1]=='B')c++;
    }
    //cout<<temp<<endl;
    cout<<c<<endl;
    #ifdef VAMP
       printf("\n>>Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
    #endif

    return 0;
}

Compiler output:
a.cc:4:4: error: stray '#' in program
    4 | BAD#include <bits/stdc++.h>
      |    ^
a.cc:1:1: error: expected unqualified-id before numeric constant
    1 | 3
      | ^
a.cc:20:9: error: 'vector' does not name a type
   20 | typedef vector<int>         vi;
      |         ^~~~~~
a.cc:21:9: error: 'vector' does not name a type
   21 | typedef vector<vi>          vvi;
      |         ^~~~~~
a.cc:22:9: error: 'vector' does not name a type
   22 | typedef vector<ll>          vll;
      |         ^~~~~~
a.cc:23:9: error: 'pair' does not name a type
   23 | typedef pair<int,int>       pii;
      |         ^~~~
a.cc:24:9: error: 'pair' does not name a type
   24 | typedef pair<ll,ll>         pll;
      |         ^~~~
a.cc:71:27: error: 'string' does not name a type
   71 | template <class T> inline string int2String(T a){ostringstream str; str<<a; return str.str();}
      |                           ^~~~~~
a.cc:72:15: error: 'string' was not declared in this scope
   72 | ll string2int(string a){stringstream str(a); ll b; str>>b; return b;}
      |               ^~~~~~
a.cc: In function 'void read(T&)':
a.cc:74:25: error: there are no arguments to 'getchar' that depend on a template parameter, so a declaration of 'getchar' must be available [-fpermissive]
   74 |     r=0;int f=1;char ch=getchar();
      |                         ^~~~~~~
a.cc:74:25: note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
a.cc:75:51: error: there are no arguments to 'getchar' that depend on a template parameter, so a declaration of 'getchar' must be available [-fpermissive]
   75 |     while (ch<'0' or ch>'9'){f=(ch=='-'?-1:1), ch=getchar();}
      |                                                   ^~~~~~~
a.cc:76:51: error: there are no arguments to 'getchar' that depend on a template parameter, so a declaration of 'getchar' must be available [-fpermissive]
   76 |     while (ch>='0' and ch<='9'){r=r*10+ch-'0', ch=getchar();}
      |                                                   ^~~~~~~
a.cc: In function 'int main()':
a.cc:39:29: error: 'scanf' was not declared in this scope
   39 | #define si(x)               scanf("%d", &x)
      |                             ^~~~~
a.cc:116:5: note: in expansion of macro 'si'
  116 |     si(n);
      |     ^~
a.cc:118:5: error: 'string' was not declared in this scope
  118 |     string s;
      |     ^~~~~~
a.cc:119:5: error: 'vector' was not declared in this scope
  119 |     vector<string> A,B;
      |     ^~~~~~
a.cc:119:20: error: 'A' was not declared in this scope
  119 |     vector<string> A,B;
      |                    ^
a.cc:119:22: error: 'B' was not declared in this scope
  119 |     vector<string> A,B;
      |                      ^
a.cc:122:9: error: 'cin' was not declared in this scope
  122 |         cin>>s;
      |         ^~~
a.cc:122:14: error: 's' was not declared in this scope
  122 |         cin>>s;
      |              ^
a.cc:136:5: error: 'sort' was not declared in this scope; did you mean 'short'?
  136 |     sort(all(A));
      |     ^~~~
      |     short
a.cc:137:5: error: 'reverse' was not declared in this scope
  137 |     reverse(all(A));
      |     ^~~~~~~
a.cc:138:10: error: 'vector' is not a member of 'std'
  138 |     std::vector<string> v;
      |          ^~~~~~
a.cc:1:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
  +++ |+#include <vector>
    1 | 3
a.cc:138:25: error: 'v' was not declared in this scope
  138 |     std::vector<string> v;
      |                         ^
a.cc:142:15: error: expected ';' before 'tt'
  142 |         string tt = v[i];
      |               ^~~
      |               ;
a.cc:143:17: error: 'tt' was not declared in this scope; did you mean 'tr'?
  143 |         reverse(tt.begin(),tt.end());
      |                 ^~
      |                 tr
a.cc:150:15: error: expected ';' before 'tt'
  150 |         string tt = v[i];
      |               ^~~
      |               ;
a.cc:151:17: error: 'tt' was not declared in this scope; did you mean 'tr'?
  151 |         reverse(tt.begin(),tt.end());
      |                 ^~
      |                 tr
a.cc:157:11: error: expected ';' before 'temp'
  157 |     string temp;
      |           ^~~~~
      |           ;
a.cc:160:20: error: 'temp' was not declared in this scope
  160 |         if(i<sz(A))temp+=A[i++];
      |                    ^~~~
a.cc:161:20: error: 'temp' was not declared in this scope
  161 |         if(j<sz(B))temp+=B[j++];
      |                    ^~~~
a.cc:167:20: error: 'temp' was not declared in this scope
  167 |         if(i<sz(A))temp+=A[i++];
      |                    ^~~~
a.cc:170:17: error: 'temp' was not declared in this scope
  170 |      if(j<sz(B))temp+=B[j++];
      |                 ^~~~
a.cc:172:22: error: 'temp' was not declared in this scope
  172 |     for(int k=0;k<sz(temp)-1;k++){
      |                      ^~~~
a.cc:37:33: note: in definition of macro 'sz'
   37 | #define sz(c)               int(c.size())
      |                                 ^
a.cc:176:5: error: 'cout' was not declared in this scope
  176 |     cout<<c<<endl;
      |     ^~~~
a.cc:176:14: error: 'endl' was not declared in this scope
  176 |     cout<<c<<endl;
      |              ^~~~