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

import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    E=[[] for _ in range(n)]
    edges={}
    for i in range(n-1):
        a,b=map(int,input().split())
        a-=1; b-=1
        E[a].append(b)
        E[b].append(a)
        edges[(a,b)]=[i,None]

    k=max(len(E[v]) for v in range(n))

    # DFSで辺に色付け
    Q=[0]
    while(Q):
        v=Q.pop()
        if(v==0):
            col=list(range(1,k+1))
        else:
            p=min(E[v])
            c=edges[(p,v)][1]
            col=set(range(1,k+1))
            col.remove(c)
            col=list(col)
        for nv in E[v]:
            if(v==0):
                c=col.pop()
                edges[(v,nv)][1]=c
                Q.append(nv)
            else:
                if(nv==p): continue
                c=col.pop()
                edges[(v,nv)][1]=c
                Q.append(nv)

    res=list(edges.values())
    res.sort()
    print(k)
    for i,c in res:
        print(c)

resolve()

### FIXED CODE ###

import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    E=[[] for _ in range(n)]
    idx={}
    for i in range(n-1):
        a,b=map(int,input().split())
        a-=1; b-=1
        E[a].append(b)
        E[b].append(a)
        idx[(a,b)]=i

    ans=[None]*(n-1)
    k=max(len(E[v]) for v in range(n))

    # DFSで辺に色付け
    Q=[0]
    while(Q):
        v=Q.pop()
        if(v):
            p=min(E[v]) # 親はE[v]の最小値
            c=ans[idx[(p,v)]] # 親につながる色
        cnt=1
        for nv in E[v]:
            if(v==0):
                ans[idx[(v,nv)]]=cnt
                cnt+=1
                Q.append(nv)
            else:
                if(cnt==c): cnt+=1
                if(nv==p): continue
                ans[idx[(v,nv)]]=cnt
                cnt+=1
                Q.append(nv)

    print(k)
    for c in ans:
        print(c)

resolve()
### BUGGY CODE ###

from collections import Counter
 
def verify_anagrams(first_word, second_word):
    def get_counter(s):
        return Counter(s.upper().replace(' ', ''))
 
    return get_counter(first_word) == get_counter(second_word)
flag=0
n=int(input())
list1=[]
check_list=[]
for i in range(n):
    list1.append(input())
for i in range(n):
    for j in range(n):
        if (i!=j)and(list1[j] not in check_list):
            if verify_anagrams(list1[i], list1[j]):
                check_list.append(list1[i])
                flag=flag+1
print(flag)

### FIXED CODE ###

from collections import defaultdict
N = int(input())
d = defaultdict(int)
 
for i in range(N):
    s = str(sorted(input()))
    d[s] += 1
ans = 0
 
for key in d.keys():
    ans += d[key]*(d[key]-1)//2
print(ans)
### BUGGY CODE ###

R, G, B, n = map(int, input().split())
cnt = 0
for r in range(n+1):
    for g in range(n+1):
        bb = n - r*R - g*G
        if bb >= 0 and bb%B == 0:
            cnt += 1
print(cnt)

### FIXED CODE ###

R, G, B, n = map(int, input().split())
cnt = 0
for r in range(n+1):
    for g in range(n+1):
        bb = n - r*R - g*G
        if bb < 0:
            break
        elif bb%B == 0:
            cnt += 1
print(cnt)
### BUGGY CODE ###

r,g,b,n=map(int,input().split())
def INT(m):
  if int(m)==m:
    return True
  return False
aa=[r,g,b]
aa.sort()
a,b,c=aa[0],aa[1],aa[2]
ans=0
for i in range(n//c + 1):
  for j in range((n-i*c)//b + 1):
    if INT((n-i*c-j*b)/a):
      ans+=1
print(ans)


### FIXED CODE ###

r,g,b,n=map(int,input().split())
def INT(m):
  if int(m)==m:
    return True
  return False
aa=[r,g,b]
aa.sort()
a,b,c=aa[0],aa[1],aa[2]
ans=0
for i in range(n//c +1):
  for j in range((n-i*c)//b +1):
    if INT((n-i*c-j*b)/a):
      ans+=1
print(ans)
### BUGGY CODE ###

# 1からNまでの数字それぞれの約数を求める
# Nから(大きい値から)見ていき、1であれば入れる
# 数字iを入れた場合、iの約数の数を+1
# それぞれの数はdictで保持する

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

def divisor(n):
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    table.sort()
    return table

dic = {}
ans = [0 for _ in range(N)]
for i in range(N):
    tmp = N - i
    if tmp in dic:
        if dic[tmp] % 2 != A[tmp-1]:
            dic[tmp] += 1
            ans[tmp - 1] = 1
            divs = divisor(tmp)
            for div in divs:
                if div in dic:
                    dic[div] += 1
                else:
                    dic[div] = 1

    else:
        if A[tmp-1] == 1:
            dic[tmp] = 1
            ans[tmp - 1] = 1
            divs = divisor(tmp)
            for div in divs:
                if div in dic:
                    dic[div] += 1
                else:
                    dic[div] = 1
        else:
            dic[tmp] = 0

print(sum(ans))
ans_list = ""
for i in range(N):
    if ans[i] == 1:
        ans_list += str(i + 1)
        if i != N - 1:
            ans_list += " "

print(ans_list)

### FIXED CODE ###

# 1からNまでの数字それぞれの約数を求める
# Nから(大きい値から)見ていき、1であれば入れる
# 数字iを入れた場合、iの約数の数を+1
# それぞれの数はdictで保持する

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

ans = [0 for _ in range(N)]

ans_num = 0
ans_list = ""
for i in range(N):
    tmp = N - i
    s = 0
    for j in range(tmp, N+1, tmp):
        s += ans[j-1]

    if s % 2 != A[tmp - 1]:
        ans[tmp - 1] = 1
        ans_num += 1
        ans_list += str(tmp)
        ans_list += " "


print(ans_num)
print(ans_list[:-1])
### BUGGY CODE ###

import sys
if sys.version[0] == '2':
    range, input = xrange, raw_input
N = int(input())

A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

dp = [N]
for w in range(1, N+1):
    dp.append(max([N] + [dp[w-a] + b-a for a, b in zip(A, B) if w-a >= 0]))

M = max(dp)
dp = [M]
for w in range(1, M+1):
    dp.append(max([M] + [dp[w-b] + a-b for a, b in zip(A, B) if w-b >= 0]))

print(max(dp))


### FIXED CODE ###

import sys
if sys.version[0] == '2':
    range, input = xrange, raw_input
N = int(input())

A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

dp = [0] * (N+1)
for a, b in ((a, b) for a, b in zip(A, B) if a < b):
    for w in range(a, N+1):
        dp[w] = max(dp[w], dp[w-a] + b-a)

M = max(dp) + N
dp = [0] * (M+1)
for a, b in ((a, b) for a, b in zip(A, B) if a > b):
    for w in range(b, M+1):
        dp[w] = max(dp[w], dp[w-b] + a-b)

print(max(dp) + M)
### BUGGY CODE ###

N, K = map(int, input().split())
mod = 998244353
D = []
dp = [0] * (N+10)
for i in range(K):
    L, R = map(int, input().split())
    for i in range(L, R+1):
        D.append(i)

D = sorted(D)
dp[0] = 1
for i in range(N):
    for d in D:
        if i + d > N:
            continue
        dp[i + d] += dp[i]
        dp[i + d] %= mod

print(dp[N-1])



### FIXED CODE ###

N, K = map(int, input().split())
mod = 998244353
D = []
dp = [0] * (N+1)
for i in range(K):
    L, R = map(int, input().split())
    D.append([L, R])

dp[0] = 1
a = 0
for i in range(N):
    a += dp[i]
    a %= mod
    for d in D:
        if i + d[0] > N:
            continue
        dp[i + d[0]] += a
        dp[i + d[0]] %= mod
        if i + d[1] + 1 > N:
            continue

        dp[i + d[1] + 1] -= a
        dp[i + d[1] + 1] %= mod


print(dp[N-1])
### BUGGY CODE ###

# coding: utf-8
# Your code here!

from collections import deque

H, W = map(int, input().rstrip().split(' '))

field = [[0] * W for _ in range(H)]
field_dist = [[2000] * W for _ in range(H)]
move_history = [[[False] * 4 for _ in range(W)] for _ in range(H)]
for i in range(H):
    s = input()
    for j in range(W):
        if s[j] == '#':
            field[i][j] = 1
            init_h = i
            init_w = j
'''
import random
H, W = 1000, 1000
field = [[0] * W for _ in range(H)]
field_dist = [[2000] * W for _ in range(H)]
move_history = [[[False] * 4 for _ in range(W)] for _ in range(H)]
for i in range(H):
    for j in range(W):
        if random.randint(0, 2) % 2 == 0:
            field[i][j] = 1
            init_h = i
            init_w = j
'''
            
d = deque([[init_h, init_w]])
reverse_d = []
while len(d) > 0:
    cur_h, cur_w = d.popleft()
    cur_d = abs(init_h - cur_h) + abs(init_w - cur_w)
    
    if field[cur_h][cur_w] == 1:
        field_dist[cur_h][cur_w] = 0
    
    for i, (dh, dw) in enumerate([[0, 1], [0, -1], [1, 0], [-1, 0]]):
        if move_history[cur_h][cur_w][i] == False:
            move_history[cur_h][cur_w][i] = True
            if (cur_h + dh) >= 0 and (cur_h + dh) < H and (cur_w + dw) >= 0 and (cur_w + dw) < W:
                next_d = abs(init_h - (cur_h + dh)) + abs(init_w - (cur_w + dw))
                if next_d > cur_d:
                    field_dist[cur_h+dh][cur_w+dw] = min(field_dist[cur_h+dh][cur_w+dw], field_dist[cur_h][cur_w]+1)
                    d.append([cur_h+dh, cur_w+dw])
                    reverse_d.append([cur_h+dh, cur_w+dw, cur_h, cur_w])
         
max_dist = 0
while len(reverse_d) > 0:
    s_h, s_w, d_h, d_w = reverse_d.pop()
    if field_dist[s_h][s_w] + 1 < field_dist[d_h][d_w]:
        field_dist[d_h][d_w] = field_dist[s_h][s_w] + 1
    max_dist = max(max_dist, field_dist[s_h][s_w])

print(max_dist)
'''
for i in range(H):
    for j in range(W):
        print(field_dist[i][j], end=' ')
    print()
'''

### FIXED CODE ###

# coding: utf-8
# Your code here!

from collections import deque

H, W = map(int, input().rstrip().split(' '))

field = [[0] * W for _ in range(H)]
d = deque()
for i in range(H):
    s = input()
    for j in range(W):
        if s[j] == '#':
            field[i][j] = 1
            d.append([i, j, 0])

max_dist = 0
while len(d) > 0:
    cur_h, cur_w, dist = d.popleft()
    for i, (dh, dw) in enumerate([[0, 1], [0, -1], [1, 0], [-1, 0]]):
        if (cur_h + dh) >= 0 and (cur_h + dh) < H and (cur_w + dw) >= 0 and (cur_w + dw) < W:
            if field[cur_h+dh][cur_w+dw] == 0:
                field[cur_h+dh][cur_w+dw] = 1
                d.append([cur_h+dh, cur_w+dw, dist+1])
                max_dist = max(max_dist, dist+1)

print(max_dist)
### BUGGY CODE ###

def d_friends():
    class UnionFind(object):
        def __init__(self, n):
            """要素番号は 0 スタートを前提とする"""
            self.num_element = n
            self.parents = [-1] * n  # 要素が根の場合は、-(グループの要素数) を格納

        def find(self, x):
            """要素 x が属するグループの根を返す"""
            if self.parents[x] < 0:
                return x
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

        def union(self, x, y):
            """要素 x が属するグループと要素 y が属するグループとを併合する"""
            u, v = self.find(x), self.find(y)

            if u == v:
                return

            # u のグループの方が要素数が少なかった (parents の 定義より)
            if self.parents[u] > self.parents[v]:
                u, v = v, u

            self.parents[u] += self.parents[v]  # u と同グループの要素数を増やす
            self.parents[v] = u  # v は u に繋げる

        def get_members(self, x):
            """要素 x が属するグループに属する要素をリストで返す"""
            root = self.find(x)
            return [i for i in range(self.num_element) if self.find(i) == root]

        def get_roots(self):
            """根となっている要素のすべてを返す"""
            return [i for i, x in enumerate(self.parents) if x < 0]

    N, M = [int(i) for i in input().split()]
    uf = UnionFind(N)
    for _ in range(M):
        a, b = [int(i) - 1 for i in input().split()]
        uf.union(a, b)
    return max([len(uf.get_members(r)) for r in uf.get_roots()])

print(d_friends())

### FIXED CODE ###

def d_friends():
    class UnionFind(object):
        def __init__(self, n):
            """要素番号は 0 スタートを前提とする"""
            self.num_element = n
            self.parents = [-1] * n  # 要素が根の場合は、-(グループの要素数) を格納

        def find(self, x):
            """要素 x が属するグループの根を返す"""
            if self.parents[x] < 0:
                return x
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

        def union(self, x, y):
            """要素 x が属するグループと要素 y が属するグループとを併合する"""
            u, v = self.find(x), self.find(y)

            if u == v:
                return

            # u のグループの方が要素数が少なかった (parents の 定義より)
            if self.parents[u] > self.parents[v]:
                u, v = v, u

            self.parents[u] += self.parents[v]  # u と同グループの要素数を増やす
            self.parents[v] = u  # v は u に繋げる

        def get_size(self, x):
            """要素 x が属するグループの要素数を返す"""
            return -self.parents[self.find(x)]

    N, M = [int(i) for i in input().split()]
    uf = UnionFind(N)
    for _ in range(M):
        a, b = [int(i) - 1 for i in input().split()]
        uf.union(a, b)
    return max([uf.get_size(r) for r in range(N)])

print(d_friends())
### BUGGY CODE ###

class Uf():
    def __init__(self, n):
        self.par = list(range(N))
 
    def root(self, x):
        if self.par[x] == x:
            return x
        
        root_x = self.root(self.par[x])
        self.par[x] = root_x
        return root_x
    
    def merge(self, a, b):
        root_a, root_b = self.root(a), self.root(b)
        
        if root_a == root_b:
            return
            
        if root_a > root_b:
            root_a, root_b = root_b, root_a
        
        self.par[root_a] = root_b
    
    def isSame(self, a, b):
        return self.root(a) == self.root(b)
    
    def size(self, x):
        return self.par.count(self.par[x])


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

exep = [[] for i in range(N)]

uf = Uf(N)

for i in range(M):
    a, b  = map(int,input().split())
    a, b = a-1, b-1 
    exep[a].append(b)
    exep[b].append(a)
    uf.merge(a, b)

for i in  range(K):
    a, b  = map(int,input().split())
    a, b = a-1, b-1
    if not uf.isSame(a,b):
        continue
    exep[a].append(b)
    exep[b].append(a)

for i in range(N):
    uf.root(i)

for i in range(N):
    print(uf.size(i) - 1 - len(exep[i]), end=" ")

### FIXED CODE ###

import sys
sys.setrecursionlimit(4100000)

class Uf():
    def __init__(self, n):
        self.par = [-1]*N
 
    def root(self, x):
        if self.par[x] < 0:
            return x
        
        root_x = self.root(self.par[x])
        self.par[x] = root_x
        return root_x
    
    def merge(self, a, b):
        a, b = self.root(a), self.root(b)
        
        if a == b:
            return
            
        if self.par[a] > self.par[b]:
            a, b = b, a
        
        self.par[a] += self.par[b]
        self.par[b] = a
                 
    def isSame(self, a, b):
        return self.root(a) == self.root(b)
    
    def size(self, x):
        return -self.par[self.root(x)]


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

exep = [[] for i in range(N)]

uf = Uf(N)

for i in range(M):
    a, b  = map(int,input().split())
    a, b = a-1, b-1 
    exep[a].append(b)
    exep[b].append(a)
    uf.merge(a, b)

for i in  range(K):
    a, b  = map(int,input().split())
    a, b = a-1, b-1
    if not uf.isSame(a,b):
        continue
    exep[a].append(b)
    exep[b].append(a)

for i in range(N):
    print(uf.size(i) - 1 - len(exep[i]), end=" ")
### BUGGY CODE ###

# coding: utf-8

N, Y=(int(x) for x in input().split())

A = Y // 10000 #Yを越えない最大の10000円札の枚数
B = Y // 5000
C = Y // 1000

roop = 0
for i in range(A+1):
    if roop == 1:
        break
    for j in range(B+1):
        if roop == 1:
            break
        for k in range(C+1):
            if 10 * i + 5 * j + k == Y // 1000 and i + j + k == N:
                # a:10000円札、b:5000円札、c:1000円札の枚数
                a = i
                b = j
                c = k
                roop = 1
if roop == 1:
    print("{0} {1} {2}".format(a, b, c))
else:
    print("-1 -1 -1")

### FIXED CODE ###

# coding: utf-8

N, Y=(int(x) for x in input().split())

A = Y // 10000 #Yを越えない最大の10000円札の枚数
B = Y // 5000
C = Y // 1000

roop = 0
for i in range(A+1):
    if roop == 1:
        break
    for j in range(B+1):
        if i + j > N:
            break
        c = N - i - j #c:1000円札の枚数
        if 10*i + 5*j + c == Y//1000 and c >= 0:
            # a:10000円札、b:5000円札
            a = i
            b = j
            roop = 1
            break

if roop == 1:
    print("{0} {1} {2}".format(a, b, c))
else:
    a, b, c = -1, -1, -1
    print("{0} {1} {2}".format(a, b, c))
### BUGGY CODE ###

s = input()
a = int(s)
mods = [a%2019]
for i in range(len(s)):
  a = a-int(s[i])*10**(len(s)-i-1)
  mods.append(a%2019)
mod_N = {}
for i in mods:
  mod_N[i] = 0
for i in mods:
  mod_N[i] += 1
ans = 0
for i in mod_N:
  ans += int(mod_N[i]*(mod_N[i]-1)/2)
print(ans)

### FIXED CODE ###

s = input()
a = 0
mods = [0]*2019
mods[a] += 1
r = 1
for i in s[::-1]:
  a = (a+int(i)*r)%2019
  r = r*10%2019
  mods[a] += 1
ans = 0
for i in mods:
  ans += i*(i-1)//2
print(ans)
### BUGGY CODE ###

S = list(str(input()))

count = [0] * len(S)

for i in range(0, len(S)):
  current = i
  
  if S[current] == "R":
    for j in range(0, pow(10, 100)):
      if S[current+1] == "L":
        if j % 2 == 1:
          current += 1
        break
      else:
        current += 1
  else:
    for j in range(0, pow(10, 100)):
      if S[current-1] == "R":
        if j % 2 == 1:
          current -= 1
        break
      else:
        current -= 1

  count[current] += 1
  
result = " ".join(map(str, count))

print(result)

### FIXED CODE ###

S = list(str(input()))
result_position = [0] * len(S)
count = [0] * len(S)

# 最も左の計算
current = 0
for j in range(0, pow(10, 100)):
  if S[current + 1] == "L":
    if j % 2 == 1:
      current += 1
    break
  else:
    current += 1
result_position[0] = current
count[current] += 1

for i in range(1, len(S)):
  if (S[i - 1] == "R") or (S[i - 1] == "L" and S[i] == "L"):
    if S[result_position[i - 1]] == "R":
      result_position[i] = result_position[i - 1] + 1
    else:
      result_position[i] = result_position[i - 1] - 1
    count[result_position[i]] += 1
  else:
    current = i
    for j in range(0, pow(10, 100)):
      if S[current+1] == "L":
        if j % 2 == 1:
          current += 1
        break
      else:
        current += 1
    result_position[i] = current
    count[current] += 1
  
result = " ".join(map(str, count))

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

import copy

N=int(input())
L=[]
tmp=[]
for _ in range(N):
  L.append(int(input()))

T=sorted(copy.deepcopy(L))
h=max(L)
h2=T[len(T)-2]

for i in range(N):
  if L[i]!=h:
    print(h)
  elif L[i]!=h2:
    print(h2)
  else:
    tmp=copy.deepcopy(L)
    del tmp[i]
    print(max(tmp))

### FIXED CODE ###

N=int(input())
L=[]
for _ in range(N):
  L.append(int(input()))
sL=sorted(L)
sL.reverse()
m=max(L)
m2=sL[1]

for i in range(N):
  if L[i]==m:
    print(m2)
  else:
    print(m)
### BUGGY CODE ###

N = int(input())
dic = {}
for i in range(N):
  a = int(input())
  dic[i + 1] = a
l = [1]
n = dic[1]
i = 1
flg = False
if n == 2:
  print(1)
else:
  while n not in l:
    l.append(n)
    n = dic[n]
    i += 1
    if n == 2:
      flg = True
      ans = i
      break
  if flg:
    print(ans)
  else:
    print(-1)
  


### FIXED CODE ###

n = int(input())
dic = {}
push = [True] * n
for i in range(1, n+1):
  a = int(input())
  dic[i] = a
i = 1
cnt = 1
push[0] = False
while True:
  if dic[i] == 2:
    break
  else:
    k = dic[i]
    if push[k-1]:
      i = k
      cnt += 1
      push[k-1] = False
    else:
      cnt = -1
      break
print(cnt)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

n,k = map(int,input().split())
l = list(map(int,input().split()))
#print(l)
cnt = l[k-1]
p = 1
g = k-1
i = 0
while(i < k-1):
    cnt = cnt*l[g-1]
    g = g-1
    i = i+1

g = g+1
pr = l[g-1]
while(k < n):
    if l[k] > pr:
        sys.stdout.write("Yes")
        print("")

    else:
        sys.stdout.write("No")
        print("")
    g = g+1
    pr = l[g-1]
    k = k+1


### FIXED CODE ###

import sys
input = sys.stdin.readline

n,k = map(int,input().split())
l = list(map(int,input().split()))
#print(l)
cnt = l[k-1]
p = 1
g = 0
g = g+1
pr = l[g-1]
while(k < n):
    if l[k] > pr:
        sys.stdout.write("Yes")
        print("")

    else:
        sys.stdout.write("No")
        print("")

    g = g+1
    pr = l[g-1]
    k = k+1
### BUGGY CODE ###

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

    count = 0
    flag = False

    for i in A:
        if(A.count(i) > 1):
            flag = True
            break

    if(flag):
        print('NO')
    else:
        print('YES')
    '''
    for i in A:
        for j in A:
            if(count == 2):
                flag = True
                break
            if(i == j):
                count += 1
        count = 0

        if(flag):
            break

    if(flag):
        print('NO')
    else:
        print('YES')
        '''

if __name__ == "__main__":
    main()

### FIXED CODE ###

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

    count = 0
    flag = False

    set_A = set(A)

    if(len(set_A) == len(A)):
        print('YES')
    else:
        print('NO')
        
    '''
    for i in A:
        if(A.count(i) > 1):
            flag = True
            break

    if(flag):
        print('NO')
    else:
        print('YES')
    '''

'''
    for i in A:
        for j in A:
            if(i == j):
                count += 1
            if(count > 1):
                flag = True
                break
        count = 0

        if(flag):
            break

    if(flag):
        print('NO')
    else:
        print('YES')
        '''

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

N=int(input())
S=input()
ans=0
tmp=0
for k in range(N):
  for j in range(k):
    i=int(2*j-k)
    if i>=0:
      if S[i]!=S[j] and S[i]!=S[k] and S[j]!=S[k]:
        tmp+=1
ans=S.count("R")*S.count("G")*S.count("B")-tmp
print(ans)

      
      
    

### FIXED CODE ###

n=int(input())
s=input()
sum=0
r=int(s.count('R'))
g=int(s.count('G'))
b=int(s.count('B'))
for k in range(n):
    for j in range(k):
        i=2*j-k
        if i+1>0:
            if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
                sum=sum+1
print(r*g*b-sum)
### BUGGY CODE ###

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

ans = 3000

if R-L >= 2100 :
    ans = 0

for i in range(L,R):
    for j in range(L+1,R+1):
        if (i*j)%2019 < ans :
            ans = (i*j)%2019
            if ans == 0 :
                break

print(ans)


### FIXED CODE ###

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

if R-L >= 2100 :
    ans = 0
else :
    ans = 2019
    for i in range(L,R):
        for j in range(i+1,R+1):
            if (i*j)%2019 < ans :
                ans = (i*j)%2019
                if ans == 0 :
                    break

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

s=input()
s=s[::-1]
l=[0]*2019
l[0]=1
prev=0
ans=0

for i in range(len(s)):
  mul=(10**i)%2019
  now=(int(s[i])*mul)%2019
  ans+=l[(prev+now)%2019]
  l[(prev+now)%2019]+=1
  prev=(prev+now)%2019

print(ans)

### FIXED CODE ###

s=input()


s=s[::-1]
l=[0]*2019
l[0]=1
prev=0
ans=0
mul=1

for i in range(len(s)):
  now=(int(s[i])*mul)%2019
  ans+=l[(prev+now)%2019]
  l[(prev+now)%2019]+=1
  prev=(prev+now)%2019
  mul=(mul*10)%2019

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

def main():
    S = input()
    Q = int(input())
    is_turned = False

    for _ in range(Q):
        query = input()
        if query == "1":
            is_turned = not is_turned
        else:
            T, F, C = query.split()
            if is_turned ^ (F == "1"):
                S = C + S
            else:
                S = S + C

    if (is_turned):
        print(S[::-1])
    else:
        print(S)


if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    S = input()
    Q = int(input())
    L = ""
    R = ""
    is_turned = False

    for _ in range(Q):
        Query = input().split()
        if Query[0] == "1":
            is_turned = not is_turned
        else:
            if is_turned ^ (Query[1] == "1"):
                # L.insert(0, Query[2])
                L = Query[2] + L
            else:
                # R.append(Query[2])
                R = R + Query[2]

    if (is_turned):
        print("".join(L + S + R)[::-1])
    else:
        print("".join(L + S + R))


if __name__ == "__main__":
    main()