#include namespace { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-function" #include #pragma GCC diagnostic pop using namespace std; using namespace atcoder; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) template bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; } template bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; } using ll = long long; using P = pair; using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; constexpr int A = 'A' - 'A'; constexpr int G = 'G' - 'A'; constexpr int C = 'C' - 'A'; constexpr int T = 'T' - 'A'; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; VI st1(n), st2; int cnt[26]{}; // in original int rot = 0; rep(i, n) { char c; cin >> c; int x = c - 'A'; st1[i] = x; cnt[x]++; } int ans = 0; auto is_AGCT = [](int x) { return x == A || x == G || x == C || x == T; }; while(true) { int c1 = 0; rep(i, 26) if (is_AGCT((i + rot) % 26)) c1 += cnt[i]; if (c1 == 0) break; ans++; while((int)st1.size() > c1) st2.emplace_back(st1.back()), st1.pop_back(); while((int)st1.size() < c1) st1.emplace_back(st2.back()), st2.pop_back(); int x = st1.back(); st1.pop_back(); int c2 = --cnt[x]; rot += c2; rot %= 26; } cout << ans << '\n'; }