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

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

ans=0
now=1
i=1
result=[1]
while i<=k:
    now=a[now-1]
    if now in result:
        x=result.index(now)
        length=i-x
        ans=result[(k-x)%length+x]
    result.append(now)
    i+=1
    
if ans!=0:
    print(ans)
else:
    print(result[-1])

### FIXED CODE ###

n,k=map(int,input().split())
a=list(map(lambda x:int(x)-1,input().split()))

ans=-1
l=[-1]*n
now=0
i=1
result=[0]
while i<=k:
    now=a[now]
    if l[now]!=-1:
        
        length=i-l[now]
        d=(k-i)%length+l[now]
        ans=l.index(d)
        break
    l[now]=i
    i+=1
    
if ans!=-1:
    print(ans+1)
else:
    print(now+1)
### BUGGY CODE ###

N,M = [int(s) for s in input().split()]
lst=[]
for i in range(N):
  lst=lst+[[int(s) for s in input().split()]]
lst.sort()
n=0
cost=0
for i in range(N):
  n+=lst[i][1]
  cost+=lst[i][0]*lst[i][1]
  if(n>=M):
    break
if(n>M):
  cost-=lst[i][0]*(n-M)
print(cost)

### FIXED CODE ###

N,M = [int(s) for s in input().split()]
lst=[]
for i in range(N):
  lst.append([int(s) for s in input().split()])
lst.sort()
count=0
cost=0
for e in lst:
  count+=e[1]
  cost+=e[0]*e[1]
  if(count>=M):
    cost-=e[0]*(count-M)
    break
print(cost)
### BUGGY CODE ###

def checkRGB(a,b):
    if not("B" in a) and not("B" in b):
        return "B"
    elif not("G" in a) and not("G" in b):
        return "G"
    else:
        return "R"

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

if N<4:
    print(0)
    exit()
sum = 0
for i in range(1,N//2+N%2+1):
    center = S[i]
    for j in range(i):
        if S[j] != center:
            left = S[j]
            rS1 = S[i+1:2*i-j]
            rS2 = S[2*i-j+1:]
            right = checkRGB(left,center)
            sum += rS1.count(right) + rS2.count(right)
        else:
            pass
for i in range(N//2+N%2+1,N-1):
    center = S[i]
    for j in range(i+1,N):
        if S[j] != center:
            right = S[j]
            lS1 = S[:2*i-j]
            lS2 = S[2*i-j+1:i]
            left = checkRGB(right,center)
            sum += lS1.count(left) + lS2.count(left)
        else:
            pass
print(sum)


### FIXED CODE ###

def checkRGB(a,b,c):
    if a == b or b == c or c == a:
        return 0
    else:
        return 1

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

if N<4:
    print(0)
    exit()
sum1 = S.count("R")*S.count("G")*S.count("B")
sum2 = 0
for i in range(0,N-2):
    left = S[i]
    for j in range(i+1,(N+i)//2+(N+i)%2):
        center = S[j]
        right = S[2*j-i]
        if checkRGB(left,center,right):
            sum2 += 1
print(sum1-sum2)
### BUGGY CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
tmpA = [1 for i in range(N)]
tmpB = []

for i in range(min(K, 50)):
    tmpA = [1 for i in range(N)]
    tmpB = []
    for j in range(N):
        tmpA[j] += len(tmpB)
        tmpB = list(filter(lambda x:x, map(lambda x:x-1, tmpB)))
        if A[j]:
            tmpB.append(A[j])
    
    tmpB = []
    for j in range(N - 1, -1 ,-1):
        tmpA[j] += len(tmpB)
        tmpB = list(filter(lambda x:x, map(lambda x:x-1, tmpB)))
        if A[j]:
            tmpB.append(A[j])

    A = tmpA

[print(i, end=' ') for i in A]
print()


### FIXED CODE ###

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

for i in range(min(K, 50)):
    B = [0 for i in range(N)]
    for j in range(0, N):
        l = max(0, j - A[j])
        r = min(N - 1, j + A[j])
        B[l] += 1
        if r + 1 < N:
            B[r + 1] -= 1

    for j in range(1, N):
        B[j] += B[j - 1]
        
    A = B

[print(i, end=' ') for i in B]
print()
### BUGGY CODE ###

n,k=map(int,input().split())
n=int(n)
k=int(k)
n = n % k
minimam = k
for i in range(k):
  if n < minimam:
    minimam = n
  n = abs(n-k)
print(minimam)

### FIXED CODE ###

n,k=map(int,input().split())
n=int(n)
k=int(k)
n = n % k
minimam = n
record=[]
for i in range(k):
  n=abs(n-k)
  if n < minimam:
    minimam = n
  record.append(n)
  if n in record:
    break
print(minimam)
### BUGGY CODE ###

from math import factorial
import collections

MEMO = {}
def fact(n):
    if MEMO.get(n):
        return MEMO[n]
    r = 2
    if n - r < 0:
        return 0
    MEMO[n] = factorial(n) // factorial(r) // factorial(n - r)
    return MEMO[n]

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

counts = collections.Counter(BALLS)
for i in range(N):
    print(sum(fact(v if k != BALLS[i] else v - 1) for (k, v) in counts.items()))

### FIXED CODE ###

from math import factorial
import collections

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

MEMO = {}
def fact(n):
    if MEMO.get(n):
        return MEMO[n]
    r = 2
    if n - r < 0:
        MEMO[n] = 0
        return 0
    MEMO[n] = factorial(n) // factorial(r) // factorial(n - r)
    return MEMO[n]

COUNTS = collections.Counter(BALLS)
TOTAL = sum(fact(n) for n in COUNTS.values())

MEMO2 = {}
def solve(n):
    if MEMO2.get(n):
        return MEMO2[n]

    MEMO2[n] = TOTAL - fact(COUNTS[n]) + fact(COUNTS[n] - 1)
    return MEMO2[n]

for i in range(N):
    print(solve(BALLS[i]))
### BUGGY CODE ###

def main():
    n=int(input())
    a=list(map(int,input().split()))
    l1=[0]*61
    for i in a:
        j=list(reversed(bin(i)[2:]))
        for k in range(len(j)):
            if j[k]=="1":
                l1[k]+=1
    l0=[n-i for i in l1]
    ans=0
    mod=10**9+7
    for i in range(len(l1)):
        ans=(ans+l0[i]*l1[i]*pow(2,i,mod))%mod
    print(ans)
main()

### FIXED CODE ###

def main():
    n=int(input())
    a=list(map(int,input().split()))
    l1=[0]*61
    for i in a:
        j=list(reversed(bin(i)[2:]))
        for k in range(len(j)):
            if j[k]=="1":
                l1[k]+=1
    l0=[n-i for i in l1]
    ans=0
    mod=10**9+7
    for i in range(len(l1)):
        ans=(ans+l0[i]*l1[i]*pow(2,i,mod))%mod
    print(ans)
main()
### BUGGY CODE ###

N = int(input())
if N==1:
    print(1)
    exit()

f = N if N%2 else 2*N
from collections import Counter
def factorize(n):
    d = Counter()
    m = 2
    while m*m <= n:
        while n%m == 0:
            n //= m
            d[m] += 1
        m += 1
    if n > 1:
        d[n] += 1
    return d

fac = factorize(f)
step = len(fac)
for k,v in fac.items():
    step = max(step, k**v)

for m in range(step, 2*N, step):
    if (m*(m-1)//2) % N == 0:
        print(m-1)
        exit()
    if (m*(m+1)//2) % N == 0:
        print(m)
        exit()

print(N*2-1)

### FIXED CODE ###

N = int(input())

def crt(rs,ms):
    def _inv_gcd(a,b):
        if a==0: return (b,0)
        s,t,m0,m1 = b,a,0,1
        while t:
            u = s // t
            s -= t * u
            m0 -= m1 * u
            tmp = s
            s = t
            t = tmp
            tmp = m0
            m0 = m1
            m1 = tmp
        if m0 < 0: m0 += b//s
        return (s, m0)
    assert len(rs) == len(ms)
    n = len(rs)
    r0,m0 = 0,1
    for i in range(n):
        assert 1 <= ms[i]
        r1,m1 = rs[i] % ms[i], ms[i]
        if m0 < m1:
            r0,r1,m0,m1 = r1,r0,m1,m0
        if m0 % m1 == 0:
            if r0 % m1 != r1: return (0,0)
            continue
        g,im = _inv_gcd(m0,m1)
        u1 = m1 // g
        if (r1-r0) % g: return (0,0)
        x = (r1-r0) // g % u1 * im % u1
        r0 += x * m0
        m0 *= u1
        if r0 < 0: r0 += m0
    return (r0,m0)

divs = set()
m = 1
NN = 2*N
while m*m <= NN:
    if NN%m == 0:
        divs.add(m)
        divs.add(NN//m)
    m += 1

ans = NN-1
for x in divs:
    y = NN//x
    if y==1: continue
    r,m = crt([0,-1], [x,y])
    if r==m==0: continue
    ans = min(ans, r)

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


num=input()
num=int(num)

list1=[]
list2=[]
for i in range(num):
    n=input()
    n=int(n)
    list1.append(n)
    list2.append(n)
    
count=0
for j in range(num):
    for k in range(list1.index(num-j)+1):
        if list1[k]>list1[list1.index(num-j)]:
            #print(str(list1[list1.index(num-j)])+" "+str(k))
            del list1[list1.index(num-j)]
            list1.insert(0,num-j)
            #print(list1)
            count=count+1
            break
        else:
            k+=1
#print(count)

count2=0
for j in range(1,num+1):
    for k in range(list2.index(j),num):
        if list2[k]<list2[list2.index(j)]:
            #print(str(list1[list1.index(j)])+" "+str(k))
            del list2[list2.index(j)]
            list2.insert(num-1,j)
            #print(list2)
            count2=count2+1
            break
        else:
            k+=1
#print(count2)
if count<=count2:
    print(count)
else:
    print(count2)
    

### FIXED CODE ###

import bisect

N=int(input())

A=[int(input())for i in range(N)]
#print(A)

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

for i in range(N):
    if L[A[i]-1]>0:
        L[A[i]]=(L[A[i]-1]+1)
    else:
        L[A[i]]=1
print(N-max(L))
### BUGGY CODE ###

import numpy as np
N = int(input())
An = list(map(int, input().split()))
ok = [False] * N
a_An = np.array(An)
for i, a in enumerate(An):
    temp = a_An / a
    temp[i] = 0.1
    check = (temp % 1 == 0)
    ok = ok | check
print(np.count_nonzero(ok == 0))

### FIXED CODE ###

N = int(input())
An = list(map(int, input().split()))
An.sort()
max_n = max(An)
dp = [0] * (max_n + 1)
for i in range(N):
    if dp[An[i]] != 0:
        dp[An[i]] = 2
        continue
    for j in range(1, max_n//An[i] + 1):
        dp[An[i]*j] += 1
ans = 0
for a in An:
    if dp[a] == 1:
        ans += 1
print(ans)
### BUGGY CODE ###

n=int(input())
from collections import defaultdict
import math
a=list(map(int,input().split()))
d=defaultdict(int)
for m in a:
  d[m]+=1
sm=0
for m in d:
  if d[m]>1:
    sm+=math.factorial(d[m])//math.factorial(d[m]-2)//2
for m in a:
  if d[m]>2:
    print(sm-math.factorial(d[m])//math.factorial(d[m]-2)//2+math.factorial(d[m]-1)//math.factorial(d[m]-3)//2)
  elif d[m]==2:
    print(sm-1)
  else:
    print(sm)

  



### FIXED CODE ###

n=int(input())
from collections import defaultdict
import math
a=list(map(int,input().split()))
d=defaultdict(int)
for m in a:
  d[m]+=1
sm=0
for m in d:
  if d[m]>1:
    sm+=d[m]*(d[m]-1)//2
for m in a:
  if d[m]>2:
    print(sm-d[m]+1)
  elif d[m]==2:
    print(sm-1)
  else:
    print(sm)
### BUGGY CODE ###

n, m = map(int, input().split())
s = list(map(int, input().split()))
t = list(map(int, input().split()))
mod = 10 ** 9 + 7

dp = [[0] * (m+1) for _ in range(n+1)]
for i in range(n+1):
    dp[i][0] = 1
for j in range(m+1):
    dp[0][j] = 1

for i in range(1, n+1):
    for j in range(1, m+1):
        if s[i-1] == t[j-1]:
            dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % mod
        else:
            dp[i][j] = (dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1]) % mod


print(dp[n][m])

### FIXED CODE ###

n, m = map(int, input().split())
s = list(map(int, input().split()))
t = list(map(int, input().split()))
mod = 10 ** 9 + 7

dp = [[0] * (m+1) for _ in range(n+1)]
for i in range(n+1):
    dp[i][0] = 1
for j in range(m+1):
    dp[0][j] = 1

for i in range(1, n+1):
    for j in range(1, m+1):
        if s[i-1] == t[j-1]:
            dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % mod
        else:
            dp[i][j] = (dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1]) % mod


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

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

P = 10 ** 9 + 7


def conb(n, r):
    resp = n
    for i in range(1, r):
        resp = (resp * (n - i) * pow(i + 1, P - 2))%P
    return resp


def pow(x, n):
    ans = 1
    while (n > 0):
        if (bin(n & 1) == bin(1)):
            ans = (ans * x)%P
        x = (x * x) % P
        n = n >> 1  # ビットシフト
    return ans



print((pow(2, n) - conb(n, a) - conb(n, b)-1)%P)


### FIXED CODE ###

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

P = 10 ** 9 + 7


def conb(n, r):
    P = 10 ** 9 + 7
    x = 1
    y = 1
    for i in range(n - r + 1, n + 1):
        x = (x * i % P)
    for i in range(1, r + 1):
        y = (y * i % P)
    y_inv = pow(y, P - 2)
    return x * y_inv


def pow(x, n):
    ans = 1
    while (n > 0):
        if (bin(n & 1) == bin(1)):
            ans = (ans * x) % P
        x = (x * x) % P
        n = n >> 1  # ビットシフト
    return ans


print((pow(2, n) - conb(n, a) - conb(n, b) - 1) % P)
### BUGGY CODE ###

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

rl = []
gl = []
bl = []
rld = [0]*(n)
gld = [0]*(n)
bld = [0]*(n)

for i in range(len(s)):
  if s[i] == 'R':
    rl += [i]
    rld[i] = 1 
  elif s[i] == 'G':
    gl += [i]
    gld[i] = 1 
  else:
    bl += [i]
    bld[i] = 1

ans = 0 
for i in rl:
  for j in gl:
    #print(i, j, j+j-i, bl[j+1:])
    #print(bl[j+1:])
    if i >= j:
      continue
    ans += sum(bld[j+1:])
    if j+j-i < n:
      ans -= bld[j+j-i]

for i in rl:
  for j in bl:
    if i >= j:
      continue
    ans += sum(gld[j+1:])
    if j+j-i < n:
      ans -= gld[j+j-i]

for i in gl:
  for j in bl:
    if i >= j:
      continue
    ans += sum(rld[j+1:])
    if j+j-i < n:
      ans -= rld[j+j-i]

for i in gl:
  for j in rl:
    if i >= j:
      continue
    ans += sum(bld[j+1:])
    if j+j-i < n:
      ans -= bld[j+j-i]
for i in bl:
  for j in gl:
    if i >= j:
      continue
    ans += sum(rld[j+1:])
    if j+j-i < n:
      ans -= rld[j+j-i]

for i in bl:
  for j in rl:
    if i >= j:
      continue
    ans += sum(gld[j+1:])
    if j+j-i < n:
      ans -= gld[j+j-i]
    
print(ans)


### FIXED CODE ###

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

rl = []
gl = []
bl = []
rld = [0]*(n)
gld = [0]*(n)
bld = [0]*(n)

for i in range(len(s)):
  if s[i] == 'R':
    rl += [i]
    rld[i] = 1 
  elif s[i] == 'G':
    gl += [i]
    gld[i] = 1 
  else:
    bl += [i]
    bld[i] = 1

rlds = rld[:]
glds = gld[:]
blds = bld[:]

for i in range(n-1, 0, -1):
  blds[i-1] += blds[i]
  rlds[i-1] += rlds[i] 
  glds[i-1] += glds[i] 

ans = 0 
for i in rl:
  for j in gl:
    if i >= j or j+1 >= n:
      continue
    ans += blds[j+1]
    if j+j-i < n:
      ans -= bld[j+j-i]

for i in rl:
  for j in bl:
    if i >= j or j+1 >= n:
      continue
    ans += glds[j+1]
    if j+j-i < n:
      ans -= gld[j+j-i]

for i in gl:
  for j in bl:
    if i >= j or j+1 >= n:
      continue
    ans += rlds[j+1]
    if j+j-i < n:
      ans -= rld[j+j-i]

for i in gl:
  for j in rl:
    if i >= j or j+1 >= n:
      continue
    ans += blds[j+1]
    if j+j-i < n:
      ans -= bld[j+j-i]
for i in bl:
  for j in gl:
    if i >= j or j+1 >= n:
      continue
    ans += rlds[j+1]
    if j+j-i < n:
      ans -= rld[j+j-i]

for i in bl:
  for j in rl:
    if i >= j or j+1 >= n:
      continue
    ans += glds[j+1]
    if j+j-i < n:
      ans -= gld[j+j-i]
    
print(ans)
### BUGGY CODE ###

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

def main():
    # 入力
    st = input()

    if len(st) < 4:
        print(0)
        return

    cnt = 0
    for l in range(4, len(st)+1):
        for idx in range(len(st) + 1 - l):
            target_st = st[idx:idx+l]
            if int(target_st) % 2019 == 0:
                cnt += 1

    print(cnt)


main()


### FIXED CODE ###

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

def main():
    # 入力
    st = input()

    # if len(st) < 4:
    #     print(0)
    #     return

    # 右からi文字目から最後の数字までを数値化したものについてmodを計算していく
    mod_res_dic = {0: [0]}
    tmp_mod_val = 0
    r_st = ''.join(list(reversed(st)))
    cnt = 0
    for i in range(len(r_st)):
        target_st = r_st[i:i+1]
        # mod_res = ((10 ** i) * int(target_st) + tmp_mod_val) % 2019
        tmp_mod_val += int(target_st)*pow(10, i, 2019)
        tmp_mod_val %= 2019
        ls = mod_res_dic.setdefault(tmp_mod_val, [])
        ls.append(i-1)
        if len(ls) > 1:
            cnt += len(ls)-1
        # tmp_mod_val = mod_res

    # print(mod_res_dic)
    # modが同じペアのものについて、iからj文字目までを2019で割り切れるので、その組み合わせを計算
    # cnt = 0
    # for v in mod_res_dic.values():
    #     comb = len(v)
    #     if comb < 2:
    #         continue
    #     cnt += (comb * (comb - 1)) / 2

    print(int(cnt))


main()
### BUGGY CODE ###

n, q = map(int ,input().split())
s = list(input())
l, r = [], []
for i in range(q):
    ll, rr = map(int, input().split())
    l.append(ll)
    r.append(rr)

for i in range(q):
    ss = ''.join(s[l[i]-1:r[i]])
    ans = ss.count('AC')
    print(ans)

### FIXED CODE ###

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

b=[0]*n
for i in range(1,n):
 if s[i-1]+s[i]=='AC':
  b[i]=b[i-1]+1
 else:
  b[i]=b[i-1]

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

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

import numpy as np
N = int(readline())
A = [int(x) for x in readline().rstrip().split()]
B = [0] * 60
ans = 0
for i in range(N):
    i_bin = np.array(list(bin(A[i])))
    i_bin = i_bin[2:]
    i_bin = i_bin[::-1]
    k = 0
    for j in i_bin:
        if j == "1":
            B[k] += 1
        k += 1

for q in range(60):
    temp = B[q] * (N - B[q])
    ans += (temp % (7 + 10 ** 9)) * ((2 ** q) % (7 + 10 ** 9))
    ans %= 7 + 10 ** 9
print(ans)    

### FIXED CODE ###

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

N = int(readline())
A = [int(x) for x in readline().rstrip().split()]
B = [0] * 60
ans = 0
for i in range(N):
    i_bin = list(bin(A[i]))
    i_bin = i_bin[2:]
    i_bin = i_bin[::-1]
    k = 0
    for j in i_bin:
        if j == "1":
            B[k] += 1
        k += 1

for q in range(60):
    temp = B[q] * (N - B[q])
    ans += (temp % (7 + 10 ** 9)) * ((2 ** q) % (7 + 10 ** 9))
    ans %= 7 + 10 ** 9
print(ans)
### BUGGY CODE ###

#!/usr/bin/env python3
from collections import Counter
n = int(input())
s = input()
# n=10**3
# s='abcab'*(10**3)
count = 0
for le in range(1, n//2+1):
    mojiretu = Counter()
    for i in range(n-le+1):
        j = i+le
        if 0 < mojiretu[s[i:j]] <= i:
            count = le
            break
        else:
            mojiretu[s[i:j]] = j
print(count)

### FIXED CODE ###

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

class RollingHash():
    BASE1 = 1007
    BASE2 = 2009
    MOD1 = 1000000007
    MOD2 = 1000000009
 
    def __init__(self, s, opt=2):
        self.n = len(s)
        self.opt = opt
        self.hash1 = [0] * (self.n + 1)
        self.power1 = [1] * (self.n + 1)
        if opt == 2:
            self.hash2 = [0] * (self.n + 1)
            self.power2 = [1] * (self.n + 1)
        for i, e in enumerate(s):
            self.hash1[i + 1] = (self.hash1[i] * self.__class__.BASE1 + ord(e)) % self.__class__.MOD1
            self.power1[i + 1] = (self.power1[i] * self.__class__.BASE1) % self.__class__.MOD1
            if opt == 2:
                self.hash2[i + 1] = (self.hash2[i] * self.__class__.BASE2 + ord(e)) % self.__class__.MOD2
                self.power2[i + 1] = (self.power2[i] * self.__class__.BASE2) % self.__class__.MOD2
 
    def get(self, l: int, r: int):
        res1 = self.hash1[r] - self.hash1[l] * self.power1[r - l] % self.__class__.MOD1
        if(res1 < 0):
            res1 += self.__class__.MOD1
        if self.opt == 2:
            res2 = self.hash2[r] - self.hash2[l] * self.power2[r - l] % self.__class__.MOD2
            if(res2 < 0):
                res2 += self.__class__.MOD2
        return (res1, res2) if self.opt == 2 else res1


    
rh = RollingHash(S, opt=1)

def check(n: int):
    d = dict()
    for i in range(N - n + 1):
        p = rh.get(i, i + n)
        if p in d.keys():
            if(i - d[p] >= n):
                return True
        else:
            d[p] = i
    return False
    
ok, ng = 0, N // 2 + 1
while ng - ok > 1:
    mid = (ok + ng) // 2
    if check(mid):
        ok = mid
    else:
        ng = mid
print(ok)
### BUGGY CODE ###

import bisect

N = int(input())
L = input().split()
for i in range(0, N):
  L[i] = int(L[i])
L.sort()
ans = 0
for i in range(0, N-1):
  for j in range(i+1, N):
    a = L[j] - L[i]
    b = L[j] + L[i]
    c = bisect.bisect_right(L, a)
    d = bisect.bisect_left(L, b)
    if 2*L[i] > L[j]:
      ans += d-c-2
    else:
      ans += d-c-1
print(ans // 3)

### FIXED CODE ###

import bisect

N = int(input())
L = input().split()
for i in range(0, N):
  L[i] = int(L[i])
L.sort()
ans = 0
for i in range(0, N-1):
  for j in range(i+1, N):
    a = L[i] + L[j]
    b = bisect.bisect_left(L, a)
    ans += b-j-1
print(ans)
### BUGGY CODE ###

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

d = [0] * (len(a)) 

for i in range(n):
    if i == 0:
        d[i] = k - a[-1]
        continue
    d[i] = a[i]-a[i-1]

d += d
ans = 1001001001
for i in range(len(d)-n+1):
    ans = min(ans, sum(d[i:i+n-1]))
print(ans)


### FIXED CODE ###

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

[k-a[-1]+a[0]]
d = []

for i in range(n):
    if i>0:
        d.append(a[i]-a[i-1])
d.append(k-a[-1]+a[0])
print(k-max(d))
### BUGGY CODE ###

from itertools import combinations,permutations

n,m = map(int,input().split())
prices,keys = [],[]
for i in range(m):
	a,b = map(int,input().split())
	C = list(map(int,input().split()))

	prices.append(a)
	cur_key = 0
	for c in C:
		cur_key += 2**(c-1)
	keys.append(cur_key)
ans_max = 2**n-1
cnt = 0
ans = float("inf")
for i in range(1,m+1):
	for comb in combinations(range(0,m),r=i):
		# print(comb)
		price = 0
		cur_key = 0
		for c in comb:
			price += prices[c]
			cur_key |= keys[c]
		# print(price,cur_key)
		if cur_key == ans_max and price < ans:
			ans = price
if ans == float("inf"):
	ans = -1
print(ans)

### FIXED CODE ###

n,m = map(int,input().split())
vals = []
inf = float("inf")
res = [inf]*2**n

for i in range(m):
	a,b = map(int,input().split())
	C = list(map(int,input().split()))
	cur = 0
	for c in C:
		cur |= 2**(c-1)
	res[cur] = min(res[cur],a)

ans = []
for i,r in enumerate(res):
	if res[i] == inf:
		continue
	ans.append([i,r])


for i,a in ans:
	for j in range(2**n):
		res[i|j] = min(res[i|j],res[i]+res[j])

if res[-1] == inf:
	print(-1)
else:
	print(res[-1])
### BUGGY CODE ###

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

min = n
for i in range(n):
    count = 0
    for j in range(n):
        if j == i:
            continue
        elif ((j < i and s[j] != "E")
            or (j > i and s[j] != "W")):
            count += 1
        if count > min:
            break
    if count < min:
        min = count

print(min)


### FIXED CODE ###

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

min = n
count = 0
for i in range(1, n):
    if s[i] == "E":
        count += 1
min = count

for i in range(1, n):
    if s[i] == "E":
        count -= 1
    if s[i-1] == "W":
        count += 1

    if count < min:
        min = count

print(min)
### BUGGY CODE ###

n,q=map(int,input().split())
s=input().replace("AC","10").replace("A","0").replace("T","0").replace("C","0").replace("G","0")
for i in range(q):
  l,r=map(int,input().split())
  print(len(s[l-1:r-1].replace("0","")))

### FIXED CODE ###

n,q=map(int,input().split())
l=[0 for i in range(n)]
for i,v in enumerate(list(input().replace("AC","X!"))):
    l[i]=l[i-1]+(v=="!")
for c in range(q):
    h,m=map(int,input().split())
    print(l[m-1]-l[h-1])
### BUGGY CODE ###

n, m = list(map(int, input().split()))
results = []
if m:
    results = [input().split() for _ in range(m)]
ac = {}
wa = {}
cnt_ac = 0
cnt_wa = 0
for res in results:
    if res[1] == "AC":
        if not res[0] in ac.keys():
            cnt_ac += 1
            ac[res[0]] = "AC"
            if res[0] in wa.keys():
                cnt_wa += wa[res[0]]
    else:
        if res[0] in wa.keys():
            wa[res[0]] += 1
        else:
            wa[res[0]] = 1
print(cnt_ac, cnt_wa)

### FIXED CODE ###

N,M=map(int,input().split())
AC=[0]*N
WA=[0]*N
wa=0
for i in range(M):
  p,s=input().split()
  p=int(p)-1
  if AC[p]==0 and s=="AC":
  	AC[p]=1
  	wa+=WA[p]
  WA[p]+=1
print(sum(AC),wa)