#include #include #include #include #include #include #include #include #include #include #include #include #include #include constexpr int MAX_INT = 2147483647; constexpr int MIN_INT = -2147483648; #define rep(n, a, b) for (int (n) = (a); (n) < (b); (n)++) #define rrep(n, a, b) for (int (n) = (a); (n) >= (b); (n)--) #define llrep(n, a, b) for (long long (n) = (a); (n) < (b); (n)++) #define llrrep(n, a, b) for (long long (n) = (a); (n) >= (b); (n)--) #define itrAll(x) (x).begin(), (x).end() #define inputvec(v) for (auto& x : v) {std::cin >> x;} using namespace std; using uint = unsigned int; using ushort = unsigned short; using byte = unsigned char; using ll = long long; using ull = unsigned long long; using ldouble = long double; using ipair = pair; using llpair = pair; int main() { int N; string S; cin >> N >> S; vector cpc; rep(i, 0, N - 2) { if (S[i] == 'C' && S[i + 1] == 'P' && S[i + 2] == 'C') { cpc.push_back(i); } } if (!cpc.size()) { cout << 0 << endl; return 0; } /// /// [i] := { /// [first]: i+1番目のCPCまでの部分文字列のうち, 少なくともi番目のCPCを変換したときのCPCTFの個数の最大値. /// [second]: 〃のうち, i番目のCPCを変換していないときの〃. /// } /// vector> cnt(cpc.size()); cnt[0] = { 0,0 }; for (int i = 1; i < cpc.size(); i++) { int l = cpc[i - 1] + 3; int r = cpc[i] + 2; if (r - l >= 4 && S[l] == 'T' && S[l + 1] == 'F') { int v = cnt[i - 1].second + 1; cnt[i] = { v,v }; } else if (r - l == 3 && S[l] == 'T') { cnt[i] = { cnt[i - 1].second + 1, max(cnt[i - 1].first, cnt[i - 1].second) }; } else if (r - l == 1) { cnt[i] = { cnt[i - 1].second, max(cnt[i - 1].first, cnt[i - 1].second) }; } else { int v = max(cnt[i - 1].first, cnt[i - 1].second); cnt[i] = { v,v }; } } int l = cpc[cpc.size() - 1] + 3; auto& p = cnt[cpc.size() - 1]; if (N - l >= 2 && S[l] == 'T' && S[l + 1] == 'F') { cout << max(p.first, p.second + 1) << endl; } else { cout << max(p.first, p.second) << endl; } return 0; }