/* -*- coding: utf-8 -*- * * 2021.cc: No.2021 Not A but B - yukicoder */ #include #include using namespace std; /* constant */ const int MAX_N = 200000; /* typedef */ /* global variables */ char s[MAX_N + 4]; /* subroutines */ /* main */ int main() { int n; scanf("%d%s", &n, s); int c = 0, d = 0; for (int i = 0; i < n;) { int j = i; while (i < n && s[i] == 'B') i++; if (i - j >= 2) d = 1; if (i >= n) break; j = i; while (i < n && s[i] == 'A') i++; int l = i - j; if (l == 1) c++; else c += (l + 1) - (j == 0 ? 1 : 0) - (i == n ? 1 : 0); } printf("%d\n", c + d); return 0; }