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

n = int(input())

u = [0] * n
v = [0] * n
w = [0] * n

color = [-1] * n
dist = [-1] * n
adj_list = [[] for _ in range(n)]

for i in range(n - 1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1

    adj_list[u].append([v, w])
    adj_list[v].append([u, w])

q = []
dist[0] = 0
color[0] = 0
q.append(0)

while len(q) > 0:
    node = q.pop(0)

    for next, d in adj_list[node]:
        if dist[next] > 0:
            continue

        if dist[next] == -1 or dist[next] > dist[node] + d:
            dist[next] = dist[node] + d
            q.append(next)

for i in range(n):
    if dist[i] % 2 == 0:
        dist[i] = 0
    else:
        dist[i] = 1
    print(dist[i])


### FIXED CODE ###

from collections import deque

n = int(input())

u = [0] * n
v = [0] * n
w = [0] * n

dist = [-1] * n
adj_list = [[] for _ in range(n)]

for i in range(n - 1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1

    adj_list[u].append([v, w])
    adj_list[v].append([u, w])

q = deque()
dist[0] = 0
q.append(0)

while len(q) > 0:
    node = q.popleft()

    for next, d in adj_list[node]:
        if dist[next] > 0:
            continue

        if dist[next] == -1 or dist[next] > dist[node] + d:
            dist[next] = dist[node] + d
            q.append(next)

for i in range(n):
    if dist[i] % 2 == 0:
        dist[i] = 0
    else:
        dist[i] = 1
    print(dist[i])
### BUGGY CODE ###

import sys
import bisect

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

    n,m = map(int,input().split())
    a = list(map(int,input().split()))
    bc = []
    for _ in range(m):
        bc.append(list(map(int,input().split())))

    a.sort()
    a = tuple(a)

    bc.sort(key=lambda x: x[1], reverse=True)

    num = 0
    ans = 0
    for i in range(m):
        b = bc[i][0]
        c = bc[i][1]
        index = bisect.bisect_left(a[num:],c)
        if index == 0:
            break
        elif index > b:
            ans += c * b
        else:
            ans += c * index
            ans += sum(a[num+index:num+b])

        num += b
        if num >= n:
            break
    if num < n:
        print(ans + sum(a[num:]))
    else:
        print(ans)

if __name__ == '__main__':
  main()


### FIXED CODE ###

import sys

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

    n,m = map(int,input().split())
    a = list(map(int,input().split()))
    bc = []
    for _ in range(m):
        bc.append(list(map(int,input().split())))

    a.sort()
    a = tuple(a)

    bc.sort(key=lambda x: x[1], reverse=True)

    num = 0
    ans = 0

    for i in range(m):
        b = bc[i][0]
        c = bc[i][1]
        for j in range(num,min(num+b,n)):
            if c > a[j]:
                ans += c
            else:
                ans += a[j]

        num += b
        if num >= n:
            break

    if num < n:
        print(ans + sum(a[num:]))
    else:
        print(ans)
if __name__ == '__main__':
    main()
### BUGGY CODE ###

K = int(input())

lunlun_number_memo = {}

def is_lunlun(str_n):
    if lunlun_number_memo.get(str_n):
        return True
    elif len(str_n) == 1:
        return True
    else:
        if abs(int(str_n[0]) - int(str_n[1])) <= 1:
            return is_lunlun(str_n[1:])
        else:
            return False


lunlun_number_count = 0
i = 0
while lunlun_number_count < K:
    i += 1
    if is_lunlun(str(i)):
        lunlun_number_memo[str(i)] = True
        lunlun_number_count += 1
        # print(i)
        # print(lunlun_number_count)
        # print("running")

print(i)


### FIXED CODE ###

import sys
import queue

def main():
    K = int(input())
    q = queue.Queue()
    for i in range(1, 10):
        q.put(i)

    i = 0
    while True:
        i += 1

        n = q.get()
        center_num = (10 * n) + (n % 10)
        
        if n % 10 != 0:
            q.put(center_num - 1)
        
        q.put(center_num)

        if n % 10 != 9:
            q.put(center_num + 1)

        if i >= K:
            # print(q.queue)
            print(n)
            sys.exit()

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

def main(): 
    s=list(input())
    q=int(input())
    query = [input().split() for i in range(q)]

    for query_list in query:
        if query_list[0] == '1':
            s = s[::-1]
        else:
            if query_list[1] == '1':
                s.insert(0, query_list[2])
            else:
                s.append(query_list[2])

    print(''.join(s))

main()

### FIXED CODE ###

s=input()
q=int(input())
query = [input().split() for i in range(q)]

Inv = False #反転しているか
front_str = [] #末尾側
back_str = [] #先頭側

for query_list in query:
    if query_list[0] == '1':
        Inv = not Inv
    else:
        if query_list[1] == '1': #先頭に追加
            if Inv:
                front_str.append(query_list[2])
            else:
                back_str.append(query_list[2])
        else:
            if Inv:
                back_str.append(query_list[2])
            else:
                front_str.append(query_list[2])

answer = "".join(back_str[::-1] + [s] + front_str)

if Inv:
    answer = answer[::-1]

print(answer)
### BUGGY CODE ###

K = int(input())  # ぜんぜんちがう
ans = -1
 
def moduloseven(K):
	for i in range(500000):
		sev = int(str(7)*(i+1))
		if sev % K == 0:
			ans = i+1
			break
		else:
			ans = K-1
	return(ans)
 
if K % 2 != 0:
	if K % 5 != 0:
		ans = moduloseven(K)
print(ans)

### FIXED CODE ###

#ABC_174_C_Respect_review.py

K = int(input())
ans = 1

if K % 2 == 0:
	print(-1)
	exit()
if K % 5 == 0:
	print(-1)
	exit()

temp = 7
for i in range(1*10**6):
	if temp % K == 0:
		print(ans)
		exit()
	res = temp % K
	temp = res*10 + 7
	ans += 1
print(-1)
### BUGGY CODE ###

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

MAX=10**18
ans = 1
fover=False
for A in As:
    ans *= A
    if ans > MAX:
        fover=True

if ans == 0 or fover==False:
    print(ans)
else:
    print(-1)

### FIXED CODE ###

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

MAX=10**18
ans = 1
fover=False
fzero=False
for A in As:
    if A==0:
        fzero=True
        break
    if not fover:
        ans *= A
        if ans > MAX:
            fover=True

if fzero:
    print(0)
elif fover:
    print(-1)
else:
    print(ans)
### BUGGY CODE ###

K=int(input())
num=9
count=9
if K<10:
    print(K)
else:
    for j in range(1000000000000000):
        num+=1
        order=len(str(num))
        count2=0
        for k in range(order-1):
            if abs(int(str(num)[k])-int(str(num)[k+1]))<2:    
                count2+=1
            else:
                break
        if count2==order-1:
            count+=1
        if count==K:
            break        
    print(num)

### FIXED CODE ###

K=int(input())
num1=[[1,2,3,4,5,6,7,8,9]]
num2=[]
sm=0
for j in range(10):
    li=[]
    for k in range(len(num1[j])):
        if num1[j][k]%10!=0:
            li.append(num1[j][k]*10+num1[j][k]%10-1)
        li.append(num1[j][k]*10+num1[j][k]%10)
        if num1[j][k]%10!=9:
            li.append(num1[j][k]*10+num1[j][k]%10+1)
    li.sort()
    num1.append(li)
for j in range(len(num1)):
    sm+=len(num1[j])
    num2+=num1[j]
print(num2[K-1])
### BUGGY CODE ###

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

answer = 1
if 0 in A:
    print(0)
else:
    for i in A:
        answer *= i
    if answer > 10**18:
        print(-1)
    else:
        print(answer)

### FIXED CODE ###

n = int(input())
d = list(map(int, input().split()))
c_nega = 0
flag = False
for i in range(n):
  if d[i] == 0:
    flag = True
    break

if flag:
  print(0)
else:
  a = 1
  for i in range(n):
    a *= d[i]
    if a > 10**18:
      flag = True
      break
  if flag:
    print(-1)
  else:
    print(a)
### BUGGY CODE ###

# coding: utf-8
N = int(input())
A = [int(input()) for _ in range(N)]
for i in range(N):
    B = A[:]
    B.pop(i)
    print(max(B))


### FIXED CODE ###

# coding: utf-8
N = int(input())
A = []#value
for i in range(N):
    A.append(int(input()))
B = A[:]
B.sort()
one = B[-1]
two = B[-2]
for i in range(N):
    if A[i] == one:
        print(two)
    else:
        print(one)
### BUGGY CODE ###

from collections import deque

N, A, B, C, D = map(int, input().split(' '))
S = input()
blocks = [i+1 for i, s in enumerate([s for s in S]) if s == '#']
flag = False
check_set = set()

que = deque([(A, B)])
while que:
    A, B = que.pop()
    check_set.add((A, B))
    if A == C and B == D:
        flag = True
        break
    for i in range(3):
        for j in range(3):
            if i == j == 0:
                continue
            if A+i <= C and B+j <= D and A+i != B+j and (A+i) not in blocks and (B+j) not in blocks:
                if (A+i, B+j) not in check_set:
                    que.append((A+i, B+j))

if flag:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

N, A, B, C, D = map(int, input().split(' '))
S = input()
blocks = [i+1 for i, s in enumerate([s for s in S]) if s == '#']

if '##' in S[A-1:C] or '##' in S[B-1:D]:
    print('No')
elif C < D:
    if S[C-1] == '.' and S[D-1] == '.':
        print('Yes')
    else:
        print('No')
else:
    if '...' in S[max(0, B - 2):D+1]:
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

N=int(input())
S=input()
R=S.count("R")
G=S.count("G")
B=S.count("B")
ans=R*G*B
for i in range(0,N-2):
    for j in range(i+1,N-1):
        try:
            if S[i]!=S[j] and S[j]!=S[2*j-i] and S[i]!=S[2*j-i]:
                ans-=1
        except:
            continue
print(ans)

### FIXED CODE ###

N=int(input())
S=input()
ans=S.count("R")*S.count("G")*S.count("B")
for i in range(0,N-2):
    for j in range(i+1,N-1):
        if 2*j-i<N:
            if S[i]!=S[j] and S[j]!=S[2*j-i] and S[i]!=S[2*j-i]:
                ans-=1
print(ans)
### BUGGY CODE ###

A,B,C,D=map(int,input().split())
mod=998244353

dp=[[0]*D for _ in range(C)]

dp[A-1][B-1]=1

for i in range(A-1,C):
    for j in range(B-1,D):
        if i==A-1 and j==B-1:
            continue
        if i>A-1:
            dp[i][j]+=dp[i-1][j]*(j+1)
        if j>B-1:
            dp[i][j]+=dp[i][j-1]*(i+1)
        if i>A-1 and j>B-1:
            dp[i][j]-=dp[i-1][j-1]*(j)*(i)
        dp[i][j]%=mod

print(dp[C-1][D-1]%mod)


### FIXED CODE ###

A,B,C,D=map(int,input().split())
mod=998244353

dp=[[0]*D for _ in range(C)]

dp[A-1][B-1]=1

for i in range(A-1,C):
    for j in range(B-1,D):
        if i==A-1 and j==B-1:
            continue
        if i>A-1:
            dp[i][j]+=dp[i-1][j]*(j+1)
        if j>B-1:
            dp[i][j]+=dp[i][j-1]*(i+1)
        if i>A-1 and j>B-1:
            dp[i][j]-=dp[i-1][j-1]*(j)*(i)
        dp[i][j]%=mod

print(dp[C-1][D-1]%mod)
### BUGGY CODE ###

import heapq
N, M = map(int, input().split())
data = []
for i in range(M):
    a, b = map(int, input().split())
    heapq.heappush(data, (b, a))
bridge = [1] * N

for i in range(M):
    b, a = heapq.heappop(data)
    if sum(bridge[a:b]) == b - a:
        bridge[b-1] = 0

print(N-sum(bridge))

### FIXED CODE ###

import heapq
N, M = map(int, input().split())
data = []
for i in range(M):
    a, b = map(int, input().split())
    heapq.heappush(data, (b, a))

cut = 0
answer = 0
for i in range(M):
    b, a = heapq.heappop(data)
    if cut <= a:
        answer += 1
        cut = b

print(answer)
### BUGGY CODE ###

N, M = map(int, input().split())
PY = [list(map(int, input().split())) for _ in range(M)]

group = [[] for _ in range(N + 1)]
for p, y in PY:
	group[p] += [y]

for g in group:
	g.sort()

for p, y in PY:
	print("{:06d}{:06d}".format(p, group[p].index(y) + 1))


### FIXED CODE ###

N, M = map(int, input().split())
PY = [list(map(int, input().split())) for _ in range(M)]

cs = {}
for p, y in PY:
	if not p in cs:
		cs[p] = [y]
	else:
		cs[p] += [y]

csm = {}
for k, v in cs.items():
	v.sort()
	csm[k] = {}
	for i, p in enumerate(v):
		csm[k][p] = i + 1

for p, y in PY:
	print("{:06d}{:06d}".format(p, csm[p][y]))
### BUGGY CODE ###

#!/usr/bin/env python3

def main():
    import sys
    def I(): return int(sys.stdin.readline())
    def LI(): return list(map(int,sys.stdin.readline().split()))

    n = I()
    V = []
    W = []
    for _ in range(n):
        v, w = LI()
        V.append(v)
        W.append(w)
    
    q = I()
    vl = []
    maxL = 0
    for _ in range(q):
        v, l = LI()
        maxL = max(maxL, l)
        vl.append([v,l])
    
    m = min(n, 1 << 10)
    dp = [[0]*(maxL + 1) for _ in range(m + 1)]
    
    for i in range(1, m+1):
        v, w = V[i-1], W[i-1]
        for j in range(maxL+1):
            if j < w:
                dp[i][j] = dp[i>>1][j]
            else:
                dp[i][j] = max(dp[i>>1][j], dp[i>>1][j - w] + v)
    
    for i in range(q):
        v, L = vl[i]
        if v <= m:
            print(dp[v][L])
            continue
        cnt = 0
        tmp = v
        v_ = []
        w_ = []
        while tmp > m:
            v_.append(V[tmp-1])
            w_.append(W[tmp-1])
            tmp >>= 1
            cnt += 1
        ret = dp[tmp][L]
        v_tmp = [0] * (1 << cnt)
        w_tmp = [0] * (1 << cnt)
        for b in range(1, 1 << cnt):
            lsb = b & -b
            l = lsb.bit_length()
            w_b = w_tmp[b - lsb] + w_[l-1]
            w_tmp[b] = w_b
            if w_b <= L:
                v_b = v_tmp[b - lsb] + v_[l-1]
                v_tmp[b] = v_b
                ret = max(ret, v_b + dp[tmp][L - w_b])
        print(ret)
    return

if __name__ == "__main__":
    main()

### FIXED CODE ###

#!/usr/bin/env python3

def main():
    import sys
    def I(): return int(sys.stdin.readline())
    def LI(): return list(map(int,sys.stdin.readline().split()))

    n = I()
    V = []
    W = []

    maxL = 10**5
    m = min(n, 1 << 10)
    dp = [[0]*(maxL + 1)]
    
    for i in range(n):
        v, w = LI()
        if i <= m:
            d_ = dp[(i+1)>>1][:]
            for j in range(w, maxL+1)[::-1]:
                d_[j] = max(d_[j], d_[j - w] + v)
            dp.append(d_)
        V.append(v)
        W.append(w)
    
    q = I()
    for i in range(q):
        v, L = LI()
        if v <= m:
            print(dp[v][L])
            continue
        cnt = 0
        v_ = []
        w_ = []
        while v > m:
            v_.append(V[v-1])
            w_.append(W[v-1])
            v >>= 1
            cnt += 1
        ret = dp[v][L]
        v_tmp = [0] * (1 << cnt)
        w_tmp = [0] * (1 << cnt)
        for b in range(1, 1 << cnt):
            lsb = b & -b
            l = lsb.bit_length()
            w_t = w_tmp[b - lsb] + w_[l-1]
            w_tmp[b] = w_t
            if w_t <= L:
                v_t = v_tmp[b - lsb] + v_[l-1]
                v_tmp[b] = v_t
                ret = max(ret, v_t + dp[v][L - w_t])
        print(ret)
    return

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

import sys

input=sys.stdin.readline

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

a = [list(map(int, input().split())) for _ in range(h)]

b = [list(map(int, input().split())) for _ in range(h)]

dp = [[[False for i in range(80 * h + 80 * w + 1)] for _ in range(1 + w)] for j in range(1 + h)]
# dp[i][j][k]=マスの(i,j)において絶対値をkにすることができるかどうか
dp[0][0][0] = True
dp[1][0][0] = True
dp[0][1][0] = True

# 初期値の設定
for i in range(1, h + 1):
    for j in range(1, w + 1):
      
        a_num = a[i - 1][j - 1]
        b_num = b[i - 1][j - 1]
        dif = a_num - b_num
        if i == 1:
            for k in range(80 * i + 80 * j - 79):
                if dp[1][j - 1][abs(k - dif)] or dp[1][j - 1][abs(k + dif)]:
                    dp[1][j][abs(k)] = True

        elif j == 1:
            for k in range(80 * i + 80 * j - 79):
                if dp[i - 1][1][abs(k - dif)] or dp[i - 1][1][abs(k + dif)]:
                    dp[i][1][k] = True

        else:
            for k in range(80 * i + 80 * j - 79):
                if dp[i - 1][j][abs(k - dif)] or dp[i - 1][j][abs(k + dif)] or dp[i][j - 1][abs(k - dif)] or dp[i][j - 1][abs(k + dif)]:
                    dp[i][j][k] = True

ans = 0
for i in range(80 * h + 80 * w + 1):
    if dp[h][w][i]:
        ans = i
        break

print(ans)


### FIXED CODE ###

# Atcoder Problem Solving
H,W=map(int,input().split())
c=[list(map(int,input().split())) for i in range(H)]
b=[list(map(int,input().split())) for i in range(H)]
a=[[0 for i  in range(W)] for j in range(H)]

for i in range(H):
    for j in range(W):
        a[i][j]=abs(c[i][j]-b[i][j])
        
dp=[[0 for i in range(W)] for j in range(H)]

# Bitset演算
# 答えは絶対値が絶対-80から80以内に収まる

X=3200

dp[0][0]= (1<<(X+a[0][0]))  | (1<<(X-a[0][0]))
# 初期化の条件

for i in range(H):
    for j in range(W):
        if 0<=i<H and 0<=j+1<W:
            dp[i][j+1]|=(dp[i][j]<<a[i][j+1])
            dp[i][j+1]|=(dp[i][j]>>a[i][j+1]) 
            
        if 0<=i+1<H and 0<=j<W:
            dp[i+1][j]|=(dp[i][j]<<a[i+1][j])
            dp[i+1][j]|=(dp[i][j]>>a[i+1][j])
            
A=str(bin(dp[H-1][W-1]))[::-1]
L=len(A)
ans=3200
for i in range(L):
    if A[i]=="1":
        ans=min(ans,abs(i-X))
print(ans)
### BUGGY CODE ###

import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import bisect_right
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
N,M = map(int,input().split())
count = [[0]*N for _ in range(N)]
fr = [[] for _ in range(N)]
for _ in range(M):
    a,b = map(int,input().split())
    a,b = a-1,b-1
    if count[a][b] == 1:
        continue
    count[a][b] = 1
    count[b][a] = 1
    fr[a].append(b)
    fr[b].append(a)
used = [-1]*N 
index = 0
MAX = 0
def dfs(fr,cur,parent,cnt):
    global MAX
    MAX = max(cnt,MAX)
    children = fr[cur]
    for chi in children:
        if chi == parent or used[chi] != -1:
            continue
        used[chi] = 0
        cnt += 1
        dfs(fr,chi,cur,cnt)

for i in range(N):
    cnt = 1
    if used[i] != -1:
        continue
    used[i] = 0
    dfs(fr,i,-1,cnt)
    MAX = max(MAX,cnt)
print(MAX)

            








### FIXED CODE ###

import sys
sys.setrecursionlimit(99999999)


[n,m]=list(map(int,input().split()))
friends=[]
for i in range(m):
    friends.append(list(map(int,input().split())))

tomodachi=[[]for i in range(n)]

for i in range(m):
    tomodachi[friends[i][0]-1].append(friends[i][1]-1)
    tomodachi[friends[i][1]-1].append(friends[i][0]-1)

for i in range(n):
    tomodachi[i]=list(set(tomodachi[i]))

namelist=[1 for i in range(n)]
teams=[]

def haba(x,kari,tomodachi,namelist):
    for i in range(len(tomodachi[x])):
        if namelist[tomodachi[x][i]]==1:#生き残っているなら
            kari.append(tomodachi[x][i])
            namelist[tomodachi[x][i]]=0#殺す
            haba(tomodachi[x][i],kari,tomodachi,namelist)
    return(kari)
            


for i in range(n):
    if namelist[i]==1:
        teams.append(list(set(haba(i,[i],tomodachi,namelist))))

saidai=0

for i in range(len(teams)):
    if saidai<len(teams[i]):
        saidai=len(teams[i])

ans=saidai

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

import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


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

    from operator import itemgetter
    import bisect

    xh.sort(key=itemgetter(0))
    coordinate = [xh[i][0] for i in range(n)]
    hp = [xh[i][1] for i in range(n)]

    ans = 0

    for i in range(n):
        x = coordinate[i]
        h = hp[i]

        if h > 0:
            num = (h + a - 1) // a
            ans += num
            dmg = a * num
            range_left = x
            range_right = x + 2 * d
            index_left = bisect.bisect_left(coordinate, range_left)
            index_right = bisect.bisect_right(coordinate, range_right)
            for j in range(index_left, index_right):
               hp[j] -= dmg

    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


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

    from operator import itemgetter, add
    import bisect

    xh.sort(key=itemgetter(0))
    coordinate = [xh[i][0] for i in range(n)]
    hp = [xh[i][1] for i in range(n)]

    ans = 0
    dmg_cur = 0
    dmg_cum = [0] * (n + 1)

    for i in range(n):
        x = coordinate[i]
        h = hp[i]

        dmg_cur += dmg_cum[i]
        h -= dmg_cur

        if h > 0:
            num = (h + a - 1) // a
            ans += num
            dmg = a * num
            dmg_cur += dmg
            range_left = x
            range_right = x + 2 * d
            index_right = bisect.bisect_right(coordinate, range_right)
            dmg_cum[index_right] -= dmg
    print(ans)


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

s = input().split();
a = int(s[0]);
b = int(s[1]);
c = int(s[2]);
k = int(s[3]);
max = 0;
while(k > 0):
    if(a > 0):
        max += 1;
        a -= 1;
        k -= 1;
    elif(b > 0):
        b -= 1;
        k -= 1;
    else:
        max -= 1;
        k -= 1;


print(max);

### FIXED CODE ###

s = input().split();
a = int(s[0]);
b = int(s[1]);
c = int(s[2]);
k = int(s[3]);
max = 0;
x = a;
if( (a - k) >= 0 ):
    max = k;
elif((a + b - k) >= 0):
    max = a;
else:
    k = k - (a + b);
    max = -k;
    max = max + a;

print(max);
### BUGGY CODE ###

NK = list(map(int, input().split(' ')))
N = NK[0]
K = NK[1]
A = list(map(int, input().split(' ')))

score = A[0]
for i in range(1, K):
    score = score * A[i]

for i in range(K, N):
    prev_score = score
    score = score * A[i] / A[i-K]
    if (prev_score < score):
        print('Yes')
    else:
        print('No')


### FIXED CODE ###

NK = list(map(int, input().split(' ')))
N = NK[0]
K = NK[1]
A = list(map(int, input().split(' ')))

for i in range(K, N):
    if (A[i-K] < A[i]):
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

import itertools
def resolve():
    l,r=map(int,input().split())
    k=min(r+1,l+4020)
    lst=list(itertools.combinations(range(l,k),2))
    print(min([(i[0]*i[1])%2019 for i in lst]))

resolve()

### FIXED CODE ###

import itertools

def resolve():
	l,r=map(int,input().split())
	k=min(r+1,l+2020)
	lst=[i%2019 for i in range(l,k)]
	if 0 in lst:
		ans=0
	elif 673 in lst:
		if len(lst)>3:
			ans=0
		elif 672 in lst or 675 in lst:
			ans=0
		else:
			ans=1346
	else:
		ans=min([(i[0]*i[1])%2019 for i in list(itertools.combinations(lst,2))])
	
	print(ans)
resolve()
### BUGGY CODE ###

N = int(input())
A = [int(input()) for _ in range(N)]
for i in range(N):
    tmp = A.copy()
    tmp.pop(i)
    print(max(tmp))


### FIXED CODE ###

N = int(input())
A = [int(input()) for _ in range(N)]
As = sorted(A)
for i in range(N):
    if A[i] == As[-1]:
        print(As[-2])
    else:
        print(As[-1])
### BUGGY CODE ###

N = int(input())
A = [int(i) for i in input().split()]

level_count = dict()
for a in A:
    bin_a = bin(a)
    for i in range(len(bin_a[2:])):
        if int(bin_a[-i-1]) == 1:
            try:
                level_count[i] += 1
            except:
                level_count[i] = 1

sum_ = 0
for level, count in level_count.items():
    sum_ += 2**level * count * (N - count)
print(sum_ % (10**9 + 7))


### FIXED CODE ###

N = int(input())
A = [int(i) for i in input().split()]

# level_count = dict()
# for a in A:
#     bin_a = bin(a)
#     for i in range(len(bin_a[2:])):
#         if int(bin_a[-i-1]) == 1:
#             try:
#                 level_count[i] += 1
#             except:
#                 level_count[i] = 1
# 
# sum_ = 0
# for level, count in level_count.items():
#     sum_ += 2**level * count * (N - count)
# print(sum_ % (10**9 + 7))

import numpy as np

A = np.array(A)
sum_ = 0
for i in range(len(bin(np.max(A))) - 2):
    count = np.count_nonzero(A & 1)
    sum_ += 2**i * count * (N - count)
    A >>= 1
print(sum_ % (10**9 + 7))