Harryxun/stf_run huggingface dataset:
n, m = map(int, input().split())
l = [-1]*n

r = True
for i in range(m):
    s, c = map(int, input().split())
    if l[s-1] == -1:
        l[s-1] = c
    else:
        if l[s-1] != c:
            r = False

if l[0] == -1:
    if n == 1:
        l[0] = 0
    else:
        l[0] = 1

for i in range(1, n+1):
    if l[i] == -1:
        l[i] = 0
if r == True:
    print("".join(map(str, l)))
else:
    print(-1)

### FIXED CODE ###

n, m = map(int, input().split())
l = [-1]*n

r = True
for i in range(m):
    s, c = map(int, input().split())
    if l[s-1] == -1:
        l[s-1] = c
    else:
        if l[s-1] != c:
            r = False

if l[0] == -1:
    if n == 1:
        l[0] = 0
    else:
        l[0] = 1
if l[0] == 0:
    if n != 1:
        r = False
        
for i in range(1, n):
    if l[i] == -1:
        l[i] = 0
        
if r == True:
    print("".join(map(str, l)))
else:
    print(-1)
suuzi = input(u">")
 
if suuzi <= 999:
	print u"ABC"
elif suuzi >= 1000:
	print u"ABD"

### FIXED CODE ###

suuzi = int(raw_input())
 
if suuzi <= 999:
	print("ABC")
elif suuzi >= 1000:
	print("ABD")
import itertools
from collections import Counter

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

ans = Counter()

for first, second in list(itertools.permutations(point, 2)):
    fx, fy = first
    sx, sy = second
    if sx-fx < 0 or sy-fy < 0:
        continue
    else:
        ans[(sx-fx, sy-fy)] += 1
print(N - ans.most_common()[0][1])


### FIXED CODE ###

import itertools
from collections import Counter

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

ans = Counter()
if N == 1:
    print(1)
    exit()

for first, second in list(itertools.permutations(point, 2)):
    fx, fy = first
    sx, sy = second
    ans[(sx-fx, sy-fy)] += 1

print(max(1, N - ans.most_common()[0][1]))
n, m = map(int,input().split())

g = {}
for i in range(m):
    s,t = map(int,input().split())
    val = g.get(s,[])
    val.append(t)
    g[s] = val
    val = g.get(t,[])
    val.append(s)
    g[t] = val

count = 0
def dfs(g, s, done=[]):
    global count
    count += 1
    if s in done:
        return
    done.append(s)
    for c in g[s]:
        dfs(g, c, done)
    return done

q = int(input())

n = set(g.keys())
cc = []
from sys import setrecursionlimit
setrecursionlimit(1500)
while n != set([]):
    t = n.pop()
    d = dfs(g, t, [])
    cc.append(d)
    n = n - set(d)

for j in range(q):
    s,t = map(int,input().split())
    k = True
    for c in cc:
        if s in c and t in c:
            print('yes')
            k = False
            break
    if k: print('no')

### FIXED CODE ###

n, m = map(int,input().split())

g = {}
for i in range(m):
    s,t = map(int,input().split())
    val = g.get(s,[])
    val.append(t)
    g[s] = val
    val = g.get(t,[])
    val.append(s)
    g[t] = val

color = 1
done = [-1] + [-1] * n

def dfs(g, s):
    done[s] = color
    stack = [s]
    while stack != []:
        t = stack.pop()
        
        for c in g.get(t,[]):
            if done[c] == -1:
                done[c] = color
                stack.append(c)

q = int(input())

for v in range(n):
    if done[v] == -1:
        dfs(g,v)
        color += 1

for j in range(q):
    s,t = map(int,input().split())
    if done[s] == done[t]:
        print('yes')
    else: print('no')
N,M,C=map(int,input().split()) 
B=list(map(int,input().split()))
A =[list(map(int,input().split()))for i in range(N)]
ans=0
for i in range(N):
    for j in range(M):
        X+=(A[i][j]*B[j])
    X=X+C
    if  0 < X:
        ans = ans+1
    else:
        ans = ans
print(ans)

### FIXED CODE ###

n,m,c=map(int,input().split())
B=list(map(int,input().split()))
A=[list(map(int,input().split()))for i in range(n)]
cnt=0
for i in range(n):
    total=0
    for j in range(m):
        total+=B[j]*A[i][j]
    total+=c
    if 0<total:
        cnt+=1
print(cnt)
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

N,Q=map(int,input().split())
a=list(map(int,input().split()))
lr=[]
for i in range(Q):
    l,r=map(int1,input().split())
    lr.append((l,r,i))
lr.sort(key=lambda t: t[1],reverse=1)
class RangeBIT:
    def __init__(self,n):
        self.p=self.BIT(n+1)
        self.q=self.BIT(n+1)
    
    def add(self,s,t,x):
        self.p.add(s,-x*s)
        self.p.add(t,x*t)
        self.q.add(s,x)
        self.q.add(t,-x)
    
    def sum(self,s,t):
        return self.p.sum(t)+self.q.sum(t)*t-self.p.sum(s)-self.q.sum(s)*s
    
    class BIT:
        def __init__(self,n):
            self.num=n
            self.dat=[0]*(self.num+1)
        
        def add(self,i,x):
            i+=1
            while i<=self.num:
                self.dat[i]+=x
                i+=i&-i
        
        def sum(self,i):
            i+=1
            s=0
            while i>0:
                s+=self.dat[i]
                i-=i&-i
            return s
    
b=RangeBIT(N)
lastap=[-1]*N
ans=[-1]*Q
for i in range(N):
    if lastap[a[i]]!=-1:
        b.add(lastap[a[i]],lastap[a[i]]+1,-1)
    b.add(i,i+1,1)
    lastap[a[i]]=i
    while lr and lr[-1][1]==i:
        l,r,j=lr.pop()
        ans[j]=b.sum(l,r+1)
for x in ans:
    print(x)

### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

N,Q=map(int,input().split())
a=tuple(map(int1,input().split()))
lr=[[0,0,i] for i in range(Q)]
for i in range(Q):
    lr[i][0],lr[i][1]=map(int1,input().split())
lr.sort(key=lambda t: t[1],reverse=1)
class RangeBIT:
    def __init__(self,n):
        self.p=self.BIT(n+1)
        self.q=self.BIT(n+1)
    
    def add(self,s,t,x):
        self.p.add(s,-x*s)
        self.p.add(t,x*t)
        self.q.add(s,x)
        self.q.add(t,-x)
    
    def sum(self,s,t):
        return self.p.sum(t)+self.q.sum(t)*t-self.p.sum(s)-self.q.sum(s)*s
    
    class BIT:
        def __init__(self,n):
            self.num=n
            self.dat=[0]*(self.num+1)
        
        def add(self,i,x):
            i+=1
            while i<=self.num:
                self.dat[i]+=x
                i+=i&-i
        
        def sum(self,i):
            i+=1
            s=0
            while i>0:
                s+=self.dat[i]
                i-=i&-i
            return s

b=RangeBIT(N)
lastap=[-1]*N
ans=[-1]*Q
l,r,j=lr.pop()
for i,x in enumerate(a):
    if lastap[x]!=-1:
        b.add(lastap[x],lastap[x]+1,-1)
    b.add(i,i+1,1)
    lastap[x]=i
    while r==i:
        ans[j]=b.sum(l,r+1)
        if lr:
            l,r,j=lr.pop()
        else:
            l,r,j=-1,-1,-1
for x in ans:
    print(x)
# coding: utf-8

w, h, N = list(map(int, input().split()))

rect = [0, w, 0, h]
for i in range(N):
    x, y, a = list(map(int, input().split()))
    rect[a - 1] = (lambda c, r, p: [r, c][p * (c - r) < 0])([x, y][a > 2], rect[a - 1], int(not a % 2) - int(a % 2))

length = lambda x: [x, 0][x < 0]
print(length(rect[1] - rect[0]) * length(rect[3] - rect[2]))

### FIXED CODE ###

# coding: utf-8

def solve_a():
    candies = list(map(int, input().split()))
    for c in candies:
        if 2 * c == sum(candies):
            return "Yes"
    return "No"

print(solve_a())
N = int(input())
A = list(map(int, input().split()))
A.sort()
B = [0] * 2 * 10 ** 5
M = A[-1]

for a in A:
	B[a] = 1

if sum(B) == 1:
	print(0)
else:
	for a in A:
		i = 2
		b = a * i
		while b <= M:
			B[b] = 0
			i += 1
			b = a * i
	print(sum(B))

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
A.sort()
M = max(A)
B = [0] * (M + 1)

for a in A:
    B[a] += 1

for a in A:
    if B[a] > 0:
        i = 2
        b = a * i
        while b <= M:
            B[b] = 0
            i += 1
            b = a * i
for i in range(M + 1):
    if B[i] > 1:
        B[i] = 0
print(sum(B))
n: int = input()
number: int = [input()]
count: int = 0
flag: bool = False

while flag != True:
    tmp: int = []
    for n in number:
        if n % 2 == 0:
            tmp.append(n / 2)

        else:
            flag = True
            break

    if flag:
        print(count)
        break

    number = tmp
    count += 1


### FIXED CODE ###

number = str(input())
count = 0

for n in number:
  if n == "1":
    count += 1

print(count)
d,c = map(int,input(),split())
print(d * c)

### FIXED CODE ###

d,c = map(int,input().split())
print(d * c)
N, Q = map(int, input().split())
s = input()
td = [input().split() for i in range(Q)]
#print("td = {}".format(td))

llim = 0
rlim = N - 1
for t, d in reversed(td):
    if("L" == d):
        if(s[llim] == t):
            llim += 1
        if(rlim < N - 1):
            if(s[rlim + 1] == t):
                rlim += 1
    else:# if("R" == d):
        if(s[rlim] == t):
            rlim -= 1
        if(llim > 0):
            if(s[llim - 1] == t):
                llim -= 1
#    print("td = {}, llim = {}, rlim = {}".format([t, d], llim, rlim))

print(str(max(0, rlim - llim + 1)))


### FIXED CODE ###

N, Q = map(int, input().split())
s = " " + input() + " "
td = []
for i in range(Q):
    td.append(input().split())
#print("td = {}".format(td))

llim = 0
rlim = N + 1
for t, d in reversed(td):
    if((s[llim + 1] == t) and ("L" == d)):
        llim += 1
    elif((s[llim] == t) and ("R" == d)):
        llim -= 1
    if((s[rlim - 1] == t) and ("R" == d)):
        rlim -= 1
    elif((s[rlim] == t) and ("L" == d)):
        rlim += 1
#    print("td = {}, llim = {}, rlim = {}".format([t, d], llim, rlim))

print(str(max(0, rlim - llim - 1)))
s = input().split(" ")
k = int(s[0])
n = int(s[1])

d = input().split(" ")
dist = []

for i in range(0,n):
    dist.append(int(d[i]))

ex = dist[0] + k - dist[n-1]
res = k - ex

for i in range(1, n):
 	diff = dist[i] - dist[i-1]
    aux = res + ex - diff
    
    if aux < res:
        res = aux
        
	ex = diff

print(str(res))

### FIXED CODE ###

s = input().split(" ")
k = int(s[0])
n = int(s[1])

d = input().split(" ")
dist = []

for i in d:
    dist.append(int(i))

res = dist[n-1] - dist[0]

for i in range(1, n):
    diff = dist[i] - dist[i-1]
    aux = k - diff
    if aux < res:
        res = aux

print(str(res))
import math
n=int(input())
infy=math.inf
arr=[int(x) for x in input().split()]
arr.append(0)
val=[infy]*(n+1)
val[0]=0
for i in range(0,n-1):
    val[i+1]=min(val[i+1],abs(arr[i+1]-arr[i])+val[i])
    val[i+2]=min(val[i+2],abs(arr[i+2]-arr[i])+val[i])

print(val[n-1])


### FIXED CODE ###

n=int(input())
infy=float('inf')
arr=[int(x) for x in input().split()]
arr.append(0)
val=[infy]*(n+1)
val[0]=0
for i in range(0,n-1):
    val[i+1]=min(val[i+1],abs(arr[i+1]-arr[i])+val[i])
    val[i+2]=min(val[i+2],abs(arr[i+2]-arr[i])+val[i])

print(val[n-1])
n = int(input())
p = list(map(int, input().split()))
for i in range(n): p[i] -= 1

ans = 0
for i in range(n):
    if p[i] == i:
        ans += 1
        p[i], p[i+1] = p[i+1], p[i]

print(ans)

### FIXED CODE ###

n = int(input())
p = list(map(int, input().split()))
p.append(0)
for i in range(n): p[i] -= 1

ans = 0
for i in range(n):
    if p[i] == i:
        ans += 1
        p[i], p[i+1] = p[i+1], p[i]

print(ans)
import numpy as np

n, m = list(map(int, input().split()))
py = np.array([list(map(int, input().split())) for _ in range(m)])

py = np.array(py)
order = np.argsort(py[:, 1])
argsorted = py[order]

count_below_same_class = []
visited = dict()
visited_keys = []
for i in range(m):
    p = argsorted[i, 0]
    if p not in visited_keys:
        count_below_same_class.append(0)
        visited[p] = 0
        visited_keys.append(p)
    else:
        count_below_same_class.append(visited[p] + 1)
        visited[p] += 1

inv_order = np.argsort(order)

for i in range(m):
    first = str(py[i, 0]).zfill(6)
    second = str(count_below_same_class[inv_order[i]] + 1).zfill(6)
    print(first + second)


### FIXED CODE ###

n, m = map(int, input().split())
pd = [list(map(int, input().split())) for _ in range(m)]

from collections import defaultdict
dict = defaultdict(list)
for i, (p, d) in enumerate(pd):
    dict[p].append((d, i))

ans = ['' for _ in range(m)]
for key in dict:
    v = dict[key]
    v.sort()

    for i, (y, idx) in enumerate(v):
        tmp = str(key).zfill(6) + str(i + 1).zfill(6)
        ans[idx] = tmp

for a in ans:
    print(a)
n = int(raw_input())
S = set(int,raw_input().split())
q = int(raw_input())
T = set(int,raw_input().split())
print len(S&T)

### FIXED CODE ###

n = int(raw_input())
S = set(raw_input().split())
q = int(raw_input())
T = set(raw_input().split())
print len(S&T)
n = input()
kakeru = input().split()
kakekake = kakeru[0]
    if n > 2:
        for i in range(2,n+1):
            kakekake = kakekake * kakeru[i+1]
if kakekake > 10**18:
    print(-1)
print(kakekake)

### FIXED CODE ###

n = int(input())
b = 1
a = list(map(int,input().split()))
if 0 in a:
    print(0)
else:
    for i in range(n):
        b *= a[i]
        if b > 10**18:
            print(-1)
            break
    if b <=10**18:
        print(b)
a,b = map(int,input().split())
print(max(a+b,a-b,a*b)

### FIXED CODE ###

a,b = map(int,input().split())
print(max(a+b,a-b,a*b))
N=int(input())
X=list(map(int,input().split()))
ans=[]
for i in range(min(X),max(X)):
    goukei = 0
    for j in range(N):
        if i%1==0:
            goukei+=(X[j]-i)**2
    ans.append(goukei)
kotae=set(ans)
print(min(kotae))

### FIXED CODE ###

N=int(input())
X=list(map(int,input().split()))
ans=[]
for i in range(max(X)+1):
    goukei = 0
    for j in range(N):
        if i%1==0:
            goukei+=(X[j]-i)**2
    ans.append(goukei)
kotae=set(ans)
print(min(kotae))
while True:
  2         x,y = map(int,raw_input().split())
  3         if x==0:
  4             break
  5         else:
  6             for i in xrange(x):
  7                 for j in xrange(y):
  8                     print "#",
  9                 print ""
 10         print ""

### FIXED CODE ###

while True:
        x,y = map(int,raw_input().split())
        if x==0:
            break
        else:
            for i in xrange(x):
                print y*"#"
            print ""
c = input() 

if (c == 'a'): 
elif (c == 'i'):
elif (c == 'u'):
elif (c == 'e'):
elif (c == 'o'): 
    is_vowel = True
else:
    is_vowel = False

if is_vowel:
    print('vowel')
else:
    print('consonant')

### FIXED CODE ###

print(['vowel','consonant'][not input() in ['a','e','i','o','u']])
S = input()
a = S // 3600
b = S % 3600
c = b // 60
d = c % 60
print a + ":" + c + ":" + d

### FIXED CODE ###

S = input()
if S >= 0 and S <= 86400:
   a = S // 3600
   b = S % 3600
   c = b // 60
   d = b % 60
   print "%d:%d:%d" % (a, c, d)
N=int(input())
A=int(input())
B=int(input())
ballb=[]
ballr=[]
ballb.append('b')
ballb2=ballb*A
ballr.append('r')
ballr2=ballr*B
ball=(ballb2+ballr2)*N
count=0
for i in range(N):
    if ball[i]=='b':
        count += 1
print(count)


### FIXED CODE ###

N,A,B=map(int,input().split())
a=N//(A+B)*A
c=N%(A+B)
b=min(A,c)
print(a+b)
from math import factorial

N = int(input())
words_dict = {}
for i in range(N):
  ss = input()
  ss_dict = {}
  for s in ss:
    ss_dict.setdefault(s, 0)
    ss_dict[s] += 1
  ss_dict = sorted(ss_dict.items())
  ss = [str(k)+str(v) for (k, v) in ss_dict]
  word = ''.join(ss)
  words_dict.setdefault(word, 0)
  words_dict[word] += 1
count = 0
for k, v in words_dict.items():
  if v > 1:
      count += int(factorial(v) / factorial(2) / factorial(v-2))
print(count)

### FIXED CODE ###

N = int(input())
words_dict = {}
count = 0
for i in range(N):
  ss = input()
  ss = "".join(sorted(ss))
  words_dict.setdefault(ss, 0)
  count += words_dict[ss]
  words_dict[ss] += 1
print(count)
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

h, w = na()
m = []
m = [ns() for _ in range(h)]
dp = [[inf] * w for _ in range(h)]
dp[0][0] = int(m[0][0] == '#')
for x in range(1, w):
    dp[0][x] = dp[0][x-1] + (int(m[0][x]=="#") if m[0][x-1]=="." else 0)
for y in range(1, h):
    dp[y][0] = dp[y-1][0] + (int(S[y][0]=="#") if S[y-1][0]=="." else 0)
    for x in range(1, W):
        dp[y][x] = min(
            dp[y][x-1] + (int(S[y][x]=="#") if S[y][x-1]=="." else 0),
            dp[y-1][x] + (int(S[y][x]=="#") if S[y-1][x]=="." else 0)
        )
print(dp[-1][-1])

### FIXED CODE ###

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

h, w = na()
m = []
m = [ns() for _ in range(h)]
dp = [[inf] * w for _ in range(h)]
dp[0][0] = int(m[0][0] == '#')
for x in range(1, w):
    dp[0][x] = dp[0][x-1] + (int(m[0][x]=="#") if m[0][x-1]=="." else 0)
for y in range(1, h):
    dp[y][0] = dp[y-1][0] + (int(m[y][0]=="#") if m[y-1][0]=="." else 0)
    for x in range(1, w):
        dp[y][x] = min(
            dp[y][x-1] + (int(m[y][x]=="#") if m[y][x-1]=="." else 0),
            dp[y-1][x] + (int(m[y][x]=="#") if m[y-1][x]=="." else 0)
        )
print(dp[-1][-1])
x,y=map(int,input().split()
l=[x,y]
l=sorted(l)
if l[1]%l[0]==0:
  print(-1)
else:
  print(x)

### FIXED CODE ###

x,y=map(int,input().split())
if x%y==0:
  print(-1)
else:
  print(x)
a = int(input())
if a%2  == 0 :
    print(a**2)
else :
    prin((a+1)/2*(a-1)/2)
  

### FIXED CODE ###

a = int(input())
if a%2  == 0 :
    print(int(a**2/4))
else :
    print(int((a+1)/2*(a-1)/2))
a = int(input(""))
b = int(input(""))

print(str(a * b) + " " + str(2 * a + 2 * b))
print("")


### FIXED CODE ###

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

print(str(a * b) + " " + str(2 * a  + 2 * b))
s=input()
x,y=map(int,input().split())
X,Y=[],[]
ct=0
dir=1
for i in range(len(s)):
  if s[i]=="F":
    ct+=1
    if i==len(s)-1:
      if dir==1:
        X.append(ct)
      else:
        Y.append(ct)
  else:
    if dir==1:
      X.append(ct)
      ct,dir=0,0
    else:
      Y.append(ct)
      ct,dir=0,1
if s[0]=="F":
  x-=X[0]
  X=X[1:]

def chk(Z,z):
  tot=sum(Z)
  nz=len(Z)
  DP=[[False]*(2*tot+1) for _ in range(nz+1)]
  DP[0][tot]=True
  for i in range(nz):
    zz=Z[i]
    for j in range(2*tot+1):
      if j+zz<2*tot+1 and DP[i][j+zz]==True:
        DP[i+1][j]=True
      elif j-zz>=0 and DP[i][j-zz]==True:
        DP[i+1][j]=True
  return DP[nz][z+tot]

if chk(X,x) and chk(Y,y):
  print("Yes")
else:
  print("No")

### FIXED CODE ###

s=input()
x,y=map(int,input().split())
ct=0
XY=[]
for i in range(len(s)):
  if s[i]=="F":
    ct+=1
  else:
    XY.append(ct)
    ct=0
XY.append(ct)
x-=XY[0]
X=XY[2::2]
Y=XY[1::2]


def chk(Z,z):
  tot,nz=sum(Z),len(Z)
  if tot==0:
    if z==0:
      return True
    else:
      return False
  elif abs(z)>tot:
    return False
  else:
    DP=[[False]*(2*tot+1) for _ in range(nz+1)]
    DP[0][tot]=True
    for i in range(nz):
      zz=Z[i]
      for j in range(2*tot+1):
        if j+zz<2*tot+1 and DP[i][j+zz]==True:
          DP[i+1][j]=True
        if j-zz>=0 and DP[i][j-zz]==True:
          DP[i+1][j]=True
    return DP[nz][z+tot]

if chk(X,x) and chk(Y,y):
  print("Yes")
else:
  print("No")
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
    long long int n,k;
    long long int a[200010],f[200010];
    cin >> n >> k;
    for (int i = 0; i < n; ++i) cin >> a[i];
    for (int i = 0; i<n; i++) cin >> f[i];
    sort(a,a+n);
    sort(f, f + n, greater<int>());
    long long int left=0;
    long long int right=1000000000000;
    while(left<=right){
    long long int m=(left+right)/2;
    long long int c=0;
    for(int i=0;i<n;i++){
        c+=a[i]-m/f[i];
    }
    if(c<=k) right=m;
      else left=m+1;
    }
    cout << right << endl;
}


### FIXED CODE ###

import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)

a = []
f = []
n = 0

def rec(l, r, k):
    if l+1 < r:
        mid = (l + r) // 2
        s = 0
        for i in range(n):
            s += max(a[i] - mid // f[i], 0)
        if s <= k:
            return rec(l, mid, k)
        else:
            return rec(mid, r, k)
    else:
        return r

def main():
    global a, f, n
    n, k = map(int, input().strip().split())
    a = list(map(int, input().strip().split()))
    f = list(map(int, input().strip().split()))
    a = sorted(a)
    f = sorted(f, reverse=True)
    print(rec(-1, 10**12, k))

if __name__ == '__main__':
    main()
= int(input())
P = list(map(int, input().split()))
cnt = 0
for i in range(N-1):
  if i+1 == P[i]:
    continue
  elif i+1 != P[i] and P[P[i]] == i+1:
    cnt = 1
  elif cnt == 0:
    print('NO')
    cnt = 2
    break
if cnt!=2:
  print('NYES')

### FIXED CODE ###

N = int(input())
P = list(map(int, input().split()))
cnt = 0
for i in range(N):
  if i+1 != P[i]:
    cnt += 1
print('NO' if cnt>2 else 'YES')
n, m = map(int, input().split())
a = [list(map(int, input().split()))[1:] for _ in range(m)]
p = list(map(int, input().split()))
c = 0
for n in range(1 << n):
    for i, s in enumerate(a):
        if p[i] ^ sum(n >> s-1 & 1 for s_ in s) & 1:
            break
        else:
            c += 1
print(c)

### FIXED CODE ###

n, m = map(int, input().split())
s_lists = [list(map(int, input().split()))[1:] for _ in range(m)]
P = list(map(int, input().split()))
count = 0
for i in range(2**n):
  l = 1
  for p, S in zip(P, s_lists):
    l *= (sum([int(bin(i)[2:].zfill(n)[s-1]) for s in S]) % 2 == p)
  count += l
print(count)
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
import numpy as np
 
N = int(readline())
A = np.zeros(N+2,np.int32)
A[1:-1] = np.array(read().split(),np.int32)

N = ir()
A = np.zeros(N+2, np.int32)
A[1:-1] = np.array(read().split(),np.int32)

left_max = np.maximum.accumulate(A[:-2])
right_max = np.maximum.accumulate(A[::-1])[::-1][2:]
answer = np.maximum(left_max, right_max)
print('\n'.join(answer.astype(str)))


### FIXED CODE ###

n = int(input())
a = [int(input()) for i in range(n)]
max_a = max(a)
second_a = sorted(a)[-2]
max_count = a.count(max_a) - 1
if max_count:
    [print(max_a) for _ in range(len(a))]
else:
    [print(max_a) if a[i] != max_a else print(second_a) for i in range(len(a))]
n,m=map(int,input().split())
N=3*n
d=[[0]*(N+1) for i in range(N+4)]
d[0][0]=1
for i in range(N):
  a,b,c,d=d[i:i+4]
  for j in range(N):
    b[j]=(b[j]+a[j])%m
    c[j+1]=(c[j+1]+a[j]*(i+1))%m
    d[j+1]=(d[j+1]+a[j]*(i+1)*(i+2))%m
print(sum(d[n3][:n+1])%m)


### FIXED CODE ###

n,m=map(int,input().split())
n3=3*n
x=lambda a,b:(a+b)%mod
d=[[0]*(n+2) for i in range(n3+4)]
d[0][0]=1
for i in range(n3):
  d0,d1,d2,d3=d[i:i+4]
  for j in range(n+1):
    d1[j]=(d1[j]+d0[j])%m
    d2[j+1]=(d2[j+1]+d0[j]*(i+1))%m
    d3[j+1]=(d3[j+1]+d0[j]*(i+1)*(i+2))%m
print(sum(d[n3][:n+1])%m)
l,r=map(int,input().split())

ans=10**9
c=0
for i in range(l,r+1):
    for j in range(l,r+1):
        if i!=j:
            ans=min((i*j)%2019)
        c+=1
        if c>2019**2:
            continue
print(ans)
    

### FIXED CODE ###

l,r=map(int,input().split())
r=min(r,l+2020)
  
ans=10**9
c=0
for i in range(l,r+1):
    for j in range(l,r+1):
        if i!=j:
            ans=min(ans,(i*j)%2019)
        c+=1
print(ans)