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

from pprint import pprint
h,w=map(int,input().split())
ch,cw=map(int,input().split())
ch-=1;cw-=1
dh,dw=map(int,input().split())
dh-=1;dw-=1
maze=[input() for _ in range(h)]

from collections import deque

dist=[[-1]*w for _ in range(h)]
q=deque()
p=[]
q.append((ch,cw))
dist[ch][cw]=0
cur=0 #ワープ回数
while q:
    while q:
        x,y=q.popleft()
        if dist[x][y]>cur:
            continue
        dist[x][y]=cur
        for i in range(-1,2):
            for j in range(-1,2):
                if abs(i)+abs(j)==1:
                    xx=x+i
                    yy=y+j
                    if 0<=xx<=h-1 and 0<=yy<=w-1:
                        if dist[xx][yy]==-1:
                            if maze[xx][yy]==".":
                                dist[xx][yy]=cur
                                q.append((xx,yy))
                        if dist[xx][yy]>cur:
                            dist[xx][yy]=cur
                            q.append((xx,yy))
                                
        for i in range(-2,3):
            for j in range(-2,3):
                if abs(i)+abs(j)>=2:
                    xx=x+i
                    yy=y+j
                    if 0<=xx<=h-1 and 0<=yy<=w-1:
                        if dist[xx][yy]==-1:
                            if maze[xx][yy]==".":
                                p.append((xx,yy))
    
    if len(q)==0:
        # print(p,q)
        for pp in p:
            if dist[pp[0]][pp[1]]==-1:
                q.append(pp)
        p=[]
        cur+=1
# pprint(dist)
print(dist[dh][dw])
  
    


### FIXED CODE ###

from pprint import pprint
from collections import deque
h,w=map(int,input().split())
ch,cw=map(int,input().split())
ch-=1;cw-=1
dh,dw=map(int,input().split())
dh-=1;dw-=1
INF=float("inf")
maze=[input() for _ in range(h)]
dist=[[INF]*w for _ in range(h)]
q=deque()
p=[]
q.append((ch,cw))
dist[ch][cw]=0
cur=0
# pprint(dist)
# exit()
while q:
    while q:
        x,y=q.popleft()
        # (x,y)は到達訪問済み
        d=dist[x][y]
        for i in range(-2,3):
            for j in range(-2,3):
                # absの和が1、上下左右
                if abs(i)+abs(j)==1:
                    xx=x+i
                    yy=y+j
                    # 範囲内の時
                    if 0<=xx<=h-1 and 0<=yy<=w-1:
                        # 道のとき
                        if maze[xx][yy]==".":
                            # 未到達の時
                            if dist[xx][yy]>d:
                                # 移動前のdist[x][y]と同じコスト
                                dist[xx][yy]=d
                                q.append((xx,yy))
                # ワープ 
                if abs(i)+abs(j)>=2:
                    xx=x+i
                    yy=y+j
                    if 0<=xx<=h-1 and 0<=yy<=w-1:
                        if maze[xx][yy]==".":
                            if dist[xx][yy]>d+1:
                                dist[xx][yy]=d+1
                                p.append((xx,yy))
                                
   
    cur+=1
    q=deque(p)
    p=[]
            

# pprint(dist)
ans=dist[dh][dw]
if ans==INF:
    print(-1)
else:
    print(ans)
### BUGGY CODE ###

import math
A, B, N = map(int, input().split())

ans = 0
for i in range(1, N+1):
  if ans < (math.floor(A*i/B) - A*math.floor(i/B)):
    ans = math.floor(A*i/B) - A*math.floor(i/B)
    
print(ans)

### FIXED CODE ###

import math
A, B, N = map(int, input().split())

i = min(B-1, N)
ans = (A*i//B) - A*(i//B)
    
print(ans)
### BUGGY CODE ###

from sys import stdin
N=(stdin.readline().rstrip())
def str_del(str,index):
    str = str[:index]+str[index+1:]
    return str
ans=0
for i in range(100000000000):
    index=N.find("W")
    if index==-1:
        break
    ans=ans+index
    N=str_del(N,index)
print(ans)

### FIXED CODE ###

from sys import stdin
N=(stdin.readline().rstrip())
N=list(N)
cnt=0
ans=0
for i in N:
    if i=="B":
        cnt+=1
    else:
        ans+=cnt
print(ans)
### BUGGY CODE ###

import numpy as np
N=int(input())

for i in range(int(np.sqrt(N))):
    a=int(np.sqrt(N))-i
    if N%a==0:
        A=a
        B=N//a
        break
print(A+B-2)

### FIXED CODE ###

import numpy as np
N=int(input())
a=int(np.sqrt(N))
for i in range(int(np.sqrt(N))):
    if N%a==0:
        print(a+N//a-2)
        break
    a-=1
### BUGGY CODE ###

A, B, K = map(int, input().split())
for i in range(A, B + 1):
    if i < A + K or i > B - K:
        print(i)


### FIXED CODE ###

A, B, K = map(int, input().split())
R = range(A, min(B + 1, A + K))
S = range(max(A, B - K + 1), B + 1)
L = list(set(R) | set(S))
L.sort()
print(*L, sep="\n")
### BUGGY CODE ###

def solve():
    import sys
    input = sys.stdin.readline

    numChar = 26
    #numChar = 5
    ordA = ord('a')

    N = int(input())
    Ss = input()
    nos = [ord(S)-ordA for S in Ss]
    Q = int(input())

    def makeBIT(numEle):
        numPow2 = 2 ** (numEle-1).bit_length()
        datas = [[0]*(numPow2+1) for _ in range(numChar)]
        return datas, numPow2
    def addValue(no, iA, A):
        data = datas[no]
        iB = iA + 1
        while iB <= numPow2:
            data[iB] += A
            iB += iB & -iB
    def getSum(no, iA):
        data = datas[no]
        iB = iA + 1
        ans = 0
        while iB > 0:
            ans += data[iB]
            iB -= iB & -iB
        return ans
    def getRangeSum(no, iFr, iTo):
        return getSum(no, iTo) - getSum(no, iFr-1)


    datas, numPow2 = makeBIT(N)

    for i in range(N):
        no = nos[i]
        addValue(no, i, 1)

    anss = []
    for _ in range(Q):
        tp, v1, v2 = input().split()
        if tp == '1':
            pos = int(v1)-1
            no1 = nos[pos]
            no2 = ord(v2)-ordA
            addValue(no1, pos, -1)
            addValue(no2, pos, 1)
            nos[pos] = no2
        else:
            L, R = int(v1)-1, int(v2)-1
            ans = 0
            for no in range(numChar):
                if getRangeSum(no, L, R):
                    ans += 1
            anss.append(ans)

    print('\n'.join(map(str, anss)))


solve()


### FIXED CODE ###

def solve():
    import sys
    input = sys.stdin.readline

    numChar = 26
    #numChar = 5
    ordA = ord('a')

    N = int(input())
    Ss = input()
    nos = [ord(S)-ordA for S in Ss]
    Q = int(input())

    def makeBIT(numEle):
        numPow2 = 2 ** (numEle-1).bit_length()
        datas = [[0]*(numPow2+1) for _ in range(numChar)]
        return datas, numPow2
    def addValue(no, iA, A):
        data = datas[no]
        iB = iA + 1
        while iB <= numPow2:
            data[iB] += A
            iB += iB & -iB
    def getSum(no, iA):
        data = datas[no]
        iB = iA + 1
        ans = 0
        while iB > 0:
            ans += data[iB]
            iB -= iB & -iB
        return ans
    def getRangeSum(no, iFr, iTo):
        return getSum(no, iTo) - getSum(no, iFr-1)


    datas, numPow2 = makeBIT(N)

    for i in range(N):
        no = nos[i]
        addValue(no, i, 1)

    anss = []
    for _ in range(Q):
        tp, v1, v2 = input().split()
        if tp == '1':
            pos = int(v1)-1
            no1 = nos[pos]
            no2 = ord(v2)-ordA
            addValue(no1, pos, -1)
            addValue(no2, pos, 1)
            nos[pos] = no2
        else:
            L, R = int(v1)-1, int(v2)-1
            ans = 0
            for no in range(numChar):
                if getRangeSum(no, L, R):
                    ans += 1
            anss.append(ans)

    print('\n'.join(map(str, anss)))


solve()
### BUGGY CODE ###

D, G = list(map(int, input().split(' ')))
p_list = list()
c_list = list()
for _ in range(D):
    p, c = list(map(int, input().split(' ')))
    p_list.append(p)
    c_list.append(c)
num_prob_list = [0] * D
min_prob_num_sum = sum(p_list)


def dfs(prob_index=-1, prob_num=0, current_prob_num_sum=0, current_score=0):
    """
    Returns whether score >= G with local minimum of problems.
    """
    global min_prob_num_sum
    if prob_index >= 0:
        current_prob_num_sum += prob_num
        if current_prob_num_sum >= min_prob_num_sum:
            return False
        num_prob_list[prob_index] = prob_num
        current_score += 100 * (prob_index + 1) * prob_num
        if prob_num == p_list[prob_index]:
            current_score += c_list[prob_index]
        if current_score >= G:
            min_prob_num_sum = current_prob_num_sum
            # print(num_prob_list[:(prob_index + 1)])
            # print(current_score)
            return True
    next_prob_index = prob_index + 1
    if next_prob_index > D - 1:
        return False
    for next_prob_num in range(p_list[next_prob_index] + 1):
        if dfs(next_prob_index, next_prob_num, current_prob_num_sum, current_score):
            break


dfs()
print(min_prob_num_sum)

### FIXED CODE ###

import itertools
import math
D, G = list(map(int, input().split(' ')))
p_list = list()
c_list = list()
for _ in range(D):
    p, c = list(map(int, input().split(' ')))
    p_list.append(p)
    c_list.append(c)
ans = sum(p_list)
pattern_list = itertools.product([0, 1], repeat=D)
for pattern in pattern_list:
    score = 0
    prob_num = 0
    # Solve all problems with bit `1`
    score += sum([bit * (100 * (index + 1) * p_list[index] + c_list[index]) for index, bit in enumerate(pattern)])
    prob_num += sum([bit * p_list[index] for index, bit in enumerate(pattern)])
    # Solve problems partially with bit `0'
    if score < G:
        for index in range(D - 1, -1, -1):
            if pattern[index] == 1:
                # skip because these cases are already counted
                continue
            required_num = math.ceil((G - score) / (100 * (index + 1)))
            sol_num = min([p_list[index] - 1, required_num])
            score += 100 * (index + 1) * sol_num
            prob_num += sol_num
            if score >= G:
                break
    # update answer
    if score >= G:
        ans = min([ans, prob_num])
print(ans)
### BUGGY CODE ###

def resolve():
    S = input()
    list_S = list(S)
    len_S = len(list_S)
    ans = 0

    if len(list_S) <= 3:
        print(ans)
        return

    for start_i in range(0, len_S - 3):
        for last_i in range(3, len_S):
            tmp = ''.join(list_S[start_i:last_i + 1])
            if tmp:
                tmp_ans = int(tmp) % 2019

                if tmp_ans == 0:
                    ans += 1

    print(ans)


resolve()

### FIXED CODE ###

from collections import defaultdict


def resolve():
    s = input()

    cnt = defaultdict(int)
    cnt[0] += 1
    tmp = 0
    for i, c in enumerate(s[::-1]):
        c = int(c)
        tmp = (tmp + c * pow(10, i, 2019)) % 2019
        cnt[tmp] += 1

    ans = sum(c * (c - 1) // 2 for c in cnt.values())
    print(ans)


resolve()
### BUGGY CODE ###

import itertools
# from math import factorial

N = int(input())
words_dict = {}
for i in range(N):
  ss = input()
  ss_dict = {}
  for s in ss:
    ss_dict.setdefault(s, 0)
    ss_dict[s] += 1
  ss_dict = sorted(ss_dict.items())
  ss = [str(k)+str(v) for (k, v) in ss_dict]
  word = ''.join(ss)
  words_dict.setdefault(word, 0)
  words_dict[word] += 1
count = 0
for k, v in words_dict.items():
  if v > 1:
      count += len(list(itertools.combinations(range(v), 2)))
      # count += int(factorial(v) / factorial(2) / factorial(v-2))
print(count)

### FIXED CODE ###

N = int(input())
words_dict = {}
count = 0
for i in range(N):
  ss = input()
  ss = "".join(sorted(ss))
  words_dict.setdefault(ss, 0)
  count += words_dict[ss]
  words_dict[ss] += 1
print(count)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
"""
Created on Thu Apr  4 14:43:20 2019

@author: fumito
"""

def count(lr,S):
    sub = S[int(lr[0])-1:int(lr[1])]
    sub = [i for i in sub]
    A_index = [i for i,x in enumerate(sub) if x == 'A']
    count = 0
    for i in A_index:
        if i == len(sub)-1:
            pass
        elif sub[i+1] == 'C':
            count += 1
        else:
            pass
    return count

if __name__ == "__main__":
    N,Q = map(int,input().split())
    S = str(input())
    lr = [input().split() for i in range(Q)]
    

    for i in range(Q):
        Count = count(lr[i],S)
        print(Count)
        


### FIXED CODE ###

N,Q = map(int,input().split())
S = str(input())
l,r = [0]*Q,[0]*Q
for i in range(Q):
    l[i],r[i] = map(int,input().split())
    
count_list = []
count = 0
count_list.append(0)
for i in range(1,N):
    if S[i-1] == "A" and S[i] == "C":
        count += 1
        count_list.append(count)
    else:
        count_list.append(count)
    
for j in range(Q):
    print(count_list[r[j]-1]-count_list[l[j]-1])
### BUGGY CODE ###

s=input()
mod=1000000007

#後ろから解くアルゴリズム
n=13
dp=[0 for _ in range(n)]
dp[0]=1

mul=1
for i in range(len(s)-1, -1, -1):
    nextDP=[0 for _ in range(n)]
    c=s[i]
    if c=='?':
        for k in range(10):
            for j in range(13):
                nextDP[(mul*k+j)%13] += dp[j]
                nextDP[(mul*k+j)%13] %= mod
    else:
        k=int(c)
        for j in range(n):
            nextDP[(mul*k+j)%13] += dp[j]
            nextDP[(mul*k+j)%13] %= mod
    
    mul*=10
    mul%=n
    dp=nextDP.copy()   

print(dp[5])


### FIXED CODE ###

S = input()
mod = 10 ** 9 + 7

dp = [0]*13
dp[0] = 1

mul = 1
for i, s in enumerate(S[::-1]):
    new = [0]*13
    if s == "?":
        for x in range(13):
            for y in range(10):
                next_x = y * mul + x
                new[next_x % 13] += dp[x]
                new[next_x % 13] %= mod
    else:
        for x in range(13):
            next_x = int(s) * mul + x
            new[next_x % 13] = dp[x]

    dp = new
    mul *= 10
    mul %= 13

ans = dp[5] % mod
print(ans)
### BUGGY CODE ###

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

n = int(raw_input())
li = map(int, raw_input().split())

s = ""

for i in xrange(1,n+1):
    s += str(li.index(i) +1) + " "

print s

### FIXED CODE ###

# coding: utf-8
n = int(raw_input())
li = map(int, raw_input().split())

listb = []
listb = sorted(range(len(li)), key=lambda k: li[k])

s = str(map(lambda x: x+1, listb))

print s.replace("[","").replace("]","").replace(",","")
### BUGGY CODE ###

#!/usr/bin/env python3
# coding=utf-8

import itertools
import sys

n, k = map(int, sys.stdin.readline().strip().split(" "))
xyc = [l.strip().split(" ") for l in sys.stdin.readlines()]
xyc = [tuple((int(_x), int(_y), _c == "W")) for (_x, _y, _c) in xyc]
xyc = [
    tuple((_x % k, _y % k, _c if (_x // k + _y // k) % 2 == 0 else not _c)) for (_x, _y, _c) in xyc
]


def checker(base, condition):
    i, j, f = base
    x, y, c = condition
    if not ((x <= i and y <= j) or (i < x and j < y)):
        f = not f
    return f == c


ans = 0
for i, j, f in itertools.product(range(k), range(k), {True, False}):
    checks = [checker((i, j, f), _xyc) for _xyc in xyc]
    ans = max(ans, sum(checks))
    if ans == n:
        break
print(ans)


### FIXED CODE ###

import numpy as np
N, K = map(int, input().split())
ub = K * 2
b = [[0 for j in range(ub + 1)] for i in range(ub + 1)]
ADD = {"B": 0, "W": K}


def create_bound(p, K, ub):
    if p - K + 1 >= 0:
        return [(p - K + 1, p + 1)]
    else:
        return [(0, p + 1), ((p - K + 1) % ub, ub)]


for i in range(N):
    x, y, c = input().split()
    nx = int(x) % ub
    ny = (int(y) + ADD[c]) % ub
    for add in [0, K]:
        for xlb, xub in create_bound((nx + add) % ub, K, ub):
            for ylb, yub in create_bound((ny + add) % ub, K, ub):
                b[xlb][ylb] += 1
                b[xlb][yub] -= 1
                b[xub][ylb] -= 1
                b[xub][yub] += 1

b_arr = np.array(b)
for i in range(ub):
    b_arr[i + 1, :] += b_arr[i, :]
for j in range(ub):
    b_arr[:, j + 1] += b_arr[:, j]
print(b_arr.max())
### BUGGY CODE ###

class Kenken():
	def __init__(self,n,a,b,c,d,s):
		self.n = n
		self.a = a-1
		self.b = b-1
		self.c = c-1
		self.d = d-1
		self.s = s
		self.s = self.s[:a-1] + "A" + self.s[a:]
		self.s = self.s[:b-1] + "B" + self.s[b:]

	def str_replace(self,i,k,S):
		if k == 1:
			self.s = self.s[:i] + "." + S + self.s[i+2:]
		else:
			self.s = self.s[:i] + "." + self.s[i+1] + S + self.s[i+3:]

	def check_stone(self,i):
		if i < self.n:
			if self.s[i] == ".":
				return True
		return False

	def check_goal(self):
		if self.a == self.c and self.b == self.d:
			return False
		else:
			return True

	def left(self,target,i):
		if target == "a":
			self.str_replace(self.a,i,"A")
			self.a += i
		else:
			self.str_replace(self.b,i,"B")
			self.b += i
	
	def get_space(self,S):
		if S == "a":
			return self.a
		elif S == "b":
			return self.b
		elif S == "c":
			return self.c
		elif S == "d":
			return self.d

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

ken = Kenken(n,a,b,c,d,s)
flag=0
while ken.check_goal():
	if (ken.check_stone(ken.get_space("b")+1) and ken.check_stone(ken.get_space("b")-1)) or (ken.get_space("a")+1 == ken.get_space("b") and ken.check_stone(ken.get_space("b")+1)): 
		if ken.check_stone(ken.get_space("a")+1) and ken.get_space("a") != ken.get_space("c"):
			ken.left("a",1)
		elif ken.check_stone(ken.get_space("a")+2) and ken.get_space("a") != ken.get_space("c"):
			ken.left("a",2)
		elif ken.check_stone(ken.get_space("b")+1) and ken.get_space("b") != ken.get_space("d"):
			ken.left("b",1)
		elif ken.check_stone(ken.get_space("b")+2) and ken.get_space("b") != ken.get_space("d"):
			ken.left("b",2)
		else:
			flag=1
			break
	else:
		if ken.check_stone(ken.get_space("b")+1) and ken.get_space("b") != ken.get_space("d"):
			ken.left("b",1)
		elif ken.check_stone(ken.get_space("b")+2) and ken.get_space("b") != ken.get_space("d"):
			ken.left("b",2)
		elif ken.check_stone(ken.get_space("a")+1) and ken.get_space("a") != ken.get_space("c"):
			ken.left("a",1)
		elif ken.check_stone(ken.get_space("a")+2) and ken.get_space("a") != ken.get_space("c"):
			ken.left("a",2)
		else:
			flag=1
			break

if flag == 0:
	print("Yes")
else:
	print("No")

### FIXED CODE ###

n,a,b,c,d = map(int, input().split())
s = input()
if s[a:c-1].count("##")!=0 or s[b:d-1].count("##")!=0:
	print("No")
	exit()

if c > d:
	if s[b-2:d+1].count("...") == 0:
		print("No")
		exit()
print("Yes")
### BUGGY CODE ###

import sys
input = sys.stdin.readline
N,K=map(int,input().rstrip().split())
h=list(map(int,input().rstrip().split()))

dp=[0]*N
for i in range(N):
    dp[i]=1000000000000
dp[0]=0

for i in range(1,N,1):
    for k in range(1,K+1,1):
        if(i-k>=0):
            dp[i]=min(dp[i],dp[i-k]+abs(h[i]-h[i-k]))
        else:
            break
print(dp[N-1])
 

### FIXED CODE ###

import sys
input = sys.stdin.readline
N,K=map(int,input().rstrip().split())
h=list(map(int,input().rstrip().split()))

inf=10**9+7
dp=[inf]*N
dp[0]=0

for i in range(1,N,1):
    for k in range(1,K+1,1):
        if(i-k<0):
            continue
        dp[i]=min(dp[i],dp[i-k]+abs(h[i]-h[i-k]))
print(dp[N-1])
### BUGGY CODE ###

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

R = S.count('R')
G = S.count('G')
B = S.count('B')

ans = R * G * B

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

print(ans)

### FIXED CODE ###

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

R = S.count('R')
G = S.count('G')
B = S.count('B')

ans = R * G * B

for i in range(N):
    for j in range(i + 1, N):
        if S[i] != S[j]:
            k = 2 * j - i
            if k >= N:
                break
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                ans -= 1

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

N, K = map(int, input().split())
P = 10**9+7
R = int(N**0.5)+1
A = [i for i in range(R)] + [N//i for i in range(1, R)][::-1]
M = len(A)
X = [0] + [1] * (M-1)
for i in range(1, K+1):
    NX = [0] * M
    for j in range(1, M):
        NX[j] = (NX[j-1] + X[M-j]*(A[j]-A[j-1])) % P
    X = NX
print(X[-1])

### FIXED CODE ###

N, K = map(int, input().split())
P = 10**9+7
R = int(N**0.5)+1
A = [i for i in range(R)] + [N//i for i in range(1, R)][::-1]
M = len(A)
X = [0] + [1] * (M-1)
for i in range(1, K+1):
    NX = [0] * M
    for j in range(1, M):
        NX[j] = (NX[j-1] + X[M-j]*(A[j]-A[j-1])) % P
    X = NX
print(X[-1])
### BUGGY CODE ###

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

def gcd(a,b):
  while b != 0:
    a, b = b, a % b
  return a

l_ans = []
for i in range(n):
    g = 0
    for j in range(i):
        g = gcd(g, v[j])
    l_ans.append(g)
r_ans = []
for i in range(n):
    g = 0
    for j in range(i):
        g = gcd(g, v[n-1-j])
    r_ans.append(g)
r_ans.reverse()
ans = 1
for i in range(n):
    ans = max(ans, gcd(l_ans[i], r_ans[i]))
print(ans)


### FIXED CODE ###

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

def gcd(a,b):
  while b != 0:
    a, b = b, a % b
  return a

l_ans = [0] * n
g = 0
for i in range(1, n):
    g = gcd(g, v[i-1])
    l_ans[i] = g
r_ans = [0] * n
g = 0
for i in range(1, n):
    g = gcd(g, v[n-i])
    r_ans[i] = g
r_ans.reverse()
ans = 1
for i in range(n):
    ans = max(ans, gcd(l_ans[i], r_ans[i]))
print(ans)
### BUGGY CODE ###

import numpy as np
n=int(input())
s=list(input())
sr=[0]*n
sg=[0]*n
sb=[0]*n
for ii in range(n):
    if s[ii]=="R":
        sr[ii]=1
    if s[ii]=="G":
        sg[ii]=1
    if s[ii]=="B":
        sb[ii]=1

r=0
"""
print(sr)
print(sg)
print(sb)
"""
gb=[0]*n
bg=[0]*n
rb=[0]*n
br=[0]*n
rg=[0]*n
gr=[0]*n
for jj in np.arange(1,n-1):
    if sg[jj]>0:
        gb[jj]=sum(sb[jj+1:n])
        gr[jj]=sum(sr[jj+1:n])
    if sb[jj]>0:
        bg[jj]=sum(sg[jj+1:n])
        br[jj]=sum(sr[jj+1:n])
    if sr[jj]>0:
        rb[jj]=sum(sb[jj+1:n])
        rg[jj]=sum(sg[jj+1:n])

for ii in np.arange(1,n-1):
  for jj in np.arange(ii+1,n):
    if s[ii-1]!=s[jj-1] and jj<n:
        kk=2*jj-ii-1
        if (s[ii-1]=="R" and s[jj-1]=="G") or (s[jj-1]=="R" and s[ii-1]=="G"):
            if s[ii-1]=="R":
                r+=gb[jj-1]
            if s[ii-1]=="G":
                r+=rb[jj-1]
            if kk<n:
                r-=sb[kk]
        if (s[ii-1]=="R" and s[jj-1]=="B") or (s[jj-1]=="R" and s[ii-1]=="B"):
            if s[ii-1]=="R":
                r+=bg[jj-1]
            if s[ii-1]=="B":
                r+=rg[jj-1]
            if kk<n:
                r-=sg[kk]
        if (s[ii-1]=="B" and s[jj-1]=="G") or (s[jj-1]=="B" and s[ii-1]=="G"):
            if s[ii-1]=="B":
                r+=gr[jj-1]
            if s[ii-1]=="G":
                r+=br[jj-1]
            if kk<n:
                r-=sr[kk]
        """
      for kk in np.arange(jj+1,n+1):
        #print(ii,jj,kk)
        if jj-ii!=kk-jj:
          if s[jj-1]!=s[kk-1] and s[ii-1]!=s[kk-1]:
            r+=1
        """
print(r)
    

### FIXED CODE ###

import numpy as np
n=int(input())
s=list(input())
sr=set()
sg=set()
sb=set()
for ii in range(n):
    if s[ii]=="R":
        sr.add(ii)
    if s[ii]=="G":
        sg.add(ii)
    if s[ii]=="B":
        sb.add(ii)
l=[len(sr),len(sg),len(sb)]
l.sort()

if l[0]==len(sr):
  s1=sr
  if l[1]==len(sg):
    s2=sg
    s3=sb
  else:
    s2=sb
    s3=sg
elif l[0]==len(sg):
  s1=sg
  if l[1]==len(sr):
    s2=sr
    s3=sb
  else:
    s2=sb
    s3=sr
else:
  s1=sb
  if l[1]==len(sr):
    s2=sr
    s3=sg
  else:
    s2=sg
    s3=sr
  
r=0
for ii in s1:
  for jj in s2:
    r+=len(s3)
    dt=abs(ii-jj)
    if ii+dt in s3:
      r-=1
    if ii-dt in s3:
      r-=1
    if jj+dt in s3:
      r-=1
    if jj-dt in s3:
      r-=1
    if (ii+jj)%2==0:
      if (ii+jj)//2 in s3:
        r-=1
      
print(r)
### BUGGY CODE ###

N=int(input())
S=input()
#print(N,S)

pins=list()

for i in range(N-1):
  for j in range(i+1,N):
    for k in range(j+1,N):
     pins.append(S[i]+S[j]+S[k])
   #print(set(S[j+1:]))
  
print(len(set(pins)))

### FIXED CODE ###

N=int(input())
S=input()
#print(N,S)

count=0


for n1 in range(10):
 cond=0
 for i in range(N-2):
   if n1==int(S[i]):
      p1=i
      cond=1
      break
 if cond==1:
  for n2 in range(10):
    for j in range(p1+1,N-1):
      if n2==int(S[j]):
        p2=j
        cond=2
        break
    if cond==2:
     for n3 in range(10):
       #print(n3,S[p2+1:],str(n3) in S[p2+1:] )
       if str(n3) in S[p2+1:]:
        #print(n1,n2,n3)
        count+=1
        cond=0
      
              
print(count)