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

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

#############
# Libraries #
#############

import math
from functools import lru_cache

#############
# Constants #
#############

MOD = 10**9 +7
INF = float('inf')

#############
# Functions #
#############

kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

#############
# Main Code #
#############

N = int(input())

@lru_cache(maxsize=None)
def count(n,a,b):
  counter = 0
  for i in range(1,n+1):
    if int(str(i)[0])==a and int(str(i)[-1])==b:
      counter += 1
  return counter

ans = 0
for i in range(10):
  for j in range(10):
    ans += count(N,i,j)*count(N,j,i)

print(ans)

### FIXED CODE ###

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

#############
# Libraries #
#############

import math
from functools import lru_cache

#############
# Constants #
#############

MOD = 10**9 +7
INF = float('inf')

#############
# Functions #
#############

kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

#############
# Main Code #
#############

N = int(input())

dic = [[0 for i in range(10)] for j in range(10)]
for i in range(1,N+1):
  top = int(str(i)[0])
  bottom = int(str(i)[-1])
  dic[top][bottom] += 1

ans = 0
for i in range(10):
  for j in range(10):
    ans += dic[i][j]*dic[j][i]

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

def main():
    n = int(input())
    a = [int(input()) for i in range(n)]
    for i in range(n):
        d = sorted(a, reverse=True)
        if d[0] == a[i]:
            print(d[1])
        else:
            print(d[0])
            
if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    n = int(input())
    a = [int(input()) for i in range(n)]
    d = sorted(a, reverse=True)
    for i in range(n):    
        if d[0] == a[i]:
            print(d[1])
        else:
            print(d[0])

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

import sys

n = int(input())
for i in range(3500):
    for j in range(3500):
        temp = 4 * (i + 1) * (j + 1) - n * (i + j + 2)
        if temp != 0:
            if (n * (i + 1) * (j + 1)) % temp == 0:
                if (n * (i + 1) * (j + 1)) // temp > 0:
                    print(i + 1, j + 1, (n * (i + 1) * (j + 1)) // temp)
                    sys.exit()

### FIXED CODE ###

import sys

n = int(input())
for i in range(3500):
    for j in range(3500):
        temp = 4 * (i + 1) * (j + 1) - n * (i + j + 2)
        if temp != 0:
            if (n * (i + 1) * (j + 1)) % temp == 0:
                if (n * (i + 1) * (j + 1)) // temp > 0:
                    print(i + 1, j + 1, (n * (i + 1) * (j + 1)) // temp)
                    sys.exit()
### BUGGY CODE ###

K=input()
D=int(input())
mod=10**9+7

L=len(K)

DP=[[0]*D for i in range(2)]#DP[num][limit]で,一つ前の桁について,「桁和,そこまでKと一致していれば1」の場合の数


for j in range(10):
    if j>int(K[0]):
        continue
    if j==int(K[0]):
        DP[1][j%D]+=1
    else:
        DP[0][j%D]+=1

for ketanum in K[1:]:
    NDP=[[0]*D for i in range(2)]

    for i in range(D):
        for j in range(10):
            NDP[0][(i+j)%D]=(NDP[0][(i+j)%D]+DP[0][i])%mod

            if j>int(ketanum):
                continue
            if j==int(ketanum):
                NDP[1][(i+j)%D]=(NDP[1][(i+j)%D]+DP[1][i])%mod
            else:
                NDP[0][(i+j)%D]=(NDP[0][(i+j)%D]+DP[1][i])%mod

    DP=NDP

print((DP[0][0]+DP[1][0]-1)%mod)

### FIXED CODE ###

K=input()
D=int(input())
mod=10**9+7

L=len(K)

DP=[0]*D#DP[num][limit]で,一つ前の桁について,「桁和,そこまでKと一致していれば1」の場合の数
LIMIT=[]

for j in range(10):
    if j>int(K[0]):
        continue
    if j==int(K[0]):
        LIMIT=j%D
    else:
        DP[j%D]+=1

for ketanum in K[1:]:
    NDP=[0]*D

    for i in range(D):
        for j in range(10):
            NDP[(i+j)%D]=(NDP[(i+j)%D]+DP[i])%mod

    for j in range(int(ketanum)):
        NDP[(LIMIT+j)%D]+=1

    LIMIT=(LIMIT+int(ketanum))%D

    DP=NDP

print((DP[0]-1+ (LIMIT==0) )%mod)
### BUGGY CODE ###

n = int(input())
s = input()
l = len(s)
mod = 10**9 + 7
now = [0 for _ in range(l)]
now = [1] + now
for _ in range(n+l):
  last = now
  now = [0 for _ in range(l+1)]
  for i in range(l):
    now[i] += last[i] * 25
    now[i+1] = last[i]
  now[-1] += last[-1] * 26
  for i in range(l+1):
    now[i] %= mod
  #print(now)
print(now[-1])

### FIXED CODE ###

n = int(input())
s = input()
l = len(s)
mod = 10**9 + 7

now = 1
for _ in range(n+l):
  now *= 25
  now %= mod
#print(now)
def inv(x):
  y = 1
  while x != 1:
    y *= mod // x + 1
    x -= mod % x
  return y
ans = 0
#print('#')
for i in range(n+l):
  now *= (n+l-i)
  now *= inv(i+1)
  now *= inv(25)
  now %= mod
  if i+1 >= l:
    ans += now
    ans %= mod
  #print(now)
print(ans)
### BUGGY CODE ###

H,W = map(int,input().split())
List=[input() for i in range(H)]
A =[[] for i in range(H)]
B =[[] for i in range(W)]
for i in range(H):
    k = 0
    a = 0
    while k < W:
        if List[i][k]==".":
            a += 1
            k = k+1
        else:
            for j in range(a):
                A[i].append(a)
            A[i].append(0)
            a = 0
            k = k+1
    for j in range(a):
                A[i].append(a)
for i in range(W):
    k = 0
    a = 0
    while k < H:
        if List[k][i]==".":
            a += 1
            k = k+1
        else:
            for j in range(a):
                B[i].append(a)
            B[i].append(0)
            a = 0
            k = k+1
    for j in range(a):
                B[i].append(a)
max = 0
for i in range(H):
    for j in range(W):
        if max < A[i][j] + B[j][i]:
            max = A[i][j] + B[j][i]
print(max-1)
        

### FIXED CODE ###

H,W = map(int,input().split())
List=[input() for i in range(H)]
A =[[1]*(W) for i in range(H)]
B =[[1]*(H) for i in range(W)]
for i in range(H):
    k = 0
    a = 0
    while k < W:
        if List[i][k]==".":
            a += 1
            k = k+1
        else:
            for j in range(a):
                A[i][k-j-1]=a
            A[i][k]=a
            a = 0
            k = k+1
    for j in range(a):
                A[i][k-j-1]=a
for i in range(W):
    k = 0
    a = 0
    while k < H:
        if List[k][i]==".":
            a += 1
            k = k+1
        else:
            for j in range(a):
                B[i][k-j-1]=a
            B[i][k] = 0
            a = 0
            k = k+1
    for j in range(a):
                B[i][k-j-1]= a
max = 0
for i in range(H):
    for j in range(W):
        if max < A[i][j] + B[j][i]:
            max = A[i][j] + B[j][i]
print(max-1)
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
b = sorted(a)
maxcomb = 0
x=0
y=0
def comb(n,r):
    npr = 1
    rp1 = 1
    for i in range(n-r+1,n+1):
        npr *= i
    for j in range(1,r+1):
        rp1 *= j
    return npr // rp1

comb(10,2)

for i in range(1,n):
    for j in range(0,i):
        if maxcomb < comb(b[i],b[j]):
            maxcomb = comb(b[i],b[j])
            x=b[i]
            y=b[j]
print(x,y)
    

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
b = sorted(a)
maxb = max(b)
mini = b[0]
for i in b:
    if abs(maxb/2 - i) < abs(maxb/2 - mini):
        mini = i
print(maxb,mini)
### BUGGY CODE ###

N = int(input())
stones = [l for l in input()]

cnt = 0
for i in range(N//2):
    for j in range(N-1, i , -1):
        if stones[i] == 'W' and stones[j] == 'R':
            stones[i] = 'R'
            stones[j] = 'W'
            cnt += 1
            break
            
print(cnt)

### FIXED CODE ###

N = int(input())
stones = [l for l in input()]

cnt = 0
memo = N-1
for i in range(N):
    for j in range(memo, i , -1):
        if stones[i] == 'R':
            break
        else :
            if stones[j] == 'R':
                stones[i] = 'R'
                stones[j] = 'W'
                cnt += 1
                break
    memo = j
    if memo == i:
        break
            
print(cnt)
### BUGGY CODE ###

from collections import deque
n=int(input())
edge=list(list(map(int,input().split())) for _ in range(n-1))
color=[0]*(n-1)
d=deque()


s=1
d.append(s)
while d:
  c=1
  s=d.popleft()
  check=[]
  seen=[]
  for i in range(n-1):
    if s in edge[i]:
      for k in edge[i]:
        if k!=s:
          e=k
      if color[i]==0:
        d.append(k)
        check.append(i)
      else:
        seen.append(color[i])
  for j in check:
    if c not in seen:
      color[j]=c
      c+=1
    else:
      while c in seen:
        c+=1
      color[j]=c
      c+=1
print(int(max(color)))
print(" ".join(list(map(lambda x: str(int(x)), color))))        
    


### FIXED CODE ###

#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
from fractions  import gcd
#input=sys.stdin.readline
#import bisect
n=int(input())
v=tuple(tuple(map(lambda x: int(x)-1,input().split())) for _ in range(n-1))

node=[[] for _ in range(n)]
k=0
used=[-1]*n
seen=[-1]*n
for pair in v:
    node[pair[0]].append(pair[1])
    node[pair[1]].append(pair[0])
    k=max(k,len(node[pair[0]]),len(node[pair[1]]))
print(k)
ans={}
d=deque()
d.append(0)
while d:
    i=d.pop()
    seen[i]=1
    res=1
    for j in node[i]:
        if seen[j]==1:
            continue
        d.appendleft(j)
        if res!=used[i]:
            ans[(i,j)]=res
        else:
            res+=1
            ans[(i,j)]=res
        used[j]=res
        res+=1
for pair in v:
    a,b=pair
    if (a,b) in ans:
        print(ans[(a,b)])
    else:
        print(ans[(b,a)])
### BUGGY CODE ###

def main():
    from math import gcd
    _ = int(input())
    A = [int(i) for i in input().split()]

    def prime_factorize(n):
        for i in range(2, n+1):
            if i*i > n:
                break
            if n % i != 0:
                continue
            while n % i == 0:
                n //= i
            B[i] += 1
        if n != 1:
            B[n] += 1
    maxA = max(A)
    B = [0] * (maxA + 1)
    for a in A:
        prime_factorize(a)

    g = A[0]
    for a in A:
        g = gcd(g, a)

    if g != 1:
        print("not coprime")
    elif max(B) <= 1:
        print("pairwise coprime")
    else:
        print("setwise coprime")


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    from math import gcd
    MINFact = [-1] * (10**6 + 10)
    MINFact[0] = 0
    MINFact[1] = 1

    def Eratosthenes(sup: int) -> set:
        primes = [True for i in range(sup+1)]
        primes[0] = False
        primes[1] = False
        for i in range(2, sup+1):
            if primes[i]:
                MINFact[i] = i
                mul = 2
                while i*mul <= sup:
                    primes[i*mul] = False
                    if MINFact[i*mul] == -1:
                        MINFact[i*mul] = i
                    mul += 1

    def prime_factor(n):
        while n != 1:
            prime = MINFact[n]
            while MINFact[n] == prime:
                n //= prime
            B[prime] += 1

    _ = int(input())
    A = [int(i) for i in input().split()]
    g = A[0]
    for a in A:
        g = gcd(g, a)
    Eratosthenes(10**6 + 5)
    B = [0]*(10**6 + 5)
    for a in A:
        prime_factor(a)
    # 素因数分解したのをBにいれる
    # 1より大きいのがあったら gcd != 1 のペアが存在する
    if g != 1:
        print("not coprime")
    elif max(B) <= 1:
        print("pairwise coprime")
    else:
        print("setwise coprime")


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

n = int(input())
a = list(map(int, input().split()))
c = {}
for i in range(n):
  c[a[i]] = c.get(a[i], 0) + 1

prime_bool = [True]*(max(a)+1)
prime_bool[0] = False
count = 0
for p in sorted(a):
  if prime_bool[p]:
    if c[p] == 1:
      count += 1
    #print(p)
    for j in range(2*p, max(a)+1, p):
      prime_bool[j] = False

print(count)



### FIXED CODE ###

import collections

n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
c = collections.Counter(a)
data = sorted(list(set(a)))
max_ = max(a)+1
prime_bool = [True]*max_
prime_bool[0] = False

for i in range(len(data)):
  p = data[i]
  if prime_bool[p]:
    #print(p)
    k = 2
    while k*p < max_:
      prime_bool[k*p] = False
      k += 1

count = 0
for i in range(len(prime_bool)):
  if prime_bool[i]:
    if c[i] == 1:
      count += 1
print(count)
#print(prime_bool)
### BUGGY CODE ###

N = int(input())
X = input()

d = [0 for _ in range(N)]
for i in range(1, N):
    v = i % bin(i)[2:].count("1")
    d[i] = d[v] + 1

a = int(X, 2)
b = X.count("1")
k = 2 ** (N-1)

for i, ch in enumerate(X):
    if ch == "0":
        x = a + k
        y = b + 1
    else:
        x = a - k
        y = b - 1
    k //= 2

    if x == 0:
        print(0)
    else:
        print(d[x % y] + 1)


### FIXED CODE ###

N = int(input())
X = input()

a = int(X, 2)
b = X.count("1")

if b > 1:
    a1 = a % (b-1)
else:
    a1 = 0
a0 = a % (b+1)

for i in range(N):
    if X[i] == "1":
        if b == 1:
            print(0)
            continue
        t = (a1 - pow(2, N-1-i, b-1)) % (b-1)
    else:
        t = (a0 + pow(2, N-1-i, b+1)) % (b+1)
    
    ans = 1
    while t > 0:
        t %= bin(t).count("1")
        ans += 1
    print(ans)
### BUGGY CODE ###

N = int(input())
L = [int(i) for i in input().split()]
L.sort()

cnt = 0
for i in range(N-2):
  for j in range(i+1,N-1):
    lo = j+1
    hi = N
    while lo < hi:
      k = (lo+hi)//2
      if L[k] < L[i] + L[j]:
        lo = k + 1
      else:
        hi = k
    cnt += max(0,lo-j-1)
print(cnt)

### FIXED CODE ###

N = int(input())
L = list(map(int, input().split()))
L.sort()

from bisect import bisect_left 
cnt = 0
for i in range(0,N):
  for j in range(i+1,N):
    t = L[i]+L[j]
    idx = bisect_left(L,t)
    cnt += max(0,idx-j-1)
print(cnt)
### BUGGY CODE ###

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

if 0 in A:
    print(0)
elif max(A) >= 10**18:
    print(-1)
else:
    for i in A:
        B *= i
    if B > 10 ** 18:
        print(-1)
    else:
        print(B)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
B = 1
# print(max(A))
if 0 in A:
    print(0)
elif max(A) > 10**18:
    print(-1)
else:
    for i in A:
        B *= i
        if B > 10 ** 18:
            B = -1
            break
    print(B)
### BUGGY CODE ###

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

result = 1 
for i in multi:
    result = result * i
    
if (result > 10**18):
    print(-1)
else:
    print(result)

### FIXED CODE ###

n = int(input())
multi = list(map(int,input().split()))
result = 1 

if 0 in multi:
    result = 0
    print(0)
    exit()

for i in range(n):
    result = result * multi[i]
    if (result > 10**18):
        result = -1
        break 
        
print(result)
### BUGGY CODE ###


# 入力部
N, K = map(int, input().split())
data_list = []
for i in range(N):
    x, y, c = input().split()
    x, y = int(x), int(y)
    data_list.append([x, y, c])

# スコア行列[K, K]
# 白チェッカー左下を(x, y)としたときの正解数-誤答数
score_matrix = [[0 for x in range(K)] for y in range(K)]

# 座標をmod Kに変換してスコア行列[K, K]を導出 O(N)
# 同時に初期値であるhope[0][0]も計算
score_matrix = [[0 for x in range(K)] for y in range(K)]
# 白チェッカー左下が(0, 0)のときの希望の数
base_hope = 0
for data in data_list:
    x, y, c = data[0] // K, data[1] // K, data[2]
    x_coord, y_coord = data[0] % K, data[1] % K
    # 正解
    if ((x + y) % 2 == 0 and c == "W") or ((x + y) % 2 == 1 and c == "B"):
        score_matrix[y_coord][x_coord] += 1
        base_hope += 1
    # 誤答
    else:
        score_matrix[y_coord][x_coord] -= 1
# print(score_matrix)

# スコア行列の二次元累積和を求める O(K^2)
xy = [(x, y) for x in range(K) for y in range(K)]
for x, y in xy:
    accum = score_matrix[y][x]
    if x > 0:
        accum += score_matrix[y][x-1]
    if y > 0:
        accum += score_matrix[y-1][x]
    if x > 0 and y > 0:
        accum -= score_matrix[y-1][x-1]
    score_matrix[y][x] = accum
# print(score_matrix)

# 希望行列を累積和に基づき計算していく O(K^2)
# 同時に最大値を計算
max_hope = 0
for x, y in xy:
    diff = 0
    if x > 0:
        diff += score_matrix[K-1][x-1]
    if y > 0:
        diff += score_matrix[y-1][K-1]
    if x > 0 and y > 0:
        diff -= 2 * score_matrix[y-1][x-1]
    hope = base_hope - diff
    true_hope = max(hope, N - hope)
    if true_hope > max_hope:
        max_hope = true_hope

print(max_hope)

### FIXED CODE ###

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

score = [[0] * (K+1) for y in range(K+1)]
base_hope = 0

for i in range(N):
    x, y, c = input().split()
    x2, y2 = int(x) // K, int(y) // K
    x_coord, y_coord = int(x) % K + 1, int(y) % K + 1
    if ((x2 + y2) % 2 == 0 and c == "W") or ((x2 + y2) % 2 == 1 and c == "B"):
        score[y_coord][x_coord] += 1
        base_hope += 1
    else:
        score[y_coord][x_coord] -= 1

xy = [(x, y) for x in range(K) for y in range(K)]
for x, y in xy:
    score[y+1][x+1] += score[y+1][x] + score[y][x+1] - score[y][x]

max_hope = 0
for x, y in xy:
    hope = base_hope - score[K][x] - score[y][K] + 2 * score[y][x]
    true_hope = hope if hope > N - hope else N - hope
    if true_hope > max_hope:
        max_hope = true_hope

print(max_hope)
### BUGGY CODE ###

N = int(input())
s = [sorted(list(input())) for i in range(N)]
s.sort()

#[print(i) for i in s]

ans = 0

for i in range(N):
    for j in range(i+1,N):
        if s[i] == s[j]:
            #print("s[" + str(i)+"]" + " = s[" + str(j)+"]" )
            ans+=1

if not ans == 0:
    print(ans)
else:
    print(0)


### FIXED CODE ###

N = int(input())
s = ["".join(sorted(input())) for i in range(N)]

#print(s)

#出現文字列
sdict = {}

for i in range(N):

    s_i = str(s[i])

    if s_i in sdict:
        #組み合わせが増えるので
        sdict[s_i]+= 1
        continue

    else:
        sdict[s_i] = 1

ans = 0
for i in sdict.values():
    ans += i*(i-1)//2
print(ans)
### BUGGY CODE ###

n,q = map(int,input().split())
s = input()

l = []
r = []

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

### FIXED CODE ###

n,q = map(int,input().split())
s = input()


t = [0] * n
for i in range(n-1):
    if s[i] == "A" and s[i+1] == "C":
        t[i+1] = t[i] + 1
    else:
        t[i+1] = t[i]


for i in range(q):
    l, r = map(int,input().split())
    print(t[r-1] - t[l-1])
### BUGGY CODE ###

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

S = input()

count = [[0,0,0] for i in range(N)]
for i in range(N-1, 0, -1):
    for j in range(3):
        count[i-1][j] = count[i][j]
    if S[i] == "R":
        count[i-1][0] += 1
    elif S[i] == "G":
        count[i-1][1] += 1
    elif S[i] == "B":
        count[i-1][2] += 1
"""
for j in range(3):
    for i in range(N):
        print(count[i][j], end = " ")
    print()
"""
ans = 0
for i in range(N):
    for j in range(i + 1, N):
        if S[i] == S[j]:
            continue
        if (S[i] == "R" and S[j] == "G") or (S[i] == "G" and S[j] == "R"):
            ans += count[j][2]
            diff = j-i
            if j+diff < N and S[j+diff] == "B":
                ans -= 1
        elif (S[i] == "B" and S[j] == "R") or (S[i] == "R" and S[j] == "B"):
            ans += count[j][1]
            diff = j-i
            if j+diff < N and S[j+diff] == "G":
                ans -= 1
        elif (S[i] == "G" and S[j] == "B") or (S[i] == "B" and S[j] == "G"):
            ans += count[j][0]
            diff = j-i
            if j+diff < N and S[j+diff] == "R":
                ans -= 1
print(ans)

### FIXED CODE ###

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

S = input()

count = [[0,0,0] for i in range(N)]
for i in range(N-1, 0, -1):
    for j in range(3):
        count[i-1][j] = count[i][j]
    if S[i] == "R":
        count[i-1][0] += 1
    elif S[i] == "G":
        count[i-1][1] += 1
    elif S[i] == "B":
        count[i-1][2] += 1
"""
for j in range(3):
    for i in range(N):
        print(count[i][j], end = " ")
    print()
"""
ans = 0
for i in range(N):
    for j in range(i + 1, N):
        if S[i] == S[j]:
            continue
        if (S[i] == "R" and S[j] == "G") or (S[i] == "G" and S[j] == "R"):
            ans += count[j][2]
            diff = j-i
            if j+diff < N and S[j+diff] == "B":
                ans -= 1
        elif (S[i] == "B" and S[j] == "R") or (S[i] == "R" and S[j] == "B"):
            ans += count[j][1]
            diff = j-i
            if j+diff < N and S[j+diff] == "G":
                ans -= 1
        elif (S[i] == "G" and S[j] == "B") or (S[i] == "B" and S[j] == "G"):
            ans += count[j][0]
            diff = j-i
            if j+diff < N and S[j+diff] == "R":
                ans -= 1
print(ans)
### BUGGY CODE ###

n=int(input())
ans=0
for i in range(1,n+1):
  sa=list(str(i))
  sumj=0
  for j in sa:
    sumj+=int(j)
  ans=max(ans,sumj)
print(ans)

### FIXED CODE ###

n=str(input())
cn=sum(map(int,list(n)))

k=len(n)
c=int(n[0])
n=int(n)
if cn==(c+9*(k-1)):
  print(c+9*(k-1))
else:
  print(c+9*(k-1)-1)
### BUGGY CODE ###

n = input()
countArray = [0] * 2019
count = 0
countArray[0] +=1
for i in range(len(n)):
    countArray[int(n[-i-1:])%2019]+=1

for i in countArray:
    count += (i * (i - 1)) / 2
print(int(count))

### FIXED CODE ###

n = input()
countArray = [0] * 2019
count = 0
countArray[0] += 1
nums=0
for i in range(len(n))[::-1]:
    nums = nums + int(n[len(n)-1-i])*pow(10,i,2019)
    countArray[nums%2019]+=1

for i in countArray:
    count += (i * (i - 1)) // 2
print(count)