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

n=int(input())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
def bitsum(BIT,i):
  s=0
  while i>0:
    s+=BIT[i]
    i-=i&(-i)
  return s

def bitadd(BIT,i,x):
  while i<=2**n:
    BIT[i]+=x
    i+=i&(-i)
  return BIT

def tentou(X):
  ret=0
  BIT=[0]*nn
  BIT.insert(0,0)
  for i1 in range(n):
    x=X[i1]+1
    ret+=i1-bitsum(BIT,x)
    bitadd(BIT,x,1)
  return ret

nn=2**n
ans=float("inf")
for i in range(nn):
  E,O=[],[]
  for j in range(n):
    if i&(1<<j)==0:
      if j%2==0:
        E.append(A[j]*100+j)
      else:
        O.append(A[j]*100+j)
    else:
      if j%2==0:
        O.append(B[j]*100+j)
      else:
        E.append(B[j]*100+j)
  if len(E)!=(n+1)//2:
    continue
  else:
    E.sort()
    O.sort()

    chk=True
    C=[E[0]%100]
    prev=E[0]//100
    for i in range(1,n):
      ii=i//2
      if i%2==0:
        C.append(E[ii]%100)
        if E[ii]//100<prev:
          chk=False
          break
        else:
          prev=E[ii]//100
      else:
        C.append(O[ii]%100)
        if O[ii]//100<prev:
          chk=False
          break
        else:
          prev=O[ii]//100
    
  if chk:
    ans=min(ans,tentou(C))
print(-1 if ans==float("inf") else ans)



### FIXED CODE ###

import itertools
n=int(input())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
def bitsum(BIT,i):
  s=0
  while i>0:
    s+=BIT[i]
    i-=i&(-i)
  return s

def bitadd(BIT,i,x):
  while i<=64:
    BIT[i]+=x
    i+=i&(-i)
  return BIT

def tentou(X):
  ret=0
  BIT=[0]*64
  BIT.insert(0,0)
  for i1 in range(n):
    x=X[i1]+1
    ret+=i1-bitsum(BIT,x)
    bitadd(BIT,x,1)
  return ret
N=[int(i) for i in range(n)]
nn=2**n
ans=float("inf")
for _ in range(n//2+1):
  for com in itertools.combinations(N,2*_):
    i=0
    for ura in com:
      i+=2**ura
    E,O=[],[]
    for j in range(n):
      if i&(1<<j)==0:
        if j%2==0:
          E.append(A[j]*100+j)
        else:
          O.append(A[j]*100+j)
      else:
        if j%2==0:
          O.append(B[j]*100+j)
        else:
          E.append(B[j]*100+j)
    if len(E)!=(n+1)//2:
      continue
    else:
      E.sort()
      O.sort()

      chk=True
      C=[E[0]%100]
      prev=E[0]//100
      for i in range(1,n):
        ii=i//2
        if i%2==0:
          C.append(E[ii]%100)
          if E[ii]//100<prev:
            chk=False
            break
          else:
            prev=E[ii]//100
        else:
          C.append(O[ii]%100)
          if O[ii]//100<prev:
            chk=False
            break
          else:
            prev=O[ii]//100
    
    if chk:
      ans=min(ans,tentou(C))
print(-1 if ans==float("inf") else ans)
### BUGGY CODE ###

from collections import Counter

S = input()
n = len(S)

dp = [0]*(n+1)

dp[n-1] = int(S[-1])

for i in range(n-2,-1,-1):
    dp[i] = (dp[i+1]+(10**(n-i-1))*int(S[i]))%2019

ans = Counter(dp)
cnt = 0
for i in ans.values():
    cnt += i*(i-1)//2
    
print(cnt)


### FIXED CODE ###

from collections import Counter

S = input()
n = len(S)

dp = [0]*(n+1)

dp[n-1] = int(S[-1])

for i in range(n-2,-1,-1):
    dp[i] = (dp[i+1]+pow(10,n-i-1,2019)*int(S[i]))%2019

ans = Counter(dp)
cnt = 0
for i in ans.values():
    cnt += i*(i-1)//2
    
print(cnt)
### 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
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))
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 ###

import collections
n = int(input())
a = [int(i) for i in input().split()]
s = [sum(a[:i]) for i in range(1,n+1)]
c = collections.Counter(s)
d = [i*(i-1)//2 for i in c.values() if i>1]
print(sum(d)+c[0])


### FIXED CODE ###

import collections
n = int(input())
a = [int(i) for i in input().split()]
s = [a[0]]
for i in range(1,n):s.append(s[i-1]+a[i])
c = collections.Counter(s)
d = [i*(i-1)//2 for i in c.values()]
print(sum(d)+c[0])
### BUGGY CODE ###

def main():
    import sys
    input = sys.stdin.readline
    from collections import deque

    N = int(input())
    # 1-indexed
    A = [deque() for _ in range(N+1)]
    # O(N^2)
    for i in range(1,N+1):
        for j in input().split():
            A[i].append(int(j))

    # O(N)
    def is_not_empty():
        for x in A:
            if x:
                return True
        return False

    answer = 0
    while is_not_empty():
        played = set()
        for i in range(1,N+1):
            if i in played:
                continue
            if not A[i]:
                continue
            enemy = A[i].popleft()
            ME = A[enemy].popleft()
            if ME == i and not(enemy in played):
                played.add(ME)
                played.add(enemy)
            else:
                A[i].appendleft(enemy)
                A[enemy].appendleft(ME)
        if not played:
            print(-1)
            exit()
        answer += 1

    print(answer)

if __name__ == '__main__':
    main()

### FIXED CODE ###

# O(N)
def is_not_empty(A):
    for x in A:
        if x:
            return True
    return False

def main():
    import sys
    input = sys.stdin.readline
    from collections import deque

    N = int(input())
    # 1-indexed
    A = [deque() for _ in range(N+1)]
    # O(N^2)
    for i in range(1,N+1):
        for j in input().split():
            A[i].append(int(j))

    # 当日の参加者
    today = set()
    # 初日
    for i in range(1,N+1):
        # 既に参加した人はダメ
        if i in today:
            continue
        enemy = A[i].popleft()
        ME = A[enemy].popleft()
        if ME == i and not(enemy in today):
            today.add(ME)
            today.add(enemy)
        else:
            A[i].appendleft(enemy)
            A[enemy].appendleft(ME)
    # 初日に誰も試合できなかったとき
    if not today:
        print(-1)
        exit()

    # 前日の参加者
    yesterday = today
    # 日数
    answer = 1
    while is_not_empty(A):
        today = set()
        # 前日に試合した人は必ず次の日に試合する
        for i in yesterday:
            if not A[i]:
                continue
            if i in today:
                continue
            enemy = A[i].popleft()
            ME = A[enemy].popleft()
            if ME == i and not(enemy in today):
                today.add(ME)
                today.add(enemy)
            else:
                A[i].appendleft(enemy)
                A[enemy].appendleft(ME)
        if not today:
            print(-1)
            exit()
        answer += 1
        yesterday = today

    print(answer)

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

n,m = map(int, input().split())
ml = [[-1 for i in range(n)] for j in range(n)]

for i in range(m):
    l,r,d = map(int, input().split())
    l -= 1
    r -= 1
    if ml[l][l] == -1 and ml[r][r] == -1:
        ml[l][l] = 0
        ml[r][r] = d
    elif ml[l][l] != -1 and ml[r][r] == -1:
        ml[r][r] = d + ml[l][l]
    elif ml[l][l] == -1 and ml[r][r] != -1:
        ml[l][l] = ml[r][r] - d
    else:
        if ml[r][r] - ml[l][l] != d:
            print('No', flush=True)
            import sys
            sys.exit()

print('Yes', flush=True)


### FIXED CODE ###

import sys
n,m = map(int, input().split())

# it watches only end of union
# for i in range(m):
#     l,r,d = map(int, input().split())
#     if ml[l] == -1 and ml[r] == -1:
#         ml[l] = 0
#         ml[r] = d
#     elif ml[l] != -1 and ml[r] == -1:
#         ml[r] = d + ml[l]
#         if ml[r] > n:
#             print('R', i, ml[l], ml[r], flush=True)
#             print('No', flush=True)
#             sys.exit()
#     elif ml[l] == -1 and ml[r] != -1:
#         ml[l] = ml[r] - d
#         if ml[l] < 1:
#             print('L', i, ml[l], ml[r], flush=True)
#             print('No', flush=True)
#             sys.exit()
#     else:
#         if ml[r] - ml[l] != d:
#             print('B', i, l, ml[l], r, ml[r], d, flush=True)
#             print('No', flush=True)
#             sys.exit()
# print('Yes', flush=True)

class UnionfindWithWeight():
    def __init__(self,n):
        self.parents=[-1]*n
        self.ranks=[0]*n
        self.dist=[0]*n
    def find(self,x):
        if self.parents[x]<0:
            return self.dist[x],x
        else:
            tmp=self.find(self.parents[x])
            self.dist[x]+=tmp[0]
            self.parents[x]=tmp[1]
            return self.dist[x],self.parents[x]
    def union(self,x,y,d):
        rx=self.find(x)[-1]
        ry=self.find(y)[-1]
        diff=d+self.dist[x]-self.dist[y]
        if rx==ry:
            if diff!=0:
                return True
            return False
        if self.ranks[ry]>self.ranks[rx]:
            rx,ry=ry,rx
            diff=-diff
        self.parents[ry]=rx
        self.dist[ry]=diff
        if self.ranks[ry]==self.ranks[rx]:
            self.ranks[rx]+=1
        return False
lrd = []
for i in range(m):
    l,r,d = list(map(int, input().split()))
    lrd.append([l,r,d])
v=UnionfindWithWeight(n)
for i in lrd:
    l, r, d = i
    if v.union(l-1,r-1,d):
        print('No')
        import sys
        sys.exit()
print('Yes')
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import collections
# input
n = int(input())
s = []
for i in range(n):
    s.append(input())
c = collections.Counter(s)
# output
# print(c.most_common()[0][1])
# print(list(c))
#print(sorted([k for k, v in c.items() if v == c.most_common()[0][1]]))
for i in sorted([k for k, v in c.items() if v == c.most_common()[0][1]]):
    print(i)


### FIXED CODE ###

# -*- coding: utf-8 -*-
from collections import Counter
# input
n = int(input())
s = []
for i in range(n):
    s.append(input())
c = Counter(s)
# output
ma = c.most_common()[0][1]
o = [k for k, v in c.items() if v == ma]
o.sort()
print('\n'.join(o))
### BUGGY CODE ###

import sys
input = sys.stdin.readline
n = int(input())
a = [list(input().rstrip()) for i in range(n)]
ans = 0
for k in range(n):
    for i in range(n):
        for j in range(i+1,n):
            if a[(i+k)%n][j] != a[(j+k)%n][i]:
                break
        else:
            continue
        break
    else:
        ans += n
print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline
n = int(input())
a = [list(input().rstrip()) for i in range(n)]
ans = 0
for k in range(n):
    for i in range(n):
        for j in range(i+1,n):
            if a[(i+k)%n][j] != a[(j+k)%n][i]:
                break
        else:
            continue
        break
    else:
        ans += n
print(ans)
### BUGGY CODE ###

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

n,m = map(int,input().split())
A = [int(input()) for _ in range(m)] #壊れた階段

pos = 0
count = 1
dp = [0] * (n+1)
dp[0] = 1 #dp[i] i段目の時点での場合の数 dp[n]まで

for i in range(n):
    # dp[i] %= 1000000007
    if (i+1) in A and (i+2) in A:
        print(0)
        exit()
    if (i+1) not in A:
        dp[i+1] += dp[i]
    if (i+2) not in A and (i+2) <= n:
        dp[i+2] += dp[i]

print(dp[n] % 1000000007)

### FIXED CODE ###

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

MOD = 10 ** 9 + 7
n,m = map(int,input().split())
A = set(int(input()) for _ in range(m)) #壊れた階段

dp = [0] * (n+1)
dp[0] = 1

for i in range(1,n+1):
    if i in A:
        continue
    x = dp[i-1]
    if i > 1:
        x += dp[i-2]
    dp[i] = x%MOD

print(dp[n])
### BUGGY CODE ###

a,b,c,d = map(int, input().split())
e = 0
for l in range(a,b+1):
    if l%c != 0 and l%d != 0:
        e += 1
print(e)

### FIXED CODE ###

def gcd(a,b):
    while b:a,b=b,a%b
    return a
def lcm(c,d):return c*d//gcd(c,d)
def div(x):
    num=x
    num-=x//C
    num-=x//D
    num+=x//lcm(C,D)
    return num
A,B,C,D=map(int,input().split())
print(div(B)-div(A-1))
### BUGGY CODE ###


import fractions as fr
from itertools import count

N = int(input())

for a in count(1):
  if (a*N)%(3*a-1) == 0:
    h = N
    n = a*N
    w = (a*N)//(3*a-1)
    print(h,n,w)
    break

### FIXED CODE ###


import fractions as fr
from itertools import count,product
from math import ceil

N = int(input())

if N%2 == 0:
  print(N,N,N//2)
  exit()

for h in range(1,3501):
  if 4*h > N:
    a = N*h//(4*h-N)+1
    b = 3501
  else:
    a = 1
    b = N*h//(4*h-N)+1
  for n in range(a,b):
    if (N*h*n)%(4*h*n-N*h-N*n) == 0:
      print(h,n,(N*h*n)//(4*h*n-N*h-N*n))
      exit()
### BUGGY CODE ###

# C
from collections import Counter
 
def ana(first_word, second_word):
    def get_counter(s): return Counter(s.upper().replace(' ', ''))
    return get_counter(first_word) == get_counter(second_word)

n = int(input())
s = []*n
for i in range(n): s.append(input()) 

ans = 0
for i in range(n):
    for j in range(i+1,n):
        if ana(s[i], s[j]): ans += 1 
            
print(ans)


### FIXED CODE ###

# C
from collections import *

n = int(input())
dic = defaultdict(lambda: 0)
for i in range(n): dic["".join(sorted(input()))] += 1

ans = 0
for k,v in dic.items(): ans += v*(v-1)//2
print(ans)
### BUGGY CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# N = int(input())
# L = sorted(list(map(int, input().split())))
N = int(readline().strip())
L = sorted(list(map(int, read().strip().split())))


def f(v):
    left = 0
    right = N
    while left + 1 < right:
        x = (left + right) // 2
        if v > L[x]:
            left = x
        else:
            right = x
    return right


ans = 0
for i in range(N):
    for j in range(i + 1, N):
        idx = f(L[i] + L[j])
        # print('a, b, idx', a, b, idx)
        # idx = np.searchsorted(L, a + b, sorter=None)
        ans += idx - 1 - j
print(ans)


### FIXED CODE ###

from bisect import bisect_left

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

ans = 0
for i in range(N):
    for j in range(i + 1, N):
        a = L[i]
        b = L[j]
        idx = bisect_left(L, a + b)
        ans += idx - 1 - j
print(ans)
### BUGGY CODE ###

# seishin.py
N, M = map(int, input().split())
r_min = [0]*(N+1); r_max = [N+1]*(N+1)
g_min = [0]*(N+1); g_max = [N+1]*(N+1)
for i in range(M):
    l, r, x = map(int, input().split())

    # 仮定: R < G < B を元に各r,gの値の範囲を絞り込む(B = rになるため計算しない)
    if x == 1:
        # x = 1の時、あるrに紐づく全てのl_iについて G < l_i を満たす必要がある
        # => G < min(l_i) を満たせばよい
        g_max[r] = min(g_max[r], l-1)
    elif x == 2:
        # x = 2の時、あるrに紐づく全てのl_iについて R < l_i, l_i <= G を満たす必要がある
        # => R < min(l_i), max(l_i) <= G を満たせばよい
        g_min[r] = max(g_min[r], l)
        r_max[r] = min(r_max[r], l-1)
    elif x == 3:
        # x = 3の時、あるrに紐づく全てのl_iについて l_i <= R を満たす必要がある
        # =>  max(l_i) <= R を満たせばよい
        r_min[r] = max(r_min[r], l)

MOD = 10**9 + 7

#def check(r, g, k):
#    return (r_min[k] <= r <= r_max[k] and g_min[k] <= g <= g_max[k])

# 左からk個置いた時、各色の最右の位置を持ってbfs
# r < g < b(= k) を維持して計算していく
que = [{} for i in range(N+1)]
que[0][0, 0] = 1
for k in range(N-1):
    cur = que[k]
    nxt = que[k+1]
    get = nxt.get
    rm = r_min[k+1]; rM = r_max[k+1]
    gm = g_min[k+1]; gM = g_max[k+1]
    for key, val in cur.items():
        # r < g < b < k+1 の関係を元に次の状態に伝播
        r, g = key
        val %= MOD

        # 制約を満たす場合のみに伝播
        if gm <= k <= gM:
            if rm <= g <= rM:
                nxt[g, k] = get((g, k), 0) + val
            if rm <= r <= rM:
                nxt[r, k] = get((r, k), 0) + val
        if rm <= r <= rM and gm <= g <= gM:
            nxt[key] = get(key, 0) + val

rm = r_min[N]; rM = r_max[N]
gm = g_min[N]; gM = g_max[N]
ans = 0
for key, val in que[N-1].items():
    r, g = key
    if gm <= N-1 <= gM:
        ans += val*( (rm <= r <= rM) + (rm <= g <= rM) )
    if rm <= r <= rM and gm <= g <= gM:
        ans += val
    ans %= MOD

print(ans)

### FIXED CODE ###

MOD = 10**9 + 7
N, M = map(int, input().split())
S = [[N]*(N+1) for i in [0,1,2]]
T = [[0]*(N+1) for i in [0,1,2]]

C = [0]*(N+1)
for i in range(M):
    l, r, x = map(int, input().split())
    S[x-1][r] = min(S[x-1][r], l)
    T[x-1][r] = max(T[x-1][r], l)
    C[r] = 1

S0, S1, S2 = S
T0, T1, T2 = T

ok = 1
for i in range(N+1):
    if not T2[i] < S1[i] or not T1[i] < S0[i]:
        ok = 0
        break

if not ok:
    print(0)
    exit(0)


X = {(0, 0): 3}
for b in range(1, N):
    t2 = T2[b+1]; s1 = S1[b+1]; t1 = T1[b+1]; s0 = S0[b+1]
    check = lambda r, g: t2 <= r < s1 and t1 <= g < s0

    Z = [0]*(N+1)
    if C[b+1]:
        if t1 <= b < s0:
            for (r, g), v in X.items():
                if t2 <= g < s1:
                    # r <- b+1
                    Z[g] += v
                if t2 <= r < s1:
                    # g <- b+1
                    Z[r] += v
        X = {(r, g): v for (r, g), v in X.items() if t2 <= r < s1 and t1 <= g < s0}
    else:
        Z = [0]*(N+1)
        for (r, g), v in X.items():
            # r <- b+1
            Z[g] += v
            # g <- b+1
            Z[r] += v;
    for z, v in enumerate(Z):
        if v:
            X[z, b] = v % MOD
print(sum(X.values()) % MOD)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n-1):
    cnt = 1
    a_std = a[i]
    for j in range(i+1, n):
        if cnt == a_std + a[j]: ans += 1
        cnt += 1
print(ans)

### FIXED CODE ###

from collections import Counter
n = int(input())
a1, a2 = [], []
for idx, ai in enumerate(map(int, input().split())):
    a1.append(ai+idx)
    a2.append(idx-ai)
cnt = Counter(a2)
res = 0
for idx, i in enumerate(a1):
    cnt[a2[idx]] -= 1
    res += cnt[i]
print(res)
### BUGGY CODE ###

#dt = {} for i in x: dt[i] = dt.get(i,0)+1
#dt = {k:v for k,v in sorted(x.items(), key=lambda i: i[1])}
ipnl = lambda n: [int(input()) for _ in range(n)]
inp = lambda :int(input())
ip = lambda :[int(w) for w in input().split()]

n,m = ip()
graph = {i:[] for i in range(1,n+1)}
for i in range(m):
    a,b = ip()
    graph[a].append(b)
    graph[b].append(a)

start = 1
nodes = list(graph.keys())
d = {i:float('inf') for i in nodes}
parent = {i:-1 for i in nodes}
q = set([i for i in nodes])
vis = {i:1 for i in nodes}
d[start] = 0

while len(q):
    mn = float('inf')
    for v in nodes:
        if d[v] < mn and vis[v]:
            mn = d[v]
            u = v
    q.remove(u)
    vis[u] = 0
    for v in graph[u]:
        if d[u]+1 < d[v] and vis[v]:
            d[v] = d[u] + 1
            parent[v] = u

if float('inf') in list(d.values()):
    print("No")
    exit()
print("Yes")
for i in range(2,n+1):
    print(parent[i])







### FIXED CODE ###

#dt = {} for i in x: dt[i] = dt.get(i,0)+1
#dt = {k:v for k,v in sorted(x.items(), key=lambda i: i[1])}
ipnl = lambda n: [int(input()) for _ in range(n)]
inp = lambda :int(input())
ip = lambda :[int(w) for w in input().split()]

n,m = ip()
graph = {i:[] for i in range(1,n+1)}
for i in range(m):
    a,b = ip()
    graph[a].append(b)
    graph[b].append(a)

parent = {i:-1 for i in range(1,n+1)}
parent[1] = 0
q = [1]
while len(q):
    u = q.pop(0)
    for v in graph[u]:
        if parent[v] == -1:
            q.append(v)
            parent[v] = u

if -1 in list(parent.values()):
    print("No")
    exit()
print("Yes")
for i in range(2,n+1):
    print(parent[i])
### BUGGY CODE ###

S = input()
L = []
for i in S[::-1]:
    if i == "W":
        L.append(0)
    if i == "B":
        L = [ j+1 for j in L ]

print(sum(L))

### FIXED CODE ###

S = input()
L = [0]
for i in S[::-1]:
    if i == "W":
        L.append(0)
    if i == "B":
        L[-1] += len(L)-1 

print(sum(L))
### BUGGY CODE ###

import math
b = input()
a = int(b)

c = int(math.sqrt(a))

for i in range(1000000000):
    d = a / (c + i)
    if d.is_integer() == True:
        break

e = d + c + i - 2
print(int(e))


### FIXED CODE ###

import math
b = input()
a = int(b)

sqA = int(math.sqrt(a))

for i in range(10000000):
    d = a / (sqA - i)
    if d.is_integer() == True:
        break


e = d + sqA - i - 2

print(int(e))
### BUGGY CODE ###

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

cnt=0
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        else:
            if (a[i]%a[j])==0:
                cnt+=1
                break
ans=n-cnt
print(ans)

### FIXED CODE ###

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

l=[0]*(10**6+1)
ans=0
#print(l)
for i in a:
    if l[i]==0:
        for j in range(i,10**6+1,i):
            l[j]+=1
    else:
        l[i]+=1
for i in a:
    if l[i]==1:
        ans+=1
print(ans)
### BUGGY CODE ###

N = int(input())

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

answer=1
for i in range(N):
  answer = answer*A[i]

if answer>10**18:
  print(-1)
else:
  print(answer)

### FIXED CODE ###

N = int(input())

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

answer=1
if 0 in A:
  print(0)
else:
  for i in range(N):
    answer = answer*A[i]
    if answer>10**18:
      print(-1)
      break
  else:
    print(answer)
### BUGGY CODE ###

k, s = map(int, input().split())
cnt = 0
for x in range(k+1):
    for y in range(k+1):
        for z in range(k+1):
            if x+y+z == s:
                cnt += 1
            elif x+y+z > s:
                continue
print(cnt)


### FIXED CODE ###

k, s = map(int, input().split())
cnt = 0
for x in range(k+1):
    for y in range(k+1):
        if (0 <= s-x-y) and (s-x-y <= k):
            cnt += 1
print(cnt)
### BUGGY CODE ###

n,x,y = map(int,input().split())
ans=[0]*n
for i in range(1,n):
    for j in range(i+1,n+1):
        ans[min(abs(i-j),min(abs(i-x)+1+abs(j-y),abs(i-y)+1+abs(j-x)))]+=1
for i in range(1,n):
    print(ans[i])

### FIXED CODE ###

n,x,y = map(int,input().split())
ans=[0]*n
for i in range(1,n):
    for j in range(i+1,n+1):
        ans[min(j-i,abs(i-x)+1+abs(j-y))]+=1
for i in range(1,n):
    print(ans[i])
### BUGGY CODE ###

import itertools
from collections import Counter

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

C=Counter(S)
r = C['R']
g = C['G']
b = C['B']


cnt = r * g * b

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

cnt -= sum

print(cnt)

### FIXED CODE ###

import itertools
from collections import Counter

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

C=Counter(S)
r = C['R']
g = C['G']
b = C['B']


cnt = r * g * b

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

print(cnt)