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

n,m=map(int,input().split())
lr=[[int(i) for i in input().split()] for i in range(m)]
cnt=[i for i in range(lr[0][0],lr[0][1]+1)]
ans=len(cnt)
for i in range(m):
    cnt=list(set([i for i in range(lr[i][0],lr[i][1]+1)])&set(cnt))
    ans=len(cnt)
    if len(cnt)==0:
        ans=0
        break
print(ans)

### FIXED CODE ###

n,m=map(int,input().split())
lr=[[int(i) for i in input().split()] for i in range(m)]
l=lr[0][0]
r=lr[0][1]
ans=0
for i in range(1,m):
    l=max(l,lr[i][0])
    r=min(r,lr[i][1])
ans=r-l+1
if r<l:
    ans=0
print(ans)
### BUGGY CODE ###

n = int(input())
s = input()

out = 0

for i in range(n):
    for j in range(i+1,n):
        if s[i] == s[j]:
            continue
        for k in range(j+1,n):
            if j - i == k - j:
                continue
            elif s[i] == s[k]:
                continue
            elif s[j] == s[k]:
                continue
            else:
                out += 1
print(out)

### FIXED CODE ###

import math
N = int(input())
S = input()

R = len([s for s in S if s == "R"])
G = len([s for s in S if s == "G"])
B = len([s for s in S if s == "B"])

out = R * G * B
for i in range(N):
    intvl = math.ceil((N - i)/2)
    for j in range(1,intvl):
        if S[i] != S[i+j] and S[i+j] != S[i+2*j] and S[i] != S[i+2*j]:
            out -= 1
print(out)
### BUGGY CODE ###

import bisect

N=int(input())
D=[int(x) for x in input().split()]

D.sort()
total=0

for i in range(N-2):
    for j in range(i+1,N-1):
        total+= bisect.bisect_left(D[j+1:],D[i]+D[j])

print(total)

### FIXED CODE ###

import bisect

N=int(input())
D=[int(x) for x in input().split()]

D.sort()
total=0

for i in range(N-2):
    for j in range(i+1,N-1):
        total+=bisect.bisect_left(D,D[i]+D[j])-j-1

print(total)
### BUGGY CODE ###

n, q = map(int, input().split())
S = list(input())

for i in range(q):
  l, r = map(int, input().split())
  l = l-1
  r = r-1
  if r - l < 1:
    print(0)
  else:
    counter = 0
    for j in range(r - l):
      if S[l+j] == "A" and S[l+j+1] == "C":
        counter += 1
    print(counter)
    

### FIXED CODE ###

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

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

Simos = [0] * n
Simos[0] = Sev[0]
for i in range(1, n):
  Simos[i] = Simos[i-1] + Sev[i]
    
for i in range(q):
  l, r = map(int, input().split())
  l = l-1
  r = r-1
  r = r-1
  if l == 0:
    print(Simos[r])
  else:
    print(Simos[r] - Simos[l-1])
### BUGGY CODE ###

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

sum=0
mod = 1000000007

def permod(x):
  return x%mod
B = list(map(permod,A))

for i in range(1,N+1):
    for j in range(1,N+1):
        if i < j:
            sum += B[i-1]*B[j-1]
            sum = sum %mod
print(sum)

### FIXED CODE ###

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

mod= 10**9+7

A = sum(a)

ans=0

for i in a:
  A -= i
  A%=mod
  ans += A*i
  ans%=mod
print(ans)
### BUGGY CODE ###

S = input()

dp = [0] * 2019

for i in range(len(S)-1, -1, -1):
    dp[int(S[i:]) % 2019] += 1

ans = sum(x*(x-1)//2 for x in dp)
ans += dp[0]

print(ans)

### FIXED CODE ###

S = input()
S_reverse = S[::-1]

dp = [0] * 2019
now_mod = 0
digit = 1

for i_s in S_reverse:
    now_mod = (now_mod + int(i_s)*digit) % 2019
    digit = (digit*10) % 2019
    dp[now_mod] += 1

ans = sum(x*(x-1)//2 for x in dp)
ans += dp[0]

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

#d=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
#import numpy as np
#n=int(input())
#import fractions
#import math
#lis=list(input().split())
#lis=list(map(float,input().split()))
#n=int(input())
#S=input()

import itertools

lis=list(map(int,input().split()))
alist=[-1]
ans=1
for i in range(lis[1]):
    alist.append(int(input()))
alist.append(lis[0]+1)

for i in range(lis[1]+1):
    l=alist[i+1]-alist[i]-2
    tmp=0
    t=int((l+l%2)/2)
    h=int((l-l%2)/2)
    for j in range(h+1):
        tmp+=len(list(itertools.combinations(range(t+j),h-j)))
    ans=(ans*tmp)%((10**9)+7)
print(ans)


### FIXED CODE ###

lis=list(map(int,input().split()))
alist=[0]*(lis[0]+1)
for i in range(lis[1]):
    a=int(input())
    alist[a]=1
steps=[0]*(lis[0]+2)
steps[1]=1
mod=(10**9)+7
for i in range(2,lis[0]+2):
    if alist[i-1]==0:
        steps[i]=(steps[i-1]+steps[i-2])%mod
ans=steps[-1]
print(ans)
### BUGGY CODE ###

N, W = map(int, input().split())
w = [0] * N
v = [0] * N
for i in range(N):
    w[i], v[i] = map(int, input().split())

dp = [[0 for _ in range(W+1)] for _ in range(N+1)]

for i in range(N):
    for sum_w in range(W+1):
        if w[i] <= sum_w:
            dp[i+1][sum_w] = max(dp[i][sum_w], dp[i][sum_w-w[i]] + v[i])
        dp[i+1][sum_w] = max(dp[i][sum_w], dp[i+1][sum_w])

print(dp[N][W])

### FIXED CODE ###

dp = [[0] * 100100 for i in range(110)]

N, W = map(int, input().split())
w = [0] * N
v = [0] * N
for i in range(N):
    w[i], v[i] = map(int, input().split())

for i in range(1, N+1):
    for sum_w in range(W+1):
        if sum_w - w[i-1] >= 0:
            dp[i][sum_w] = max(dp[i][sum_w], dp[i-1][sum_w-w[i-1]] + v[i-1])
        
        dp[i][sum_w] = max(dp[i][sum_w], dp[i-1][sum_w])

print(dp[N][W])
### BUGGY CODE ###

def get_sieve_of_eratosthenes_new(n):
    import math
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = []
    limit = math.sqrt(n)
    data = [i + 1 for i in range(1, n)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]

primelist=get_sieve_of_eratosthenes_new(10**5)
subprimelist=[(primelist[i]+1)//2 for i in range(0,len(primelist))]
primeset=set(primelist)
subprimeset=set(subprimelist)
real=list(primeset&subprimeset)
real=[2*real[i]-1 for i in range(0,len(real))]
real=set(real)

Q=int(input())
l=[0]*Q
r=[0]*Q
for i in range(0,Q):
    l[i],r[i]=map(int,input().split())
for i in range(0,Q):
    test={i for i in range(l[i],r[i]+1)}
    print(len(test&real))


### FIXED CODE ###

def get_sieve_of_eratosthenes_new(n):
    import math
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = []
    limit = math.sqrt(n)
    data = [i + 1 for i in range(1, n)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]

primelist=get_sieve_of_eratosthenes_new(10**5)
subprimelist=[(primelist[i]+1)//2 for i in range(0,len(primelist))]
primeset=set(primelist)
subprimeset=set(subprimelist)
real=list(primeset&subprimeset)
real=[2*real[i]-1 for i in range(0,len(real))]
real.sort()

Q=int(input())
l=[0]*Q
r=[0]*Q
for i in range(0,Q):
    l[i],r[i]=map(int,input().split())
for i in range(0,Q):
    if r[i]<3 or l[i]>99877:
        print(0)
    else:
        s=0
        t=0
        start=0
        end=len(real)-1
        while end-start>1:
            test=(end+start)//2
            if real[test]>=l[i]:
                end=test
            else:
                start=test
        if real[start]>=l[i]:
            s=start
        else:
            s=end
        start=0
        end=len(real)-1
        while end-start>1:
            test=(end+start)//2
            if r[i]>=real[test]:
                start=test
            else:
                end=test
        if r[i]>=real[end]:
            t=end
        else:
            t=start
        print(t-s+1)
### BUGGY CODE ###

from collections import deque

H,W=map(int, raw_input().split() )
S=[ raw_input() for i in range(H) ] 


D=[ (1,0), (-1,0), (0,1), (0,-1) ] 


ret=0
q = deque([]) 
def dfs(x,y,current):
	ret=0
	V=[ [ 0 for i in range(W) ] for j in range(H) ]
	V[x][y]=1
	q.append( (x,y,current) )

	while q:
		x,y,current=q.popleft()

		for dx,dy in D:
			if 0<=x+dx<H and 0<=y+dy<W:
				next=S[x+dx][y+dy] 
				if V[x+dx][y+dy]==0 and current !=next:
						if next==".":  ret+=1
						V[x+dx][y+dy]=1
						q.append( (x+dx, y+dy,next) )

	return ret




ans=0
for x in range(H):
	for y in range(W):
		if S[x][y]=="#":
			ret=0
			q = deque([]) 
			ans+=dfs(x,y, "#")

print ans



### FIXED CODE ###

from collections import deque

H,W=map(int, raw_input().split() )
S=[ raw_input() for i in range(H) ] 


D=[ (1,0), (-1,0), (0,1), (0,-1) ] 


V=[ [ 0 for i in range(W) ] for j in range(H) ]


def dfs(x,y,current):
	bc=0	#black count
	wc=0	#white count
	q = deque([]) 
	V[x][y]=1
	q.append( (x,y,current) )

	while q:
		x,y,current=q.popleft()

		if current == "#":	  bc+=1
		else:  wc+=1

		for dx,dy in D:
			if 0<=x+dx<H and 0<=y+dy<W:
				next=S[x+dx][y+dy] 
				if V[x+dx][y+dy]==0 and current !=next:
						V[x+dx][y+dy]=1
						q.append( (x+dx, y+dy,next) )

	return bc*wc




ans=0
for x in range(H):
	for y in range(W):
		if S[x][y]=="#" and V[x][y]==0:
			ans+=dfs(x,y, "#")

print ans
### BUGGY CODE ###

N,Q = map(int,input().split())
S = input()
lr_lists = [list(map(int,input().split())) for i in range(Q)]

for i in range(Q):
    str = S[lr_lists[i][0] -1:lr_lists[i][1] ]
    print(str.count("AC"))

### FIXED CODE ###

N, Q = map(int,input().split())
S = input()

count_list = [0]*(N+1)

for i in range(N):
    if S[i:i+2] == 'AC':
        count_list[i+1] = count_list[i] + 1
    else:
        count_list[i+1] = count_list[i]

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

# string
# a, b, c = input().split()
# str_list = list(input().split())

# number
# a, b, c = map(int, input().split())
# num_list = list(map(int, input().split()))

# lows
# str_list = [input() for _ in range(n)]

# many inputs
# num_list = []
# for i in range(n): num_list.append(list(map(int, input().split())))

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

for i in range(n):
    p[i] -= 1

ans = int(-1e14)
for i in range(n):
    tmp = []
    cycle = 0
    index = i
    while True:
        index = p[index]
        tmp.append(c[index])
        cycle += c[index]
        if i == index:
            break
    
    l = len(tmp)
    t = 0
    for j in range(l):
        t += tmp[j]
        if j >= k:
            break
        cur = t
        if cycle > 0:
            e = int((k-j-1) / l)
            cur += e * cycle
        ans = max(cur, ans)
        
print(ans)


### FIXED CODE ###

# string
# a, b, c = input().split()
# str_list = list(input().split())

# number
# a, b, c = map(int, input().split())
# num_list = list(map(int, input().split()))

# lows
# str_list = [input() for _ in range(n)]

# many inputs
# num_list = []
# for i in range(n): num_list.append(list(map(int, input().split())))

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

for i in range(n):
    p[i] -= 1

ans = int(-1e14)
for i in range(n):
    tmp = []
    cycle = 0
    index = i
    while True:
        index = p[index]
        tmp.append(c[index])
        cycle += c[index]
        if i == index:
            break
    
    l = len(tmp)
    t = 0
    for j in range(l):
        t += tmp[j]
        if j >= k:
            break
        cur = t
        if cycle > 0:
            e = int((k-j-1) / l)
            cur += e * cycle
        ans = max(cur, ans)
        
print(ans)
### BUGGY CODE ###

N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i, a in enumerate(L[:N-2]):
  for j, b in enumerate(L[i+1:N-1]):
    for c in L[i+j+2:N]:
      if a + b > c:
        ans += 1
            
print(ans)

### FIXED CODE ###

from bisect import bisect_left

N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    ans += bisect_left(L, L[i]+L[j]) - (j + 1)

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

S = input()
Q = int(input())
ans = S
for i in range(Q):
    query = input().split()
    if (query[0] == "1"):
        ans = ans[::-1]
    if (query[0] == "2"):
        if (query[1] == "1"):
            ans = query[2] + ans
        if (query[1] == "2"):
            ans = ans + query[2]

print(ans)

### FIXED CODE ###

from collections import deque

S = input()
Q = int(input())
ans = deque()
ans.append(S)
turncnt = 0
for i in range(Q):
    query = input().split()
    if (query[0] == "1"):
        turncnt = turncnt + 1
    if (query[0] == "2"):
        if (query[1] == "1"):
            if (turncnt % 2 == 0):
                ans.appendleft(query[2])
            else:
                ans.append(query[2])
        if (query[1] == "2"):
            if (turncnt % 2 == 0):
                ans.append(query[2])
            else:
                ans.appendleft(query[2])

anstr = "".join(ans)
if (turncnt % 2 == 1):
    anstr = anstr[::-1]
print(anstr)
### BUGGY CODE ###

import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()
 
n,m = na()
a = na()
aa = [-i for i in a]
aa = sorted(aa)

import bisect

for i in range(m):
    b,c = na()
    k = bisect.bisect_right(aa,-c)
    if k < n:
      for j in range(min(b,n-k)):
        bisect.insort_right(aa,-c)

print(-sum(aa[:n]))

### FIXED CODE ###

import sys
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,m = na()
a = na()

bc = [na() for i in range(m)]
bc.sort(key=lambda x:x[1])

for b,c in bc[::-1]:
  a.extend([c]*b)
  if len(a)>2*n:
    break

a.sort(reverse=True)
print(sum(a[:n]))
### BUGGY CODE ###

s=input()
t=0
p=[0]*2019
for i,c in enumerate(s[::-1]):
  t+=int(c)*10**i
  t%=2019
  p[t]+=1
print(p[0]+sum((i*(i-1)//2) for i in p[1:]))

### FIXED CODE ###

s=input()
res=0
t=1
p=[0]*2019
for i in map(int,s[::-1]):
  res+=i*t
  res%=2019
  p[res]+=1
  t*=10
  t%=2019
print(p[0]+sum((i*(i-1)//2) for i in p))
### BUGGY CODE ###

def solve(n, s, MOD):
    d = 26
    ttt = [ord(c) - 97 for c in s]

    ttx = []
    c = 1
    for t in ttt[::-1]:
        ttx.append(t * c % MOD)
        c = c * d % MOD
    ttx.reverse()
    ttc = [0]
    for t in ttx:
        ttc.append((ttc[-1] + t) % MOD)

    for l in range(n // 2, 0, -1):
        appeared = []
        comparing = set()
        l2 = l * 2
        p = 1

        for i in range(l, n + 1):
            t = (ttc[i] - ttc[i - l]) * p % MOD
            if i >= l2:
                comparing.add(appeared[i - l2])
            if t in comparing:
                return l
            appeared.append(t)
            p = p * d % MOD

    return 0


n = int(input())
s = input()
print(min(solve(n, s, MOD) for MOD in (999999999989, 1000000000039)))


### FIXED CODE ###

def z_algorithm(s):
    n = len(s)
    prefix = [0] * n
    j = 0
    ret = 0
    for i in range(1, n):
        if i + prefix[i - j] < j + prefix[j]:
            prefix[i] = prefix[i - j]
        else:
            k = max(0, j + prefix[j] - i)
            while i + k < n and s[k] == s[i + k]:
                k += 1
            prefix[i] = k
            ret = max(ret, min(i, k))
            j = i
    return ret


n = int(input())
s = input()
print(max(z_algorithm(s[i:]) for i in range(n - 1)))
### BUGGY CODE ###

from functools import reduce

def main():
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]
    T = [
        ['d','r','e','a','m'],
        ['d','r','e','a','m','e','r'],
        ['e','r','a','s','e'],
        ['e','r','a','s','e','r']
    ]
    S = list(_ for _ in input())
    S.reverse()

    for i in range(4):
        T[i].reverse()
    while len(S)>0:
        tmp_S = S
        for i in range(4):
            if(S[0:len(T[i])] == T[i]):
                S = S[len(T[i]):len(S)]
                break
        if(tmp_S == S):
            break
    if(len(S)>0):
        print('NO')
    else:
        print('YES')

    
if __name__ == '__main__':
    main()


### FIXED CODE ###

from functools import reduce

def main():
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]
    T = [
        ['d','r','e','a','m'],
        ['d','r','e','a','m','e','r'],
        ['e','r','a','s','e'],
        ['e','r','a','s','e','r']
    ]
    S = list(_ for _ in input())
    S.reverse()

    for i in range(4):
        T[i].reverse()
    while len(S)>0:
        if(S[0:len(T[0])] == T[0]):
            for i in range(len(T[0])):
                S.pop(0)
        elif(S[0:len(T[1])] == T[1]):
            for i in range(len(T[1])):
                S.pop(0)
        elif(S[0:len(T[2])] == T[2]):
            for i in range(len(T[2])):
                S.pop(0)
        elif(S[0:len(T[3])] == T[3]):
            for i in range(len(T[3])):
                S.pop(0)
        else:
            print('NO')
            break
        
    if(len(S) ==0):
        print('YES')

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

X,Y,Z,K = map(int, input().split())
A = [int(i) for i in input().split()] 
B = [int(i) for i in input().split()] 
C = [int(i) for i in input().split()] 

ans = []
for x in range(X):
    for y in range(Y):
        for z in range(Z):
            ans.append(A[x]+B[y]+C[z])
ans.sort(reverse=True)
for k in range(K):
    print(ans[k])

### FIXED CODE ###

X,Y,Z,K = map(int, input().split())
A = [int(i) for i in input().split()] 
B = [int(i) for i in input().split()] 
C = [int(i) for i in input().split()] 

ans = []
for x in range(X):
    for y in range(Y):
        ans.append(A[x]+B[y])

ans.sort(reverse=True)
C.sort(reverse=True)
ans2 = []
for k in range(min(K,X*Y)):
    for z in range(min(Z,K)):
        ans2.append(ans[k]+C[z])
ans2.sort(reverse=True)

for k in range(K):
    print(ans2[k])
### BUGGY CODE ###

MOD = 10**9 + 7
P = 7 ** 21 + 52


def F(a, b):
    return (a * pow(b, P-2, P)) % P


def main():
    from collections import Counter
    import sys
    input = sys.stdin.buffer.readline
    N = int(input())
    T = [[int(i) for i in input().split()] for j in range(N)]
    A = []
    cnt_zero = [0, 0]  # 片方が0のとき
    p = 0  # 両方0
    cA = Counter()
    for a, b in T:
        if a == 0 and b == 0:
            p += 1
        elif a == 0:
            cnt_zero[0] += 1
        elif b == 0:
            cnt_zero[1] += 1
        else:
            A.append((F(a, b), -F(b, a) % P))
            cA[F(a, b)] += 1

    used = set()
    ans = 1
    ans *= pow(2, cnt_zero[0], MOD) - 1 + pow(2, cnt_zero[1], MOD) - 1 + 1
    for a, b in A:
        if a in used or b in used:
            continue
        ans *= pow(2, cA[a], MOD) - 1 + pow(2, cA[b], MOD) - 1 + 1
        ans %= MOD
        used.add(a)
        used.add(b)
    print((ans + p - 1) % MOD)


if __name__ == '__main__':
    main()


### FIXED CODE ###

MOD = 10**9 + 7
P = 7 ** 21 + 52


def F(a, b):
    return (a * pow(b, P-2, P)) % P


def main():
    from collections import Counter
    import sys
    input = sys.stdin.buffer.readline
    N = int(input())
    T = [[int(i) for i in input().split()] for j in range(N)]
    cnt_zero = [0, 0]  # 片方が0のとき
    p = 0  # 両方0
    cA = Counter()
    B = []
    used = set()
    for a, b in T:
        if a == 0 and b == 0:
            p += 1
        elif a == 0:
            cnt_zero[0] += 1
        elif b == 0:
            cnt_zero[1] += 1
        else:
            x = F(a, b)
            y = -F(b, a) % P
            cA[x] += 1
            if x not in used and y not in used:
                B.append((x, y))
                used.add(x)
                used.add(y)

    ans = 1
    ans *= pow(2, cnt_zero[0], MOD) - 1 + pow(2, cnt_zero[1], MOD) - 1 + 1
    for a, b in B:
        ans *= pow(2, cA[a], MOD) - 1 + pow(2, cA[b], MOD) - 1 + 1
        ans %= MOD
    print((ans + p - 1) % MOD)


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

c=[[int(i) for i in input().split()] for j in range(3)]
ans='No'
for x in range(101):
  for y in range(101):
    for z in range(101):
      d=[]
      d.append([c[0][j]-x for j in range(3)])
      d.append([c[1][j]-y for j in range(3)])
      d.append([c[2][j]-z for j in range(3)])
      if sum(len(set(d[i][j] for i in range(3))) for j in range(3))==3:
             ans='Yes'
print(ans)

### FIXED CODE ###

c=[[int(i) for i in input().split()] for j in range(3)]
ans='No'
for x in range(101):
  for y in range(101):
    for z in range(101):
      d=[]
      d.append([c[0][j]-x for j in range(3)])
      d.append([c[1][j]-y for j in range(3)])
      d.append([c[2][j]-z for j in range(3)])
      if sum(len(set(d[i][j] for i in range(3))) for j in range(3))==3:
             ans='Yes'
print(ans)
### BUGGY CODE ###

n=int(input())
s=input()
r=[0]*n
b=[0]*n
g=[0]*n
cb=0
cg=0
cr=0
for i in range(n-1,-1,-1):
  if s[i]=='R':
    cr+=1
  elif s[i]=='G':
    cg+=1
  else:
    cb+=1
  r[i]=cr
  g[i]=cg
  b[i]=cb
p=0
for i in range(n):
  for j in range(i+1,n-1):
    if( (s[i]=='R' and s[j]=='B') or (s[i]=='B' and s[j]=='R') ):
      p+=g[j+1]
      if j+(j-i)<n and s[j+(j-i)]=='G':
        p-=1
        
    if( (s[i]=='R' and s[j]=='G') or (s[i]=='G' and s[j]=='R') ):
      p+=b[j+1]
      if j+(j-i)<n and s[j+(j-i)]=='B':
        p-=1
     
    if( (s[i]=='G' and s[j]=='B') or (s[i]=='B' and s[j]=='G') ):
      p+=r[j+1]
      if j+(j-i)<n and s[j+(j-i)]=='R':
        p-=1
print(p)

### FIXED CODE ###

n=int(input())
s=input()
r=[0]*n
b=[0]*n
g=[0]*n
cb=0
cg=0
cr=0
for i in range(n-1,-1,-1):
  if s[i]=='R':
    cr+=1
  elif s[i]=='G':
    cg+=1
  else:
    cb+=1
  r[i]=cr
  g[i]=cg
  b[i]=cb
  
fr=[0]*n
fb=[0]*n
fg=[0]*n
cb=0
cg=0
cr=0
for i in range(n):
  if s[i]=='R':
    cr+=1
  elif s[i]=='G':
    cg+=1
  else:
    cb+=1
  fr[i]=cr
  fg[i]=cg
  fb[i]=cb
  
p=0
for i in range(1,n-1):
  if s[i]=='B':
    p+=fg[i-1]*r[i+1]+fr[i-1]*g[i+1]
    j=i-1
    k=i+1
    while (j>-1 and k<n):
      if (s[j]=='G' and s[k]=='R' or s[j]=='R' and s[k]=='G'):
        p-=1
      j-=1
      k+=1
      
  if s[i]=='G':
    p+=fb[i-1]*r[i+1]+fr[i-1]*b[i+1]
    j=i-1
    k=i+1
    while (j>-1 and k<n):
      if (s[j]=='B' and s[k]=='R' or s[j]=='R' and s[k]=='B'):
        p-=1
      j-=1
      k+=1
      
  if s[i]=='R':
    p+=fb[i-1]*g[i+1]+fg[i-1]*b[i+1]
    j=i-1
    k=i+1
    while (j>-1 and k<n):
      if (s[j]=='B' and s[k]=='G' or s[j]=='G' and s[k]=='B'):
        p-=1
      j-=1
      k+=1
  
print(p)