#!/usr/bin/env PyPy3 from collections import Counter, defaultdict, deque import itertools import re import math from functools import reduce import operator import bisect from heapq import * import functools mod=10 ** 9 + 7 import sys input = sys.stdin.readline class Bit:#0-indexed を 1-indexedに変換するので、0-indexedを入れる def __init__(self, n): self.size = n + 1 self.tree = [0] * (n + 2) self.depth = (n + 1).bit_length() def add(self, i, x): i += 1 while i <= self.size: self.tree[i] += x i += i & -i def sum(self, i): i += 1 s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def lower_bound(self, x): """ 累積和がx以上になる最小のindexと、その直前までの累積和 """ sum_ = 0 pos = 0 for i in range(self.depth, -1, -1): k = pos + (1 << i) if k <= self.size and sum_ + self.tree[k] < x: sum_ += self.tree[k] pos += 1 << i return pos, sum_ n = int(input()) s = input().rstrip() dele = [0,ord('C') - ord('A'),ord('G') - ord('A'),ord('T') - ord('A')] li = [0] * 26 for ss in s: li[ord(ss) - ord('A')] += 1 ans = 0 bit = Bit(n) for i in range(n): bit.add(i,1) while li[dele[0]] + li[dele[1]] + li[dele[2]] + li[dele[3]]: c = li[dele[0]] + li[dele[1]] + li[dele[2]] + li[dele[3]] idx,_ = bit.lower_bound(c) li[ord(s[idx]) - ord('A')] -= 1 bit.add(idx,-1) for i in range(4): dele[i] -= li[ord(s[idx]) - ord('A')] dele[i] %= 26 ans += 1 print(ans)