Harryxun/stf_run huggingface dataset:
n,k= map(int,input().split())
m = n - k +1 
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7
N = 10**4
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1] 

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

for i in range(1,k+1):
    print(cmb(m,i,mod)*nmb(k,i-1,mod))


### FIXED CODE ###

n, k = map(int,input().split())
m = n - k + 1 
def nCr(l,r,mod):
    if (r<0 or r>l):
        return 0
    r = min(r,l-r)
    return g1[l] * g2[r] * g2[l-r] % mod
mod = 10**9 + 7
N = 10**5
g1 = [1,1]
g2 = [1,1]
inverse = [0,1]
for i in range(2,N+1):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
for i in range(1,k+1):
    print(nCr(m,i,mod)*nCr(k-1,i-1,mod)%mod)
import sys
sys.setrecursionlimit(10 ** 6)

from math import factorial
def comb(n, r):
  if r < 0 or r > n:
    return 0
  else:
    return factorial(n) // (factorial(n - r) * factorial(r))

# 左から i 桁目以降について、0 以外の値を残り K 個使用可能
# smaller: i 桁目までが 一致している時=False, 小さい時=True  
def solve(i, k, smaller):
  if i == n:
    if k == 0:
      return 1
    else:
      return 0
  if k == 0:
    return 1
  if smaller:
    return comb(n - i, k) * 9 ** k
  else:
    if S[i] == "0":
      return solve(i + 1, k, Flase)
    else:
      zero = solve(i + 1, k, True)
      aida = solve(i + 1, k - 1, True) * (int(S[i]) - 1)
      icchi = solve(i + 1, k - 1, False)
      return zero + aida + icchi

S = input()  
n = len(S)
k = int(input())
print(solve(0, k, False))

### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 6)

from math import factorial
def comb(n, r):
  if r < 0 or r > n:
    return 0
  else:
    return factorial(n) // (factorial(n - r) * factorial(r))

# 左から i 桁目以降について、0 以外の値を残り K 個使用可能
# smaller: i 桁目までが 一致している時=False, 小さい時=True  
def solve(i, k, smaller):
  if i == n:
    if k == 0:
      return 1
    else:
      return 0
  if k == 0:
    return 1
  if smaller:
    return comb(n - i, k) * 9 ** k
  else:
    if S[i] == "0":
      return solve(i + 1, k, False)
    else:
      zero = solve(i + 1, k, True)
      aida = solve(i + 1, k - 1, True) * (int(S[i]) - 1)
      icchi = solve(i + 1, k - 1, False)
      return zero + aida + icchi

S = input()  
n = len(S)
k = int(input())
print(solve(0, k, False))
# -*- coding: utf-8 -*-

n, k, q =map(int, input().split())
a = []

for i in range(q):
  a.append(int(input()))

m = list([k]*n)

for i in range(a):
  for j in range(n):
    m[j]-=1
    m[i-1]+=1
  
for i in range(n):
  if m[i]>0:
    print("Yes")
  else:
    print("No")

### FIXED CODE ###

# -*- coding: utf-8 -*-
 
n, k, q =map(int, input().split())
a = [int(input()) for i in range(q)]

p = [0]*(n+1)

for i in range(q):
  p[a[i]] += 1
  

for i in range(1,n+1):
  if p[i]>q-k:
    print("Yes")
  else:
    print("No")
def main():
    h, w = map(int, input().split())

    if h == 1 or w == 1:
        print(1)
    else:
        print((w * h + 1) // 2))


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    h, w = map(int, input().split())

    if h == 1 or w == 1:
        print(1)
    else:
        print(int(w * (h/2)) if h % 2 == 0 else int(w*(h//2) + (w+1)//2))


if __name__ == '__main__':
    main()
N, M = [int(x) for x in input().split()]
s, c = [], []
ans_array = [None for _ in range(N)]

for i in range(M):
    s_i, c_i = [int(x) for x in input().split()]
    s.append(s_i)
    c.append(c_i)

for i in range(M):
    if ans_array[s[i] - 1] is None:
        ans_array[s[i] - 1] = c[i]
    else:
        if ans_array[s[i] - 1] != c[i]:
            print(-1)
            exit()

if ans_array[-1] is not None:
    ans_array = [0 if num is None else num for num in ans_array]
elif len(ans_array) == 1:
    print(0)
else:
    print(-1)
    exit()

ans = int("".join([str(num) for num in ans_array]))
print(ans)

### FIXED CODE ###

import math

N, M = [int(x) for x in input().split()]
s, c = [], []

for i in range(M):
    s_i, c_i = [int(x) for x in input().split()]
    s.append(s_i)
    c.append(c_i)

for num in range(10 ** N):
    num = str(num)
    if len(num) != N:
        continue
    for i in range(M):
        if num[s[i] - 1] != str(c[i]):
            break
    else:
        print(int(num))
        exit()

print(-1)
import sys

line = sys.stdin.readline()
x, y = line.split(" ")

x = int(x)
y = int(y)

divide = 1

if x > y:
    x, y = y, x

while(1):
    flag = 0
    for i in range(2, x + 1):
        if x % i == 0 and y % i == 0:
            divide = divide * i
            x = x / i
            y = y / i
            flag = 1
            break
    if flag == 0:
        print divide
        exit()

### FIXED CODE ###

import sys

def div(x, y):
    if x % y == 0:
        print y
    else:
        div(y, x%y)


line = sys.stdin.readline()
x, y = line.split(" ")

x = int(x)
y = int(y)

if x < y:
    x, y = y, x

if x == y:
    print x

else:
    div(x, y)
house=[
[ 0 for i in range(10)],
[ 0 for i in range(10)],
[ 0 for i in range(10)],
[ "#" for i in range(20)],
[ 0 for i in range(10)],
[ 0 for i in range(10)],
[ 0 for i in range(10)],
[ "#" for i in range(20)],
[ 0 for i in range(10)],
[ 0 for i in range(10)],
[ 0 for i in range(10)],
[ "#" for i in range(20)],
[ 0 for i in range(10)],
[ 0 for i in range(10)],
[ 0 for i in range(10)]]
#n = int(input())
for i in range(1):
    b,f,r,v = map(int,input().split())
    if b==1:
        house[f-1+(b-1)*4][r-1] += v
    elif b==2:
        house[f-1+(b-1)*4][r-1] += v
    elif b==3:
        house[f-1+(b-1)*4][r-1] += v
    else:
        house[f-1+(b-1)*4][r-1] += v
    for i in range(len(house)):
        if (i+1)%4 ==0:
            print(''.join(str(i) for i in house[i]))
        else:
            print('',' '.join(str(i) for i in house[i]))


### FIXED CODE ###

house = [[ 0 for i in range(10)],
        [ 0 for i in range(10)],
        [ 0 for i in range(10)],
        [ "#" for i in range(20)],
        [ 0 for i in range(10)],
        [ 0 for i in range(10)],
        [ 0 for i in range(10)],
        [ "#" for i in range(20)],
        [ 0 for i in range(10)],
        [ 0 for i in range(10)],
        [ 0 for i in range(10)],
        [ "#" for i in range(20)],
        [ 0 for i in range(10)],
        [ 0 for i in range(10)],
        [ 0 for i in range(10)]]
n = int(input())
for i in range(n):
    b,f,r,v = map(int,input().split())
    house[f-1+(b-1)*4][r-1] += v

for i in range(len(house)):
    if (i+1)%4 ==0:
        print(''.join(str(i) for i in house[i]))
    else:
        print('',' '.join(str(i) for i in house[i]))
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

l = [a,b,c,d,e]
nl = []
ans = 0
for t in l:
  if t%10 == 0:
    ans += t
  else:
    nl.append(t)
    
nl = sorted(nl, key=lambda x: x%10, reverse=True)

def tyumon(t, ans):
  ans += t
  if ans % 10 == 0:
    return ans
  else:
    return (ans//10 + 1)*10

for i in range(len(nl)-1):
  ans = tyumon(nl[i], ans)
print(ans + nl[-1])

### FIXED CODE ###

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

l = []
ans = 0
for t in [a,b,c,d,e]:
  if t%10 == 0:
    ans += t
  else:
    l.append(t)

if len(l) < 1:
  print(ans)
elif len(l) == 1:
  print(ans + l[0])
else:
  l = sorted(l, key=lambda x: x%10, reverse=True)

  def tyumon(t, ans):
    ans += t
    if ans % 10 == 0:
      return ans
    else:
      return (ans//10 + 1)*10

  for i in range(len(l)-1):
    ans = tyumon(l[i], ans)
  print(ans + l[-1])
inport sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

N = int(readline())

U = 10**6 + 100

div = np.arange(1, U, dtype=np.int64)
div = div[N%div==0]

div = np.union1d(div, N//div)

answer = (div + (N//div)).min() - 2
print(answer)

### FIXED CODE ###

import math
n = int(input())
l = [0]

for i in range(1, int(math.sqrt(n))+1):
  if n % i == 0:
    l[0] = i

print(l[0]+(n//l[0])-2)
N, K = map(int, input().split())
A = [int(a) for a in input().split()]

Plus, Whole = [0], [0]
for i in range(N):
    Plus.append(Plus[-1] + max(A[i], 0))
    Whole.append(Whole[-1] + A[i])

Full = Plus[N-K] - Plus[0] + Whole[N] - Whole[N-K]
MaxScore = max(Full, Plus[N-K] - Plus[0])
for i in range(1, K):
    temp = Plus[N-K] - Plus[0] + Whole[N]-Whole[N-K+i] - (Plus[N-K] - Plus[N+1 -2*K])
    MaxScore = max(MaxScore, temp)

Fullb = Plus[N] - Plus[K] + Whole[K] - Whole[0]
MS2 = max(Fullb, Plus[N] - Plus[N-K])
for i in range(1, K):
    temp = Plus[N] - Plus[K] + Whole[K] - Whole[K-i] - (Plus[2*K-i] - Plus[K])
    MS2 = max(MS2, temp)

print(max(MaxScore, MS2))

### FIXED CODE ###

N, K = map(int, input().split())
A = [int(a) for a in input().split()]

Plus, Whole = [0], [0]
for i in range(N):
    Plus.append(Plus[-1] + max(A[i], 0))
    Whole.append(Whole[-1] + A[i])

Score = max(max(0, Whole[K] - Whole[0]) + Plus[N] - Plus[K], Plus[N-K] - Plus[0] + max(0, Whole[N] - Whole[N-K]))
for i in range(1, N-K):
    temp = Plus[i] + max(0, Whole[i+K] - Whole[i]) + Plus[N] - Plus[i+K]
    Score = max(Score, temp)

print(Score)
import math
s = input().split()
a = int(s[0])
b = int(s[1])
re = int(a*b/math.gcd(a, b))
print(re)

### FIXED CODE ###

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
s = input().split()
a = int(s[0])
b = int(s[1])
re = int(a*b/gcd(a, b))
print(re)
a=input()
	s=str(a)
	if(s[-1] in ('2','4','5','7','9')):
		print('hon')
	elif(s[-1] in ('0','1','6','8')):
		print('pon')
	elif(s[-1] == '3'):
		print('bon')

### FIXED CODE ###

a=input()
s = str(a)
if(s[-1] in ('2','4','5','7','9')):
	print('hon')
elif(s[-1] in ('0','1','6','8')):
	print('pon')
elif(s[-1] == '3'):
	print('bon')
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value

N = ii()
N_f = float(N)
A = li()

cnt = [0, 0, 0]
for a in A:
    cnt[a-1] += 1

#dp = dp3(-1.0, cnt[2]+1, cnt[1]+cnt[2]+1, N+1)
dp = dp3(0.0, N+1, N+1, N+1)
dp = dp3(0.0, 301, 301, 301)
dp[0][0][0] = 0

for k in range(cnt[2]+1):
#for i in range(N+1):
    for j in range(cnt[1]+cnt[2]+1):
    #for j in range(N+1):
        #for k in range(cnt[2]+1):
        #for k in range(N+1):
        for i in range(N+1):
            #print(i, j, k)
            if i+j+k == 0:
                continue
            num = i+j+k
            dp[i][j][k] = N_f
            if i > 0:
                dp[i][j][k] += dp[i-1][j][k] * i
            if j > 0:
                dp[i][j][k] += dp[i+1][j-1][k] * j
            if k > 0:
                dp[i][j][k] += dp[i][j+1][k-1] * k
            dp[i][j][k] /= num

print(dp[cnt[0]][cnt[1]][cnt[2]])

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value

N = ii()
N_f = float(N)
A = li()

cnt = [0, 0, 0]
for a in A:
    cnt[a-1] += 1

#dp = dp3(-1.0, cnt[2]+1, cnt[1]+cnt[2]+1, N+1)
dp = dp3(0.0, N+1, N+1, N+1)
#dp = dp3(0.0, 301, 301, 301)
dp[0][0][0] = 0

for k in range(cnt[2]+1):
#for i in range(N+1):
    for j in range(cnt[1]+cnt[2]+1-k):
    #for j in range(N+1):
        #for k in range(cnt[2]+1):
        #for k in range(N+1):
        for i in range(N+1-j-k):
            #print(i, j, k)
            if i+j+k == 0:
                continue
            num = i+j+k
            dp[i][j][k] = N_f
            if i > 0:
                dp[i][j][k] += dp[i-1][j][k] * i
            if j > 0:
                dp[i][j][k] += dp[i+1][j-1][k] * j
            if k > 0:
                dp[i][j][k] += dp[i][j+1][k-1] * k
            dp[i][j][k] /= num

print(dp[cnt[0]][cnt[1]][cnt[2]])
N,M=map(int,input().split())
unionfindTree = [i for i in range(N)]
size = [1 for _ in range(N)]
inconvenience = N*(N-1)//2
answers = [inconvenience] #M bridges destroyed
#answers[i] should be inconvenience after M-i bridges destroyed.

def root(x):
    p = unionfindTree[x]
    if x==p:
        return(p)
    else:
        unionfindTree[x] = root(p)
        # size[x] = size[p]
        return(unionfindTree[x])

def getsize(x):
    r = root(x)
    return(size[r])

def union(x,y):
    rx = root(x)
    ry = root(y)
    convenience = 0
    if rx != ry:
        unionfindTree[ry] = rx
        sx = size[rx]
        sy = size[ry]
        convenience = sx * sy
        size[rx] = sx+sy
    return(convenience)

revBridges = []
for _ in range(M):
    a,b = map(int,input().split())
    revBridges.append((a-1,b-1))
revBridges.reverse()

for i in range(M):
    a,b = revBridges[i]
    c = union(a,b)
    inconvenience -= c
    answers.append(inconvenience)
    # print("link",(a,b))
    # print(unionfindTree)
    # print([getsize(i) for i in range(N)])



### FIXED CODE ###

N,M = map(int,input().split())
edges = []
for _ in range(M):
    a,b = map(int,input().split())
    edges.append((a-1,b-1))
edges.reverse()
parents = list(range(N))
size = [1 for _ in range(N)]
rank = [0 for _ in range(N)]

def root(x):
    px = parents[x]
    if px == x:
        return(x)
    else:
        r = root(px)
        parents[x] = r
        return(r)

def same(x,y):
    return(root(x) == root(y))

def union(x,y):
    rx = root(x)
    ry = root(y)
    if rx == ry:
        return(0)
    if rank[ry] > rank[rx]:
        parents[rx] = ry
        size[ry] += size[rx]
    else:
        parents[ry] = rx
        size[rx] += size[ry]
        if rank[rx] == rank[ry]:
            rank[rx] += 1
    return(1)

inconvinience = N*(N-1)//2
answers=[inconvinience]

for edge in edges:
    x,y = edge
    rx = root(x)
    ry = root(y)
    sx = size[rx]
    sy = size[ry]
    res = union(rx,ry)
    if res == 1:
        inconvinience -= sx*sy
    answers.append(inconvinience)

answers.reverse()

for answer in answers[1:]:
    print(answer)
nCr = {}
def cmb(n, r):
    if r == 0 or r == n:
        return 1
    if r == 1:
        return n
    if (n,r) in nCr:
        return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

INF = 10**9+7
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()

ans = 0
for i in range(N-K+1):
    ans += A[-1-i]*cmb(N-1-i, K-1)
    ans %= INF
    ans -= A[i]*cmb(N-1-i, K-1)
    ans %= INF

print(ans)

### FIXED CODE ###

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

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

ans = 0
for i in range(N-K+1):
    ans += A[-1-i]*cmb(N-1-i, K-1, mod)
    ans %= mod
    ans -= A[i]*cmb(N-1-i, K-1, mod)
    ans %= mod

print(ans)
s = input()
n = int(input())
for i in range(n):
    t = input().split()
    cmd, a, b = t[0], int(t[1]), int(t[2])
    if cmd == "print":
        print(s[a:b+1])
    elif cmd == "reverse":
        s = s[:a] + s[a:b].reverse() + s[b:]
    else:
        s = s[:a] + t[3] + s[b:]


### FIXED CODE ###

s = input()
n = int(input())
for i in range(n):
    t = input().split()
    cmd, a, b = t[0], int(t[1]), int(t[2])
    if cmd == "print":
        print(s[a:b+1])
    elif cmd == "reverse":
        s = s[:a] + s[a:b+1][::-1] + s[b+1:]
    else:
        s = s[:a] + t[3] + s[b+1:]
import math
N=int(input())
a=input().split()
A=[int(b) for b in a]
A=sorted(A,reverse=True)
numbers=[]
for n in range(N-1):
    answer=math.gcd(A[n],A[n+1])
    numbers.append(answer)
print(min(numbers))


### FIXED CODE ###

import fractions
N=int(input())
a=input().split()
A=[int(b) for b in a]
A=sorted(A,reverse=True)
numbers=[]
numbers.append(fractions.gcd(A[0],A[1]))
for a in range(1,N):
    answer=fractions.gcd(numbers[-1],A[a])
    numbers.append(answer)
print(numbers[-1])
s = input()
t = input()
n = len(s)
m = len(t)

for i in range(n - m + 1):
    flag = True
    for j in range(m):
      if s_dash[i+j] != "?" and s_dash[i+j] != t[j]:
        flag = False
        break
    if flag:
      ans = list(s_dash)
      ans[i:i+m] = list(t)
      ans = "".join(ans).replace("?", "a")
      print(ans)
      exit()
      
print("UNRESTORABLE")
      

### FIXED CODE ###

S = input()
T = input()
if len(S) < len(T):
    print("UNRESTORABLE")
    exit()
for i in range(len(S) - len(T), -1, -1):
    for s, t in zip(S[i:i+len(T)], T):
        if s != "?" and s != t:
            break
    else:
        S = list(S)
        S[i:i+len(T)] = list(T)
        S = "".join(S).replace("?", "a")
        print(S)
        exit()
print("UNRESTORABLE")
import math
N = int(input())
print(math.factrial(N)%(10**9+7))

### FIXED CODE ###

import math
N = int(input())
print(math.factorial(N) % (10**9+7))
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

def search3(w,v,n):
    res = 0
    for n1 in range(n//w[0]+1):
        for n2 in range((n-w[0]*n1)//w[1]+1):
            n3 = (n-w[0]*n1-w[1]*n2)//w[2]
            res = max(res,n+(v[0]-w[0])*n1+(v[1]-w[1])*n2+(v[2]-w[2])*n3)
    return res

def search2(w,v,W):
    res = 0
    for n1 in range(n//w[0]+1):
        n2 = (n-w[0]*n1)//w[1]
        res = max(res,n+(v[0]-w[0])*n1+(v[1]-w[1]*n2))
    return res

AB = [[A[0]-B[0],A[0],B[0]],[A[1]-B[1],A[1],B[1]],[A[2]-B[2],A[2],B[2]]]
AB.sort()
A = [AB[i][1] for i in range(3)]
B = [AB[i][2] for i in range(3)]

if AB[0][0]>0:
    ans = search3(B,A,N)
elif AB[1][0]>0:
    n = N+(B[0]-A[0])*(N//A[0])
    ans = search2(B[1:],A[1:],n)
elif AB[2][0]>0:
    n = search2(A[:2],B[:2],N)
    n = n+(A[2]-B[2])*(n//B[2])
else:
    ans = search3(A,B,N)

print(ans)

### FIXED CODE ###

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

def search3(w,v,n):
    res = 0
    for n1 in range(n//w[0]+1):
        for n2 in range((n-w[0]*n1)//w[1]+1):
            n3 = (n-w[0]*n1-w[1]*n2)//w[2]
            res = max(res,n+(v[0]-w[0])*n1+(v[1]-w[1])*n2+(v[2]-w[2])*n3)
    return res

def search2(w,v,n):
    res = 0
    for n1 in range(n//w[0]+1):
        n2 = (n-w[0]*n1)//w[1]
        res = max(res,n+(v[0]-w[0])*n1+(v[1]-w[1])*n2)
    return res

AB = [[A[0]-B[0],A[0],B[0]],[A[1]-B[1],A[1],B[1]],[A[2]-B[2],A[2],B[2]]]
AB.sort()
A = [AB[i][1] for i in range(3)]
B = [AB[i][2] for i in range(3)]

if AB[0][0]>0:
    ans = search3(B,A,N)
elif AB[1][0]>0:
    n = N+(B[0]-A[0])*(N//A[0])
    ans = search2(B[1:],A[1:],n)
elif AB[2][0]>0:
    n = search2(A[:2],B[:2],N)
    ans = n+(A[2]-B[2])*(n//B[2])
else:
    ans = search3(A,B,N)

print(ans)
a,b,c,k= map(int,input().split(' '))
    if k<a:
        print(k)
    else:
        k-=a
        if k<b:
            print(a)
        else:
            k-=b
            print(a-k)

### FIXED CODE ###

a,b,c,k= map(int,input().split(' '))
if k<=a:
    print(k)
else:
    if k<=(a+b):
        print(a)
    else:
        print(a+(a+b-k))
while True:
    a,b = map(int, raw_input().split())
    print len(str(a+b))

### FIXED CODE ###

import sys
for v in sys.stdin:
    a,b = map(int, v.split())
    print len(str(a+b))
a = int(input())
b = int(input())

print((a-1) * (b-1))

### FIXED CODE ###

a, b = (int(i) for i in input().split())

print((a-1) * (b-1))
N, M = map(int, input().split())
A = [int(input()) for i in range(M)]

DENOMINATOR = 1000000007

pos = 0
route = 1
before = 0

for i in range(1, N+1):
    route, before = route+before, route
    if A[pos] == i:
        route = 0
        if pos < M-1:
            pos+=1

print(route%DENOMINATOR)

### FIXED CODE ###

N, M = map(int, input().split())
A = [int(input()) for i in range(M)]

DENOMINATOR = 1000000007

pos = 0
route = 1
before = 0

for i in range(1, N+1):
    route, before = route+before, route
    if pos < M:
        if A[pos] == i:
            route = 0
            pos+=1

print(route%DENOMINATOR)
from collections import defaultdict

n = int(input())
seen = [-1]*(n+1)
path = defaultdict(dict)

for _ in range(n-1):
    u, v, w = map(int, input().split())
    path[u][v] = w
    path[v][u] = w


def dfs(seen, pos, color):
    if seen[pos] != -1:
        return
    else:
        seen[pos] = color
        for nx in path[pos].keys():
            check = path[pos][nx]
            if check % 2 == 1:
                color = 1 - color
            dfs(seen, nx, color)


dfs(seen, 1, 0)
for i in range(1, n+1):
    print(seen[i])

### FIXED CODE ###

from collections import defaultdict
import sys
sys.setrecursionlimit(10**7)

n = int(input())
seen = [-1]*(n+1)
path = defaultdict(dict)

for _ in range(n-1):
    u, v, w = map(int, input().split())
    path[u][v] = w
    path[v][u] = w


def dfs(seen, pos, color):
    if seen[pos] != -1:
        return
    else:
        seen[pos] = color
        change_color = 1 - color
        for nx in path[pos].keys():
            check = path[pos][nx]
            if check % 2 == 1:
                dfs(seen, nx, change_color)
            dfs(seen, nx, color)


dfs(seen, 1, 0)
for i in range(1, n+1):
    print(seen[i])
for i in range(3): l[i] = [int(j) for j in input().split()]
print(l[0][0] + l[1][1] + l[2][2])

### FIXED CODE ###

s = ''
for i in range(3): s += input()[i]
print(s)
N = int(input())
a = [int(i) for i in input().split()]
res = []
for i in range(1,len(a)):
    res.append(abs(a[:i+1]-a[i:]))

print(min(res))


### FIXED CODE ###

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

l = [0] * (N+1)
r = [0] * (N+1)

for i in range(N):
    l[i+1] = l[i] + a[i]

for i in range(N-1,-1,-1):
    r[i] = r[i+1] + a[i]

res = []

for i in range(1,len(l)-1):
    res.append(abs(l[i]-r[i]))

print(min(res))
N=int(input())
S=input()
maxa=-10
for i in range(N-1):
  a=set(L[:i+1])
  b=set([i+1:])
  maxa=max(maxa,len(a&b))
print(maxa)

### FIXED CODE ###

N=int(input())
L=list(input())
maxa=-10
for i in range(N-1):
  a=set(L[:i+1])
  b=set(L[i+1:])
  maxa=max(maxa,len(a&b))
print(maxa)