#include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    string s;
    cin >> n >> s;
    long long ans = 1LL * n * (n + 1) / 2;      // 每个子串至少贡献 1
    for (int i = 0; i + 1 < n; ++i) {
        if (s[i] != s[i + 1]) {
            // 边界 i(1-based 为 i+1)被覆盖的子串个数
            ans += 1LL * (i + 1) * (n - (i + 1));
        }
    }
    cout << ans << '\n';
    return 0;
}