#include <algorithm>
#include <bits/stdc++.h>
#include <cstddef>
#include <cstdint>
#include <functional>
#include <iostream>
#include <iterator>
#include <stdexcept>
#include <type_traits>
#include <vector>

// lib/monoid.hpp
#ifndef MONOID_HPP
#define MONOID_HPP


namespace tools {
  template <typename T>
  class monoid {
  private:
    ::std::function<T(T, T)> m_operation;
    T m_identity;

  public:
    monoid(const ::std::function<T(T, T)>& operation, const T& identity) :
      m_operation(operation),
      m_identity(identity) {
    }
    monoid(const ::tools::monoid<T>&) = default;
    monoid(::tools::monoid<T>&&) = default;
    ::tools::monoid<T>& operator=(const ::tools::monoid<T>&) = default;
    ::tools::monoid<T>& operator=(::tools::monoid<T>&&) = default;
    virtual ~monoid() = default;

    T operation(const T& x, const T& y) const {
      return this->m_operation(x, y);
    }
    const T& identity() const {
      return this->m_identity;
    }

    template <typename U = T, typename ::std::enable_if<::std::is_integral<U>::value, ::std::nullptr_t>::type = nullptr>
    static ::tools::monoid<U> multiplies() {
      return ::tools::monoid<U>(::std::multiplies<U>(), 1);
    }
  };
}

#endif

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// lib/group.hpp
#ifndef GROUP_HPP
#define GROUP_HPP


namespace tools {
  template <typename T>
  class group : public ::tools::monoid<T> {
  private:
    ::std::function<T(T)> m_inverse;

  public:
    group(const ::std::function<T(T, T)>& operation, const T& identity, const ::std::function<T(T)>& inverse) :
      ::tools::monoid<T>(operation, identity), m_inverse(inverse) {
    }
    group(const ::tools::group<T>&) = default;
    group(::tools::group<T>&&) = default;
    ::tools::group<T>& operator=(const ::tools::group<T>&) = default;
    ::tools::group<T>& operator=(::tools::group<T>&&) = default;
    virtual ~group() = default;

    T inverse(const T& x) const {
      return this->m_inverse(x);
    }

    template <typename U = T, typename ::std::enable_if<::std::is_integral<U>::value, ::std::nullptr_t>::type = nullptr>
    static ::tools::group<U> plus() {
      return ::tools::group<U>(::std::plus<U>(), 0, ::std::negate<U>());
    }
  };
}

#endif

// lib/cumsum.hpp
#ifndef CUMSUM_HPP
#define CUMSUM_HPP


/*
usage:

// 元配列はa[y][x]の形で値が格納されているとする
std::vector<std::vector<int>> a;
const auto cumsum = tools::cumsum2d(tools::group<int>::plus(), a.begin(), a.end());
cumsum(x1, y1, x2, y2);
*/

namespace tools {
  namespace detail {
    namespace cumsum {
      template <typename Iterator>
      class monoid1d {
      private:
        using T = typename ::std::iterator_traits<Iterator>::value_type;
        ::tools::monoid<T> monoid;
        ::std::vector<T> from_left;
        ::std::vector<T> from_right;

      public:
        monoid1d(const ::tools::monoid<T>& monoid, const Iterator& begin, const Iterator& end) :
          monoid(monoid), from_left({monoid.identity()}), from_right({monoid.identity()}) {
          ::std::vector<T> source;
          ::std::copy(begin, end, ::std::back_inserter(source));
          this->from_left.reserve(source.size() + 1);
          for (const T& source_i : source) {
            this->from_left.push_back(monoid.operation(this->from_left.back(), source_i));
          }
          ::std::reverse(source.begin(), source.end());
          this->from_right.reserve(source.size() + 1);
          for (const T& source_i : source) {
            this->from_right.push_back(monoid.operation(this->from_right.back(), source_i));
          }
          ::std::reverse(this->from_right.begin(), this->from_right.end());
        }

        T operator()(const ::std::size_t l, const ::std::size_t r) const {
          if (l == 0) {
            return this->from_left[r];
          } else if (r + 1 == this->from_right.size()) {
            return this->from_right[l];
          } else {
            throw ::std::runtime_error("Unsupported operation.");
          }
        }
      };

      template <typename Iterator>
      class group1d {
      private:
        using T = typename ::std::iterator_traits<Iterator>::value_type;
        ::tools::group<T> group;
        ::std::vector<T> preprocessed;

      public:
        group1d(const ::tools::group<T>& group, const Iterator& begin, const Iterator& end) :
          group(group), preprocessed({group.identity()}) {
          for (Iterator it = begin; it != end; ++it) {
            this->preprocessed.push_back(group.operation(this->preprocessed.back(), *it));
          }
        }

        T operator()(const ::std::size_t l, const ::std::size_t r) const {
          return this->group.operation(this->preprocessed[r], this->group.inverse(this->preprocessed[l]));
        }
      };

      template <typename Iterator>
      class group2d {
      private:
        using OuterT = typename ::std::iterator_traits<Iterator>::value_type;
        using T = typename ::std::iterator_traits<typename OuterT::iterator>::value_type;
        ::tools::group<T> group;
        ::std::vector<::std::vector<T>> preprocessed;

      public:
        group2d(const ::tools::group<T>& group, const Iterator& begin, const Iterator& end) :
          group(group),
          preprocessed(
            ::std::distance(begin, end) + 1,
            ::std::vector<T>((begin == end ? 0 : ::std::distance(::std::begin(*begin), ::std::end(*begin))) + 1, group.identity())
          )
        {
          const ::std::size_t height = ::std::distance(begin, end);
          const ::std::size_t width = begin == end ? 0 : ::std::distance(::std::begin(*begin), ::std::end(*begin));

          {
            Iterator it1 = begin;
            for (::std::size_t y = 0; y < height; ++y, ++it1) {
              auto it2 = ::std::begin(*it1);
              for (::std::size_t x = 0; x < width; ++x, ++it2) {
                this->preprocessed[y + 1][x + 1] = group.operation(this->preprocessed[y + 1][x], *it2);
              }
            }
          }
          for (::std::size_t x = 0; x < width; ++x) {
            for (::std::size_t y = 0; y < height; ++y) {
              this->preprocessed[y + 1][x + 1] = group.operation(this->preprocessed[y][x + 1], this->preprocessed[y + 1][x + 1]);
            }
          }
        }

        T operator()(const ::std::size_t x1, const ::std::size_t y1, const ::std::size_t x2, const ::std::size_t y2) const {
          T tmp = this->group.operation(this->preprocessed[y2][x2], this->group.inverse(this->preprocessed[y2][x1]));
          tmp = this->group.operation(tmp, this->group.inverse(this->preprocessed[y1][x2]));
          return this->group.operation(tmp, this->preprocessed[y1][x1]);
        }
      };
    }
  }

  template <typename Iterator>
  ::std::function<typename ::std::iterator_traits<Iterator>::value_type(::std::size_t, ::std::size_t)> cumsum1d(
    const ::tools::monoid<typename ::std::iterator_traits<Iterator>::value_type>& monoid,
    const Iterator& begin,
    const Iterator& end
  ) {
    return ::tools::detail::cumsum::monoid1d<Iterator>(monoid, begin, end);
  }

  template <typename Iterator>
  ::std::function<typename ::std::iterator_traits<Iterator>::value_type(::std::size_t, ::std::size_t)> cumsum1d(
    const ::tools::group<typename ::std::iterator_traits<Iterator>::value_type>& group,
    const Iterator& begin,
    const Iterator& end
  ) {
    return ::tools::detail::cumsum::group1d<Iterator>(group, begin, end);
  }

  template <typename Iterator>
  ::std::function<typename ::std::iterator_traits<typename ::std::iterator_traits<Iterator>::value_type::iterator>::value_type(::std::size_t, ::std::size_t, ::std::size_t, ::std::size_t)> cumsum2d(
    const ::tools::group<typename ::std::iterator_traits<typename ::std::iterator_traits<Iterator>::value_type::iterator>::value_type>& group,
    const Iterator& begin,
    const Iterator& end
  ) {
    return ::tools::detail::cumsum::group2d<Iterator>(group, begin, end);
  }
}

#endif

// main.cpp

int main() {
  i64 N;
  std::string S;
  std::cin >> N >> S;

  std::unordered_map<char, i64> to_code = {{'R', 0}, {'G', 1}, {'B', 2}};
  constexpr i64 variety = 3;
  std::array<std::vector<i64>, variety> base = {std::vector<i64>(N, 0), std::vector<i64>(N, 0), std::vector<i64>(N, 0)};
  for (i64 i = 0; i < N; ++i) {
    ++base[to_code[S[i]]][i];
  }

  std::array<std::function<i64(std::size_t, std::size_t)>, variety> cumsum;
  for (i64 code = 0; code < variety; ++code) {
    cumsum[code] = tools::cumsum1d(tools::group<i64>::plus(), base[code].begin(), base[code].end());
  }

  i64 answer = 0;
  for (i64 i = 0; i < N; ++i) {
    const i64 code = to_code[S[i]];
    const i64 another_code = (code + 1) % 3;
    const i64 yet_another_code = (another_code + 1) % 3;
    answer += cumsum[another_code](0, i) * cumsum[yet_another_code](i + 1, N) + cumsum[yet_another_code](0, i) * cumsum[another_code](i + 1, N);
    for (i64 j = 1; 0 <= i - j && i + j < N; ++j) {
      if ((to_code[S[i - j]] == another_code && to_code[S[i + j]] == yet_another_code) || (to_code[S[i - j]] == yet_another_code && to_code[S[i + j]] == another_code)) {
        --answer;
      }
    }
  }

  std::cout << answer << std::endl;
  return 0;
}

Measured memory_bytes: 3868