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

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


a.sort(reverse=True)
cnt = a.pop(0)
for i in range(n-2):
    if i % 2 == 0:
        cnt += a[0]
    else:
        cnt += a.pop(0)

print(cnt)

### FIXED CODE ###

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


a.sort(reverse=True)
cnt = a.pop(0)
if (n-2) % 2 == 0:
    tmp = 2 * sum(a[0:(n-2)//2])
else:
    tmp = 2 * sum(a[0:(n-2)//2]) + a[(n-2)//2]
cnt += tmp
print(cnt)
### BUGGY CODE ###

import bisect

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

a.sort()
b.sort()
c.sort()

count = 0
for i in a:
  for j in range(bisect.bisect(b, i), len(b)):
    count += len(b) - bisect.bisect(c, b[j])
print(count)


### FIXED CODE ###

import bisect

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

a.sort()
b.sort()
c.sort()

count = 0
for i in b:
  count += bisect.bisect_left(a, i) * (len(c) - bisect.bisect(c, i))
print(count)
### BUGGY CODE ###

BIG = (10 ** 9) + 7

f_list = [1] * 200000
f_r_list = [1] * 200000

for i in range(199999):
	f_list[i + 1] = int((f_list[i] * (i + 2)) % BIG)

def power(n, x):
	if x == 1:
		return n
	elif x % 2 == 0:
		return power(int((n * n) % BIG), int(x / 2))
	else:
		return int((n * power(n, x - 1)) % BIG)

for i in range(200000):
	f_r_list[i] = power(f_list[i], BIG - 2)

def comb(n, r):
	if n == 0 or r == 0 or n == r:
		return 1
	else:
		return (((f_list[n - 1] * f_r_list[n - r - 1]) % BIG) * f_r_list[r - 1]) % BIG 

h, w, a, b = map(int, input().split())

ans = 0

for i in range(h - a):
	ans = int((ans + int((comb(b + i - 1, b - 1) * comb(h + w - b - i - 2, w - b - 1)) % BIG)) % BIG)

print(int(ans))

### FIXED CODE ###

BIG = (10 ** 9) + 7

f_list = [1] * 200000
f_r_list = [1] * 200000

for i in range(199999):
	f_list[i + 1] = int((f_list[i] * (i + 2)) % BIG)

def power(n, x):
	if x == 1:
		return n
	elif x % 2 == 0:
		return power(int((n * n) % BIG), int(x / 2))
	else:
		return int((n * power(n, x - 1)) % BIG)

f_r_list[-1] = power(f_list[-1], BIG - 2)

for i in range(2, 200001):
	f_r_list[-i] = int((f_r_list[-i + 1] * (200002 - i)) % BIG)

def comb(n, r):
	if n == 0 or r == 0 or n == r:
		return 1
	else:
		return (((f_list[n - 1] * f_r_list[n - r - 1]) % BIG) * f_r_list[r - 1]) % BIG 

h, w, a, b = map(int, input().split())

ans = 0

for i in range(h - a):
	ans = int((ans + int((comb(b + i - 1, b - 1) * comb(h + w - b - i - 2, w - b - 1)) % BIG)) % BIG)

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

N, M = map(int, input().split())
price = list(map(int, input().split()))
for i in range(M):
  price[price.index(max(price))] = int(price[price.index(max(price))] / 2)
print(sum(price))

### FIXED CODE ###

from heapq import heappop, heappush

N, M = map(int, input().split())
price = list(map(int, input().split()))
he = []
for i in price:
  heappush(he, -i)
for i in range(M):
  max = heappop(he)
  heappush(he, -(-max//2))
print(-sum(he))
### BUGGY CODE ###

N,K,Q=map(int,input().split())
A=[int(input()) for _ in range(Q)]

p=[K]*N

for a in A:
    p = list(map(lambda x:x-1, p))
    p[a-1]+=1
for i in p:
    print('Yes' if 0<i else 'No')

### FIXED CODE ###

N,K,Q=map(int,input().split())
A=[0]*N
for _ in range(Q):
    A[int(input())-1]+=1
p=[K-Q]*N

for a,b in zip(A,p):
    print('Yes' if 0<a+b else 'No')
### BUGGY CODE ###

n=int(input())
d=list(map(int,input().split()))
dd=sorted(d)
N=dd[n-1]
sum1=0
sum2=0
count=0
for k in range(N+1):
    for i in range(n):
        if d[i]>=k:
            sum1+=1
    if sum1==n-sum1:
        count+=1
    sum1=0
    sum2=0
print(count)

### FIXED CODE ###

n=int(input())
d=list(map(int,input().split()))
dd=sorted(d)
N=dd[int((n/2))]-dd[int((n/2)-1)]
print(N)
### BUGGY CODE ###

#13:12
n,q = map(int,input().split())
import heapq
import sys
input = sys.stdin.readline
event = []
for _ in range(n):
  s,t,x = map(int,input().split())
  heapq.heappush(event,[s-x,t-x,x])
t = 0
now = []
for _ in range(q):
  d = int(input())
  if event:
    while event[0][0] <= d:
      tmp = heapq.heappop(event)
      heapq.heappush(now,[tmp[2],tmp[1]])
      if not event:
        break
  if now:
    while now[0][1] <= d:
      heapq.heappop(now)
      if not now:
        print(-1)
        break
    else:
      print(now[0][0])
  else:
    print(-1)

### FIXED CODE ###

#13:12
n,q = map(int,input().split())
import heapq
import sys
input = sys.stdin.readline
event = []
for _ in range(n):
  s,t,x = map(int,input().split())
  heapq.heappush(event,(s-x,t-x,x))
t = 0
now = []
for _ in range(q):
  d = int(input())
  if event:
    while event[0][0] <= d:
      tmp = heapq.heappop(event)
      heapq.heappush(now,(tmp[2],tmp[1]))
      if not event:
        break
  if now:
    while now[0][1] <= d:
      heapq.heappop(now)
      if not now:
        print(-1)
        break
    else:
      print(now[0][0])
  else:
    print(-1)
### BUGGY CODE ###

n=int(input())
s=[input() for _ in range(n)]
a=set(s)
c=[]
d=0
for i in a:
    b=s.count(i)
    c.append([i,b])
    d=max(d,b)
e=[]
for i in range(len(c)):
    if c[i][1]==d:
        e.append(c[i][0])
e=sorted(e)
for i in range(len(e)):
    print(e[i])

### FIXED CODE ###

n=int(input())
a={}
for i in range(n):
    key=input()
    if key in a:
        a[key]+=1
    else:
        a[key]=1
b=max(list(a.values()))
c=[]
for k,v in a.items():
    if v==b:
        c.append(k)
c=sorted(c)
for i in range(len(c)):
    print(c[i])
### BUGGY CODE ###

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

for i in a:
    ans *= i

if (ans > 1000000000000000000):
        ans = -1

print(ans)

### FIXED CODE ###

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

for i in a:
    ans *= i

    if (ans > 1000000000000000000):
        ans = -1
        break

if(0 in a): print(0)
else: print(ans)
### BUGGY CODE ###

A, B, K = map(int, input().split())

a = [i for i in range(A,B+1)]
if B-A+1 <= 2*K:
    for ans in a:
        print(ans)
else:
    for ans in a[:K]:
        print(ans)
    for ans in a[-K:]:
        print(ans)


### FIXED CODE ###

A, B, K = map(int, input().split())

if B-A+1 <= 2*K:
    for ans in range(A,B+1):
        print(ans)
else:
    for ans in range(A, A+K):
        print(ans)
    for ans in range(B-K+1, B+1):
        print(ans)
### BUGGY CODE ###

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        self.sizes = [1] * (n+1)
        self.root = [1] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.root[x] = -1
            self.sizes[y] += self.sizes[x]
        else:
            self.par[y] = x
            self.root[y] = -1
            self.sizes[x] += self.sizes[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
        

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)
    
    def size(self, x):
        return self.sizes[find(x)]
    

n, m = map(int, input().split())
lst = [list(map(int, input().split())) for _ in range(m)]

all_comb = n*(n-1)/2

a = UnionFind(n)

ans = [all_comb]
for pair in reversed(lst):
    if a.same_check(pair[0], pair[1]):
        pass
    else:
        a.union(pair[0], pair[1])
    count = 0
    for i in range(n+1):
        if a.root[i] == 1:
            size = a.sizes[i]
            count += size * (size-1) / 2
    ans.append(all_comb - count)
    
for i in reversed(ans[:-1]):
    print(int(i))

### FIXED CODE ###

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        self.sizes = [1] * (n+1)
        self.root = [1] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.root[x] = -1
            self.sizes[y] += self.sizes[x]
        else:
            self.par[y] = x
            self.root[y] = -1
            self.sizes[x] += self.sizes[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
        

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)
    
    def size(self, x):
        return self.sizes[find(x)]
    

n, m = map(int, input().split())
lst = [list(map(int, input().split())) for _ in range(m)]

all_comb = n*(n-1)/2

a = UnionFind(n)

ans = [all_comb]
for pair in reversed(lst):
    if a.same_check(pair[0], pair[1]):
        ans.append(ans[-1])
        pass
    else:
        ans.append(ans[-1] - a.sizes[a.find(pair[0])]*a.sizes[a.find(pair[1])])
        a.union(pair[0], pair[1])
    
for i in reversed(ans[:-1]):
    print(int(i))
### BUGGY CODE ###

N = int(input())
As = list(sorted(list(map(int, input().split()))))

result = 0
stored = []
while len(As)!=0:
    item = As[-1]
    As = As[:-1]
    is_exist = False
    if item in stored:
        continue
    for A in As:
        if item%A==0:
            is_exist = True
            break
    if not is_exist:
        result+=1
    stored.append(item)
print(result)


### FIXED CODE ###

N = int(input())
As = list(sorted(list(map(int, input().split()))))

max_num = max(As)
tfs = [0 for _ in range(max_num+1)]

for A in As:
    if tfs[A] != 0:
        tfs[A] = 2
        continue
    for j in range(A, max_num+1, A):
        tfs[j]+=1

result = 0
for A in As:
    if tfs[A] == 1:
        result+=1
print(result)
### BUGGY CODE ###

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

B=[0]*N
for i in range(N):
    B[i]=A[i]+i
C=[]
for i in range(N):
    if i-A[i]>0:
        C.append(i-A[i])

ans=0
for i in B:
    ans+=C.count(i)
print(ans)

### FIXED CODE ###

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

d={}
for i in range(N):
    if i-A[i]>0:
        if str(i-A[i]) in d:
            d[str(i-A[i])]+=1
        else:
            d[str(i-A[i])]=1

ans=0
for j in range(N):
    if str(j+A[j]) in d:
        ans+=d[str(j+A[j])]
print(ans)
### BUGGY CODE ###

K = int(input())
count = len(str(K))
n = 0
for i in range(count):
    n += 7*10**i
while True:
    if K % 2 == 0:
        count = -1
        break
    if n % K == 0:
        break
    n += 7*10**count
    count += 1
print(count)

### FIXED CODE ###

K = int(input())
count = 1
n = 0
if K % 2 == 0 or K % 5 == 0:
    count = -1
    print(count)
else:
    while True:
        n = (n*10+7)%K
        if n == 0:
            break
        count += 1
    print(count)
### BUGGY CODE ###

k, s = map(int, input().split())

count = 0
if int(s / 3) == 0:
    for x in range(s + 1):
        for y in range(s + 1):
            for z in range(s + 1):
                if x + y + z == s:
                    count += 1
else:
    for x in range(max(k, int(s / 3) + 1)):
        for y in range(max(k, int(s / 3) + 1)):
            for z in range(max(k, int(s / 3) + 1)):
                if x + y + z == s:
                    count += 1

print(count)

### FIXED CODE ###

k, s = map(int, input().split())

count = 0
for x in range(k + 1):
    for y in range(k + 1):
        if 0 <= s - x - y and s - x - y <= k:
            count += 1

print(count)
### BUGGY CODE ###

n,k=map(int,input().split())
a=[int(i) for i in input().split()]
d=[0 for i in range(n)]
c=1
k=min(k,40)


while c<=k:
    b=list(d)
    e=float("inf")
    for i in range(n):
        l=max(0,i-a[i])
        r=min(n-1,i+a[i])
        b[l]+=1
        if r+1<n:
            b[r+1]-=1
    for i in range(1,n):
        b[i]+=b[i-1]
        e=max(e,b[i-1])
    c+=1
    a=b
    if e==n:
        break
print(" ".join(map(str,a)))

### FIXED CODE ###

n,k=map(int,input().split())
a=[int(i) for i in input().split()]
k=min(k,41)

for j in range(k):
    b=[0 for i in range(n)]
    for i in range(n):
        l=max(0,i-a[i])
        r=min(n-1,i+a[i])
        b[l]+=1
        if r+1<n:
            b[r+1]-=1
    for i in range(1,n):
      b[i]+=b[i-1]
    a=b
print(" ".join(map(str,a)))
### BUGGY CODE ###

def main():
    s = input()
    for _ in range(int(input())):
        temp = input().split()
        if temp[0] == "1":
            s = s[::-1]
        else:
            if temp[1] == "1":
                s = temp[2] + s
            elif temp[1] == "2":
                s = s + temp[2]
    print(s)

main()

### FIXED CODE ###

from collections import deque

def main():

    s = deque(input())
    q = int(input())

    flag = 0
    query = []

    for _ in range(q):
        temp = input().split()
        if len(temp) == 1:
            flag += 1
        else:
            query.append(temp + [flag%2])

    for q in query:
        if q[-1] == 0:
            if q[1] == "1":
                s.appendleft(q[2])
            else:
                s.append(q[2])
        else:
            if q[1] == "1":
                s.append(q[2])
            else:
                s.appendleft(q[2])

    if flag % 2 == 1:
        print("".join(list(s)[::-1]))
    else:
        print("".join(s))

main()
### BUGGY CODE ###

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

def main():
    n,k = LI()
    a = [I() - k for _ in range(n)]
    t = []
    ti = 0
    r = 0
    for c in a:
        if c >= 0:
            r += 1
        bi = bisect.bisect_left(t,-c - ti)
        ti += c
        r += len(t) - bi
        bisect.insort_left(t,c-ti)

    return r



print(main())


### FIXED CODE ###

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
gosa = 1.0 / 10**10
mod = 10**9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

class Seg():
    def __init__(self, n, default, func):
        i = 1
        while 2**i <= n:
            i += 1
        self.D = default
        self.H = i
        self.N = 2**i
        self.A = [default] * (self.N*2-1)
        self.F = func

    def find(self, i):
        return self.A[i + self.N - 1]

    def update(self, i, x):
        i += self.N - 1
        self.A[i] = x
        while i > 0:
            i = (i-1) // 2
            self.A[i] = self.merge(self.A[i*2+1], self.A[i*2+2])

    def merge(self, a, b):
        return self.F(a, b)

    def total(self):
        return self.A[0]

    def query(self, a, b):
        def _query(k,l,r):
            if r <= a or b <= l:
                return self.D
            if a <= l and r <= b:
                return self.A[k]
            m = (l+r)//2
            vl = _query(k*2+1,l,m)
            vr = _query(k*2+2,m,r)
            return self.merge(vl,vr)
        return _query(0,0,self.N)

def main():
    n,k = LI()
    a = [I() for _ in range(n)]

    b = [0]
    for i in range(n):
        b.append(b[-1] + a[i] - k)

    d = {}
    for c,i in zip(sorted(set(b)), range(n+1)):
        d[c] = i
    e = [d[c] for c in b]

    l = len(d)

    def f(a,b):
        return a+b

    seg = Seg(l, 0, f)
    for c in e:
        seg.update(c, seg.find(c) + 1)

    r = 0
    for c in e[::-1]:
        t = seg.query(0,c+1)
        r += t-1
        seg.update(c, seg.find(c) - 1)

    return r

print(main())
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
M=0
X=[]
for i in range(N-1,-1,-1):
  _=0
  for j in range(i+1,N+1,i+1):
    if j in X:
      _+=1
  if A[i]==0 and _%2==1:
    M+=1
    X.append(i+1)
  elif A[i]==1 and _%2==0:
    M+=1
    X.append(i+1)
print(M)
print(*X)

### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
M=0
X=[]
XX=[0]*N
for i in range(N-1,-1,-1):
  _=0
  for j in range(i+1,N+1,i+1):
    _+=XX[j-1]
  if A[i]==0 and _%2==1:
    M+=1
    X.append(i+1)
    XX[i]=1
  elif A[i]==1 and _%2==0:
    M+=1
    X.append(i+1)
    XX[i]=1
print(M)
print(*X)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10 ** 6)

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

graph = [[] for _ in range(n + 1)]

for i in range(m):
    f, t = map(int, input().split())
    graph[t].append(f)

dp = [None] * (n + 1)
def dfs(now):
    if dp[now] is not None:
        return dp[now]

    if not graph[now]:
        return 0

    r = max(dfs(parent) for parent in graph[now]) + 1
    dp[now] = r
    return r

print(max(dfs(i) for i in range(1, n + 1)))


### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 6)

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

graph = [[] for _ in range(n + 1)]

for i in range(m):
    f, t = map(int, input().split())
    graph[t].append(f)

dp = [-1] * (n + 1)
def dfs(now):
    if dp[now] != -1:
        return dp[now]

    if not graph[now]:
        return 0

    r = max(dfs(parent) for parent in graph[now]) + 1
    dp[now] = r
    return r

print(max(dfs(i) for i in range(1, n + 1)))
### BUGGY CODE ###

N, K = [int(_) for _ in input().split()]
H = [int(_) for _ in input().split()]

for k in range(K):
    max_H = 0
    for i in H:
        if max_H < i:
            max_H = i
    if len(H) > 0:
        H.remove(max_H)

attack = 0
for i in H:
    attack += i

print(attack)


### FIXED CODE ###

N, K = [int(_) for _ in input().split()]
H = [int(_) for _ in input().split()]
H.sort(reverse=True)
print(sum(H[K:]))
### BUGGY CODE ###

import sys
def input():
  return sys.stdin.readline()[:-1]
h, n = map(int, input().split())
a=[0]*n
b=[0]*n
for i in range(n):
  a[i], b[i] = map(int, input().split())

dp = [float('inf')]*(h+max(a))
dp[0] = 0 
for i in range(1, h+max(a)):
  for j in range(n):
    dp[i] = min(dp[i], dp[i-a[j]]+b[j])
print(min(dp[h:]))

### FIXED CODE ###

import sys
def input():
  return sys.stdin.readline()[:-1]
h, n = map(int, input().split())
a=[0]*n
b=[0]*n
for i in range(n):
  a[i], b[i] = map(int, input().split())

dp = [float('inf')]*(h+max(a))
dp[0] = 0 
for i in range(1, h+max(a)):
  for j in range(n):
    dp[i] = min(dp[i], dp[i-a[j]]+b[j])
print(min(dp[h:]))
### BUGGY CODE ###

a=int(input())
moji=input()
r=[]
g=[]
b=[]
for i in range(a):
    if moji[i]=="R":
        r.append(i)
    elif moji[i]=="G":
        g.append(i)
    elif moji[i]=="B":
        b.append(i)
res=len(r)*len(g)*len(b)
if len(r)==0 or len(g)==0 or len(b)==0:
    print(0)
else:
    # min_len={len(r):r,len(g):g,len(b):b}
    # tmp=list(min_len.keys()).sort()
    for i in (r):
        for j in g:
            if -abs(i-j)+min(i,j) in b:
                res-=1
            if abs(i-j)+max(i,j) in b:
                res-=1
            if abs(i-j)%2==0 and  int(abs(i-j)/2)+min(i,j) in b:
                res-=1
    print(res)

### FIXED CODE ###

a=int(input())
moji=input()
r=[]
g=[]
b=[]
for i in range(a):
    if moji[i]=="R":
        r.append(i)
    elif moji[i]=="G":
        g.append(i)
    else:
        b.append(i)
res=len(r)*len(g)*len(b)
if len(r)==0 or len(g)==0 or len(b)==0:
    print(0)
else:
    for i in range(0,a-2):
      for j in range(i+1,a-1):
        if 2*j-i<a and moji[i]!=moji[j] and moji[j]!=moji[2*j-i] and moji[2*j-i]!=moji[i]:
          res-=1
    print(res)
### BUGGY CODE ###

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

N = int(input())
nums = [str(i) for i in range(1, N+1)]
heads = [s[0] for s in nums]
tails = [s[-1] for s in nums]

count = 0
for A in range(N):
    for B in range(A, N):
        if heads[A] == tails[B] and tails[A] == heads[B]:
            if A == B:
                count += 1
            else:
                count += 2

print(count)


### FIXED CODE ###

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

# input
N = int(input())

# create and init dictionary
heads_and_tails = {}
for head in range(1, 10):
    for tail in range(1, 10):
        heads_and_tails[(head, tail)] = 0

# create dictionary contents
for num in range(1, N+1):
    if num%10 == 0:
        continue
    head = int(str(num)[0])
    tail = int(str(num)[-1])
    heads_and_tails[(head, tail)] +=1

# count
count = 0
for head in range(1, 10):
    for tail in range(1, 10):
        count += heads_and_tails[(head, tail)] * heads_and_tails[(tail, head)]

print(count)
### BUGGY CODE ###

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

ans=1
for i in a_list:
  ans=ans*i

if ans>10**18:
  ans=-1
print(ans)


### FIXED CODE ###

n= int(input())
a_list = list(map(int, input().split()))
 
a_list = [n for n in a_list if n!=1]  
#print(a_list)
ans=1

if 0 in a_list:
  ans=0
elif len(a_list)>56:
  ans=-1
else:
  for i in a_list:
    ans=ans*i
  if ans>1000000000000000000:
      ans=-1
  
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

N, A, B, = map(int, input().split())
L = [int(input()) for _ in range(N)]

L.sort()

ans = (L[-1] // B) + 1

def f(n):
    c = n
    for v in L:
        if v > n * B:
            v -= n * B
            t = v // (A - B)
            if v % (A - B) != 0:
                t += 1
            c -= t
    return c >= 0

first = 1
for _ in range(50):
    t = (first + ans) // 2
    if f(t):
        ans = t
    else:
        first = t

print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline

N, A, B, = map(int, input().split())
L = [int(input()) for _ in range(N)]

L.sort()

ans = (L[-1] // B) + 1

def f(n):
    c = n
    for v in L:
        if v > n * B:
            v -= n * B
            t = v // (A - B)
            if v % (A - B) != 0:
                t += 1
            c -= t
    return c >= 0

first = 1
for _ in range(40):
    t = (first + ans) // 2
    if f(t):
        ans = t
    else:
        first = t

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

n = int(input())
nums = [input() for i in range(n)]
m = max(nums)
m2 = sorted(nums)[-2]

[print(m) if nums.count(m) >=2 or nums[i] != m else print(m2) for i in range(n)]

### FIXED CODE ###

n = int(input())
nums = [int(input()) for i in range(n)]
m = max(nums)
m2 = sorted(nums)[-2]
[print(m) if nums[i] != m else print(m2) for i in range(n)]
### BUGGY CODE ###

def resolve():
    n,k,q=map(int, input().split())
    l=[int(input()) for i in range(q)]
    for i in range(1,n+1):
        if k-(q-l.count(i))<=0:
            print('No')
        else:
            print('Yes')
resolve()

### FIXED CODE ###

def resolve():
    n,k,q=map(int, input().split())
    l=[int(input()) for i in range(q)]
    a=[k-q for i in range(n)]
    for i in l:
        a[i-1]+=1
    for i in range(n):
        if a[i]<=0:
            print('No')
        else:
            print('Yes')
resolve()
### BUGGY CODE ###

import sys
input = sys.stdin.readline

def main():

    n = int(input())
    s = input()

    r = s.count("R")
    g = s.count("G")
    b = s.count("B")

    ans = r*g*b

    for i in range(n):
        for j in range(n):
            if i + j*2 < n:
                if s[i] != s[i + j] and s[i] != s[i + j*2] and s[i + j] != s[i + j*2]:
                    ans -= 1
    print(ans)

main()

### FIXED CODE ###

n = int(input())
s = input()

r = s.count("R")
g = s.count("G")
b = s.count("B")

comb = r*g*b

for i in range(1, n - 1):
    for j in range(2, n):
        if i < j:
            if (2*j - i) <= n:
                if s[i - 1] != s[j - 1]:
                    if s[i - 1] != s[2*j - i - 1]:
                        if s[j - 1] != s[2*j - i - 1]:
                            comb -= 1

print(comb)