Harryxun/stf_run huggingface dataset:
n, m = input().split()
n = int(n)
m = int(m)
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]

s = 0

map = [[0 for i in range(n)] for j in range(m)]

yokomap = [0] * n
tatemap = [0] * m

for i in range(n-1):
    for j in range(m-1):
        yokomap = (i+1) * (n-1-i)
        tatemap = (j+1) * (m-1-j)
        map[i][j] = yokomap * tatemap

for i in range(n-1):
    for j in range(m-1):
        yoko = x[i+1] - x[i]
        tate = y[j+1] - y[j]
        s += yoko * tate * map[i][j]
        s %= (10**9 + 7)


print(s)


### FIXED CODE ###

n, m = input().split()
n = int(n)
m = int(m)
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]

def sum(a, n):
    sum_a = 0
    for i in range(0, n):
        sum_a += i * a[i] - (n-1-i) * a[i]
    return sum_a

sum_x = sum(x,n)
sum_y = sum(y,m)

s = sum_x * sum_y % (10**9 + 7)

print(s)
import sys

n = int(input())
sys.setrecursionlimit(10**10)



def count(num):
    if num > n:
        return 0
    fl = 0
    s = str(num)
    if '3' in s and '5' in s and '7' in s:
        fl = 1

    return fl + count(num*10+3) + count(num*10+5) + count(num*10+7)


print(count(0))

### FIXED CODE ###

import sys

n = int(input())
sys.setrecursionlimit(2*10**9+1)


def count(num):
    if num > n:
        return 0
    fl = 0
    s = str(num)
    if '3' in s and '5' in s and '7' in s:
        fl = 1

    return fl + count(num*10+3) + count(num*10+5) + count(num*10+7)


print(count(0))
n, q = map(int, input().split())

road = [[] for _ in range(n)]
cnt = [0 for _ in range(n)]

for i in range(n - 1):
    a, b = map(int, input().split())
    road[a - 1].append(b - 1)
    road[b - 1].append(a - 1)

for i in range(q):
    idx, v = map(int, input().split())
    cnt[idx - 1] += v

dist = [-1] * n
que = deque()
dist[0] = 0
que.append(0)

while(len(que) != 0):
    # BFS/DFS
    v = que.pop()
    for r in road[v]:
        if dist[r] != -1:
            continue
        # print(r, v)
        dist[r] = dist[v] + 1
        cnt[r] += cnt[v]
        que.append(r)
print(*cnt)


### FIXED CODE ###

from collections import deque
n, q = map(int, input().split())

road = [[] for _ in range(n)]
cnt = [0 for _ in range(n)]

for i in range(n - 1):
    a, b = map(int, input().split())
    road[a - 1].append(b - 1)
    road[b - 1].append(a - 1)

for i in range(q):
    idx, v = map(int, input().split())
    cnt[idx - 1] += v

dist = [-1] * n
que = deque()
dist[0] = 0
que.append(0)

while(len(que) != 0):
    # BFS/DFS
    v = que.pop()
    for r in road[v]:
        if dist[r] != -1:
            continue
        # print(r, v)
        dist[r] = dist[v] + 1
        cnt[r] += cnt[v]
        que.append(r)
print(*cnt)
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

import sys
input = sys.stdin.readline
n,m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]
uf = UnionFind(n)
for i in range(m):
    uf.union(a[i][0]-1,a[i][1]-1)
ans = 0
x = [True]*n
for i in range(n):
    if (x[i]==False):
        continue
    print(i)
    t = uf.members(i)
    ans = max(ans,len(t))
    for j in t:
        x[j] = False
print(ans)


### FIXED CODE ###

def pf(N):
    A = []
    while N % 2 == 0:
        A.append(2)
        N //= 2
    f = 3
    while f * f <= N:
        if N % f == 0:
            A.append(f)
            N //= f
        else:
            f += 2
    if N != 1:
        A.append(N)
    return A

n = int(input())
a = list(map(int, input().split()))
b = [0]*1000001
for i in range(n):
    x = pf(a[i])
    x = list(set(x))
    for j in x:
        b[j] += 1
#print(b)
tnp = 0
for i in range(1000001):
    if (b[i]>1):
        tnp += 1
        break
if (tnp==0):
    print("pairwise coprime")
    exit()
        
for i in range(1000001):
    if (b[i]==n):
        print("not coprime")
        exit()
print("setwise coprime")
import math

a,b,x = map(int,input().split())

q = a*b*b/(2*x)

print(math.degrees(math.atan(q))

### FIXED CODE ###

import math

a,b,x = map(int,input().split())

q = a*b*b/2/x
w = (2*b-2*x/a**2)/a

if 2*x/a/b <= a:
  print(math.degrees(math.atan(q)))
else:
  print(math.degrees(math.atan(w)))
def longest_common_subsequence(S, T):
    LS = len(S); LT = len(T)
    dp = [[0] * (LT + 1) for _ in range(LS + 1)]
    for i, s in enumerate(S):
        for j, t in enumerate(T):
            if s == t:
                dp[i + 1][j + 1] = dp[i][j] + 1
            else:
                dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j])
    return dp
    

def reconstruct_LCS(S, T, dp):
    tmp = []
    i, j = len(S), len(T)
    while i and j:
        if S[i - 1] == T[j - 1]:
            i, j = i - 1, j - 1
            tmp.append(S[i])
        elif dp[i][j] == dp[i - 1][j]:
            i -= 1
        else:
            j -= 1
    return ''.join(reversed(tmp))


s,t=input(), input()
print(reconstruct_LCS(s, t, LCS(s, t)))


### FIXED CODE ###

s=input()
t=input()
n=len(s)
m=len(t)
dp=[[0 for i in range(m+1)] for j in range(n+1)]
for i in range(n):
    for j in range(m):
        if s[i]==t[j]:
            dp[i+1][j+1]=dp[i][j]+1
        else:
            dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j])
ans = ''
while(dp[n][m]>0):
  if dp[n][m] == dp[n-1][m-1] +1 and dp[n][m] == dp[n-1][m] +1 and dp[n][m] == dp[n][m-1] +1:
    ans = ''.join([s[n-1],ans])
    n -= 1
    m -= 1
  elif dp[n-1][m] > dp[n][m-1]:
    n -= 1
  else:
    m -= 1
print(ans)
T, X = map(int, input().split(''))

print(T/X)

### FIXED CODE ###

T, X = [int(i) for i in input().split()]

print(T/X)
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys

class G(object):
    def __init__(self, i):
        self.paths = dict()

    def add(self, v, d):
        self.paths[v] = d

    def dist(self, g, s):
        if self is g:
            return s
        if g in self.paths:
            d = g.dist(g, s + self.paths[g])
            self.add(g, d)
            return d
        for k, v in self.paths.items():
            d = k.dist(g, s + v)
            if d >= 0:
                self.add(v, d)
                return d
        return -1

def main():
    (n, m) = tuple(map(int, input().split()))
    lrds = tuple(map(int, input().split()) for _ in range(m))

    g = dict()
    for lrd in lrds:
        (l, r, d) = lrd
        if l not in g:
            g[l] = G(l)
        if r not in g:
            g[r] = G(r)
        pd = g[l].dist(g[r], 0)
        if pd != -1 and pd != d or g[r].dist(g[l], 0) != -1:
            print('No')
            sys.exit()
        g[l].add(g[r], d)

    print('Yes')

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys

def main():
    n, m = map(int, sys.stdin.readline().split())
    lrds = ((map(int, line.split())) for line in sys.stdin.readlines())

    g = tuple([] for _ in range(n))
    x = [None] * n

    for l, r, d in lrds:
        l -= 1
        r -= 1
        g[l].append((r, d))
        g[r].append((l, -d))

    for i in range(n):
        if x[i] is not None:
            continue
        stack = [i]
        x[i] = 0
        while len(stack):
            v = stack.pop()
            for u, d in g[v]:
                if x[u] is None:
                    stack.append(u)
                    x[u] = x[v] + d

    for v in range(n):
        for u, d in g[v]:
            if x[v] + d != x[u]:
                print('No')
                sys.exit()

    print('Yes')

if __name__ == '__main__':
    main()
L=int(input())
max_vol=0
for i in range(1,L):
  for j in range(1,L-i):
    k=L-i-j
    vol=i*j*k
    max_vol=max(max_vol,vol)
print(max_vol)

### FIXED CODE ###

N,M = map(int,input().split())
if((N<=1)&(M<=1)):
  num=0
else:
  num=int(N*(N-1)/2)+int(M*(M-1)/2)
print(num)
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    def dfs(start, v, p, tot_d):
        for d, u in edge[v]:
            if u == p:
                continue
            if tot_d + d > l:
                dp[start][u] = min(dp[start][u], dp[start][v] + 1)
                tot_d = d
            else:
                dp[start][u] = min(dp[start][u], dp[start][v])
                tot_d += d
            dfs(start, u, v, tot_d)

    n, m, l = map(int, input().split())
    edge = [[] for _ in range(n)]
    for _ in range(m):
        a, b, c = map(int, input().split())
        if c > l:
            continue
        edge[a - 1].append([c, b - 1])
        edge[b - 1].append([c, a - 1])

    # dp[i][j]:iからスタートしてjに行くまでに補給する最小回数
    dp = [[f_inf] * n for _ in range(n)]
    for i in range(n):
        dp[i][i] = 0
        dfs(i, i, - 1, 0)

    q = int(input())
    for _ in range(q):
        s, t = map(int, input().split())
        dp[s - 1][t - 1] = min(dp[s - 1][t - 1], dp[t - 1][s - 1])
        if dp[s - 1][t - 1] == f_inf:
            print(-1)
        else:
            print(dp[s - 1][t - 1])
            

if __name__ == '__main__':
    resolve()


### FIXED CODE ###

import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, m, l = map(int, input().split())
    cost = [[f_inf] * n for _ in range(n)]
    for i in range(n):
        cost[i][i] = 0
    for _ in range(m):
        a, b, c = map(int, input().split())
        cost[a - 1][b - 1] = c
        cost[b - 1][a - 1] = c

    for k in range(n):
        for i in range(n):
            for j in range(n):
                cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])

    res = [[f_inf] * n for _ in range(n)]
    for i in range(n):
        for j in range(n):
            if cost[i][j] <= l:
                res[i][j] = 1

    for k in range(n):
        for i in range(n):
            for j in range(n):
                res[i][j] = min(res[i][j], res[i][k] + res[k][j])

    q = int(input())
    for _ in range(q):
        s, t = map(int, input().split())
        print(-1 if res[s - 1][t - 1] == f_inf else res[s - 1][t - 1] - 1)


if __name__ == '__main__':
    resolve()
a = input()
aa = int(a)
b = input()
bb = int(b)

cross = int(aa * bb)

cd = int(cross / 2)

if cd == 0:
    print("even")

if cd != 0:
    print("odd")

### FIXED CODE ###

a,b = map(int, input().split())
if (a * b) % 2 == 0:
  print('Even')
else:
  print('Odd')
import math

A = int(input())
B = int(input())

x = (B-1) / (A-1)

print(math.ceil(x))


### FIXED CODE ###

import math
A, B = list(map(int, input().split()))
print(math.ceil((B-1)/(A-1)))
N=int(input())
A=list(map(int, input().split))
A.sort()
print(A[N-1]-A[0])

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
sum1=0
sum2=0
for num in range(N):
  if num % 2 == 0:
    sum1 += A[num]
  else:
    sum2 += A[num]
print(sum1 - sum2)
import math
A, B, C, D = map(int, input().split())
sc = B//C - (A-1)//C
sd = B//D - (A-1)//D
scd = B//math.gcd(C, D) - (A-1)//math.gcd(C, D)
print(sc, sd, scd, B-A+1)
print(B-A+1 - sc - sd + scd)


### FIXED CODE ###

from fractions import gcd


def lcm(a, b):
    return (a*b)//gcd(a, b)


A, B, C, D = map(int, input().split())
sc = B//C - (A-1)//C
sd = B//D - (A-1)//D
scd = B//lcm(C, D) - (A-1)//lcm(C, D)
#print(B//lcm(C, D), (A-1)//lcm(C, D))
#print(sc, sd, scd, B-A+1)
print(B-A+1 - sc - sd + scd)
import math
N,K = map(int,imput().split())

def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

A = Base_10_to_n(N, K)
print(len(A))


### FIXED CODE ###

def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)
  
N,K = map(int,input().split())
A = Base_10_to_n(N, K)
print(len(A))
#!/usr/bin/python3

import math
import sys


DEBUG = False


def inp():
    return sys.stdin.readline().rstrip()


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


def solve(N, A):
    par = abs(A[0][0] + A[0][1]) % 2
    for (x, y) in A:
        if abs(x + y) % 2 != par:
            return None

    m = [1] * (10 + par)
    S = []

    for (x, y) in A:
        assert abs(x) <= 10
        assert abs(y) <= 10
        s = []
        if x >= 0:
            for _ in range(x):
                s.append('R')
        else:
            for _ in range(-x):
                s.append('L')

        if y >= 0:
            for _ in range(y):
                s.append('U')
        else:
            for _ in range(-y):
                s.append('D')

        while len(s) < len(m):
            s.append('R')
            s.append('L')

        S.append(''.join(s))

    return (m, S)


def main():
    N = int(inp())
    A = []
    for _ in range(N):
        x, y = [int(e) for e in inp().split()]
        A.append((x, y))

    ans = solve(N, A)
    if ans is None:
        print('-1')
        return

    m, s = ans
    print(len(m))
    print(*m)
    for t in s:
        print(t)


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/python3

import math
import sys


DEBUG = False


def inp():
    return sys.stdin.readline().rstrip()


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


def solve(N, A):
    par = abs(A[0][0] + A[0][1]) % 2
    for (x, y) in A:
        if abs(x + y) % 2 != par:
            return None

    M = [2 ** i for i in range(31, -1, -1)]
    if par == 0:
        M.append(1)
    S = []

    for x, y in A:
        u = x + y
        v = x - y
        if par == 0:
            u += 1
            v += 1

        s = []
        for i in range(32):
            if u > 0:
                uv = 1
                u -= M[i]
            else:
                uv = -1
                u += M[i]

            if v > 0:
                vv = 1
                v -= M[i]
            else:
                vv = -1
                v += M[i]

            if (uv, vv) == (-1, -1):
                s.append('L')
            elif (uv, vv) == (1, 1):
                s.append('R')
            elif (uv, vv) == (-1, 1):
                s.append('D')
            else:
                s.append('U')

        assert u == 0
        assert v == 0

        if par == 0:
            s.append('L')

        S.append(''.join(s))

    return (M, S)



def main():
    N = int(inp())
    A = []
    for _ in range(N):
        x, y = [int(e) for e in inp().split()]
        A.append((x, y))

    ans = solve(N, A)
    if ans is None:
        print('-1')
        return

    m, s = ans
    print(len(m))
    print(*m)
    for t in s:
        print(t)


if __name__ == '__main__':
    main()
n, m, l = [int(i) for i in input().split()]

A = []
B = []
C = []

for ni in range(n):
    A.append([int(i) for i in input().split()])

for mi in range(m):
    B.append([int(i) for i in input().split()])

for i in range(n):
    C.append([])
    for j in range(l):
        C[i].append(0)
        for k in range(m):
            C[i][j] += A[i][k] * B[k][j]
for li in range(l):
    print(" ".join([str(s) for s in C[li]]))

### FIXED CODE ###

n, m, l = [int(i) for i in input().split()]

A = []
B = []
C = []
for ni in range(n):
    A.append([int(i) for i in input().split()])

for mi in range(m):
    B.append([int(i) for i in input().split()])

for i in range(n):
    C.append([])
    for j in range(l):
        C[i].append(0)
        for k in range(m):
            C[i][j] += A[i][k] * B[k][j]

for ni in range(n):
    print(" ".join([str(s) for s in C[ni]]))
import numpy as np

N=int(input())
A=np.ones(N)
a=np.ones(N)

A=map(int,input().rstrip().split())


a=sorted(A,reverse=True)

a_product=1
flag_1e18=False
flag_0=False

if a[N-1]==0:
  flag_0=True

for i in range(0,N,1):
  a_product=a_product*a[i]
  if a_product>1e18:
    flag_1e18=True
    break
  else:
    continue
    
if flag_1e18==True and flag_0==False:
  print(-1)
elif flag_0==True:
  print(0)
else:
  print(A_product)
  


### FIXED CODE ###

import numpy as np

N=int(input())
A=np.ones(N)
a=np.ones(N)

A=map(int,input().rstrip().split())


a=sorted(A,reverse=True)

a_product=1
flag_1e18=False
flag_0=False

if a[N-1]==0:
  flag_0=True

for i in range(0,N,1):
  a_product=a_product*a[i]
  if a_product>1e18:
    flag_1e18=True
    break
  else:
    continue
    
if flag_1e18==True and flag_0==False:
  print(-1)
elif flag_0==True:
  print(0)
else:
  print(a_product)
n,a,b = map(int,input().split())
if a > b or (n == 1 and a != b):
    print(0)
else:
    print(len(list(range(a*(n-1)+b, a+(n-1)*b+1))))

### FIXED CODE ###

n,a,b = map(int,input().split())
if a == b:
    print(1)
elif n == 1 or a > b:
    print(0)
else:
    print((a+(n-1)*b) - (a*(n-1)+b) + 1)
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
a = 0
sum = 0
for i in range(N):
	A = list(map(int, input().split()))
    for j in range(M):
        sum += A[j] * B[j]
    if sum + C > 0:
        a += 1
        sum = 0
    else :
        sum = 0
print(a)

### FIXED CODE ###

N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = [list(map(int, input().split())) for i in range(N)]
a = 0
sum = 0
for i in range(N):
    for j in range(M):
        sum += A[i][j] * B[j]
    if sum + C > 0:
        a += 1
        sum = 0
    else :
        sum = 0
print(a)
x,a,b = list(map(int, input().split()))

if a>=b:
    print('delicious')
elif b-a =< x:
    print('safe')
else:
    print('dangerous')

### FIXED CODE ###

x,a,b = list(map(int, input().split()))

if a>=b:
    print('delicious')
elif b-a <= x:
    print('safe')
else:
    print('dangerous')
n,k = map(int,input().spolit())
print(n-k+1)

### FIXED CODE ###

n,k = map(int,input().split())
print(n-k+1)
import math
A,B,N = map(int,input().split())
maxi = -100000
Npower = 0
diff = 0
while N > 1:
    N /=10
    Npower += 1
if Npower >= 6:
  diff = N-1000
for i in range(diff,N+1):
    maxi = max(math.floor(A*i/B)-A*math.floor(i/B),maxi,0)
print(maxi)

### FIXED CODE ###

import math
from math import floor
A,B,N = map(int,input().split())
def f(x):
  return floor(A*x/B) - A*floor(x/B)
print(f(min(B-1,N)))
1,m1,h2,m2,k =(int(x) for x in input().split())  
 
hrtom= (h2-h1)
 
if (m2-m1 < 0) and (h2-h1 >=0) : 
    min = (h2-h1)*60 - (m2-m1) - k
    print(min)
    
elif (m2-m1 >= 0) and (h2-h1 >=0 ):
    min = (h2-h1)*60 + (m2-m1) - k 
    print(min)

elif (m2-m1 < 0) and (h2-h1) <=0 :
    min = (24-h1+h2)*60 - (m2-m1) -k 
    print(min) 
    
elif (m2-m1 >= 0) and (h2-h1) <=0 :
    min = (24-h1+h2)*60 + (m2-m1) -k 
    print(min) 
    
else:
    print('0')

### FIXED CODE ###

h1,m1,h2,m2,k =(int(x) for x in input().split())  
 
hrtom= (h2-h1)
 
if (m2-m1 < 0) and (h2-h1 >=0) : 
    min = (h2-h1)*60 + (m2-m1) - k
    print(min)
    
elif (m2-m1 >= 0) and (h2-h1 >=0 ):
    min = (h2-h1)*60 + (m2-m1) - k 
    print(min)

    

else:
    print('0')
import sys
n=int(input())
h=list(map(int,input().split()))
if h[0]>0:
  h[0]-=1
for i in range(1,n):
  if h[i-1]==h[i]:
    sonomama=1
  elif h[i]>[i-1]:
    h[i]-=1
  else:
    print("No")
	sys.exit()
print("Yes")
    

### FIXED CODE ###

import sys
n=int(input())
h=list(map(int,input().split()))
if h[0]>0:
  h[0]-=1
for i in range(1,n):
  if h[i-1]==h[i]:
    sonomama=1
  elif h[i]>h[i-1]:
    h[i]-=1
  else:
    print("No")
    sys.exit()
print("Yes")
import sys
input = sys.stdin.readline
n = int(input())
li = [[] for i in range(n)]

for i in range(n-1):
  a,b,dist = map(int,input().split())
  li[a-1].append((b-1,dist))
  li[b-1].append((a-1,dist))

q,k = map(int,input().split())
tdp = [-1]*n
tdp[k-1] = 0

def dfs(x):
  for node in li[x]:
    if tdp[node[0]] == -1:
      tdp[node[0]] = tdp[x] + node[1]
      dfs(node[0])

dfs(k-1)
for i in range(q):
  a,b = map(int,input().split())
  print(tdp[a-1]+tdp[b-1])

### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.readline
n = int(input())
li = [[] for i in range(n)]

for i in range(n-1):
  a,b,dist = map(int,input().split())
  li[a-1].append((b-1,dist))
  li[b-1].append((a-1,dist))

q,k = map(int,input().split())
tdp = [-1]*n
tdp[k-1] = 0

def dfs(x):
  for node in li[x]:
    if tdp[node[0]] == -1:
      tdp[node[0]] = tdp[x] + node[1]
      dfs(node[0])

dfs(k-1)
for i in range(q):
  a,b = map(int,input().split())
  print(tdp[a-1]+tdp[b-1])
from bisect import bisect_left

N = int(input())
S = input()
R = []
G = []
B = []

for idx, s in enumerate(S):
    if s == 'R':
        R.append(idx+1)
    if s == 'G':
        G.append(idx+1)
    if s == 'B':
        B.append(idx+1)
# print(R, G, B)

R0, G0, B0 = R, G, B

sum = 0

for i in range(6):
    if i == 0:
        R, G, B, temp = R0, G0, B0, 'B'
    elif i == 1:
        R, G, B, temp = R0, B0, G0, 'G'
    elif i == 2:
        R, G, B, temp = B0, R0, G0, 'G'
    elif i == 3:
        R, G, B, temp = B0, G0, R0, 'R'
    elif i == 4:
        R, G, B, temp = G0, R0, B0, 'B'
    elif i == 5:
        R, G, B, temp = G0, B0, R0, 'R'

    for s in R:
        idx1 = bisect_left(G, s)
        if idx1 > G[-1]:
            break
        for g in G[idx1:]:
            idx2 = bisect_left(B, g)

            if idx2 > B[-1]:
                break
            sum += len(B[idx2:])
            if 2 * g - s <= N:
                if S[2 * g - s - 1] == temp:
                    sum -= 1

print(sum)


### FIXED CODE ###

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

import sys
# 再起回数上限変更
# sys.setrecursionlimit(1000000)
from bisect import bisect_left

N = int(input())
S = input()
R = []
G = []
B = []

cnt_r, cnt_g, cnt_b = 0, 0, 0
for idx, s in enumerate(S):
    if s == 'R':
        R.append(idx+1)
        cnt_r += 1
    if s == 'G':
        G.append(idx+1)
        cnt_g += 1
    if s == 'B':
        B.append(idx+1)
        cnt_b += 1
# print(R, G, B)

if (cnt_r > 0) and (cnt_g > 0) and (cnt_b > 0):
    pass
else:
    print(0)
    sys.exit()

R0, G0, B0 = R, G, B

sum = 0

for i in range(6):
    if i == 0:
        R, G, B, temp = R0, G0, B0, 'B'
    elif i == 1:
        R, G, B, temp = R0, B0, G0, 'G'
    elif i == 2:
        R, G, B, temp = B0, R0, G0, 'G'
    elif i == 3:
        R, G, B, temp = B0, G0, R0, 'R'
    elif i == 4:
        R, G, B, temp = G0, R0, B0, 'B'
    elif i == 5:
        R, G, B, temp = G0, B0, R0, 'R'

    for s in R:
        if s > G[-1]:
            break
        idx1 = bisect_left(G, s)
        for g in G[idx1:]:
            if g > B[-1]:
                break
            idx2 = bisect_left(B, g)
            sum += len(B[idx2:])
            if 2 * g - s <= N:
                if S[2 * g - s - 1] == temp:
                    sum -= 1

print(sum)
N = int(input())
x = int(input())
y=x
cage = []
for i in range(N):
    nu = int(input())
    cage.append(nu)
ans=0
for i in range(N):
    ind = cage.index(min(cage))
    if(min(cage) > x):
        break
    x = x - min(cage)
    cage[ind] = y
    ans += 1
if x>0:
    ans = ans - 1
print(ans)

### FIXED CODE ###

N, x = map(int, input().split())
A = list(map(int, input().split()))
 
x_tmp = x
for i, Ai in enumerate(sorted(A)):
    x_tmp -= Ai
    if x_tmp == 0:
        ans = i + 1
        break
    elif x_tmp < 0:
        ans = i
        break
    else: continue
else: ans = i
 
print(ans)