/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-04-12 20:34:27
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { os << '{'; for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } os << '}'; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

template <class _Tp>
class CumulativeSum {
 public:
  CumulativeSum(const std::vector<_Tp>& vec) : vec_(vec) { build(); }

  // return sum of [l, r]
  _Tp get(int l, int r) { return sum_[r + 1] - sum_[l]; }

 private:
  std::vector<_Tp> vec_;
  std::vector<_Tp> sum_;

  void build() {
    sum_.assign(vec_.size() + 1, static_cast<_Tp>(0));
    for (size_t i = 0; i < vec_.size(); ++i) {
      sum_[i + 1] = sum_[i] + vec_[i];
    }
  }
};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n; cin >> n;
  string s; cin >> s;

  int64 ans = 0;

  vector<int> dp_R(n, 0), dp_G(n, 0), dp_B(n, 0);

  for (int i = 0; i < n; ++i) {
    dp_R[i] += s[i] == 'R';
    dp_G[i] += s[i] == 'G';
    dp_B[i] += s[i] == 'B';
  }

  CumulativeSum<int> csR(dp_R);
  CumulativeSum<int> csG(dp_G);
  CumulativeSum<int> csB(dp_B);

  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      if (s[i] == s[j]) continue;
      int diff = j - i;
      if ((s[i] == 'R' && s[j] == 'G') || (s[i] == 'G' && s[j] == 'R')) {
        ans += csB.get(j + 1, n - 1);
        if (j + diff < n && s[j + diff] == 'B') --ans;
      } else if ((s[i] == 'R' && s[j] == 'B') || (s[i] == 'B' && s[j] == 'R')) {
        ans += csG.get(j + 1, n - 1);
        if (j + diff < n && s[j + diff] == 'G') --ans;
      } else if ((s[i] == 'B' && s[j] == 'G') || (s[i] == 'G' && s[j] == 'B')) {
        ans += csR.get(j + 1, n - 1);
        if (j + diff < n && s[j + diff] == 'R') --ans;
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3744