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

N = int(input())
L = list(map(int,input().split()))
ans = 1
for i in range(N):
    ans = ans*L[i]
if ans <= 10**18 and i == N-1:
    print(ans)
elif ans >= 10**18 and i == N-1:
    print("-1")


### FIXED CODE ###

import sys
N = int(input())
L = list(map(int,input().split()))
ans = 1

if 0 in L:
    print(0)
    sys.exit()

for i in L:
    ans = ans*i
    if ans > 10**18:
        print(-1)
        sys.exit()
print(ans)
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
b=a[0]-1
ans=0
ansl=0
ansr=0
for i in range(n):
    ans+=abs(a[i]-b-i-1)
    ansl+=abs(a[i]-b-i)
    ansr+=abs(a[i]-b-i-2)
    
A=[10**10,ans] 
if ans>ansl:
    b-=1
    A.append(ansl)
    while A[-1]<A[-2]:
        ans=0
        b-=1
        for i in range(n):
            ans+=abs(a[i]-b-i-1)
        A.append(ans) 
elif ans>ansr:
    b+=1
    A.append(ansr)
    while A[-1]<A[-2]:
        ans=0
        b+=1
        for i in range(n):
            ans+=abs(a[i]-b-i-1)
        A.append(ans)
else:
    print(ans)
    exit()
print(A[-2]) 
    
               
            
            
            
              

    
        

### FIXED CODE ###

n=int(input())
import math
a=list(map(int,input().split()))
for i in range(n):
    a[i]-=(i+1)
a=sorted(a)  
if n%2==0:
    x=math.floor((a[int(n/2)]+a[int((n/2)-1)])/2)
else:
    x=a[int(n//2)]    
ans=0
for i in range(n):
    ans+=abs(a[i]-x)
print(ans)
### BUGGY CODE ###

# -*- coding utf-8 -*-
import bisect

N = int(input())

c = [int(input())]

for ai in range(1, N):
    a = int(input())
    if a <= c[0]:
        c = [a] + c
    else:
        i = bisect.bisect_left(c, a) - 1
        c[i] = a

print(len(c))


### FIXED CODE ###

import bisect
from collections import deque

N = int(input())

# c = [int(input())]
c = deque()
c.appendleft(int(input()))


for ai in range(1, N):
    a = int(input())
    if a <= c[0]:
        c.appendleft(a)
    else:
        i = bisect.bisect_left(c, a) - 1
        c[i] = a

print(len(c))
### BUGGY CODE ###

import sys 
from functools import reduce
from math import gcd
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
mod = 10 ** 9 + 7
N = int(readline())
A = list(map(int,readline().split()))
lcm = reduce(lambda x,y:x*y//gcd(x,y),A)
ans = 0
for i in range(N):
    ans += lcm//A[i]%mod
print(ans%mod)

### FIXED CODE ###

import sys 
from functools import reduce
from math import gcd
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
mod = 10 ** 9 + 7
N = int(readline())
A = list(map(int,readline().split()))
lcm = reduce(lambda x,y:x*y//gcd(x,y),A)
ans = 0
ans = sum(lcm//x for x in A)
print(ans%mod)
### BUGGY CODE ###

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

a.sort()

ans = 0
for n in a:
    ans = max(a.count(n) + a.count(n+1) + a.count(n+2), ans)

print(ans)

### FIXED CODE ###

N = int(input())
a = list(map(int, input().split()))
A = [0] * (10 ** 5 + 5)
for ai in a:
    A[ai - 1] += 1
    A[ai] += 1
    A[ai + 1] += 1
print(max(A))
### BUGGY CODE ###

import sys
import math

#sys.setrecursionlimit(10000)

n,k = map(int, input().split())
h = sorted(list(map(int, (input() for i in range(n)))))

l = []
for i in range(n - 1):
    l.append(h[i + 1] - h[i])

ans = max(l)
for j in range(len(l) - (k - 2)):
    ans = min(ans,sum(l[j:j + k - 1]))

print(ans)


### FIXED CODE ###

import sys
import math

#sys.setrecursionlimit(10000)

n,k = map(int, input().split())
h = sorted(list(map(int, (input() for i in range(n)))))

ans = max(h)

for i in range(n - k + 1):
    ans = min(ans,h[i + k - 1] - h[i])
print(ans)
### BUGGY CODE ###

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

### FIXED CODE ###

n=int(input())
x=list(map(int,input().split()))
l=sorted(x)
m1=l[n//2-1]
m2=l[n//2]
for i in range(n):
    if x[i]<=m1:
        print(m2)
    else:
        print(m1)
### BUGGY CODE ###

N = int(input())
limit = 10**18
A = list(map(int, input().split()))
ans = 1
for i in A:
    ans = ans*i
print(ans if ans <= limit else -1)

### FIXED CODE ###

# %%time
from numba import njit
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))


@njit
def f(A):
    ans = 1
    limit = 10**18
    if np.sum(A == 0) > 0:
        return 0
    elif np.sum(np.log10(A)) > 18:
        return -1
    for i in A:
        ans = ans*i
    return ans if ans<=limit else -1



print(int(f(A)))
### BUGGY CODE ###

s=input()
a=int(s)
list=[]
list.append(1)
list.append(6)
list.append(9)
list.append(36)
list.append(81)
list.append(216)
list.append(729)
list.append(1296)
list.append(6561)
list.append(7776)
list.append(59049)
list.append(46656)
pp=[50 for l in range(50)]
def money(x,y):
  for i in range(12):
    b=x//list[i]
    if b==0:
      continue
    if i%2==1:
      if 0<b<6:
        if x%list[i]==0:
          pp[y+b]=y+b
        else:
          money(x-list[i],y+1)
    elif i%2==0:
      if i!=0:
        if 0<b<9:
          if x%list[i]==0:
            pp[y+b]=y+b
          else:
            money(x-list[i],y+1)
      else:
        if 0<b<6:
          pp[y+b]=y+b
money(a,0)
print(min(pp))

### FIXED CODE ###

s=input()
a=int(s)
list=[]
list.append(1)
list.append(6)
list.append(9)
list.append(36)
list.append(81)
list.append(216)
list.append(729)
list.append(1296)
list.append(6561)
list.append(7776)
list.append(59049)
list.append(46656)
pp=[]
def money(x,y):
  for i in range(12):
    b=x//list[i]
    if b==0:
      continue
    if i%2==1:
      if 0<b<6:
        if x%list[i]==0:
          pp.append(y+b)
        else:
          if y>20:
            break
          money(x-list[i],y+1)
    elif i%2==0:
      if i!=0:
        if 0<b<9:
          if x%list[i]==0:
            pp.append(y+b)
          else:
            if y>20:
              break
            money(x-list[i],y+1)
      else:
        if 0<b<6:
          pp.append(y+b)
money(a,0)
print(min(pp))
### BUGGY CODE ###

n, m = map(int, input().split())
L, R = [], []
for _ in range(m):
    l,r = map(int, input().split())
    L.append(l)
    R.append(r)

res = 0
for i in range(1, n+1):
    if max(L) <= i <= min(R):
        res += 1
print(res)

### FIXED CODE ###

n, m = map(int, input().split())
L, R = [], []
for _ in range(m):
    l,r = map(int, input().split())
    L.append(l)
    R.append(r)


res = min(R) - max(L) + 1
if res < 0:
    print(0)
else:
    print(res)
### BUGGY CODE ###

s = input()
q = int(input())
reverse = False
for _ in range(q):
    query = input().split()
    if query[0] == "1":
        reverse = not(reverse)
    else:
        if query[1] == "1":
            if reverse:
                s = s + query[2]
            else:
                s = query[2] + s
        else:
            if reverse:
                s = query[2] + s
            else:
                s = s + query[2]
if reverse:
    print(s[::-1])
else:
    print(s)


### FIXED CODE ###

def main():
    s = input()
    q = int(input())
    reverse = 0
    head = ""
    tail = ""
    for _ in range(q):
        query = input().split()
        if query[0] == "1":
            reverse = not(reverse)
        else:
            if (reverse^int(query[1]))&1:
                head += query[2]
            else:
                tail += query[2]
    s = head[::-1] + s + tail
    if reverse&1:
        print(s[::-1])
    else:
        print(s)
if __name__ == "__main__":
    main()
### BUGGY CODE ###

import sys
from math import factorial

def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))
    MOD = 10**9 + 7

    used = set()
    first = 0
    second = 0
    for i in range(N+1):
        if A[i] in used:
            second = i
            first = A.index(A[i])
        else:
            used.add(A[i])

    factrial = [1] * (N+2)
    for k in range(1, N+2):
        factrial[k] = (factrial[k-1] * k) % MOD

    fact_inv = [1] * (N+2)
    fact_inv[N+1] = pow(factrial[N+1], MOD - 2, MOD)
    for k in range(N, -1, -1):
        fact_inv[k] = (fact_inv[k+1] * (k+1)) % MOD

    def comb(n, r, MOD):
        if n < 0 or r < 0 or n < r:
            return 0
        else:
            return (factrial[n] * fact_inv[r] * fact_inv[n-r]) % MOD

    for i in range(1, N+2):
        ans = comb(N+1, i, MOD)
        for j in range(i):
            m_f = first
            r_f = j

            m_b = N - second
            r_b = i - (j + 1)

            ans -= comb(m_f, r_f, MOD) * comb(m_b, r_b, MOD)

        print(int(ans) % MOD)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))
    MOD = 10**9 + 7

    used = set()
    first = 0
    second = 0
    for i in range(N+1):
        if A[i] in used:
            second = i
            first = A.index(A[i])
        else:
            used.add(A[i])

    factrial = [1] * (N+2)
    for k in range(1, N+2):
        factrial[k] = (factrial[k-1] * k) % MOD

    fact_inv = [1] * (N+2)
    fact_inv[N+1] = pow(factrial[N+1], MOD - 2, MOD)
    for k in range(N, -1, -1):
        fact_inv[k] = (fact_inv[k+1] * (k+1)) % MOD

    def comb(n, r, MOD):
        if n < 0 or r < 0 or n < r:
            return 0
        else:
            return (factrial[n] * fact_inv[r] * fact_inv[n-r]) % MOD

    m = first + (N - second)
    for i in range(1, N+2):
        ans = comb(N+1, i, MOD) - comb(m, i-1, MOD)
        print(int(ans) % MOD)


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

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

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

keep_val = 0
check = 0
for i in range(n-k+1):
    if keep_val < sum(p[i:i+k]):
        check = i
        keep_val = sum(p[i:i+k])

#print(p[check:check+k])

ans = 0
for i in p[check:check+k]:
    ans += (i+1)/2
print(ans)


### FIXED CODE ###

# -*- coding: utf-8 -*-
 
n, k = map(int, input().split())
p = list(map(int, input().split()))

summation = 0
exp_val = []
for i in range(n):
    summation += (p[i]+1)/2
    exp_val.append(summation)
exp_val.insert(0, 0)
#print(exp_val)

ans = 0
for i in range(n-k+1):
    m = exp_val[k+i] - exp_val[i]
    ans = max(ans, m)

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

def gca(x, y):
    if x == 0:
        return y
    return gca(y % x, x)

N = int(input())
A = [int(i) for i in input().split()]

dic = {}



maxg = 0
for ignore in  range(N):
    g = A[0]
    if ignore == 0:
        g = A[1]
    for i in range(N):
        if i == ignore:
            continue
        x = g
        y = A[i]
        if y > x : x, y = y, x
        if (x, y) in dic:
            g = dic[(x, y)]
        else:
            g = gca(g, A[i])
        dic[(x, y)] = g

    maxg = max(g, maxg)

print(maxg)

### FIXED CODE ###

def gca(x, y):
    if x == 0:
        return y
    return gca(y % x, x)

N = int(input())
A = [int(i) for i in input().split()]

L = [0] * N
R = [0] * N
L[0] = A[0]
R[N - 1] = A[N - 1]

for i in range(1, N):
    L[i] = gca(A[i], L[i - 1])
for i in range(N - 2, -1, -1):
    R[i] = gca(A[i], R[i + 1])
maxg = 0
for i in range(1, N - 1):
    maxg = max(maxg, gca(L[i - 1], R[i + 1]))

print(max(L[N - 2], R[1], maxg))
### BUGGY CODE ###

n = int(input())
pwr = 1
for i in range(n): 
    pwr *= 1*(i+1)
print(pwr%(10**9+7))

### FIXED CODE ###

n = int(input())
pwr = 1
for i in range(n): 
    pwr *= 1*(i+1)
    pwr = pwr%(10**9+7)
print(pwr)
### BUGGY CODE ###

n,k=map(int,input().split())
a,b=[],[]
for i in range(n):
    A,B=map(int,input().split())
    b=[A]*B
    a=a+b
a.sort()
print(a[k-1])

### FIXED CODE ###

n,k=map(int,input().split())
a=[]
for i in range(n):
    A=list(map(int,input().split()))
    a.append(A)
a = sorted(a, key=lambda x: x[0])
b=0
for i in range(n):
    b+=a[i][1]
    if b>=k:
        print(a[i][0])
        exit()
### BUGGY CODE ###

class Tree:
    nodes = []
    def __init__(self, root = None):
        self.root = root
    def insert(self, label, children = []):
        self.nodes.append(Node(label, children))
    def search_label(self, label):
        for i in self.nodes:
            if i.label == label:
                return i
    def find_parent(self):
        for i in self.nodes:
            if i.children != []:
                for k in i.children:
                    self.search_label(k).parent = i.label
    def distribute_type(self):
        for i in self.nodes:
            if i.parent != -1:
                if i.children == []:
                    i.type_ = "leaf"
                else:
                    i.type_ = "internal node"
    def distribute_depth(self, node):
        if node.children == []:
            return
        for i in node.children:
            x = self.search_label(i)
            x.depth += node.depth + 1
            self.distribute_depth(x)

class Node:
# type_は0:root, 1:internal node, 2:leaf
    def __init__(self, label, children = []):
        self.label = label
        self.type_ = "root"
        self.depth = 0
        self.parent = -1
        self.children = children


tree = Tree()
n = int(input())
for i in range(n):
    a = list(map(int, input().split()))
    label = a[0]
    if a[1] > 0:
        children = a[2:]
        tree.insert(label, children)
    else:
        tree.insert(label)
tree.find_parent()
tree.distribute_type()
tree.nodes.sort(key = lambda x: x.label)
for i in tree.nodes:
    if i.type_ == "root":
        tree.distribute_depth(i)
for i in tree.nodes:
    print("node {0:}: parent = {1:}, depth = {2:}, {3:}, {4:}".format(i.label, i.parent, i.depth, i.type_, i.children))


### FIXED CODE ###

class Tree:
    nodes = []
    def __init__(self, root = None):
        None
    def insert(self, label, children = []):
        if children != []:
            for i in children:
                self.nodes[label].children.append(self.nodes[i])
                self.nodes[i].parent = self.nodes[label]
                self.nodes[i].type_ = "internal node"
    def depth(self, node):
        if node.children == []:
            node.type_ = "leaf"
        else:
            for i in node.children:
                i.depth = node.depth + 1
                self.depth(i)

class Node:
    def __init__(self, label, children = []):
        self.label = label
        self.type_ = "root"
        self.depth = 0
        self.parent = -1
        self.children = [] # self.children = childrenにするとハマる

tree = Tree()
n = int(input())
for i in range(n):
    tree.nodes.append(Node(i))
for i in range(n):
    children = []
    label, num, *children = map(int, input().split())
    tree.insert(label, children)
for i in tree.nodes:
    if i.parent == -1:
        tree.depth(i)
        None
if n == 1:
    tree.nodes[0].type_ = "root"
for i in tree.nodes:
    print("node {0:}: parent = {1:}, depth = {2:}, {3:}, ".\
            format(i.label, i.parent if i.parent == -1 else i.parent.label,\
            i.depth, i.type_), end = "")
    print([i.label for i in i.children])
### BUGGY CODE ###

N, Q = map(int, input().split())
S = input()
lr = [list(map(int, input().split())) for i in range(Q)]
for i in range(Q):
    print(S[lr[i][0]-1:lr[i][1]].count('AC'))

### FIXED CODE ###

N, Q = map(int, input().split())
S = input()
count = [0]*N
for i in range(1, N): #i番目までに何個の'AC'があったかをリスト格納
    count[i] += count[i-1]
    if S[i-1:i+1] == 'AC':
        count[i] += 1
for i in range(Q):
    l, r = map(int, input().split())
    print(count[r-1]-count[l-1])
### BUGGY CODE ###

import copy
N, M = map(int, input().split())
boxkey = [[[], 0] for _ in range(N)]
keymoney = [0 for _ in range(M)]

for i in range(M):
	a, b = list(map(int, input().split()))
	keymoney[i] = a
	C = list(map(int, input().split()))
	for c in C:
		boxkey[c - 1][0].append(i + 1)
		
for i in range(N):
	boxkey[i][1] = len(boxkey[i][0])

boxkey = sorted(boxkey, key = lambda x : (x[1]))
mini = float('inf')

	
minimum = float('inf')
end = 0

def dfs(blg_key, depth, money):
	global mini
	depth += 1
	if depth == N:
		mini = min(money, mini)
		return money
	else:
		# print(boxkey[depth][0])
		for i in boxkey[depth][0]:
			
			# print(i)
			t = copy.deepcopy(blg_key)
			if not i in blg_key:
				t.append(i)
				# print(t)
				dfs(t, depth, money + keymoney[i - 1])
			else:
				# print(t)
				dfs(t, depth, money)
				
				
for i in boxkey:
	if i[1] == 0:
		end = 1
		print(-1)
		break
if end == 0:
	for i in boxkey[0][0]:
		dfs([i], 0, keymoney[i - 1])
	print(mini)

### FIXED CODE ###

# 所持している鍵の集合をbitで表現する
#　鍵の集合を表す2進数が少なくなる方向に遷移することはないから，for文for文でかける

N, M = map(int, input().split())
status_money = [float('inf')] * (1 << N)

# 初期状態からの遷移を記録
for _ in range(M) :
    a, b = map(int, input().split())
    C = 0
    for c in input().split() :
        C |= (1 << (int(c) - 1))
    status_money[C] = min(status_money[C], a)
    
# ある状態とある状態の組合せを全部取る
for c in range(1 << N):
    # どんな鍵の組合せでも到達できない宝箱の組合せがあるかもしれない
    if status_money[c] == float('inf'):
        continue
    for d in range(1 << N):
        # c と d の論理和をとって新しく生成される状態 e を考える
        e = c | d
        # eにあらかじめ格納されている最小コストと，今生成したコストとのminをとる
        status_money[e] = min(status_money[c] + status_money[d], status_money[e])

# そもそも到達できない場合の処理を記述       
if status_money[-1] == float('inf'):
    print(-1)
else:
    print(status_money[-1])
### BUGGY CODE ###

import numpy as np

n, m = map(int, input().split())
a = [int(num) for num in input().split()]

cnt_dict = {}
for i in range(m):
    b, c = map(int, input().split())
    cnt_dict.setdefault(c, 0)
    cnt_dict[c] += b
for a_ in a:
    cnt_dict.setdefault(a_, 0)
    cnt_dict[a_] += 1

cnt_dict = sorted(cnt_dict.items(), key=lambda x: -x[0])

cnt = 0
ans = 0

for (k, v) in cnt_dict:
    v_ = np.min([v, n - cnt])
    ans += v_ * k
    cnt += v_
    if cnt == n:
        break


print(ans)


### FIXED CODE ###

from sys import stdin

n, m = map(int, stdin.readline().split())
a = [int(num) for num in stdin.readline().split()]

cnt_list = [(a[i], 1) for i in range(n)]
for i in range(m):
    b, c = map(int, stdin.readline().split())
    cnt_list.append((c, b))

cnt_list.sort()
cnt_list.reverse()

cnt = n
ans = 0

for (k, v) in cnt_list:
    acc_v = min(v, cnt)
    ans += k * acc_v
    cnt -= acc_v


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

#for  _ in range(int(input())):
    #n, k = map(int, input().split())

n = int(input())

arr = list(map(int, input().split()))
ans=1
for i in range(n):
    ans=ans*arr[i]
if ans>10**18:
    print(-1)
else:
    print(ans)


### FIXED CODE ###

#for  _ in range(int(input())):
    #n, k = map(int, input().split())

n = int(input())

arr = list(map(int, input().split()))
arr.sort()
if arr[0]==0:
    print(0)
else:
    arr=arr[::-1]
    ans=1
    for i in range(n):
        ans*=arr[i]
        if ans>10**18:
            ans=-1
            break
    print(ans)
### BUGGY CODE ###

def main():
    n,x,y = tuple([int(t)for t in input().split()])

    dmin = [[n]*n for _ in [0]*n]

    nlist = list(range(n))

    for i in range(n):
        for j in range(i,n):
            dmin[i][j] = j-i
            dmin[j][i] = j-i

    for i in range(x):
        for j in range(y-1,n):
            dmin[i][j] -= y-x-1
            dmin[j][i] -= y-x-1


    for i in range(n):
        for j in range(x,(x+y)//2):
            t = dmin[j][x-1]+dmin[x-1][i]
            if dmin[i][j]>t:
                dmin[i][j] = t
                dmin[j][i] = t

        for j in range((x+y)//2,y):
            t = dmin[j][y-1]+dmin[y-1][i]
            if dmin[i][j]>t:
                dmin[i][j] = t
                dmin[j][i] = t

    res = [0]*(n+1)
    for dmin_ in dmin:
        for d in dmin_:
            res[d] += 1

    for r in res[1:n]:
        print(r//2)

if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    n,x,y = tuple([int(t)for t in input().split()])

    dmin = [[n]*n for _ in [0]*n]

    nlist = list(range(n))

    for i in range(n):
        for j in range(i,n):
            dmin[i][j] = j-i
            dmin[j][i] = j-i

    for i in range(x):
        for j in range(y-1,n):
            dmin[i][j] -= y-x-1
            dmin[j][i] -= y-x-1


    for i in range(n):
        for j in range(x,(x+y)//2):
            t = dmin[j][x-1]+dmin[x-1][i]
            if dmin[i][j]>t:
                dmin[i][j] = t
                dmin[j][i] = t

        for j in range((x+y)//2,y):
            t = dmin[j][y-1]+dmin[y-1][i]
            if dmin[i][j]>t:
                dmin[i][j] = t
                dmin[j][i] = t

    res = [0]*(n+1)
    for dmin_ in dmin:
        for d in dmin_:
            res[d] += 1

    for r in res[1:n]:
        print(r//2)

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

from scipy.sparse import*
i=lambda:tuple(map(int,input().split()))
f=csgraph.dijkstra
n,m,l=i()
d=eval('[0]*-~n,'*-~n)
while m:a,b,c=i();d[a][b]=c;m-=1
d=f(f(d,0)<=l)
d[d>n]=0
q,=i()
exec('print(int(d[i()])-1);'*q)

### FIXED CODE ###

from scipy.sparse import*
s=csgraph.floyd_warshall
n,m,l,*t=map(int,open(0).read().split())
d=eval('[9e9]*-~n,'*-~n)
for a,b,c in zip(*[iter(t[:m*3])]*3):d[a][b]=d[b][a]=c
d=s(d)
d[d>l]=9e9
d[d<=l]=1
d=s(d)
d[d>9e9]=9e9
for s,t in zip(*[iter(t[m*3+1:])]*2):print(int(d[s,t]%9e9-1))
### BUGGY CODE ###

N = int(input())
S = list(input())
S_l = len(S)
ans = 0
cum = [[0]*3 for _ in range(N+1)]
for i,s in enumerate(S,1):
    cum[i]=cum[i-1].copy()
    if s=='R':
        cum[i][0]+=1
    elif s=='G':
        cum[i][1]+=1
    elif s=='B':
        cum[i][2]+=1


for i in range(len(S)):
  for j in range(i+1,len(S)):
    if S[i]==S[j]:
      continue
    else:
      x = 'RGB'.replace(S[i],'').replace(S[j],'')
      if x=='R':
        ans+=cum[-1][0]-cum[j][0]
        y = 2*j-i
        if y<S_l:
          if S[y]=='R':
            ans-=1
      elif x=='G':
        ans+=cum[-1][1]-cum[j][1]
        y = 2*j-i
        if y<S_l:
          if S[y]=='G':
            ans-=1
      else:
        ans+=cum[-1][2]-cum[j][2]
        y = 2*j-i
        if y<S_l:
          if S[y]=='B':
            ans-=1
 
print(ans)

### FIXED CODE ###

N = int(input())
S = list(input())
S_l = len(S)
ans = 0
from collections import deque
R = deque([])
G = deque([])
B  = deque([])
for i,s in enumerate(S):
    if s=='R':
        R.append(i)
    elif s=='G':
        G.append(i)
    elif s=='B':
        B.append(i)

def res(X,Y,S,i,a,b):
  x = X.copy()
  ret = 0
  for y in Y:
    if len(x)!=0:
      while x[0]<y:
        x.popleft()
        if len(x)==0:
          break
    ret+=len(x)
    tmp = 2*y-i
    if tmp>=S_l:
      continue
    if S[tmp]==a:
      ret-=1
  
  y = Y.copy()
  for x in X:
    if len(y)!=0:
      while y[0]<x:
        y.popleft()
        if len(y)==0:
          break
    ret+=len(y)
    tmp = 2*x-i
    if tmp>=S_l:
      continue
    if S[tmp]==b:
      ret-=1

      
  return ret
    
for i in range(len(S)):
    if S[i]=='R':
      r = R.popleft()
      ans += res(G,B,S,i,'G','B')
    elif S[i]=='G':
      g = G.popleft()
      ans += res(R,B,S,i,'R','B')
    else:
      b = B.popleft()
      ans += res(R,G,S,i,'R','G')
      
print(ans)