#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pii = pair<int, int>;
using pll = pair<lint, lint>;
template <typename T>
using vc = vector<T>;
template <typename T>
using vvc = vector<vector<T>>;
template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
constexpr lint ten(int n) { return n == 0 ? 1 : ten(n - 1) * 10; }
class Task {
 public:
  lint f(string& s) {
    int lasta = -1, lastb = -1, n = (int)(s).size();
    lint res = 0;
    for (int i = (0); i < (n); ++i) {
      if (s[i] == 'A') {
        if (lasta > -1) res += i - lasta;
        lasta = i;
      } else {
        if (lastb > -1) res += i - lastb;
        lastb = i;
      }
    }
    if (lasta > -1) res += n - lasta;
    if (lastb > -1) res += n - lastb;
    return res;
  }
  void solve(istream& in, ostream& out) {
    int N;
    in >> N;
    string S;
    in >> S;
    lint ans = 1ll * N * (N + 1) / 2;
    ans -= f(S);
    reverse((S).begin(), (S).end());
    ans -= f(S);
    ans += N;
    for (int i = (0); i < (N - 1); ++i)
      if (S[i] != S[i + 1]) ++ans;
    out << ans << '\n';
  }
};
int main() {
  istream& in(cin);
  ostream& out(cout);
  ios_base::sync_with_stdio(false);
  in.tie(nullptr), out.tie(nullptr);
  Task solver;
  solver.solve(in, out);
  return 0;
}
