#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b+a); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(a) (a).begin(), (a).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());


int main1() {
    // int N; string S;
    // cin >> N >> S;

  int N; 
  // cin >> n;
  N = 4000;
  string S; 
  // cin >> s;
  S = "GBRBRGGRRBRGBBGGRRGBRGGBRGGGBBGRGBRBRGGBGGGGRRGGBGGRGGGGRRGGRRGBBBGGRBGRRBBGGBRRBGGGGGBGGBGGRBBBGBGRGGRBGGRGRRRBRGBBBGGGRRBGRBBGGRGGRGRBGRRBGGRBRGGBBRGBRGRRGGRBGBRGBRGRRBGBRRBGRGBBGBRBGBBRBBGBBGBGGRBBRGRRGGRRBBBBRBBGBBGGRGRBBGGGBGGGGRRBBRGBBBBBRGGGBGGBBBRGRGRBGGGGBGBRGGBRGBRRRBGGBBRBBGGRRRBRRBRGGBGBBRBRRBGRGRBRBRRGRRRRRBRBRRBGBRRRGBBRRRRRGRRBBRBGGBRRGBRGBBBBBGRGBGBBRBBBRBRBBBBBRGRGGRGBBGRRGRGRGGGBBBBBGRGBBRBBGRGGGRGRRGGRGBBBGRGGGRBBBRRBBGBGRBRGBRRRBGRBGRBBBRGRGGBBBGBBGGGGRBRBRBBGBRRRBGBBGRBGRGRRBBGBBBRRRBGBRRBGBGGRBBBGGGBRRBRRRRBRBRGBRBGRBRGGRRRRBBGRBGRBGRGRRGRGGGBBRGRBGBRGBBBGBRBBRBBBRBBRGRGGBRRBRGRRGGRRBBRGRGBRGGBGRGGGRBBRRRBRBRRGGGRRGBGBBBRGGRGRGBBGGGBRGGGGRBBGBBBBGGRRBGGBGRRGBBRGBGGBRGRRBGRRRRR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BGRBGRRRGRRGGGBGBBBBBBRGGBRGBGRGGGBGGRBRRGRRRBRRBBGBGRBGGRBGRGRBGRRGBGGGRRGBRGGGGBGBRRBGGGRRRGGBBRBRRRBGGGGGBRBGGBBGRRRRGBBGGBRGGRBRBRGRRGRGBBGRBRGBRRGRRGGBBGGBBRRRBRBRGGGGRRGGBRBRBRBGRRBRRGGGRBGRBRGRBRRBBBBGBGRBGBGBRRGRG";
    long long r = 0, g = 0, b = 0;
    for (auto c : S) {
        if (c == 'R') ++r;
        else if (c == 'G') ++g;
        else ++b;
    }
    long long all = r * g * b;

  cout << all << endl;
    long long sub = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = i+1; j < N; ++j) {
            if (S[i] == S[j]) continue;
            int k = j*2-i;
            if (k >= N || S[k] == S[i] || S[k] == S[j]) continue;
            ++sub;
        }
    }
    cout << all - sub << endl;
}

int main2() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n; 
  cin >> n;
  // n = 4000;
  string s; 
  cin >> s;
  // s = "GBRBRGGRRBRGBBGGRRGBRGGBRGGGBBGRGBRBRGGBGGGGRRGGBGGRGGGGRRGGRRGBBBGGRBGRRBBGGBRRBGGGGGBGGBGGRBBBGBGRGGRBGGRGRRRBRGBBBGGGRRBGRBBGGRGGRGRBGRRBGGRBRGGBBRGBRGRRGGRBGBRGBRGRRBGBRRBGRGBBGBRBGBBRBBGBBGBGGRBBRGRRGGRRBBBBRBBGBBGGRGRBBGGGBGGGGRRBBRGBBBBBRGGGBGGBBBRGRGRBGGGGBGBRGGBRGBRRRBGGBBRBBGGRRRBRRBRGGBGBBRBRRBGRGRBRBRRGRRRRRBRBRRBGBRRRGBBRRRRRGRRBBRBGGBRRGBRGBBBBBGRGBGBBRBBBRBRBBBBBRGRGGRGBBGRRGRGRGGGBBBBBGRGBBRBBGRGGGRGRRGGRGBBBGRGGGRBBBRRBBGBGRBRGBRRRBGRBGRBBBRGRGGBBBGBBGGGGRBRBRBBGBRRRBGBBGRBGR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RBRGGBRGBRBBRGGBRBGBRRBGRBBBGBGRBGGRBBBBGRGGGBGBBGGRBGBRGBRRRRGGGGRGGBRGBBBBRRGGBBRRRGBBBRRBBRBGBBRGGRRGGRBGGBGBGBRRBGGGGBBGGGRRRBBBRRRGRGRBGRBGGBBGRBRRGRBRBGRGGBRGGGRBBBBBBGGRRGGRGGGRBRRGGBRGGGGBBGRGBBGBBGBBRGBGRBGRRRGRRGGGBGBBBBBBRGGBRGBGRGGGBGGRBRRGRRRBRRBBGBGRBGGRBGRGRBGRRGBGGGRRGBRGGGGBGBRRBGGGRRRGGBBRBRRRBGGGGGBRBGGBBGRRRRGBBGGBRGGRBRBRGRRGRGBBGRBRGBRRGRRGGBBGGBBRRRBRBRGGGGRRGGBRBRBRBGRRBRRGGGRBGRBRGRBRRBBBBGBGRBGBGBRRGRG";

  // r,g,b のすべての組み合わせ
  // - r,g,b の組み合わせかつ index の差が等しい

  ll ac = 0,gc = 0,bc = 0;

  rep(i,n) {
    if (s[i] == 'R') {
      ac += 1;
    } else if (s[i] == 'G') {
      gc += 1;
    } else if (s[i] == 'B') {
      bc += 1;
    }
  }
  // すべての組み合わせ
  ll sum = ac*gc*bc;

  // cout << sum << endl;

  // index の差が等しい
  ll minus = 0;
  for (int i = 0; i < n; i++)
  {
    for (int j = i+1; j < n; j++)
    {
      int k = j + j - i;
      if (k >= n) continue;
      if (s[i] == s[j] || s[i] == s[k] || s[j] == s[k]) continue;
      minus++;
    }
  }
  
  cout << sum - minus << endl;

  return 0;
}

int main() {
//   2369716640
// 2368828716
  main2();
}

Measured memory_bytes: 3664