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

N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        s = L[i]+L[j]
        for k in range(j+1,N):
            if L[k] >= s:
                break
            ans += 1
print(ans)

### FIXED CODE ###

import bisect as bs
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        s = L[i] + L[j]
        ans += bs.bisect_left(L,s) - j - 1
        # bisect.bisect_left(list, x)
        # はリストにxを挿入できる点を返す
        # すなわち、
        # (val < x for val in list[0:i]) + (val >= x for val in list[i:len(list)])
print(ans)
### BUGGY CODE ###

#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def f(x):
    cnt = 0
    for i in range(n):
        if a[i] == 0:
            if x >= 0:
                cnt += n-i-1
        elif a[i] > 0:
            r =  br(a,x//a[i])
            if r <= i:
                continue
            cnt += r - i - 1
        else:
            l = bl(a,-(x//-a[i]))
            if l <= i:
                l = i+1
            cnt += n - l
    return cnt >= k
n,k = LI()
a = LI()
a.sort()

ok = 10**18+1
ng = -10**18-1
while ok-ng > 1:
    mid = (ok+ng)//2
    if f(mid):
        ok = mid
    else:
        ng = mid
print(ok)



    

### FIXED CODE ###

#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def f(x):
    cnt = 0
    if x < 0:
        j = p-1
        for i in range(m)[::-1]:
            while j >= 0:
                if minus[i]*plus[j] <= x:
                    j -= 1
                else:
                    break
            cnt += p - j - 1
    else:
        j = p-1
        for i in range(p):
            while j >= 0:
                if plus[i]*plus[j] > x:
                    j -= 1
                else:
                    break
            cnt += max(0,j - i)
        j = 0
        for i in range(m)[::-1]:
            while j < m:
                if minus[i]*minus[j] > x:
                    j += 1
                else:
                    break
            cnt += max(0,i - j)
        cnt += (m+p)*zero + zero*(zero-1)//2 + m*p
    return cnt >= k
        
n,k = LI()
a = LI()
a.sort()
minus = [x for x in a if x < 0]
plus = [x for x in a if x > 0]
m = len(minus)
p = len(plus)
zero = bl(a,1) - br(a,-1)
ok = 10**18
ng = -10**18-1
while ok-ng > 1:
    mid = (ok+ng)//2
    if f(mid):
        ok = mid
    else:
        ng = mid
print(ok)
### BUGGY CODE ###

import math
#from functools import reduce
#def gcd(*numbers):
#    return reduce(math.gcd, numbers)
k = int(input())
sum = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        for l in range(1,k+1):
            sum += math.gcd(math.gcd(i,j),l)
print(sum)


### FIXED CODE ###

import math
#from functools import reduce
#def gcd(*numbers):
#    return reduce(math.gcd, numbers)
k = int(input())
sum = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        for l in range(1,k+1):
            sum += math.gcd(math.gcd(i,j),l)
print(sum)
### BUGGY CODE ###

n,q=map(int,input().split())
s=input()
for i in range(q):
    l,r=map(int,input().split())
    sub = s[l-1:r]
    print(sub.count('AC'))

### FIXED CODE ###

n,q=map(int,input().split())
s=input()
t=[0]*(n+1)
for i in range(n):
    t[i+1] = t[i] + (1 if s[i:i+2] == 'AC' else 0)
for i in range(q):
    l,r=map(int,input().split())
    print(t[r-1]-t[l-1])
### BUGGY CODE ###

import math

# xのn乗
def pow_k(x, n):
    """
    O(log n)
    """
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2

    return K * x

# nCkの導出
def comb(n,k):
    nCk = 1
    # X
    for i in range(n-k+1, n+1):
        nCk *= i
        # nCk %= mod

    # Y
    for i in range(1,k+1):
        nCk *= pow(i,mod-2,mod)
        nCk %= mod
    return nCk

n, a, b = map(int, input().split())
mod = 10**9+7

# ans = pow_k(2,n) - c(n,a) - c(n,b) - 1

ans = pow(2,n,mod) - 1 - comb(n,a) - comb(n,b)

print(ans)
# print(ans%mod)

### FIXED CODE ###

import math

# xのn乗
def pow_k(x, n):
    """
    O(log n)
    """
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2

    return K * x

# nCkの導出
def comb(n,k):
    nCk = 1
    # X
    for i in range(n-k+1, n+1):
        nCk *= i
        nCk %= mod

    # Y
    for i in range(1,k+1):
        nCk *= pow(i,mod-2,mod)
        nCk %= mod
    return nCk

n, a, b = map(int, input().split())
mod = 10**9+7

# ans = pow_k(2,n) - c(n,a) - c(n,b) - 1

ans = pow(2,n,mod) - 1 - comb(n,a) - comb(n,b)

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

import copy
n=int(input())
l=[int(input()) for _ in range(n)]


k=sorted(l)
dic_lst={}
for i in l:
  if i not in dic_lst:
    dic_lst[i]=1
  else:
    dic_lst[i]+=1
for i in l:
  max_num=max(dic_lst.keys())
  if i<max_num:
    print(max_num)
  if i==max_num:
    if dic_lst[i]>1:
      print(max_num)
    elif dic_lst[i]==1:
      print(k[-2])


### FIXED CODE ###

n=int(input())
l=[int(input()) for _ in range(n)]
k=sorted(l)

for i in l:
	if i<k[-1]:
		print(k[-1])
	if i==k[-1]:
		print(k[-2])
### BUGGY CODE ###

n = int(input())
A = list(map(int, input().split())) 
q = int(input())

from collections import Counter
a = Counter(A)
x = 0

for _ in range(q):
    b, c = map(int, input().split())
    a[c] += a[b]
    a[b] = 0

    s = sum(item*a[item] for item in a if item!=0)
    # s = 0
    # for i,v in a.items():
    #     if v != 0:
    #         s += i*v
    print(s)

### FIXED CODE ###

n = int(input())
A = list(map(int, input().split())) 
q = int(input())

from collections import Counter
arr = Counter(A)
ans = sum([i*arr[i] for i in arr])
 
for i in range(q):
    b,c = list(map(int,input().split()))
    ans += (c-b)*arr[b]
    arr[c],arr[b] = arr[c]+arr[b],0
    print(ans)
### BUGGY CODE ###

N, C = [int(i) for i in input().split(" ")]
x = [0]
v = [0]
for i in range(N):
    t = [int(i) for i in input().split(" ")]
    x.append(t[0])
    v.append(t[1])
x.append(C)
v.append(0)
    

right_cal = [0 for i in range(N + 2)]
for i in range(1, N + 1):
    right_cal[i] = (v[i] + right_cal[i - 1] - x[i] + x[i - 1])
    
left_cal = [0 for i in range(N + 2)]
for i in range(N, 0, -1):
    left_cal[i] = (v[i] + left_cal[i + 1] - x[i + 1] + x[i])

ans = 0
for i in range(N + 1):
    ans = max(ans, right_cal[i] + max(left_cal[i + 1 : ]) - x[i])
    
ans = max(ans, left_cal[0] + max(right_cal))
for i in range(1, N + 1):
    ans = max(ans, left_cal[i] + max(right_cal[ : i]) - C + x[i])
    
# print(right_cal)
# print(left_cal)
# print(max_cal)
print(ans)

### FIXED CODE ###

x = [0 for i in range(100001)]
v = [0 for i in range(100001)]
v_sum_right = [0 for i in range(100001)]
v_sum_left = [0 for i in range(100001)]
g = [[0, 0] for i in range(100001)]
g2= [0 for i in range(100001)]
N = 0
C = 0
i = 0
ans = 0
t = 0

N, C = [int(i) for i in input().split(" ")]
for i in range(N):
    x[i], v[i] = [int(i) for i in input().split(" ")]


v_sum_right[0] = v[0]
for i in range(1, N):
    v_sum_right[i] = v_sum_right[i - 1] + v[i]

v_sum_left[N] = 0
for i in range(N - 1, -1, -1):
    v_sum_left[i] = v_sum_left[i + 1] + v[i]


# // g計算
g[0][0] = 0
g[0][1] = 0
g2[0] = 0
for i in range(1, N + 1):
    g[i][0] = max(g[i - 1][0], v_sum_right[i - 1] - x[i - 1])
    g2[i] = max(g2[i - 1], v_sum_right[i - 1] - 2 * x[i - 1])
    if g[i - 1][0] == g[i][0]:
        g[i][1] = g[i - 1][1]
    else:
        g[i][1] = x[i - 1]
    
# // 探査
ans = v_sum_left[0] - C + x[0]
for i in range(1, N):
    ans = max(ans, v_sum_left[i] + g[i][0] - 2 * (C +- x[i]), v_sum_left[i] - C + x[i] + g2[i])
ans = max(ans, g[N][0])

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

memo = {}

def gcd(a, b):
    if (a, b) in memo.keys():
        return memo[(a, b)]
    if b == 0:
        return a
    g = gcd(b, a % b)
    memo[(a, b)] = g
    return g

n = input()
a_list = map(int, raw_input().split())
max_g = 0
for exclude in xrange(n):
    g = a_list[0] if exclude > 0 else a_list[1]
    for i, a in enumerate(a_list):
        if i == 0 or i == exclude:
            continue
        g_new = gcd(g, a)
        if (g, a) not in memo:
            memo[(g, a)] = g_new
        g = g_new
        if g <= max_g:
            break
    if g > max_g:
        max_g = g
print(max_g)


### FIXED CODE ###

def gcd(a, b):
    if b == 0:
        return a
    g = gcd(b, a % b)
    return g

n = input()
a_list = map(int, raw_input().split())

gs1 = [None] * n
gs1[0] = a_list[0]
for i in xrange(1, n):
    gs1[i] = gcd(gs1[i - 1], a_list[i])

gs2 = [None] * n
gs2[n - 1] = a_list[n - 1]
for i in reversed(xrange(n - 1)):
    gs2[i] = gcd(gs2[i + 1], a_list[i])

max_g = 0
for exclude in xrange(n):
    if exclude == 0:
        g = gs2[1]
    elif exclude == n - 1:
        g = gs1[n - 2]
    else:
        g = gcd(gs1[exclude - 1], gs2[exclude + 1])
    if g > max_g:
        max_g = g
print(max_g)
### BUGGY CODE ###

N,M=map(int,input().split())
A=list(map(int,input().split()))
num=[0,2,5,5,4,5,6,3,7,6]
dp=[[1,0,0,0,0,0,0,0,0,0]]
tmp=0
tmp1=0
tmp2=0
for i in range(0,N+1):
    dp.append([0,0,0,0,0,0,0,0,0,0])
    tmp=0
    for j in A:
        if(i-num[j]>=0):
            tmp1=dp[i-num[j]].copy()
            #存在しないなら不可
            if(tmp1[0]==0):
                continue
            tmp1[j]+=1
            tmp2=0
            for k in range(1,10):
                if(tmp1[10-k]!=0):
                    tmp2*=(10**tmp1[10-k])
                    tmp2+=(10-k)*int("1"*tmp1[10-k])
            if(tmp2>tmp):
                tmp=tmp2
                dp[i]=tmp1
ans=0
for k in range(1,10):
    if(dp[N][10-k]!=0):
        ans*=10**dp[N][10-k]
        ans+=(10-k)*int("1"*dp[N][10-k])
print(int(ans))

### FIXED CODE ###

N,M=map(int,input().split())
A=list(map(int,input().split()))
if(1 in A):
    if(4 in A):
        A.remove(4)
    if(9 in A):
        A.remove(9)
    if(6 in A):
        A.remove(6)
if(5 in A):
    if(3 in A):
        A.remove(3)
    if(2 in A):
        A.remove(2)
if(3 in A):
    if(2 in A):
        A.remove(2)
if(9 in A):
    if(6 in A):
        A.remove(6)
if(7 in A):
    if(9 in A):
        A.remove(9)
    if(6 in A):
        A.remove(6)
num=[0,2,5,5,4,5,6,3,7,6]
dp=[0]
keta=[0]
tmp=0
tmp1=0
tmp_keta=-1
tmp1_keta=-1
for i in range(1,N+1):
    tmp=-1
    tmp_keta=-1
    for j in A:
        tmp1=-1
        tmp1_keta=-1
        if(i-num[j]>=0):
            if(dp[i-num[j]]>0):
                tmp1=dp[i-num[j]]+j*(10**keta[i-num[j]])
                tmp1_keta=keta[i-num[j]]+1
            elif(dp[i-num[j]]==0):
                tmp1=j
                tmp1_keta=1

            if(tmp1>tmp):
                tmp=tmp1
                tmp_keta=tmp1_keta
                
    dp.append(tmp)
    keta.append(tmp_keta)
print(dp[N])
### BUGGY CODE ###

l = raw_input().split()
#l=input[0].split()

n = int(l[0])
a = [2147483647]*n

for i in range(0,int(l[1])):
	l = raw_input().split()
#	l=input[i+1].split()
	if int(l[0])==0:
		a[int(l[1])]=int(l[2])
	else:
		print min(a[int(l[1]):int(l[2])+1])

### FIXED CODE ###

#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin
 
 
def main(init=int(2**31-1), readline=stdin.readline):
    n, q = (int(s) for s in readline().split())
 
    a = [init] * n
    b = [init] * ((n // 100) + 1)
 
    for _ in range(q):
        com, x, y = (int(s) for s in readline().split())
        if com:
            bx = x - (x % 100) + 100
            by = y - (y % 100)
            if bx < by:
                m = min(min(a[x:bx]), min(b[bx//100:by//100]),
                        min(a[by:y+1]))
            else:
                m = min(a[x:y+1])
            print(m)
        else:
            a[x] = y
            bx = x - (x % 100)
            b[x//100] = min(a[bx:bx+100])
 
 
main()
### BUGGY CODE ###

def make_divisors(n):
    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)

    divisors.sort()
    return divisors

nu=int(input())
total=0
for p in range(1,nu):
    num=nu-p
    total+=len(make_divisors(num))
print(total)

### FIXED CODE ###

import collections

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a



nu=int(input())
total=0
for p in range(1,nu):
    s=collections.Counter(prime_factorize(p))
    sama=1
    for j in s.values():
        sama=sama*(j+1)
    total+=sama
print(total)
### BUGGY CODE ###


url = "https://atcoder.jp//contests/abc113/tasks/abc113_c"

def main():
    t = list(map(int, input().split()))
    town = {k: [] for k in range(1, t[0]+1)}
    all_town = []
    for _ in range(t[1]):
        tmp = list(map(int, input().split()))
        all_town.append(tmp)
        town[tmp[0]].append(tmp[1])
    for k in town:
        town[k].sort()
    for row in all_town:
        print(str(row[0]).zfill(6) + str(town[row[0]].index(row[1])+1).zfill(6))


if __name__ == '__main__':
    main()


### FIXED CODE ###


url = "https://atcoder.jp//contests/abc113/tasks/abc113_c"

def main():
    t = list(map(int, input().split()))
    town = {k: [] for k in range(1, t[0]+1)}
    all_town = []
    for _ in range(t[1]):
        tmp = list(map(int, input().split()))
        all_town.append(tmp)
        town[tmp[0]].append(tmp[1])
    ans = {}
    for k in town:
        town[k].sort()
        tmp_dic = {town[k][i]: str(k).zfill(6)+str(i+1).zfill(6) for i in range(len(town[k]))}
        ans.update(tmp_dic)
    for at in all_town:
        print(ans[at[1]])


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

N = int(input())
A = list(map(int,input().split()))
Q = int(input())
l=[]
for _ in range(Q):
    l.append(list(map(int,input().split())))
for i in range(Q):
    if l[i][0] in A:
        index_num = [n for n, v in enumerate(A) if v == l[i][0]]
        for j in index_num:
            A[j]=l[i][1]
    print(sum(A))


### FIXED CODE ###

import collections
N = int(input())
A = list(map(int,input().split()))
Q = int(input())
l=[]
for _ in range(Q):
    l.append(list(map(int,input().split())))
c = collections.Counter(A)
sum=sum(A)
for i in range(Q):
    if c[l[i][0]] == 0:
        print(sum)
        continue
    else:
        sum+=c[l[i][0]]*(l[i][1]-l[i][0])
        c[l[i][1]]+=c[l[i][0]]
        del c[l[i][0]]
        print(sum)
### BUGGY CODE ###

import sys
input = lambda: sys.stdin.readline().rstrip()

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

sushi = [[] for _ in range(N)]

for i in range(N):
    a,b = map(int, input().split())
    a -= 1
    sushi[a].append(b)

first = []
second = []
for a in sushi:
    if a:
        sort_a = sorted(a, reverse=True)
        flg = 1
        for num in sort_a:
            if flg:
                first.append((num, 1))
                flg = 0
            else:
                second.append((num, 0))
first.sort(reverse=True)                
second.sort(reverse=True)                

i = 0
j = 0
ans = 0

for i in range(len(first)):
    sum_first = 0
    sum_second = 0
    cnt = 0
    if i > K-1:
        break
    for j in range(i+1):
        sum_first += first[j][0]
        cnt += 1
    for k in range(K-i-1):
        if k > len(second) - 1:
            break
        sum_second += second[k][0]
  
    ans = max(ans, sum_first + sum_second + cnt*cnt)

print(ans)

### FIXED CODE ###

import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import defaultdict
from itertools import accumulate

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

sushi = defaultdict(list)

for i in range(N):
    a,b = map(int, input().split())
    sushi[a].append(b)

first = []
second = []

for nums in sushi.values():
    nums.sort(reverse=True)
    for i, j in enumerate(nums):
        if i == 0:
            first.append(j)
        else:
            second.append(j)
first.sort(reverse=True)
second.sort(reverse=True)

first_cum = [0] + list(accumulate(first))
second_cum = [0] + list(accumulate(second))

ans = 0

for i in range(K, 0, -1):
    neta = min(i, len(first))
    tmp = neta * neta + first_cum[neta]

    if K - neta > len(second):
        break
    
    tmp += second_cum[K - neta]

    ans = max(ans, tmp)

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

import collections

N, K = map(int, input().split())
A = list(map(int, input().split()))
A = dict(collections.Counter(A))

cnt = 0

while len(A) > K:
    min_k = min(A, key=A.get)
    cnt += A[min_k]
    A.pop(min_k)

print(cnt)


### FIXED CODE ###

import collections

N, K = map(int, input().split())
A = list(map(int, input().split()))
A = dict(collections.Counter(A))
A = sorted(A.items(), key=lambda x: x[1], reverse=True)

cnt = 0

for i in range(N):
    if len(A) > K:
        cnt += A[-1][1]
        A.pop()
    else:
        break

print(cnt)
### BUGGY CODE ###

import bisect

n = int(input())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
c = sorted(list(map(int, input().split())))
a_n = [0] * n
b_n = [0] * n
for i in range(n):
    a_n[i] = bisect.bisect_right(b, a[i])
for i in range(n):
    b_n[i] = n - bisect.bisect_right(c, b[i])
ans = 0
for i in a_n:
    ans += sum(b_n[i:])
print(ans)

### FIXED CODE ###

import bisect

n = int(input())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
c = sorted(list(map(int, input().split())))
a_n = [0] * n
b_n = [0] * n
for i in range(n):
    a_n[i] = bisect.bisect_right(b, a[i])
for i in range(n):
    b_n[i] = n - bisect.bisect_right(c, b[i])
ans = 0
b_n_t = [0]
for i in range(n):
    b_n_t.append(b_n[i] + b_n_t[i])
for i in a_n:
    ans += b_n_t[-1] - b_n_t[i]
print(ans)
### BUGGY CODE ###

n,q = map(int,input().split())
s = input()
for i in range(q):
    x,y = map(int,input().split())
    print(s[x-1:y].count("AC"))
    

### FIXED CODE ###

N,Q=map(int,input().split())
S=input()
count=[0]*N
for i in range(1,N):
    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 itertools

N = int(input())
red = [tuple(map(int, input().split())) for i in range(N)]
blue = [tuple(map(int, input().split())) for i in range(N)]

res = 0
for _blue in itertools.permutations(blue):
    sum_pair = len([1 for (a, b), (c, d) in zip(red, _blue) if a < c and b < d])
    res = max(res, sum_pair)
print(res)

### FIXED CODE ###


N = int(input())
red = [list(map(int, input().split())) for i in range(N)]
blue = [list(map(int, input().split())) for i in range(N)]

red.sort(key=lambda x:x[1], reverse=True)
blue.sort()

c = 0
for bx, by in blue:
    for i, (rx, ry) in enumerate(red):
        if rx<bx and ry<by:
            c += 1
            red.pop(i)
            break

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

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

ans = 0

for i in range(n - 1):
    for j in range(i + 1, n):
        ans += a[i] * a[j]

ans = ans % (10 ** 9 + 7)

print(ans)

### FIXED CODE ###

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

sum_a = sum(a)

ans = 0

for i in range(n - 1):
    sum_a -= a[i]
    ans += a[i] * sum_a

ans = ans % (10 ** 9 + 7)

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

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

### FIXED CODE ###

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

N = int(input().strip())
S = input().strip()

csum = {
  'R': [0]*(N+1),
  'G': [0]*(N+1),
  'B': [0]*(N+1)
}
for i, c in enumerate(S):
  for k in csum.keys():
    csum[k][i+1] = csum[k][i]
  csum[c][i+1] += 1

ans = 0
for j in range(1, N-1):
  for i in range(j):
    if S[i] == S[j]: continue
    s = set('RGB') - {S[i], S[j]}
    s = s.pop()
    diff = j-i
    cand = csum[s][-1] - csum[s][j]
    if j+diff < N and S[j+diff] == s: cand -= 1
    ans += cand
    
print(ans)

### FIXED CODE ###

N = int(input().strip())
S = input().strip()

csum = {
  'R': [0]*(N+1),
  'G': [0]*(N+1),
  'B': [0]*(N+1)
}
for i, c in enumerate(S):
  for k in csum.keys():
    csum[k][i+1] = csum[k][i]
  csum[c][i+1] += 1

ans = 0
for j in range(1, N-1):
  for i in range(j):
    if S[i] == S[j]: continue
    s = set('RGB') - {S[i], S[j]}
    s = s.pop()
    diff = j-i
    cand = csum[s][-1] - csum[s][j]
    if j+diff < N and S[j+diff] == s: cand -= 1
    ans += cand
    
print(ans)
### BUGGY CODE ###

def main():
    import bisect
    import array
    B=bisect.bisect_left
    I=10**9+1
    n,q,*t=map(int,open(0).read().split())
    d=tuple(t[-q:])
    t=tuple(t[:-q])
    N0=2**(q-1).bit_length()
    data=array.array('I',[I]*2*N0)
    for x,l,r in sorted(((x,B(d,s-x)+N0,B(d,t-x)+N0)for s,t,x in zip(t[::3],t[1::3],t[2::3])),reverse=1):
        while l<r:
            if r&1:
                r-=1
                data[r-1]=x
            if l&1:
                data[l-1]=x
                l+=1
            l>>=1
            r>>=1
    for k in range(N0-1,q+N0-1):
        s=I
        while~k:
            if data[k]<s:s=data[k]
            k=(k-1)//2
        print(-(s==I)or s)
if __name__=='__main__':
    main()

### FIXED CODE ###

def main():
    from bisect import bisect_left
    def update(l,r,v):
        L,R=l+N0,r+N0
        while L<R:
            if R&1:
                R-=1
                data[R-1]=v
            if L&1:
                data[L-1]=v
                L+=1
            L>>=1
            R>>=1
    def query(k):
        k+=N0-1
        s=10**18
        while k+1:
            if data[k]<s:s=data[k]
            k=~-k//2
        return s
    n,*t=open(0)
    n,q=map(int,n.split())
    d=[-10**18]+list(map(int,t[n:]))+[10**18]
    N0=2**(q+1).bit_length()
    data=[10**18]*2*N0
    for x,t,s in sorted(list(map(int,t.split()))[::-1]for t in t[:n])[::-1]:
        l=bisect_left(d,s-x)
        r=bisect_left(d,t-x)
        update(l,r,x)
    for i in range(q):
        a=query(i+1)
        print(-(a==10**18)or a)
if __name__=='__main__':
    main()
### BUGGY CODE ###

N = int(input())
a = [int(input()) for i in range(N)]
for i in range(len(a)):
  b = a.copy()
  del b[i]
  print((max(b)))

### FIXED CODE ###

N = int(input())
a = [int(input()) for i in range(N)]
amax = max(a)
amax2 = sorted(a)[-2]
for i in range(len(a)):
  if a[i]==amax:
    print(amax2)
  else:
    print(amax)