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

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

'''A1だけ別個で計算する'''
tmp = 0
for j in range(0, N, 2):
    tmp += A[j]
for k in range(1, N, 2):
    tmp -= A[k]
R.append(tmp)

'''A2~AN'''
for i in range(1, N):
    tmp = 0
    pm = -1
    for j in range(i-1-N, -N-1, -1):  # A[i-1]より手前側
        pm *= -1
        tmp += A[j] * pm
    pm = -1
    for k in range(i, N):  # A[i]より後ろ側
        pm *= -1
        tmp += A[k] * pm
    R.append(tmp)

print(*R)


### FIXED CODE ###

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

'''プラススタート、マイナススタートの累積和を取る'''
plus_start = []
minus_start = []
'''後ろからの累積和'''
plus_start_rev = []
minus_start_rev = []

tmp = 0
pm = -1
for i in range(N):
    pm *= -1
    tmp += A[i] * pm
    plus_start.append(tmp)
tmp = 0
pm = -1
for i in range(-1, -N-1, -1):
    pm *= -1
    tmp += A[i] * pm
    plus_start_rev.append(tmp)

tmp = 0
pm = 1
for i in range(N):
    pm *= -1
    tmp += A[i] * pm
    minus_start.append(tmp)

tmp = 0
pm = 1
for i in range(-1, -N-1, -1):
    pm *= -1
    tmp += A[i] * pm
    minus_start_rev.append(tmp)

'''各山の降水量を計算する'''
for i in range(N):
    if i == 0:
        tmp = plus_start[-1]
        R.append(tmp)
        continue
    if i % 2 == 0:
        tmp = minus_start[i-1] + plus_start_rev[N-i-1]
    else:
        tmp = plus_start[i-1] + minus_start_rev[N-i-1]
    R.append(tmp)

print(*R)
### BUGGY CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
seiseki = []

for i in range(N - K + 1):
  num = 1
  for j in range(K):
    num *= A[i + j]
  seiseki.append(num)
  if i > 0:
    if seiseki[-2] < seiseki[-1]:
      print("Yes")
    else:
      print("No")

### FIXED CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
seiseki = []

for i in range(N - K):
  if A[i] < A[i + K]:
    print("Yes")
  else:
    print("No")
### BUGGY CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
from collections import deque
 
N,Q = map(int,readline().split())
ki = []
for i in range(N-1):
    ki.append(list(map(int,readline().split())))
co = []
for i in range(Q):
    co.append(list(map(int,readline().split())))
 
ki.sort(key=lambda x: x[0])
 
#print(ki)
 
kid = deque(ki)
#print(kid)
 
ver = []
for i in range(N):
    ver.append([0,False])
 
for i in range(Q):
    ver[co[i][0]-1][0] += co[i][1]
 
ver[0][1] = True
#print(ver)
 
 
while len(kid) != 0:
    k = kid.popleft()
    if ver[k[0]-1][1] == True:
        ver[k[1]-1][0] += ver[k[0]-1][0]
        ver[k[1]-1][1] = True
    elif ver[k[1]-1][1] == True:
        ver[k[0]-1][0] += ver[k[1]-1][0]
        ver[k[0]-1][1] = True
    else:
        kid.append(k)
 
for i in range(N):
    print(ver[i][0],end=' ')

### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from collections import deque

N,Q = map(int,readline().split())
ki = []
for i in range(N-1):
    ki.append(list(map(int,readline().split())))
co = []
for i in range(Q):
    co.append(list(map(int,readline().split())))
 
ki.sort(key=lambda x: x[1])

kid = deque(ki)
ver = []
check = []
for i in range(N):
    ver.append(0)
    check.append(False)
 
for c in co:
    ver[c[0]-1] += c[1]

check[0] = True

kid2 = deque()

while len(kid) != 0:
    k = kid.popleft()
    if check[k[0]-1] == True:
        ver[k[1]-1] += ver[k[0]-1]
        check[k[1]-1] = True
    elif check[k[1]-1] == True:
        ver[k[0]-1] += ver[k[1]-1]
        check[k[0]-1] = True
    else:
        kid2.append(k)

while len(kid2) != 0:
    k = kid2.pop()
    if check[k[0]-1] == True:
        ver[k[1]-1] += ver[k[0]-1]
        check[k[1]-1] = True
    elif check[k[1]-1] == True:
        ver[k[0]-1] += ver[k[1]-1]
        check[k[0]-1] = True
    else:
        kid2.appendleft(k)


print(' '.join(map(str,ver)))
### BUGGY CODE ###

from collections import deque

H, W = map(int, input().split())
maze = [list(input()) for _ in range(H)]


def bfs(x, y):
    visited, queue = [], deque([(x, y, 0)])
    max_cost = 0
    while queue:
        px, py, cost = queue.popleft()
        max_cost = max(max_cost, cost)

        candidate = ((px + 1, py), (px - 1, py), (px, py + 1), (px, py - 1))
        visited.append((px, py))
        for cx, cy in candidate:
            if not (0 <= cx < W and 0 <= cy < H):
                continue
            if (cx, cy) in visited:
                continue
            if maze[cy][cx] == "#":
                continue
            queue.append((cx, cy, cost + 1))
    return max_cost


ans = 0
for y in range(H):
    for x in range(W):
        if maze[y][x] == "#":
            continue
        ans = max(ans, bfs(x, y))

print(ans)

### FIXED CODE ###

H, W = map(int, input().split())
m = [list(input()) for _ in range(H)]
inf = 10**3

V = H*W
maze = [[inf]*V for _ in range(V)]

for i in range(V):
    maze[i][i] = 0

for py in range(H):
    for px in range(W):
        if m[py][px] == "#":
            continue
        candidate = [(px+1, py), (px-1, py), (px, py+1), (px, py-1)]
        for x, y in candidate:
            if not (0<=x<W and 0<=y<H):continue
            if m[y][x] == "#":
                continue
            maze[W*py+px][W*y+x] = 1

for k in range(V):
    for i in range(V):
        for j in range(V):
            maze[i][j] = min(maze[i][j], maze[i][k]+maze[k][j])

print(max([j for i in maze for j in i if j!=inf]))
### BUGGY CODE ###

N = int(input())

numbers = list(map(int, input().split()))

# max_x = max(numbers) + 1
# max_x = int(sum(numbers) / len(numbers))
res = []
test = set()
for n in numbers:
    test.add(n)
    test.add(n - 1)
    test.add(n + 1)

# for i in range(max_x + 1):
for i in test:
    c = 0
    for n in numbers:
        if n - 1 == i or n == i or n + 1 == i:
            c += 1
    res.append(c)

print(max(res))

### FIXED CODE ###

N = int(input())

numbers = list(map(int, input().split()))

# max_x = max(numbers) + 1
# max_x = int(sum(numbers) / len(numbers))
# res = 0
test = set()
for n in numbers:
    test.add(n)
    test.add(n - 1)
    test.add(n + 1)
length = len(test)
res = {}
# print(test)
# for i in range(max_x + 1):
for n in numbers:
    c = 0
    sub = set([n - 1, n, n + 1]) & test
    # print(sub)
    for s in sub:
        if res.get(s) is None:
            res[s] = 1
        else:
            res[s] += 1
# for i in test:
#     c = 0
#     for n in numbers:
#         if n - 1 == i or n == i or n + 1 == i:
#             c += 1
#     if res < c:
#         res = c

# print(res)
res = max(res.values())
print(res)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
import bisect

def main():
    n = int(input())
    A = list(map(int, input().split()))
    T = [[] for _ in range(n)]
    for _ in range(n-1):
        u, v = map(int, input().split())
        u -= 1
        v -= 1
        T[u].append(v)
        T[v].append(u)
    L = [0]*n
    INF = 2**31 - 1
    def dfs(v, par, B):
        B[bisect.bisect_left(B, A[v])] = A[v]
        L[v] = bisect.bisect_left(B, INF)
        for nv in T[v]:
            if nv != par:
                dfs(nv, v, B.copy())
    dfs(0, -1, [INF]*n)
    print(*L, sep="\n")

if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
import bisect
INF = 2**31 - 1

n = int(input())
A = list(map(int, input().split()))
T = [[] for _ in range(n)]
for _ in range(n-1):
  u, v = map(int, input().split())
  u -= 1
  v -= 1
  T[u].append(v)
  T[v].append(u)
stack = []
L = [INF]*n
ans = [0]*n
def dfs(v, par=-1):
  a = A[v]
  idx = bisect.bisect_left(L, a)
  stack.append((idx, L[idx]))
  L[idx] = a
  ans[v] = bisect.bisect_left(L, INF)
  for nv in T[v]:
    if nv != par:
      dfs(nv, v)
  b, c = stack.pop()
  L[b] = c
dfs(0)
print(*ans, sep="\n")
### BUGGY CODE ###

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

ans = 0
a_book = 0
min = 0

for i in range(n+1):
    book = a_book
    now = min

    for j in range(m+1):
        if now > k:
            ans = max(ans,book-1)
            break

        if j == m:
            ans = max(ans, book)
            break

        now += b[j]
        book += 1

    if min > k or i == n:
        break
    a_book += 1
    min += a[i]


print(ans)


### FIXED CODE ###

n,m,k = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

a = [0]
b = [0]

for i in range(n):
    a.append(A[i] + a[-1])
for i in range(m):
    b.append(B[i] + b[-1])

best = 0
ans = 0

for i in range(n+1):
    if a[i] > k:
        break
    for j in range(best,m+1):
       min = a[i] + b[j]
       if min > k:
           book = i + j - 1
           ans = max(book,ans)
           best = j - 1
           break

       if j == m:
           book = i + j
           ans = max(book, ans)
           best = j - 1
           break


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

from  collections import deque
N,M,K=list(map(int,input().split()))
AB=[list(map(int,input().split())) for i in range(M)]
CD=[list(map(int,input().split())) for i in range(K)]

user=[0 for i in range(N+1)]
graph_ab=[[] for i in range(N+1)]
graph_cd=[[] for i in range(N+1)]
visit_list=[[] for i in range(N+1)]
for i in range(M):
    a,b=AB[i]
    graph_ab[a].append(b)
    graph_ab[b].append(a)

for j in range(1,N+1):
    stack=deque([j])
    visited=[-1 for i in range(N+1)]
    visited[j]=0
    while stack:
        x=stack.popleft()
        for i in graph_ab[x]:
            if visited[i]<0:
                visited[i]=1
                stack.append(i)
    visit_list[j]=visited
    
for i in range(K):
    c,d=CD[i]
    if visit_list[c][d]==1:
        graph_cd[c].append(d)
        graph_cd[d].append(c)

for i in range(1,N+1):
    user[i]=visit_list[i].count(1)-len(graph_ab[i])-len(graph_cd[i])

del user[0]
print(*user)

### FIXED CODE ###

from  collections import deque,Counter
N,M,K=list(map(int,input().split()))
AB=[list(map(int,input().split())) for i in range(M)]
CD=[list(map(int,input().split())) for i in range(K)]

user=[0 for i in range(N+1)]
graph_ab=[[] for i in range(N+1)]
graph_cd=[[] for i in range(N+1)]
visited=[0 for i in range(N+1)]
for i in range(M):
    a,b=AB[i]
    graph_ab[a].append(b)
    graph_ab[b].append(a)
time=0
for j in range(1,N+1):
    if visited[j]==0:
        stack=deque([j])
        time+=1
        visited[j]=time
        while stack:
            x=stack.popleft()
            for i in graph_ab[x]:
                if visited[i]==0:
                    visited[i]=time
                    stack.append(i)
#     visit_list[j]=visited
counter=Counter(visited) 
for i in range(K):
    c,d=CD[i]
    if visited[c]==visited[d]:
        graph_cd[c].append(d)
        graph_cd[d].append(c)

for i in range(1,N+1):
    user[i]=counter[visited[i]]-len(graph_ab[i])-len(graph_cd[i])-1

del user[0]
print(*user)
### BUGGY CODE ###

from functools import reduce


def factorial(end, start=1):
    return reduce(lambda f, i: f * i, list(range(start, end + 1)), 1)


def combination(n, r):
    return factorial(n) // (factorial(r) * factorial(n - r))


N = int(input())


dp = {}
result = 0

for _ in range(N):
    s = ''.join(sorted(input()))
    if s in dp:
        dp[s] += 1
    else:
        dp[s] = 1

print(reduce(lambda r, key: r + combination(dp[key], 2), dp, 0))


### FIXED CODE ###

from functools import reduce

N = int(input())
dp = {}
result = 0

for _ in range(N):
    s = ''.join(sorted(input()))
    if s in dp:
        dp[s] += 1
    else:
        dp[s] = 1

print(reduce(lambda r, key: r + dp[key] * (dp[key] - 1) // 2, dp, 0))
### BUGGY CODE ###

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

for i in range(M):
  makks = max(A)
  if makks == 0:
    break
  A.remove(max(A))
  A.append(makks // 2)
S = 0
for j in range(len(A)):
  S += A[j]
print(S)

### FIXED CODE ###

import heapq
pq = []

N, M = map(int, input().split())
A = list(map(int, input().split()))
for i in A:
  heapq.heappush(pq, -i)
for i in range(M):
  x = pq[0]
  heapq.heappop(pq)
  heapq.heappush(pq, -((-x)//2))
print(-sum(pq))
### BUGGY CODE ###

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

import sys
import math
def setwise_coprime(a):
  ans=a[0]
  for i in range(1,n):
    ans=math.gcd(ans,a[i])
  return ans

def erast(n):
  num_set=set()
  prime_set=set()
  for i in range(2,n+1):
    if i not in num_set:
      prime_set.add(i)
      for j in range(i*i,n+1,i):
        num_set.add(j)
  s=prime_set
  return s

def is_prime(n):
  if n==1:
    return False
  if n==2:
    return True
  else:
    for i in range(2,int(math.sqrt(n))+1):
      if n%i==0:
        return False
    return True
  
check=set()


if setwise_coprime(a)==1:
  s=erast(1000)
  for i in range(n):
    if is_prime(a[i]):
      s.add(a[i])
  s=list(s)  
  s.sort()
  for i in range(n):
    if a[i]!=1:
      for j in range(len(s)):
        if a[i]%s[j]==0:
          if s[j] in check:
            print("setwise coprime")
            sys.exit()
          else:
            check.add(s[j])
            
  print("pairwise coprime")    
else:
  print("not coprime")
  
  



      
      
    


### FIXED CODE ###

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

import sys
import math
def setwise_coprime(a):
  ans=a[0]
  for i in range(1,n):
    ans=math.gcd(ans,a[i])
  return ans

#エラストテネスのふるい
def create_sieve(n):
  sieve=[0]*(n+1)
  for i in range(2,n+1):
    if sieve[i]==0:
      for j in range(i*i,n+1,i):
        sieve[j]=i
  return sieve

#高速素因数分解
def fast_factorization(n, sieve):
  prime={}
  while n>1:
    p=sieve[n]
    #nが素数の場合
    if p==0:
      prime[n]=prime.get(n,0)+1
      break
    #nが素数ではない場合
    else:
      prime[p]=prime.get(p,0)+1
      n=n//p
  return prime

check=set()
if setwise_coprime(a)==1:
  #素因数のダブリをcheck
  sieve=create_sieve(10**6)
  for i in range(n):
    if a[i]!=1:
      s=fast_factorization(a[i], sieve)
      for i in s:
        if i in check:
          print("setwise coprime")
          sys.exit()
        else:
          check.add(i)
  print("pairwise coprime")    
else:
  print("not coprime")
### BUGGY CODE ###

# coding: utf-8
# Your code here!
N,Q = map(int,input().split())
tree = {}
px = []
counter = [0 for _ in range(N)]
for _ in range(N-1):
    a,b = map(int,input().split())
    if a in tree:
        tree[a] |= {b}
    else:
        tree[a] = {b}
    if b in tree:
        tree[b] |= {a}
    else:
        tree[b] = {a}
for _ in range(Q):
    ip,ix = map(int,input().split())
    px.append([ip,ix])


oya = [1]

while oya:
    oyai = oya.pop(0)
    for ko in tree[oyai]:
        tree[ko].remove(oyai)
        oya.append(ko)


for pi,xi in px:
    oya = [pi]
    
    while oya:
        oyai = oya.pop(0)
        counter[oyai-1] +=xi
        for ko in tree[oyai]:
            oya.append(ko)  
print(' '.join(map(str,counter)))


### FIXED CODE ###

# coding: utf-8
# Your code here!
from collections import deque
N,Q = map(int,input().split())
tree = {}
px = []
counter = [0 for _ in range(N)]
for _ in range(N-1):
    a,b = map(int,input().split())
    if a in tree:
        tree[a].append(b)
    else:
        tree[a] = [b]
    if b in tree:
        tree[b].append(a)
    else:
        tree[b] = [a]
for _ in range(Q):
    ip,ix = map(int,input().split())
    counter[ip-1] += ix


oya = deque([1])

while oya:
    oyai = oya.popleft()
    for ko in tree[oyai]:
        tree[ko].remove(oyai)
        counter[ko-1] += counter[oyai-1]
        oya.append(ko)




print(' '.join(map(str,counter)))
### BUGGY CODE ###

N=int(input())
ans=0
for i in range(1,1+N):
    m=N-N%i
    n=N//i
    ans+=(i+m)*n//2
print(ans)

### FIXED CODE ###

N=int(input())
ans=0
for i in range(1,1+N):
    m=N-N%i
    n=N//i
    ans+=(i+m)*n//2
print(ans)
### BUGGY CODE ###

from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)

N, K = list(map(int, input().split()))
a = [0] + list(map(int, input().split()))
mod = 10**9+7

dp = [[0]*(K+1) for i in range(N+1)]
dp[0][0] = 1

for i in range(1,N+1):
    for k in range(K+1):
        s = list(itertools.accumulate(dp[i-1]))
        m = max(0, k-a[i])
        if m > 0:
            dp[i][k] = ((s[k] % mod) - (s[m-1] % mod)) % mod
        else:
            dp[i][k] = s[k] % mod

print(dp[N][K] % mod)



### FIXED CODE ###

from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)

N, K = list(map(int, input().split()))
a = [0] + list(map(int, input().split()))
mod = 10**9+7

dp = [[0]*(K+1) for i in range(N+1)]
dp[0][0] = 1

for i in range(1,N+1):
    s = list(itertools.accumulate(dp[i - 1]))
    for k in range(K+1):
        m = max(0, k-a[i])
        if m > 0:
            dp[i][k] = ((s[k] % mod) - (s[m-1] % mod)) % mod
        else:
            dp[i][k] = s[k] % mod

print(dp[N][K] % mod)
### BUGGY CODE ###

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

### FIXED CODE ###

N = int(input())
power = 1
for i in range(1,N+1):
    power *= i
    if power >= 10**9 + 7:
        power %= 10**9 + 7
print(power % (10**9 + 7))
### BUGGY CODE ###

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A = [0]*(n+1)
B = [0]*(m+1)
cnt  =0

for i in range(1,n+1):
    A[i] = A[i-1] + a[i-1]
for i in range(1,m+1):
    B[i] = B[i-1] + b[i-1]

for i in range(n+1):
    for j in range(m+1):
        if A[i] + B[j] <= k:
            cnt = max(i+j, cnt)

print(cnt)

### FIXED CODE ###

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A = [0]*(n+1)
B = [0]*(m+1)
cnt  =0

for i in range(1,n+1):
    A[i] = A[i-1] + a[i-1]
for i in range(1,m+1):
    B[i] = B[i-1] + b[i-1]

j = m
for i in range(n+1):
    if A[i] > k:
        break
    while B[j] + A[i] > k:
        j -= 1
    cnt = max(cnt, i + j)

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

import numpy as np

N = int(input())
A = list(map(int,input().split()))
a = np.array([],dtype = int)

ans = 0
for i in range(N-1):
    a = np.append(a,1-A[i])
    a = np.sort(a)
    ans += np.count_nonzero(a==A[i+1])
    a = a + 1

print(ans)

### FIXED CODE ###

import collections

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

L = [A[x]+x+1 for x in range(N)]
R = [x+1-A[x] for x in range(N)]

cL = collections.Counter(L)
cR = collections.Counter(R)

cRlist = list(cR.keys())

for i in range(len(cRlist)):
    tmp = cRlist[i]
    ans += cR.get(tmp,0) * cL.get(tmp,0)
    
print(ans)
### BUGGY CODE ###

# 解説放送を見た
# https://youtu.be/9MphwmIsO7Q?t=5738

def main():
    mod = 10 ** 9 + 7

    n = int(input())
    *c, = map(int, input().split())

    c.sort()

    pw = [1 << j for j in range(n + 1)]

    ret = 0
    for l, x in enumerate(c):
        r = n - 1 - l  # lxr
        ret = (ret + x * pw[l] * (pw[r] + pw[r - 1] * r)) % mod

    ret = ret * pw[n] % mod

    print(ret)


if __name__ == '__main__':
    main()


### FIXED CODE ###

# 解説放送を見た
# https://youtu.be/9MphwmIsO7Q?t=5738

def main():
    mod = 10 ** 9 + 7

    n = int(input())
    *c, = map(int, input().split())

    c.sort()

    pw = [1]
    t = 1
    for _ in range(n):
        t = t * 2 % mod
        pw.append(t)

    ret = 0
    for l, x in enumerate(c):
        r = n - 1 - l  # lxr
        ret = (ret + x * pw[l] * (pw[r] + pw[r - 1] * r)) % mod

    ret = ret * pw[n] % mod

    print(ret)


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


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

ans = 0

r = []
if s[0] == "R":
    r.append(1)
else:
    r.append(0)

for i in range(1, len(s)):
    if s[i] == "R":
        r.append(r[-1] + 1)
    else:
        r.append(r[-1])

g = []
if s[0] == "G":
    g.append(1)
else:
    g.append(0)

for i in range(1, len(s)):
    if s[i] == "G":
        g.append(g[-1] + 1)
    else:
        g.append(g[-1])

b = []
if s[0] == "B":
    b.append(1)
else:
    b.append(0)

for i in range(1, len(s)):
    if s[i] == "B":
        b.append(b[-1] + 1)
    else:
        b.append(b[-1])

for i in range(n):
    for j in range(i+1, n):
        if s[i] == s[j]:
            continue
        else:
            tmp = [s[i]] + [s[j]]
            target_idx = j + (j - i)

            if "R" not in tmp:
                ans += r[-1] - r[j]
                if target_idx >= len(s):
                    continue
                if s[target_idx] == "R":
                    ans -= 1
            elif "G" not in tmp:
                ans += g[-1] - g[j]
                if target_idx >= len(s):
                    continue
                if s[target_idx] == "G":
                    ans -= 1
            else:
                ans += b[-1] - b[j]
                if target_idx >= len(s):
                    continue
                if s[target_idx] == "B":
                    ans -= 1

print(ans)


### FIXED CODE ###

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

ans = 0
sn = len(s)

r = []
if s[0] == "R":
    r.append(1)
else:
    r.append(0)
g = []
if s[0] == "G":
    g.append(1)
else:
    g.append(0)
b = []
if s[0] == "B":
    b.append(1)
else:
    b.append(0)

for i in range(1, sn):
    if s[i] == "R":
        r.append(r[-1] + 1)
        g.append(g[- 1])
        b.append(b[- 1])
    elif s[i] == "G":
        r.append(r[-1])
        g.append(g[-1] + 1)
        b.append(b[- 1])
    elif s[i] == "B":
        r.append(r[-1])
        g.append(g[-1])
        b.append(b[-1] + 1)
    else:
        r.append(r[-1])
        g.append(g[- 1])
        b.append(b[- 1])

for i in range(n - 2):
    for j in range(i + 1, n - 1):
        if s[i] != s[j]:
            tmp = dict()
            tmp[s[i]] = 0
            tmp[s[j]] = 0
            target_idx = j + (j - i)

            if tmp.get("B", 1) == 1:
                ans += b[-1] - b[j]
                if target_idx >= sn:
                    continue
                if s[target_idx] == "B":
                    ans -= 1
            elif tmp.get("G", 1) == 1:
                ans += g[-1] - g[j]
                if target_idx >= sn:
                    continue
                if s[target_idx] == "G":
                    ans -= 1
            else:
                ans += r[-1] - r[j]
                if target_idx >= sn:
                    continue
                if s[target_idx] == "R":
                    ans -= 1

print(ans)