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

input = raw_input

N,Q = map(int,input().split(" "))
s=list(input())
ju = []
for i in range(Q):
    ju.append(input().split(" "))

mem = [0] * N
def isdead(xp):
    if mem[xp] == 1:
        return True
    elif mem[xp] == 2:
        return False
    oxp = xp
    for i in range(Q):
        com = ju[i]
        if s[xp] == com[0]:
            if com[1] == "L":
                xp -= 1
            else:
                xp += 1
        if xp < 0 or xp > N-1:
            mem[oxp] = 1
            return True
    mem[oxp] = 2
    return False

def mid(x1,x2):
    return int((x1+x2)/2)

p1 = 0
p3 = N-1
p2 = int((p1+p3) / 2)
ap = -1
#left
while p1 != p2:
    if isdead(p2):
        p2,p3 = int((p1+p2)/2),p2
    else:
        ap = p2
        break
#right
if ap == -1:
    while p2 != p3:
        if isdead(p2):
            p2,p1 = int((p2+p3)/2),p2
        else:
            ap = p2
            break
if ap == -1:
    print(0)
    exit()

#left
p1 = 0
p3 = ap
p2 = mid(p1,p3)
while p3 - p1 != 1:
    if isdead(p2):
        p1,p2 = p2,mid(p2,p3)
    else:
        p2,p3 = mid(p1,p2),p2
if isdead(p1):
    p = p3
else:
    p = p1
#right
p1 = ap
p3 = N-1
p2 = mid(p1,p3)
while p3 - p1 != 1:
    if isdead(p2):
        p2,p3 = mid(p1,p2),p2
    else:
        p1,p2 = p2,mid(p2,p3)
if isdead(p3):
    q = p1
else:
    q = p3


if p > q:
    print(0)
else:
    print(q-p+1)


### FIXED CODE ###

input = raw_input

N,Q = map(int,input().split(" "))
s=list(input())
ju = []
for i in range(Q):
    ju.append(input().split(" "))

def isdeadleft(xp):
    oxp = xp
    for i in range(Q):
        com = ju[i]
        if s[xp] == com[0]:
            if com[1] == "L":
                xp -= 1
            else:
                xp += 1
        if xp < 0:
            return True
        if xp > N-1:
            xp = N-1
    return False

def isdeadright(xp):
    oxp = xp
    for i in range(Q):
        com = ju[i]
        if s[xp] == com[0]:
            if com[1] == "L":
                xp -= 1
            else:
                xp += 1
        if xp < 0:
            xp = 0
        if xp > N-1:
            return True
    return False

def mid(x1,x2):
    return int((x1+x2)/2)

if isdeadleft(N-1) or isdeadright(0):
    print(0)
    exit()

#left
p1 = 0
p3 = N-1
p2 = mid(p1,p3)
while p3 - p1 != 1:
    if isdeadleft(p2):
        p1,p2 = p2,mid(p2,p3)
    else:
        p2,p3 = mid(p1,p2),p2
if isdeadleft(p1):
    p = p3
else:
    p = p1
#right
p1 = 0
p3 = N-1
p2 = mid(p1,p3)
while p3 - p1 != 1:
    if isdeadright(p2):
        p2,p3 = mid(p1,p2),p2
    else:
        p1,p2 = p2,mid(p2,p3)
if isdeadright(p3):
    q = p1
else:
    q = p3

if p > q:
    print(0)
else:
    print(q-p+1)
### BUGGY CODE ###

import math
import sys
n, m = map(int, input().split())
s = list(input())
t = list(input())
a = (n*m)//math.gcd(n, m)
b0 = [i*(a//n)+1 for i in range(n)]
b1 = [i*(a//m)+1 for i in range(m)]
b2 = set(b0)
b3 = set(b1)

for j, i in enumerate(b0):
    if i in b3:
        if s[b0.index(i)] != t[b1.index(i)]:
            print(-1)
            sys.exit()
            
for j, i in enumerate(b1):
    if i in b2:
        if s[b0.index(i)] != t[b1.index(i)]:
            print(-1)
            sys.exit()
print(a)


### FIXED CODE ###

import math
import sys
n, m = map(int, input().split())
s = list(input())
t = list(input())
a = (n*m)//math.gcd(n, m)
b0 = [i*(a//n)+1 for i in range(n)]
b1 = [i*(a//m)+1 for i in range(m)]
b2 = set(b0)
b3 = set(b1)

for j, i in enumerate(b0):
    if i in b3:
        if s[j] != t[b1.index(i)]:
            print(-1)
            sys.exit()
            
for j, i in enumerate(b1):
    if i in b2:
        if s[b0.index(i)] != t[j]:
            print(-1)
            sys.exit()
print(a)
### BUGGY CODE ###






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

# 10^100はでかすぎるので和の第1項(10^100の整数倍、巨大)と第2項(端数)が干渉することはない

# ありうる和が何通りか
possible = 0

# 選んだ数値の個数がselectedのとき
for selected in range(K, (N + 1) + 1):
    # 第2項の最小値は数列のうち先頭selected個をとったもの
    minFraction = sum(range(selected))

    # 第2項の最大値は数列のうち末尾selected個をとったもの
    maxFraction = sum(range(N + 1 - selected, N + 1))

    # 最小値と最大値の間の数は全てありえるので個数は
    possible += maxFraction - minFraction + 1

print(possible)



### FIXED CODE ###

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

# 10^100はでかすぎるので和の第1項(10^100の整数倍、巨大)と第2項(端数)が干渉することはない

#求める場合の数。ありうる和が全部で何通りか
possible = 0

# firstからlastまでの和を速く計算する
def sumRange(first, last):
    count = last - first + 1
    return int((first + last) * count / 2)

# 選んだ数値の個数がselectedのとき
# 第1項の係数はselectedになるので、選んだ個数が違えば和も必ず異なる
# よって、選んだ個数ごとに分けて考えてよい
for selected in range(K, (N + 1) + 1):
    # 最小値は数列のうち先頭selected個をとったもの
    minFraction = sumRange(0, selected - 1)

    # 最大値は数列のうち末尾selected個をとったもの
    maxFraction = sumRange(N - selected + 1, N)

    # 最小値と最大値の間の数は全てありえるので個数は
    possible += maxFraction - minFraction + 1

# modで小さくして答えろとの指示
print(possible % (10 **9 + 7))
### BUGGY CODE ###

import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
s = 0
n = int(input())
for i in range(1,n+1):
  for j in range(1,n+1):
    for k in range(1,n+1):
      s += gcd(i,j,k)
print(s)

### FIXED CODE ###

import math
n = int(input())
sum = 0
for i in range(1,n+1):
  for j in range(1,n+1):
    g = math.gcd(i,j)
    for k in range(1,n+1):
      sum += math.gcd(g,k)
print(sum)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

n, q = map(int, input().split())
graph = [[] for i in range(n + 1)]
for i in range(n - 1):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)
add = [0 for i in range(n + 1)]
for i in range(q):
    p, x = map(int, input().split())
    add[p] += x
flag = [False for i in range(n + 1)]
check = [1]
while check:
    test = check.pop(0)
    flag[test] = True
    num_list = graph[test]
    for i in num_list:
        if flag[i] == True:
            pass
        else:
            add[i] += add[test]
            check.append(i)
for i in range(n):
    print(add[i + 1], end = " ")
print()

### FIXED CODE ###

import sys, collections
input = sys.stdin.readline

n, q = map(int, input().split())
graph = [[] for i in range(n + 1)]
for i in range(n - 1):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)
add = [0 for i in range(n + 1)]
for i in range(q):
    p, x = map(int, input().split())
    add[p] += x
flag = [False for i in range(n + 1)]
check = collections.deque([1])
while check:
    test = check.popleft()
    flag[test] = True
    num_list = graph[test]
    for i in num_list:
        if flag[i] == True:
            pass
        else:
            add[i] += add[test]
            check.append(i)
for i in range(n):
    print(add[i + 1], end = " ")
print()
### BUGGY CODE ###

n,m=map(int,input().split())
root_kouho=set(list(range(n)))
ki=[[] for _ in range(n)]
for i in range(n-1+m):
  a,b=map(int,input().split())
  a,b=a-1,b-1
  root_kouho.discard(b)
  ki[a].append(b)
root=root_kouho.pop()
p=[-1]*n
p[root]=0
todo=[[root,-1,0]]
ans=[-1]*n
ans[root]=0
seen=[0]*n
#todo=[[root,-1]]
while todo:
  t,p,d=todo.pop()
  for li in ki[t]:
    if li!=p:
      if seen[li]==-1 or seen[li]<d+1:
        ans[li]=t+1
        seen[li]=d+1
        todo.append([li,t,d+1])
print(*ans,sep='\n')

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
n,m=map(int,input().split())
root_kouho=set(list(range(n)))
leaf=set(list(range(n)))
ki=[[] for _ in range(n)]
for i in range(n-1+m):
  a,b=map(int,input().split())
  a,b=a-1,b-1
  root_kouho.discard(b)
  leaf.discard(a)
  ki[b].append(a)
root=root_kouho.pop()
ans=[-1]*n
dp=[-1]*n # 根までの最長距離
ans[root]=0
dp[root]=0
def func(v):
  if dp[v]>=0:
    return dp[v]
  else:
    ret=-1
    for nv in ki[v]:
      tmp=func(nv)
      if ret<tmp:
        ret=tmp
        ans[v]=nv+1
    dp[v]=ret+1
    return ret+1
while leaf:
  l=leaf.pop()
  func(l)
print(*ans,sep='\n')
#print(dp)
### BUGGY CODE ###

def main():
    N = int(input())
    A = list(input().split())
    for i,a_1 in enumerate(A):
        for a_2 in A[i+1:]:
#            print(a_1,a_2)
            if a_1==a_2:
                print("NO")
                return
    print("YES")
    

if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    N = int(input())
    A = sorted(input().split())
    for i in range(N-1):
        if A[i]==A[i+1]:
            print("NO")
            return
    print("YES")
    

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

n = int(input())
list = list(map(int,input().split(" ")))
result = n
for i in range(n):
    for j in range(i):
        if list[i] > list[j]:
            result -= 1
            break
print(result)

### FIXED CODE ###

n = int(input())
list = list(map(int,input().split(" ")))
result = n
tem = list[0]
for i in range(n):
    if tem >= list[i]:
        tem = list[i]
    else:
        result -= 1

print(result)
### BUGGY CODE ###

import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)
  
k=int(input())
r=0
for i in range(k):
  for j in range(k):
    for l in range(k):
      r+=gcd(i+1,j+1,l+1)
print(r)


### FIXED CODE ###

import math
  
k=int(input())
r=0
ls=[]

for i in range(k):
  for j in range(k):
    a=math.gcd(i+1,j+1)
    for l in range(k):
      r+=math.gcd(a,l+1)
print(r)
### BUGGY CODE ###

from collections import defaultdict
from collections import deque
from collections import Counter
import math
import itertools

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n,k = readInts()
pos = set()
for _ in range(k):
	l,r = readInts()
	for i in range(l,r+1):
		pos.add(i)

pos = sorted(list(pos))

dp = [-1]*(n+1)
dp[n]=1
ans = 0
for i in range(n-1,0,-1):
	t = 0
	for j in pos:
		if n-i>=j:
			t+=dp[i+j]
		else:
			break
	dp[i]=t%998244353

print(dp[1])

### FIXED CODE ###

from collections import defaultdict
from collections import deque
from collections import Counter
import math
import itertools

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n,k = readInts()
lr = [readInts() for i in range(k)]

dp = [-1]*(n+2)
dp[n]=1
dp[n+1]=0
i=n
ruiseki = [0]*(k)
for j in range(k):
	ruiseki[j] = dp[min(i+lr[j][0],n+1)]-dp[min(i+lr[j][1],n+1)]
#print(ruiseki)
ans = 0
for i in range(n-1,0,-1):
	t = 0
	for j in range(k):
		ll = dp[min(i+lr[j][0],n+1)]
		rr = dp[min(i+lr[j][1]+1,n+1)]
		#print(ll,rr)
		ruiseki[j] += ll-rr
	t+=sum(ruiseki)
	dp[i]=t%998244353
	#print(i,ruiseki,dp)

print(dp[1])
### BUGGY CODE ###

MOD = 10**9 + 7
N, M = map(int, input().split())
S = [[N]*(N+1) for i in [0,1,2]]
T = [[0]*(N+1) for i in [0,1,2]]
for i in range(M):
    l, r, x = map(int, input().split())
    S[x-1][r] = min(S[x-1][r], l)
    T[x-1][r] = max(T[x-1][r], l)

S0, S1, S2 = S
T0, T1, T2 = T

ok = 1
for i in range(N+1):
    if not T2[i] < S1[i] or not T1[i] < S0[i]:
        ok = 0
        break

if not ok:
    print(0)
    exit(0)


X = {(0, 0): 1}
for b in range(N):
    t2 = T2[b+1]; s1 = S1[b+1]; t1 = T1[b+1]; s0 = S0[b+1]
    check = lambda r, g: t2 <= r < s1 and t1 <= g < s0

    Y = {}
    for (r, g), v in X.items():
        v %= MOD
        if check(g, b):
            # r <- b+1
            Y[g, b] = Y.get((g, b), 0) + v
        if check(r, b):
            # g <- b+1
            Y[r, b] = Y.get((r, b), 0) + v
        if check(r, g):
            # b <- b+1
            Y[r, g] = Y.get((r, g), 0) + v
    X = Y
print(sum(X.values()) % MOD)

### FIXED CODE ###

MOD = 10**9 + 7
N, M = map(int, input().split())
S = [[N]*(N+1) for i in [0,1,2]]
T = [[0]*(N+1) for i in [0,1,2]]

C = [0]*(N+1)
for i in range(M):
    l, r, x = map(int, input().split())
    S[x-1][r] = min(S[x-1][r], l)
    T[x-1][r] = max(T[x-1][r], l)
    C[r] = 1

S0, S1, S2 = S
T0, T1, T2 = T

ok = 1
for i in range(N+1):
    if not T2[i] < S1[i] or not T1[i] < S0[i]:
        ok = 0
        break

if not ok:
    print(0)
    exit(0)


X = {(0, 0): 3}
for b in range(1, N):
    t2 = T2[b+1]; s1 = S1[b+1]; t1 = T1[b+1]; s0 = S0[b+1]
    check = lambda r, g: t2 <= r < s1 and t1 <= g < s0

    Z = [0]*(N+1)
    if C[b+1]:
        if t1 <= b < s0:
            for (r, g), v in X.items():
                if t2 <= g < s1:
                    # r <- b+1
                    Z[g] += v
                if t2 <= r < s1:
                    # g <- b+1
                    Z[r] += v
        X = {(r, g): v for (r, g), v in X.items() if t2 <= r < s1 and t1 <= g < s0}
    else:
        Z = [0]*(N+1)
        for (r, g), v in X.items():
            # r <- b+1
            Z[g] += v
            # g <- b+1
            Z[r] += v;
    for z, v in enumerate(Z):
        if v:
            X[z, b] = v % MOD
print(sum(X.values()) % MOD)
### BUGGY CODE ###

h,w=map(int,input().split())
s=[input() for x in range(h)]

e=[[0 for i in range(w)] for j in range(h)]
r=[[0 for i in range(w)] for j in range(h)]
l=[[0 for i in range(w)] for j in range(h)]
d=[[0 for i in range(w)] for j in range(h)]
u=[[0 for i in range(w)] for j in range(h)]


for i in range(h):
  for j in range(w):
    if s[i][j]=='.':
      e[i][j] = 1

for i in range(h):
  l[i][0] = e[i][0]
  for j in range(1,w):
    l[i][j] = (l[i][j-1]+1) * e[i][j]
  r[i][w-1] = e[i][w-1]
  for j in range(w-1,0,-1):
    r[i][j-1] = (r[i][j]+1) * e[i][j-1]

for i in range(w):
  u[0][i]=e[0][i]
  for j in range(1,h):
    u[j][i] = (u[j-1][i]+1) * e[j][i]
  d[h-1][i]=e[h-1][i]
  for j in range(h-1,0,-1):
    d[j-1][i] = (d[j][i]+1) * e[j-1][i]

m = 0
for i in range(h):
   for j in range(w):
      m = max(m,l[i][j]+r[i][j]+u[i][j]+d[i][j]-3)

print(m)


### FIXED CODE ###

import numpy as np

h,w=map(int,input().split())
s=np.array([[(1 if x=='.' else 0) for x in list(input())] for y in range(h)])

r=np.zeros((h,w),dtype=int)
l=np.zeros((h,w),dtype=int)
d=np.zeros((h,w),dtype=int)
u=np.zeros((h,w),dtype=int)

l[:,0] = s[:,0]
r[:,w-1] = s[:,w-1]
for i in range(1,w):
  l[:,i] = (l[:,i-1]+1) * s[:,i]
  r[:,w-i-1] = (r[:,w-i]+1) * s[:,w-i-1]

u[0]=s[0]
d[h-1]=s[h-1]
for i in range(1,h):
  u[i] = (u[i-1]+1) * s[i]
  d[h-i-1] = (d[h-i]+1) * s[h-i-1]

print(((l+r+u+d).max()-3))
### BUGGY CODE ###


def f(exponent):
	#reurns how many times a prime raised to exponent can be used
	step = 1
	cumul = 0
	count = 0
	while( cumul <= exponent):
		cumul += step
		count +=1
		step +=1
	return count - (1 if cumul > exponent else 0)

def answer(n):
	if n == 1: return 0
	res = 0
	on = n
	d = 2
	while(d * d <= on and n > 1):
		if n % d == 0:
			e = 0
			while(n%d == 0): e +=1
			res+= f(e)
		d +=1
	return res if n == 1 else 1

print answer(int(raw_input()))

### FIXED CODE ###

def f(exponent):
	#reurns how many times a prime raised to exponent can be used
	step = 1
	cumul = 0
	count = 0
	while( cumul <= exponent):
		cumul += step
		count +=1
		step +=1
	return count - (1 if cumul > exponent else 0)

def answer(n):
	if n == 1: return 0
	res = 0
	on = n
	p = True
	for d in range(2, int(on ** 0.5) + 2):
		if n % d == 0:
			p = False
			e = 0
			while(n%d == 0): 
				e +=1
				n/=d
			res+= f(e)
	if n > 1: res += 1
	return res

print answer(int(raw_input()))
### BUGGY CODE ###

N,K=map(int,input().split())
a=N
while True:
  b=a
  a=abs(a-K)
  if a>b:
    break
print(b) 

### FIXED CODE ###

N,K=map(int,input().split())
a=N % K
print(min(a,abs(K-a)))
### BUGGY CODE ###

s=input()
q=int(input())
for i in range (q):
    a=list(input().split())
    if a[0]=="1":
        s=s[::-1]
    else:
        if a[1]=="1":
            s=a[2]+s
        else:
            s=s+a[2]

print(s)

### FIXED CODE ###

from collections import deque

s=input()
q=int(input())
d=deque()
d.append(s)
m=1
for i in range (q):
    a=list(input().split())
    if a[0]=="1":
        m=m*(-1)
    else:
        if m==1:
            if a[1]=="1":
                d.appendleft(a[2])
            else:
                d.append(a[2])
        else:
            if a[1]=="2":
                d.appendleft(a[2])
            else:
                d.append(a[2])
s="".join(d)


print(s[::m])
### BUGGY CODE ###

s = input()[::-1]
n = len(s)
dp = [1] + [0]*2018
now = 0

for i in range(n):
    now += 10**i * int(s[i])
    tmp = now % 2019
    dp[tmp] += 1

ans = sum([i*(i-1)/2 for i in dp])
print(int(ans))


### FIXED CODE ###

s = input()
n = len(s)
dp = [1] + [0]*2019
now = 0
i = 1

for c in reversed(s):
    now = (now+i*int(c))%2019
    dp[now] += 1
    i *= 10
    i %= 2019

ans = sum([i*(i-1)/2 for i in dp])
print(int(ans))
### BUGGY CODE ###

from collections import Counter
N, K = map(int, input().split())
A = list(map(int, input().split()))

c = Counter(A).most_common()
c.sort(key=lambda x: x[1])
ans = 0
while len(c) > K:
    ans += c.pop(0)[1]
print(ans)

### FIXED CODE ###

from collections import Counter
N, K = map(int, input().split())
A = list(map(int, input().split()))

c = Counter(A).most_common()
c.sort(key=lambda x: -x[1])
ans = 0
while len(c) > K:
    ans += c.pop()[1]
print(ans)
### BUGGY CODE ###

A, B = map(int, input().split())

acc = B
for i in range(A, B):
    acc ^= i

print("{}".format(acc))


### FIXED CODE ###

from functools import reduce

A, B = map(int, input().split())
if A == B:
    result = A
else:
    result_top = reduce(lambda acc, n: acc ^ n, range(A, (int(A/4)+1) * 4))
    result_tail = reduce(lambda acc, n: acc ^ n, range(int(B/4) * 4, B + 1))
    result = result_top ^ result_tail

print("{}".format(result))
### BUGGY CODE ###

number =str(input())
numbers = number.split(" ")
A = int(numbers[0])
B = int(numbers[1])
C = int(numbers[2])
D = int(numbers[3])
list_1 = []
list_2 = []

for i in range(A, B+1):
    if i % C != 0:
        list_1.append(i)
for j in list_1:
    if j % D != 0:
        list_2.append(j)
        
print(len(list_2))

### FIXED CODE ###

import fractions

A,B,C,D = map(int, input().split())
lcm_number = C*D // fractions.gcd(C, D)
all_number = B -A + 1

answer_C = B // C - (A-1) // C
answer_D = B // D - (A-1) // D
answer_lcm = B // lcm_number - (A-1) // lcm_number

print(all_number - answer_C - answer_D + answer_lcm)
### BUGGY CODE ###

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

ans = 0
for i in range(3001):
	for j in range(3001):
		rest = n - a*i - b*j
		if rest >= 0 and rest % c == 0:
			ans += 1

print(ans)

### FIXED CODE ###

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

ans = 0
for i in range(3001):
	for j in range(3001):
		rest = n - a*i - b*j
		if rest >= 0 and rest % c == 0:
			ans += 1

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

N, P = map(int, input().split())
S = list(map(int,list(input())))
U = []

for i in range(N+1):
    tmp = 0
    for j in range(i,N):
        tmp += S[j] * (10 ** (N-1-j))
    U.append(tmp)
    
def check(i,j,P,U):
    num = (U[i]-U[j])//10 ** (N - j)
    return num % P == 0


ans = 0
for i in range(N):
    for j in range(i+1,N+1):
        if check(i,j,P,U):
            ans += 1

print(ans)

### FIXED CODE ###

N, P = map(int, input().split())
S = list(map(int,list(input())))
U = [0 for i in range(N+1)]
POW = [1 for i in range(N)]

for i in range(N-1):
    POW[i+1] = (POW[i]*10) % P

for i in range(N):
    U[N-(i+1)] = (U[N-i] + S[N-1-i] * POW[i]) % P
    
def solve(U,S):
    if P == 2 or P == 5:
        return solve1(S)
    else:
        return solve2(U)
    
def solve1(S):
    ans = 0
    for i in range(N):
        if S[i] % P == 0:
            ans += i+1
    return ans

def solve2(U):
    ans = 0
    cnt = [0 for i in range(P)]
    for i in range(N+1):
        cnt[U[i]] += 1
    for i in range(P):
        p = cnt[i]
        ans += (p * (p-1)) // 2
    return ans

print(solve(U,S))
### BUGGY CODE ###

import heapq
n,k=map(int,input().split())
a=sorted(list(map(int,input().split())))
f=sorted(list(map(int,input().split())),reverse=True)
d=[[-a[i]*f[i],f[i]] for i in range(n)]
d.sort(key=lambda x:x[0])
heapq.heapify(d)
for _ in range(k):
  i,j=heapq.heappop(d)
  i+=j
  heapq.heappush(d,[i,j])
ans,_=heapq.heappop(d)
print(max(ans*(-1),0))


### FIXED CODE ###

n,k=map(int,input().split())
a=sorted(list(map(int,input().split())))
f=sorted(list(map(int,input().split())),reverse=True)
d=[[a[i]*f[i],f[i]] for i in range(n)]
r=max([di[0] for di in d])+1
l=0
x=(l+r)//2
while r-l>1:
  if r-l==2:
    cnt=0
    for di,fi in d:
      cnt+=max(0,(di-l+fi-1)//fi)
    if cnt<=k:
      x=l
    else:
      x=l+1
    break
  cnt=0
  for di,fi in d:
    cnt+=max(0,(di-x+fi-1)//fi)
  if cnt>k:
    l,r=x,r
  else:
    l,r=l,x+1
  x=(l+r)//2
if r-l==2:
  if cnt>k:
    x=l+1
  else:
    x=l

print(x)
### BUGGY CODE ###

import numpy as np

H, W, D = map(int, input().split())
A = []

for _ in range(H):
    A.append(list(map(int, input().split())))

A = np.array(A)
    
Q = int(input())

for _ in range(Q):
    L, R = map(int, input().split())
    MP = 0
    x = np.where(A == L)[0][0]
    y = np.where(A == L)[1][0]
    
    while L != R:
        L += D
        next_x = np.where(A == L)[0][0]
        next_y = np.where(A == L)[1][0]
        MP += np.absolute(next_x - x) + np.absolute(next_y - y)
        x = next_x
        y = next_y
    
    print(MP)

### FIXED CODE ###

H, W, D = map(int, input().split())
pos = [None]*(H*W)

for i in range(H):
    row = list(map(int, input().split()))
    for j in range(W):
        pos[row[j]-1] = (i, j)

costs = [0]*(H*W)
for i in range(1, D+1):
    current = i + D
    while current <= H*W:
        costs[current - 1] = costs[current - 1 - D] + abs(pos[current - 1][0] - pos[current - 1 - D][0]) + abs(pos[current - 1][1] - pos[current - 1 - D][1])
        current += D

Q = int(input())
for _ in range(Q):
    L, R = map(int, input().split())
    MP = costs[R-1] - costs[L-1]
    print(MP)
### BUGGY CODE ###

from operator import mul
from functools import reduce
N = int(input())
a = list(map(int, input().split()))
l = (10**18)
if 0 in a:
    print(0)
    exit()
c = reduce(mul, a)
if c > l:
    print(-1)
else:
    print(reduce(mul, a))

### FIXED CODE ###

import sys

input = sys.stdin.readline

N = int(input())
a = list(map(int, input().split()))
if 0 in a:
    print(0)
    exit()
c = 1
l = 10 ** 18
for i in a:
    c *= i
    if c > l:
        print(-1)
        exit()

print(c)
### BUGGY CODE ###

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

    n, d, a = map(int, readline().split())
    xh = sorted([list(map(int, readline().split())) for _ in range(n)])

    l = [0]*(n+1)
    ans = 0
    for i in range(n):
        if xh[i][1] <= 0:
            continue 
        c = -(-xh[i][1]//a)
        ans += c
        for j in range(i+1, n):
            if xh[j][0] <= xh[i][0] + d*2:
                xh[j][1] -= c*a
            else:
                break
    print(ans)

main()

### FIXED CODE ###

from collections import deque

n, d, a = map(int, input().split())
xh = sorted([list(map(int, input().split())) for _ in range(n)])

ans = 0
dam_sum = 0
q = deque()
for i, (x, h) in enumerate(xh):
    while q and q[0][0] < x:
        ran, dam = q.popleft()
        dam_sum -= dam
    h -= dam_sum
    if h <= 0:
        continue 
    c = -(-h//a)
    ans += c
    dam_sum += c*a
    q.append((x+d*2, c*a))
print(ans)
### BUGGY CODE ###

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

DP = [0] * N
DP[0] = 0
DP[1] = abs(H[0] - H[1])

for i in range(2, N):
    DP[i] = min(DP[i-x] + abs(H[i-x]-H[i]) for x in range(1, min(i+1, K+1)))
print(DP[N-1])


### FIXED CODE ###

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

DP = [10**8] * (N+1)
DP[0] = 0
DP[1] = abs(H[0] - H[1])

for i in range(2, N):
    DP[i] = min(DP[i-x] + abs(H[i-x]-H[i]) for x in range(1, min(i+1, K+1)))
print(DP[N-1])
### BUGGY CODE ###

from collections import Counter
n,k=map(int,input().split())
A=list(map(int,input().split()))
s=len(set(A))
C=Counter(A)
if s>k:
    for i in range(k):
        n-=C.most_common()[i][1]
    print(n)
else:
    print(0)

### FIXED CODE ###

n,k=map(int,input().split())
A=list(map(int,input().split()))
d={}
for a in A:
    if a in d:
        d[a]+=1
    else:
        d[a]=1
D=sorted(d.items(), key=lambda x:x[1], reverse=True)
if len(set(A))>k:
    for i in range(k):
        n-=D[i][1]
    print(n)
else:
    print(0)