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

input = raw_input

N,Q = map(int,input().split(" "))
s=list(input())
ju = []
for i in range(Q):
    ju.append(input().split(" "))

mem = [0] * N
def isdead(xp):
    if mem[xp] == 1:
        return True
    elif mem[xp] == 2:
        return False
    oxp = xp
    for i in range(Q):
        com = ju[i]
        if s[xp] == com[0]:
            if com[1] == "L":
                xp -= 1
            else:
                xp += 1
        if xp < 0 or xp > N-1:
            mem[oxp] = 1
            return True
    mem[oxp] = 2
    return False

def mid(x1,x2):
    return int((x1+x2)/2)

pf = 0
qf = N-1

p1 = 0
p3 = N-1
p2 = mid(p1,p3)
ap = -1
#left
while p1 != p2:
    if isdead(p2):
        p2,p3 = int((p1+p2)/2),p2
    else:
        pf = p1
        ap = p2
        break
#right
if ap == -1:
    while p2 != p3:
        if isdead(p2):
            p2,p1 = int((p2+p3)/2),p2
        else:
            ap = p2
            qf = p3
            break
if ap == -1:
    print(0)
    exit()

#left
p1 = pf
p3 = ap
p2 = mid(p1,p3)
while p3 - p1 != 1:
    if isdead(p2):
        p1,p2 = p2,mid(p2,p3)
    else:
        p2,p3 = mid(p1,p2),p2
if isdead(p1):
    p = p3
else:
    p = p1
#right
p1 = ap
p3 = qf
p2 = mid(p1,p3)
while p3 - p1 != 1:
    if isdead(p2):
        p2,p3 = mid(p1,p2),p2
    else:
        p1,p2 = p2,mid(p2,p3)
if isdead(p3):
    q = p1
else:
    q = p3


if p > q:
    print(0)
else:
    print(q-p+1)


### FIXED CODE ###

input = raw_input

N,Q = map(int,input().split(" "))
s=list(input())
ju = []
for i in range(Q):
    ju.append(input().split(" "))

def isdeadleft(xp):
    oxp = xp
    for i in range(Q):
        com = ju[i]
        if s[xp] == com[0]:
            if com[1] == "L":
                xp -= 1
            else:
                xp += 1
        if xp < 0:
            return True
        if xp > N-1:
            xp = N-1
    return False

def isdeadright(xp):
    oxp = xp
    for i in range(Q):
        com = ju[i]
        if s[xp] == com[0]:
            if com[1] == "L":
                xp -= 1
            else:
                xp += 1
        if xp < 0:
            xp = 0
        if xp > N-1:
            return True
    return False

def mid(x1,x2):
    return int((x1+x2)/2)

if isdeadleft(N-1) or isdeadright(0):
    print(0)
    exit()

#left
p1 = 0
p3 = N-1
p2 = mid(p1,p3)
while p3 - p1 != 1:
    if isdeadleft(p2):
        p1,p2 = p2,mid(p2,p3)
    else:
        p2,p3 = mid(p1,p2),p2
if isdeadleft(p1):
    p = p3
else:
    p = p1
#right
p1 = 0
p3 = N-1
p2 = mid(p1,p3)
while p3 - p1 != 1:
    if isdeadright(p2):
        p2,p3 = mid(p1,p2),p2
    else:
        p1,p2 = p2,mid(p2,p3)
if isdeadright(p3):
    q = p1
else:
    q = p3

if p > q:
    print(0)
else:
    print(q-p+1)
### BUGGY CODE ###

from fractions import gcd
from functools import reduce
import copy

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

valueList = []
maxList = []

g = a[0]
valueList.append(g)
g = a[1]
for k in range(1, n):
  g = gcd(g, a[k])
maxList.append(g)
  

for i in range(1,n):
  g = valueList[i-1]
  valueList.append(gcd(g, a[i]))
  for k in range(i+1, n):
    g = gcd(g, a[k])
  maxList.append(g)
    
print(max(maxList))



### FIXED CODE ###

from fractions import gcd
from functools import reduce
import copy

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

fValueList = []
lValueList = []
maxList = []

if n == 2:
  print(max(a[0], a[1]))
else:
  fValueList.append(a[0])
  lValueList.append(a[n-1])
  for i in range(1,n-1):
    g = fValueList[i-1]
    fValueList.append(gcd(g, a[i]))

  for i in range(1,n-1):
    g = lValueList[i-1]
    lValueList.append(gcd(g, a[n-1-i]))
  
  maxList.append(fValueList[n-2])
  maxList.append(lValueList[n-2])
  for k in range(n-2):
    g = gcd(fValueList[k], lValueList[n-3-k])
    maxList.append(g)
    
  print(max(maxList))
### BUGGY CODE ###

N, K = list(map(int, input().split()))
M = abs(N - K)
mini = M + 1

if (N%K == 0):
    print(0)
else:
    while (M < mini):
        mini = min(mini, M)
        M = abs(M - K)
    print(mini)


### FIXED CODE ###

N, K = list(map(int, input().split()))
M = abs(N - K)
mini = M + 1

if (not N < K):
    if (N%K == 0):
        print(0)
    else:
        M = (N % K)
        while (M < mini):
            mini = min(mini, M)
            M = abs(M - K)
        print(mini)

else:
    while (M < mini):
        mini = min(mini, M)
        M = abs(M - K)
    print(mini)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
ans = 1
for i in range(n):
    ans *= a[i]

if ans <= 10 ** 18:
    print(ans)
else:
    print(-1)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
if 0 in a:
    print(0)
else:
    ans = 1
    for i in range(n):
        ans *= a[i]
        if ans > 10 ** 18:
            print("-1")
            exit()
    print(ans)
### BUGGY CODE ###

n = int(input())
lst = list(map(int, input().split()))
mult = 1
i = 0

while i < len(lst):
    mult *= lst[i]
    i += 1

if mult <= 10 ** 18:
    print(mult)
else:
    print(-1)

### FIXED CODE ###

n = int(input())
lst = sorted(list(map(int, input().split())))
mult = 1

for i in lst:
    mult *= i
    if 10**18 < mult:
        print(-1)
        exit()
else:
    print(mult)
### BUGGY CODE ###

import bisect
import copy

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

for _ in range(m):
    a[n-1] //= 2
    if a[n-1] < a[n-2]:
        b = a[:n-1]
        bisect.insort(b,a[n-1])
        a = copy.deepcopy(b)
    
print(sum(a))

### FIXED CODE ###

import heapq

n,m = map(int,input().split())
a = list(map(int,input().split()))
for i in range(n):
    a[i] *= (-1)
heapq.heapify(a)

for i in range(m):
    b = heapq.heappop(a)
    b = - (b * (-1) // 2)
    heapq.heappush(a, b)
    
print(-sum(a))
### BUGGY CODE ###

a=int(input())
b=1
for i in range(1,a+1):
  b=b*i
print(b%1000000007)

### FIXED CODE ###

a=int(input())
b=1
for i in range(1,a+1):
  b=b*i
  if b>1000000007:
    b=b%1000000007
if b<1000000000:
  print(b)
else:
  print(b%1000000007)
### BUGGY CODE ###

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

while True:
    M = N-K
    if M<0:
        M=-M
    if M < N:
        N = M
    else:break

print(N)


### FIXED CODE ###

import math

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

while True:
    if N>K:
      N = abs(N%K)
    if abs(N-K) < N:
        N = abs(N-K)
        continue
    else:break

print(N)
### BUGGY CODE ###

S = input()
Q = int(input())

for _ in range(Q):
    ipt = input().split()
    if ipt[0] == "1":
        S = "".join(reversed(S))
    else:
        f = int(ipt[1])
        c = ipt[2]
        if f == 1:
            S = c + S
        else:
            S += c

print(S)

### FIXED CODE ###

from collections import deque

S = deque(input())
Q = int(input())

rev_stetus = False
for _ in range(Q):
    ipt = input().split()
    if ipt[0] == "1":
        rev_stetus = not rev_stetus
    else:
        f = int(ipt[1])
        c = ipt[2]
        if rev_stetus:
            if f == 1:
                S.append(c)
            else:
                S.appendleft(c)
        else:
            if f == 1:
                S.appendleft(c)
            else:
                S.append(c)

if rev_stetus:
    S.reverse()
    print("".join(S))
else:
    print("".join(S))
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
A_new=sorted(A)
n=0
sum_number=0
index=[]
number=[]
for i in range(N-1):
    if A_new[i]==A_new[i+1]:
        n=n+1
    else:
        sum_number=n*(n+1)/2+sum_number
        index.append(i)
        number.append(n+1)
        n=0
if n!=0:
    sum_number=n*(n+1)/2+sum_number
if all(number):
    number.append(n+1)
    index.append(N-1)
I=len(index)
for i in range(N):
    for s,S in enumerate(index):
        if A[i]==A_new[S]:
            L=s
            break
    print(int(sum_number+1-number[L]))


### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
number=[0]*(N+1)
all_sum=0
for i in A:
    number[i]+=1
for i in number:
    all_sum+=i*(i-1)/2
for i in range(N):
    print(int(all_sum-(number[A[i]]-1)))
### BUGGY CODE ###

s=input().rstrip().split(' ')
th=int(s[0])
tss=int(s[1])
ah=int(s[2])
ass=int(s[3])
I=0;
while(1):
    if ah!=0 and th!=0:
        if I%2==0:
            I+=1;
            ah-=tss;
        else:
            th-=ass
            I+=1;
    else:
        break;
if I%2==0:
    print("No")
else:
    print("Yes")

### FIXED CODE ###

s=input().rstrip().split(' ')
th=int(s[0])
tss=int(s[1])
ah=int(s[2])
ass=int(s[3])
I=0;
while(1):
    if ah>0 and th>0:
        if I%2==0:
            I+=1;
            ah-=tss;
        else:
            th-=ass
            I+=1;
    else:
        break;
if I%2==0:
    print("No")
else:
    print("Yes")
### BUGGY CODE ###

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

full_root = [0] + A + [0]
full_place = [abs(full_root[i] - full_root[i + 1]) for i in range(N + 1)]
# check
for ind in range(1, N + 1):
    if ind == 1:
        res = sum(full_place[2:])
    elif ind == N + 1:
        res = sum(full_place[:-2])
    else:
        res = sum(full_place[:ind - 1] + full_place[ind + 1:])

    print(res + abs(full_root[ind - 1] - full_root[ind + 1]))


### FIXED CODE ###

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

full_root = [0] + A + [0]
full_place = [abs(full_root[i] - full_root[i + 1]) for i in range(N + 1)]
full_res = sum(full_place)
# check
for ind in range(1, N + 1):
    res = full_res - sum(full_place[ind - 1:ind + 1]) + abs(full_root[ind - 1] - full_root[ind + 1])

    print(res)
### BUGGY CODE ###

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

ans = 1
for i in A:
  ans = ans * i
 
if ans > 1e18:
  print(-1)
else:
  print(ans)

### FIXED CODE ###

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

ans = 1

if 0 in A:
    print(0)
    exit()

for i in A:
    ans = ans * i
    if ans > 1e18:
        print(-1)
        exit()

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

N, Q = map(int, input().split())
S = input()
l = [0] * Q
r = [0] * Q
keyword = 'AC'

for i in range(Q):
    l[i], r[i] = map(int, input().split())
#    print(l[i], r[i])

for i in range(Q):
    sub_str = S[l[i]-1:r[i]]
#    print(sub_str)

    match = 0
    for j in range(len(sub_str)-1):
        two_char = sub_str[j:j+2]
        if two_char == keyword:
            match += 1
#        print('two char =', two_char)

    print(match)


### FIXED CODE ###

N, Q = map(int, input().split())
S = input()
t = [0] * (N + 1)

for i in range(N):
    t[i + 1] = t[i] + (1 if S[i: i + 2] == 'AC' else 0)
#    print(t[i])

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

from copy import deepcopy
from collections import deque
from functools import partial, lru_cache
from heapq import heappush, heappop

inputs = open(0).readlines()
n, k = map(int, inputs[0].split())
V = deque(map(int, inputs[1].split()))
W = []

def dfs(root, option, function):
    stack =[root]
    ans = 0
    while stack:
        current_node = stack.pop()
        ans = function(current_node, ans)
        for n in option(current_node):
            stack.append(n)
    return ans

def option(node, limit):
    i, j = node
    if i+j < limit:
        return ((i+1, j), (i, j+1))
    return tuple()

def function(node, ans, W, V, limit, memo):
    if node in memo:
        return max(ans, memo[node])
    i, j = node
    W_, V_ = map(deepcopy, (W, V))
    for _ in range(i):
        if V_:
            heappush(W_, V_.pop())
    for _ in range(j):
        if V_:
            heappush(W_, V_.popleft())
    score = sum(W_)
    for _ in range(min(limit-i-j, i+j)):
        if W_ and W_[0] < 0:
            score -= heappop(W_)
    memo[node] = score
    return max(ans, memo[node])

ans = dfs((0, 0), partial(option, limit=min(n, k)), partial(function, W=W, V=V, limit=k, memo={}))
print(ans)

### FIXED CODE ###

from collections import deque

inputs = open(0).readlines()
n, k = map(int, inputs[0].split())
V = deque(map(int, inputs[1].split()))
def calc(ii, jj, kk):
    W = []
    for i in range(ii):
        W.append(V[i])
    for j in range(jj):
        W.append(V[-j-1])
    W.sort(reverse=True)
    for _ in range(kk):
        if W[-1] < 0:
            W.pop()
    return sum(W)

ans = 0
for i in range(min(n, k)+1):
    for j in range(min(n, k)+1-i):
        for k_ in range(min(i+j, k+1-i-j)):
            ans = max(ans, calc(i, j, k_))
print(ans)
### BUGGY CODE ###

s = input()
print(sum(s[:i].count("B") for i in range(len(s)) if s[i]=="W"))

### FIXED CODE ###

c = b = 0
for s in input():
  c += b*(s=="W")
  b += s=="B"
print(c)
### BUGGY CODE ###

def main():
    n, k, q = map(int, input().split())
    a = []
    for i in range(q):
        a.append(int(input()))

    point = [k] * n

    for i in range(q):
        point = list(map(lambda x: x - 1, point))
        point[a[i]-1] += 1

    for i in range(n):
        if point[i] > 0:
            print("Yes")
        else:
            print("No")


if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    n, k, q = map(int, input().split())
    a = []
    for i in range(q):
        a.append(int(input()))

    point = [0] * n

    for i in range(q):
        # point = list(map(lambda x: x - 1, point))
        point[a[i]-1] += 1

    for i in range(n):
        if k - (q - point[i]) > 0:
            print("Yes")
        else:
            print("No")


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

import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
mod=10**9+7

N=int(input())
XY=[list(map(int,input().split())) for i in range(N-1)]

EDGELIST=[[] for i in range(N+1)]

for x,y in XY:
    EDGELIST[x].append(y)
    EDGELIST[y].append(x)

check=[0]*(N+1)

from collections import deque
start=N//2+1
QUE=deque([start])

EDGE1=[[] for i in range(N+1)]

while QUE:
    x=QUE.pop()
    if check[x]==1:
        continue

    for to in EDGELIST[x]:
        if check[to]==1:
            continue
        else:         
            QUE.append(to)
            EDGE1[x].append(to)

    check[x]=1
        

def ANS(n):
    if EDGE1[n]==[]:
        return 1,1
    else:
        b=1
        w=1
        for to in EDGE1[n]:
            x,y=ANS(to)
            b=b*y
            w=w*(x+y)

        return b%mod,w%mod

print(sum(ANS(start))%mod)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
mod=10**9+7

N=int(input())
XY=[list(map(int,input().split())) for i in range(N-1)]

EDGELIST=[[] for i in range(N+1)]

for x,y in XY:
    EDGELIST[x].append(y)
    EDGELIST[y].append(x)

check=[0]*(N+1)

from collections import deque
QUE=deque([1])

EDGE1=[[] for i in range(N+1)]

while QUE:
    x=QUE.pop()
    if check[x]==1:
        continue

    for to in EDGELIST[x]:
        if check[to]==1:
            continue
        else:         
            QUE.append(to)
            EDGE1[x].append(to)

    check[x]=1
        

def ANS(n):
    if EDGE1[n]==[]:
        return 1,1
    else:
        b=1
        w=1
        for to in EDGE1[n]:
            x,y=ANS(to)
            b=b*y%mod
            w=w*(x+y)%mod

        return b,w

print(sum(ANS(1))%mod)
### BUGGY CODE ###

k, q = map(int, input().split())
d = list(map(int, input().split()))
for _ in range(q):
  n, x, m = map(int, input().split())
  x %= m
  dmod = [di % m for di in d]
  quot = (n-1) // k
  rest = (n-1) % k
  same = dmod.count(0) * quot + dmod[:rest].count(0)
  a_last = x + sum(dmod) * quot + sum(dmod[:rest])
  beyond = a_last // m
  print(n - 1 - same - beyond)

### FIXED CODE ###

import numpy as np

k, q = map(int, input().split())
d = np.array(input().split(), dtype=np.int)
for _ in range(q):
  n, x, m = map(int, input().split())
  quot = (n-1) // k
  rest = (n-1) % k
  dmod = d % m
  same = (k - np.count_nonzero(dmod)) * quot + rest - np.count_nonzero(dmod[:rest])
  a_last = x % m + dmod.sum() * quot + dmod[:rest].sum()
  beyond = a_last // m
  print(n - 1 - same - beyond)
### BUGGY CODE ###

n, k = map(int,input().split())
h = list(map(int,input().split()))

dp = [float("inf")] * n
dp[0] = 0

for i in range(n-1):
    for j in range(1,k+1):
        if i+j <= n-1:
            dp[i+j] = min(dp[i] + abs(h[i] - h[i+j]), dp[i+j])
print(dp[n-1])

### FIXED CODE ###


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

dp = [float("inf")]*N 
dp[0] = 0

for i in range(N):
    for k in range(1,K+1):
        if i+k < N:
            dp[i+k] = min(dp[i+k],abs(h[i] - h[i+k]) + dp[i])

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

def main():
    s = input()
    l = [0 for _ in range(len(s))]
    for i in range(1, len(s) + 1):
        x = int(s[-i:])
        l[-i] = x % 2019

    ans = 0
    for x in set(l):
        y = l.count(x)
        ans += y * (y - 1) // 2
        if x == 0:
            ans += y
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    from collections import Counter
    s = input()

    n = 2019
    l = [0]
    t = 1
    for i, x in enumerate(s[::-1]):
        t = t * 10 % n
        y = (l[-1] + int(x) * t) % n
        l.append(y)

    c = Counter(l)
    ans = sum([v * (v - 1) // 2 for v in c.values()])
    print(ans)


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

a_list = list(input())
b_list = list(input())
c_list = list(input())
x=a_list.pop(0)
while True:
    if x=="a":
        if len(a_list)==0:
            print("A")
            break
        else:
            x = a_list.pop(0)
    elif x == "b":
        if len(b_list)==0:
            print("B")
            break
        else:
            x = b_list.pop(0)
    else:
        if len(c_list)==0:
            print("C")
        else:
            x = c_list.pop(0)
    

### FIXED CODE ###

a_list = list(input())
b_list = list(input())
c_list = list(input())
x=a_list.pop(0)
while True:
    if x=="a":
        if len(a_list)==0:
            print("A")
            break
        else:
            x = a_list.pop(0)
    elif x == "b":
        if len(b_list)==0:
            print("B")
            break
        else:
            x = b_list.pop(0)
    else:
        if len(c_list)==0:
            print("C")
            break
        else:
            x = c_list.pop(0)
### BUGGY CODE ###

def fib(n):
  if n ==1 or n == 0:
    return 1
  else:
    return fib(n-1) + fib(n-2)
  
print(fib(int(input())))

### FIXED CODE ###

n = int(input())

fib = [1]*(n+1)

for i in range(2,n+1):
    fib[i] = fib[i-1]+fib[i-2]
    
print(fib[n])
### BUGGY CODE ###

S=input()
Q=int(input())
query=[[i for i in input().split()] for _ in range(Q)]

rf=0
for q in query:
    if q[0] == "1":
        rf ^= 1
    else:
        if q[1] == '1':
            if rf:
                # S = S + q[2]
                S = ''.join([S, q[2]])
            else:
                # S = q[2] + S
                S = ''.join([q[2], S])
        else:
            if rf:
                S = ''.join([q[2], S])
            else: 
                S = ''.join([S, q[2]])
print(S[::-1] if rf else S)

### FIXED CODE ###

from collections import deque
S = deque([input()])
Q=int(input())
query=[[i for i in input().split()] for _ in range(Q)]

rf=0
for q in query:
    if q[0] == "1":
        rf ^= 1
    else:
        if q[1] == '1':
            if rf:
                S.append(q[2])
            else:
                S.appendleft(q[2])
        else:
            if rf:
                S.appendleft(q[2])
            else: 
                S.append(q[2])
print(''.join(S)[::-1] if rf else ''.join(S))
### BUGGY CODE ###

import itertools
import sys
from typing import Callable, NoReturn, Tuple


def main() -> NoReturn:
    readline: Callable[[], str] = sys.stdin.readline
    n, k = map(int, readline().rstrip().split())  # type: int,...
    p: Tuple[int] = tuple(int(_) for _ in readline().rstrip().split())

    if k < n // 2:
        answer: int = 10 ** 6
        for combinations in itertools.combinations(p, k):
            sum_of_comb: int = sum(combinations)
            if sum_of_comb < answer:
                answer = sum_of_comb
    else:
        not_chosen: int = 0
        for combinations in itertools.combinations(p, n - k):
            sum_of_comb: int = sum(combinations)
            if sum_of_comb > not_chosen:
                not_chosen = sum_of_comb
        answer: int = sum(p) - not_chosen

    print(answer)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import itertools
import sys
from typing import Callable, List, NoReturn


def main() -> NoReturn:
    readline: Callable[[], str] = sys.stdin.readline
    n, k = map(int, readline().rstrip().split())  # type: int,...
    p: List[int] = [int(_) for _ in readline().rstrip().split()]
    p.sort()
    print(sum(p[:k]))


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

n,m = map(int,input().split())
gate = [[int(i) for i in input().split()] for _ in range(m)]

p = [0] * (10**5)

for y in gate:
  p[y[0]-1:y[1]] = list(map(lambda x:x+1, p[y[0]-1:y[1]]))
  
cnt = 0

  
for z in range(n):
  if p[z] == m:
    cnt += 1
    
print(cnt)

### FIXED CODE ###

n,m = map(int,input().split())
gate = [[int(i) for i in input().split()] for _ in range(m)]

minv = gate[0][0]
maxv = gate[0][1]

for x in gate:
  minv = max(minv,x[0])
  maxv = min(maxv,x[1])
  
print(maxv-minv+1 if maxv-minv+1 >= 1 else 0)
### BUGGY CODE ###

#!/usr/bin/env pypy3
# n,m = map(int,sys.stdin.readline().split())
# a = list(map(int,sys.stdin.readline().split()))
# a = [sys.stdin.readline() for s in range(n)]
# s = sys.stdin.readline().rstrip()
# n = int(sys.stdin.readline())
# d = collections.defaultdict(list)
# import math
# from functools import reduce
import sys
sys.setrecursionlimit(15000)

n = int(sys.stdin.readline())
s = sys.stdin.readline().rstrip()
d = {"R":[],"G":[],"B":[]}
for i in range(n):
    d[s[i]].append(i)
s = 0
for a in d["R"]:
    for b in d["G"]:
        for c in d["B"]:
            if abs(a-b) != abs(b-c) and abs(a-c) != abs(c-b) and abs(b-a) != abs(a-c):
                s += 1
print(s)

### FIXED CODE ###

#!/usr/bin/env pypy3
# n,m = map(int,sys.stdin.readline().split())
# a = list(map(int,sys.stdin.readline().split()))
# a = [sys.stdin.readline() for s in range(n)]
# s = sys.stdin.readline().rstrip()
# n = int(sys.stdin.readline())
# d = collections.defaultdict(list)
# import math
# from functools import reduce
import sys
sys.setrecursionlimit(15000)

n = int(sys.stdin.readline())
s = sys.stdin.readline().rstrip()
d = {"R":[],"G":[],"B":[]}
sb = set()
for i in range(n):
    d[s[i]].append(i)
    if s[i]=="B":
        sb.add(i)
s = 0
#s = sum(1 for a in d["R"] for b in d["G"] for c in d["B"] if abs(a-b) != abs(b-c) and abs(a-c) != abs(c-b) and abs(b-a) != abs(a-c))
#s = len(d["R"])*len(d["G"])*len(d["B"])-sum(1 for a in d["R"] for b in d["G"] for c in d["B"] if abs(a-b) == abs(b-c) or abs(a-c) == abs(c-b) or abs(b-a) == abs(a-c))
for a in d["R"]:
    for b in d["G"]:
        s += len(d["B"])
        if 2*b-a in sb:
            s -= 1
        if 2*a-b in sb:
            s -= 1
        if (a+b)%2 == 0 and (a+b)//2 in sb:
            s -= 1
print(s)
### BUGGY CODE ###

S = input()

ans_count = 0
for i in range(len(S)):
    s = S[i]
    if s=="W":
        cut_str = S[:i]
        b_count = cut_str.count("B")
        ans_count = ans_count + b_count

print(ans_count)


### FIXED CODE ###

S = input()

ans_count = 0
b_count = 0
for s in S:
    if s=="B":
        b_count = b_count + 1
    if s=="W":
        ans_count = ans_count + b_count

print(ans_count)