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

N, M = map(int, input().split())

from fractions import gcd
ans = 0
for i in range(1, (M//N)+1):
    ans = max(ans, gcd(i, M-(i*(N-1))))

print(ans)

### FIXED CODE ###

N, M = map(int, input().split())

from fractions import gcd

def make_divisors(n: int):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)
    return divisors

divisors = make_divisors(M)

ans = 0
for i in range(len(divisors)):
    d = divisors[i]
    if d*(N-1) >= M:
        continue
    ans = max(ans, gcd(d, M-(d*(N-1))))

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

from collections import deque

h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
cnt = [[-1] * w for _ in range(h)]

def bfs():
    queue = deque()
    for i in range(h):
        for j in range(w):
            if s[i][j] == "#":
                queue.append([i, j])
                cnt[i][j] = 0
    while queue:
        i, j = queue.popleft()
        for di, dj in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            if 0 <= i + di < h and 0 <= j + dj < w and cnt[i + di][j + dj] == -1:
                queue.append([i + di, j + dj])
                cnt[i + di][j + dj] = cnt[i][j] + 1

bfs()
print(max([max(l) for l in cnt]))

### FIXED CODE ###

from collections import deque

h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
cnt = [[-1] * w for _ in range(h)]

def bfs():
    queue = deque()
    for i in range(h):
        for j in range(w):
            if s[i][j] == "#":
                queue.append([i, j])
                cnt[i][j] = 0
    while queue:
        i, j = queue.popleft()
        for di, dj in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            if 0 <= i + di < h and 0 <= j + dj < w and cnt[i + di][j + dj] == -1:
                queue.append([i + di, j + dj])
                cnt[i + di][j + dj] = cnt[i][j] + 1

bfs()
print(max([max(l) for l in cnt]))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
from math import gcd
from functools import reduce

def gcd_list(numbers):
    return reduce(gcd, numbers)

K = ii()
ans = 0

memo = dp3(-1, K+1, K+1, K+1)

for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            #l = sorted([i, j, k])
            #l = [i, j, k]
            #a, b, c = l[0], l[1], l[2]
            a, b, c = i, j, k
            if memo[a][b][c] != -1:
                ans += memo[a][b][c]
            else:
                memo[a][b][c] = gcd_list([a, b, c])
                memo[i][k][j] = memo[k][i][j] = memo[k][j][i] = memo[j][i][k] = memo[j][k][i] = memo[i][j][k]
                #memo[i][k][j] = memo[i][j][k]
                #memo[k][i][j] = memo[i][j][k]
                #memo[k][j][i] = memo[i][j][k]
                #memo[j][j][i] = memo[i][j][k]
                #memo[j][i][k] = memo[i][j][k]
                ans += memo[a][b][c]
            #ans += gcd_list([i, j, k])


print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
from math import gcd
from functools import reduce

def gcd_list(numbers):
    return reduce(gcd, numbers)

K = ii()
ans = 0

memo = dp3(-1, K+1, K+1, K+1)

for i in range(1, K+1):
    for j in range(i+1, K+1):
        for k in range(j+1, K+1):
            '''
            #l = sorted([i, j, k])
            l = [i, j, k]
            a, b, c = l[0], l[1], l[2]
            if memo[a][b][c] != -1:
                ans += memo[a][b][c]
            else:
                memo[a][b][c] = gcd_list(l)
                #memo[i][k][j] = memo[k][i][j] = memo[k][j][i] = memo[j][i][k] = memo[j][k][i] = memo[i][j][k]
                #memo[i][k][j] = memo[i][j][k]
                #memo[k][i][j] = memo[i][j][k]
                #memo[k][j][i] = memo[i][j][k]
                #memo[j][j][i] = memo[i][j][k]
                #memo[j][i][k] = memo[i][j][k]
                ans += memo[a][b][c]
                '''
            ans += gcd_list([i, j, k])*6

for i in range(1, K+1):
    for j in range(1, K+1):
        if i!=j:
            ans += gcd_list([i, i, j])*3

for i in range(1, K+1):
    ans += gcd_list([i, i, i])

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

N,M = map(int,input().split(" "))

A = []
B = []
for _ in range(N):
    a,b = map(int,input().split(" "))
    A.append(a)
    B.append(b)


# 日数でソート
ind_sorted = sorted(range(N), key = lambda x:A[x])

tmp_a = 0
tmp_b_ls = [0]
money = 0
for i in range(N):
    if A[ind_sorted[i]] > M:
        break
    if tmp_a != A[ind_sorted[i]]:
        d = A[ind_sorted[i]]-tmp_a
        tmp_b_ls = sorted(tmp_b_ls)[::-1]
        tmp_money = sum(tmp_b_ls[:d])
        tmp_b_ls = tmp_b_ls[d:]
        money += tmp_money
        tmp_a = A[ind_sorted[i]]
    tmp_b_ls.append(B[ind_sorted[i]])

d = M+1-tmp_a
tmp_money = sum(sorted(tmp_b_ls)[::-1][:d])
money += tmp_money

print(money)

### FIXED CODE ###

import bisect
import time
import heapq


# N: バイトの種類
# M: 日数の最大
N,M = map(int,input().split(" "))

# A 日数
# b バイト代
A = []
B = []
for _ in range(N):
    a,b = map(int,input().split(" "))
    A.append(a)
    B.append(-b)

# 日数でソート
ind_sorted = sorted(range(N), key = lambda x:A[x])
tmp_a = 0
tmp_b_ls = [0]
money = 0
tmp_ind = 0
for i in range(N):
    if A[ind_sorted[i]] > M:
        break
    if tmp_a != A[ind_sorted[i]]:
        # 空いている日数
        # print(d)
        # print(tmp_b_ls)
        d = A[ind_sorted[i]]-tmp_a
        for _ in range(d):
            if tmp_b_ls == []:
                break
            money -= heapq.heappop(tmp_b_ls)
        tmp_a = A[ind_sorted[i]]
    heapq.heappush(tmp_b_ls,B[ind_sorted[i]])

d = M+1-tmp_a
# print(d)
# print(tmp_b_ls)

for _ in range(d):
    if tmp_b_ls == []:
        break
    money -= heapq.heappop(tmp_b_ls)
print(money)
### BUGGY CODE ###

A=input()
a=int(A)
n1=0
n2=1
for i in range(a):
    for x in range(a):
        if n2 <= a:
            n1=(i+2)**(x+2)
            if n2 <= n1 and n1 <= a:
                n2 = n1
                #print(n2)
                n1
print(n2)

### FIXED CODE ###

A=input()
a=int(A)
b=round(a*(1/2))
n2=1
for i in range(2,b):
    for x in range(2,b):
        if n2 <= a:
            n1=(i)**(x)
            if n2 <= n1 and n1 <= a:
                n2 = n1
                #print(n2)
                n1
print(n2)
### BUGGY CODE ###

n = int(input())
s = []
ans = 0
for i in range(n):
    prize = input()
    if prize in s:
        continue
    else:
        s.append(prize)
        ans += 1
print(ans)

### FIXED CODE ###

n = int(input())
s = set()
for i in range(n):
    s.add(input())
print(len(s))
### BUGGY CODE ###

L,R = map(int,input().split())

ilist = list()
a=2*10**9
for i in range(R+1)[L:]:
  imod = i % 2019
  if imod in ilist:
    continue
  ilist.append(imod)
  for j in range(R+1)[i+1:]:
    jmod = j % 2019
    m = (imod * jmod) % 2019
    a = min(a,m)

print(a)

### FIXED CODE ###

L,R = map(int,input().split())

ilist = list()
a=2*10**9
for i in range(R+1)[L:L+2020]:
  imod = i % 2019
  if imod in ilist:
    continue
  ilist.append(imod)
  for j in range(R+1)[i+1:i+1+2020]:
    jmod = j % 2019
    m = (imod * jmod) % 2019
    a = min(a,m)

print(a)
### BUGGY CODE ###

N = int(input())

#for i in range(N+1):
    

def L(i):
    if i == 0:
        return 2
    if i == 1:
        return 1
    else:
        return L(i-1) + L(i-2)

print(L(N))

### FIXED CODE ###

# import functools
N = int(input())

#for i in range(N+1):
# @functools.lru_cache()
# def L(i):
#     if i == 0:
#         return 2
#     if i == 1:
#         return 1
#     else:
#         return L(i-1) + L(i-2)
# print(L(N))


#上はfunctoolを使うもの下がいい

LL = [2,1] # リュカ数保存するリスト

for i in range(2,N+1):
    LL.append(LL[i-1] + LL[i-2])

print(LL[N])
### BUGGY CODE ###

import numpy as np
N=input()
cnt=0
bit=0
bitflag=0
cur=0
inf=1001001001
dp=np.zeros((1000005,2)) #dp[N][2]
dp=dp.tolist()
Nd="".join(("0",N))
#print(Nd)
for i in range(0,len(Nd)+1,1):
    for j in range(2):
        dp[i][j]=inf
dp[0][0]=0
for i in range(0,len(Nd),1):
    for j in range(2):
        x=int(Nd[len(Nd)-1-i])
        #print(x)
        x=x+j
        for a in range(0,10,1):
            ni=i+1
            nj=0
            b=a-x
            if b<0:
                nj=1
                b=b+10
            dp[ni][nj]=min(dp[ni][nj],dp[i][j]+a+b)

print(dp[len(Nd)][0])






### FIXED CODE ###


N=input()
cnt=0
bit=0
bitflag=0
cur=0
inf=float("inf")

Nd="".join(("0",N))


dp=[[inf for _ in range(2)] for _ in range(1000005)]
dp[0][0]=0
#print(dp)
for i in range(0,len(Nd),1):
    for j in range(2):
        x=int(Nd[len(Nd)-1-i])
        #print(x)
        x=x+j
        for a in range(0,10,1):
            ni=i+1
            nj=0
            b=a-x
            if b<0:
                nj=1
                b=b+10
            dp[ni][nj]=min(dp[ni][nj],dp[i][j]+a+b)

print(dp[len(Nd)][0])
### BUGGY CODE ###

n,x=map(int,input().split())

lv1='BPPPB'
temp='BPPPB'
cnt=1
while cnt<n:
    temp='B'+lv1+'P'+lv1+'B'
    cnt+=1
    lv1=temp

count=0
for i in temp:
    x-=1
    if i=='P':
        count+=1

    if x==0:
        print(count)

### FIXED CODE ###

n,x=map(int,input().split())

#レベルNの層とパティの数を求める
a,p=[1],[1]
for i in range(n):
    a.append(2*a[i]+3)
    p.append(2*p[i]+1)

def cnt(n,x):
    #レベルNのバーガーのX層までに含まれるパティを数える
    if n==0:
        return 1 if x>=1 else 0

    elif x<=1+a[n-1]:
        return cnt(n-1,x-1)

    elif 2+a[n-1]<=x:
        return cnt(n-1,x-(a[n-1]+2))+p[n-1]+1

print(cnt(n,x))
### BUGGY CODE ###

from collections import Counter
import itertools
a=input()
n=len(a)
delete=int(0)
dup=list(Counter(a).values())
num=list(itertools.combinations(a,2))
count=Counter(a).values()
print((n*(n-1)-sum([i*(i-1) for i in count]))//2 +1)


### FIXED CODE ###

from collections import Counter
import itertools
a=input()
n=len(a)
delete=int(0)
count=Counter(a).values()
print((n*(n-1)-sum([i*(i-1) for i in count]))//2 +1)
### BUGGY CODE ###

import numpy as np
#from numba import njit

n = int(input())
a = np.array([int(input()) for _ in range(n)])
ans = 0
for _ in range(n):
    if set(a) == set([-1,0]) or set(a) == set([0]):
        break
    i = a.argmax()
    if i == 0:
        print(-1)
        exit()
    if a[i-1] + 1 == a[i]:
        a[i] = -1
        ans += 1
    elif a[i-1] == -1:
        a[i-1] = a[i] - 1
        a[i] = -1
        ans += 1
    else:
        print(-1)
        exit()
print(ans)

### FIXED CODE ###

n = int(input())
prev = ans = -1
a = [int(input()) for _ in range(n)]
for i in a:
    if i - prev > 1:
        print(-1)
        exit()
    elif i - prev == 1:
        ans += 1
    else:
        ans += i
    prev = i
print(ans)
### BUGGY CODE ###

import fractions
from functools import reduce
import copy
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

n=int(input())
a=[int(x) for x in input().split()]
tmp=0
for i in range(n):
    gcd=gcd_list(a[1:])
    if gcd>tmp:
        tmp=gcd
    a.append(a.pop(0))
print(tmp)

### FIXED CODE ###

import fractions
from functools import reduce
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

n=int(input())
a=[int(x) for x in input().split()]
l=[0]
r=[0]
for i in range(n):
    l.append(fractions.gcd(l[i],a[i]))
    r.append(fractions.gcd(r[i],a[(i+1)*-1]))
r = r[::-1]
m = []
for i in range(n):
    m.append(fractions.gcd(l[i],r[i+1]))
print(max(m))
### BUGGY CODE ###


def main():
    H, W = map(int, input().split()) # 横に2個
    checked = [[False if a == '.' else True for a in list(input()+'#')] for i in range(H)]
    checked.extend([[True]*(W+1)])
    qs = [[h, w] for h in range(H) for w in range(W) if checked[h][w]]

    c = 0
    for k in range(2000):
        qqs = []
        for h,w in qs:
            checked[h][w] = True
            if not checked[h-1][w]:
                qqs.append([h-1, w])
            if not checked[h+1][w]:
                qqs.append([h+1, w])
            if not checked[h][w-1]:
                qqs.append([h, w-1])
            if not checked[h][w+1]:
                qqs.append([h, w+1])
        if not qqs:
            break
        c += 1
        qs = qqs

    print(c)

if __name__=='__main__':
    main()

### FIXED CODE ###

import sys
input = sys.stdin.readline

B = int(1E8)

def main():

    H, W = map(int, input().split())
    
    l = 0
    q = []
    checked = []
    for h in range(H):
        S = input()
        L = []
        for w in range(W):
            if S[w] == '#':
                l += 1
                L.append(True)
                q.append(B*h+w)
            else:
                L.append(False)
        checked.append(L)

    Next = [[[] for _ in range(W)] for _ in range(H)]
    for h in range(H):
        for w in range(W):
            if h != 0:
                Next[h][w].append(B*(h-1) + w)
            if h != H-1:
                Next[h][w].append(B*(h+1) + w)
            if w != 0:
                Next[h][w].append(B*h + w-1)
            if w != W-1:
                Next[h][w].append(B*h + w+1)

    c = -1
    for _ in range(H+W+2):
        qq = []
        if len(q) == 0:
            break
        for hw in q:
            h, w = hw//B, hw%B
            for nhw in Next[h][w]:
                nh, nw = nhw//B, nhw%B
                if not checked[nh][nw]:
                    qq.append(B*nh + nw)
                    checked[nh][nw] = True
        q = qq
        c += 1

    print(c)


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

import fractions
from functools import reduce


def main():

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

    maxd = 1
    for n in range(N):
        l = A[:n] + A[n+1:]
        maxd = max(maxd, gcd(*l))

    print(maxd)    


def gcd(*numbers):
    return reduce(fractions.gcd, numbers)


main()


### FIXED CODE ###

import fractions
from functools import reduce


def main():

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

    gcds_r = [1] * N
    gcds_r[0] = A[0]
    for n in range(1, N):
        gcds_r[n] = fractions.gcd(gcds_r[n-1], A[n])

    gcds_l = [1] * N
    gcds_l[-1] = A[-1]
    for n in range(N-1)[::-1]:
        gcds_l[n] = fractions.gcd(gcds_l[n+1], A[n])

    max_gcd = 1
    for n in range(1, N-1):
        max_gcd = max(max_gcd, fractions.gcd(gcds_r[n-1], gcds_l[n+1]))

    max_gcd = max(max_gcd, gcds_l[1], gcds_r[N-2])

    print(max_gcd)  


main()
### BUGGY CODE ###

import math

n, k = map(int, input().split(' '))
l = map(int, input().split(' '))
pos = []
neg = []

for i in l:
	if i >= 0:
		pos.append(i)
	else:
		neg.append(i)

p = 0
n = 0
pos = sorted(pos)[::-1]
neg = sorted(neg)

answer = []
placeholder = -1

if k % 2 == 1:
	if len(pos) > 0:
		placeholder = pos.pop()
	else:
		placeholder = -2
		neg = neg[::-1]
	k -= 1

len_pos = len(pos)
len_neg = len(neg)
pos.append(0)
pos.append(0)
neg.append(0)
neg.append(0)

for i in range(k//2):
	if pos[p+0] * pos[p+1] >= neg[n+0] * neg[n+1]:
		answer.append(pos[p+0])
		answer.append(pos[p+1])
		p += 2
		p = min(p, len_pos)

	else:
		answer.append(neg[n+0])
		answer.append(neg[n+1])
		n += 2
		n = min(n, len_neg)

if placeholder == -2:
	answer.append(neg[n])
elif placeholder != -1:
	answer.append(max(placeholder, pos[p]))

s = 1
for i in answer:
	s *= i
print(s % 1000000007)

### FIXED CODE ###

n, k = map(int, input().split(' '))
l = map(int, input().split(' '))

s = 1
if n == k:
	for i in l:
		s *= i
		s %= 1000000007
	print(s)
else:
	pos = []
	neg = []

	for i in l:
		if i >= 0:
			pos.append(i)
		else:
			neg.append(i)

	pos.sort()
	neg.sort(reverse=True)
	answer = []

	if k % 2 == 1 and not pos:
		for i in range(k):
			s *= neg[i]
			s %= 1000000007
		print(s)

	else:
		if k % 2 == 1:
			s = pos.pop()
		for i in range(k//2):
			if len(pos) >= 2:
				answer.append(pos.pop()*pos.pop())
			else:
				break
		for i in range(k//2):
			if len(neg) >= 2:
				answer.append(neg.pop()*neg.pop())
			else:
				break
		answer.sort(reverse=True)
		for i in range(k//2):
			s *= answer[i]
			s %= 1000000007
		print(s)
### BUGGY CODE ###

l = raw_input().split()
s = l[0]

def get_removals(s):
    ret = []
    for i in range(len(s) - 1):
        if int(s[i]) + int(s[i + 1]) == 1:
            ret.append(i)
    return ret

def remove(s, index):
    if index == 0:
        return s[2:]
    if index == (len(s) - 1):
        return s[:index-1]
    return  s[0:index] + s[index + 2:]

num_removals = []

def process(s, count):
    removals = get_removals(s)
    if len(removals) == 0:
        num_removals.append(count)
        return
    count += 2
    max_removes = []
    for removal in removals:
        s1 = remove(s, removal)
        max_removes.append(len(get_removals(s1)))
    max_remove = max(max_removes)
    for removal in removals:
        s1 = remove(s, removal)
        if len(get_removals(s1)) == max_remove:
            process(s1, count)

process(s, 0)
print(max(num_removals))


### FIXED CODE ###

l = raw_input().split()
s = l[0]

def get_removals(s):
    ret = []
    for i in range(len(s) - 1):
        if int(s[i]) + int(s[i + 1]) == 1:
            ret.append(i)
    return ret

def remove(s, index):
    if index == 0:
        return s[2:]
    if index == (len(s) - 1):
        return s[:index-1]
    return  s[0:index] + s[index + 2:]

num_removals = []

ones = 0
zeros = 0
for num in s:
    if num == '0':
        ones += 1
    if num == '1':
        zeros += 1
max_candidate = min(ones, zeros) * 2

def process(s, count):
    removals = get_removals(s)
    if len(removals) == 0:
        num_removals.append(count)
        if count == max_candidate:
            print(max_candidate)
            exit()
        return
    count += 2
    max_remove = 0
    ss = []
    for removal in removals:
        s1 = remove(s, removal)
        ss.append(s1)
        num_removes = len(get_removals(s1))
        if max_remove < num_removes:
            max_remove = num_removes
    for s1 in set(ss):
        if len(get_removals(s1)) == max_remove:
            process(s1, count)

# process(s, 0)
print(max_candidate)
### BUGGY CODE ###

n = int(input())
c = str(input())
cn = [False]*n
for i in range(n):
    if c[i]=="R":
        cn[i]= True


ans = 0
k=n-1
b=0

for i in range(n):
    if b==1:
        break

    if cn[i]== False:
        for j in range(k,0,-1):

            if cn[j]==True:
                k =j-1
                if i < j:
                    #cn[i]=True
                    #cn[j]=False
                    ans +=1
                    break
                elif i>=j:
                    b=1
                    break
print(ans)

### FIXED CODE ###

n = int(input())
c = str(input())
cn = [False]*n
for i in range(n):
    if c[i]=="R":
        cn[i]= True


ans = 0
k=n-1
b=0

for i in range(n):
    if b==1:
        break

    if not(cn[i]):
        for j in range(k,0,-1):

            if cn[j]:
                k =j-1
                if i < j:
                    #cn[i]=True
                    #cn[j]=False
                    ans +=1
                    break
            if i>=j:
                b=1
                break
print(ans)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import sys

def main():
	N, K = map(int, input().split(" "))
	H = input().split(" ")
	H = [int(s) for s in H]
	
	DP = [-1 for _ in range(N)]
	DP[0] = 0
	
	for i in range(1, len(H)):
		for j in range(1, K+1):
			if i - j >= 0:
				tmp = abs(H[i] - H[i-j]) + DP[i-j]
				if DP[i] == -1 or DP[i] > tmp:
					DP[i] = tmp
			else:
				break
		
	print(DP[N-1])
		
if __name__ == "__main__":
	main()
	

### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys

def main():
	N, K = map(int, input().split(" "))
	H = input().split(" ")
	H = [int(s) for s in H]
	
	DP = [-1 for _ in range(N)]
	DP[0] = 0
	
	for i in range(1, len(H)):
		paths = [DP[j] + abs(H[j] - H[i]) for j in range(max(0, i-K), i)]
		DP[i] = min(paths)
		
	print(DP[N-1])
		
if __name__ == "__main__":
	main()
### BUGGY CODE ###

N = int(input())
a = list( map(int, input().split() ) )
kai = 1
M = 10**9+7
result = 0
for i in range(1,N):
    kai *= i

for i in range(N-1):
    result += ((kai//(i+1))%M) * (a[N-1] - a[i])

print( result%M )

### FIXED CODE ###

N = int(input())
d = list( map(int, input().split() ) )
kai = 1
mod = 10**9+7
result = 0

def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

for i in range(1,N):
    kai = (kai%mod)*i

for i in range(N-1):    
    result += ( kai * (d[N-1] - d[i]) * modinv(i+1) ) % mod 

print( result%mod )
### BUGGY CODE ###

# -*- coding: utf-8 -*-
"""
Created on Sun Feb 24 16:22:35 2019
 
@author: Owner
"""
import numpy as np
 
N, K = map(int, input().split())

h = list(map(int, input().split()))
 
dp = []
 
for n in range(N):
    if n == 0:
        dp.append(0)
    else:
        temp = np.inf
        for k in range(1,K+1):
            if n-k >= 0:
                temp = min(temp, dp[n-k] + abs(h[n]-h[n-k]))
            else:
                break
        dp.append(temp)
    #print(dp)
print(dp[N-1])

### FIXED CODE ###

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

import numpy as np

N, K = map(int, input().split())
 
h = np.array(list(map(int, input().split())))
 
dp = np.zeros(N)
 
for n in range(1, N):
    k = min(K, n)
    temp = np.min(dp[n-k:n] + np.abs(h[n]-h[n-k:n]))
    dp[n] = temp
print(int(dp[-1]))
### BUGGY CODE ###

cnt = [0] * int(2 * 10e5 + 10)
li = [[] for _ in range(int(2 * 10e5 + 10))]
def f(a):
    global cnt, li
    for c in li[a]:
        cnt[c] += cnt[a]
        f(c)
def solve():
    global cnt, li
    n, q = map(int, input().split())
    for _ in range(n - 1):
        a, b = map(int, input().split())
        li[a].append(b)
    for _ in range(q):
        p, x = map(int, input().split())
        cnt[p] += x
    f(1)
    print(*cnt[1 : n + 1])
solve()


### FIXED CODE ###

def solve():
    cnt = [0] * int(2 * 1e5 + 10)
    li = []
    n, q = map(int, input().split())
    for _ in range(n - 1):
        a, b = map(int, input().split())
        li.append((a, b))
    for _ in range(q):
        p, x = map(int, input().split())
        cnt[p] += x
    for a, b in sorted(li):
        cnt[b] += cnt[a]
    print(*cnt[1 : n + 1])
solve()
### BUGGY CODE ###

def main():
    n = int(input())
    s = input()
    if n < 4:
        print(0)
        return
    ans = 0

    for i, si in enumerate(s[:-2]):
        for j, sj in enumerate(s[i+1:-1]):
            if si == sj:
                continue
            for k, sk in enumerate(s[i+j+2:]):
                if j == k:
                    continue
                if si != sk != sj:
                    ans += 1

    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    n = int(input())
    s = input()
    if n < 4:
        print(0)
        return
    ans = s.count("R") * s.count("G") * s.count("B")

    for i, si in enumerate(s[:-2]):
        for j, sj in enumerate(s[i+1:-1]):
            if si == sj:
                continue

            if i + 2*j+2 < n and si != s[i + 2*j+2] != sj:
                ans -= 1

    print(ans)


if __name__ == '__main__':
    main()