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

import heapq

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

A = sorted(A)
Minus_A = [-x for x in A]
F = sorted(F, reverse=True)

Sec = []
for i in range(n):
    Sec.append(Minus_A[i]*F[i])

hq = []
for i in range(n):
    heapq.heappush(hq, [Sec[i], Minus_A[i], F[i]])

for i in range(k):
    dec_obj = heapq.heappop(hq)
    if dec_obj[1] < 0:
        dec_obj[1] = dec_obj[1] + 1
        dec_obj[0] = dec_obj[1] * dec_obj[2]
        heapq.heappush(hq, dec_obj)
        # print(hq)
    else:
        break

ans_obj = heapq.heappop(hq)
ans = ans_obj[0] * -1
print(ans)

### FIXED CODE ###

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

A = sorted(A)
Minus_A = [-x for x in A]
F = sorted(F, reverse=True)

high = 10**12
low = 0
while high - low > 1:
    mid = low + (high-low)//2
    count = 0

    for i in range(n):
        now = mid // F[i]
        count += max(A[i] - now, 0)
    
    # print('-'*30)
    # print(mid)
    # print(count)
    if count > k:
        low = mid
    else:
        high = mid
    
ans = high

if sum(A) <= k:
    ans = 0

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

n = int(input())
L = list(map(int, input().split()))
ret = []
for i in range(1,n+1):
  for k, x in enumerate(L):
    if x == i:
      ret.append(k+1)
      break
print(*ret)

### FIXED CODE ###

n = int(input())
L = list(map(int, input().split()))
ret = []
L = sorted(range(len(L)), key=lambda k: L[k])
print(*map(lambda x: x+1, L))
### BUGGY CODE ###

N = int(input())
c = 0
n = 0
list = []
for l in range(1,N+1):
    list = []
    for i in range(1,l+1):
        if i*i > l:
            break;       
        for j in range(1,l+1):
            if i*i + j*j + i*j > l:
                break;
            for k in range(1,l+1):
                #print(i,j,k,l)
                if i*i + j*j + k*k + i*j +j*k + i*k == l:
                    list.append(1)
                    break;
    print(sum(list))

### FIXED CODE ###

N = int(input())
list = [0]*(N+1)
for i in range(1,100):  
    for j in range(1,100):
        a = i*i + j*j + i*j
        for k in range(1,100):
            a = i*i + j*j + k*k + i*j +j*k + i*k
            if a <= N:
                list[a] += 1
for i in range(1,N+1):
    print(list[i])
### BUGGY CODE ###

NM=list(map(int,input().split()))
N=NM[0]
M=NM[1]
graph=[[] for j in range(N)]

for i in range(M):
  edge=list(map(int,input().split()))
  graph[edge[0]-1].append(edge[1]-1)
  
ST=list(map(int,input().split()))
S=ST[0]-1
T=ST[1]-1



first=[]
second=[]
third=[]
able=[S]

step=0

while True:
  first=[]
  second=[]
  third=[]
  judge = 0
  for i in range(len(able)):
    for j in range(len(graph[able[i]])):
      if not (graph[able[i]][j] in first):
        first.append(graph[able[i]][j])
  for i in range(len(first)):
    for j in range(len(graph[first[i]])):
      if not (graph[first[i]][j] in second):
        second.append(graph[first[i]][j])
  for i in range(len(second)):
    for j in range(len(graph[second[i]])):
      if not (graph[second[i]][j] in third):
        third.append(graph[second[i]][j])
  for i in range(len(third)):
      if not third[i] in able:
        able.append(third[i])
        judge = 1
  if judge == 0:
    print(-1)
    break
  step+=1
  if T in able:
    print(step)
    break
    
  

      




### FIXED CODE ###



import sys
from collections import deque, defaultdict
import copy
import bisect
#sys.setrecursionlimit(10 ** 9)
import math
import heapq
from itertools import combinations, permutations

import sys
def input():
	return sys.stdin.readline().strip()


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

graph = [[] for _ in range(3*N)]

for i in range(M):
	u, v = list(map(int, input().split()))
	u -= 1
	v -= 1
	graph[u%(3*N)].append((v + N)%(3*N))
	graph[(u + N) % (3 * N)].append((v+2*N)%(3*N))
	graph[(u + 2*N) % (3 * N)].append(v % (3 * N))
S, T = list(map(int, input().split()))
S -= 1
T -= 1

dist = [1000000000000000000 for _ in range(3*N)]
que = deque([])
que.append(S)
dist[S] = 0
while len(que) > 0:
	node = que.popleft()
	for edge in graph[node]:
		if dist[edge] > dist[node] + 1:
			dist[edge] = dist[node] + 1
			que.append(edge)

if dist[T] < 100000000000000:
	print(dist[T]//3)
else:
	print(-1)
### BUGGY CODE ###

import numpy as np

A,B,Q = map(int, input().split())
S=np.zeros([A])
T=np.zeros([B])
X=np.zeros([Q])
for i in range(A):
  S[i] = int(input())
for i in range(B):
  T[i] = int(input())
S = np.concatenate([[float('inf')],S,[float('inf')]],axis=0)
T = np.concatenate([[float('inf')],T,[float('inf')]],axis=0)
for i in range(Q):
  x = int(input())
  dist_x_S = S - x
  dist_x_S_abs = np.abs(dist_x_S)
  min_index = np.argmin(dist_x_S_abs)
  if dist_x_S[min_index] > 0:
    nearest_x_S = [dist_x_S[min_index-1], dist_x_S[min_index]]
  elif dist_x_S[min_index] < 0:
    nearest_x_S = [dist_x_S[min_index], dist_x_S[min_index+1]]
  else:
    nearest_x_S = [0, dist_x_S[np.argmin([np.abs(dist_x_S[min_index-1]),np.argmin(dist_x_S[min_index+1])])]]
  
  dist_x_T = T - x
  dist_x_T_abs = np.abs(dist_x_T)
  min_index = np.argmin(dist_x_T_abs)
  if dist_x_T[min_index] > 0:
    nearest_x_T = [dist_x_T[min_index-1], dist_x_T[min_index]]
  elif dist_x_T[min_index] < 0:
    nearest_x_T = [dist_x_T[min_index], dist_x_T[min_index+1]]
  else:
    nearest_x_T = [0, dist_x_T[np.argmin([np.abs(dist_x_T[min_index-1]),np.argmin(dist_x_T[min_index+1])])]]  
  
  ans_cand = []
  for x_S in nearest_x_S:
    for x_T in nearest_x_T:
      if x_S*x_T > 0:
        ans_cand.append(max(abs(x_S),abs(x_T)))
      else:
        ans_cand.append(abs(x_S)+abs(x_T)+min(abs(x_S),abs(x_T)))
  print(int(min(ans_cand)))
  
  


### FIXED CODE ###

mod = 1000000007
eps = 10**-9
inf = 10**15


def main():
    import sys
    from bisect import bisect_left
    input = sys.stdin.buffer.readline

    A, B, Q = map(int, input().split())
    S = [-inf]
    for _ in range(A):
        S.append(int(input()))
    S.append(inf)
    T = [-inf]
    for _ in range(B):
        T.append(int(input()))
    T.append(inf)

    for _ in range(Q):
        x = int(input())
        i = bisect_left(S, x)
        j = bisect_left(T, x)
        ans = []
        ans.append(x - S[i-1] + abs(S[i-1] - T[j-1]))
        ans.append(x - S[i-1] + abs(S[i-1] - T[j]))
        ans.append(x - T[j-1] + abs(T[j-1] - S[i-1]))
        ans.append(x - T[j-1] + abs(T[j-1] - S[i]))
        ans.append(S[i] - x + abs(S[i] - T[j-1]))
        ans.append(S[i] - x + abs(S[i] - T[j]))
        ans.append(T[j] - x + abs(T[j] - S[i-1]))
        ans.append(T[j] - x + abs(T[j] - S[i]))
        print(min(ans))


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

n = int(input())
a = list(map(int,input().split()))
ans = 1
flag = 0
for i in range(n):
    ans = ans * a[i]
    if a[i] == 0:
        ans = 0
        break


if ans > 10**18:
    print('-1')
else:
    print(ans)


### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
ans = 1
flag = 0
for i in range(n):
    ans = ans * a[i]
    if a[i] == 0:
        ans = 0
        break
    elif ans > 10**18 or a[i] > 10**18:
        if a[i:].count(0) > 0:
            ans = 0
            break
        else:
            ans = -1
            break
print(ans)
### BUGGY CODE ###

N, M, P = map(int, input().split())
E = [None] * M
for i in range(M):
    a, b, c = map(int, input().split())
    E[i] = (a - 1, b - 1, P - c)

d = [float("inf") for _ in range(N)]
d[0] = 0
for i in range(N):
    for (f, t, w) in E:
        if d[f] != float("inf") and d[t] > d[f] + w:
            d[t] = d[f] + w
            if i == N - 1 and t == N - 1:
                print(-1)
                exit()
if d[-1] > 0:
    print(0)
else:
    print(-d[-1])

### FIXED CODE ###

N, M, P = map(int, input().split())
E = [None] * M
for i in range(M):
    a, b, c = map(int, input().split())
    E[i] = (a - 1, b - 1, P - c)
INF = float("inf")
d = [INF for _ in range(N)]
d[0] = 0
for i in range(2*N):
    for f, t, w in E:
        if d[t] > d[f] + w:
            d[t] = d[f] + w
            if i >= N:
                d[t] = -INF
    if i == N-1:
        dN = d[-1]
if dN != d[-1]:
    print(-1)
elif dN > 0:
    print(0)
else:
    print(-dN)
### BUGGY CODE ###

S = input()
N = len(S)

B = [0] * N
for i in range(N):
  if S[i] == 'R':
    B[i] = i+1;
  else:
    B[i] = i-1;

ans = [1] * N

def move(a, B):
  N = len(a)
  res = [0] * N
  for i in range(N):
    res[B[i]] += a[i]
  return res

step = 10 ** 100
while step > 0:
  if step % 2 == 1:
    ans = move(ans, B)
  BB = B[:]
  for i in range(N):
    BB[i] = B[B[i]]
  B = BB
  step //= 2

print(" ".join(map(str, ans)))


### FIXED CODE ###

S = input()
N = len(S)

B = [0] * N
for i in range(N):
  if S[i] == 'R':
    B[i] = i+1;
  else:
    B[i] = i-1;

ans = [1] * N

def move(a, B):
  N = len(a)
  res = [0] * N
  for i in range(N):
    res[B[i]] += a[i]
  return res

step = 10 ** 10
while step > 0:
  if step % 2 == 1:
    ans = move(ans, B)
  BB = B[:]
  for i in range(N):
    BB[i] = B[B[i]]
  B = BB
  step //= 2

print(" ".join(map(str, ans)))
### BUGGY CODE ###

from collections import deque   
n = int(input())
xdeque = deque()
for _ in range(n):
    command = input().split()
    if (command[0][0] == 'i'):
        xdeque.appendleft(int(command[1]))
    elif (command[0] == 'delete'):
        try:
            xdeque.remove(int(command[1]))
        except ValueError:
            pass
    elif (command[0][6] == 'F'):
        xdeque.popleft()
    else:
        xdeque.pop()
print(*xdeque)




### FIXED CODE ###

from collections import deque
n = int(input())
a = deque()
for i in range(n):
    c = input()
    if c == "deleteFirst":
        a.popleft()
    elif c == "deleteLast":
        a.pop()
    else:
        c, v = c.split()
        if c == "insert":
            a.appendleft(v)
        else:
            try:
                a.remove(v)
            except:
                pass
print(" ".join(a))
### BUGGY CODE ###

#どっちで出すか注意, rstrip注意
#提出前に見返すこと！
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n,m = map(int, input().split())
    a = list(map(int, input().split()))
    for _ in range(m):
        b,c = map(int, input().split())
        a += [c]*b
    a.sort(reverse=1)
    print(sum(a[:n]))

if __name__ == '__main__':
    main()


### FIXED CODE ###

#どっちで出すか注意, rstrip注意
#提出前に見返すこと！
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n,m = map(int, input().split())
    a = list(map(int, input().split()))
    bc = [list(map(int, input().split())) for _ in range(m)]
    bc.sort(key=lambda a: a[1])
    a.sort()
    res = 0
    cnt = 0
    while cnt<n:
        if not bc:
            res += sum(a[cnt-n:])
            break
        if a[-1] >= bc[-1][1]:
            res += a.pop()
            cnt += 1
        else:
            d, e = bc.pop()
            if n-cnt >= d:
                res += d*e
                cnt += d
            else:
                res += (n-cnt)*e
                break

    print(res)


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

N = int(input())
S = list(input())
f=0
i_c = j_c = k_c =1
ijk = list()
for i in range(N):
    for j in range(N):
        for k in range(N):
            if(k_c>j_c and j_c>i_c):
                if(j_c-i_c!=k_c-j_c):
                    ijk.append([i,j,k])
            k_c+=1
        j_c+=1
        k_c = 1
    i_c+=1
    j_c = 1
for i in range(len(ijk)):
    if(S[ijk[i][0]]!= S[ijk[i][1]] and
       S[ijk[i][0]]!= S[ijk[i][2]] and
       S[ijk[i][1]]!= S[ijk[i][2]]):
       f+=1
print(f)

### FIXED CODE ###

n=int(input())
s=input()
r=g=b=0
for i in s:
  if i=="R":r+=1
  elif i=="G":g+=1
  else:b+=1

ans=r*g*b
for i in range(n):
  for j in range(i+1,n):
    k_ = j+(j-i)
    if(k_ >=n):
      break
    ans -= int(s[i]!= s[j] and s[i] != s[k_] and s[j] != s[k_])

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

# a < b + c
# b < a + C
# c < a + b

# 3 4 2 1
# a b c 

# abs(a - b) < c

def solution(N, data): # O(N^2 * logN)
    data = sorted(data)
    c = 0
    for i in range(N):
        for j in range(i+1, N-1):
            min_t = abs(data[i] - data[j])
            min_i = bisect_left(data[j+1:], min_t+1)
            max_t = data[i] + data[j]
            max_i = bisect_right(data[j+1:], max_t-1)
            # print(f'i: {i}, j: {j}, min_i: {min_i}, max_i: {max_i}')

            c += max_i - min_i

    return c

from math import ceil, floor
from bisect import bisect_left, bisect_right

if __name__ == '__main__':
    N = int(input())
    L_i = list(map(int, input().split()))
    a = solution(N, L_i)
    print(a)

    # a = bisect_right([4], 5)
    # b = bisect_left([4], 5)

    # print(a)
    # print(b)

    # a = binary_search_min_index([3, 4, 7, 8], 2)
    # print(a)





### FIXED CODE ###

# a < b + c
# b < a + C
# c < a + b

# 4 3 2 1
# a b c 

# abs(a - b) < c < a + b
# a < b < c
# b - a < b < c
# c < a + b 

from math import ceil, floor
from bisect import bisect_left, bisect_right

def solution(N, data): # O(N^2 * logN)
    data.sort()
    c = 0
    for i in range(N-2):
        for j in range(i+1, N-1):
            c += bisect_left(data, data[i] + data[j], j) - j - 1

    return c

if __name__ == '__main__':
    N = int(input())
    L_i = list(map(int, input().split()))
    a = solution(N, L_i)
    print(a)
### BUGGY CODE ###

import sys


def main():
    input = sys.stdin.readline

    n = int(input())
    items = [tuple(map(int, input().split())) for _ in range(n)]

    q = int(input())
    v_to_il = [[] for _ in range(n)]
    flag = [False] * n
    for i in range(q):
        v, l = map(int, input().split())
        v -= 1
        v_to_il[v].append((i, l))
        flag[v] = True
        while v > 0:
            v = (v - 1) // 2
            if flag[v]:
                break
            flag[v] = True

    MAX = 10**5
    # dp[i+1][j] = (i番目まで見て重さの合計がj以下のの時の価値の最大値)
    dp = [[0] * (MAX + 1) for _ in range(19)]
    ans = [0] * q

    def dfs(v, depth):
        val, w = items[v]
        for j in range(MAX + 1):
            if j < w:
                dp[depth + 1][j] = dp[depth][j]
            else:
                dp[depth + 1][j] = max(dp[depth][j], dp[depth][j - w] + val)

        if len(v_to_il[v]) > 0:
            for i, l in v_to_il[v]:
                ans[i] = dp[depth + 1][l]

        if v * 2 + 1 < n and flag[v * 2 + 1]:
            dfs(v * 2 + 1, depth + 1)
        if v * 2 + 2 < n and flag[v * 2 + 2]:
            dfs(v * 2 + 2, depth + 1)

    dfs(0, 0)
    print(*ans, sep='\n')


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    import sys
    input = sys.stdin.readline

    n = int(input())

    L_MAX = 10**5
    D_TH = 10
    V_MAX = (1 << D_TH) - 1
    dp = [[0] * (L_MAX + 1)]
    # items = []
    items_v = []
    items_w = []

    for i in range(n):
        val, w = map(int, input().split())
        if i < V_MAX:
            i1 = i + 1
            i0 = (i + 1) >> 1
            dp_ = dp[i0][:]

            # for j in range(w):
            #     dp[i1][j] = dp[i0][j]
            for j in range(w, L_MAX + 1)[::-1]:
                if dp_[j] < dp_[j - w] + val:
                    dp_[j] = dp_[j - w] + val
            dp.append(dp_)
        else:
            # items.append((val, w))
            items_v.append(val)
            items_w.append(w)

    # items = tuple(items)

    q = int(input())
    for _ in range(q):
        v, l = map(int, input().split())
        v -= 1

        if v < V_MAX:
            ans = dp[v + 1][l]
        else:
            vv = []
            ww = []
            while v >= V_MAX:
                # vv.append(items[v - V_MAX][0])
                # ww.append(items[v - V_MAX][1])
                vv.append(items_v[v - V_MAX])
                ww.append(items_w[v - V_MAX])
                v = (v - 1) >> 1

            ans = dp[v + 1][l]
            # m = len(vv)
            m2 = 1 << len(vv)
            v_sub = [0] * m2
            w_sub = [0] * m2
            for bit in range(1, m2):
                bit_min = bit & (-bit)
                x = bit_min.bit_length() - 1

                s_w = w_sub[bit - bit_min] + ww[x]
                w_sub[bit] = s_w
                if s_w <= l:
                    s_val = v_sub[bit - bit_min] + vv[x]
                    v_sub[bit] = s_val
                    ans = max(ans, dp[v + 1][l - s_w] + s_val)

        print(ans)


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

def getinputdata():

    array_result = []    
    array_result.append(input().split(" "))

    flg = True

    try:
        while flg:

            data = input()

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = True

            else:

                flg = False
    finally:

        return array_result

arr_data = getinputdata()

n= int(arr_data[0][0])

arr=[int(arr_data[1][x]) for x in range(n)]

cnt=0
chkflg=True

while chkflg:

    if any(x % 4 == 0 for x in arr):

        val=max(list(filter(lambda x : x%4 ==0, arr)))        
        idx=arr.index(val)
        
        for i in range(n):
            
            if i==idx:
                arr[i]//=2                
            else:
                arr[i]*=3
        
        cnt+=1
    
    elif any(x % 2 == 0 for x in arr):
    
        val=max(list(filter(lambda x : x%2 ==0, arr)))        
        idx=arr.index(val)
        
        for i in range(n):
            
            if i==idx:
                arr[i]//=2                
            else:
                arr[i]*=3
        
        cnt+=1
    
    
    else:
        chkflg=False
        
print(cnt)      




### FIXED CODE ###

def getinputdata():

    array_result = []    
    array_result.append(input().split(" "))

    flg = True

    try:
        while flg:

            data = input()

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = True

            else:

                flg = False
    finally:

        return array_result

arr_data = getinputdata()

n= int(arr_data[0][0])

arr=[int(arr_data[1][x]) for x in range(n)]
arr01 = [x for x in arr if x % 4 ==0] 
arr02 = [x for x in arr if x % 4 !=0 and x % 2==0] 

cnt=0
if len(arr)>0:

    for i in arr01:

        while i % 2==0:

            i//=2
        
            cnt+=1
    
    cnt+=len(arr02)
   
print(cnt)
### BUGGY CODE ###

s = input()
q = int(input())
d = True
for i in range(q):
    t, *u= input().split()
    if t == "1":
        d = not d
    else:
        f, c = u[0], u[1]
        if d:
            if f == "1":
                s = c + s
            else:
                s = s + c
        else:
            if f == "1":
                s = s + c
            else:
                s = c + s

print(s if d else s[::-1])


### FIXED CODE ###

s = input()
q = int(input())
d = True
head = []
tail = []
for i in range(q):
    t, *u= input().split()
    if t == "1":
        d = not d
    else:
        f, c = u[0], u[1]
        if d:
            if f == "1":
                head.append(c)
            else:
                tail.append(c)
        else:
            if f == "1":
                tail.append(c)
            else:
                head.append(c)
s = "".join(head)[::-1] + s + "".join(tail)
print(s if d else s[::-1])
### BUGGY CODE ###

N = int(input())
s = [sorted([x for x in input()]) for i in range(N)]

check = [False] * N
cnt = 0
for i in range(N - 1):
    part = 0
    if check[i]:
        continue
    for j in range(i + 1, N):
        if check[j]:
            continue
        if s[i] == s[j]:
            part += 1
            check[j] = True
    cnt += (part + 1) * part // 2

print(cnt)


### FIXED CODE ###

def f(array):
    temp = 'abcdefghijklmnopqrstuvwxyz'
    ret = [0] * len(temp)
    cnt = 0
    for x in array:
        ret[temp.index(x)] += 1
        cnt += 1
        if cnt == 10:
            break
    return ret

N = int(input())
s = [''.join(sorted(input())) for i in range(N)]

dic = {}
for i in range(N):
    if s[i] in dic:
        dic[s[i]] += 1
    else:
        dic[s[i]] = 1

cnt = 0
for v in dic.values():
    cnt += v * (v - 1) // 2

print(cnt)
### BUGGY CODE ###

K = int(input())
def gcd(x,y,z):
    List = [x,y,z]
    List.sort()
    if int(1) in List:
        return 1
    while True:
        if List[2] % List[1] !=0:
            mod = List[2] % List[1]
            List[2] = List[1]
            List[1] = mod
        else:
            gcd1 = List[1]
            break
    List2 = [List[0],gcd1]
    List2.sort
    while True:
        if List2[1] % List2[0] !=0:
            mod2 = List2[1] % List2[0]
            List2[1] = List2[0]
            List2[0] = mod2
        else:
            gcd2 = List2[0]
            break
    return gcd2
S = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            S += gcd(i,j,k)
print(S)

### FIXED CODE ###

K = int(input())
S = 0

def gcd(a,b):
   while b != 0:
       a, b = b, a % b
       if b ==0:
           return a
A1 = [0,0]
A2 = [0,0,0]
for i in range(1, K+1):
    S = S + i

if K > 1:
    for j in range(1, K):
        A1[0] =  j
        for k in range(j+1,K+1):
            A1[1] = k
            S += 6 * gcd(A1[1],A1[0])

if K > 2:
    for i1 in range(1, K-1):
        A2[0] = i1
        for k1 in range(i1+1, K):
            A2[1] = k1
            for j1 in range(k1+1,K+1):
                A2[2] = j1
                G3 = gcd(A2[2],A2[1])
                if G3 >= A2[0]:
                    S += 6 * gcd(G3,A2[0])
                else:
                    S += 6 * gcd(A2[0],G3)
print(S)
### BUGGY CODE ###

from collections import defaultdict


def p_e():
    s = input()
    t = input()
    l = defaultdict(list)

    for i, c in enumerate(list(s)):
        l[c].append(i + 1)

    for c in list(t):
        if c not in l.keys():
            print(-1)
            exit()

    N = 0
    current = 0
    for c in list(t):
        f = False
        for i in l[c]:
            if current < i:
                f = True
                current = i
                break

        if not f:
            current = l[c][0]
            N += 1

    print(N * len(s) + current)


if __name__ == '__main__':
    p_e()


### FIXED CODE ###

from collections import defaultdict
from bisect import *


def p_e():
    s = input()
    t = input()
    l = defaultdict(list)

    for i, c in enumerate(list(s)):
        l[c].append(i + 1)

    for c in list(t):
        if c not in l.keys():
            print(-1)
            exit()

    N = 0
    current = -1
    for c in list(t):
        R = l[c]

        x = bisect(R, current)

        if len(R) == x:
            N += 1
            current = R[0]
        else:
            current = R[x]

    print(N * len(s) + current)


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

# -*- coding: utf-8 -*-
s = input()
count = 0
for i in range(len(s)):
    for j in range(i+5, len(s)+1):
        if (int(s[i:j]) % 2019 == 0):
            count += 1
print(count)


### FIXED CODE ###

# -*- coding: utf-8 -*-
s = input()
mods = [0]*2019
mods[0] += 1
# for i in range(len(s)):
#     value = int(s[i:])
#     mods[value % 2019] += 1
base = 1
value = 0
for c in map(int, reversed(s)):
    value += (c*base) % 2019
    base = (base * 10) % 2019
    # value = int(s[i:])
    mods[value % 2019] += 1
print(sum([mod*(mod-1)//2 for mod in mods]))