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

# coding: utf-8
# Your code here!
import bisect
n=int(input())
d=list(map(int,input().split()))
m=int(input())
t=list(map(int,input().split()))
ans='NO'
d.sort()
for i in range(m):
    if d[bisect.bisect_right(d,t[i])-1]==t[i]:
        d.remove(d[bisect.bisect_right(d,t[i])-1])
        if i==m-1:
            ans='YES'
    else:
        break
print(ans)


### FIXED CODE ###

from collections import Counter
n=int(input())
d=list(map(int,input().split()))
m=int(input())
t=list(map(int,input().split()))

d_c=Counter(d)
t_c=Counter(t)
for i in t_c.keys():
    if t_c[i]>d_c[i]:
        print('NO')
        exit()
print('YES')
### BUGGY CODE ###

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

A.sort(reverse=True)
ans = 0
N -= 2
ans += A[0]
A.pop(0)

while True:
    if N == 0:
        print(ans)
        exit()
    elif N == 1:
        ans += A[0]
        print(ans)
        exit()
    elif N >= 2:
        ans += 2 * A[0]
        N -= 2
        A.pop(0)


### FIXED CODE ###

import heapq

N = int(input())
A = list(map(int, input().split()))
A = list(map(lambda x: x * (-1), A))

heapq.heapify(A)

ans = 0
N -= 2
ans += heapq.heappop(A) * (-1)

if N == 0:
    print(ans)
    exit()
elif N == 1:
    ans += A[0]
    print(ans)
    exit()
elif N >= 2:
    q = N // 2
    r = N % 2
    for i in range(1, q + 1):
        ans += 2 * heapq.heappop(A) * (-1)
    if r == 1:
        ans += heapq.heappop(A) * (-1)
    print(ans)
### BUGGY CODE ###

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
import numpy as np
 
K = INT()
sum = 0
 
for n in range(K):
  for m in range(K):
    for l in range(K):
      sum += gcd(n+1, gcd(m+1, l+1))
 
print(sum)

### FIXED CODE ###

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
 
K = INT()
sum = 0
 
for n in range(K):
  for m in range(K):
    for l in range(K):
      sum += gcd(n+1, gcd(m+1, l+1))
 
print(sum)
### BUGGY CODE ###

# -*- coding: utf-8 -*-

R,C,K = map(int, input().split())

items = [[0 for _ in range(C+1)] for _ in range(R+1)]
for i in range(K):
  r,c,v = map(int, input().split())
  items[r][c] = v

DP = [[[0,0,0,0] for _ in range(C+1)] for _ in range(R+1)]
for r in range(1,R+1):
  # 0
  for c in range(1,C+1):
    DP[r][c][0] = DP[r-1][c][3]
  # 1
  for c in range(1,C+1):
    DP[r][c][1] = max(DP[r][c][0]+items[r][c],DP[r][c-1][1])
  # 2
  for c in range(1,C+1):
    DP[r][c][2] = max(DP[r][c][1],DP[r][c-1][2],DP[r][c-1][1]+items[r][c])
  # 3
  for c in range(1,C+1):
    DP[r][c][3] = max(DP[r][c][2],DP[r][c-1][3],DP[r][c-1][2]+items[r][c])
        
print(DP[R][C][3])

### FIXED CODE ###

# -*- coding: utf-8 -*-

R,C,K = map(int, input().split())

items = [[0 for _ in range(C+1)] for _ in range(R+1)]
for i in range(K):
  r,c,v = map(int, input().split())
  items[r][c] = v

DP_prev = [0 for _ in range(C+1)]

for r in range(1,R+1):
  DP = [[0 for _ in range(C+1)],[0 for _ in range(C+1)],[0 for _ in range(C+1)]]
  for c in range(1,C+1):
    item = items[r][c]
    DP1 = max(DP_prev[c]+item,DP[0][c-1])
    DP2 = max(DP1,DP[1][c-1],DP[0][c-1]+item)
    DP3 = max(DP2,DP[2][c-1],DP[1][c-1]+item)
    DP[0][c] = DP1
    DP[1][c] = DP2
    DP[2][c] = DP3
  DP_prev = DP[2]
        
print(DP_prev[C])
### BUGGY CODE ###

from itertools import accumulate


def main():
    n = int(input())
    ans = 0
    for i in range(1, n):
        ans += i
    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

from itertools import accumulate


def main():
    n = int(input())
    print(n*(n-1)//2)


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

h,n=(int(i) for i in input().split())
l=[]
for i in range(n):
  a,b=(int(i) for i in input().split())
  l.append([a,b])
pocket=[0]
for i in range(h):
  mini=pocket[max(0,i+1-l[0][0])]+l[0][1]
  for j in range(n-1):
    a=l[j+1][0]
    b=l[j+1][1]
    mini=min(mini,pocket[max(0,i+1-a)]+b)
  pocket.append(mini)
print(pocket[h])


### FIXED CODE ###

h,n=(int(i) for i in input().split())
l=[]
for i in range(n):
  a,b=(int(i) for i in input().split())
  l.append([a,b])
pocket=[0]
for i in range(h):
  mini=pocket[max(0,i+1-l[0][0])]+l[0][1]
  for j in range(n-1):
    a=l[j+1][0]
    b=l[j+1][1]
    if pocket[max(0,i+1-a)]+b<mini:
      mini=pocket[max(0,i+1-a)]+b
  pocket.append(mini)
print(pocket[h])
### BUGGY CODE ###

n = int(input())
li = []
count = 0
f = 1
for i in range(n):
    a = input()
    li.append("".join(sorted(a)))
li.sort()
for i in range(n-1):
    if li[0] == li[1]:
        f += 1
        del li[0]
    else:
        count += (f*(f-1))//2
        f = 1
        del li[0]
count += (f*(f-1))//2
print(count)

### FIXED CODE ###

n = int(input())
li = []
count = 0
f = 1
for i in range(n):
    a = input()
    li.append("".join(sorted(a)))
li.sort()
for i in range(n-1):
    if li[i] == li[i+1]:
        f += 1
    else:
        count += (f*(f-1))//2
        f = 1
count += (f*(f-1))//2
print(count)
### BUGGY CODE ###

def main():
    n = int(input())
    s = [None] + list(input())
    q = int(input())
    alpha = [[] for i in range(26)]
    for i, si in enumerate(s[1:], 1):
        alpha[ord(si)-97].append(i)
    check = lambda x, y, z: [i for i in z if i >= x and i <= y]
    for _ in range(q):
        i, a, b = input().split()
        a = int(a)
        if i == "1":
            alpha[ord(s[a])-97].remove(a)
            alpha[ord(b)-97].append(a)
            s[a] = b
        else:
            cnt = 0
            for i in range(26):
                if alpha[i] and check(a, int(b), alpha[i]):
                    cnt += 1
            print(cnt)

if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    n = int(input())
    a = ord("a")
    orda = lambda x: ord(x)-a
    s = list(map(orda, list(input())))
    q = int(input())
    bits = [BIT(n) for _ in range(26)]
    for i, si in enumerate(s, 1):
        bits[si].add(i, 1)
    for _ in range(q):
        t, i, c = input().split()
        i = int(i)
        if t == "1":
            bits[s[i-1]].add(i, -1)
            bits[ord(c)-a].add(i, 1)
            s[i-1] = ord(c)-a
        else:
            c = int(c)
            cnt = 0
            for bit in bits:
                is_in = bit.sum_(c) - bit.sum_(i-1)
                if is_in:
                    cnt += 1
            print(cnt)
            
            
class BIT:
    __slots__ = ["length", "data"]
    def __init__(self, length):
        self.data = [0]*(length+1)
        self.length = length
    
    def add(self, i, x):
        while i < self.length+1:
            self.data[i] += x
            i += i&-i
    
    def sum_(self, i):
        x = 0
        while i > 0:
            x += self.data[i]
            i -= i&-i
        return x


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

n=int(input())
s=set()
for i in range(n):
  s^={input()}
print(len(s))

### FIXED CODE ###

N=int(input())
s=set()
for i in range(N):s^={input()}
print(len(s))
### BUGGY CODE ###

n,m=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
sorted_ab=sorted(ab, key=lambda x: x[0])
ans=0
i=0
for a, b in sorted_ab:
  for _ in range(b):
    if i < m:
      ans+=a
      i+=1
print(ans)

### FIXED CODE ###

n,m=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
sorted_ab=sorted(ab, key=lambda x: x[0])
ans=0
i=0
for a, b in sorted_ab:
  for _ in range(b):
    if i < m:
      ans+=a
      i+=1
    else:
      break
print(ans)
### BUGGY CODE ###

import itertools
# 解説を読んだ。
n, x, y = [int(x) for x in input().split()]

nodes = [i for i in range(1, n + 1)]
patterns = itertools.combinations(nodes, 2)

distannces = []
distannces_append = distannces.append
for p in patterns:
    routes = (
        abs(p[1] - p[0]),
        abs(x - p[0]) + 1 + abs(p[1] - y),
        abs(y - p[0]) + 1 + abs(p[1] - x)
    )
    distannces_append(min(routes))

distannces_count = distannces.count
for k in range(1, n):
    print(distannces_count(k))

# 後半 TLE したのでリストの関数をオブジェクトに格納した。


### FIXED CODE ###

from collections import deque

n, x, y = [int(x) for x in input().split()]
x -= 1
y -= 1
BIG = 65521
ans = {i: 0 for i in range(n)}


def bfs(start_v):
    """ある始点からほかの全点に行くまでの最短距離を求める。"""
    qu = deque()
    qu_append = qu.append
    qu_popleft = qu.popleft
    qu_append(start_v)
    # 始点からvに移動するまでの最短距離: dist[v]
    dist = [BIG] * n

    def push(v, d):
        """始点からvまでの最短距離が算出されていないときに，その距離を保存し，
        キューに頂点vを追加する。"""
        if dist[v] != BIG:
            # 既に訪問済みで距離が求められている。
            return
        dist[v] = d
        qu_append(v)

    push(start_v, 0)

    while len(qu):
        v = qu_popleft()
        # 始点からvの次の頂点へ移動する距離。
        d = dist[v] + 1
        if v < n - 1:
            push(v + 1, d)
        if v > 0:
            push(v - 1, d)
        if v == x:
            push(y, d)
        if v == y:
            push(x, d)

    for i in range(n):
        if dist[i] != 0:
            ans[dist[i]] += 1


def main():
    for i in range(n):
        bfs(i)

    for i in range(1, n):
        print(ans[i] // 2)


if __name__ == '__main__':
    main()

# TLE
### BUGGY CODE ###

import copy
N = int(input())
X = list(map(int, input().split()))

for i in range(N):
    Y = copy.copy(X)
    del Y[i]
    Y = sorted(Y)
    print(Y[int(N/2)-1])

### FIXED CODE ###

import copy
N = int(input())
X = list(map(int, input().split()))
Y = sorted(X)

first_harf = Y[:int(N/2)]
second_harf = Y[int(N/2):]

for i in range(N):
    if X[i] <= first_harf[-1]:
        print(second_harf[0])
    else:
        print(first_harf[-1])
### BUGGY CODE ###

a,b = map(int,input().split())
c = a*b
d = 1
ans  = 0
while d%a != 0 or d%b != 0:
    for i in range(1,c+1):
        if d%a != 0 or d%b != 0:
            d = d+1
        
print(d)

### FIXED CODE ###

a,b = map(int,input().split())
#最大公約数
def gcd(a,b):#a<=b
    while a != 0:
        a,b = b%a,a
    return b
#最小公約数
def lcm(a,b):
    return a*b // gcd(a,b)
print(lcm(a,b))
### BUGGY CODE ###


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

ans = 0
pattern = []
for x in range(N):
    for y in range(x + 1, N):
        if (S[x] + S[y]) not in pattern:
            ans += len(set(S[y + 1:]))
            pattern.append(S[x] + S[y])

print(ans)


### FIXED CODE ###

# https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_d

N = int(input())
S = input()
#
# ans = 0
# pattern = []
# for x in range(N):
#     for y in range(x + 1, N):
#         if (S[x] + S[y]) not in pattern:
#             ans += len(set(S[y + 1:]))
#             pattern.append(S[x] + S[y])
#
# print(ans)
ans = 0
for i in range(1000):
    key = str(i).zfill(3)
    first = S.find(key[0])
    if first == -1 or first == N:
        continue
    second = S[first + 1:].find(key[1])
    if second == -1 or (first + second + 2) == N:
        continue
    third = S[first + second + 2:].find(key[2])
    if not third == -1:
        # print(first, first + second + 1, first + second + third + 2, key)
        ans += 1
print(ans)
### BUGGY CODE ###

def recur(n,w):
    if n==0 or w==0:
        return 0
    elif (n,w) in dp:
        return dp[(n,w)]
    elif l[n-1][0]<=w:
        k=max(recur(n-1,w-l[n-1][0])+l[n-1][1],recur(n-1,w))
        dp[(n,w)]=k
        return k
    else:
        k=recur(n-1,w)
        dp[(n,w)]=k
        return k
n,w=map(int,input().split())
l=[]
for _ in range(n):
    a,b=map(int,input().split())
    l.append((a,b))
dp=dict()
print(recur(n,w))

### FIXED CODE ###

n,w=map(int,input().split())
l=[]
for _ in range(n):
    a,b=map(int,input().split())
    l.append((a,b))
dp=[[0 for i in range(w+1)]for i in range(n+1)]
for i in range(1,n+1):
    for j in range(1,w+1):
        if l[i-1][0]<=j:
            
            dp[i][j]=max(dp[i-1][j],dp[i-1][j-l[i-1][0]]+l[i-1][1])
        else:
            dp[i][j]=dp[i-1][j]
# print(dp)
print(dp[-1][-1])
### BUGGY CODE ###

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

dp = [float("inf")] * N
dp[0] = 0

for i in range(1, N):
    for j in range(1, K+1):
        if i - j < 0:
            break
        else:
            step = abs(h[i] - h[i-j])
            dp[i] = min(dp[i], dp[i-j]+step)

print(dp[N-1])

### FIXED CODE ###

import numpy as np

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

dp = np.zeros(N, dtype=int)
for i in range(1, N):
    dp[i] = min(dp[max(0,i-K):i]+abs(h[max(0,i-K):i]-h[i]))

print(dp[-1])
### BUGGY CODE ###

import itertools


n = int(input())
S = []
for i in range(n):
    s = list(input())
    s.sort()
    S.append(s)
cnt = 0
for v in itertools.combinations(S, 2):
    if v[0] == v[1]:
        cnt += 1
print(cnt)

### FIXED CODE ###

from collections import Counter

n = int(input())
S = []
for _ in range(n):
    s = sorted(list(input()))
    S.append(''.join(s))

S_cnt = Counter(S)

ans = 0
for k,v in S_cnt.items():
    ans += v*(v-1)//2
print(ans)
### BUGGY CODE ###

def dijkstra(s,n,w,cost):
    d = [float("inf")] * n
    used = [False] * n
    d[s] = 0
    while True:
        v = -1
        for i in range(n):
            if (not used[i]) and (v == -1):
               v = i
            elif (not used[i]) and d[i] < d[v]:
                v = i
        if v == -1:
               break
        used[v] = True
        for j in range(n):
               d[j] = min(d[j],d[v]+cost[v][j])
    return d

N = int(input())
cost = [[float("inf") for i in range(N)] for i in range(N)]
for _ in range(N-1):
    x,y,z = map(int,input().split())
    cost[x-1][y-1] = z
    cost[y-1][x-1] = z
Q, K = map(int, input().split())
result = dijkstra(K-1,N,N-1,cost)
for i in range(Q):
    x, y = map(int, input().split())
    print(abs(result[x-1]-result[K-1])+abs(result[y-1]+result[K-1]))

### FIXED CODE ###

N = int(input())
import heapq
def dijkstra_heap(s):
    d = [float("inf")] * N
    used = [True] * N
    d[s] = 0
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heapq.heappush(edgelist,e)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        d[v] = minedge[0]
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,[e[0]+d[v],e[1]])
    return d


edge = [[] for i in range(N)]
for i in range(N-1):
    x,y,z = map(int,input().split())
    edge[x-1].append([z,y-1])
    edge[y-1].append([z,x-1])
Q, K = map(int, input().split())
result = dijkstra_heap(K-1)
for i in range(Q):
    x, y = map(int, input().split())
    print(abs(result[x-1]-result[K-1])+abs(result[y-1]+result[K-1]))
### BUGGY CODE ###

N = int(input())

paper = []
for i in range(N):
    A = int(input())
    if A in paper:
        paper.remove(A)
    else:
        paper.append(A)
print(len(paper))


### FIXED CODE ###

from collections import defaultdict
N = int(input())

paper = defaultdict(int)
for i in range(N):
    A = int(input())
    paper[A] += 1

ans = 0
for k, v in paper.items():
    if v % 2 == 1:
        ans += 1
print(ans)
### BUGGY CODE ###

n,m=map(int,input().split())
A=list(map(int,input().split()))
for i in range(m):
    A.sort()
    A[-1]//=2
print(sum(A))

### FIXED CODE ###

from heapq import heappop, heappush
n,m=map(int,input().split())
A=list(map(int,input().split()))
B=sorted(map(lambda x: x * -1, A))
for i in range(m):
    a=heappop(B)
    a=-(-a//2)
    heappush(B,a)
print(-sum(B))
### BUGGY CODE ###

from itertools import permutations

def floyd_warshall():
            for k in range(N):
                for i in range(N):
                    for j in range(N):
                        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

            
N, M, R = list(map(int, input().split()))
r = (int(i)-1 for i in input().split())
res = float('inf')
dist = [[float("inf")] * N for i in range(N)]

for i in range(M):
    a, b, c = list(map(int, input().split()))
    a -= 1
    b -= 1
    dist[a][b] = dist[b][a] = c

floyd_warshall()
for p in permutations(r):
        s = 0
        for i in range(R - 1):
            s += dist[p[i]][p[i + 1]]
        if s < res:
            res = s
print(res)

### FIXED CODE ###

import sys
from itertools import permutations

def read_int_list():
    return list(map(int, input().split()))

 
def main():
    def floyd_warshall():
        for k in range(n):
            for i in range(n):
                for j in range(n):
                    dd = d[i][k] + d[k][j]
                    if dd < d[i][j]:
                        d[i][j] = dd
 
    n, m, r = read_int_list()
    v = read_int_list()
    v = [x - 1 for x in v]
    d = [[float('inf')] * n for i in range(n)]
    for i in range(n):
        d[i][i] = 0
    for i in range(m):
        a, b, c = read_int_list()
        a -= 1
        b -= 1
        d[a][b] = c
        d[b][a] = c
    floyd_warshall()
    res = float('inf')
    for p in permutations(v):
        s = 0
        for i in range(r - 1):
            s += d[p[i]][p[i + 1]]
        if s < res:
            res = s
    print(res)
 
 
main()
### BUGGY CODE ###

s=input()
a,b =map(int,input().split())
table=[[] for i in range(2)]#0が横1が縦
t = 0
k=0
for i in range(len(s)):
    if s[i]=='F':
        k+=1
    else:
        table[t].append(k)
        t=(t+1)%2
        k=0
table[t].append(k)
#booldp [2][x] 
L=2*len(s)+1
dp=[[False]*(L) for i in range(len(table[0])+1)]
dpy=[[False]*(L) for i in range(len(table[1])+1)]
dp[0][len(s)]=True
dpy[0][len(s)]=True
#print(table)
for i in range(len(table[0])):
    x=table[0][i]
    for z in range(L):
        if i==0 and 0<= z+x <L:
            dp[i+1][z+x] = dp[i][z]
            continue
        if 0<= z+x <L:
            dp[i+1][z+x] = dp[i+1][z+x]|dp[i][z]
        if 0<= z-x <L:
            dp[i+1][z-x] = dp[i+1][z-x]|dp[i][z]
for i in range(len(table[1])):
    x=table[1][i]
    for z in range(L):
        if 0<= z+x <L:
            dpy[i+1][z+x] = dpy[i+1][z+x]|dpy[i][z]
        if 0<= z-x <L:
            dpy[i+1][z-x] = dpy[i+1][z-x]|dpy[i][z]
if dp[len(table[0])][a+len(s)] and dpy[len(table[1])][b+len(s)]:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

import sys
s=input()
A,B =map(int,input().split())
table=[[] for i in range(2)]#0が横1が縦
t = 0
k=0
for i in range(len(s)):
    if s[i]=='F':
        k+=1
    else:
        table[t].append(k)
        t=(t+1)%2
        k=0
table[t].append(k)
L=len(s)
Lx=[set() for i in range(len(table[0]) +1)]
Ly=[set() for i in range(len(table[1]) +1)]
Lx[0].add(0)
Ly[0].add(0)
for i in range(len(table[0])):
    x = table[0][i]
    if i==0:
        Lx[1].add(x)
        continue
    for a in Lx[i]:
        if -L<=a+x<=L:
            Lx[i+1].add(a+x)
        if -L<=a-x<=L:
            Lx[i+1].add(a-x) 
flag=True
for a in Lx[len(table[0])]:
    if a==A:
        flag =False
if flag:
    print('No')
    sys.exit()
    
for i in range(len(table[1])):
    x = table[1][i]
    for a in Ly[i]:
        if -L<=a+x<=L:
            Ly[i+1].add(a+x)
        if -L<=a-x<=L:
            Ly[i+1].add(a-x)
flag=True
for a in Ly[len(table[1])]:
    if a==B:
        flag =False
if flag:
    print('No')
    sys.exit()
    
print('Yes')
### BUGGY CODE ###

n = int(input())
a = sorted(list(map(int, input().split())))
while True:
    a = sorted(list(set(a)))
    tmp = sorted(a[:500])
    for i in tmp:
        if i == a[0]:
            continue
        elif i % a[0] == 0:
            a.remove(i)
        else:
            a.append(i % a[0])
            a.remove(i)
    if len(a) == 1:
        break
print(a[0])


### FIXED CODE ###

n = int(input())
a = sorted(list(map(int, input().split())))
while True:
    a = sorted(list(set(a)))
    tmp = sorted(a[:])
    for i in tmp:
        if i == a[0]:
            continue
        elif i % a[0] == 0:
            a.remove(i)
        else:
            a.append(i % a[0])
            if i % a[0] == 1:
                print(1)
                exit()
            a.remove(i)
    if len(a) == 1:
        break
print(a[0])
### BUGGY CODE ###

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
S = input()

nR = S.count("R")
nG = S.count("G")
nB = S.count("B")
ans = nR*nG*nB
for i in range(N):  # 開始 index
	for j in range(1, N//2+1):  # 幅
		if i+2*j >= N:
			continue
		a, b, c = S[i], S[i+j], S[i+2*j]
		if a != b and b != c and c != a:
			ans -= 1
print(ans)


### FIXED CODE ###

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
S = input()

nR = S.count("R")
nG = S.count("G")
nB = S.count("B")
ans = nR*nG*nB
for i in range(N):  # 開始 index
	for j in range(1, N//2+1):  # 幅
		if i+2*j >= N:
			continue
		a, b, c = S[i], S[i+j], S[i+2*j]
		if a != b and b != c and c != a:
			ans -= 1
print(ans)