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

s = input()
q = int(input())
for i in range(q):
  t = input()
  if t[0] == '1':
    s = s[::-1]
  else:
    _, f, c = map(str, t.split())
    if f =='1':
      s = c+s
    else:
      s = s+c

print(s)


### FIXED CODE ###

s = list(input())
q = int(input()) #int(input())
inv = 1
query = [input() for _ in range(q)]
bef = []
aft = []


for t in query:
  if t == '1':
    inv *= -1 #s = s[::-1]
  else:
    _, f, c = map(str, t.split())
    if (f =='1' and inv == 1) or (f =='2' and inv == -1):
      # s = c+s
      bef.append(c)
    else:
      # s = s+c
      aft.append(c)

bef.reverse()
bef.extend(s)
bef.extend(aft)

print(''.join(bef[::inv]))
### BUGGY CODE ###

n,m=map(int,input().split())
ab=[[] for _ in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    a-=1
    b-=1
    ab[a].append(b)
    ab[b].append(a)
queue=[0]
ans=[-1]*n
ans[0]=0
while len(queue)!=0:
    now_check=queue.pop(0)
    for i in ab[now_check]:
        if ans[i]==-1:
            queue.append(i)
            ans[i]=now_check
print('Yes')
for i in range(1,n):
    print(ans[i]+1)

### FIXED CODE ###

from sys import stdin
from collections import deque

n,m=map(int,input().split())
ab=[[] for _ in range(n)]
for i in range(m):
    a,b=map(int,stdin.readline().split())
    a-=1
    b-=1
    ab[a].append(b)
    ab[b].append(a)
queue=[0]
ans=[-1]*n
ans[0]=0
while len(queue)!=0:
    now_check=queue.pop(0)
    for i in ab[now_check]:
        if ans[i]==-1:
            queue.append(i)
            ans[i]=now_check
print('Yes')
for i in range(1,n):
    print(ans[i]+1)
### BUGGY CODE ###

n = int(input())
tree = [[] for i in range(n+1)]

for i in range(1,n):
    u, v, w = map(int, input().split())
    tree[u].append((v, w))
    tree[v].append((u, w))

stack=[1]
visitted=[]
ans=[0]*(n+1)

while stack:
    cur = stack.pop()
    visitted.append(cur)
    for v, w in tree[cur]:
        if v in visitted:
            continue
        if v in stack:
            continue
        if w % 2 == 1:
            ans[v]=(ans[cur]+1)%2
        else:
            ans[v]=ans[cur]
        stack.append(v)

for i in ans[1:]:
    print(i)


### FIXED CODE ###

n = int(input())
tree = [[] for i in range(n+1)]

for i in range(1,n):
    u, v, w = map(int, input().split())
    tree[u].append((v, w))
    tree[v].append((u, w))

#print(tree)
stack=[1]
visitted={}
ans=[0]*n

while stack:
    cur = stack.pop()
    pre=ans[cur-1]
    visitted.setdefault(cur,1)
    #visitted.append(cur)
    for v, w in tree[cur]:
        if v in visitted:
            continue
        if w % 2 == 1:
            ans[v-1]=(pre+1)%2
        else:
            ans[v-1]=pre
        stack.append(v)

print(*ans, sep='\n')
### BUGGY CODE ###

# フェルマーの小定理
K = int(input())
S = input()

m = 1000000007

result = 0
a = 1
b = 1

for i in range(K + 1):
    # result += pow(26, K - i, m) * mcomb(len(S) - 1 + i, i) * pow(25, i, m)
    result += pow(26, K - i, m) * (a * pow(b, -1, m)) * pow(25, i, m)
    result %= m
    a *= len(S) - 1 + (i + 1)
    a %= m
    b *= i + 1
    b %= m
print(result)


### FIXED CODE ###

# フェルマーの小定理
K = int(input())
S = input()

m = 1000000007


def make_factorial_table(n):
    result = [0] * (n + 1)
    result[0] = 1
    for i in range(1, n + 1):
        result[i] = result[i - 1] * i % m
    return result


def mcomb(n, k):
    if n == 0 and k == 0:
        return 1
    if n < k or k < 0:
        return 0
    return fac[n] * pow(fac[n - k], m - 2, m) * pow(fac[k], m - 2, m) % m


fac = make_factorial_table(len(S) + K)

result = 0
for i in range(K + 1):
    result += pow(26, i, m) * mcomb(len(S) - 1 + K - i, len(S) - 1) * pow(25, K - i, m)
    result %= m
print(result)
### BUGGY CODE ###

from collections import Counter

n, m = map(int, input().split())
an = list(map(int, input().split()))
ac_ = Counter(an)
ac = {i: ac_[i] if i in ac_ else 0 for i in range(1, n + 1)}
ad = [0] * n
for a, c in ac.items():
    for i in range(max(0, a - c), a):
        ad[i] += 1
ans = ad.count(0)

for _ in range(m):
    x, y = map(int, input().split())
    ax = an[x - 1]
    xdi = ax - ac[ax]
    if xdi >= 0:
        ad[xdi] -= 1
        if ad[xdi] == 0:
            ans += 1
    ac[ax] -= 1
    ac[y] += 1
    ydi = y - ac[y]
    if ydi >= 0:
        ad[ydi] += 1
        if ad[ydi] == 1:
            ans -= 1
    an[x - 1] = y
    print(ans)


### FIXED CODE ###

from collections import Counter

n, m = map(int, input().split())
an = list(map(int, input().split()))
ac_ = Counter(an)
ac = {i: ac_[i] if i in ac_ else 0 for i in range(1, n + 1)}
ad = [0] * n
for a, c in ac.items():
    for i in range(max(0, a - c), a):
        ad[i] += 1
ans = ad.count(0)
anss = []

for x, y in (map(int, input().split()) for _ in range(m)):
    ax = an[x - 1]
    xdi = ax - ac[ax]
    if xdi >= 0:
        ad[xdi] -= 1
        if ad[xdi] == 0:
            ans += 1
    ac[ax] -= 1
    ac[y] += 1
    ydi = y - ac[y]
    if ydi >= 0:
        ad[ydi] += 1
        if ad[ydi] == 1:
            ans -= 1
    an[x - 1] = y
    anss.append(ans)
print('\n'.join(map(str, anss)))
### BUGGY CODE ###

from collections import deque
import sys
input = sys.stdin.readline

def bfs():
    H, W = map(int, input().split())
    ls = deque([])
    D = [[0] * (W+2)]
    D += ([[0] + [float("inf")]*W + [0] for i in range(H)])
    D.append([0]*(W+2))
    G = [["#"]*(W+2)]
    G += [["#"]+[i for i in input().strip()]+["#"] for i in range(H)]
    G.append(["#"]*(W+2))
    for i in range(1, H+1):
        for j in range(1, W+1):
            if G[i][j] == "#":
                ls.append([i, j, 0])
                D[i][j] = 0

    while len(ls) > 0:
        h, w, depth = ls.popleft()
        if depth + 1 < D[h+1][w]:
            ls.append([h+1, w, depth+1])
            D[h+1][w] = depth + 1
        if depth + 1 < D[h-1][w]:
            ls.append([h-1, w, depth+1])
            D[h-1][w] = depth + 1
        if depth + 1 < D[h][w+1]:
            ls.append([h, w+1, depth+1])
            D[h][w+1] = depth + 1
        if depth + 1 < D[h][w-1]:
            ls.append([h, w-1, depth+1])
            D[h][w-1] = depth + 1

    ans = 0
    for h in range(1, H+1):
        ans = max(ans, max(D[h]))
        
    return ans
    
print(bfs())

### FIXED CODE ###

import sys
input = sys.stdin.readline

H, W = map(int, input().split())
G = [[i for i in input()] for j in range(H)]

ls = []
dp = [[-1 for i in range(W)] for j in range(H)]
for h in range(H):
    for w in range(W):
        if G[h][w] == "#":
            ls.append([h,w])
            dp[h][w] = 1

ans = -1
while len(ls) > 0:
    ans += 1
    temp = []
    for h, w in ls:
        if 0 <= h+1 <= H-1 and dp[h+1][w] == -1:
            dp[h+1][w] = 1
            temp.append([h+1,w])
        if 0 <= h-1 <= H-1 and dp[h-1][w] == -1:
            dp[h-1][w] = 1
            temp.append([h-1,w])
        if 0 <= w+1 <= W-1 and dp[h][w+1] == -1:
            dp[h][w+1] = 1
            temp.append([h,w+1])
        if 0 <= w-1 <= W-1 and dp[h][w-1] == -1:
            dp[h][w-1] = 1
            temp.append([h,w-1])
    ls = temp

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

n = int(input())

result = 0
word_list = {}

for i in range(n):
    input_word = "".join(sorted(input()))
    flag = 1
    for this_word in word_list:
        if this_word == input_word:
            word_list[this_word] += 1
            result += word_list[this_word]
            flag = 0
            break
    if flag:
        word_list[input_word] = 0

print(result)

### FIXED CODE ###

n = int(input())

result = 0
word_list = {}

for i in range(n):
    input_word = "".join(sorted(input()))
    flag = 1
    if input_word in word_list:
        word_list[input_word] += 1
        result += word_list[input_word]
        flag = 0
    else:
        word_list[input_word] = 0

print(result)
### BUGGY CODE ###

from collections import Counter

N = int(input())
strings = [input() for _ in range(N)]

str_count = [Counter(l) for l in strings]

ans = 0
for x in range(len(str_count)):
    for y in range(x + 1, len(str_count)):
        if str_count[x] == str_count[y]:
            ans += 1

print(ans)


### FIXED CODE ###

from collections import Counter

N = int(input())
strings = [str(sorted(Counter(input()).items())) for _ in range(N)]

counts = Counter(strings)
ans = 0
for i in counts.values():
    ans += sum(range(i))

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

r,g,b,n = map(int,input().split())

ans = 0
for i in range(n//r +1):
    for j in range(n//g +1):
        if 0 <= n-r*i-g*j and (n-r*i-g*j)%b == 0:
            ans += 1

print(ans)

### FIXED CODE ###

r,g,b,n = map(int,input().split())

ans = 0
for i in range(n//r +1):
    for j in range(n//g +1):
        if 0 <= n-r*i-g*j and (n-r*i-g*j)%b == 0:
            ans += 1

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

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

l=[]
r=[]
for j in range(m):
    l_tmp, r_tmp = list(map(int, input().split()))
    l.append(l_tmp)
    r.append(r_tmp)

p=[]
q=[]
for k in range(Q):
    p_tmp, q_tmp = list(map(int, input().split()))
    p.append(p_tmp)
    q.append(q_tmp)
    

for qi in range(Q):
    out = 0
    for i in range(m):
        if(l[i]>=p[qi] and r[i]<=q[qi]):
            out += 1
    print(out)

### FIXED CODE ###

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

l=[]
r=[]
for j in range(m):
    l_tmp, r_tmp = list(map(int, input().split()))
    l.append(l_tmp)
    r.append(r_tmp)

p=[]
q=[]
for k in range(Q):
    p_tmp, q_tmp = list(map(int, input().split()))
    p.append(p_tmp)
    q.append(q_tmp)
    
su = [[0 for _ in range(n+1)] for __ in range(n+1)]

def sumTable(L, R):
    for i in range(m):
        su[L[i]][R[i]] += 1
    
    for i in range(1,n+1):
        for j in range(1, n+1):
            su[i][j] += su[i-1][j]
            su[i][j] += su[i][j-1]
            su[i][j] -= su[i-1][j-1]

def getSum(ll,rr):
    ans = su[rr][rr] - su[rr][ll-1] -su[ll-1][rr] + su[ll-1][ll-1]
    return ans
  
sumTable(l,r)

import copy
ss = copy.copy(su)

for qi in range(Q):
    su = copy.copy(ss)
    print(getSum(p[qi], q[qi]))
### BUGGY CODE ###

N = int(input())
S = input()

i = 0
j = 1
k = 2

cnt = 0

while i != N - 2:

	if j - i == k - j:
		pass

	else:
		if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
			cnt = cnt + 1
		else:
			pass
			
	if k != N - 1:
		k = k + 1
	elif j != N - 2:
		j = j + 1
		k = j + 1
	else:
		i = i + 1
		j = i + 1
		k = j + 1

print(cnt)

### FIXED CODE ###

N = int(input())
S = input()

cnts = [0,0,0]
for c in S:
	if c == 'R':
		cnts[0] = cnts[0] + 1 
	if c == 'G':
		cnts[1] = cnts[1] + 1 
	if c == 'B':
		cnts[2] = cnts[2] + 1 

ans = cnts[0] * cnts[1] * cnts[2]

for j in range(1,N-1):
	for i in range(0,j):
		k = j + j - i
		if k >= N:
			pass
		elif S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
			ans = ans - 1

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

import time
start = time.time()
import random
D = int(input())
*c, = map(int, input().split())
S = []
for _ in [None] * D:
    *s, = map(int, input().split())
    S += s,
INF = float("inf")

def Tread(D):
    return [int(input()) - 1 for i in [None] * D]

def check(T):
    M = 0
    MM = []
    last = [-1] * 26
    for d, t in enumerate(T):
        M += S[d][t] - sum((d - last[i]) * c[i] for i in range(26) if i != t)
        last[t] = d
        # MM += M,
    return M # MM

def C():
    T = Tread(D)
    for i in range(int(input())):
        d, q = map(int, input().split())
        T[d - 1] = q - 1
        print(check(T))
C()

### FIXED CODE ###

def P(s):
  L = [0] * 26
  R = P = 0
  for i in range(D):
    t = I[i + D][0] - 1
    R += I[i][t]
    P += s - (i + 1 - L[t]) * C[t]
    R -= P
    L[t] = i + 1
  return R
(D,), C, *I = [list(map(int, o.split())) for o in open(0)]
for d, q in I[2*D + 1:]:
  I[d - 1 + D][0] = q
  print(P(sum(C)))
### BUGGY CODE ###

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

s = set( range(l,r+1) )
for m in range(M - 1):
    l, r = map(int, input().split())
    s = s & set( range(l,r+1) )

print(len(s))

### FIXED CODE ###

N, M = map(int, input().split())
l_max = -1
r_min = N + 1
for m in range(M):
    l, r = map(int, input().split())
    if l > l_max:
        l_max = l
    if r < r_min:
        r_min = r
print(max(r_min - l_max + 1, 0))
### BUGGY CODE ###

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

def func(i, m, A):
    if m == 0:
        return True
    elif m < 0 or i >= len(A):
        return False
    else:
        if func(i+1, m-A[i], A):
            return True
        if func(i+1, m, A):
            return True
    return False

n = int(raw_input())
A = map(int, raw_input().split())
q = int(raw_input())
M = map(int, raw_input().split())
for i in range(q):
    if func(0, M[i], A):
        print "yes"
    else:
        print "no"

### FIXED CODE ###

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

n = int(raw_input())
A = {0}
for c in raw_input().split():
    for i in A.copy():
        A.add(i+int(c))
q = int(raw_input())
M = map(int, raw_input().split())
for m in M:
    if m in A:
        print "yes"
    else:
        print "no"
### BUGGY CODE ###

# 常にi < jを考える

N = int(input())
H = [0]
H.extend(list(map(int, input().split())))

plus = [H[i] + i for i in range(1,N+1)]
minus = [i - H[i] for i in range(1, N+1)]

cnt = 0
for i in range(N):
    for j in range(i+1, N):
        if plus[i] == minus[j]:
            cnt += 1

print(cnt)

### FIXED CODE ###

# 常にi < jを考える
from collections import Counter

N = int(input())
H = [0]
H.extend(list(map(int, input().split())))

plus = [H[i] + i for i in range(1,N+1)]
minus = [i - H[i] for i in range(1, N+1)]
ans = 0

# 独立というのがよくわからなかったが，
# i > jで成り立つと仮定すると，
# aj -ai = Ai + Aj > 0　で，
# j > i となり，矛盾する。
# 連想配列で調べれば良い

cnt = Counter(minus)

for i in plus:
    ans += cnt.get(i, 0)

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

import sys
from bisect import bisect_right,bisect_left
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり


N = I()
A,B = LI(),LI()

# 各桁の xor を考える

ans = 0
for i in range(29,0,-1):  # 2**(i-1) の位
    X = [A[j] & ((1 << i) - 1) for j in range(N)]
    Y = [B[j] & ((1 << i) - 1) for j in range(N)]
    Y.sort()
    r = 0
    for j in range(N):
        a = X[j]
        # [2**(i-1)-a,2*2**(i-1)-a),[3*2**(i-1)-a,4*2**(i-1)-a) にある Y の要素の個数を数え上げる
        r += bisect_right(Y,(1 << i) - a - 1) - bisect_left(Y,(1 << (i-1)) - a)
        r += bisect_right(Y,(1 << (i+1)) - a - 1) - bisect_left(Y,3*(1 << (i-1)) - a)
    if r % 2 == 1:
        ans += 1 << (i-1)

print(ans)


### FIXED CODE ###

import sys
from bisect import bisect_right,bisect_left
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり


N = I()
A,B = LI(),LI()

# 各桁の xor を考える

ans = 0
mod = 1 << 29
for i in range(29,0,-1):  # 2**(i-1) の位
    X = [a & (mod-1) for a in A]
    Y = [b & (mod-1) for b in B]
    X.sort()
    Y.sort(reverse=True)
    mod >>= 1
    r = 0
    i1,i2,i3 = 0,0,0
    for j in range(N):
        x = X[j]
        # [2**(i-1)-x,2*2**(i-1)-x),[3*2**(i-1)-x,4*2**(i-1)-x) にある Y の要素の個数を数え上げる
        # 尺取り法
        while i1 < N and Y[i1] >= mod-x:
            i1 += 1
        while i2 < N and Y[i2] >= 2*mod-x:
            i2 += 1
        while i3 < N and Y[i3] >= 3*mod-x:
            i3 += 1
        r += i1-i2+i3
    if r % 2 == 1:
        ans += mod

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

#入力（後でいじる）
def pin(type=int):
    return map(type,input().split())
#どっかで最悪計算量の入力データを用意する関数を作ろう？
"""
O(N^2)
"""
#solution:
#潜 影 蛇 手 ! !
*c,N=pin()
c.sort(reverse=True)
ans=0


I=(N//c[0])+1
J=N//c[1]+1
for i in range(I):
    for j in range(J):
        remain=(N-i*c[0]-j*c[1])
      
        if remain>=0 and remain%c[2]==0:
            
            ans+=1
            
print(ans)

### FIXED CODE ###

#入力（後でいじる）
def pin(type=int):
    return map(type,input().split())
#どっかで最悪計算量の入力データを用意する関数を作ろう？
"""
O(N^2)
"""
#solution:
#潜 影 蛇 手 ! !
*c,N=pin()
c.sort(reverse=True)
ans=0


I=(N//c[0])+1
J=N//c[1]+1
for i in range(I):
    for j in range(J):
        remain=(N-i*c[0]-j*c[1])
      
        if remain>=0 and remain%c[2]==0:
            
            ans+=1
            
print(ans)
### BUGGY CODE ###

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

ans=1

for i in range (1,n):
  low=min(l[:i+1])
  if low==l[i]:
    ans+=1
    
print(ans)

### FIXED CODE ###

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

ans=0
low=l[0]

for i in range (n):
  if l[i]<=low:
    low=l[i]
    ans+=1
    
print(ans)
### BUGGY CODE ###

import math

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

print(max([math.floor(a*i / b) - a * math.floor(i / b)  for i in range(1, b + 1 if b < n else n + 1)]))

### FIXED CODE ###

import math
 
a, b, n = map(int, input().split(" "))
i = min([b-1 , n])
print( math.floor(a*i / b) - a * math.floor(i / b) )
### BUGGY CODE ###

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

rev = 0
for i in range(q):
    inp = list(input().split())
    if inp[0] == '1':rev = (rev + 1) % 2
    else:
        if (inp[1] == '1' and rev == 0) or (inp[1] == '2' and rev == 1):
            s = inp[2] + s
        else:
            s = s + inp[2]

print(s if rev == 0 else s[::-1])

### FIXED CODE ###

from collections import deque
s=input()
q=int(input())
ans_str=deque(s)
cnt=0
for _ in range(q):
    Q=list(input().split())
    if Q[0]=='1':
        cnt=1 if cnt==0 else 0

    else:
        if Q[1]=='1':
            if cnt==0 or len(ans_str)==1:
                ans_str.appendleft(Q[-1])
            else:
                ans_str.append(Q[-1])

        else:
            if cnt==0 or len(ans_str)==1:
                ans_str.append(Q[-1])
            else:
                ans_str.appendleft(Q[-1])
    #print(ans_str,cnt,Q)

ans=list(ans_str) if cnt==0 else list(ans_str)[::-1]
print(*ans,sep='')
### BUGGY CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, T = map(int, readline().split())

AB= list(map(int, read().split()))
A = AB[0::2]
B = AB[1::2]
ls = sorted(zip(A, B))
deli = [0]*N
deli[- 1] = ls[-1][- 1]
for i in range(N - 2, 0, - 1):
    deli[i] = max(deli[i + 1], ls[i][- 1])

res = 0
dp = [0]*T
for i in range(N - 1):
    a, b = ls[i]
    for j in range(T - 1, a - 1, - 1):
        dp[j] = max(dp[j], dp[j - a] + b)
    res = max(res, dp[- 1] + deli[i + 1])
print(res)

### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, T = map(int, readline().split())

AB= list(map(int, read().split()))
A = AB[0::2]
B = AB[1::2]
ls = list(zip(A, B))
# 食べるのにかかる時間で昇順にソート
ls.sort()
# 上の並び順において、ls[i:]の美味しさの最大値をdeli[i]とする
deli = [0]*N
deli[- 1] = ls[-1][- 1]
for i in range(N - 2, - 1, - 1):
    deli[i] = max(deli[i - 1], ls[i][- 1])

res = 0
dp = [0]*T
for i in range(N - 1):
    for j in range(T - 1, - 1, - 1):
        if ls[i][0] <= j:
            dp[j] = max(dp[j], dp[j - ls[i][0]] + ls[i][1])
    res = max(res, dp[- 1] + deli[i + 1])
print(res)
### BUGGY CODE ###

N = int(input())

ans = 0

for i in range(1, N):

    ans += i

print(ans)



### FIXED CODE ###

N = int(input())
print(N*(N-1)//2)
### BUGGY CODE ###

a, b, c, d =map(int, input().split())
cnt = a*c

if a == c and b == d:
    print(max(a*c, b*d))
    exit()
else:
    for i in range(a, b+1):
        for j in range(c, d+1):
            cnt = max(cnt,i*j)
            
print(cnt)   

### FIXED CODE ###

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

if a == c and b == d:
    print(max(a*c, b*d))
    exit()
else:
    print(max(a*c, a*d,b*c,b*d))
### BUGGY CODE ###

N = int(input())
S = input()
#%%
cum = [[0]*(N+1) for _ in range(3)]
for i in range(N):
    cum[0][i+1] = cum[0][i] + (S[i]=='R')
    cum[1][i+1] = cum[1][i] + (S[i]=='G')
    cum[2][i+1] = cum[2][i] + (S[i]=='B')
    
def color(i,j):
    RGB = [0]*3
    if S[i]=='R' or S[j]=='R':
        RGB[0] = 1
    if S[i]=='G' or S[j]=='G':
        RGB[1] = 1
    if S[i]=='B' or S[j]=='B':
        RGB[2] = 1
    
    if RGB[0]==0:
        return 0
    elif RGB[1]==0:
        return 1
    else:
        return 2
def col(s):
    if s=='R':
        return 0
    elif s=='G':
        return 1
    else:
        return 2

ans = 0
for i in range(N):
    for j in range(i+1,N):
        if S[i]!=S[j]:
            idx = color(i,j)
            ans += cum[idx][N]-cum[idx][j+1]
            k = 2*j-i
            if k<N and col(S[k])==idx:
                ans -= 1
print(ans)


### FIXED CODE ###

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


N = int(input())
S = list(input())
#%%
r_ruiseki = [0]*(N+1)
b_ruiseki = [0]*(N+1)
g_ruiseki = [0]*(N+1)
for i in range(N):
    r_ruiseki[i+1] = r_ruiseki[i] + (S[i]=='R')
    g_ruiseki[i+1] = g_ruiseki[i] + (S[i]=='G')
    b_ruiseki[i+1] = b_ruiseki[i] + (S[i]=='B')
pos_r = []
pos_b = []
pos_g = []
for i,s in enumerate(S):
    if s=='R':
        pos_r.append(i)
    elif s=='B':
        pos_b.append(i)
    else:
        pos_g.append(i)

ans = 0
for i in pos_r:
    for j in pos_b:
        if j-i<=1:
            continue
        ans += g_ruiseki[j+1] - g_ruiseki[i]
        if (i&1 == j&1):
            if S[(i+j)//2]=='G':
                ans -= 1
    

for i in pos_b:
    for j in pos_r:
        if j-i<=1:
            continue
        ans += g_ruiseki[j+1] - g_ruiseki[i]
        if (i&1 == j&1):
            if S[(i+j)//2]=='G':
                ans -= 1
    

for i in pos_r:
    for j in pos_g:
        if j-i<=1:
            continue
        ans += b_ruiseki[j+1] - b_ruiseki[i]
        if (i&1 == j&1):
            if S[(i+j)//2]=='B':
                ans -= 1
    
for i in pos_g:
    for j in pos_r:
        if j-i<=1:
            continue
        ans += b_ruiseki[j+1] - b_ruiseki[i]
        if (i&1 == j&1):
            if S[(i+j)//2]=='B':
                ans -= 1
    

for i in pos_g:
    for j in pos_b:
        if j-i<=1:
            continue
        ans += r_ruiseki[j+1] - r_ruiseki[i]
        if (i&1 == j&1):
            if S[(i+j)//2]=='R':
                ans -= 1
    
for i in pos_b:
    for j in pos_g:
        if j-i<=1:
            continue
        ans += r_ruiseki[j+1] - r_ruiseki[i]
        if (i&1 == j&1):
            if S[(i+j)//2]=='R':
                ans -= 1
    

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


def solve(a):
    a=sorted(a)
    ans=a[0]#暫定最小

    if len(set(a))!=1:
        for _ in range(a[0]):
            for i in range(n):
                amari=a[i]%ans
                
                if amari>0:
                    if amari<ans:
                        ans=amari
            if ans==1:
                break
    print(ans)

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

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
import fractions as ft


ans=a[0]
for i in a:
    ans=ft.gcd(ans,i)
print(ans)