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

# Acceptance of input
import sys

file_input = sys.stdin

V, E = map(int, file_input.readline().split())

max_d = 1001
adj = [[max_d] * V for i in range(V)]

for line in file_input:
    s, t, d = map(int, line.split())
    adj[s][t] = d

max_path = 15001
dp = [[max_path] * (1 << V) for i in range(V)]
dp[0][0] = 0

# Full search with bit mask
def tsp(v, b):
    if b == (1 << V) - 1:
        return None
    
    for t, d in filter(lambda x: x[1] != max_d, enumerate(adj[v])):
        if b & (1 << t):
            continue
        mask = b | (1 << t)
        t_d = dp[v][b] + adj[v][t]
        if dp[t][mask] > t_d:
            dp[t][mask] = t_d
            tsp(t, mask)

# Output
tsp(0, 0)

ans = dp[0][-1]
if ans == max_path:
    print(-1)
else:
    print(ans)

### FIXED CODE ###

import sys

file_input = sys.stdin

V, E = map(int, file_input.readline().split())

no_route = 15001

# (v-1) th vertex is excluded
dp = [[no_route] * (V - 1) for i in range(1 << (V - 1))]

adj = [[] for i in range(V)]

for line in file_input:
    s, t, d = map(int, line.split())
    if s == V - 1:
        # Record the distance from the (v-1) th vertex to the adjacent vertex
        dp[1 << t][t] = d
    else: 
        # Store distance from source, not target
        adj[t].append((s, d))

# DP
for b in range(1, 1 << (V - 1)):
    for i in range(V - 1):
        b_i = 1 << i
        if b & b_i:
            pre_bit = b ^ b_i
            dp_pre = dp[pre_bit]
            for s, d in adj[i]:
                pre_rec = dp_pre[s]
                if pre_rec != no_route:
                    dp[b][i] = min(dp[b][i], pre_rec + d)

ans = no_route

# A state where all vertices other than (v-1) have been visited.
dp_comp = dp[(1 << (V - 1)) - 1]

for s, d in adj[V - 1]:
    comp_rec = dp_comp[s]
    if comp_rec != no_route:
        ans = min(ans, comp_rec + d)

if ans == no_route:
    print(-1)
else:
    print(ans)
### BUGGY CODE ###

from collections import defaultdict

prefecture_d = defaultdict(list)

prefecture_num,data_num = map(int,input().split())
py_data = []
for _ in range(data_num):
    prefecture,year = map(int,input().split())
    py_data.append([prefecture,year])
    prefecture_d[prefecture].append(year)
for data in py_data:
    prefecture,year = data
    id = sorted(prefecture_d[prefecture]).index(year) + 1
    print("0"*(6-len(str(prefecture))) + str(prefecture) +"0"*(6-len(str(id))) + str(id))

### FIXED CODE ###

from collections import defaultdict

N,M = map(int,input().split())
question = []
number = {}
counts = defaultdict(int)
for i in range(M):
    city,value = map(int,input().split())
    question.append([i,city,value])
sorted_question = sorted(question,key=lambda x: x[2])
for i,city,value in sorted_question:
    counts[city] += 1
    number[i] = "{:06}{:06}".format(city,counts[city])
for i in range(M):
    print(number[i])
### BUGGY CODE ###

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

q = [(N, 0, 0)]
while len(q) > 0:
    hyp = q.pop()
    num = hyp[0] + hyp[1] + hyp[2]
    currency = 10000 * hyp[0] + 5000 * hyp[1] + 1000 * hyp[2]
    if num == N and currency == Y:
        q.append(hyp)
        break
    if currency < Y:
        continue
    
    if hyp[0] >= 1:
        #### 10000円札 → 5000円札 の場合
        q.append((hyp[0] - 1, hyp[1] + 1, hyp[2]))
        #### 10000円札 → 1000円札 の場合
        q.append((hyp[0] - 1, hyp[1], hyp[2] + 1))

    #### 5000円札 x 1 → 1000円札 の場合
    if hyp[1] >= 1:
        q.append((hyp[0], hyp[1] - 1, hyp[2] + 1))

if len(q) > 0:
    print("{} {} {}".format(q[-1][0], q[-1][1], q[-1][2]))
else:
    print("-1 -1 -1")

### FIXED CODE ###

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

result = (-1, -1, -1)
for x in range(N + 1):
    for y in range(N + 1):
        if x + y > N:
            break
        if 10000 * x + 5000 * y + 1000 * (N - x - y) == Y:
            result = (x, y, N - x - y)
print("{} {} {}".format(result[0], result[1], result[2]))
### BUGGY CODE ###

def main():
    num_1 = input()
    lis = list(input().split())
    s = 1
    num_2 = int (num_1)
    for x in range(num_2):
        s = s * int(lis[x])
    if s > 10**18:
        return -1
    return s

print(main())

### FIXED CODE ###

def main():
    num_1 = input()
    lis = list(map(int,input().split()))
    s = 1
    num_2 = int (num_1)
    num = 10 ** 18
    if 0 in lis:
        print(0)
        return
    for x in range(num_2):
        s = s * int(lis[x])
        if s > num:
            print(-1)
            return
    print(s)
    return

main()
### BUGGY CODE ###

N=int(input())
S=list(str(input()))
R=[]
G=[]
B=[]
for i in range(N):
	if S[i]=='R':
		R.append(i)
	elif S[i]=='G':
		G.append(i)
	else:
		B.append(i)
ans=0
for r in R:
	for g in G:
		ans+=len(B)
		if (2*g-r) in B:
			ans-=1
		if (2*r-g) in B:
			ans-=1
		if (g+r)/2 in B:
			ans-=1
print(ans)



### FIXED CODE ###

N=int(input())
S=list(str(input()))
R=0
G=0
B=0
for i in range(N):
	if S[i]=='R':
		R+=1
	elif S[i]=='G':
		G+=1
	else:
		B+=1
ans=G*B*R
for a in range(N-1):
	for d in range(1,(N-a-1)//2+1):
		if S[a]!=S[a+d] and S[a+d]!=S[a+d*2] and S[a]!=S[a+d*2]:
			ans-=1
print(ans)
### BUGGY CODE ###

n = int(input())
s = [input() for i in range(n)]

count = 0
list1 = []
for i in range(n):
    dic1 = {}
    for k in range(10):
        
        if s[i][k] not in dic1:
            dic1[s[i][k]] = s[i].count(s[i][k])
    list1.append(dic1)
        
for i in range(n):
    for j in range(i + 1, n):
        if list1[i] == list1[j]:    
            count += 1
print(count)

### FIXED CODE ###

n = int(input())
s = [input() for i in range(n)]

count = 0
dic1 = {}
#print(s)
for i in range(n):
    #print(s[i])
    so = sorted(s[i])
    so = ''.join(so)
    if so in dic1:
        count += dic1[so]
        dic1[so] += 1
    else:
        dic1[so] = 1
    #print(count, dic1)
print(count)
### BUGGY CODE ###

(N,M)=map(int,input().split())
s = M//N;
while M%s:
    s = s-1
print(s)

### FIXED CODE ###

import math
N, M = map(int, input().split())
sqrtM = round(math.sqrt(M))+1

if N < sqrtM:
  for i in range(N,sqrtM+1):
    if M % i == 0:
      print(M//i)
      exit()
  for i in range(N-1,0,-1):
    if M % i == 0:
      print(i)
      exit()
else:
  for i in range(M//N,0,-1):
    if M % i == 0:
      print(i)
      exit()
### BUGGY CODE ###

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

visited= [1]
for i in range(K):
    next_town  = al[visited[i] - 1]
    if next_town in visited:
        loop_sta = visited.index((next_town)) #　visited_townsにおけるループ開始のインデックス
        loop_end = len(visited) #visited_townsにおけるループの終わりのインデックス
        loop_length = loop_end - loop_sta #繰り返すループの長さ
        amari = (K - loop_sta) % loop_length
        ans = visited[loop_sta + amari]
        print(ans)
        exit()
    else:
        visited.append(next_town)
        continue
        
else:
    print(visited[-1])



### FIXED CODE ###

from collections import defaultdict


def inpl():
    return list(map(int, input().split()))


N, K = inpl()
aa = inpl()

s = 1

route = [s]
ed = set([s])

for i in range(1, K + 1):
    s = aa[s - 1]
    if s in ed:
        Li = route.index(s)
        Ri = len(route)
        idx = Li + (K - Li) % (Ri - Li)
        print(route[idx])
        break
    else:
        route.append(s)
        ed.add(s)
        continue
else:
    print(s)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
S = input()
 
dp = [[0] * 5005 for _ in range(5005)]
 
for i in range(N-1, 0, -1):
  for j in range(N-1, 0, -1):
    if S[i] != S[j]:
      dp[i][j] = 0
    else:
      dp[i][j] = dp[i+1][j+1] + 1
      
ans = 0
for i in range(N):
  for j in range(N):
    if i >= j:
      continue
    now = min(dp[i][j], j-i)
    ans = max(ans, now)
    
print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
 
N = int(input())
S = input()
 
dp = [[0] * 5005 for _ in range(5005)]
 
for i in range(N-1, -1, -1):
  for j in range(N-1, -1, -1):
    if S[i] != S[j]:
      dp[i][j] = 0
    else:
      dp[i][j] = dp[i+1][j+1] + 1
      
ans = 0
for i in range(N):
  for j in range(N):
    if i >= j:
      continue
    now = min(dp[i][j], j-i)
    ans = max(ans, now)
    
print(ans)
### BUGGY CODE ###

import itertools as it

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

ans=0
for i in it.combinations([i for i in range(n)], k):
    max_x = a[max(i)]
    min_x = a[min(i)]
    ans += (max_x - min_x)

print(ans%(10**9 +7))


### FIXED CODE ###

class Combination():  # nCr(mod p) #n<=10**6
    def __init__(self, N, MOD):  # cmbの前処理
        self.mod = MOD
        self.FACT = [1, 1]  # 階乗
        self.INV = [0, 1]  # 各iの逆元
        self.FACTINV = [1, 1]  # 階乗の逆元
        for i in range(2, N + 1):
            self.FACT.append((self.FACT[-1] * i) % self.mod)
            self.INV.append(pow(i, self.mod - 2, self.mod))
            self.FACTINV.append((self.FACTINV[-1] * self.INV[-1]) % self.mod)

    def count(self, N, R):  # nCr(mod p) #前処理必要
        if (R < 0) or (N < R):
            return 0
        R = min(R, N - R)
        return self.FACT[N] * self.FACTINV[R] * self.FACTINV[N-R] % self.mod


n, k = map(int, input().split())
a = sorted(list(map(int, input().split())))
mod = 10 ** 9 + 7

ans = 0
cmb = Combination(n, mod)
for i in range(n):
    cnt = cmb.count(i, k - 1) - cmb.count(n - i - 1, k - 1)
    ans += a[i] * cnt % mod
print(ans % mod)
### BUGGY CODE ###

N = int(input())
kmax = 0
for i in range(1,N+1):
    k = 0
    while i%2**k==0:
        i = i//2
        k += 1
    kmax = max(kmax,k)
print(kmax)

### FIXED CODE ###

import math
N = int(input())
if abs(math.log2(N)-round(math.log2(N)))<1e-8:
    n = round(math.log2(N))
else:
    n = int(math.log2(N))
print(2**n)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

N=int(input())
P=[list(map(int,input().split())) for i in range(N)]
ANS=[1<<60]*(N+1)
ANS[-1]=0

DP1=[1<<60]*N

for i in range(N):
    x,y,p=P[i]
    DP1[i]=min(abs(x),abs(y))*p

ANS[0]=sum(DP1)

def dfs(DP,now,used):
    for next_town in range(now,N):
        x,y,p=P[next_town]

        DP2=list(DP)
        for i in range(N):
            DP2[i]=min(DP2[i],abs(P[i][0]-x)*P[i][2])

        #print(DP,now,used,next_town,DP2)
            
        ANS[used+1]=min(ANS[used+1],sum(DP2))
        dfs(tuple(DP2),next_town+1,used+1)



        DP2=list(DP)
        for i in range(N):
            DP2[i]=min(DP2[i],abs(P[i][1]-y)*P[i][2])

        #print(DP,now,used,next_town,DP2)
            
        ANS[used+1]=min(ANS[used+1],sum(DP2))
        dfs(tuple(DP2),next_town+1,used+1)

dfs(tuple(DP1),0,0)

print(*ANS)

### FIXED CODE ###

import sys
input = sys.stdin.readline

N=int(input())
P=[list(map(int,input().split())) for i in range(N)]
ANS=[1<<60]*(N+1)
ANS[-1]=0

DP1=[20000]*N

S=0
for i in range(N):
    x,y,p=P[i]
    DP1[i]=min(abs(x),abs(y))
    S+=DP1[i]*p

ANS[0]=S

def dfs(DP,now,used):
    if used==N-1:
        return
    for next_town in range(now,N):
        x,y,p=P[next_town]

        DP2=list(DP)
        S=0
        for i in range(N):
            DP2[i]=min(DP2[i],abs(P[i][0]-x))
            S+=DP2[i]*P[i][2]

        #print(DP,now,used,next_town,DP2)
            
        ANS[used+1]=min(ANS[used+1],S)
        if S!=0:
            dfs(DP2,next_town+1,used+1)

        DP2=list(DP)
        S=0
        for i in range(N):
            DP2[i]=min(DP2[i],abs(P[i][1]-y))
            S+=DP2[i]*P[i][2]

        #print(DP,now,used,next_town,DP2)
            
        ANS[used+1]=min(ANS[used+1],S)
        if S!=0:
            dfs(DP2,next_town+1,used+1)

dfs(DP1,0,0)

for i in range(1,N):
    ANS[i]=min(ANS[i],ANS[i-1])

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

n = int(input())
ans = 0
for i in range(n):
  ans += i
print(ans)

### FIXED CODE ###

n = int(input())
ans = int(n*(n-1)//2)
print(ans)
### BUGGY CODE ###

H,W,D=list(map(int,input().split()))
X=[(0,0) for i in range(H*W+1)]

for i in range(1,H+1):
	A=list(map(int,input().split()))
	for idx,a in enumerate(A):
		X[a]=(i,idx+1)

Q=int(input())

for i in range(Q):
	mp=0
	L,R=list(map(int,input().split()))
	now=L
	while now!=R:
		mp+=abs(X[now+D][0]-X[now][0])+abs(X[now+D][1]-X[now][1])
		now+=D
	print(mp)
	

### FIXED CODE ###

H,W,D=list(map(int,input().split()))
X=[(0,0) for i in range(H*W+1)]

for i in range(1,H+1):
	A=list(map(int,input().split()))
	for idx,a in enumerate(A):
		X[a]=(i,idx+1)

Q=int(input())
L=[]
R=[]
S=[0]*(H*W+1)

for i in range(Q):
	l,r=list(map(int,input().split()))
	L.append(l)
	R.append(r)

for i in range(D+1,H*W+1):
	S[i]=S[i-D]+abs(X[i][0]-X[i-D][0])+abs(X[i][1]-X[i-D][1])

for i in range(Q):
	print(S[R[i]]-S[L[i]])
### BUGGY CODE ###

# フェルマーの小定理
def main():
    from builtins import pow

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

    m = 1000000007

    result = 0
    t = pow(26, K, m)
    u = pow(26, m - 2, m) * 25 % m
    l = len(S)
    for i in range(K + 1):
        # result += pow(26, K - i, m) * mcomb(len(S) - 1 + i, i) * pow(25, i, m)
        result += t
        result %= m
        t *= u
        t %= m
        t *= l + i
        t %= m
        t *= pow(i + 1, m - 2, m)
        t %= m
    print(result)


main()


### FIXED CODE ###

# フェルマーの小定理
K = int(input())
S = input()

m = 1000000007


def make_factorial_table(n):
    result = [0] * (n + 1)
    result[0] = 1
    for i in range(1, n + 1):
        result[i] = result[i - 1] * i % m
    return result


def mcomb(n, k):
    if n == 0 and k == 0:
        return 1
    if n < k or k < 0:
        return 0
    return fac[n] * pow(fac[n - k], m - 2, m) * pow(fac[k], m - 2, m) % m


fac = make_factorial_table(len(S) + K)

result = 0
for i in range(K + 1):
    result += pow(26, i, m) * mcomb(len(S) - 1 + K - i, len(S) - 1) * pow(25, K - i, m)
    result %= m
print(result)
### BUGGY CODE ###

a,b,c,k = list(map(int,input().split()))	
a1 = a
b1 = b
c1 = c
for i in range(k):
    a1 = b + c
    b1 = a + c
    c1 = a + b
    a = a1
    b = b1
    c = c1
    
result = a1 - b1
if result > 10 **18:
    print("Unfair")
else:
    print(result)


### FIXED CODE ###

a,b,c,k = list(map(int,input().split()))	
x = 10 **18
result = a - b
if result > x:
    print("Unfair")
elif k % 2 == 0:
    print(result)
elif k % 2 == 1:
    result = result * -1
    print(result)
### BUGGY CODE ###

print(sum(range(1, int(input()))))


### FIXED CODE ###

N = int(input())
print((1 + (N - 1)) * (N - 1) // 2)
### BUGGY CODE ###

s = input()
n = len(s)
mod_list = [0]*2019
mod_list[0] = 1
t = 0
for i in range(n-1, -1, -1):
  t = int(s[i])*10**(n-1-i)+t
  mod_list[t%2019]+= 1
count = 0
for k in range(2019):
  count += mod_list[k] * (mod_list[k]-1)//2
print(count)

### FIXED CODE ###

s = input()

n = len(s)
mod_list = [0]*2019
mod_list[0] = 1
t = 0
keisu = 1
for i in range(n):
  t = (int(s[n-1-i])*keisu+t) %2019
  keisu = keisu*10 %2019
  mod_list[t]+= 1
count = 0
for k in range(2019):
  count += mod_list[k] * (mod_list[k]-1)//2
print(count)
### BUGGY CODE ###

def get_par(x):
  if x == par_list[x]:
    return x
  else:
    par = get_par(par_list[x])
    par_list[x] = par
    return par

N,M=map(int,input().split())
edge_list = []
for i in range(M):
  Ai,Bi=map(int,input().split())
  edge_list.append((Ai,Bi))
  
inconv_list_rev = [N*(N-1)//2]
par_list = [i for i in range(N+1)]
for Ai,Bi in reversed(edge_list):
  par_A = get_par(Ai)
  par_B = get_par(Bi)
  if par_A != par_B:
    par_list[par_B] = par_A
    
  cluster_dic = {}
  for par in par_list:
    root = get_par(par)
    if root in cluster_dic:
      cluster_dic[root] += 1
    else:
      cluster_dic[root] = 1
      
  sum_connect = 0
  for key in cluster_dic:
    val = cluster_dic[key]
    sum_connect += val*(val-1)//2
    
  inconv_list_rev.append(N*(N-1)//2-sum_connect)
  
for con in reversed(inconv_list_rev[:-1]):
  print(con)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)

def get_par(x):
  if x == par_list[x]:
    return x
  else:
    par_list[x] = get_par(par_list[x])
    return par_list[x]

N,M=map(int,input().split())
edge_list = []
for i in range(M):
  Ai,Bi=map(int,input().split())
  edge_list.append((Ai,Bi))
  
inconv = N*(N-1)//2
inconv_list_rev = [inconv]
par_list = list(range(N))
size_list = [1]*N
for Ai,Bi in reversed(edge_list):
  par_A = get_par(Ai-1)
  par_B = get_par(Bi-1)
  if par_A != par_B:
    size_A = size_list[par_A]
    size_B = size_list[par_B]
    par_list[par_B] = par_A
    size_list[par_A] += size_list[par_B]        
    inconv -= size_A*size_B
  inconv_list_rev.append(inconv)
    
for con in reversed(inconv_list_rev[:-1]):
  print(con)
### BUGGY CODE ###

n = int(input())
s = input()

sl = s[:n]
sr = s[n:][::-1]

from collections import Counter
l = Counter()
r = Counter()

from itertools import product
for m in product([False, True], repeat=n):
  key = [sl[i] for i in range(n) if not m[i]]
  key += ['-']
  key += [sl[i] for i in range(n) if m[i]]
  l[''.join(key)] += 1
  
  key = ''.join([sr[i] for i in range(n) if not m[i]])
  key += '-'
  key += ''.join([sr[i] for i in range(n) if m[i]])
  r[key] += 1
  
ans = sum(l[lk] * r[lk] for lk in l.keys())
print(ans)

### FIXED CODE ###

n = int(input())
s = input()

sl = s[:n]
sr = s[n:][::-1]

from collections import Counter
l = Counter()
r = Counter()

from itertools import product
for m in product([False, True], repeat=n):
  key = [sl[i] for i in range(n) if not m[i]]
  key += ['-']
  key += [sl[i] for i in range(n) if m[i]]
  l[''.join(key)] += 1
  
  key = [sr[i] for i in range(n) if not m[i]]
  key += ['-']
  key += [sr[i] for i in range(n) if m[i]]
  r[''.join(key)] += 1
  
ans = sum(l[lk] * r[lk] for lk in l.keys())

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


def run():
    n = int(input())
    li = []
    index = 0

    for _ in range(n):
        command = input()
        if command.startswith('0'):
            val = int(command[2:])
            li.insert(index, val)
        elif command.startswith('1'):
            i = int(command[2:])
            index += i
        elif command.startswith('2'):
            del(li[index])
        else:
            raise ValueError('invalid command')

    for n in li:
        print(n)


if __name__ == '__main__':
    run()



### FIXED CODE ###

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

    def insert(self, value):
        node = self.__class__(value)
        node.prev, node.next = self.prev, self
        if self.prev is not None:
            self.prev.next = node
        self.prev = node
        return node

    def delete(self):
        p, n = self.prev, self.next
        self.prev, self.next = None, None
        if p is None:
            n.prev = None
        else:
            n.prev, p.next = p, n
        return n

    def move(self, i):
        node = self
        if i > 0:
            for _ in range(i):
                node = node.next
        else:
            for _ in range(-i):
                node = node.prev
        return node

    def __iter__(self):
        return List.ListIterator(self)

    class ListIterator:
        def __init__(self, node):
            while node.prev is not None:
                node = node.prev
            self.node = node

        def __iter__(self):
            return self

        def __next__(self):
            val = self.node.value
            if val is None:
                raise StopIteration
            self.node = self.node.next
            return val


def run():
    n = int(input())
    li = List()

    for _ in range(n):
        command = input()
        if command.startswith('0'):
            li = li.insert(int(command[2:]))
        elif command.startswith('1'):
            li = li.move(int(command[2:]))
        elif command.startswith('2'):
            li = li.delete()
        else:
            raise ValueError('invalid command')

    for v in li:
        print(v)


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

from heapq import heappush, heappop
import sys
sys.setrecursionlimit(10 ** 7)

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

event=[]
for _ in range(n):
    s,t,x=map(int,input().split())
    event.append((s-x,1,x))
    event.append((t-x,-1,x))

for i in range(q):
    event.append((int(input()),2,i))
event.sort()

ans=[0]*q

stop=set()
hq=[]
for t,op,x in event:
    if op==1:
        heappush(hq,x)
        stop.add(x)
    elif op==-1:
        stop.remove(x)

    else:
        while hq and hq[0] not in stop:
            heappop(hq) 
        ans[x]=hq[0] if hq else -1
    
for x in ans:
    print(x)

### FIXED CODE ###

def main():
    from heapq import heappush, heappop
    import sys
    sys.setrecursionlimit(10 ** 7)

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

    event=[]
    for _ in range(n):
        s,t,x=map(int,input().split())
        event.append((s-x,1,x))
        event.append((t-x,-1,x))

    for i in range(q):
        event.append((int(input()),2,i))
    event.sort()

    ans=[0]*q

    stop=set()
    hq=[]
    for t,op,x in event:
        if op==1:
            heappush(hq,x)
            stop.add(x)
        elif op==-1:
            stop.remove(x)

        else:
            while hq and hq[0] not in stop:
                heappop(hq) 
            ans[x]=hq[0] if hq else -1
        
    for x in ans:
        print(x)

main()
### BUGGY CODE ###

l, r = list(map(int, input().split()))

ans = 2018

for i in range(l, r + 1):
  for j in range(i + 1, r + 1):
    if ((i * j) % 2019) < ans:
      ans = (i * j) % 2019

print(ans)


### FIXED CODE ###

import sys

l, r = list(map(int, input().split()))

ans = 2018

for i in range(l, r + 1):
  for j in range(i + 1, r + 1):
    if ((i * j) % 2019) < ans:
      ans = (i * j) % 2019
    if ans == 0:
      print(ans)
      sys.exit()

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


def main():
    import numpy as np
    from itertools import product

    H,W,K = map(int, input().split())
    S = np.array(([list(map(int,list(input()))) for _ in range(H)])).T

    if sum(sum(s) for s in S)<=K:
        print(0)
    else:
        answer = (H-1) * (W-1)
        for X in product([False,True], repeat=H-1):
            ans = np.sum(X)
            if ans >= answer:
                continue
            M = [[0]]
            for i, x in enumerate(X):
                if x:
                    M.append([])
                M[-1].append(i+1)
            D = np.array([0]*len(M))
            for s in S:
                D[:] += [sum(s[i] for i in m) for m in M]
                if any(d > K  for d in D):
                    ans += 1
                    if ans >= answer:
                        break
                    D[:] = [sum(s[i] for i in m) for m in M]
                    if any(d > K for d in D):
                        ans = answer + 1
                        break

            answer = min(answer,ans)

        print(answer)

main()

### FIXED CODE ###


def main():
    from itertools import product
    import numpy as np

    H,W,K = map(int, input().split())
    S = (np.array([list(map(int,list(input()))) for _ in range(H)]).T).tolist()

    if sum(sum(s) for s in S)<=K:
        print(0)
    else:
        answer = (H-1) * (W-1)
        for X in product([False,True], repeat=H-1):
            ans = np.sum(X)
            if ans >= answer:
                continue
            M = [[0]]
            for i, x in enumerate(X):
                if x:
                    M.append([])
                M[-1].append(i+1)
            D = [0]*len(M)
            for s in S:
                for k, m in enumerate(M):
                    D[k] += sum(s[i] for i in m)
                if any(d > K  for d in D):
                    ans += 1
                    if ans >= answer:
                        break
                    for k, m in enumerate(M):
                        D[k] = sum(s[i] for i in m)
                    
                    if any(d > K for d in D):
                        ans = answer + 1
                        break

            answer = min(answer,ans)

        print(answer)

main()