jiahuimbzuai/CoQuIR huggingface dataset:
//  [cpp]
#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

// 3乗で通したお詫びにO(NlogN)で通します
// 参考 : https://twitter.com/SayakaAmemiya/status/1249515024541859842

template<int mod, int proot> struct NTT {
	int get_mod() { return mod; }
	int pow(int a, int b) {
	int res = 1;
		for (; b; b >>= 1) {
			if (b & 1) res = (int64_t) res * a % mod;
			a = (int64_t) a * a % mod;
		}
		return res;
	}
	int inv(int i) { return pow(i, mod - 2); }
	void ntt(std::vector<int> &a, bool inverse) {
		int n = a.size();
		assert((n & -n) == n);
		int h = pow(proot, (mod - 1) / n);
		if (inverse) h = inv(h);
		
		for (int i = 0, j = 1; j < n - 1; j++) {
			for (int k = n >> 1; k > (i ^= k); k >>= 1);
			if (j < i) std::swap(a[i], a[j]);
		}
		for (int i = 1; i < n; i <<= 1) {
			int base = pow(h, n / i / 2);
			int w = 1;
			
			std::vector<int> ws(i);
			for (int j = 0; j < i; j++) ws[j] = w, w = (int64_t) w * base % mod;
			
			for (int j = 0; j < n; j += i << 1) {
				for (int k = 0; k < i; k++) {
					int u = a[k + j];
					int d = (int64_t) a[k + j + i] * ws[k] % mod;
					a[k + j] = u + d >= mod ? u + d - mod : u + d;
					a[k + j + i] = d > u ? u + mod - d : u - d;
				}
			}
		}
		if (inverse) {
			int ninv = inv(a.size());
			for (auto &i : a) i = (int64_t) i * ninv % mod;
		}
	}
};

int main() {
	int n = ri();
	int back[3] = { 0 };
	int forward[3] = { 0 };
	std::vector<int> a(n);
	{
		char tmp[4096];
		scanf("%s", tmp);
		for (int i = 0; i < n; i++) {
			a[i] = tmp[i] == 'R' ? 0 : tmp[i] == 'G' ? 1 : 2;
			back[a[i]]++;
		}
	}
	
	int64_t res = 0;
	// j - i != k - jを無視したの
	for (int j = 0; j < n; j++) {
		back[a[j]]--;
		res += forward[(a[j] + 1) % 3] * back[(a[j] + 2) % 3];
		res += forward[(a[j] + 2) % 3] * back[(a[j] + 1) % 3];
		forward[a[j]]++;
	}
	// j - i == k - jで相異なるものを引く
	int n2 = 1;
	for (; n2 < n + n - 1; n2 <<= 1);
	NTT<40961, 3> ntt;
	std::vector<int> count[3];
	for (auto &i : count) i.resize(n2);
	for (int i = 0; i < n; i++) count[a[i]][i]++;
	for (auto &i : count) ntt.ntt(i, false);
	
	std::vector<int> conved[3]; // conved count[i], count[(i + 1) % 3]
	for (int i = 0; i < 3; i++) {
		auto &cur = conved[i];
		cur.resize(n2);
		for (int j = 0; j < n2; j++) cur[j] = (int64_t) count[i][j] * count[(i + 1) % 3][j] % 40961;
		ntt.ntt(cur, true);
	}
	for (int j = 0; j < n; j++) res -= conved[(a[j] + 1) % 3][j + j];
	
	printf("%" PRId64 "\n", res);
	
	return 0;
}
//  [cpp]
#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

// 3乗で通したお詫びにO(NlogN)で通します
// 参考 : https://twitter.com/SayakaAmemiya/status/1249515024541859842

template<int mod, int proot> struct NTT {
	int get_mod() { return mod; }
	int pow(int a, int b) {
	int res = 1;
		for (; b; b >>= 1) {
			if (b & 1) res = (int64_t) res * a % mod;
			a = (int64_t) a * a % mod;
		}
		return res;
	}
	int inv(int i) { return pow(i, mod - 2); }
	void ntt(std::vector<int> &a, bool inverse) {
		int n = a.size();
		assert((n & -n) == n);
		int h = pow(proot, (mod - 1) / n);
		if (inverse) h = inv(h);
		
		for (int i = 0, j = 1; j < n - 1; j++) {
			for (int k = n >> 1; k > (i ^= k); k >>= 1);
			if (j < i) std::swap(a[i], a[j]);
		}
		for (int i = 1; i < n; i <<= 1) {
			int base = pow(h, n / i / 2);
			int w = 1;
			
			std::vector<int> ws(i);
			for (int j = 0; j < i; j++) ws[j] = w, w = (int64_t) w * base % mod;
			
			for (int j = 0; j < n; j += i << 1) {
				for (int k = 0; k < i; k++) {
					int u = a[k + j];
					int d = (int64_t) a[k + j + i] * ws[k] % mod;
					a[k + j] = u + d >= mod ? u + d - mod : u + d;
					a[k + j + i] = d > u ? u + mod - d : u - d;
				}
			}
		}
		if (inverse) {
			int ninv = inv(a.size());
			for (auto &i : a) i = (int64_t) i * ninv % mod;
		}
	}
};

int main() {
	int n = ri();
	int back[3] = { 0 };
	int forward[3] = { 0 };
	std::vector<int> a(n);
	{
		char tmp[4096];
		scanf("%s", tmp);
		for (int i = 0; i < n; i++) {
			a[i] = tmp[i] == 'R' ? 0 : tmp[i] == 'G' ? 1 : 2;
			back[a[i]]++;
		}
	}
	
	int64_t res = 0;
	// j - i != k - jを無視したの
	for (int j = 0; j < n; j++) {
		back[a[j]]--;
		res += forward[(a[j] + 1) % 3] * back[(a[j] + 2) % 3];
		res += forward[(a[j] + 2) % 3] * back[(a[j] + 1) % 3];
		forward[a[j]]++;
	}
	// j - i == k - jで相異なるものを引く
	int n2 = 1;
	for (; n2 < n + n - 1; n2 <<= 1);
	NTT<998244353, 3> ntt;
	std::vector<int> count[3];
	for (auto &i : count) i.resize(n2);
	for (int i = 0; i < n; i++) count[a[i]][i]++;
	for (auto &i : count) ntt.ntt(i, false);
	
	std::vector<int> conved[3]; // conved count[i], count[(i + 1) % 3]
	for (int i = 0; i < 3; i++) {
		auto &cur = conved[i];
		cur.resize(n2);
		for (int j = 0; j < n2; j++) cur[j] = (int64_t) count[i][j] * count[(i + 1) % 3][j] % 998244353;
		ntt.ntt(cur, true);
	}
	for (int j = 0; j < n; j++) res -= conved[(a[j] + 1) % 3][j + j];
	
	printf("%" PRId64 "\n", res);
	
	return 0;
}
//  [cpp]
#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

// 3乗で通したお詫びにO(NlogN)で通します
// 参考 : https://twitter.com/SayakaAmemiya/status/1249515024541859842

template<int mod, int proot> struct NTT {
	int get_mod() { return mod; }
	int pow(int a, int b) {
	int res = 1;
		for (; b; b >>= 1) {
			if (b & 1) res = (int64_t) res * a % mod;
			a = (int64_t) a * a % mod;
		}
		return res;
	}
	int inv(int i) { return pow(i, mod - 2); }
	void ntt(std::vector<int> &a, bool inverse) {
		int n = a.size();
		assert((n & -n) == n);
		int h = pow(proot, (mod - 1) / n);
		if (inverse) h = inv(h);
		
		for (int i = 0, j = 1; j < n - 1; j++) {
			for (int k = n >> 1; k > (i ^= k); k >>= 1);
			if (j < i) std::swap(a[i], a[j]);
		}
		for (int i = 1; i < n; i <<= 1) {
			int base = pow(h, n / i / 2);
			int w = 1;
			
			std::vector<int> ws(i);
			for (int j = 0; j < i; j++) ws[j] = w, w = (int64_t) w * base % mod;
			
			for (int j = 0; j < n; j += i << 1) {
				for (int k = 0; k < i; k++) {
					int u = a[k + j];
					int d = (int64_t) a[k + j + i] * ws[k] % mod;
					a[k + j] = u + d >= mod ? u + d - mod : u + d;
					a[k + j + i] = d > u ? u + mod - d : u - d;
				}
			}
		}
		if (inverse) {
			int ninv = inv(a.size());
			for (auto &i : a) i = (int64_t) i * ninv % mod;
		}
	}
};

char inputbuf[4096];
char *ptr = inputbuf;

int main() {
	fread(inputbuf, 1, sizeof(inputbuf), stdin);
	int n = 0;
	while (*ptr >= '0' && *ptr <= '9') n = n * 10 + *ptr++ - '0';
	while (*ptr != 'R' && *ptr != 'G' && *ptr != 'B') ptr++;
	
	int back[3] = { 0 };
	int forward[3] = { 0 };
	std::vector<int> a(n);
	{
		for (int i = 0; i < n; i++) {
			a[i] = *ptr == 'R' ? 0 : *ptr == 'G' ? 1 : 2;
			back[a[i]]++;
			ptr++;
		}
	}
	
	int64_t res = 0;
	// j - i != k - jを無視したの
	for (int j = 0; j < n; j++) {
		back[a[j]]--;
		res += forward[(a[j] + 1) % 3] * back[(a[j] + 2) % 3];
		res += forward[(a[j] + 2) % 3] * back[(a[j] + 1) % 3];
		forward[a[j]]++;
	}
	// j - i == k - jで相異なるものを引く
	int n2 = 1;
	for (; n2 < n + n - 1; n2 <<= 1);
	NTT<40961, 3> ntt;
	std::vector<int> count[3];
	for (auto &i : count) i.resize(n2);
	for (int i = 0; i < n; i++) count[a[i]][i]++;
	for (auto &i : count) ntt.ntt(i, false);
	
	std::vector<int> conved[3]; // conved count[i], count[(i + 1) % 3]
	for (int i = 0; i < 3; i++) {
		auto &cur = conved[i];
		cur.resize(n2);
		for (int j = 0; j < n2; j++) cur[j] = (int64_t) count[i][j] * count[(i + 1) % 3][j] % 40961;
		ntt.ntt(cur, true);
	}
	for (int j = 0; j < n; j++) res -= conved[(a[j] + 1) % 3][j + j];
	
	printf("%" PRId64 "\n", res);
	
	return 0;
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;

int main(){
  long long n;
  cin >> n;
 
  string s;
  cin >> s;
  int r=0,g=0,b=0;

  for(int i=0;i<n;i++){
    if(s[i] == 'R')r++;
    if(s[i] == 'G')g++;
    if(s[i] == 'B')b++;
  }

  int cnt = 0;
  for(int i=0;i<=n-3;i++){
    for(int j=i+1;j<=n-2;j++){
      int k = j+(j-i);
      if(k>=n)break;
      if(s[i] != s[j] && s[j] != s[k] && s[k] != s[i])cnt++;
    }
  }
  cout << r*g*b - cnt << endl;
  
  return 0;
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  string s;
  cin >> n >> s;
  
  int r = 0, g = 0, b = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'R') r++;
    else if (s[i] == 'G') g++;
    else if (s[i] == 'B') b++;
  }
  
  int cnt = 0;
  
  for (int i = 0; i < n-2; i++) {
    for (int j = i+1; j < n-1; j++) {
      int k = j + j-i;
      if (k >= n) break;
      if (s[i] != s[j] && s[i] != s[k] && s[j] != s[k]) cnt++;
    }
  }
  
  cout << r*g*b - cnt;
  
  return 0;
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  string s;
  cin >> n >> s;
  
  int r = 0, g = 0, b = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'R') r++;
    else if (s[i] == 'G') g++;
    else if (s[i] == 'B') b++;
  }
  
  int cnt = 0;
  
  for (int i = 0; i <= n-3; i++) {
    for (int j = i+1; j <= n-2; j++) {
      int k = j + j-i;
      if (k >= n) break;
      if (s[i] != s[j] && s[i] != s[k] && s[j] != s[k]) cnt++;
    }
  }
  
  cout << r*g*b - cnt;
  
  return 0;
}
//  [c]
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define STR_MAX 4000
#define BUF_SIZE (STR_MAX+10)

// size: specify sizeof(str)
int get_str(char *str, int size) {
    if(!fgets(str, size, stdin)) return -1;
    return 0;
}

int get_int(void) {
  int num;
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return 0;
  sscanf(line, "%d", &num);
#else
#error
#endif
  return num;
}

enum {
    ENUM_RED,
    ENUM_GREEN,
    ENUM_BLUE,
    ENUM_ALL
};

int table[256] = {
    ['R'] = 1<<ENUM_RED,
    ['G'] = 1<<ENUM_GREEN,
    ['B'] = 1<<ENUM_BLUE,
};

#define ALL_TYPE ((1<<ENUM_ALL) - 1)


int main(void) {
    int len = get_int(); // length
    char str[BUF_SIZE];
    get_str(str, BUF_SIZE);
    char type[BUF_SIZE] = {0};
    int i;
    for(i = 0; i < len; i++) {
        type[i] = table[str[i]];
    }
    static uint64_t dp[STR_MAX+1][1<<ENUM_ALL] = {0};
    dp[0][0] = 1;
    int pat;
    for(i = 1; i <= len; i++) {
        int tp = type[i-1];
        for(pat = 0; pat < (1<<ENUM_ALL); pat++) {
            dp[i][pat] = dp[i-1][pat];
            if(!(tp & pat)) { continue; }
            int prev_tp = pat & (~(tp));
            dp[i][pat] += dp[i-1][prev_tp];
#ifdef DEBUG
            printf("[%d]: dp[%d][%d -> %d] = %llu\n",tp, i,prev_tp, pat, dp[i][pat]);
#endif
        }
    }
    uint64_t exclude = 0;
    int dist;
    for(dist = 1; dist < len; dist++) {
        for(i = 0; i < len; i++) {
            if(i + 2*dist >= len) break;
            if((type[i] | type[i+dist] | type[i+dist*2]) == ALL_TYPE) exclude++;
        }
    }
#ifdef DEBUG
    printf("%llu %llu\n", dp[len][ALL_TYPE], exclude);
#endif
    printf("%llu\n", dp[len][ALL_TYPE]-exclude);
    return 0;
}
//  [c]
char S[4040];
i,j;c[99],t;
main(N)
{
	for(scanf("%d%s",&N,S);i<N;c[S[i++]]++)for(j=i;j>=0;j-=2)t-=(S[i]^S[i+j>>1]^S[j])==87;
	printf("%ld",1L*c[66]*c[71]*c[82]+t);
}
//  [c]
char S[4040];
i,j;c[99],t;
main(N)
{
	for(scanf("%d%s",&N,S);i<N;c[S[i++]]++)for(j=N-i+1>>1;j--;)t-=(S[i]^S[i+j]^S[i+j+j])==87;
	printf("%ld",1L*c[66]*c[71]*c[82]+t);
}
//  [c]
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<time.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define INI(n) scanf("%d",&n)
#define INL(n) scanf("%lld",&n)
#define INF 10000000000
#define mod 1000000007
#define X 100000
#define N 20
#define M 46
typedef long long int ll;
ll finv[X];
ll fac[X];
ll inv[X];
ll usort(const void *a, const void *b){return *(ll*)a-*(ll*)b;}
ll dsort(const void *a, const void *b){return *(ll*)b-*(ll*)a;}
ll ssort(const void *a, const void *b){return strcmp((char*)a,(char*)b);}
void Iswap(int *a,int *b){
  int t=*a;
  *a=*b;
  *b=t;
}
void Fswap(double *a,double *b){
  double t=*a;
  *a=*b;
  *b=t;
}
void Lswap(ll *a,ll *b){
  ll t=*a;
  *a=*b;
  *b=t;
}
ll min(ll a,ll b){
  if(a>b)return b;
  return a;
}
ll max(ll a,ll b){
  if(a>b)return a;
  return b;
}
ll z(ll a){return max(a,-a);}
ll gcd(ll a,ll b){if(!b){return a;}else{return gcd(b,a%b);}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
ll kt(ll a){
  ll sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
ll ks(ll a){
  ll sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
void nCrReady(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for (ll i=2;i<X;i++){
    fac[i]=fac[i-1]*i%mod;
    inv[i]=mod-inv[mod%i]*(mod/i)%mod;
    finv[i]=finv[i-1]*inv[i]%mod;
  }
}
ll nCr(ll n,ll k){return fac[n]*(finv[k]*finv[n-k]%mod)%mod;}

int main(void){
  int n;
  scanf("%d",&n);
  char s[n+1];
  int a[n];
  scanf("%s",s);
  int r=0,b=0,g=0;
  FOR(i,n){
    if(s[i]=='R'){
      r++;
      a[i]=2;
    }else if(s[i]=='B'){
      b++;
      a[i]=3;
    }else{
      g++;
      a[i]=5;
    }
  }
  ll ans=r*b*g;
  FOR(i,n){
    FOR(j,n){
      if(i+j*2<n){
        if(a[i]*a[i+j]*a[i+2*j]==30)ans--;
      }else{
        break;
      }
    }
  }
  PRL(ans);
  return 0;
}
//  [c]
#include <stdio.h>                                                                         int main(void){
  int N,r=0,g=0,b=0,i,j;
  long res=0;
  char S[5000];
  scanf("%d%s",&N,S);
  for(i=0;i<N;i++){
    if(S[i]=='R') r++;
    if(S[i]=='G') g++;
    if(S[i]=='B') b++;
  }
  res=r*g;
  res*=b;
  for(i=0;i<N-2;i++){
    for(j=i+1;j<N-1;j++){
      int k=2*j-i;
      if(S[i]!=S[j]&&S[i]!=S[k]&&S[j]!=S[k]&&k<N){
        res--;
      }
    }
  }
  printf("%ld",res);
  return 0;
}
//  [c]
#include  <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void){
  int n,i,j,k,r=0, g=0 ,b=0;
  long long count=0;
  char s[4005];
  scanf("%d",&n);
  scanf("%s",s);
  n=strlen(s);
  for(int l=0;l<n;l++){
    if(s[l]=='R') r++;
    if(s[l]=='G') g++;
    if(s[l]=='B') b++;
  }
  count=r*g*b;
  for(int i=0;i<n-2;i++){
    for(int j=i+1;j<n-1;j++){
      k=2*j-i;
        if(s[i]!=s[j]&&s[i]!=s[k]&&s[j]!=s[k]&&k<n){
          count--;


      }
    }
  }
  printf("%lld",count);

  return 0;
}
//  [javascript]
"use strict";

const main = arg => {
    const input = arg.trim().split("\n");

    const n = parseInt(input[0]);
    const s = input[1];
    let rs = []
    let gs = []
    let bs = []
    for(let i = 0; i<s.length;i++){
        if(s[i] === "R") rs.push(i)
        else if(s[i] === "G") gs.push(i) 
        else if(s[i] === "B") bs.push(i)
    }
    let num = rs.length * gs.length * bs.length
    for(let i = 0; i< n; i++){
        for(let j = i+1; j<n; j++){
            let k = j + j - i
            if (k >= n) break
            if( s[i] !== s[j] && s[j] !== s[k] && s[k] !== s[i]){
                num--
            }
        }
    }
    console.log(num)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [javascript]


        // if (j - i === k - j) {
        //   continue
        // }
        // if (S[i] !== S[j] && S[j] !== S[k] && S[i] !== S[k]) {
        //   count++
        // }

function main(input) {
  const inputs = input.split('\n')
  const N = Number(inputs[0])
  const S = inputs[1]
  const R = [], G = [], B = []
  S.split('').forEach((e, i) => {
    if (e === 'R') {
      R.push(i)
    } 
    if (e === 'G') {
      G.push(i)
    } 
    if (e === 'B') {
      B.push(i)
    } 
  })
  // console.log(R, G, B)

  // 貪欲
  // {
  //   let count = 0
  //   for(let i = 0; i < N - 2; i++) {
  //     for(let j = i + 1; j < N - 1; j++) {
  //       if (S[i] === S[j]) continue
  //       const ji = j - i
  //       for (let k = j + 1; k < N; k++) {
  //         if (S[j] === S[k]) continue
  //         if (k - j === ji) continue
  //         if (S[i] === S[k]) continue
  //         console.log('rgb:', i, j, k)
  //         count++
  //       }
  //     }
  //   }
  //   console.log('greedy:', count)
  // }

  let count = R.length * B.length * G.length
  // console.log(count)
  let notCount = 0
  for(let i = 0; i < N; i++) {
    for(let j = i + 1; j < N-1; j++) {
      const k = j * 2 - i
      if (k < N) {
        // console.log(i, j, k, S[i], S[j], S[k])
        if (S[i] !== S[j] && S[j] !== S[k] && S[i] !== S[k]) {
          // console.log('not count')
          notCount++
        }
      }
    }
  }

  console.log(count - notCount)

}
main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
function main(input) {
  const tmp = input.trim().split('\n')
  const n = parseInt(tmp[0], 10)
  const s = tmp[1]

  let r = 0
  let g = 0
  let b = 0

  for (let i = 0; i < n; i++) {
    if (s[i] == 'R') {
      r++
    } else if (s[i] == 'G') {
      g++
    } else {
      b++
    }
  }

  let answer = r * g * b
  for (let i = 0; i < n - 1; i++) {
    for (let j = i + 1; 2 * j - i < n; j++) {
      const k = 2 * j - i
      if (s[i] != s[j] && s[j] != s[k] && s[k] != s[i]) {
        answer--
      }
    }
  }

  console.log(answer)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))
//  [javascript]
function Main(input) {
  input = input.trim().split("\n").map(function(x) { return x.split(" ")});
  var N = parseInt(input[0],10);
  var S = input[1][0];
  console.log(S.substr(0,1));
  var vec_R = Array.from({length: N + 1}, () => 0);
  var vec_G = Array.from({length: N + 1}, () => 0);
  var vec_B = Array.from({length: N + 1}, () => 0);
  var arr_chr = [vec_R,vec_G,vec_B];
  var ans = 0;
  for(var i = S.length - 1; i >= 0; i--){
    if(S.substr(i, 1) === 'R') {
      vec_R[i] = vec_R[i + 1] + 1;
      vec_G[i] = vec_G[i + 1];
      vec_B[i] = vec_B[i + 1]; 
    }
    if(S.substr(i, 1) === 'G') {
      vec_R[i] = vec_R[i + 1];
      vec_G[i] = vec_G[i + 1] + 1;
      vec_B[i] = vec_B[i + 1];
    }
    if(S.substr(i, 1) === 'B') {
      vec_R[i] = vec_R[i + 1];
      vec_G[i] = vec_G[i + 1];
      vec_B[i] = vec_B[i + 1] + 1;
    }
  }
  vec_R = vec_R.pop();
  vec_G = vec_G.pop();
  vec_B = vec_B.pop();
  var a, b, c;
  var tmp = 0;
  for (var i = 0; i < (S.length - 3); i++){
    a = S.substr(i, 1);
    for (var j = i + 1; j < (S.length - 1); j++){
      b = S.substr(j, 1);
      if (a !== b){
        ans += arr_chr[chrSk_i(S, a, b)][j + 1];
        if (j+(j-i) < N && S.substr(j+(j-i), 1) !== a && S.substr(j+(j-i), 1) !== b) {
          ans --;
          tmp ++;
        }
      }
    }
  }
  function chrSk_i(S, a, b){
    if (a !== 'R' && b !== 'R') return 0;
    if (a !== 'G' && b !== 'G') return 1;
    if (a !== 'B' && b !== 'B') return 2;
  }
  console.log(ans);
}   

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
function main(input) {
  const inputs = input.split('\n')
  const N = Number(inputs[0])
  const S = inputs[1]

  // 貪欲

  let count = 0
  for(let i = 0; i < N - 2; i++) {
    for(let j = i + 1; j < N - 1; j++) {
      if (S[i] === S[j]) continue
      const ji = j - i
      for (let k = j + 1; k < N; k++) {
        if (S[j] === S[k]) continue
        if (k - j === ji) continue
        if (S[i] === S[k]) continue
        count++
      }
    }
  }
  console.log(count)
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
function main(input) {
  const inputs = input.split('\n')
  const N = Number(inputs[0])
  const S = inputs[1]

  // 貪欲

  let count = 0
  for(let i = 0; i < N - 2; i++) {
    for(let j = i + 1; j < N - 1; j++) {
      for (let k = j + 1; k < N; k++) {
        // console.log(i, j, k)
        if (j - i === k - j) {
          continue
        }
        if (S[i] !== S[j] && S[j] !== S[k] && S[i] !== S[k]) {
          count++
        }
      }
    }
  }
  console.log(count)
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var stdin = bufio.NewScanner(os.Stdin)

func main() {
	stdin.Split(bufio.ScanWords)
	N := nextInt()
	S := nextStr()
	sum := 0
	Rs := make([]int, 0, N)
	Gs := make([]int, 0, N)
	Bs := make([]int, 0, N)
	for i, c := range S {
		if c == 'R' {
			Rs = append(Rs, i)
		}
		if c == 'G' {
			Gs = append(Gs, i)
		}
		if c == 'B' {
			Bs = append(Bs, i)
		}
	}

	runes := []rune(S)
	for _, r := range Rs {
		for _, g := range Gs {
			var bindex int
			// right
			if r > g {
				bindex = 2*r - g
			} else {
				bindex = 2*g - r
			}
			if bindex < N && runes[bindex] == 'B' {
				sum++
			}
			// left
			if r > g {
				bindex = 2*g - r
			} else {
				bindex = 2*r - g
			}
			if bindex >= 0 && runes[bindex] == 'B' {
				sum++
			}
			// mid
			if (r+g)%2 == 0 && runes[(r+g)/2] == 'B' {
				sum++
			}
		}
	}

	// for i := 0; i < N-2; i++ {
	// 	for j := i + 1; j < N-1; j++ {
	// 		if S[i] == S[j] {
	// 			continue
	// 		}
	// 		for k := j + 1; k < N; k++ {
	// 			if j-i != k-j && S[i] != S[k] && S[j] != S[k] {
	// 				sum++
	// 			}
	// 		}
	// 	}
	// }
	fmt.Println(len(Rs)*len(Gs)*len(Bs) - sum)
}

func nextInt() int {
	stdin.Scan()
	i, err := strconv.Atoi(stdin.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func nextStr() string {
	stdin.Scan()
	i := stdin.Text()
	// if err != nil {
	// 	panic(err)
	// }
	return i
}
//  [go]
package main

import "fmt"

var (
	N          int
	S          string
	rs, gs, bs []int
)

func main() {
	fmt.Scan(&N, &S)
	rs = make([]int, 0, N)
	gs = make([]int, 0, N)
	bs = make([]int, 0, N)

	for i, c := range S {
		if c == 'R' {
			rs = append(rs, i)
		}
		if c == 'G' {
			gs = append(gs, i)
		}
		if c == 'B' {
			bs = append(bs, i)
		}
	}

	runes := []rune(S)
	ans := len(rs) * len(gs) * len(bs)
	for _, r := range rs {
		for _, g := range gs {
			k1 := max(r, g) + abs(r-g)
			k2 := min(r, g) - abs(r-g)
			if k1 > 0 && k1 < N && runes[k1] == 'B' {
				ans--
			}
			if k2 > 0 && k2 < N && runes[k2] == 'B' {
				ans--
			}
			if (r-g)%2 == 0 && runes[(r+g)/2] == 'B' {
				ans--
			}
		}
	}
	fmt.Println(ans)
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func search(i int, c rune) int {
	var x, y []int
	if c == 'R' {
		x, y = gs, bs
	} else if c == 'G' {
		x, y = rs, bs
	} else {
		x, y = rs, gs
	}
	ans := 0
	for _, j := range x {
		for _, k := range y {
			if j <= i || k <= i {
				continue
			}
			if max(j, k)-min(j, k) != min(j, k)-i {
				ans++
			}
		}
	}
	return ans
}

func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}
func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	} 
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	s := scanString()
	
	rc := 0
	gc := 0
	bc := 0

	for i := 0; i < n; i++ {
		if s[i] == 'R' {
			rc++
		} else if s[i] == 'G' {
			gc++
		} else {
			bc++
		}
	}

	ans := rc*gc*bc
	for i := 0; i < n; i++ {
		for j := 1; j < n; j++ {
			if i+j >= n || i+2*j >= n {
				break
			}
			if s[i] != s[i+j] && s[i+j] != s[i+2*j] && s[i] != s[i+2*j] {
				ans--
			}
		}
	}

	fmt.Fprintln(wr, ans)

}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

func main() {
	io := NewIo(os.Stdin, os.Stdout)
	defer io.Flush()
	_ = io.NextInt()
	s := io.Next()
	r, g, b := []int{}, []int{}, []int{}
	for i := range s {
		switch s[i] {
		case 'R':
			r = append(r, i)
		case 'G':
			g = append(g, i)
		case 'B':
			b = append(b, i)
		}
	}
	//logger.Println(r, g, b)
	ans := len(r) * len(g) * len(b)
	for i := range r {
		for j := range g {
			for k := range b {
				x, y, z := sort3(r[i], g[j], b[k])
				if x-2*y+z == 0 {
					//logger.Println(r[i], g[j], b[k])
					ans--
				}
			}
			/*
				k := sort.Search(len(b), func(k int) bool {
					x, y, z := sort3(r[i], g[j], b[k])
					return x-2*y+z >= 0
				})
				if k == len(b) {
					continue
				}
				x, y, z := sort3(r[i], g[j], b[k])
				if x-2*y+z == 0 {
					ans--
				}
			*/
		}
	}
	io.Println(ans)
}

func sort3(x, y, z int) (int, int, int) {
	if x > y {
		x, y = y, x
	}
	if y > z {
		y, z = z, y
	}
	if x > y {
		x, y = y, x
	}
	return x, y, z
}

// Io is I/O object
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

// NewIo returns a new Io instance
func NewIo(r io.Reader, w io.Writer) *Io {
	return &Io{
		reader: bufio.NewReader(r),
		writer: bufio.NewWriter(w),
	}
}

// Flush flushes writer
func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

// NextLine scans a line from stdin
func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

// Next return a word from stdin
func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

// NextInt returns an integer from stdin
func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

// Println is a wrapper of fmt.Fprintln
func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

const mod = 998244353
const facNum = 300001

func main() {
	sc := newScanner(os.Stdin)
	N := sc.i()
	S := sc.s()
	cnt := 0
	for i := 1; i <= N-2; i++ {
		for j := i + 1; j <= N-1; j++ {
			a := S[i-1]
			b := S[j-1]
			if a == b {
				continue
			}
			for k := j + 1; k <= N; k++ {
				if j-i == k-j {
					continue
				}
				c := S[k-1]
				if b == c || a == c {
					continue
				}
				cnt += 1
			}
		}
	}
	fmt.Println(cnt)
}

// fmt.Println("Yes")
// fmt.Println("No")

// I/O
type scanner struct {
	sc *bufio.Scanner
}

func newScanner(input io.Reader) *scanner {
	sc := bufio.NewScanner(input)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &scanner{sc}
}

func (s *scanner) s() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *scanner) i() int {
	i, e := strconv.Atoi(s.s())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *scanner) f() float64 {
	f, e := strconv.ParseFloat(s.s(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *scanner) bs() []byte {
	return []byte(s.s())
}

func (s *scanner) is(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.i()
	}
	return res
}

func (s *scanner) fs(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.f()
	}
	return res
}

//const factorial = new
func Pow(a, n int) int {
	ans := 1
	for n > 0 {
		if (n & 1) == 1 {
			ans = ans * a % mod
		}
		a = a * a % mod
		n = n >> 1
	}
	return ans
}

func Gcd(a, b int) int {
	if a < b {
		return Gcd(b, a)
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func combination(n, k int, fac, ifac []int) int {
	if n < k || n < 0 {
		return 0
	}
	if k == 0 {
		return 1
	}
	//while n != 0
	ans := ifac[k] * ifac[n-k] % mod
	return ans * fac[n] % mod
}

// 階乗: factorial
// コンビネーションを計算する際に前もって計算しておく
// fac[k] => k! (mod M)
// ifac[k] => k!^(M-2) (mod M)
// n: ex. 2 * 10^5 => 200001
// fac, ifac := factorial()
func factorial() (fac []int, ifac []int) {
	fac = make([]int, facNum)
	fac[0] = 1
	ifac = make([]int, facNum)
	ifac[0] = 1
	for i := 1; i < facNum; i++ {
		fac[i] = fac[i-1] * i % mod
		ifac[i] = ifac[i-1] * Pow(i, mod-2) % mod
	}
	return
}

// vs: sorted slice int value
func lowerBound(vs []int, v int) (index int) {
	n := len(vs) / 2
	m := len(vs)
	for m != n {
		if vs[n] < v {
			n = (m-n+1)/2 + n
			//m = m
		} else {
			m = n
			n = n / 2
		}
	}
	return n
}

func IntSlice(n, init int) []int {
	r := make([]int, n)
	for i := range r {
		r[i] = init
	}
	return r
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func scanInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func scanInt64() int64 {
	sc.Scan()
	i, _ := strconv.ParseInt(sc.Text(), 10, 64)
	return i
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func scanInts64(n int) []int64 {
	res := make([]int64, n)
	for i := range res {
		res[i] = scanInt64()
	}
	return res
}

func scanText() string {
	sc.Scan()
	return sc.Text()
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	n := scanInt()
	s := scanText()

	r := strings.Count(s, "R")
	g := strings.Count(s, "G")
	b := strings.Count(s, "B")

	ans := r * g * b

	for i := 1; i < n; i++ {
		for j := 1; j <= n; j++ {
			gi := i + j
			bi := gi + j
			if bi > n {
				break
			}
			if s[i-1:i] != s[gi-1:gi] && s[bi-1:bi] != s[gi-1:gi] && s[i-1:i] != s[bi-1:bi] {
				fmt.Println(i, gi, bi)
				ans--
			}
		}
	}
	fmt.Println(ans)
}
//  [ruby]
$n = gets.to_i
colors = gets.chomp.split("")
color_array = Array.new(3) { Array.new }
colors.each.with_index(1) do |color, index|
  case color
  when "R"
    color_array[0] << index
  when "G"
    color_array[1] << index
  when "B"
    color_array[2] << index
  end
end

$ngs = Array.new($n + 1, 0)

def count_ngs(a, b)
  gap = b - a
  $ngs[((a + b) / 2)] += 1 if gap.even?
  $ngs[a - gap] += 1 if (a - gap) > 0
  $ngs[b + gap] += 1 if (b + gap) <= $n
end

color_array[0].each do |i1|
  color_array[1].each do |i2|
    if i1 > i2
      count_ngs(i2, i1)
    else
      count_ngs(i1, i2)
    end
  end
end

ans = color_array[0].size * color_array[1].size * color_array[2].size

color_array[2].each do |i|
  ans -= $ngs[i]
end

puts ans
//  [ruby]
n = gets.to_i
s = gets.chomp.bytes

cnt = 0
(n-2).times do |i|
 j = i + 1
 k = j + 1
 while k < n
  cnt += 1 if s[i] != s[j] && s[i] != s[k] && s[j] != s[k]
  j += 1
  k += 2
 end
end

puts s.count(82) * s.count(71) * s.count(66) - cnt
//  [ruby]
n = gets.to_s.to_i
s = gets.to_s.chomp.bytes

cnt = 0
n.times do |i|
  j = i + 1
  k = i + 2
  while k < n
    cnt += 1 if (s[i] != s[j] && s[j] != s[k] && s[i] != s[k])
    j += 1
    k += 2
  end
end

# p "RGB".bytes #=> [82, 71, 66]
puts s.count(82) * s.count(71) * s.count(66) - cnt
//  [ruby]
use std::io;

fn read() -> String {
    let mut buff = String::new();
    io::stdin().read_line(&mut buff).unwrap();
    buff.trim().to_string()
}

fn main() {
    let n: i32 = read().parse().unwrap();
    let chars: Vec<char> = read().chars().collect();

    let r_count = chars.iter().filter(|c| c == &&'R').count();
    let g_count = chars.iter().filter(|c| c == &&'G').count();
    let b_count = chars.iter().filter(|c| c == &&'B').count();

    let mut ans = r_count * g_count * b_count;

    for i in 0..n {
        for j in (i + 1)..n {
            let k = 2 * j - i;
            if k < n {
                let ci = chars[i as usize];
                let cj = chars[j as usize];
                let ck = chars[k as usize];
                if ci != cj && ci != ck && cj != ck {
                    ans -= 1;
                }
            }
        }
    }

    println!("{}", ans);
}
//  [ruby]
n = gets.to_i
cs = gets.strip.chars

r_count = cs.count("R")
g_count = cs.count("G")
b_count = cs.count("B")

miss = 0

n.times do |i|
  ((i + 1)..n).each do |j|
    k = 2 * j - i
    rest = (["R", "G", "B"] - [cs[i], cs[j]])
    if rest.length == 1
      if cs[k]
        if cs[k] == rest.first
          miss += 1
        end
      end
    end
  end
end

puts(r_count * g_count * b_count - miss)
//  [ruby]
n = gets.to_i
s = gets.chomp

tally = s.chars.tally
tally.default = 0
answer = tally['R'] * tally['G'] * tally['B']

(0...n).each do |i|
  (1...n / 3).each do |d|
    break if (i + 2 * d) > n - 1

    if s[i] != s[i + d] && s[i + d] != s[i + 2 * d] && s[i + 2 * d] != s[i + d]
      answer -= 1
    end
  end
end

puts answer
//  [rust]
macro_rules! get_one {
    ($t:ty) => {{
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse::<$t>().unwrap()
    }};

    ($t:ty; $n:expr) => {
        (0..$n).map(|_| get_one!($t)).collect::<Vec<_>>()
    };
}

fn main() {
    let _ = get_one!(usize);
    let v_s: Vec<char> = get_one!(String).chars().collect();
    let r_pos = pos('R', &v_s);
    let g_pos = pos('G', &v_s);
    let b_pos = pos('B', &v_s);

    let mut except = 0;
    for &r in r_pos.iter() {
        for &g in g_pos.iter() {
            if let Some('B') = v_s.get((2 * r - g) as usize) {
                except += 1;
            }
            if let Some('B') = v_s.get((2 * g - r) as usize) {
                except += 1;
            }
            if (r + g) % 2 == 0 && v_s[((r + g) / 2) as usize] == 'B' {
                except += 1;
            }
        }
    }

    let r_num = r_pos.len();
    let g_num = g_pos.len();
    let b_num = b_pos.len();

    println!("{}", r_num * g_num * b_num - except);
}

fn pos(chr: char, v: &Vec<char>) -> Vec<i32> {
    v.iter().enumerate().filter_map(|(i, &c)| if c == chr {Some(i as i32)} else {None}).collect()
}
//  [rust]
use proconio;

fn disj3(x: char, y: char, z: char) -> bool {
    x != y && y != z && z != x
}

fn count_bad(s: &Vec<char>, step: usize) -> usize {
    let mut count = 0;
    for i in 0..s.len() {
        if i + step * 2 >= s.len() {
            break;
        }
        if disj3(s[i], s[i+step], s[i+step*2]) {
            count += 1;
        }

    }
    count
}

fn main() {
    proconio::input! {
        _n: usize,
        s: String,
    }
    let s: Vec<char> = s.chars().collect();

    let mut r: usize = 0;
    let mut g: usize = 0;
    let mut b: usize = 0;

    for c in s.iter() {
        if c == &'R' {
            r += 1;
        }
        if c == &'G' {
            g += 1;
        }
        if c == &'B' {
            b += 1;
        }
    }

    let mut bad = 0;
    for i in 1..=s.len() {
        bad += count_bad(&s, i);
    }
    println!("{}", r * g * b - bad);
}
//  [rust]
#![allow(non_snake_case)]
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use num_traits::*;
use superslice::*;
use std::ops::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;

fn main() {
    input!{
        n: usize,
        s: Chars,
    }

    let mut ans = 0;
    for i in 0..n-2 {
        for j in i+1..n-1 {
            if s[i] == s[j] { continue; }
            for k in (j+1..n).filter(|&x| x != 2*j - i) {
                if j-i == k-j { continue; }
                if s[i] != s[j] && s[j] != s[k] && s[k] != s[i] {
                    ans += 1;
                }
            }
        }
    }

    println!("{}", ans)
}
//  [rust]
#![allow(non_snake_case)]
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use num_traits::*;
use superslice::*;
use std::ops::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;

fn main() {
    input!{
        n: usize,
        s: Chars,
    }

    let mut ans = 0;
    for i in 0..n-2 {
        for j in i+1..n-1 {
            if s[i] == s[j] { continue; }
            for k in j+1..n {
                if j-i == k-j { continue; }
                if s[j] != s[k] && s[k] != s[i] {
                    ans += 1;
                }
            }
        }
    }

    println!("{}", ans)
}
//  [rust]
#![allow(non_snake_case)]
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use num_traits::*;
use superslice::*;
use std::ops::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;

fn main() {
    input!{
        n: usize,
        s: Chars,
    }

    let mut ans = 0;
    for i in 0..n-2 {
        for j in i+1..n-1 {
            for k in j+1..n {
                if j-i == k-j { continue; }
                if s[i] != s[j] && s[j] != s[k] && s[k] != s[i] {
                    ans += 1;
                }
            }
        }
    }

    println!("{}", ans)
}
//  [swift]
func main() {
    let N = Int(readLine()!)!
    let S = Array(readLine()!)
    
    var count: [Character: Int] = ["R": 0, "G": 0, "B": 0]
    for c in S {
        count[c]! += 1
    }
    
    var ans = 1
    for c in "RGB" {
        ans *= count[c]!
    }
    
    for i in 1...((N - 1) / 2) {
        var first = 0
        while first + 2 * i < N {
            let mid = first + i
            let last = first + 2 * i
            if S[first] != S[mid] && S[mid] != S[last] && S[first] != S[last] {
                ans -= 1
            }
            first += 1
        }
    }
    
    print(ans)
}

main()
//  [swift]
let n = Int(readLine()!)!
let s = Array(readLine()!)

var d: [Character: Int] = ["R": 0, "G": 0, "B": 0]

for char in s {
    d[char]! += 1
}

var result = d["R"]! * d["G"]! * d["B"]!
for i in 0..<n {
    for j in i+1..<n {
        let k = 2 * j - i
        if k >= n {break}
        if s[i] != s[j] && s[j] != s[k] && s[k] != s[i] {
            result -= 1
        } 
    }
}

print(result)
//  [swift]
let N = Int(readLine()!) ?? 0
let rgbArray = Array(readLine()!)
var count = 0
var rgbIndex = Array(repeating: Array(repeating: 0, count: 0), count: 3)

rgbArray.enumerated().forEach{
    if $0.1 == "R"{
        rgbIndex[0].append($0.0)
    }
    if $0.1 == "G"{
        rgbIndex[1].append($0.0)
    }
    if $0.1 == "B"{
        rgbIndex[2].append($0.0)
    }

    
}
var total = rgbIndex[2].count*rgbIndex[1].count*rgbIndex[0].count

for i in 0 ..< N {
    for j in i+1 ..< N {
        let k = 2 * j - i
        if k >= N {
          break
        }
        if rgbArray[i] != rgbArray[j] && rgbArray[j] != rgbArray[k] && rgbArray[k] != rgbArray[i] {
            total -= 1
        } 
    }
}

print(total)
//  [swift]
let N = 39

let rgbArray = Array(" RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB")
print(rgbArray)
var count = 0

var rgbIndex = Array(repeating: Array(repeating: 0, count: 0), count: 3)

rgbArray.enumerated().forEach{
    if $0.1 == "R"{
        rgbIndex[0].append($0.0)
    }
    if $0.1 == "G"{
        rgbIndex[1].append($0.0)
    }
    if $0.1 == "B"{
        rgbIndex[2].append($0.0)
    }

    
}
var total = rgbIndex[2].count*rgbIndex[1].count*rgbIndex[0].count

for i in 1...(N-2) {
    for j in (i+1)...(N-1) {
        let x = j - i
        let k = j + x
        if k <= N && rgbArray[i] != rgbArray[j] && rgbArray[i] != rgbArray[k] && rgbArray[j] != rgbArray[k]{
            total -= 1
        }

    }
}

print(total)
//  [typescript]
export class Main {
  static main(input: string): string {
    const tmp: string[] = input.split("\n");
    const [n]: number[] = tmp.shift().split(" ").map(int => parseInt(int));
    const [s]: string[] = tmp.shift().split(" ");
    const sList = s.split("").slice(0, n);
    let rCount = 0;
    let gCount = 0;
    let bCount = 0;
    for (let i = 0, leni = n; i < leni; i++) {
      switch (sList[i]) {
        case "R":
          rCount++;
          break;
        case "G":
          gCount++;
          break;
        default:
          bCount++;
      }
    }
    let allCount = rCount * gCount * bCount;
    let noCount = 0;
    for (let j = 1, lenj = n - 1; j < lenj; j++) {
      for (let d = 1, len = Math.min(j, n - (j + 1)); d <= len; d++) {
        let si = sList[j - d];
        let sj = sList[j];
        let sk = sList[j + d];
        if (si != sj && sj != sk && sk != si) {
          noCount++;
        }
      }
    }
    return `${allCount - noCount}`;
  }
}
console.log(Main.main(require("fs").readFileSync("/dev/stdin", "utf8")));
//  [typescript]
process.stdin.resume();
process.stdin.setEncoding('utf8');

// 標準入力取込
let gInput = '';
process.stdin.on('data', (chunk) => (gInput += chunk));
process.stdin.on('end', () => main(gInput.split(/\r?\n/)));

// 解答
function main(inputs: string[]): void {
  const length = Number(inputs[0]);
  const str = inputs[1];
  let rejectCount = 0;
  let sum = 0;

  if (str.includes('R') && str.includes('G') && str.includes('B')) {
    sum += (str.split('R').length - 1) * (str.split('G').length - 1) * (str.split('B').length - 1);
  } else {
    console.log(sum);
    return;
  }

  for (let i = 0; i < length; i++) {
    for (let j = 1; j < length; j++) {
      if (i + j >= length || i + j * 2 >= length) {
        break;
      }

      if (str[i] !== str[i + j] && str[i] !== str[i + j * 2] && str[i + j] !== str[i + j * 2]) {
        rejectCount++;
      }
    }
  }

  sum -= rejectCount;

  console.log(sum);
}
//  [typescript]
process.stdin.resume();
process.stdin.setEncoding('utf8');

// 標準入力取込
let gInput = '';
process.stdin.on('data', (chunk) => (gInput += chunk));
process.stdin.on('end', () => main(gInput.split(/\r?\n/)));

// 解答
function main(inputs: string[]): void {
  const length = Number(inputs[0]);
  const str = inputs[1];
  const checkList = ['R', 'G', 'B'];
  let rejectCount = 0;
  let sum = 0;

  if (str.includes('R') && str.includes('G') && str.includes('B')) {
    sum += (str.split('R').length - 1) * (str.split('G').length - 1) * (str.split('B').length - 1);
  } else {
    console.log(sum);
    return;
  }

  for (let i = 0; i < length; i++) {
    for (let j = 1; j < length; j++) {
      if (i + j >= length || i + j * 2 >= length) {
        break;
      }

      if (str[i] !== str[i + j] && str[i] !== str[i + j * 2] && str[i + j] !== str[i + j * 2]) {
        rejectCount++;
      }
    }
  }

  sum -= rejectCount;

  console.log(sum);
}
//  [typescript]
import * as fs from 'fs'

const input: string = fs.readFileSync('/dev/stdin', 'utf8');
const args: string[][] = input.split('\n').map(l => l.split(' '));

const n: number = parseInt(args[0][0]);
const s: string = args[1][0];


let cnt = 0;
for (let i = 0; i < n - 2; i++) {
  for (let j = i + 1; j < n - 1; j++) {
    for (let k = j + 1; k < n; k++) {
      if (j - i !== k - j) {
        if (s[i] !== s[j] && s[j] !== s[k] && s[k] !== s[i]) cnt++;
      }
    }
  }
}

console.log(cnt);
//  [typescript]
import * as fs from "fs";

function main(lines: string[][]) {
  const data = lines[1][0].split("");
  let count = 0;
  data.forEach((n1, i1) => {
    data.forEach((n2, i2) => {
      if (i1 < i2) return;
      if (n1 === n2) return;
      data.forEach((n3, i3) => {
        if (i2 < i3) return;
        if (n2 === n3) return;
        if (n1 === n3) return;
        if (i3 - i2 === i2 - i1) return;
        count++;
      });
    });
  });
  console.log(count);
}

const lines = fs
  .readFileSync("/dev/stdin", "utf8")
  .split("\n")
  .map((l) => l.split(" "))
  .filter((input) => !(input.length === 1 && input[0] === ""));

main(lines);
//  [typescript]
import * as fs from 'fs';

function Main(input: string) {
    const lines = input.split('\n');
    const constraintN = parseInt(lines[0], 10);
    const S = lines[1];

    let sum = 0;

    let maxI = constraintN - 2;
    let maxJ = constraintN - 1;

    for (let i = 0; i < maxI; i++) {
        for (let j = i + 1; j < maxJ; j++) {
            for (let k = j + 1; k < constraintN; k++) {
                if (j - i !== k - j &&
                    S[i] !== S[j] &&
                    S[i] !== S[k] &&
                    S[j] !== S[k]) {
                    sum++;
                }
            }
        }
    }

    //output
    console.log(sum);
}

Main(fs.readFileSync('/dev/stdin', 'utf8'));
//  [python]
A, B, K = map(int, input().split())
a, b = [], []
for i in range(1,A+1):
    if A % i == 0:
        a.append(i)
for j in range(1,B+1):
    if B % j == 0:
        b.append(j)
lis = [k for k in a if k in b]
lis.reverse()
print(lis[K-1])
//  [python]
A, B, K = map(int, input().split())

for i in range(1, min(A, B) + 1)[::-1]:
    if A % i == 0 and B % i == 0:
        K -= 1

    if K == 0:
        print(i)
        break
//  [python]
a,b,k = map(int,input().split())
l = []
for i in range(1,101):
    if a%i == 0 and b%i == 0:
        l.append(i)
print(l[::-1][k-1])
//  [python]
import numpy as np
A,B,K = map(int,input().split())

def cal_common_divisor(num1,num2):
    prime = [2,3,5,7,11,13]
    ans_list = []
    for i in range(len(prime)):
        while True:
            if num1 % prime[i] == 0 and num2 % prime[i] == 0:
                num1 //= prime[i]
                num2 //= prime[i]
                ans_list.append(prime[i])
            if num1 % prime[i] != 0 or num2 % prime[i] != 0:
                break
    return ans_list
    
ans = cal_common_divisor(A,B)
n = len(ans)

nnn = []
for i in range(2**n):
    negt = []
    num = 1
    for j in range(n):
        if ((i >> j)& 1):
            negt.append(ans[j])
    for k in range(len(negt)):
        num *= negt[k]
    nnn.append(num)
nnn = list(set(nnn))
nnn.sort(reverse=True)
print(nnn[K-1])
//  [python]
import numpy as np
A,B,K = map(int,input().split())

def cal_common_divisor(num1,num2):
    prime = [2,3,5,7,11,13]
    ans_list = []
    for i in range(len(prime)):
        while True:
            if num1 % prime[i] == 0 and num2 % prime[i] == 0:
                num1 //= prime[i]
                num2 //= prime[i]
                ans_list.append(prime[i])
            if num1 % prime[i] != 0 or num2 % prime[i] != 0:
                break
    return ans_list
    
ans = cal_common_divisor(A,B)
n = len(ans)

nnn = []
for i in range(2**n):
    negt = []
    num = 1
    for j in range(n):
        if ((i >> j)& 1):
            negt.append(ans[j])
    for k in range(len(negt)):
        num *= negt[k]
    nnn.append(num)
nnn = list(set(nnn))
nnn.sort(reverse=True)
print(nnn)
print(nnn[K-1])
//  [python]
a,b,k = map(int,input().split())

num = 0
metric_num = 0

while True:
    num += 1
    if a % num ==0 and b % num ==0:
        metric_num += 1
        if metric_num == k:
            break
print(num)
//  [java]
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int a = Integer.parseInt(str[0]);
    int b = Integer.parseInt(str[1]);
    int k = Integer.parseInt(str[2]);
    
    int[] divisor_array = new int[k];
    
    for(int i = Math.min(a,b), j = 0; i>=1; i--) {
      if(a%i==0 && b%i==0){
        divisor_array[j] = i;
        j++;
      }
      if(j == k)
        break;
    }
    System.out.println(divisor_array[k-1]);
  }
}
//  [java]
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main{
	public static void main(String[] args){
		InputStreamReader ir = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(ir);

		String str = null;
		try{
			str = br.readLine();
		}catch(IOException ex){
			ex.printStackTrace();
		}

		String[] input = str.split(" ");
		int a = Integer.parseInt(input[0]);
		int b = Integer.parseInt(input[1]);
		int k = Integer.parseInt(input[2]);

		List<Integer> res = new ArrayList<>();
		for(int i = 1; i <= 100; i++){
			if(a % i == 0 && b % i == 0){
				res.add(i);
			}
		}
		System.out.println(res.get(res.size() - k));
	}
}