Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

N = int(input())
S = input()

from collections import defaultdict

memo = [defaultdict(int) for j in range(N+1)]

ans = 0



for i,s in enumerate(S):
    memo[i+1]["R"] = memo[i]["R"]
    memo[i+1]["G"] = memo[i]["G"]
    memo[i+1]["B"] = memo[i]["B"]
    memo[i+1][s]+=1
    others = set(["R","G","B"])
    others.remove(s)
    others = list(others)
    ans += memo[i+1][others[0]] * memo[i+1][others[1]]

rgb = set(["R","G","B"])
# print(rgb)

if N > 2:
    if N %2 == 1:
        length = N // 2
    else:
        length = N // 2 - 1

    # print(length)
    
    for skip in range(length):
        for i in range(len(S)):
            # print(i)
            if i+2+skip*2 > len(S)-1:

                break
            a,b,c = S[i],S[i+1+skip],S[i+2+skip*2]
            # print(set([a,b,c]))
            if set([a,b,c]) == rgb:
                ans -= 1
        

print(ans)


### FIXED CODE ###

N = int(input())
S = input()

from collections import defaultdict

memo = [defaultdict(int) for j in range(N+1)]

ans = 0



for i,s in enumerate(S):
    memo[i+1]["R"] = memo[i]["R"]
    memo[i+1]["G"] = memo[i]["G"]
    memo[i+1]["B"] = memo[i]["B"]
    memo[i+1][s]+=1
    others = set(["R","G","B"])
    others.remove(s)
    others = list(others)
    ans += memo[i+1][others[0]] * memo[i+1][others[1]]

rgb = set(["R","G","B"])
# print(rgb)

if N > 2:
    if N %2 == 1:
        length = N // 2
    else:
        length = N // 2 - 1

    # print(length)
    
    for skip in range(length):
        for i in range(len(S)):
            # print(i)
            if i+2+skip*2 > len(S)-1:

                break
            a,b,c = S[i],S[i+1+skip],S[i+2+skip*2]
            # print(set([a,b,c]))
            if set([a,b,c]) == rgb:
                ans -= 1
        

print(ans)
### BUGGY CODE ###

S = input()
N = len(S)
MOD = 10 ** 9 + 7

# dp[i][j] := i文字目までみた時に13で割ってj余るような数の通り数
dp = [[0] * 13 for i in range(N + 1)]
dp[0][0] = 1

for i, s in enumerate(S):
    for j in range(13):
        if s != '?':
            dp[i + 1][((j * 10) + int(s)) % 13] += dp[i][j]
            dp[i + 1][((j * 10) + int(s)) % 13] %= MOD
        else:
            for k in range(10):
                dp[i + 1][((j * 10) + k) % 13] += dp[i][j]
                dp[i + 1][((j * 10) + k) % 13] %= MOD

print(dp[-1][5] % MOD)


### FIXED CODE ###

S = input()
N = len(S)
MOD = 10 ** 9 + 7
dp = [[0] * 13 for i in range(N + 1)]
dp[0][0] = 1

for i, s in enumerate(S[::-1], start=1):
    p10 = pow(10, i - 1, 13)
    if s != '?':
        for k in range(13):
            dp[i][(int(s) * p10 + k) % 13] += dp[i - 1][k]
            dp[i][(int(s) * p10 + k) % 13] %= MOD
    else:
        for j in range(10):
            for k in range(13):
                dp[i][(j * p10 + k) % 13] += dp[i - 1][k]
                dp[i][(j * p10 + k) % 13] %= MOD

print(dp[N][5] % MOD)
### BUGGY CODE ###

s=input()
cnt=0
le=len(s)
for i in range(1,le-2):
    for j in range(i+3,le+1):
        number=s[i-1:j]
        if int(number)%2019==0:
            cnt+=1
            break
    else: continue
print(cnt)

### FIXED CODE ###

s=input()[::-1]
mod=[0]*2019
mod[0]=1
x=1
num=0
ans=0

for t in s:
    num += int(t) * x
    num %= 2019
    x *= 10
    x %= 2019
    mod[num] +=1

for u in mod:
    ans += u*(u-1)//2

print(ans)
### BUGGY CODE ###

import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip() # ignore trailing spaces 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))

def sumitrust2019_d(a,b,c,s):
    a,b,c = map(str,[a,b,c])
    for idx_a in range(len(s)-2):
        if s[idx_a] == a:
            for idx_b in range(idx_a+1,len(s)-1):
                if s[idx_b] == b:
                    for idx_c in range(idx_b+1,len(s)):
                        if s[idx_c] == c:
                                return True
    else:
        return False

def main():
    n = ni()
    s = ns()
    ans = 0
    for a in range(10):
        for b in range(10):
            for c in range(10):
                if sumitrust2019_d(a,b,c,s):
                    ans += 1
    print(ans)
    return

if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip() # ignore trailing spaces 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))

def sumitrust2019_d(a,b,c,s):
    abc = list(map(str,[a,b,c]))
    now = 0
    for i in range(len(s)):
        if s[i] == abc[now]:
            now += 1
            if now == 3:
            	return True
    return False

def main():
    n = ni()
    s = ns()
    ans = 0
    for a in range(10):
        for b in range(10):
            for c in range(10):
                if sumitrust2019_d(a,b,c,s):
                    ans += 1
    print(ans)
    return

if __name__ == '__main__':
    main()
### BUGGY CODE ###

N, K = map(int, input().split())
P = list(map(int, input().split()))

ans = 0
for i in range(N - K + 1):
    tmp = 0
    for j in range(i, i + K):
        tmp += sum([n for n in range(1, P[j] + 1)]) / P[j]
    ans = max(ans, tmp)
print(ans)

### FIXED CODE ###

N, K = map(int, input().split())
P = list(map(int, input().split()))

s = sum(P[0:K])
m = s
id = 0
for i in range(1, N - K + 1):
    s += (P[i + K - 1] - P[i - 1])
    if s > m:
        id = i
        m = s

ans = 0
for j in range(id, id + K):
    ans += (P[j] + 1) / 2
print(ans)
### BUGGY CODE ###

N, M = map(int, input().split())
d = {}
for _ in range(M):
    A, B = map(int, input().split())
    if A not in d:
        d[A] = [B]
    else:
        d[A].append(B)
    if B not in d:
        d[B] = [A]
    else:
        d[B].append(A)

ans = [(-1, float("inf"))] * N
cnt = 0
stack = [(1, 0)]
while stack:
    val, step = stack.pop()
    next_vals = d[val]
    for nxt in next_vals:
        if ans[nxt - 1][1] > step + 1:
            if ans[nxt - 1][0] == -1:
                cnt += 1
            ans[nxt - 1] = (val, step + 1)
            stack.append((nxt, step + 1))

if cnt < N - 1:
    print("No")
else:
    print("Yes")
    for i in range(1, N):
        print(ans[i][0])

### FIXED CODE ###

from collections import deque

N, M = map(int, input().split())
d = {}
for _ in range(M):
    A, B = map(int, input().split())
    if A not in d:
        d[A] = [B]
    else:
        d[A].append(B)
    if B not in d:
        d[B] = [A]
    else:
        d[B].append(A)

ans = [(-1, float("inf"))] * N
cnt = 0
# stack = [(1, 0)]
queue = deque([(1, 0)])

while queue:
    val, step = queue.popleft()
    next_vals = d[val]
    for nxt in next_vals:
        #        if ans[nxt - 1][1] > step + 1:
        if ans[nxt - 1][0] == -1:
            cnt += 1
            ans[nxt - 1] = (val, step + 1)
            queue.append((nxt, step + 1))

if cnt < N - 1:
    print("No")
else:
    print("Yes")
    for i in range(1, N):
        print(ans[i][0])
### BUGGY CODE ###

#from bisect import bisect_left
#from operator import itemgetter

n, q = map(int, input().split())
stx = [tuple(int(x) for x in input().split()) for _ in range(n)]
d = [int(input()) for _ in range(q)]

ans = [-1] * q

#stx.sort(reverse=True, key=itemgetter(2))

e = []

for s, t, x in stx:
    e.append([s-x, 1, x])
    e.append([t-x, -1, x])

e.sort()
e.append([10 ** 9, 1, 10 ** 9])

h = set()
h.add(10 ** 9)
i = 0

for p in d:
    while e[i][0] <= p:
        if e[i][1] == 1:
            h.add(e[i][2])
        else:
            h.remove(e[i][2])
        i += 1
    ans = min(h)
    if ans == 10 ** 9:
        print(-1)
    else:
        print(min(h))

### FIXED CODE ###

from bisect import bisect_left
from operator import itemgetter

n, q = map(int, input().split())
stx = [tuple(int(x) for x in input().split()) for _ in range(n)]
d = [int(input()) for _ in range(q)]

ans = [-1] * q
skip = [-1] * q

stx.sort(key=itemgetter(2))

for s, t, x in stx:
    L = bisect_left(d, s-x)
    R = bisect_left(d, t-x)
    while L < R:
        if skip[L] == -1:
            ans[L] = x
            skip[L] = R
            L += 1
        else:
            L = skip[L]

for x in ans:
    print(x)
### BUGGY CODE ###

from sys import stdin

n,m = [int(x) for x in stdin.readline().rstrip().split()]
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(m)]

lin = []

for i in li:
    if i[1] == n:
        lin.append(i[0])
for j in lin:
    if [1,j] in li:
        print("POSSIBLE")
        exit()

print("IMPOSSIBLE")

### FIXED CODE ###

from sys import stdin

n,m = [int(x) for x in stdin.readline().rstrip().split()]
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(m)]

lin = [0]*n

for i in li:
    if i[0] == 1:
        lin[i[1]-1] += 1
    if i[1] == n:
        lin[i[0]-1] += 1

for i in lin:
    if i == 2:
        print("POSSIBLE")
        exit()

print("IMPOSSIBLE")
### BUGGY CODE ###

x = input()
while "ST" in x:
  x = x.replace("ST","")
print(len(x))

### FIXED CODE ###

x = list(input())
c = 0
for i in x:
  if i == "S":
    c += 1
  elif c>0:
    c -= 1
print(2*c)
### BUGGY CODE ###

def main():
    x = int(input())
    a = int(x**(1/5))
    while True:
        b = a**5 - x
        if b < 0:
            b = abs(b-0)**(1/5)
            b = b * (-1)
        else:
            b = b**(1/5)
        b = int(b)
        if a**5 - b**5 == x:
            print(a,b)
            return 0
        else:
            a+=1
    
if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    x = int(input())
    a = 0
    while True:
        b = a**5 - x
        if b < 0:
            b = abs(b-0)**(1/5)
            b = b * (-1)
        else:
            b = b**(1/5)
        b = int(b)

        if a**5 - b**5 == x:
            print(a,b)
            return 0
        else:
            a+=1
    
if __name__ == '__main__':
    main()
### BUGGY CODE ###

s = input()

count = 0
while ('01' in s or '10' in s and len(s) > 0):
   if ('01' in s):
      s = s.replace('01', '', 1)
   else:
      s = s.replace('10', '', 1)
   count += 2

print(count)


### FIXED CODE ###

s = input()

ans = 2 * min(s.count('0'), s.count('1'))
print(ans)
### BUGGY CODE ###

N = int(input())
S = list(input())
ans = []

for i in range(N):
  ans.append(S[:i].count('W') + S[i:].count('E'))
  
print(min(ans))

### FIXED CODE ###

N = int(input())
S = input()
#左からスタートするとして，全てWならば0になるため
E_count = S.count('E')
W_count = 0
mini_count = E_count

for i in S:
  if i == 'E':
    #リーダーはどちらを向いていても良いので1を引く
    E_count -= 1
  else:
    #Wの場合は，今後向きを変えてもらう必要があるため
    W_count += 1
  if mini_count > E_count + W_count:
    mini_count = E_count + W_count
print(mini_count)
### BUGGY CODE ###

H, W = map(int, input().split())
s = [[c for c in input()] for i in range(H)]
s_vrt = [[s[i][j] for i in range(H)] for j in range(W)]

dp_l = [[0 for j in range(W)] for i in range(H)]
dp_r = [[0 for j in range(W)] for i in range(H)]
dp_u = [[0 for j in range(W)] for i in range(H)]
dp_d = [[0 for j in range(W)] for i in range(H)]

for i in range(H):
    cnt = 0
    for j in range(W):
        if s[i][j] == '#':
            cnt = 0
        else:
            dp_l[i][j] = cnt
            cnt += 1

    cnt = 0
    for j in range(W)[::-1]:
        if s[i][j] == '#':
            cnt = 0
        else:
            dp_r[i][j] = cnt
            cnt += 1

for j in range(W):
    cnt = 0
    for i in range(H):
        if s[i][j] == '#':
            cnt = 0
        else:
            dp_d[i][j] = cnt
            cnt += 1

    cnt = 0
    for i in range(H)[::-1]:
        if s[i][j] == '#':
            cnt = 0
        else:
            dp_u[i][j] = cnt
            cnt += 1


count_max = 0
for i in range(H):
    for j in range(W):
        if s[i][j] == '#':
            continue
        count_max = max(count_max,
            dp_l[i][j]
            + dp_r[i][j]
            + dp_u[i][j]
            + dp_d[i][j]
            + 1)

print(count_max)

### FIXED CODE ###

import numpy as np


H, W = map(int, input().split())
s = np.array([[c for c in input()] for i in range(H)]) == '.'
s_t = s.transpose()

dp_l = np.zeros((W, H), dtype=int)
dp_r = np.zeros((W, H), dtype=int)
dp_u = np.zeros((H, W), dtype=int)
dp_d = np.zeros((H, W), dtype=int)

dp_l[0] = s_t[0]
dp_r[W-1] = s_t[W-1]
dp_u[0] = s[0]
dp_d[H-1] = s[H-1]

for i in range(1, W):
    dp_l[i] = s_t[i] * (dp_l[i-1] + 1)

for i in reversed(range(W-1)):
    dp_r[i] = s_t[i] * (dp_r[i+1] + 1)

for i in range(1, H):
    dp_u[i] = s[i] * (dp_u[i-1] + 1)

for i in reversed(range(H-1)):
    dp_d[i] = s[i] * (dp_d[i+1] + 1)

cnts = dp_l + dp_r + dp_d.transpose() + dp_u.transpose()
print(max(np.amax(cnts, 0)) - 3)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
import numpy as np
N = int(input())
A = np.array([0] + [int(x) for x in input().split()] + [0])
for i in range(1,N+1):
    B = np.concatenate([A[:i],A[i+1:]])
    print(abs(np.diff(B)).sum())


### FIXED CODE ###

import sys
input = sys.stdin.readline
import numpy as np
N = int(input())
A = np.array([0] + [int(x) for x in input().split()] + [0])
A_diff = np.diff(A)
total = abs(A_diff).sum()
for i in range(1,N+1):
    ans = total
    ans -= abs(A_diff[i]) + abs(A_diff[i-1]) 
    ans += abs(A[i+1] - A[i-1])
    print(ans)
### BUGGY CODE ###

import sys

N, K = list(map(int, input().split()))

pre = N
while True:
    if N % K == 0 and N // K > 1:
        print(0)
        sys.exit()
        
    N = abs(N-K)
    if pre <= N:
        print(pre)
        sys.exit()
    else:
        pre = N

### FIXED CODE ###

import sys

N, K = list(map(int, input().split()))

pre = N
while True:
    if N % K == 0 and N // K >= 1:
        print(0)
        sys.exit()
        
    if N > K:
        N = N % K
    else:
        N = abs(N-K)
    
    if pre <= N:
        print(pre)
        sys.exit()
    else:
        pre = N
### BUGGY CODE ###

n = int(input())
a = [0]*n
cnt = 0
for i in range(1,int((n-3)**1/2 //1)):
  for j in range(1,int((n-i**2)**1/2 //1)):
    for k in range(1,int((n-i**2-j**2)**1/2 //1)):
      b = i**2 + j**2 + k**2 + i*j + j*k + k*i
      if b <= n:
        a[b-1] += 1

for i in a:
  print(i)

### FIXED CODE ###

n = int(input())
a = [0]*n
cnt = 0
for i in range(1,100):
  for j in range(1,100):
    for k in range(1,100):
      b = i**2 + j**2 + k**2 + i*j + j*k + k*i
      if b <= n:
        a[b-1] += 1

for i in a:
  print(i)
### BUGGY CODE ###

import numpy as np

n=int(input())
E=[]
W=[]
node_l=np.zeros(n)
node_l[0]=1
for i in range(n-1):
    u,v,w=map(int,input().split())
    #print(u,v,w)
    E.append([u,v])
    W.append(w)
#print(E,W)

def bfs(node,node_l,l,w_l):
    i=0
    A=[]
    L=[]
    for edge in l:
        if edge[0]==node:
            L.append(edge[1])
            A.append(i)
        elif edge[1]==node:
            L.append(edge[0])
            A.append(i)
        i+=1
    if L==[]:
        return
    for j in range(len(L)):
        if node_l[L[j]-1]==0:
                if W[A[j]]%2==0:
                    node_l[L[j]-1]=node_l[node-1]
                    bfs(L[j],node_l,l,w_l)
                else:
                    node_l[L[j]-1]=node_l[node-1]*-1
                    bfs(L[j],node_l,l,w_l)
    return
bfs(1,node_l,E,W)
for i in range(n):
    if node_l[i]==1:
        print('1',end='\n')
    else:
        print('0',end='\n')



### FIXED CODE ###

import numpy as np

n=int(input())
E=[]
node_l=np.zeros(n)
node_l[0]=1
for i in range(n-1):
    u,v,w=map(int,input().split())
    #print(u,v,w)
    E.append((u,v,w))
#print(E,W)

def bfs(node,l):
    root=[[] for i in range(n)]
    for a,b,c in l:
        root[a-1]+=[(b-1,c)]
        root[b-1]+=[(a-1,c)]
    stack=[]
    stack.append(node-1)
    #print(root)
    dist=[-1]*n
    dist[node-1]=0
    while stack:
        #print(stack)
        buf=stack.pop(-1)
        for v,weight in root[buf]:
            if dist[v]==-1:
                dist[v]=dist[buf]+weight
                stack.append(v)
    return dist

for i in bfs(1,E):
    print(i%2,end='\n')
### BUGGY CODE ###

h, w = map(int, input().split(" "))
sr, sc = map(int, input().split(" "))
er, ec = map(int, input().split(" "))

board=[['' for i in range(w)] for j in range(h)]
for i in range(h):
    s=input()
    for j in range(w):
        board[i][j]= s[j]
rs,cs=[],[]
rs.append(sr-1)
cs.append(sc-1)
magic=[[1e6 for i in range(w)] for j in range(h)]
dr=[-1,1,0,0]
dc=[0,0,-1,1]
magic[sr-1][sc-1]=0
while len(rs)>0:
    r,c=rs.pop(),cs.pop()
    for i in range(4):
        nr,nc= r+dr[i],c+dc[i]
        if nr>=0 and nr<h and nc>=0 and nc<w and board[nr][nc]!='#':
            if magic[nr][nc]>magic[r][c]:
                magic[nr][nc]= magic[r][c]
                rs.append(nr)
                cs.append(nc)
    #wizard
    for nr in range(r-2,r+3):
        for nc in range(c-2,c+3):
            if nr>=0 and nr<h and nc>=0 and nc<w and board[nr][nc]!='#':
                if magic[nr][nc] > magic[r][c]+1:
                    magic[nr][nc] = magic[r][c]+1
                    rs.append(nr)
                    cs.append(nc)
print(magic[er-1][ec-1] if magic[er-1][ec-1]<1e6 else -1)

### FIXED CODE ###

import collections

h, w = map(int, input().split(" "))
sr, sc = map(int, input().split(" "))
er, ec = map(int, input().split(" "))

board=[['' for i in range(w)] for j in range(h)]
for i in range(h):
    s=input()
    for j in range(w):
        board[i][j]= s[j]
rs,cs=collections.deque([sr-1]),collections.deque([sc-1])
magic=[[1e6 for i in range(w)] for j in range(h)]
dr=[-1,1,0,0]
dc=[0,0,-1,1]
magic[sr-1][sc-1]=0
while len(rs)>0:
    r,c=rs.popleft(),cs.popleft()
    for i in range(4):
        nr,nc= r+dr[i],c+dc[i]
        if nr < 0 or nr >= h or nc < 0 or nc >= w or board[nr][nc] == '#':
            continue
        if magic[nr][nc]>magic[r][c]:
            magic[nr][nc]= magic[r][c]
            rs.appendleft(nr)
            cs.appendleft(nc)
    #wizard
    for nr in range(r-2,r+3):
        for nc in range(c-2,c+3):
            if nr < 0 or nr >= h or nc < 0 or nc >= w or board[nr][nc] == '#':
                continue
            if magic[nr][nc] > magic[r][c]+1:
                    magic[nr][nc] = magic[r][c]+1
                    rs.append(nr)
                    cs.append(nc)
print(magic[er-1][ec-1] if magic[er-1][ec-1]<1e6 else -1)
### BUGGY CODE ###

import itertools
from fractions import gcd
 
K = int(input())
l = range(1, K+1)
ans = sum(l)
 
for a, b in itertools.combinations(l, 2):
    ans += gcd(a, b) * 6
 
for a, b, c in itertools.combinations(l, 3):
    ans += gcd(gcd(a, b), c) * 6
        
print(ans)

### FIXED CODE ###

import itertools
import math
 
K = int(input())
l = range(1, K+1)
ans = sum(l)
 
for a, b in itertools.combinations(l, 2):
    ans += math.gcd(a, b) * 6
 
for a, b, c in itertools.combinations(l, 3):
    ans += math.gcd(math.gcd(a,b), c)*6
    
        
print(ans)
### BUGGY CODE ###

# coding: utf-8
# Your code here!

N = int(input())
A = list(map(int,input().split()))

l_max = len(A)
#print(l_max)
r = 0
count = l_max
bit_max = 0
    
    
for l in range(0, l_max):
    bitSums = A[l]
    Sums = A[l]
    bit_max = max(A[l:l_max])
    for r in range(l+1, l_max):
        Sums = Sums + A[r]
        if len(bin(Sums))>len(bin(bit_max)):
            #print('break!')
            break
        bitSums = bitSums ^ A[r]
        if bitSums == Sums:
            count += 1

print(count)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))

count = 0
Sum = 0
r = 0

for l in range(0, N):
    #Sum = A[l]
    while r < N and Sum + A[r] == Sum ^ A[r]:
            Sum += A[r]
            r += 1
    count += r-l
    if(l==r):
        r+=1
    else:
        Sum -= A[l]
    
    
print(count)
### BUGGY CODE ###

N, K = map(int, input().split())
p = list(map(int, input().split()))

s = [sum(p[i:i+K]) for i in range (N-(K-1))]

print((max(s)+K)/2)

### FIXED CODE ###

N, K = map(int, input().split())
p = list(map(int, input().split()))

s = sum(p[:K]) 
m = s

for i in range(N-K):
    s = s - p[i] + p[K+i]
    if m < s:
        m = s

print((m+K)/2)
### BUGGY CODE ###

a,b,k=map(int,input().split())
for i in range(k):
    if a>0:
        a-=1
    else:
        b-=1
    if a==0 and b==0:
        break
print(a,b)

### FIXED CODE ###

a,b,k=map(int,input().split())
if a>k:
    a-=k
elif a+b>k:
    b=b-k+a
    a=0
else:
    a=0
    b=0
print(a,b)
### BUGGY CODE ###

import bisect
import sys
from numba import jit
if __name__ == '__main__':


    @jit
    def solve():
        input = sys.stdin.readline
        n = int(input())
        s = list(input())
        r = []
        g = []
        b = []

        for i in range(n):
            if s[i] == "R":
                r.append(i)
            elif s[i] == "G":
                g.append(i)
            else:
                b.append(i)
        ans = 0
        for i in range(n):
            for j in range(i, n):
                if s[i] == s[j]:
                    continue
                if s[i] == "R" and s[j] == "G":
                    out = j * 2 - i
                    tmp = bisect.bisect_left(b, j)
                    t = len(b) - tmp
                    ans += (t - 1) if out in b[tmp:] else t

                elif s[i] == "R" and s[j] == "B":
                    out = j * 2 - i
                    tmp = bisect.bisect_left(g, j)
                    t = len(g) - tmp
                    ans += (t - 1) if out in g[tmp:] else t

                elif s[i] == "G" and s[j] == "B":
                    out = j * 2 - i
                    tmp = bisect.bisect_left(r, j)
                    t = len(r) - tmp
                    ans += (t - 1) if out in r[tmp:] else t

                elif s[i] == "G" and s[j] == "R":
                    out = j * 2 - i
                    tmp = bisect.bisect_left(b, j)
                    t = len(b) - tmp
                    ans += (t - 1) if out in b[tmp:] else t

                elif s[i] == "B" and s[j] == "R":
                    out = j * 2 - i
                    tmp = bisect.bisect_left(g, j)
                    t = len(g) - tmp
                    ans += (t - 1) if out in g[tmp:] else t

                elif s[i] == "B" and s[j] == "G":
                    out = j * 2 - i
                    tmp = bisect.bisect_left(r, j)
                    t = len(r) - tmp
                    ans += (t - 1) if out in r[tmp:] else t

        print(ans)
    solve()

### FIXED CODE ###

import sys

if __name__ == '__main__':
    input = sys.stdin.readline
    n = int(input())
    s = list(input())
    s.remove('\n')
    r = 0
    g = 0
    b = 0
    for i in s:
        if i == "R":
            r += 1
        elif i == "G":
            g += 1
        else:
            b += 1
    ans = r * g * b
    for i in range(n):
        for j in range(i, n):
            out = j * 2 - i
            if out >= n:
                continue
            if len({s[i], s[j], s[out]}) == 3:
                ans -= 1
    print(ans)
### BUGGY CODE ###

from copy import copy
N = int(input())
A= list(map(int, input().split()))
for i in range(N):
    f=0
    a=copy(A)
    a.remove(a[i])
    l=len(a)
    for j in range(l):
        for k in range(j+1,l):
            if a[j]==a[k]:
                f+=1
    print(f)

### FIXED CODE ###

import collections
N = int(input())
A = list(map(int, input().split()))
l = collections.Counter(A)
al = sum([x*(x-1)//2 for x in l.values()])
for i in range(N):
    print(al - (l[A[i]]-1))
### BUGGY CODE ###

n, k = map(int, input().split())
H = list(map(int, input().split()))

DP = [10 ** 9] * n
DP[0] = 0

for i in range(1, n):
    j = 1
    while i - j >= 0 and j <= k:
        DP[i] = min(DP[i], DP[i-j] + abs(H[i] - H[i-j]))
        j += 1
print(DP[-1])

### FIXED CODE ###

n, k = map(int, input().split())
H = list(map(int, input().split()))

DP = [10 ** 9] * n
DP[0] = 0

for i in range(1, n):
    j = 1
    while i - j >= 0 and j <= k:
        DP[i] = min(DP[i], DP[i-j] + abs(H[i] - H[i-j]))
        j += 1
print(DP[-1])
### BUGGY CODE ###

N = int(input())
A = input().split()

for i in range(N):
    A[i] = int(A[i])

ans = 0
for j in range(1, N):
    for i in range(0, j):
        ans += A[i]*A[j]

print(ans % 1000000007)

### FIXED CODE ###

N = int(input())
A = input().split()

toA = 0
for i in range(N):
    A[i] = int(A[i])
    toA += A[i]

ans = 0
for i in range(0, N):
    toA -= A[i]
    ans += A[i]*toA

print(ans % 1000000007)