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

n,m = map(int,input().split())
count_ac = 0
count_wa = 0
l = [('','')]*m
memo_n = []
import collections
for i in range(m):
    t = tuple(input().split())
    l[i] = t
    if t[1] == 'AC' and t[0] not in memo_n:
        memo_n.append(t[0])
        count_ac += 1
        c = collections.Counter(l)
        # count_wa += l.count((t[0],'WA'))
        count_wa += c[(t[0],'WA')]

print(str(count_ac) + " " + str(count_wa))

### FIXED CODE ###

n,m = map(int,input().split())
ac = [0]*n
wa = [0]*n
for i in range(m):
    p,s = input().split()
    p = int(p)
    if ac[p-1]:
        continue
    if s == 'AC':
        ac[p-1] = 1
    else:
        wa[p-1] += 1
count_ac = 0
count_wa = 0
for i in range(n):
    count_ac += ac[i]
    if ac[i]:
        count_wa += wa[i]
print(str(count_ac) + " " + str(count_wa))
### BUGGY CODE ###

import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    N,K = map(int,input().split())
    LR = [list(map(int,input().split())) for i in range(N)]

    mod = 998244353

    dp = [0 for i in range(N)]
    dp[0] = 1
    dp = np.array(dp)

    left = N
    for i in range(K):
        left = min(left,LR[i][0])

    for i in range(N):
        for k in range(K):
            l = LR[k][0]
            r = LR[k][1]
            if i + l >= N:
                continue
            else:
                L = i + l
            if i + r >= N:
                R = N - 1
            else:
                R = i + r
            dp[L:R+1] += dp[i]
            dp[L:R+1] %= mod

    # print(dp)
    print(dp[-1])



main()


### FIXED CODE ###

import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)
from numba import njit,i8


@njit(i8(i8,i8,i8,i8[:,:],i8[:],i8,i8))
def give_dp(N,K,mod,LR,dp,l,r):
    for i in range(N):
        if i > 0:
            dp[i] += dp[i-1]
            dp[i] %= mod
        for k in range(K):
            l = LR[k][0]
            r = LR[k][1]
            if i + l < N:
                dp[i+l] += dp[i]
                dp[i+1] %= mod
            if i + r < N:
                dp[i+r+1] -= dp[i]
                dp[i+1] %= mod
    return dp[-1]


def main():
    N,K = map(int,input().split())
    LR = [list(map(int,input().split())) for i in range(K)]
    LR = np.array(LR)

    mod = 998244353

    dp = [0 for i in range(N)]
    dp[0] = 1
    dp[1] = -1
    dp = np.array(dp)

    res = give_dp(N,K,mod,LR,dp,0,0)
    res %= mod

    print(res)



main()
### BUGGY CODE ###

# arc 100 D

def ruiseki(n,array):
    res = [0]*(n+1)
    for i in range(n):
        res[i+1] = res[i] + array[i]
    return res

n = int(input())
A = list(map(int,input().split()))
sa = ruiseki(n,A)

from bisect import bisect_right

ans = 10**15
for i in range(1,n-2):
    left = sa[i+1]
    right = sa[-1] - sa[i+1]

    lsplit = min(bisect_right(sa[:i+1],left//2) - 2,i-1)
    rsplit = min(bisect_right(sa[i+1:],right//2 + left) + i-1,n-2)
    lleft = [(sa[lsplit + 1],sa[i+1] - sa[lsplit + 1]),(sa[lsplit + 2],sa[i+1] - sa[lsplit + 2])]
    rright = [(sa[rsplit+1] - sa[i+1],sa[-1] - sa[rsplit+1]),(sa[rsplit+2] - sa[i+1],sa[-1] - sa[rsplit+2])]
    for s,t in [(0,0),(0,1),(1,0),(1,1)]:
        l = lleft[s]
        r = rright[t]
        m = min(l+r)
        M = max(l+r)
        ans = min(ans,M-m)

print(ans)




### FIXED CODE ###

# arc 100 D

def ruiseki(n,array):
    res = [0]*(n)
    for i in range(n):
        res[i] = res[i-1] + array[i]
    return res

n = int(input())
A = list(map(int,input().split()))
sa = ruiseki(n,A)

ans = 10**15
left_c = 0
right_c = 2
for center in range(1,n-1):
    while left_c+1 < center:
        if abs(sa[center]-2*sa[left_c]) > abs(sa[center]-2*sa[left_c+1]):
            left_c+=1
        else:
            break

    right_c = max(right_c, center+1)
    while right_c+1 < n-1:
        if abs(sa[-1] + sa[center] - 2*sa[right_c]) > abs(sa[-1] + sa[center] - 2*sa[right_c+1]):
            right_c+=1
        else:
            break
    
    x = max(sa[left_c], sa[center]-sa[left_c], sa[right_c]-sa[center], sa[-1]-sa[right_c])
    y = min(sa[left_c], sa[center]-sa[left_c], sa[right_c]-sa[center], sa[-1]-sa[right_c])
    ans = min(ans, x-y)

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

k = int(input())
a, b = map(int, input().split())
i = 1
ans = 'NG'

while k * i <= b:
    if a <= k * i <= b: ans = 'OK'

print(ans)

### FIXED CODE ###

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

if a <= int(b / k) * k: print('OK')
else: print('NG')
### BUGGY CODE ###

N = int(input())
S = []

for i in range(N):
  S.append(input())

dict = {i : 0 for i in set(S)}
for i in S:
  dict[i] += 1
for k in sorted([i for i, j in dict.items() if j == max(dict.values())]):
  print(k)

### FIXED CODE ###

from collections import Counter

N, *S = open(0).read().split()
count = Counter(S)
max_value = max(count.values())
ans_list = [i for i, j in count.items() if j == max_value]
ans_list.sort()
print("\n".join(ans_list))
### BUGGY CODE ###

import sys

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    n = II()
    a_s = LI()
    kaizyo = [1]
    keta = [0 for i in range(61)]
    ans = 0
    for i in range(61):
        kaizyo.append(kaizyo[i] * 2 % MOD)
    for i in a_s:
        for i, v in enumerate(bin(i)[:1:-1]):
            keta[i] += int(v)
    # print(kaizyo)
    # print(keta)
    for i, v in enumerate(keta):
        c = v * (n-v) % MOD
        ans += c * kaizyo[i]
        ans = ans % MOD
        # print(ans, c, kaizyo[i])

    print(ans)
if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys

sys.setrecursionlimit(10**7)
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())

def main():
    n = II()
    a_s = LI()
    kaizyo = [1]
    kaizyo_append = kaizyo.append
    keta = [0 for i in range(60)]
    ans = 0
    for i in range(60):
        kaizyo_append(kaizyo[i] * 2 % MOD)
    for i in a_s:
        for j in range(60):
            v, i = i % 2, i // 2
            keta[j] += v
    for i, v in enumerate(keta):
        c = v * (n-v) % MOD
        ans += c * kaizyo[i] % MOD
        ans = ans % MOD

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

from operator import itemgetter

N, M = map(int, input().split())
pairs = [tuple(map(int, input().split())) for _ in range(N)]

pairs.sort(key = itemgetter(1), reverse = True)
schedule = [0] * (M+1)
for A, B in pairs:
    for i in range(A, M+1):
        if schedule[i] == 0:
            schedule[i] = B
            break

print(sum(schedule))            


### FIXED CODE ###

from operator import itemgetter
import heapq

N, M = map(int, input().split())
pairs = [tuple(map(int, input().split())) for _ in range(N)]
pairs.sort(key = itemgetter(0))

heap = []
reward = 0
index_of_pairs = 0   
for i in range(1, M+1):
    while index_of_pairs < N and pairs[index_of_pairs][0] <= i:
        heapq.heappush(heap, -pairs[index_of_pairs][1])
        index_of_pairs += 1
    if heap:
        reward -= heapq.heappop(heap)

print(reward)
### BUGGY CODE ###

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

# 約数を求める時間はない！

n = int(input())
ans = 0

for i in range(1, n + 1):
    for j in range(1, (i // 2) +1):
        if i % j == 0:
            ans += i
    ans += i
print(ans)

### FIXED CODE ###

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

# 約数を求める時間はない！

N = int(input())

ans = 0
for i in range(1, N + 1):
    n = N // i
    ans += i * (n * (n + 1)) // 2

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

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

for i in range(n):
  print(a.count(i+1))

### FIXED CODE ###

import numpy as np
n = int(input())
a = list(map(int, input().split()))
c = np.zeros(n)

for ai in a:
  c[ai-1] += 1
  
for i in range(n):
  print(int(c[i]))
### BUGGY CODE ###

import bisect as bi
n = int(input())
kariA = list(map(int,input().split()))
kariB = list(map(int,input().split()))
kariC = list(map(int,input().split()))
A = sorted(kariA)
B = sorted(kariB)
C = sorted(kariC)
count = 0
for c in C:
    for b in B[:bi.bisect_left(B,c)]:
            count += bi.bisect_left(A,b)
    
print(count)

### FIXED CODE ###

import bisect as bi
n = int(input())
kariA = list(map(int,input().split()))
kariB = list(map(int,input().split()))
kariC = list(map(int,input().split()))
A = sorted(kariA)
B = sorted(kariB)
C = sorted(kariC)
count = 0
Clength = len(C)
for b in B:
    count += bi.bisect_left(A,b)*(Clength - bi.bisect_right(C,b))
print(count)
### BUGGY CODE ###

n, p = [int(i) for i in input().split()]
max_x = int(p**(1/n))
ans = 1
if n >= p:
    print(1)
else:
    for i in range(max_x+1, 1, -1):
        if p % pow(i,n) == 0:
            ans = i
            break
    print(ans)

### FIXED CODE ###

n, p = [int(i) for i in input().split()]
tmp = p**(1/n)
if tmp - int(tmp) > 0.999:
    max_x = int(tmp) + 1
else:
    max_x = int(tmp)
ans = 1
for i in range(max_x, 1, -1):
    if p % pow(i,n) == 0:
        ans = i
        break
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
from math import ceil
from bisect import bisect
N,D,A = map(int,input().split())
XH = [list(map(int,input().split())) for _ in range(N)]
XH.sort(key = lambda x:x[0])
X,H = map(list, zip(*XH))

ans = 0
for i in range(N):
    if H[i] > 0:
        tmp = bisect(X,X[i]+2*D)
        num = ceil(H[i]/A)
        for j in range(i,tmp):
            H[j] -= A*num
        ans += num
print(ans)


### FIXED CODE ###

#https://atcoder.jp/contests/abc153/submissions/9750027

import sys
input = sys.stdin.readline
from math import ceil
from collections import deque
N,D,A = map(int, input().split())
XH = [list(map(int,input().split())) for _ in range(N)]
XH.sort(key = lambda x:x[0])
#X,H = map(list, zip(*XH))
q = deque()
d = 0
ans = 0

for x,h in XH:
    while q and q[0][0] < x:    #今見ている座標が既にそれまでの爆弾範囲から外れていたら
        d -= q.popleft()[1]
    h -= d
    if h > 0:
        num = ceil(h/A)
        ans += num
        q.append((x+2*D, num*A))    #(末端, そこまででの爆弾の威力)
        d += num*A
print(ans)
### BUGGY CODE ###

S = input()
Q = int(input())

for i in range(Q):
    query = input()
    query = query.replace(' ', '')
    if query[0] == '1':
        S = S[::-1]
    elif query[0] == '2':
        if query[1] == '1':
            S = query[2] + S
        else:
            S = S + query[2]

print(S)


### FIXED CODE ###

from collections import deque

S = deque(input())
Q = int(input())
reverse_index = -1

for i in range(Q):
    query = input()
    if query[0] == '1':
        reverse_index *= -1
    elif query[0] == '2':
        if query[2] == '1':
            if reverse_index == -1:
                S.appendleft(query[4])
            else:
                S.append(query[4])
        else:
            if reverse_index == -1:
                S.append(query[4])
            else:
                S.appendleft(query[4])

if reverse_index == 1:
    S.reverse()
    print(*S, sep='')
else:
    print(*S, sep='')
### BUGGY CODE ###

s = input()
K = int(input())

substring = ''
for i in range(len(s)):
    for j in range(i,len(s)):
        substring += s[i:j+1] + ','
L = sorted(set(substring.split(',')[:-1]))
print(L[K-1])

### FIXED CODE ###

s = input()
K = int(input()) # 1 <= K <= 5

alpha = "abcdefghijklmnopqrstuvwxyz"
substring = ''
L = []
for i in alpha:
    indeces = [key for key, x in enumerate(s) if x == i]
    for j in indeces:
        for k in range(j,j+K):
            substring += s[j:k+1] + ','
    L += substring.split(',')[:-1] 
    if len(set(L)) >= K:
        break
    substring = ""
print(sorted(set(L))[K-1])
### BUGGY CODE ###

N = int(input())
A = map(int, input().split())
A = list(A)
index = 0
sum = 0
j = 0

for i in range(N):
    index = j
    for a in A[index:]:
        j = j + 1
        if a == (i+1):
           sum = sum + 1
           break

if sum == 0:
    print('-1')
else:
    print(N-sum)

### FIXED CODE ###

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

num = 1
ans = 0

for i in A:
    if i == num:
        num += 1
    else:
        ans += 1

if num == 1:
    print('-1')
else:
    print(str(ans))
### BUGGY CODE ###

while True:
    try:
        n = int(raw_input())
        count = 0
        for i in range(1,n+1):
            List = [i%j != 0 for j in range(3,int(i**.5)+1,2)]
            if i != 1 and all(List):
                count += 1
        print count
    except:
        break

### FIXED CODE ###

# coding: utf-8
#Problem Name: Prime Number
#ID: tabris
#Mail: t123037@kaiyodai.ac.jp

__max = 999999
List = [False,True]*(__max/2+1)
List[1] = False
List[2] = True
for i in xrange(3,int(__max**.5)+1,2):
    List[i**2::i] = [False]*len(List[i**2::i])

List = [i for i in xrange(2,__max) if List[i]]

while True:
    try:
        n = int(raw_input())
        print __import__('bisect',fromlist=['bisect_right']).bisect_right(List,n)
    except:
        break
### BUGGY CODE ###

n = int(input())
ab = [list(map(int, input().split())) for _ in range(n-1)]

if n ==1:
    print(0)
    exit()

res = [0]
res.append(ab[n-2][0]+ab[n-2][1])

for i in range(n-3,-1,-1):
    temp = ab[i][0]+ab[i][1]
    if temp <= ab[i+1][1]:
        res.append(res[-1])
    else:
        for j in range(i,n-2):
            for k in range(0,100010):
                if temp <= ab[j+1][1] + ab[j+1][2]*k:
                    temp = ab[j+1][1]+ab[j+1][2]*k +ab[j+1][0] 
                    break
        res.append(temp)

for l in range(n-1,-1,-1):
    print(res[l])

### FIXED CODE ###

n = int(input())
ab = [list(map(int, input().split())) for _ in range(n-1)]

if n ==1:
    print(0)
    exit()

res = [0]
res.append(ab[n-2][0]+ab[n-2][1])

for i in range(n-3,-1,-1):
    temp = ab[i][0]+ab[i][1]
    if temp <= ab[i+1][1]:
        res.append(res[-1])
    else:
        for j in range(i,n-2):
            if temp <= ab[j+1][1]:
                temp = ab[j+1][1] + ab[j+1][0]
            else:
                if temp % ab[j+1][2] ==0:
                    temp += ab[j+1][0]
                else:
                    temp = ((temp//ab[j+1][2])+1) * ab[j+1][2] +ab[j+1][0]
        res.append(temp)

for l in range(n-1,-1,-1):
    print(res[l])
### BUGGY CODE ###

from fractions import gcd
# https://img.atcoder.jp/agc028/editorial.pdf
N, M = map(int,input().split())
S = input()
T = input()

L = int((N*M)/gcd(N, M))

A = [None for i in range(L)]
for n in range(N):
  index =  L*n//N 
  if A[index] is None:
    A[index] = S[n]
  else:
    print(-1)
    exit()

for m in range(M):
  index =  L*m//M
  if A[index] is None or A[index] == T[m]:
    A[index] = T[m]
  else:
    print(-1)
    exit()

print(len(A))

### FIXED CODE ###

from fractions import gcd
# https://img.atcoder.jp/agc028/editorial.pdf
N, M = map(int,input().split())
S = input()
T = input()

L = int((N*M)/gcd(N, M))

gcded = gcd(N,M)
n = N//gcded
m = M//gcded
for i in range(gcded):
  if S[i*n] != T[i*m]:
    print(-1)
    exit()

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

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

for i in range(a, b+1):
    if abs(a-i) < k or abs(b-i) < k:
        print(i)

### FIXED CODE ###

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

res = []

for i in range(a, min(a+k, b+1)):
    res.append(i)

for j in range(max(a, b-k+1), b+1):
    res.append(j)

for k in sorted(set(res)):
    print(k)
### BUGGY CODE ###

#!/usr/bin/env python3
S = input()
Q = int(input())

count = 0
ans = S

for i in range(Q):
    T = input().split()
    if len(T)==1:
        count+=1
        continue

    if count%2==0:
        if T[1] == '1': ans = T[2] + ans
        else: ans += T[2]
    else:
        if T[1] == '1': ans += T[2]
        else: ans = T[2] + ans

if count%2==0:
    print(ans)
else:
    print(ans[::-1])


### FIXED CODE ###

#!/usr/bin/env python3
S = input()
Q = int(input())

count = True
ans = S

ireru_mae = ''
ireru_usiro = ''
for i in range(Q):
    T = input().split()
    if len(T)==1:
        count = not(count)
        ans = ireru_mae + ans + ireru_usiro
        ireru_mae = ''
        ireru_usiro = ''
        continue

    if count:
        if T[1] == '1': ireru_mae = T[2] + ireru_mae
        else: ireru_usiro += T[2]
    else:
        if T[1] == '1': ireru_usiro += T[2]
        else: ireru_mae = T[2] + ireru_mae

ans = ireru_mae + ans + ireru_usiro
if count:
    print(ans)
else:
    print(ans[::-1])
### BUGGY CODE ###

from collections import defaultdict
N = int(input())


def prime_factorize(n):
    a = defaultdict(int)
    while n % 2 == 0:
        a[2] += 1
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a[f] += 1
            n //= f
        else:
            f += 2
    if n != 1:
        a[n] += 1

    b = 1
    for _, v in a.items():
        b *= v + 1
    return b


ans = 0
for i in range(1, N+1):
    ans += i * prime_factorize(i)

print(ans)


### FIXED CODE ###

N = int(input())

T = [1] * (N+1)

for i in range(2, N+1):
    c = 1
    while i * c <= N:
        T[i * c] += 1
        c += 1

ans = 0

for i in range(1, N+1):
    ans += i * T[i]

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

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

P = list(map(int,input().split()))

def calc_e(p):
    temp = 0
    for i in range(1, p + 1):
#        temp += i * (1 / p)
        temp = 0.5 + 0.5 * p
    return temp

temp_max = 0
temp_i = 0

for i in range(N - K + 1):
    temp = sum(P[i:i+K])
    if temp_max <= temp:
        temp_max = temp
        temp_i = i


temp = 0
for i in range(temp_i,temp_i + K):
    temp += calc_e(P[i])
print(temp)

### FIXED CODE ###


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

temp_num = sum(line[0:K])
temp_max = temp_num

for i in range(N - K):
    temp_num = temp_num - line[i] + line[i + K]
    if temp_num > temp_max:
        temp_max = temp_num


print((temp_max + K) / 2)
### BUGGY CODE ###

import math

N=int(input())
count=[0]*(N+1)
for i in range(1,N+1):
  for x in range(1,int(math.sqrt(N+1))):
    for y in range(1,int(math.sqrt(N+1))):
      for z in range(1,int(math.sqrt(N+1))):
        if(x**2+y**2+z**2+x*y+y*z+z*x==i):
          count[i]+=1
  print(count[i])

### FIXED CODE ###

N=int(input())
count=[0]*(N+1)
for x in range(1,100):
  for y in range(1,100):
    for z in range(1,100):
      n=x*x+y*y+z*z+x*y+y*z+z*x
      if(n<=N):
        count[n]+=1
for i in range(1,N+1):
  print(count[i])
### BUGGY CODE ###

N = input()
A = input()

A = A.split()
A = [int(a) for a in A]

ANS = 0
while len(A) != 0:
    ANS = ANS + (len(A) - A.index(max(A))) * A[A.index(max(A))] - sum(A[A.index(max(A)):])
    A = A[:A.index(max(A))]

print(ANS)

### FIXED CODE ###

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

MAX = 0
ANS = 0

for i in range(N):
    ANS += max(0, MAX - A[i])
    MAX = max(MAX, A[i])

print(ANS)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

X, Y, Z, K = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]

ablst = [m + n for n in b for m in a]

ablst.sort(reverse=True)

c.sort(reverse=True)

abclst = [m + n for n in c[:K] for m in ablst[:K]]

abclst.sort(reverse=True)

print(*abclst[:K], sep='\n')


### FIXED CODE ###

import sys
input = sys.stdin.readline

X, Y, Z, K = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]

a.sort(reverse=True)
b.sort(reverse=True)

ablst = [m + n for n in b for m in a]

ablst.sort(reverse=True)

c.sort(reverse=True)

abclst = [m + n for n in c[:K] for m in ablst[:K]]

abclst.sort(reverse=True)

print(*abclst[:K], sep='\n')
### BUGGY CODE ###

n=int(input())
A=list(map(int,input().split()))
mod=10**9+7
ans=0
for i in range(62):
    cnt=0
    for j in range(n):
        cnt+=(A[j]>>i)&1
    ans+=cnt * (n-cnt) *(2**i)%mod
print(ans%mod)

### FIXED CODE ###

n=int(input())
A=list(map(int,input().split()))
mod=10**9+7
ans=0
for i in range(62):
    cnt=0
    for j in range(n):
        cnt+=(A[j]>>i)&1
    ans+=cnt * (n-cnt) *(2**i)%mod
print(ans%mod)
### BUGGY CODE ###

import sys

class binarySearchTree:
    def __init__(self):
        self.root = None

    def insert(self, key):
        z = Node(key)
        y = None
        x = self.root
        while x:
            y = x
            if z.key < x.key:
                x = x.left
            else:
                x = x.right

        if y is None:
            self.root = z
        elif z.key < y.key:
            y.left = z
        else:
            y.right = z

    def printBT(self):
        print inorderTreeWalk(self.root)
        print preorderTreeWalk(self.root)

class Node:
    def __init__(self, key):
        self.key = key
        self.left = None
        self.right = None

def inorderTreeWalk(node):
    if node:
        return inorderTreeWalk(node.left) + " " + str(node.key) + inorderTreeWalk(node.right)
    return ""

def preorderTreeWalk(node):
    if node:
        return " " + str(node.key) + preorderTreeWalk(node.left) + preorderTreeWalk(node.right)
    return ""

if __name__ == "__main__":
    m = int(raw_input())
    bt = binarySearchTree()
    for i in range(m):
        line = raw_input()
        if line[0] == "i":
            bt.insert(int(line.split()[1]))
        else:
            bt.printBT()

### FIXED CODE ###

import sys

class Node:
    def __init__(self, key):
        self.key = key
        self.parent = None
        self.left = None
        self.right = None

def insert(z):
    global root
    y = None
    x = root
    while x is not None:
        y = x
        if z.key < x.key:
            x = x.left
        else:
            x = x.right
    z.parent = y
    if y is None:
        root = z
    elif z.key < y.key:
        y.left = z
    else:
        y.right = z

def inorderTreeWalk(node):
    global In
    if node:
        inorderTreeWalk(node.left)
        In.append(str(node.key))
        inorderTreeWalk(node.right)

def preorderTreeWalk(node):
    global Pre
    if node:
        Pre.append(str(node.key))
        preorderTreeWalk(node.left)
        preorderTreeWalk(node.right)

if __name__ == "__main__":
    lines = sys.stdin.readlines()
    del lines[0]

    root = None
    for line in lines:
        if line[0] == "i":
            insert(Node(int(line.split()[1])))
        else:
            In = []
            Pre = []
            inorderTreeWalk(root)
            print " " + " ".join(map(str, In))
            preorderTreeWalk(root)
            print " " + " ".join(map(str, Pre))
### BUGGY CODE ###

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

A.sort()
B.sort()
C.sort()

from fractions import gcd
from math import ceil
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations

ans = 0
ind = bisect_right(B,A[0])
for a in A:
    if a >= B[-1]:
        continue
    while a >= B[ind]:
        ind += 1
    for b in B[ind:]:
        indc = bisect_right(C,b)
        ans += N-indc

        

print(ans)

### FIXED CODE ###

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

A.sort()
B.sort()
C.sort()

from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort

ans = 0

for b in B:
    ans += bisect_left(A,b) * (N - bisect_right(C,b))

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

S=str(input())
k=len(S)
count=0
for i in range(k-2):
    for j in range(4,k):
        if i+j>k:
            continue
        n=int(S[i:i+j])
        if n%2019==0:
            count+=1
print(count)


### FIXED CODE ###

S=str(input())
n=len(S)
mod=2019
ans=0
mod_set=[0]*mod
mod_set[0]+=1
ten=1
k=0
for i in range(n-1,-1,-1):
    k=(k+ten*int(S[i]))%mod
    mod_set[k]+=1
    ten=(ten*10)%mod

for i in mod_set:
    ans+=i*(i-1)//2
print(ans)