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

n = 50001
c = [1 for i in range(n)]
c[0] = 0
i = 2
while i**2 <= n:
    j = i*2
    while j <= n:
        c[j - 1] = 0
        j += i
    i += 1

while True:
    n = int(input())
    if n == 0:
        break
    elif n%2 == 1:
        print(0)
        continue
    cnt = 0
    for i in range(n):
        if c[i] == 1 and c[n-i] == 1:
            cnt +=1
    print(cnt)



### FIXED CODE ###

n = 50001
is_prime = [i for i in range(n)]
is_prime[0] = is_prime[1] = 0
i = 2
while i**2 <= n:
    j = i*2
    while j < n:
        is_prime[j] = 0
        j += i
    i += 1

prime_set  = set(is_prime)
prime_set.remove(0)
prime_list = sorted(list(prime_set))

while True:
    cnt = 0
    n = int(input())
    if n == 0:
        break
    for i in prime_list:
        if i > n//2:
            break
        if n - i in prime_set:
            cnt += 1
    print(cnt)
### BUGGY CODE ###

from collections import deque

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

que = deque()
for i in range(h):
    for j in range(w):
        if G[i][j] == '#':
            que.append((i, j, 0))
cnt = 0
while que:
    i, j, c = que.popleft()

    for ni, nj in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
        if i + ni < 0 or j + nj < 0: continue
        if i + ni >= h or j + nj >= w: continue

        if G[i + ni][j + nj] == '.':
            G[i + ni][j + nj] = '#'
            que.append((i + ni, j + nj, c + 1))
            cnt = max(cnt, c + 1)
print(cnt)


### FIXED CODE ###

H, W = [int(_) for _ in input().split()]
A = [list(input()) for _ in range(H)]

from collections import deque

lst = deque()

for i in range(H):
    for j in range(W):
        if A[i][j] == '#':
            lst.append((i, j, 0))


def chg(i, j):
    if i < 0 or j < 0 or H <= i or W <= j: return False
    if A[i][j] == '.':
        A[i][j] = '#'
        return True
    return False


ans = 0
while lst:
    h, w, v = lst.popleft()
    ans = max(v, ans)
    for i in range(-1, 2):
        for j in range(-1, 2):
            if i != 0 and j != 0: continue

            if chg(h + i, w + j):
                lst.append((h + i, w + j, v + 1))
print(ans)
### BUGGY CODE ###

N = int(input())
A = input().split(' ')

t = []
for i in range(N):
    t.append(0)

for i in range(N):
    t[int(A[i]) - 1] = i + 1

res = ''
for i in range(N):
    res = res + str(t[i]) + ' '

print(res.strip())


### FIXED CODE ###

N = int(input())
A = input().split(' ')

t = []
for i in range(N):
    t.append(0)

for i in range(N):
    t[int(A[i]) - 1] = str(i + 1)

print(' '.join(t))
### BUGGY CODE ###

"""TLE
N = int(input())
sequence = list(input().split())
ans = []
for i in range(N):
    a_i = sequence[i]
    ans.append(a_i)
    ans = ans[::-1]
print(" ".join(ans))
"""

N = int(input())
sequence = list(input().split())
ans = []
for i in range(N):
    if i % 2 == N % 2:
        ans.append(sequence[i])
    else:
        ans.insert(0,sequence[i])
print(" ".join(ans))


### FIXED CODE ###

"""TLE
N = int(input())
sequence = list(input().split())
ans = []
for i in range(N):
    a_i = sequence[i]
    ans.append(a_i)
    ans = ans[::-1]
print(" ".join(ans))
"""

from collections import deque
n = int(input())
sequence = deque(map(int,input().split()))
ans = deque()
if n % 2 == 1:
    for i in range(n):
        if i % 2 == 0:
            ans.appendleft(sequence[0])
        else:
            ans.append(sequence[0])
        sequence.popleft()
        #print(ans)
else:
    for i in range(n):
        if i % 2 == 1:
            ans.appendleft(sequence[0])
        else:
            ans.append(sequence[0])
        sequence.popleft()
        #print(ans)
print(*ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**7)
import numpy as np
# n = int(input())
# a, b = map(int, input().split())
# int_list = list(map(int, input().split()))
# l = list(input().split())

def solve():
    b_list = []
    c_list = []
    n, m = map(int, input().split())
    a_list = list(map(int, input().split()))
    for j in range(m):
        b, c = map(int, input().split())
        b_list.append(b)
        c_list.append(c)
    #print(a_list)

    a = np.array(a_list, dtype=np.int64)

    for j in range(m):
        a.sort()
        # print(a)
        # print(c_list[j])
        to_index = min(b_list[j], sum(a < c_list[j]))
        a[:to_index] = c_list[j]
        # print(a)
        # print("")

    print(np.sum(a))
solve()

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
import numpy as np
from collections import defaultdict
d = defaultdict(int)
# n = int(input())
# a, b = map(int, input().split())
# int_list = list(map(int, input().split()))
# l = list(input().split())

def solve():
    # b_list = []
    # c_list = []
    n, m = map(int, input().split())
    d = defaultdict(int)
    a_list = list(map(int, input().split()))

    for a in a_list:
        d[a] += 1

    for j in range(m):
        b, c = map(int, input().split())
        d[c] += b
        # a_list += [c] * b
        # b_list.append(b)
        # c_list.append(c)

    #print(d)
    current_n = 0
    sum = 0
    for k in sorted(d.keys(), reverse=True):
        sum += min(d[k], n - current_n) * k
        current_n += d[k]
        if current_n >= n:
            break
    print(sum)
    # for j in range(m):
    #     a_list += [c_list[j]] * b_list[j]

    # a_list.sort(reverse=True)
    # print(sum(a_list[:n]))


    # a = np.array(a_list, dtype=np.int64)


    #
    # for j in range(m):
    #     a.sort()
    #     to_index = min(b_list[j], sum(a < c_list[j]))
    #     a[:to_index] = c_list[j]
    #
    # print(np.sum(a))
solve()
### BUGGY CODE ###

import sys

h,w=[int(x) for x in input().rstrip().split()]
l=[]
black=0
for i in range(h):
  s=[x for x in input()]
  l.append(s)
  for j in s:
    if j=="#":
      black+=1

dist=[[False]*w for i in range(h)]
done=[[float('inf')]*w for i in range(h)]

cnt=0
def bfs():
  stack=[[0,0]]
  done[0][0]=0
  while(stack):
    x,y=stack.pop(0)
    dist[y][x]=True
    
    move=[[x+1,y],[x-1,y],[x,y+1],[x,y-1]]

    for mx,my in move:
      if not(0<=my<=h-1) or not(0<=mx<=w-1) or l[my][mx]=="#" or dist[my][mx]==True:
        continue

      done[my][mx]=done[y][x]+1
      stack.append([mx,my])
    
      if my==h-1 and mx==w-1:
        print(h*w-done[my][mx]-black-1)
        sys.exit()
  print(-1)


if __name__=="__main__":
  bfs()




### FIXED CODE ###

import sys
 
h,w=[int(x) for x in input().rstrip().split()]
l=[]
black=0
for i in range(h):
  s=[x for x in input()]
  l.append(s)
  black+=sum(j.count("#") for j in s)
 
done=[[float('inf')]*w for i in range(h)]
def bfs():
  stack=[[0,0]]
  done[0][0]=0
  while(stack):
    x,y=stack.pop(0)
    move=[[x+1,y],[x-1,y],[x,y+1],[x,y-1]]
 
    for mx,my in move:
      if not(0<=my<=h-1) or not(0<=mx<=w-1) or l[my][mx]=="#" or done[my][mx]!=float('inf'):
        continue

      done[my][mx]=done[y][x]+1
      stack.append([mx,my])
      
      if my==h-1 and mx==w-1:
        print(h*w-done[my][mx]-black-1)
        sys.exit()
  print(-1)
 
if __name__=="__main__":
  bfs()
### BUGGY CODE ###

import bisect

n, d, a = map(int, input().split())
xh = []
for i in range(n):
    xh.append(list(map(int, input().split())))
xh.sort()
count = 0
min_x = 0
x = [xh[i][0] for i in range(n)]
sum_h = sum([xh[i][1] for i in range(n)])
while sum_h > 0:
    flag = True
    place = xh[min_x][0] + d
    num = (xh[min_x][1] - 1) // a + 1
    count += num
    for i in range(min_x, bisect.bisect(x, place + d)):
        new_h = max(0, xh[i][1] - a * num)
        sum_h -= (xh[i][1] - new_h)
        if new_h == 0:
            if flag == True:
                min_x += 1
        else:
            flag = False
        xh[i][1] = new_h
print(count)

### FIXED CODE ###

import bisect

n, d, a = map(int, input().split())
xh = []
for i in range(n):
    xh.append(list(map(int, input().split())))
xh.sort()
x = [xh[i][0] for i in range(n)]
h = [xh[i][1] for i in range(n)]
count = 0
min_x = 0
acm = [0] * (n + 1)
dif = [0] * (n + 1)
while min_x < n:
    place = x[min_x] + d
    num = (h[min_x] - acm[min_x + 1] - 1) // a + 1
    count += num
    dif[min_x] += num
    dif[bisect.bisect(x, place + d)] -= num
    for i in range(min_x, bisect.bisect(x, place + d)):
        acm[i + 1] = acm[i] + dif[i] * a
        if acm[i + 1] >= h[i]:
            min_x += 1
            continue
        else:
            break
print(count)
### BUGGY CODE ###


n = int(input())

num = 0

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


for i in range(n):
    i +=1
    f = len(make_divisors(i))
    num += f*i

print(num)

### FIXED CODE ###


n = int(input())

ans = 0

def calc(b,e):
    cnt = e // b
    return (b + e) * cnt // 2

for i in range(1, n+1):
    ans += calc(i, n//i * i)

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

mod=10**9+7
n, m=map(int,input().split())
x=tuple(map(int,input().split()))
y=tuple(map(int,input().split()))

lx=[]
for i in range(0, n-1):
    for j in range(i, n):
        lx.append(x[j]-x[i])
ly=[]
for i in range(0, m-1):
    for j in range(i, m):
        ly.append(y[j]-y[i])

ans=0
for i in lx:
    for j in ly:
        ans+=i*j
        ans%=mod
print(ans)

### FIXED CODE ###

mod=10**9+7
n, m=map(int,input().split())
x=tuple(map(int,input().split()))
y=tuple(map(int,input().split()))

lx, ly=0, 0
for i in range(n):
    lx+= i*x[i]-(n-i-1)*x[i]
    lx%=mod
for i in range(m):
    ly+= i*y[i]-(m-i-1)*y[i]
    ly%=mod

print((lx*ly)%mod)
### BUGGY CODE ###

N, K, Q = map(int, input().split(' '))
score = [K for player in range(N)]

for question in range(Q):
    index = int(input())
    for i in range(N):
        if i != index - 1:
            score[i] = score[i] - 1

for result in score:
    if result > 0:
        print('Yes')
    else:
        print('No')


### FIXED CODE ###

N, K, Q = map(int, input().split(' '))
score = [K for player in range(N)]
answers = [int(input()) - 1 for q in range(Q)]

for answer in answers:
    score[answer] = score[answer] + 1

score = [point - Q for point in score]

for result in score:
    if result > 0:
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

import sys


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

ope = [tuple(map(int, x.split())) for x in sys.stdin.readlines()]

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

cnt = 0
for b, c in ope:
    A = A + [c] * b
    cnt += b

    if cnt >= N:
        break

A.sort(reverse=True)

print(sum(A[:N]))


### FIXED CODE ###

import sys


N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)

ope = [list(map(int, x.split())) for x in sys.stdin.readlines()]

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

mp = 0
ap = 0
cnt = 0
ans = 0

while cnt < N:
    a = A[ap]
    m = ope[mp][1] if mp < M else 0

    if m >= a:
        mc = min(ope[mp][0], N - cnt)
        ans += m * mc
        cnt += mc
        mp += 1
    else:
        ans += a
        cnt += 1
        ap += 1

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

import heapq
def SME(start,end):
    if end > N : end = N
    count = 0
    for i,x in enumerate(Whole[start:end]):
        heapq.heappush(A,[x,i])
    for j in range(start,end):
        a = heapq.heappop(A)
        if None not in ANS[a[1]:a[1]+L] : continue
        for i in range(L):
            idx = a[1] + i
            try :
                if ANS[idx] : continue
                else :
                    ANS[idx] = a[0]
                    count += 1
            except IndexError : continue
        if count > N * parameter : break
    for i in range(L):
        if ANS[i] : continue
        else : ANS[i] = min(Whole[:i+1])
    i = L
    while i < N :
        if None not in ANS[i:i+L//2] :
            i += L//2
            continue
        if ANS[i] : continue
        else: ANS[i] = min(Whole[i+1-L:i+1])
        i+=1
    return ANS
[N,L] = [int(x) for x in input().split()]
Whole = [int(x) for x in input().split()]
A = []
parameter = 0.999
ANS = [None]*N
ANS = SME(0, N)
for i in ANS[L-1:-1]:print(i, end=" ")
print(ANS[-1])

### FIXED CODE ###

def ascend(a,b):
    mini = min(A[a:a+L])
    ans[a] = mini
    for i in range(a+1,b):
        if A[i+L-1] <= mini : mini = A[i+L-1]
        elif A[i-1] == mini : mini = min(A[i:i+L])
        ans[i] = mini

def descend(a,b):
    mini = min(A[b-1:b+L-1])
    ans[b-1] = mini
    for i in range(b-2,a-1,-1):
        if A[i] <= mini : mini = A[i]
        elif A[i+L] == mini: mini = min(A[i:i+L])
        ans[i] = mini
    
[N,L] = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ans = [None]*(N-L+1)
count = 0;
if N > 10 ** 4:
    for i in range(100):
        if A[i+1] > A[i] : count += 1
    if count > 80 : descend(0, N-L+1)
    else : ascend(0,N-L+1)
else :
    ascend(0, N-L+1)
for i in ans[:-1] : print(i, end=" ")
print(ans[-1])
### BUGGY CODE ###

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

L=[]
for i in range(0, 10):
    if i not in D:
        L.append("i")    

i = N
while True:
    if set(list(str((i)))) <= set(L):
        print(i)
        break
    i += 1   

### FIXED CODE ###

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

L=[]
for i in range(0, 10):
    if i not in D:
        L.append(str(i))    

L.sort()

i = N
while True:
    if set(list(str((i)))) <= set(L):
        print(i)
        break
    i += 1
### BUGGY CODE ###

import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8') 
inf = float('inf') ;mod = 10**9+7 
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n = int(input())
A = list(map(int, input().split()))
ans_str = ""
for i in range(1, n+1):
    if i == n:
        ans_str += str(A.index(i)+1)
        print(ans_str)
        exit()
    ans_str += str(A.index(i)+1) + " "

### FIXED CODE ###

import sys, math, itertools, collections, bisect 
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8') 
inf = float('inf') ;mod = 10**9+7 
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n=int(input())
A=[(e,i) for i,e in enumerate(list(map(int,input().split())))]
#print(A)
A.sort(key=lambda tup: tup[0])
#print(A)
for e,i in A:
    print(i+1)
### BUGGY CODE ###

a=[]
b=int(input())
c=[]
i=0
while i<b:
    a.append(int(input()))
    i+=1

i=1
while i<=b:
    for x in a:
        c.append(x)
    c[i-1]=0
    c.sort()
    print(c[-1])
    i+=1
    c=[]

### FIXED CODE ###

a=[]
b=int(input())
c=[]
i=0
while i<b:
    a.append(int(input()))
    i+=1
for x in a:
    c.append(x)
c.sort()

i=1

if c[-1]!=c[-2]:
    while i<=b:
        if a[i-1]!=c[-1]:
            print(c[-1])
        else:
            print(c[-2])
        i+=1
else:
    while i<=b:
        print(c[-1])
        i+=1
### BUGGY CODE ###

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

# Nが偶数ならAiは全て奇数、Nが奇数なら Aiは全て偶数でなければならない,なぜなら、2x + Ai = N - 1を満たすxが自然数(非負整数)でなければならないから
# さらに、Nが奇数の時はfor i in range(0, N, 2) において 0が１個、それ以外のiが２個ずつ存在しなければならず(これはAiが全て偶数であることも満たしている)、
# Nが偶数の時はfor i in range(1, N, 2) において 全てのiが２個ずつ存在しなければならない(これはAiがすべて奇数であることも満たしている)
# これを踏まえた上でNが偶数の時は N/2人の位置が決まれば反対側の人の位置も決まり、Nが奇数の時は中央の人は固定として、それ以外 (N-1)/2人の位置が決まれば残りの人は反対側で位置が決まる。それぞれ２通りなので、
# よって
if N % 2 != 0:
    for i in range(0, N, 2):
        if A.count(i) == 2:
            continue
        elif A.count(0) == 1:
            continue
        print(0)
        exit()
    order_count = 2 ** ((N - 1) // 2)

else:
    for i in range(1, N, 2):
        if A.count(i) != 2:
            print(0)
            exit()
    order_count = 2 ** (N // 2)

print(order_count)


### FIXED CODE ###

mod = 10 ** 9 + 7
N = int(input())
A = [int(a) for a in input().split()]
A.sort()

if N % 2 != 0:
    if A[0] == 0:
        for i in range(2, N, 2):
            if not (A[i] == i and A[i-1] == i):
                print(0)
                exit()
        order_count = 2 ** ((N - 1) // 2) % mod
    else:
        print(0)
        exit()

else:
    for i in range(1, N, 2):
        if not (A[i] == i and A[i-1] == i):
            print(0)
            exit()
    order_count = 2 ** (N // 2) % mod 

print(order_count)
### BUGGY CODE ###

import sys
n = int(input())
ls = list(map(int,input().split()))
for k in range(2**n):
    a = [0]*n
    for l in range(n):
        if (k>>l)&1:
            a[l] += 1
    p = 0
    for i in range(n):
        di = a[i::i+1]
        m = sum(di)
        if m % 2 != ls[i]:
            p = 1
            break
    if p == 0:
        new = []
        for t in range(len(a)):
            if a[t] == 1:
                new.append(t+1)
        print(sum(a))
        if sum(a) != 0:
            print(*new)
        sys.exit()
print(-1)

### FIXED CODE ###

n = int(input())
ls = list(map(int,input().split()))
di = [100]*(n+1)
di[0] = 0
for i in range(n):
    N = n - i
    num = int(n/N)
    fi = []
    for j in range(num):
        fi.append(N*(j+1))
    p = 0
    for k in fi:
        p += di[k]
    if (p - 100)%2 == ls[fi[0]-1]:
        di[fi[0]] = 0
    else:
        di[fi[0]] = 1
print(sum(di))
for e in range(1,len(di)):
    if di[e] == 1:
        print(e,end=" ")
### BUGGY CODE ###

N=int(input())
l=list(map(int,input().split()))
k=[0]*N
a=0
for i in range(N-1):
  a+=l[i]
  k[i]=(sum(l)-a)%(10**9+7)
ans=0
for i in range(0,len(l)-1):
  ans=(ans+l[i]*k[i]%(10**9+7))%(10**9+7)
print(ans)
 


### FIXED CODE ###

N=int(input())
l=list(map(int,input().split()))
b=10**9+7
d=(sum(l))**2
c=0
for i in range(N):
  c=c+l[i]**2
print((d-c)//2%b)
### BUGGY CODE ###

x,y,z,k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a = sorted(a)
b = sorted(b)
c = sorted(c)
memory = []
ai = x-1
bi = y-1
ci = z-1
p = 10**11
while k>0:
    ps = []
    abc = []
    for dx in range(-30,30):
        for dy in range(-30,30):
            for dz in range(-30,30):
                if not (ai+dx>=0 and ai+dx<x and bi+dy>=0 and bi+dy<y and ci+dz>=0 and ci+dz<z):
                    continue
                tmp = a[ai+dx]+b[bi+dy]+c[ci+dz]
                if p >= tmp and not (ai+dx,bi+dy,ci+dz) in memory:
                    ps.append(tmp) 
                    abc.append((ai+dx, bi+dy, ci+dz))
    p = max(ps)
    i = ps.index(p)
    memory.append(abc[i])
    print(p)
    k -= 1


### FIXED CODE ###

def main():
    X, Y, Z, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    A.sort(reverse=True)
    B.sort(reverse=True)
    C.sort(reverse=True)

    T = []
    for a in A:
        for b in B:
            T.append(a + b)

    T = sorted(T, reverse=True)[:min(K, len(T))]

    res = []
    for t in T:
        for c in C:
            res.append(t + c)

    res = sorted(res, reverse=True)[:K]
    for r in res:
        print(r)

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

#横にn個入力
n, m, q = map(int, input().split())
#行列
s = []
for i in range(m):#h:高さ
    s.append([int(m) for m in input().split()])
# 行列
t = []
for i in range(q):  # h:高さ
    t.append([int(m) for m in input().split()])
nnli = []
for i in range(n):
    nnli.append([])
for i in range(n):
    for j in range(n):
        nnli[i].append(0)
for h in range(m):
    for i in range(s[h][0]):
        for j in range(s[h][1] - 1, n):
            nnli[i][j] += 1

for g in range(q):
    print(nnli[t[g][0] - 1][t[g][1] - 1])

### FIXED CODE ###

#横にn個入力
n, m, q = map(int, input().split())
#行列
s = []
for i in range(m):#h:高さ
    s.append([int(m) for m in input().split()] + [i])
# 行列
t = []
for i in range(q):  # h:高さ
    t.append([int(m) for m in input().split()])

LR = [[0 for _ in range(n + 1)] for _ in range(n + 1)]
for v in range(m):
     LR[s[v][0]][s[v][1]] += 1

for j in range(1, n + 1):
    for i in range(1, n + 1):#Lについての累積和
        LR[i][j] += LR[i - 1][j]
for i in range(1, n + 1):
    for j in range(1, n + 1):#Rについての累積和，2次元累積和にする
        LR[i][j] += LR[i][j - 1]

for k in range(q):
    tmp = 0
    #for j in range(t[k][0], t[k][1] + 1):#Rについてみていく
        #tmp += LR[t[k][1]][j] - LR[t[k][0] - 1][j]
    tmp += (LR[t[k][1]][t[k][1]] - LR[t[k][1]][t[k][0] - 1]) - (LR[t[k][0] - 1][t[k][1]] - LR[t[k][0] - 1][t[k][0] - 1])

    print(tmp)
### BUGGY CODE ###

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

ans = 0

for i in range(n):
    for j in range(i+1,n):
        if s[j] != s[i]:
            for k in range(j+1,n):
                if (s[k] != s[j]) and (s[k] != s[i]):
                    if (j-i) != (k-j):
                        ans += 1
print(ans)

### FIXED CODE ###

from itertools import permutations

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

out = 0
ans = s.count("R")*s.count("G")*s.count("B")

combi = list(permutations(["R","G","B"],3))

for i in range(1,n):
    for j in range(n-i*2):
        if (s[j], s[j+i], s[j+i*2]) in combi:
            ans -= 1

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

N,W=map(int,input().split())
dp=[[0]*(W+1) for i in range(N+1)]
for i in range(1,N+1):
  w,v=map(int,input().split())
  for j in range(1,W+1):
    if j>=w:
      dp[i][j]=max(dp[i-1][j],dp[i-1][j-w]+v)
    else:
      dp[i][j]=dp[i-1][j]
print(dp[-1][-1])

### FIXED CODE ###

N,W=map(int,input().split())
dp=[[0]*(W+1) for i in range(N+1)]
for i in range(N):
  w,v=map(int,input().split())
  for j in range(W+1):
    if j>=w:
      dp[i+1][j]=max(dp[i][j-w]+v,dp[i][j])
    else:
      dp[i+1][j]=dp[i][j]
print(dp[N][W])
### BUGGY CODE ###

N, K, Q, *A = map(int, open(0).read().split())
print("\n".join(["Yes" if Q < K + A.count(a)
                 else "No" for a in range(1, N + 1)]))


### FIXED CODE ###

from sys import stdin
from collections import Counter

lines = stdin.readlines()

N, K, Q = map(int, lines[0].split())
ans = [0] * N
A = Counter((int(i) - 1 for i in lines[1:]))
for k in A.keys():
    ans[k] += A[k]
print("\n".join(("Yes" if Q < K + a
                 else "No" for a in ans)))
### BUGGY CODE ###

import sys
input = sys.stdin.readline

def main():       
    def build(list):
        for i,x in enumerate(list,n):
            d = set()
            d.add(x)
            seg[i] = d
            
        for i in range(n-1,0,-1):
            seg[i] = seg[i<<1]|seg[i<<1 | 1]

        ## take the value of [l,r) 
    def get(l,r):
        l += n
        r += n
        res = set()

        while l < r:
            if l & 1:
                res |= seg[l]
                l += 1
            if r & 1:
                res |= seg[r-1]
            l >>= 1
            r >>= 1
        return len(res)

    n,q = map(int,input().split())
    c = list(map(int,input().split()))
    seg = [set()]*(2*n)
    build(c)

    for i in range(q):
        l,r = map(int,input().split())
        print(get(l-1,r))
if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
input = sys.stdin.readline

class BIT:
    def __init__(self, n):
        self.size = n
        self.tree = [0]*(n+1)
 
    def sum(self, i):
        # [0, i) の要素の総和を返す
        s = 0
        while i>0:
            s += self.tree[i]
            i -= i & -i
        return s
    # 0 index を 1 index に変更  転倒数を求めるなら1を足していく
    def add(self, i, x):
        i += 1
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


n,q = map(int,input().split())
c = list(map(int,input().split()))
Q = []
for i in range(q):
    l,r = map(int,input().split())
    Q.append([l,r,i])

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

bit = BIT(n)
ind = [-1]*(n+1)

ans = [0]*q
now = 0
for l,r,num in Q:
    while now < r:
        x = c[now]
        if ind[x] == -1:
            ind[x] = now
            bit.add(now,1)
        else:
            bit.add(ind[x],-1)
            ind[x] = now
            bit.add(now,1)
        now += 1
    ans[num] = bit.sum(r)-bit.sum(l-1)
for i in ans:
    print(i)
### BUGGY CODE ###

a,b,c,k = map(int,input().split())
card = []
for i in range(a):
    card.append(1)
for i in range(b):
    card.append(0)
for i in range(c):
    card.append(-1)
card.sort(key=int,reverse=True)
result = 0
for i in range(k):
    result += card[i]
print(result)

### FIXED CODE ###

a,b,c,k = map(int,input().split())
if k < a:
    print(k)
elif a + b > k:
    print(a)
else:
    print(a - (k - a - b))