Harryxun/stf_run huggingface dataset:
n = int(input())
points = []
for i in range(n):
  x,y,h = map(int,input().split())
  if h == 0:
    continue
  points.append(list(x,y,h))
  

for k in range(len(points)):
　for l in range(k+1,len(points)):
　　for i in range(100):
　　　for j in range(100):
        if points[k][2] - points[l][2] == abs(points[l][0]-i) + abs(points[l][1]-j)- abs(points[k][0]-i)-abs(points[k][1]-j):
          

### FIXED CODE ###

n = int(input())
hist = [tuple(map(int,input().split())) for _ in range(n)]
hist.sort(key=lambda x: x[2], reverse=1)

cands = []
x0,y0,h0 = hist[0]

for i in range(0,101):
  for j in range(0,101):
    if h0 == 0:
      cands.append((i,j,1))
    else:
      cands.append((i,j, h0+abs(i-x0)+abs(j-y0)))
    
for X,Y,H in cands:
  for x,y,h in hist:
    if max(H-abs(X-x)-abs(Y-y),0) == h:
      continue
    else:
      break
  else:
    print(X,Y,H)
    break
N,A,B=map(int,input().split())
ans = 0
for i in range(1,N+1):
  sum = 0
  while j !=0:
    sum += j % 10
    j = j//10
  if A <= sum <= B:
    ans += i
print(ans)

### FIXED CODE ###

n,a,b=map(int,input().split())
cnt = 0
for i in range(1,n+1):
  s= i%10 + i//10%10 + i//100%10 + i//1000%10 + i//10000%10
  if a<=s<=b:
    cnt+=i
print(cnt)
ans=0
for i in range(N-1):
  ans=ans+i+2
print(ans)

### FIXED CODE ###

N=int(input())
print(N*(N-1)//2)
n = int(input())
words = [input() for _ in range(n)]
print("Yes" if all([y[0] == x[-1] for x, y in zip(words, words[1:]]) and len(set(words)) == n else "No")

### FIXED CODE ###

n = int(input())

words = [input() for _ in range(n)]

spoken = {words[0]}

for x, y in zip(words, words[1:]):
    if y[0] != x[-1]:
        print("No")
        exit()
    if y in spoken:
        print("No")
        exit()
    spoken.add(y)
else:
    print("Yes")
A, B = map(int, raw_input().split())

s = 1 + 2 + 3
print '{}'.format(s-A-B)


### FIXED CODE ###

A = int(input())
B = int(input())
s = 1 + 2 + 3
print '{}'.format(s-A-B)
n, d = map(int,input().split())
s == 0
for i in range(n):
	x, y = map(int,input().split())
	if x**2+y**2 <= d**2:
		s = s+1
	else:
			s = s
print(s)

### FIXED CODE ###

n, d = map(int, input().split())
s = 0
for i in range(n):
	x, y = map(int, input().split())
	if x**2+y**2 <= d**2:
		s += 1
print(s)
N = int(input())
strings = []
for i in range(N):
    strings.append(input())


strings = [''.join(sorted(s)) for s in strings]
strings.sort()

for s in strings:
    print(s)


hashMap = {}
for string in strings:
    if string not in hashMap:
        hashMap[str(string)] = 1
    else:
        hashMap[str(string)] += 1


sum = 0

for key in hashMap:
    v = hashMap[key]
    sum += v * (v - 1) / 2
print(int(sum))


### FIXED CODE ###



a, b = input().split()

a = int(a)
b = int(b)


sum = a + b
dif = a - b
pro = a * b


def greatest(a, b, c):
    if a > b:
        if a > c:
            return a
        else:
            return c
    else:
        if b > c:
            return b
        else:
            return c


print(greatest(sum, dif, pro))
def s(n):
    return[m(t)for t in d(f(n))]
def f(n):
    l=[]
    b,e=2,0
    while b*b<=n:
        while not n%b:
            n//=b
            e+=1
        if e:
            l.append((b,e))
        b,e=b+1,0
    if n>1:
        l.append((n,1))
    return l
def d(l):
    b,e=l.pop()
    p=d(l)if l else[[]]
    v=[[(b,k)]for k in range(e+1)]
    return[s+t for s in p for t in v]
def m(l):
    a=1
    for b,e in l:
        a*=b**e
    return a
N,M=map(int,input().split())
a=0
for i in sorted(s(M))[::-1]:
    if M//i>=N:
        a=i
        break
print(a)

### FIXED CODE ###

def s(n):
    return[m(t)for t in d(f(n))]
def f(n):
    l=[]
    b,e=2,0
    while b*b<=n:
        while not n%b:
            n//=b
            e+=1
        if e:
            l.append((b,e))
        b,e=b+1,0
    if n>1:
        l.append((n,1))
    return l
def d(l):
    b,e=l.pop()
    p=d(l)if l else[[]]
    v=[[(b,k)]for k in range(e+1)]
    return[s+t for s in p for t in v]
def m(l):
    a=1
    for b,e in l:
        a*=b**e
    return a
N,M=map(int,input().split())
if M<2:print(1);exit()
a=0
for i in sorted(s(M))[::-1]:
    if M//i>=N:
        a=i
        break
print(a)
n=int(input())
s=input()
lst=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','X','Y','Z']
S=list(s)
for i in range(len(list(s))):
  idx=lst.index(S[i])
  S[i]=lst[(idx+n)%len(lst)]
t=''.join(S)
print(t)
  


### FIXED CODE ###

n=int(input())
s=input()
lst=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
S=list(s)
for i in range(len(S)):
  idx=lst.index(S[i])
  S[i]=lst[(idx+n)%(len(lst))]
t=''.join(S)
print(t)
s = input()
s_asc = ''.join(sorted(s))

t = input()
t_dsc = ''.join(sorted(t, reverse = True))

if s_asc < t_dsc:
    print('Yes')
else:
    print('No')



### FIXED CODE ###

s = input()
s_asc = ''.join(sorted(s))

t = input()
t_dsc = ''.join(sorted(t, reverse = True))

if s_asc < t_dsc:
    print('Yes')
else:
    print('No')
"""
N: state num
M: city num
"""

state_cnt = {}
city_id_dict = {}

(N, M) = list(map(int, input().split()))
# N = 3
# m = 3

for z in range(M):
# p_y_list = [
#     [1, np.random.randint(100)]
#     ,[3, np.random.randint(100)]
#     ,[2, np.random.randint(100)]
#     ,[2, np.random.randint(100)]
#     ,[1, np.random.randint(100)]
#     ,[2, np.random.randint(100)]
    
# ]
# for (P, Y) in p_y_list:
    (P, Y) = list(map(int, input().spilt()))

    if P not in state_cnt.keys():
        state_cnt[P] = 1
    elif P in state_cnt.keys():
        state_cnt[P] += 1
        
    state_num = str(P).zfill(6)
    city_num = str(state_cnt[P]).zfill(6)
    tmp_id = state_num + city_num
    city_id_dict[Y] = tmp_id
    
# get_state = set(map(int, state_cnt.keys()))
# all_state = set(range(1, N+1, 1))
# remain = set(all_state) - set(get_state)
# for num in ramain:
#     tmp_id = str(num).zfill(6) + "0"*6
#     city_id_list.append(tmp_id)
    
for _, city_id in sorted(city_id_dict.items()):
    print(city_id)

### FIXED CODE ###

N, M = map ( int, input ( ).split ( ) )# N,Mを取得
#初期化
lists = [ ]
#listに要素を追加　後で並び変えるため並び替える前の順番を示すキーを第三要素に挿入しておく
for i in range ( M ):
    lists.append ( list ( map ( int, input ( ).split ( ) ) ) + [ i ] )
#第一要素に昇順で並び替えた後、第二要素で昇順に並び替える
lists.sort ( key=lambda x: x[ 1 ] )
lists.sort ( key=lambda x: x[ 0 ] )
# befは前回の第一要素　stateは第一要素での順位
bef = 0
state = 0
retstr = ''
triple = [ ]#第四要素に識別番号を追加したリストの初期化
for i in lists:
    if (i[ 0 ] != bef):
        bef = i[ 0 ]
        state = 1
        triple.append ( [ i[ 0 ], i[ 1 ], i[ 2 ], str ( i[ 0 ] ).rjust ( 6, '0' ) + str ( state ).rjust ( 6, '0' ) ] )
    else:
        state += 1
        triple.append ( [ i[ 0 ], i[ 1 ], i[ 2 ], str ( i[ 0 ] ).rjust ( 6, '0' ) + str ( state ).rjust ( 6, '0' ) ] )
 
triple.sort ( key=lambda x: x[ 2 ] )#第三要素で並び替えて、元の入力に対応した式ベンツ番号の順番に戻す
for i in triple:
    print ( i[ 3 ] )#識別番号の出力
a = int(input())
N= map(int, input().split())
x = list(map(int, input().split()))
m = max(x)
M = m/2
s = float("INF")
for i in x:
    s = min(s,abs(M-i))
print(m,s)

### FIXED CODE ###

a = int(input())
x = list(map(float, input().split()))
m = max(x)
M = m/2
t = 0
s = float("INF")
for i in x:
    #print(s,abs(M-i),i,M)
    if s >= abs(M-i):
        s = min(s,abs(M-i))
        t = i
print(str(int(m))+" "+str(int(t)))
N, Q = map(int, input().split())
string = input()
 
counter = [0]*N

for i in range(Q):
    counter[i+1] = counter[i]
    if string[i:i+2] == "AC":
        counter[i+1] += 1
        
for i in range(Q):
    l, r = map(int, input().split())
    print(counter[l-1] - counter[r-1])

### FIXED CODE ###

N, Q = map(int, input().split())
string = input()
 
counter = [0]*(N+1)

for i in range(N):
    counter[i+1] = counter[i] + (1 if string[i:i+2] == "AC" else 0)

for i in range(Q):
    l, r = map(int, input().split())
    print(counter[r-1] - counter[l-1])
from collections import defaultdict
from itertools import accumulate
from operator import xor


def solve_0(acc):
    MOD = 10 ** 9 + 7
    cnt_0 = 0
    counts = defaultdict(list)
    for a in acc:
        if a == 0:
            for i, cnt in counts.items():
                if len(cnt) % 2 == 0:
                    cnt[-1] += 1
                else:
                    cnt.append(1)
            cnt_0 += 1
        else:
            cnt = counts[a]
            if len(cnt) % 2 == 0:
                cnt.append(1)
            else:
                cnt[-1] += 1
    ans = pow(2, cnt_0 - 1, MOD)
    for i, cnt in counts.items():
        c1 = cnt[0]
        ans += c1
        loc = {c1: 0}
        if len(cnt) > 2:
            for c0, c1 in zip(cnt[1::2], cnt[2:-1:2]):
                tmp = c1
                for i1, i0 in loc.items():
                    tmp += i1 * (i0 + c0) * c1
                    loc[i1] += c0
                loc[tmp] = 0
                ans = (ans + tmp) % MOD
                # print(ans, c0, c1, loc, tmp)
        ans %= MOD
    return ans


def solve_1(acc):
    MOD = 10 ** 9 + 7
    common = acc[-1]
    step = 1
    cnt = 0
    ans = 0
    for a in acc:
        if a == common:
            cnt = (cnt + step) % MOD
        elif a == 0:
            step = (step + cnt) % MOD
            ans = cnt
    return ans + 1


n = int(input())
aaa = list(map(int, input().split()))
acc = list(accumulate(aaa, func=xor))
# print(acc)
if acc[-1] == 0:
    print(solve_0(acc))
else:
    print(solve_1(acc))


### FIXED CODE ###

import sys
from collections import defaultdict
from itertools import accumulate
from operator import xor


def solve_0(acc):
    MOD = 10 ** 9 + 7
    cnt_0 = 0
    counts = defaultdict(list)
    last_0 = {}
    for a in acc:
        if a == 0:
            cnt_0 += 1
        else:
            cnt = counts[a]
            if len(cnt) == 0:
                cnt.append(1)
                last_0[a] = cnt_0
            else:
                btw_0 = cnt_0 - last_0[a]
                if btw_0 > 0:
                    cnt.append(btw_0)
                    cnt.append(1)
                    last_0[a] = cnt_0
                else:
                    cnt[-1] += 1

    ans = pow(2, cnt_0 - 1, MOD)
    for i, cnt in counts.items():
        dp0 = 1
        dp1 = cnt[0]
        for c0, c1 in zip(cnt[1::2], cnt[2::2]):
            dp0 = (dp0 + dp1 * c0) % MOD
            dp1 = (dp1 + dp0 * c1) % MOD
        ans = (ans + dp1) % MOD

    return ans


def solve_1(acc):
    MOD = 10 ** 9 + 7
    common = acc[-1]
    dp0 = 1
    dp1 = 0
    for a in acc:
        if a == 0:
            dp0 = (dp0 + dp1) % MOD
        elif a == common:
            dp1 = (dp1 + dp0) % MOD
    return dp0


n = int(input())
aaa = list(map(int, input().split()))
if 'PyPy' in sys.version:
    acc = [0] * n
    t = 0
    for i in range(n):
        t = acc[i] = t ^ aaa[i]
else:
    acc = list(accumulate(aaa, func=xor))
# print(acc)
if acc[-1] == 0:
    print(solve_0(acc))
else:
    print(solve_1(acc))
S=list(input())
i=0
while 0<=i<=len(S)-1:
    if S[i]=="S":
        if S[i+1]=="T":
            S.remove(S[i])
            S.remove(S[i])
            i=0
        else:
            i+=1
    else:
        i+=1
print(len(S))
            

### FIXED CODE ###

S=input()
t=0
u=0
for i in range(len(S)):
    if S[i]=="S":
        t+=1
    else:
        if t>=1:
            u+=2
            t-=1
print(len(S)-u)
import sys
input = sys.stdin.readline

#input
X, Y = map(int, input().split())

#output
import math

if (X + Y) % 3 == 0:
    k = (-X + 2*Y) //3
    l = (2*X -Y) //3
    answer = math.factorial(k+l)//(math.factorial(k)*math.factorial(l)) % (10**9 + 7)
else:
    answer = 0

print(answer)    

### FIXED CODE ###

import sys
input = sys.stdin.readline

#input
X, Y = map(int, input().split())

#output
import math

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

if (X + Y) % 3 == 0:
    k = (-X + 2*Y) //3
    l = (2*X -Y) //3
    if k < 0 or l <0:
        answer = 0
    else:
        answer = cmb(k+l, l) % (10**9 + 7)
else:
    answer = 0

print(answer)
N, C = map(int, input().split())
D = [list(map(int, input().split())) for _ in range(C)]
c = [list(map(lambda x: int(x)-1, input().split())) for _ in range(N)]

cost = [[0] * 3 for _ in range(C)]
for p in range(C):
    for i in range(N):
        for j in range(N):
            #グループごとにかかるコストの計算
            cost[(i+j)%3][p] += D[c[i][j]][p]

res = 10 ** 9
p = [0] * 3
for p[0] in range(C):
    for p[1] in range(C):
        if p[0] == p[1]:
            continue
        for p[2] in range(C):
            if p[2] == p[0] or p[1] == p[2]:
                continue
            tmp = 0
            for i in range(3):
                tmp += cost[i][p[i]]
            res = min(res, tmp)

print(res)
                

### FIXED CODE ###

N, C = map(int, input().split())
D = [list(map(int, input().split())) for _ in range(C)]
c = [list(map(lambda x: int(x)-1, input().split())) for _ in range(N)]

cost = [[0] * C for _ in range(3)]
for p in range(C):
    for i in range(N):
        for j in range(N):
            #グループごとにかかるコストの計算
            cost[(i+j)%3][p] += D[c[i][j]][p]

res = 10 ** 9
p = [0] * 3
for p[0] in range(C):
    for p[1] in range(C):
        if p[0] == p[1]:
            continue
        for p[2] in range(C):
            if p[2] == p[0] or p[1] == p[2]:
                continue
            tmp = 0
            for i in range(3):
                tmp += cost[i][p[i]]
            res = min(res, tmp)

print(res)
a = int(input())
b, c = list(map(int, input().split()))
if 
if int(c/a)>int(b/a):
  print("OK")
else:
  if b % a == 0:
    print("OK")
  else:
    print("NG")

### FIXED CODE ###

a = int(input())
b, c = list(map(int, input().split()))
flag = 0
for i in range(b, c+1):
  if i % a == 0:
    flag = 1
if flag:
  print("OK")
else:
  print("NG")
N, M = map(int, input().split())
arr = [0 for _ in range(M)]
for i in range(M):
    p, y = map(int, input().split())
    arr[i] = [p, y, i]

arr.sort(key=lambda x: x[1])

arr[0][1] = 1
P_cnt = [1 for _ in range(10 ** 5)]
ans_list = [0] * M
for p, y, i in arr:
    ans_list[i] = [str(p).zfill(6) + str(P_cnt[p]).zfill(6), i]
    P_cnt[p] += 1

ans_list.sort(key=lambda x: x[1])
for i in range(M):
    print(ans_list[i][0])

### FIXED CODE ###

N, M = map(int, input().split())
arr = [0 for _ in range(M)]
for i in range(M):
    p, y = map(int, input().split())
    arr[i] = [p, y, i]

arr.sort(key=lambda x: x[1])

arr[0][1] = 1
P_cnt = [1 for _ in range(10 ** 6)]
ans_list = [0] * M
for p, y, i in arr:
    ans_list[i] = [str(p).zfill(6) + str(P_cnt[p]).zfill(6), i]
    P_cnt[p] += 1

ans_list.sort(key=lambda x: x[1])
for i in range(M):
    print(ans_list[i][0])
def is_target_string(S):
    if S[0] != 'A':
        return false
    C_cnt = 0
    C_index = -1
    for i in range(2, len(S)-1):
        if S[i] == 'C':
            C_cnt += 1
            C_index = i
    if C_cnt != 1:
        return False

    for i in range(len(S)):
        if i != 0 and i != C_index:
            if S[i].isupper():
                return False

    return True

S = input()

print('AC' if is_target_string(S) else 'WA')



### FIXED CODE ###

def is_target_string(S):
    if S[0] != 'A':
        return False
    C_cnt = 0
    C_index = -1
    for i in range(2, len(S)-1):
        if S[i] == 'C':
            C_cnt += 1
            C_index = i
    if C_cnt != 1:
        return False

    for i in range(len(S)):
        if i != 0 and i != C_index:
            if S[i].isupper():
                return False

    return True

S = input()

print('AC' if is_target_string(S) else 'WA')
import sys
input = sys.stdin.readline

n = int(input())
l = [list(map(int,input().split())) for i in range(n)]
dp = [[0,-1] for i in range(n+1)]

for i in range(n):
    a = l[i].index(max(l[i]))
    if dp[i][1] == a:
        b = l[i].index(min(l[i]))
        dp[i+1][0],dp[i+1][1] = dp[i][0]+l[i][3-a-b],3-a-b
    else:
        dp[i+1][0],dp[i+1][1] = dp[i][0]+l[i][a],a
    
print(dp[n][0])
        
    

### FIXED CODE ###

import sys
input = sys.stdin.readline

n = int(input())
l = [list(map(int,input().split())) for i in range(n)]
dp = [[0]*3 for i in range(n+1)]

for i in range(n):
    dp[i+1][0] = max(dp[i][1],dp[i][2])+l[i][0]
    dp[i+1][1] = max(dp[i][0],dp[i][2])+l[i][1]
    dp[i+1][2] = max(dp[i][1],dp[i][0])+l[i][2]
    
print(max(dp[n]))
#!/usr/bin/env python3
from functools import reduce

mod = 10**9 + 7
n, k, *a = map(int, open(0).read().split())
a.sort(key=lambda x: abs(x))
ans = reduce(lambda a, b: (a * b) % mod, a[-k:])

c = a[-k:]
j = sum(i < 0 for i in c) % 2
if j:
    c = a[-k:]
    neg = [i for i in c if i < 0]
    pos = [i for i in c if i > 0]
    b = sorted(a[:n - k])
    if 0 >= b[-1] / neg[0] > b[0] / pos[0]:
        ans = ans * pow(neg[0], mod - 2, mod) * b[-1] % mod
    elif b[-1] / neg[0] <= 0:
        ans = ans * pow(pos[0], mod - 2, mod) * b[0] % mod
    else:
        ans = reduce(lambda a, b: (a * b) % mod, a[:k])
print(ans)


### FIXED CODE ###

#!/usr/bin/env python3
from functools import reduce

mod = 10**9 + 7
n, k, *a = map(int, open(0).read().split())
a.sort(key=lambda x: abs(x))
ans = reduce(lambda a, b: (a * b) % mod, a[-k:])

c = a[-k:]
j = sum(i < 0 for i in c) % 2
if j:
    c = a[-k:]
    neg = [i for i in c if i < 0]
    pos = [i for i in c if i > 0]
    b = sorted(a[:n - k])
    if b == []:
        print(ans)
        exit()
    if neg == []:
        if pos[0] * b[0] < 0:
            ans = ans * pow(pos[0], mod - 2, mod) * b[0] % mod
        else:
            ans = reduce(lambda a, b: (a * b) % mod, a[:k])
    elif pos == []:
        if neg[0] * b[-1] < 0:
            ans = ans * pow(neg[0], mod - 2, mod) * b[-1] % mod
        else:
            ans = reduce(lambda a, b: (a * b) % mod, a[:k])
    elif pos[0] * b[-1] < neg[0] * b[0] and pos[0] * b[0] < 0:
        ans = ans * pow(pos[0], mod - 2, mod) * b[0] % mod
    elif 0 > b[-1] * neg[0]:
        ans = ans * pow(neg[0], mod - 2, mod) * b[-1] % mod
    else:
        ans = reduce(lambda a, b: (a * b) % mod, a[:k])
print(ans)
T = input()
lis = list(T)
n = lis.count("?")

temp = [i for i, x in enumerate(lis) if x == '?']

t =0
op_cnt = n
for i in range(2 ** n):
    op = ["P"] * n  # あらかじめ ["P", "P", "P"] というリストを作っておく
    for j in range(n):
        if ((i >> j) & 1):
            op[n - 1 - j] = "D"  # フラグが立っていた箇所を "D" で上書き

    for i, e in enumerate(op):
        lis[temp[i]] = e
        LIS = ''.join(lis)
        print(t , LIS.count("PD"))
        if t < LIS.count("PD"):
            t = LIS.count("PD")
            List = LIS
            #print(t,LIS)
        else:
            pass
print(List)

### FIXED CODE ###

T = input()
print(T.replace("?","D"))
import numpy as np

s = input()
int a = 0

for i in range len(s):
    if i % 2 == 0:
        if a[i] != "R":
            a++
    if i % 2 == 1:
        if a[i] != "L":
            a++
    if a == len(s):
        print('Yes')
    else:
        print('NO')
  
  

### FIXED CODE ###

s = input()
a = 0
n = len(s)

for i in range (n):
    if i % 2 == 1:
        if s[i] != "R":
            a=a+1
    if i % 2 == 0:
        if s[i] != "L":
            a=a+1
if a == len(s):
    print('Yes')
else:
    print('No')
import numpy as np

n, m = map(int, input().strip().split())
a = np.zeros((n,m), dtype = int)
b = np.zeros((m,1), dtype = int)

for i in range(n):
    a[i] = list(map(int, input().strip().split()))
for i in range(m):
    b[i] = int(input())

c = a.dot(b)

for i in range(n):
    print(c[i][0])

### FIXED CODE ###

n, m = map(int, input().strip().split())
a = [[0 for j in range(m)] for i in range(n)]
b = [[0] for j in range(m)]
c = [[0] for j in range(n)]

for i in range(n):
    a[i] = list(map(int, input().strip().split()))

for i in range(m):
    b[i] = [int(input())]


for i in range(n):
    for j in range(m):
        c[i][0] += a[i][j]*b[j][0]
    print(c[i][0])
n = input()
a_n = map(int,raw_input().split())
j = -1
for i in range(n):
	print '\b',
	sys.stdout.write(str(a_n[j])
	j -= 1

### FIXED CODE ###

import sys
n = input()
a_n = map(int,raw_input().split())
j = -1
for i in range(n):
	if j == -1 :
			sys.stdout.write(str(a_n[j]))
			j -= 1
	else :		
		print (' '),
		sys.stdout.write(str(a_n[j]))
		j -= 1
print ''
A,B =map(int,input().split())

print(max(A*2-1,A+B,B*2-1)

### FIXED CODE ###

A,B =map(int,input().split())
 
print(max(A*2-1,A+B,B*2-1))
N = int(input())

for i in (26):
	for j in(16):
  		if j*4+J*7 == N:
      		print("Yes")
        else:
          print("No")

### FIXED CODE ###

N = int(input())

flag = 0

for i in range(26):
    for j in range(16):
      if i*4+j*7 == N:
        flag = 1

if flag == 1:
    print("Yes")
else:
    print("No")
def lcs():
    A = raw_input()
    B = raw_input()

    m = len(A)
    n = len(B)

    dp = [[0 for i in range(n + 1)] for j in range(m + 1)]

    maxl = 0

    for i in range(1, m + 1):
        for j in range(1, n + 1):
            if A[i - 1] == B[j - 1]:
                dp[i][j] = dp[i - 1][j - 1] + 1
            else:
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1])

            maxl = max(maxl, dp[i][j])

    return maxl

n = input()
for _ in range(n):
    print lcs()

### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_10_C

最長共通部分列
"""


c = []
def prep_array(X, Y):
    global c
    """ 値が0の2次元配列を用意する。サイズは入力データの最大値を想定して縦横(1000+1)以上必要。 """
    # from array import array
    # c = [array('I', [0] * (len(X)+1)) for _ in range(len(Y)+1)]  #  arrayで用意
    c = [[0]*(len(Y)+2) for _ in range(len(X)+2)] #  リストで用意
    return c


def check_max(array):
    """ 2次元配列の中の最大の値を返す """
    max_lcs = 0
    for row in array:
        temp_max = max(row)
        if temp_max > max_lcs:
            max_lcs = temp_max
    return max_lcs


def calc_lcs4(X, Y, c):
    """
    Y[j]のアクセス方法を変更
    リストの値を一旦変数に保存するように変更
    最長共通部分長を関数内で計算するように変更
    4/5 のテストデータを使用してプロファイリングすると実効時間は 5.6秒
    """
    X = ' ' + X
    Y = ' ' + Y
    m = len(X)
    n = len(Y)
    max_lcs = 0

    pre_row = c[0]
    for i in range(1, m):
        row = c[i]
        XX = X[i]
        for j, YY in enumerate(Y):
            if XX == YY:
                pr_j1 = pre_row[j - 1]
                row[j] = pr_j1 + 1
                if pr_j1+1 > max_lcs:
                   max_lcs = pr_j1 + 1
            else:
                pr_j = pre_row[j]
                r_j1 = row[j-1]
                if pr_j >= r_j1:
                    row[j] = pr_j
                else:
                    row[j] = r_j1
        pre_row = row
    return max_lcs


if __name__ == '__main__':
    # データの入力
    num = int(input())
    #f = open('input.txt')
    #num = int(f.readline())

    for _ in range(num):
        X = input().strip()
        Y = input().strip()

        # 処理の実行
        result = calc_lcs4(X, Y, prep_array(X, Y))

        # 結果の表示
        print(result)
a,b,c,k = [int(i) for i in input().split()]
if k<=a:
  print(k)
else if a<k<=a+b:
  print(a)
else:
  print(a-(k-a-b))
      

### FIXED CODE ###

a,b,c,k = [int(i) for i in input().split()]
if k<=a:
  print(k)
elif k<=a+b and k>a:
  print(a)
else:
  print(a-(k-a-b))