CF 1353E
void solve() {
int n, k;
string s;
cin >> n >> k >> s;
s = ')' + s;
int one = 0;
for (int i = 1; i <= n; ++i) {
if (s[i] == '1') {
one++;
}
}
int cur = 0, ans = 0x3f3f3f3f;
for (int i = 1;i <= k; ++i) {
cur = 0;
for (int j = i; j <= n; j+=k) {
if (s[j] == '1') {
++cur;
} else {
--cur;
}
cur = max(cur, 0);
ans = min(ans, one - cur);
}
}
cout << ans << '\n';
return;
}
CF 1335E1
void solve() {
int n, x;
cin >> n;
vector<int> a(n + 1);
vector cnt(n + 1, vector<int>(27));
for (int i = 1; i <= n; ++i) {
cin >> x;
for (int j = 1;j <= 26; ++j) {
cnt[i][j] = cnt[i-1][j] + (x == j);
}
}
int ans = 0;
for (int l = 1; l <= n; ++l) {
for (int r = l; r <= n; ++r) {
int x = 0, y = 0;
for (int k = 1;k <= 26; ++k) {
x = max(x, cnt[r][k] - cnt[l - 1][k]); //centroid
y = max(y, 2 * min(cnt[n][k] - cnt[r][k], cnt[l - 1][k])); //two sides
}
ans = max(ans, x + y);
}
}
cout << ans << '\n';
return;
}