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

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

T = 0
for i in range(Q):
    Query = list(input().split())
    if Query[0] == "1" :
        T = T + 1
    elif Query[0] == "2" :
        if T % 2 == 0 :
            if Query[1] == "1" :
                S = Query[2] + S
            elif Query[1] == "2" :
                S = S + Query[2]
        elif T % 2 == 1 :
            if Query[1] == "1" :
                S = S + Query[2]
            elif Query[1] == "2" :
                S = Query[2] + S

if T % 2 == 1 :
    S = S[::-1]

print(S)

### FIXED CODE ###

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

T = ""
for i in range(Q) :
    Query = list(input().split())
    if Query[0] == "1" :
        S, T = T, S
    elif Query[0] == "2" :
        if Query[1] == "1" :
            T = T + Query[2]
        elif Query[1] == "2" :
            S = S + Query[2]

T = T[::-1]
T = T + S
print(T)
### BUGGY CODE ###

# your code goes here
N = int(input())
point = list(map(int,input().split()))

for i in range(N):
	prev = 0
	ans = 0
	for j in range(N):
		if j == i:
			continue
		ans += abs(point[j] - prev)
		prev = point[j]
	ans += abs(prev)
	print(ans)

### FIXED CODE ###

# your code goes here
N = int(input())
point = [0]
point.extend(list(map(int,input().split())))
point.append(0)

total = 0
for i in range(1,N+2):
	total += abs(point[i] - point[i-1])

for i in range(1,N+1):
	ans = total - abs(point[i]-point[i-1]) - abs(point[i+1]-point[i]) + abs(point[i+1]-point[i-1])
	print(ans)
### BUGGY CODE ###


N=int(input())
A=[int(input()) for i in range(N)]
lst=[]
nowN=max(A)+1
i=0
while i<N:
    if nowN>=A[i]:
        nowN=A[i]
        lst.append([A[i]])
    else:
        flag=0
        for n in range(len(lst)):
            if lst[n][-1]<A[i]:
                lst[n].append(A[i])
                flag=1
                break
        if not flag:
            lst.append([A[i]])
    i+=1
print(len(lst))


### FIXED CODE ###

import bisect
import collections

N=int(input())
A=[int(input()) for i in range(N)]
B=[0 for i in range(N)]
C=sorted(A)
count=0
lst=collections.deque([])
for i in range(N):
    if A[i]==C[-1]:
        C.pop()
        if lst:
            lst.pop()
        else:
            count+=1
        continue
    idx=bisect.bisect_left(lst,A[i])-1
    #print(idx,lst,A[i])
    if idx<0:
        lst.appendleft(A[i])
        count+=1
    else:
        lst[idx]=A[i]

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

#!/usr/bin/env python3
import sys
from collections import defaultdict
from collections import Counter
from collections import OrderedDict

def solve(N: int, s: "List[str]"):
    count_dict = defaultdict(int)
    for i, string in enumerate(s):
        string = list(string)
        info = sorted(OrderedDict(Counter(string)).items(), key=lambda x:x[0])
        info = tuple([tuple([i, j]) for i, j in info])
        count_dict[info] += 1
    result = 0
    for _, v in count_dict.items():
        result += int((v-1) * 0.5 * (1 + v-1))
        #result += sum([i for i in range(v)])
    print(result)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    s = [ next(tokens) for _ in range(N) ]  # type: "List[str]"
    solve(N, s)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
from collections import defaultdict
from collections import Counter

def solve(N: int, s: "List[str]"):
    count_dict = defaultdict(int)
    for i, string in enumerate(s):
        string = list(string)
        info = sorted(Counter(string).items(), key=lambda x:x[0])
        info = tuple([tuple([i, j]) for i, j in info])
        count_dict[info] += 1

    result = 0
    for _, v in count_dict.items():
        result += int((v-1) * 0.5 * (1 + v-1))
    print(result)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    s = [ next(tokens) for _ in range(N) ]  # type: "List[str]"
    solve(N, s)

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

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

P_extracted = [0]
for i in range(0, (n-k)+1):
    tmp = P[i:i+k]
    # print(tmp)
    if sum(P_extracted) < sum(tmp):
        P_extracted = tmp
# print(tmp)
e = 0
for i in P_extracted:
    tmp = 0
    for j in range(1, i+1):
        tmp += j / i
    # print(tmp)
    e += tmp
print(e)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

INF = float('inf')

def tsum(l, r):
    return (r + l) * (r - l + 1) // 2

def exp(num):
    return tsum(1, num) / num

def solve():
    n, k = MI()
    P = LI()

    E = [0] * n
    pre = 0
    for i in range(n):
        E[i] = pre + exp(P[i])
        pre = E[i]
    # print(E)

    p = E[0]
    mx = E[k-1]
    for j in range(k, n):
        diff = E[j] - E[j-k]
        # print(diff)
        if mx < diff:
            mx = diff
    print(mx)


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

S = input()
K = int(input())

A = []
for i in range(len(S)):
    for j in range(1,len(S)+1):
        if S[i:j] != "":
            A.append(S[i:j])

A = sorted(set(A))
#A = sorted(set(A), key=A.index)

B =[]
for i in A:
    if len(i) < 6:
        B.append(i)
        
print(B[K-1])

### FIXED CODE ###

S = input()
K = int(input())

A = []
for i in range(len(S)):  
    for j in range(1,i + 6):
        if S[i:j] != "":
            A.append(S[i:j])

A = sorted(set(A))
        
print(A[K-1])
### BUGGY CODE ###

import itertools

N = int(input())

data = []
min_value_0 = 0
for _ in range(N):
	X, Y, P = town = tuple(map(int, input().split()))
	data.append(town)
	min_value_0 += min(abs(X), abs(Y)) * P

print(min_value_0)

B = 2 ** N
table_h = []
table_v = []

for b in range(B):
	towns = []
	i = 0
	x = b
	while x > 0:
		if x % 2 == 1:
			towns.append(i)
		x //= 2
		i += 1
	dists_h = []
	dists_v = []
	for i in range(N):
		X0, Y0, P0 = data[i]
		d_h = abs(X0)
		d_v = abs(Y0)
		for j in towns:
			X1, Y1, P1 = data[j]
			d_h = min(d_h, abs(X1 - X0))
			d_v = min(d_v, abs(Y1 - Y0))
		dists_h.append(d_h * P0)
		dists_v.append(d_v * P0)
	table_h.append(dists_h)
	table_v.append(dists_v)
#	print(f"{{:0{N}b}}".format(b), dist_h, dist_v)

table = [min_value_0] * (N + 1)

import sys

def calc(c, b0, b1, b, n):
	if n == N:
		value = 0
		t1 = table_h[b0]
		t2 = table_v[b1]
		for i in range(N):
			value += min(t1[i], t2[i])
		if table[c] > value:
			table[c] = value
	else:
		calc(c, b0, b1, b * 2, n + 1)
		calc(c + 1, b0 + b, b1, b * 2, n + 1)
		calc(c + 1, b0, b1 + b, b * 2, n + 1)

calc(0, 0, 0, 1, 0)

for i in range(1, N):
	print(table[i])

print(0)


### FIXED CODE ###

import itertools

N = int(input())

data = []
min_value_0 = 0
for _ in range(N):
	X, Y, P = town = tuple(map(int, input().split()))
	data.append(town)
	min_value_0 += min(abs(X), abs(Y)) * P

print(min_value_0)

B = 2 ** N
table_h = []
table_v = []

for b in range(B):
	towns = []
	i = 0
	x = b
	while x > 0:
		if x % 2 == 1:
			towns.append(i)
		x //= 2
		i += 1
	dists_h = []
	dists_v = []
	for i in range(N):
		X0, Y0, P0 = data[i]
		d_h = abs(X0)
		d_v = abs(Y0)
		for j in towns:
			X1, Y1, P1 = data[j]
			d_h = min(d_h, abs(X1 - X0))
			d_v = min(d_v, abs(Y1 - Y0))
		dists_h.append(d_h * P0)
		dists_v.append(d_v * P0)
	table_h.append(dists_h)
	table_v.append(dists_v)
#	print(f"{{:0{N}b}}".format(b), dist_h, dist_v)

table = [min_value_0] * (N + 1)

import sys

stack = [0] * N
i = 0
c = 0
b0 = 0
b1 = 0
b = 1
while True:
	if i == N:
		value = 0
		t1 = table_h[b0]
		t2 = table_v[b1]
		for j in range(N):
			value += min(t1[j], t2[j])
		if table[c] > value:
			table[c] = value
		i -= 1
		b //= 2
	else:
		s = stack[i]
		if s == 3:
			if i == 0:
				break
			else:
				stack[i] = 0
				i -= 1
				b //= 2
		else:
			if s == 0:
				b0 += b
				c += 1
			elif s == 1:
				b0 -= b
				b1 += b
			else:
				b1 -= b
				c -= 1
			stack[i] = s + 1
			i += 1
			b *= 2

for i in range(1, N):
	print(table[i])

print(0)
### BUGGY CODE ###

N, K= map(int, input().split())
H=list(map(int, input().split()))
if K>=len(H):
    print(0)
else:
    for i in range(K):
        index=H.index(max(H))
        H.pop(index)
    print(sum(H))

### FIXED CODE ###

N, K= map(int, input().split())
H=list(map(int, input().split()))
if K>=len(H):
    print(0)
else:
    if K==0:
        print(sum(H))
    else:
        H=sorted(H)
        print(sum(H[:-K]))
### BUGGY CODE ###

import sys

def main():
    N, M = map(int, input().split())
    a = [int(sys.stdin.readline().strip()) for _ in range(M)]

    dp = [0]*(N+1)

    for i in range(0, N+1):
        if i in a:
            dp[i] = 0
            continue

        if i == 0 or i == 1:
            dp[i] = 1
            continue

        dp[i] = dp[i-1] + dp[i-2]

    print(dp[N] % 1000000007)

main()

### FIXED CODE ###

import sys
from collections import deque

def main():
    N, M = map(int, input().split())
    a = deque([int(sys.stdin.readline().strip()) for _ in range(M)])

    atmp = -1
    if len(a) != 0:
        atmp = a.popleft()

    dp=[0] * (N+1)
    for i in range(0, N+1):
        if i == atmp:
            if len(a) != 0:
                atmp = a.popleft()
            continue

        if i == 0 or i == 1:
            dp[i] = 1
            continue

        if dp[i-1] == 0 and dp[i-2] == 0:
            break


        dp[i] = dp[i-1] + dp[i-2]

    print(dp[N] % 1000000007)

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

import sys
# input = sys.stdin.buffer.readline
def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)

MOD = 10**9+7

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

ans = 0
for i in range(60):
    zero, one = 0, 0
    for j in range(N):
        if A[j]>>i&1:
            one += 1
        else:
            zero += 1
    ans += (one * zero)<<i
    ans %= MOD
print(ans)


### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
MOD = 10**9+7

ans = 0
for i in range(60):
    ones = 0
    for j in range(N):
        if ((A[j] >> i) & 1):
            ones += 1
    ans += 2**i * ones * (N - ones) % MOD
    ans %= MOD

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

n,k = map(int,input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
a.sort()
b.sort(reverse=True)


def ok(mid,a,b,k,n):
    tmp = 0
    for i in range(n):
        if a[i] * b[i] > mid:
            tmp += a[i] - mid//b[i]
    if tmp > k:
        return 1
    else:
        return -1


def bin_search(a,b,k,n):
    l = 0
    r = 10**20
    while l <= r:
        mid = l + (r - l)//2
        res = ok(mid,a,b,k,n)
        if res < 0:
            r = mid - 1
        else:
            l = mid + 1
    return l


print(bin_search(a,b,k,n))

### FIXED CODE ###

n,k = map(int,input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
a.sort()
b.sort(reverse=True)


def ok(mid,a,b,k,n):
    tmp = 0
    for i in range(n):
        if a[i] * b[i] > mid:
            tmp += a[i] - mid//b[i]
    if tmp > k:
        return 1
    else:
        return -1


def bin_search(a,b,k,n):
    l = 0
    r = 10**12
    while l <= r:
        mid = l + (r - l)//2
        res = ok(mid,a,b,k,n)
        if res < 0:
            r = mid - 1
        else:
            l = mid + 1
    return l


print(bin_search(a,b,k,n))
### BUGGY CODE ###

from itertools import combinations
from decimal import Decimal
import math


def solve(a, b):
    x = a * b
    return int(x) == math.ceil(x)


n = int(input())
arr = [Decimal(input()) for _ in range(n)]


ans = []
for x, y in combinations(arr, 2):
    ans.append(solve(x, y))

print(sum(ans))

### FIXED CODE ###

def div(n, d):
    cnt = 0
    while n % d == 0 and cnt < 18:
        n //= d
        cnt += 1
    return cnt


n = int(input())
dp = [[0]*19 for _ in range(19)]

ans = 0
for _ in range(n):
    x = round(float(input()) * pow(10, 9))
    two = div(x, 2)
    five = div(x, 5)
    ans += dp[18 - two][18 - five]
    for i in range(two + 1):
        for j in range(five + 1):
            dp[i][j] += 1

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

from collections import deque
N, M, K = map(int, input().split())
F = dict()
Block = dict()
for i in range(1, N+1):
    F[i] = []
    Block[i] = []

for _ in range(M):
    A, B = map(int, input().split())
    F[A].append(B)
    F[B].append(A)
for _ in range(K):
    C, D = map(int, input().split())
    Block[C].append(D)
    Block[D].append(C)

def dfs(i, F):
    cnt = 0
    visited = [False]*N
    visited[i-1] = True
    deq = deque(F[i])
    while deq:
        Q = deq.pop()
        if type(Q) == int:
            Q = [Q]
        for q in Q:
            if visited[q-1]:
                continue
            visited[q-1] = True
            if q not in F[i] and  q not in Block[i]:
                cnt += 1
            deq.append(F[q])
    return cnt

for i in range(1, N+1):
    if i != N:
        print(dfs(i, F), end=' ')
    else:
        print(dfs(i, F))

### FIXED CODE ###

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

class UnionFind:
    def __init__(self, n):
        self.ps = [-1] * (n + 1)
 
    def find(self, x):
        if self.ps[x] < 0:
            return x
        else:
            self.ps[x] = self.find(self.ps[x])
            return self.ps[x]
 
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if self.ps[x] > self.ps[y]:
            x, y = y, x
        self.ps[x] += self.ps[y]
        self.ps[y] = x
        return True
 
    def same(self, x, y):
        return self.find(x) == self.find(y)
 
    def size(self, x):
        x = self.find(x)
        return -self.ps[x]

uf = UnionFind(N)
friends = [0]*(N+1)
chain = [0]*(N+1)


for _ in range(M):
    A, B = map(int, input().split())
    friends[A] += 1
    friends[B] += 1
    uf.union(A, B)

for _ in range(K):
    C, D = map(int, input().split())
    if uf.same(C, D):
        friends[C] += 1
        friends[D] += 1

ans = []

for i in range(1, N+1):
    ans.append(uf.size(i) - friends[i] - 1)

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

ans = 0
k = int(input())
def GCD(a, b):
  if b == 0:
    return a
  else:
    return GCD(b, a%b)
for i in range(1, k+1):
  for j in range(1, k+1):
    gcd = GCD(i, j)
    for l in range(1, k+1):
      ans += GCD(gcd, l)
print(ans)

### FIXED CODE ###

from math import gcd
ans = 0
k = int(input())
for i in range(1, k+1):
  for j in range(1, k+1):
    GCD = gcd(i, j)
    for l in range(1, k+1):
      ans += gcd(GCD, l)
print(ans)
### BUGGY CODE ###

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


def formation():
    global S, Q

    ls = list(S)
    for _ in range(Q):
        t_str = input()

        if t_str[0] == '1':
            ls.reverse()
        else:
            splited = t_str.split(' ')
            f = splited[1]
            c = splited[2]
            if f == '1':
                ls.insert(0, c)
            else:
                ls.append(c)

        #print(ls)

    return ''.join(ls)


print(formation())


### FIXED CODE ###

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


class Node:
    def __init__(self, value=None, prev=None, next=None):
        self.value = value
        self.prev = prev
        self.next = next

    def __str__(self):
        return str(self.value)


class LinkedList:
    def __init__(self, initial_string=None):
        self.first = Node()
        self.last = Node()
        self.first.next = self.last
        self.last.prev = self.first
        self.should_reverse = False
        for s in initial_string:
            self.insert_last(s)

    def _insert_first(self, value=None):
        prev_next = self.first.next
        self.first.next = Node(value, self.first, prev_next)
        prev_next.prev = self.first.next

    def _insert_last(self, value=None):
        prev_prev = self.last.prev
        self.last.prev = Node(value, prev_prev, self.last)
        prev_prev.next = self.last.prev

    def insert_first(self, value=None):
        if self.should_reverse:
            self._insert_last(value)
        else:
            self._insert_first(value)

    def insert_last(self, value=None):
        if self.should_reverse:
            self._insert_first(value)
        else:
            self._insert_last(value)

    def set_reverse(self):
        self.should_reverse = not self.should_reverse

    def _print(self):
        node = self.first.next
        while node is not None:
            if node.value is not None:
                print(node, end="")
            node = node.next
        print("")

    def _print_reverse(self):
        node = self.last.prev
        while node is not None:
            if node.value is not None:
                print(node, end="")
            node = node.prev
        print("")

    def print_list(self):
        if self.should_reverse:
            self._print_reverse()
        else:
            self._print()


def formation():
    global S, Q

    linked_list = LinkedList(S)

    for _ in range(Q):
        t_str = input()

        if t_str[0] == '1':
            linked_list.set_reverse()
        else:
            split = t_str.split(' ')
            f = split[1]
            c = split[2]
            if f == '1':
                linked_list.insert_first(c)
            else:
                linked_list.insert_last(c)

    linked_list.print_list()


formation()
### BUGGY CODE ###

#import sys
#sys.setrecursionlimit(10**5)
MOD = 10**9+7

# input
N = int(input())
C = list(map(int, input().split()))
    
# process
C.sort(reverse=True)
ans = 0

if N == 1:
    ans = C[0]
else:
    for i in range(N):
        ans += C[i]*(2+i)*2**(N-2)
        
# output
print(ans*2**N%MOD)


### FIXED CODE ###

#import sys
#sys.setrecursionlimit(10**5)
MOD = 10**9+7

# input
N = int(input())
C = list(map(int, input().split()))
    
# process
C.sort(reverse=True)
ans = 0

if N == 1:
    ans = C[0]*2**N
else:
    for i in range(N):
        ans += C[i]*(2+i)

    ans *= 4**(N-1)

# output
print(ans%MOD)
### BUGGY CODE ###

def dijkstra(g,n,s):
    '''
    input
        g: n x n　list
        n: int
        s: start index
    '''
    d = [float('inf')]*n
    U = [i for i in range(n)]
    d[s] = 0
    while len(U)>0:
        w = U[0]
        for u in U:
            if d[u]<d[w]:
                w = u
        U.pop(U.index(w))
        for v in U:
            d[v] = min(d[v],d[w]+g[w][v])
    return d

def main():
    n = int(input())
    G = [[float('inf') for i in range(n)] for i in range(n)]
    for _ in range(n-1):
        a,b,c = map(int,input().split())
        G[a-1][b-1] = G[b-1][a-1] = c
    q,k = map(int,input().split())
    d = dijkstra(G, n, k-1)
    for _ in range(q):
        x,y = map(int,input().split())
        print(d[x-1]+d[y-1])

if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    n = int(input())
    G = {}
    for i in range(n):
        G[i+1] = []
    for _ in range(n-1):
        a,b,c = map(int,input().split())
        G[a] += [[b,c]]
        G[b] += [[a,c]]
    q,k = map(int,input().split())
    dist = [-1]*n
    dist[k-1] = 0
    que = [k]
    while len(que) > 0:
        s = que.pop(0)
        for [nv,c] in G[s]:
            if dist[nv-1] != -1:
                continue
            dist[nv-1] = dist[s-1]+c
            que.append(nv)
    for _ in range(q):
        x,y = map(int,input().split())
        print(dist[x-1]+dist[y-1])

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

import numpy as np

N, K = [int(i) for i in input().split()]
P = [int(p) for p in input().split()]

max_P = []
max = 0
for i in range(N-K+1):
    tmp = P[i:i+K]
    sum_dice = np.sum(tmp)
    if sum_dice > max:
        max = sum_dice
        max_P = tmp

ans = 0
for p in max_P:
    ans += np.sum(np.arange(1,p+1))/p

print(ans)


### FIXED CODE ###

import numpy as np

N, K = [int(i) for i in input().split()]
P = [int(p) for p in input().split()]

max = 0
sum = 0
for i in range(N):
    sum += P[i]
    if i >= K:
        sum -= P[i-K]
    if max < sum:
        max = sum
print((max+K)/2)
### BUGGY CODE ###

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

for i in range(N):
  a = input()
  if(a in list_A):
    list_A.remove(a)
  else:
    list_A.append(a)

ans = len(list_A)

print(ans)

### FIXED CODE ###

N = int(input())
A = []
B = []
for i in range(N):
  A.append(int(input()))
  
A.sort()
B.append(1)

for i in range(1, N):
  if(A[i]!= A[i- 1]):
    B.append(1)
  else:
    B[-1]+= 1
  i+= 1
  
ans = list(filter(lambda x: x % 2 == 1, B))

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

import numpy as np
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    s=STR()
    count=np.zeros(2019,dtype=int)
    ans=0
    count_t=np.zeros(2019,dtype=int)
    for i in range(len(s)):
        count_t[int(s[i])]+=1
        for k in range(2019):
            t=(k*10+int(s[i]))%2019
            count_t[k]-=count[k]
            count_t[t]+=count[k]
            if t==0:
                ans+=count[k]
        #print(count[0:20])
        #print(count_t[0:20])
        count=count+count_t
        count_t-=count_t
    print(ans)
                
if __name__ == '__main__':
    do()

### FIXED CODE ###

INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    s=STR()
    cnt=[0]*2019
    cnt[0]=1
    temp=0
    keta=1
    ans=0
    for i in s[::-1]:
        temp=(temp+int(i)*keta)%2019
        keta=(keta*10)%2019
        cnt[temp]+=1
    for i in cnt:
        ans+=(i*(i-1))//2
    print(ans)
    
    
if __name__ == '__main__':
    do()
### BUGGY CODE ###

import numpy as np

N, C = map(int, input().split(' '))
s = []
t = []
c = []
for i in range(N):
    s_i, t_i, c_i = map(int, input().split(' '))
    s.append(s_i)
    t.append(t_i)
    c.append(c_i - 1)
T = 2*max(t)
table = np.zeros(T)
for i in range(C):
    table_i = np.zeros(T)
    for j in range(N):
        if c[j] == i:
            table_i[2*s[j]-1: 2*t[j]] += 1
    table += list(map(lambda x: 1 if x>0 else 0, table_i))
print(int(np.max(table)))

### FIXED CODE ###

import numpy as np

import numpy as np

N, C = map(int, input().split(' '))
s = []
t = []
c = []
for i in range(N):
    s_i, t_i, c_i = map(int, input().split(' '))
    s.append(s_i)
    t.append(t_i)
    c.append(c_i - 1)
T = 2*max(t)
# for i in range(N):
#     table[2*s[i]-1: 2*t[i]] += 1
table = np.zeros(T)
for i in range(C):
    table_i = np.zeros(T)
    for j in range(N):
        if c[j] == i:
            table_i[2*s[j]-1: 2*t[j]] = 1
    table += table_i
print(int(np.max(table)))
### BUGGY CODE ###

N, K = map(int, input().split())
*A, = map(int, input().split())
*F, = map(int, input().split())
A.sort()
F.sort(reverse=True)

def f(x):
    ans = 0
    for i,j in zip(A, F):
        ans += (i*j-x+j-1)//j if i*j-x>=0 else 0
    return ans<=K

l, r = -1, 10**18+1
while r-l>1:
    mid = (r+l)//2
    if f(mid):
        r = mid
    else:
        l = mid

print(r)

### FIXED CODE ###

N, K = map(int, input().split())
*A, = map(int, input().split())
*F, = map(int, input().split())
A.sort()
F.sort(reverse=True)

def f(x):
    ans = 0
    for i,j in zip(A, F):
        ans += (i*j-x+j-1)//j if i*j-x>=0 else 0
    return ans<=K

l, r = -1, 10**18+1
while r-l>1:
    mid = (r+l)//2
    if f(mid):
        r = mid
    else:
        l = mid

print(r)