OI XVII - ant

// https://szkopul.edu.pl/problemset/problem/kBgruExq9qEwLJY2oQIAFnnj/site/?key=statement
// Antysymetria XVII OI

#include <bits/stdc++.h>

#define int long long

int64_t countAntipalindromicSubstrings(const std::string& s) {
    int n = s.size();
    int64_t total = 0;

    int center = 0, right = 0;
    std::vector<int> P(n, 0);

    for (int i = 0; i < n - 1; ++i) {
        int mirror = 2 * center - i;

        if (i < right) {
            P[i] = std::min(right - i, P[mirror]);
        }

        while (i - P[i] >= 0 && i + 1 + P[i] < n && s[i - P[i]] != s[i + 1 + P[i]]) {
            ++P[i];
        }

        if (i + P[i] > right) {
            center = i;
            right = i + P[i];
        }

        total += P[i];
    }

    return total;
}

void solve() {
    int n;
    std::cin >> n;

    std::string s;
    std::cin >> s;

    int ans = countAntipalindromicSubstrings(s);
    std::cout << ans << std::endl;
}

int32_t main() {
    std::ios_base::sync_with_stdio(0);
    std::cin.tie(0);
    std::cout.tie(0);

    int t = 1;

    for (; t > 0; t--) {
        solve();
    }

    return 0;
}