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

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

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

ans=R*G*B
if ans==0:
    print(0)
    exit()
    
    
for i in range(1,N-1):
    for j in range(i+1,N):
        if S[i-1]==S[j-1]:continue
        n=2*j-i
        if n>=N+1:continue
        if S[i-1]!=S[n-1] and S[j-1]!=S[n-1]:
            ans-=1

print(ans)

### FIXED CODE ###

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

Lis=[[] for _ in range(3)]
RGB="RGB"

for i in range(N):
    idx=RGB.index(S[i])
    Lis[idx].append(i+1)

if len(Lis[0])==0 or len(Lis[1])==0 or len(Lis[2])==0:
    print(0)
    exit()

Ng=len(Lis[2])
ans=0
for r in Lis[0]:
    for g in Lis[1]:
        n1=2*r-g
        n2=2*g-r
        n3=(r+g)//2
        Su=Ng
        if N>=n1>0:
            if S[n1-1]=="B":
                Su-=1
        if N>=n2>0:
            if S[n2-1]=="B":
                Su-=1
        if (g-r)%2==0:
            if S[n3-1]=="B":
                Su-=1
        ans+=Su
print(ans)
### BUGGY CODE ###


def resolve():
    MOD = 10 ** 9 + 7
    N = int(input())
    C = sorted(map(int, input().split()))
    P = [1] * (N + 1)
    for i in range(N):
        P[i + 1] *= P[i] * 2
    ans = 0
    for i in range(N):
        # 各ビットの係数: (2^r + 2^r-1 * r) * 2^l
        l, r = i, N - i - 1
        now = P[r]
        if r != 0:
            now += P[r - 1] * r % MOD
        now *= P[l]
        now *= C[i]
        ans += now % MOD
        ans %= MOD
    ans *= P[N]
    print(ans % MOD)


if __name__ == "__main__":
    resolve()

### FIXED CODE ###


def resolve():
    MOD = 10 ** 9 + 7
    N = int(input())
    C = sorted(map(int, input().split()))
    P = [1] * (N + 1)
    for i in range(N):
        P[i + 1] *= P[i] * 2
        P[i + 1] %= MOD
    ans = 0
    for i in range(N):
        # 各ビットの係数: (2^r + 2^r-1 * r) * 2^l
        l, r = i, N - i - 1
        now = P[r]
        if r != 0:
            now += P[r - 1] * r
        now *= P[l]
        now *= C[i]
        ans += now
        ans %= MOD
    ans *= P[N]
    print(ans % MOD)


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

#!/usr/bin/env python3
def main():
    N, K = map(int, input().split())
    A = [int(x) - 1 for x in input().split()]

    way = []
    now = 0
    for _ in range(K):
        if len(way) != len(set(way)):
            loop_start = way.index(now)
            loop = way[loop_start:]
            K -= len(way[:loop_start])
            now = loop[K % len(loop)]
            break
        way.append(now)
        now = A[now]
    print(now + 1)


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
def main():
    N, K = map(int, input().split())
    A = [int(x) - 1 for x in input().split()]

    way = []
    seen = [False for _ in [0] * (2 * 10 ** 5 + 1)]
    now = 0
    for _ in range(K):
        if seen[now]:
            loop_start = way.index(now)
            loop = way[loop_start:]
            K -= len(way[:loop_start])
            now = loop[K % len(loop)]
            break
        way.append(now)
        seen[now] = True
        now = A[now]
    print(now + 1)


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

N = int(input())
AList = [input() for i in range(N)]

resultCash = {}

for i in range(N) :
    if AList[i] not in resultCash :
        resultCash[AList[i]] = max(AList[0:i] + AList[i+1:N])
    print(resultCash[AList[i]])

### FIXED CODE ###

N = int(input())
AList = [int(input()) for i in range(N)]
max_AList = max(AList)
max2nd_AList = sorted(AList, reverse = True)[1]

for i in range(N) :
    if AList[i] == max_AList :
        print(max2nd_AList)
    else :
        print(max_AList)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
import collections

N, X, Y = map(int, input().split())

def bfs(i, j):
    dist = [-1]*N
    dist[i] = 0
    que = collections.deque([])
    que.append(i)
    
    while len(que) != 0:
        v = que.popleft()
        for nv in graph[v]:
            if dist[nv] != -1:continue
            dist[nv] = dist[v]+1
            if nv == j:break
            que.append(nv)
    return dist[j]

graph = {}
for i in range(N):
    graph[i] = set()

for i in range(N-1):
    graph[i].add(i+1)
    graph[i+1].add(i)
graph[X-1].add(Y-1)
graph[Y-1].add(X-1)

ans = [0]*N
for i in range(N):
    for j in range(i+1,N):
        d = bfs(i,j)
        ans[d] += 1
for i in range(N):
    if i == 0:continue
    print(ans[i])

### FIXED CODE ###

import sys
input = sys.stdin.readline
import collections

N, X, Y = map(int, input().split())

def dist(i,j):
    return min(abs(j-i), abs(X-i)+1+abs(j-Y))

ans = [0]*N
for i in range(N):
    for j in range(i+1, N):
        d = dist(i+1,j+1)
        ans[d] += 1
for i in range(N):
    if i == 0:
        continue
    print(ans[i])
### BUGGY CODE ###

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

S=""
count=-1

for i in range(K):
  S += "7"
  M = int(S)
  if( M%K == 0):
    count = i+1
    break

print(count)

### FIXED CODE ###

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

S=0
count=-1

for i in range(K):
  S = (S*10)%K
  S = (S+7)%K
  if( S == 0):
    count = i+1
    break

print(count)
### BUGGY CODE ###

from itertools import accumulate
N, K = map(int, input().split())
A = list(map(int, input().split()))


def calc_imos(arr):
    imos = [0] * (N + 1)
    for i, a in enumerate(arr):
        l = max(0, i - a)
        r = min(N - 1, i + a)
        imos[l] += 1
        imos[r + 1] -= 1
    imos = list(accumulate(imos))
    return imos[:-1]


for k in range(min(1000, K)):
    A = calc_imos(A)
print(*A, sep=' ')


### FIXED CODE ###

from itertools import accumulate
N, K = map(int, input().split())
A = list(map(int, input().split()))


def calc_imos(arr):
    imos = [0] * (N + 1)
    for i, a in enumerate(arr):
        l = max(0, i - a)
        r = min(N - 1, i + a)
        imos[l] += 1
        imos[r + 1] -= 1
    imos = list(accumulate(imos))
    return imos[:-1]


for k in range(min(50, K)):
    A = calc_imos(A)
print(*A, sep=' ')
### BUGGY CODE ###

S = input()
dp = [[0 for _ in range(13)] for _ in range(len(S))]
if S[0] == "?":
  for i in range(10):
    dp[0][i] = 1
else:
  dp[0][int(S[0])] = 1
#print(dp)
for i in range(len(S) - 1):
  if S[i + 1] == "?":
    for j in range(13):
      for k in range(10):
        dp[i + 1][(j * 10 + k) % 13] += dp[i][j]
  else:
    for j in range(13):
      dp[i + 1][(j * 10 + int(S[i + 1])) % 13] += dp[i][j] 
#print(dp)
print(dp[len(S) - 1][5] % (10 ** 9 + 7))

### FIXED CODE ###

S = input()
#S = "19?04??????451??" * (10 ** 5 // 5)
mod = 10 ** 9 + 7
dp = [[0 for _ in range(13)] for _ in range(len(S))]
if S[0] == "?":
  for i in range(10):
    dp[0][i] = 1
else:
  dp[0][int(S[0])] = 1
#print(dp)
for i in range(len(S) - 1):
  if S[i + 1] == "?":
    for j in range(13):
      for k in range(10):
        dp[i + 1][(j * 10 + k) % 13] += dp[i][j] % mod
  else:
    for j in range(13):
      dp[i + 1][(j * 10 + int(S[i + 1])) % 13] += dp[i][j] % mod
#print(dp)
print(dp[len(S) - 1][5] % (10 ** 9 + 7))
### BUGGY CODE ###

from collections import deque

def main():
    N,K=map(int,input().split())

    A=list(map(lambda x:int(x)-1,input().split()))

    loop=[]

    slack_que=deque([])
    flag=0
    t=0
    start=0
    while flag==0:
        slack_que.append(t)
        t=A[t]
        slack_que.append(t)
        ind=slack_que.index(t)
        if (ind!=len(slack_que)-1):
            start=ind
            flag=1
        slack_que.pop()

    slack=list(slack_que)
    slack_num=start
    loop_num=len(slack)-slack_num

    # print(slack)
    # print(start)
    # print(slack_num)
    # print(loop_num)
    #
    loop=slack[start:]
    # print(loop)
    if (K-slack_num)<0:
        res=slack[K]+1
    else:
        tele_num=((K-slack_num)%loop_num)
        town=loop[tele_num]
        res=town+1

    print(res)

if __name__=="__main__":
    main()



### FIXED CODE ###

from collections import deque

def main():
    N,K=map(int,input().split())

    A=list(map(lambda x:int(x)-1,input().split()))
    FootPrintA=A[:]

    loop=[]

    slack_que=deque([])
    flag=0
    t=0
    start=0
    while flag==0:
        slack_que.append(t)
        t_ = FootPrintA[t]
        FootPrintA[t]=-1
        if t_==-1:
            start=slack_que.index(t)
            flag=1
            slack_que.pop()
        t = A[t]

    slack=list(slack_que)
    slack_num=start
    loop_num=len(slack)-slack_num

    # print(slack)
    # print(start)
    # print(slack_num)
    # print(loop_num)
    #
    loop=slack[start:]
    # print(loop)
    if (K-slack_num)<0:
        res=slack[K]+1
    else:
        tele_num=((K-slack_num)%loop_num)
        town=loop[tele_num]
        res=town+1

    print(res)

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

from collections import defaultdict
def main():
    s = list(input())
    n = len(s)
    for i in range(n):
        s[i] = int(s[i])
    dp = [0 for _ in range(2019)]
    dp[0] += 1
    x = 0
    for i in range(n):
        x = x+s[n-1-i]*(10**i)
        dp[x%2019] += 1
    ans = 0
    for i in range(2019):
        ans += (dp[i]*(dp[i]-1))//2
    print(ans)

if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    s = input()
    n = len(s)
    dp = [0 for _ in range(2019)]
    dp[0] += 1
    x = 0
    for i in range(n):
        x = (x+int(s[n-1-i])*pow(10,i,2019))%2019
        dp[x] += 1
    ans = 0
    for i in range(2019):
        ans += (dp[i]*(dp[i]-1))//2
    print(ans)

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

from numpy import*
h,*s=open(0)
h,w=int32(h.split())
s=[[u>'#'for u in t]for t in s]
s,a,b,c,d=eval('int32(s),'*5)
for i in range(w):a[:,i],b[:,~i]=-~a[:,i-1]*s[:,i],-~b[:,-i]*s[:,~i]
for i in range(1,h):c[i,:],d[~i,:]=-~c[i-1,:]*s[i,:],-~d[-i,:]*s[~i,:]
print(amax(a+b+c+d)-3)

### FIXED CODE ###

def main():
    h,*s=open(0)
    h,w=map(int,h.split())
    a=tuple([0]*w for _ in range(h))
    b=tuple([0]*w for _ in range(h))
    c=tuple([0]*w for _ in range(h))
    d=tuple([0]*w for _ in range(h))
    for i in range(h*w):
        i,j=divmod(i,w)
        a[i][j]=a[i][j-1]+1if s[i][j]=='.'else 0
        b[i][~j]=b[i][-j]+1if s[i][-j-2]=='.'else 0
        c[i][j]=c[i-1][j]+1if s[i][j]=='.'else 0
        d[~i][j]=d[-i][j]+1if s[~i][j]=='.'else 0
    print(max(a[i][j]+b[i][j]+c[i][j]+d[i][j]-3for i in range(h)for j in range(w)))
main()
### BUGGY CODE ###

n = int(input())
A = list(map(int,input().split()))
ans = []

for i in range(n):
    tmp = A.index(i+1)
    ans.append(tmp+1)
    
print(' '.join([str(n) for n in ans]))

### FIXED CODE ###

n = int(input())
A = list(map(int,input().split()))
ans = [0]*n

for i,j in enumerate(A):
    ans[j-1] = i+1    
print(' '.join([str(n) for n in ans]))
### BUGGY CODE ###

import operator as op

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

L = [0] * N

for a in A:
    L[a-1] = A.index(a) + 1

print(*L)


### FIXED CODE ###

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

L = [0] * N

for i, a in enumerate(A):
    L[a-1] = i + 1

print(*L)
### BUGGY CODE ###

N=int(input())
A=[list(map(int,input().split())) for i in range(N)]
from collections import defaultdict
d=defaultdict(int)
l=defaultdict(list)
for i in range(N):
    x,y=(i,A[i][0]-1) if i<A[i][0]-1 else (A[i][0]-1,i)
    d[(x,y)]+=1
    l[(x,y)].append(i)
p=[0]*N
r=0
while len(d)>0:
    r+=1
    f=0
    diff=defaultdict(int)
    for k in list(d.keys()):
        if d[k]==2:
            del d[k]
            for i in l[k]:
                p[i]+=1
                if p[i]>N-2:
                    continue
                x,y=(i,A[i][p[i]]-1) if i<A[i][p[i]]-1 else (A[i][p[i]]-1,i)
                diff[(x,y)]+=1
                l[(x,y)].append(i)
            f=1
    for x,y in diff.keys():
        d[(x,y)]+=diff[(x,y)]
    if f==0:
        break
print(r if f>0 else -1)

### FIXED CODE ###

N=int(input())
A=[list(map(int,input().split())) for i in range(N)]
from collections import defaultdict
d=defaultdict(int)
l=defaultdict(list)
for i in range(N):
    x,y=(i,A[i][0]-1) if i<A[i][0]-1 else (A[i][0]-1,i)
    d[(x,y)]+=1
    l[(x,y)].append(i)
p=[0]*N
r=0
cand=list(d.keys())
while len(d)>0:
    r+=1
    f=0
    diff=defaultdict(int)
    for k in cand:
        if d[k]==2:
            del d[k]
            for i in l[k]:
                p[i]+=1
                if p[i]>N-2:
                    continue
                x,y=(i,A[i][p[i]]-1) if i<A[i][p[i]]-1 else (A[i][p[i]]-1,i)
                diff[(x,y)]+=1
                l[(x,y)].append(i)
            f=1
    for x,y in diff.keys():
        d[(x,y)]+=diff[(x,y)]
    cand=diff.keys()
    if f==0:
        break
print(r if f>0 else -1)
### BUGGY CODE ###

import heapq
def SME(start,end):
    if end > N : end = N
    count = 0
    for i,x in enumerate(Whole[start:end]):
        heapq.heappush(A,[x,i])
    for j in range(start,end):
        a = heapq.heappop(A)
        if None not in ANS[a[1]:a[1]+L] : continue
        for i in range(L):
            idx = a[1] + i
            try :
                if ANS[idx] : continue
                else :
                    ANS[idx] = a[0]
                    count += 1
            except IndexError : continue
        if count > N * parameter : break
    for i in range(L):
        if ANS[i] : continue
        else : ANS[i] = min(Whole[:i+1])
    i = L
    while i < N :
        if None not in ANS[i:i+L//2+2] :
            i += L//10+2
            continue
        if ANS[i] : continue
        else: ANS[i] = min(Whole[i+1-L:i+1])
        i+=1
    return ANS
[N,L] = [int(x) for x in input().split()]
Whole = [int(x) for x in input().split()]
A = []
parameter = 0.999
ANS = [None]*N
ANS = SME(0, N)
for i in ANS[L-1:-1]:print(i, end=" ")
print(ANS[-1])

### FIXED CODE ###

def ascend(a,b):
    mini = min(A[a:a+L])
    ans[a] = mini
    for i in range(a+1,b):
        if A[i+L-1] <= mini : mini = A[i+L-1]
        elif A[i-1] == mini : mini = min(A[i:i+L])
        ans[i] = mini

def descend(a,b):
    mini = min(A[b-1:b+L-1])
    ans[b-1] = mini
    for i in range(b-2,a-1,-1):
        if A[i] <= mini : mini = A[i]
        elif A[i+L] == mini: mini = min(A[i:i+L])
        ans[i] = mini
    
[N,L] = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ans = [None]*(N-L+1)
count = 0;
if N > 10 ** 4:
    for i in range(100):
        if A[i+1] > A[i] : count += 1
    if count > 80 : descend(0, N-L+1)
    else : ascend(0,N-L+1)
else :
    ascend(0, N-L+1)
for i in ans[:-1] : print(i, end=" ")
print(ans[-1])
### BUGGY CODE ###

import sys
 
n=0
m=0
id_list=[]

n, m  = map(int, input().split())
for i in range(0, m):
  gate_min, gate_max = map(int, input().split())
  id_list.append([gate_min, gate_max])
 

result = 0
for i in range(1, n+1):
  is_passed = True
  for gate in id_list:
    if not((i >= gate[0]) and (i <= gate[1])) :
      is_passed = False
      break

  if is_passed:
    result = result + 1	
print(result)
sys.exit(0)

### FIXED CODE ###

import sys
n=0
m=0

n, m  = map(int, input().split())
_min, _max  = map(int, input().split())
for i in range(1, m):
  gate_min, gate_max = map(int, input().split())
  if (_max > gate_max):
    _max = gate_max
   
  if _min < gate_min:
    _min = gate_min
 
result_list = list(filter(lambda x : (_min <= x) and (x <= _max), range(1, n+1)))
result = len(result_list)

print(result)
sys.exit(0)
### BUGGY CODE ###

x,y,z,k=map(int,input().split())
a,b,c=[list(map(int,input().split())) for i in range(3)]
l=sorted([i+j for i in a for j in b])[:-k-1:-1]
maxl=sorted([i+j for i in l for j in c])[:-k-1:-1]
for a in maxl:
    print(a)


### FIXED CODE ###

x,y,z,k=map(int,input().split())
a,b,c=[sorted(list(map(int,input().split())),reverse=True) for i in range(3)]
L=[]
for i in range(x):
    for j in range(y):
        if (i+1)*(j+1)>k:
            break
        for m in range(z):
            if (i+1)*(j+1)*(m+1)>k:
                break
            else:
                L.append(a[i]+b[j]+c[m])
for i in sorted(L,reverse=True)[:k]:
    print(i)
### BUGGY CODE ###

import sys

s = input()
s_x = s.replace('x', '')

if len(s) == 1:
	print(0)
	sys.exit()

middle, mod = divmod(len(s_x),2)
middle += mod
if s_x[:middle] != s_x[::-1][:middle]:
	print(-1)
	sys.exit()

pali_orig = s_x[:middle]

x_count_l, x_count_r = [0]*middle, [0]*middle

i = 0
for c in range(middle):
	cnt = 0
	while s[i] != pali_orig[c]:
		cnt += 1
		i += 1
	x_count_l[c] = cnt
	i += 1

i = 0
for c in range(middle):
	cnt = 0
	while s[::-1][i] != pali_orig[c]:
		cnt += 1
		i += 1
	x_count_r[c] = cnt
	i += 1


ans = 0

for i in range(middle):
	ans += abs(x_count_l[i] - x_count_r[i])

print(ans)

### FIXED CODE ###

import sys

s = input()
s_x = s.replace('x', '')

if len(s) == 1:
	print(0)
	sys.exit()

middle, mod = divmod(len(s_x),2)
middle += mod
if s_x[:middle] != s_x[::-1][:middle]:
	print(-1)
	sys.exit()

x_count = []
cnt = 0
for i in range(len(s)):
	if s[i] != 'x':
		x_count.append(cnt)
		cnt = 0
	else:
		cnt += 1
x_count.append(cnt)

ans = 0
for i in range(len(x_count)):
	ans += abs(x_count[i] - x_count[-(1+i)])

print(ans//2)
### BUGGY CODE ###

import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy


def make_divisors(n):
    divisors = []
    for i in range(1,int(n**0.5)+1):
        if n%i == 0:
            divisors.append(i)
            if i != n//i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

if __name__ == "__main__":
    n = int(input())
    dp = [0]*(10**7+1)
    for i in range(1,n+1):
        for j in range(i,n+1,i):
            dp[j]+=1
    ans = 0
    for i in range(1,n+1):
        ans += i*dp[i]
    print(ans)

### FIXED CODE ###

import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy


def make_divisors(n):
    divisors = []
    for i in range(1,int(n**0.5)+1):
        if n%i == 0:
            divisors.append(i)
            if i != n//i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

if __name__ == "__main__":
    n = int(input())
    dp = [0]*(10**7+1)
    for i in range(1,n+1):
        for j in range(i,n+1,i):
            dp[j]+=1
    ans = 0
    for i in range(1,n+1):
        ans += i*dp[i]
    print(ans)
### BUGGY CODE ###

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

ans = 0
for i in range(N-1):
  ans += A[0]
  if i % 2 == 0:
    del A[0]
    
print(ans)

### FIXED CODE ###

import math
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse = True)

ans = 0
for i in range(1,N):
  a = math.floor(i/2)
  ans += A[a]
    
print(ans)
### BUGGY CODE ###

# L 以下の数のうち最大の2のべき数をtとする。t = 2 ** k とする。
# k は len(L)-1だね。

# a+bがt未満： 3 ** k 通り
# a+bがt以上L以下： いろいろ複雑！

L = input()
lenL = len(L) 
ans = 3 ** (lenL - 1)
mod = 10 ** 9 + 7

num_one_leftside = 1
for i in range(1, len(L)):
	if L[i] == '1':
		ans += 2 ** num_one_leftside * 3 ** (lenL - i - 1)
		ans %= mod

#		print (num_one_leftside ,  (lenL - i - 1))
		num_one_leftside += 1

ans += 2 ** num_one_leftside 
ans %= mod

print(ans)

### FIXED CODE ###

# L 以下の数のうち最大の2のべき数をtとする。t = 2 ** k とする。
# k は len(L)-1だね。

# a+bがt未満： 3 ** k 通り
# a+bがt以上L以下： いろいろ複雑！

L = input()
lenL = len(L) 
ans = 3 ** (lenL - 1)
mod = 10 ** 9 + 7

pow_2 = [1] * (lenL+1)
pow_3 = [1] * (lenL+1)

for i in range(1, lenL+1):
	pow_2[i] = pow_2[i-1] * 2 % mod
	pow_3[i] = pow_3[i-1] * 3 % mod

num_one_leftside = 1
for i in range(1, lenL):
	if L[i] == '1':
		ans += pow_2[num_one_leftside] * pow_3[lenL - i - 1]
		ans %= mod

#		print (num_one_leftside ,  (lenL - i - 1))
		num_one_leftside += 1

ans += pow_2[num_one_leftside]
ans %= mod

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

def check(pin):
    flag = 0
    for s in S:
        if flag == 0:
            if pin[0] in s:
                flag = 1
        elif flag == 1:
            if pin[1] in s:
                flag = 2
        else:
            if pin[2] in s:
                return True
    return False
            
n = int(input())
S = input()
ans = 0
# Sではなく,PINの候補を全探索
for i in range(10):
    for j in range(10):
        for k in range(10):
            PIN = str(i)+str(j)+str(k)
            if check(PIN):
                ans += 1
print(ans)

### FIXED CODE ###

N=int(input())
s=input()
PIN=[]
firs=[]
sec=[]
thir=[]
for i in range(N-2):
    if s[i] not in firs:
        firs.append(s[i])
        for j in range(i+1,N-1):
            if s[j] not in sec:
                sec.append(s[j])
                for k in range(j+1,N):
                    if s[k] not in thir:
                        thir.append(s[k])
                        PIN.append(s[i]+s[j]+s[k])
                thir=[]
        sec=[]       
print(len(PIN))
### BUGGY CODE ###

a,b = map(int,input().split(" "))
c = 1
d = 1
for i in range(2,a+1):
    c *= i % (10 ** 9 + 7)
for i in range(2,b+1):
    d *= i % (10 ** 9 + 7)
if abs(a - b) >= 2:
    print(0)
elif a == b:
    print(((c * d) * 2) % (10 ** 9 + 7))
else:
    print((c * d) % (10 ** 9 + 7))

### FIXED CODE ###

a,b = map(int,input().split(" "))
c = 1
d = 1
for i in range(2,a+1):
    c = (c * i) % (10 ** 9 + 7)
for i in range(2,b+1):
    d = (d * i) % (10 ** 9 + 7)
if abs(a - b) >= 2:
    print(0)
elif a == b:
    print(((c * d) * 2) % (10 ** 9 + 7))
else:
    print((c * d) % (10 ** 9 + 7))
### BUGGY CODE ###

k, s = map(int, input().split())
count = 0
for i in range(k+1):
  for j in range(k+1):
    for c in range(k+1):
      if(i + j + c == s):
        count += 1
print(count)

### FIXED CODE ###

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

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

res=0
for i in range(N-K+1):
    res=max(res,(sum(p[i:i+K])+K)/2)
print(res)

### FIXED CODE ###

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

res=0
s=sum(p[:K])
for i in range(N-K+1):
    res=max(res,(s+K)/2)
    if i!=N-K:
        s=s+p[i+K]-p[i]
print(res)
### BUGGY CODE ###

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

num = K
memo = []
town = 1
if K > N:
    for _ in range(N):
        memo.append(town)
        if not A[town-1] in memo:
            town = A[town-1]
            num -= 1
        else:
            index = memo.index(A[town-1])
            l = len(memo) - index
            if num % l == 0:
                town = memo[-1]
            else:
                town = memo[index + (num % l) - 1]
            break
else:
    for _ in range(K):
        town = A[town - 1]

print(town)

### FIXED CODE ###

from collections import deque
n, k = map(int, input().split())
a = [-1] + list(map(int, input().split()))
town = [-1] * (n + 1)
town[1] = 0
now_town = 1
second_first = 0
while True:
    if town[a[now_town]] != -1:
        second_first = a[now_town]
        break
    town[a[now_town]] = town[now_town] + 1
    if town[a[now_town]] == k:
        print(a[now_town])
        exit()
    now_town = a[now_town]
    # print(town)
start_index = town[second_first]
end_index = max(town)
rest = k - end_index
div = (rest-1) % (end_index - start_index + 1)
# print(rest, div)
ans = town.index((start_index) + div)
print(ans)