# 前半はAがいい、後半はCがいい # なぜならCが出るたびに、それまでのAのカウントがansに追加されるから # dpなのか貪欲的なのか # dp[i個目][Aの個数][今回A0 C1] 得点最大値 N = int(input()) S = input() INF = 10**10 dp = [[[-INF]*2 for j in range(N+1)] for i in range(N+1)] dp[0][0][0] = 0 dp[0][0][1] = 0 #print(dp[0]) for i in range(1, N+1): if S[i-1] == 'A': for j in range(N+1): if j+1 <= N: dp[i][j+1][0] = max(dp[i][j+1][0], dp[i-1][j][0]) dp[i][j+1][0] = max(dp[i][j+1][0], dp[i-1][j][1]) elif S[i-1] == 'C': for j in range(N+1): if j <= N: dp[i][j][1] = max(dp[i][j][1], dp[i-1][j][0]+j) dp[i][j][1] = max(dp[i][j][1], dp[i-1][j][1]+j) elif S[i-1] == '?': for j in range(N+1): if j+1 <= N: dp[i][j+1][0] = max(dp[i][j+1][0], dp[i-1][j][0]) dp[i][j+1][0] = max(dp[i][j+1][0], dp[i-1][j][1]) for j in range(N+1): if j <= N: dp[i][j][1] = max(dp[i][j][1], dp[i-1][j][0]+j) dp[i][j][1] = max(dp[i][j][1], dp[i-1][j][1]+j) #print(dp[i]) ans = 0 for j in range(N+1): for k in range(2): ans = max(ans, dp[N][j][k]) print(ans)