n, m, r = map(int, input().split())
b, s = min(map(int, input().split())), max(map(int, input().split()))
print(max(r //  b * s + r % b, r))

nmr=input().split()
n=int(nmr[0])
m=int(nmr[1])
r=int(nmr[2])
C=list(map(int,input().split()))
S=list(map(int,input().split()))
x=min(C)
y=max(S)
if(y<=x):
	print(r)
else:
	n=r//x
	rem=r%x
	r=rem+n*y
	print(r)

import sys, math,os
#from io import BytesIO, IOBase
#data = BytesIO(os.read(0,os.fstat(0).st_size)).readline
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter
# from itertools import permutations,combinations
from decimal import Decimal
from fractions import Fraction
def data(): return sys.stdin.readline().strip()
def mdata(): return list(map(int, data().split()))
def outl(var): sys.stdout.write(' '.join(map(str, var)) + '\n')
def out(var): sys.stdout.write(str(var) + '\n')
#sys.setrecursionlimit(100000 + 1)
INF = 10**9
mod = 10**9 + 7

n,m,r=mdata()
s=mdata()
b=mdata()
out(max((r//min(s))*max(b)+r%min(s),r))

if __name__ == "__main__":
    first_line_components = input().split(' ')
    s = [int(i) for i in input().split(' ')]
    b = [int(i) for i in input().split(' ')]
    r = int(first_line_components[2])
    min_buy = min(s)
    max_sell = max(b)

    balance = r % min_buy
    balance += (r // min_buy) * max_sell

    result = max([balance, r])
    print(result)

import sys
input=sys.stdin.readline
from collections import defaultdict as dd
n,m,r=map(int,input().split())
l=list(map(int,input().split()))
ll=list(map(int,input().split()))
a=min(l)
b=max(ll)
cou=r//a
left=r%a
tot=left+cou*b
print(max(tot,r))

R = int(input().split()[-1])

best_buy = min(map(int, input().split()))
best_sell = max(map(int, input().split()))

num_buy = R // best_buy

print(max(R, R + (best_sell - best_buy) * num_buy))

import os
import sys
import math
import heapq
from decimal import *
from io import BytesIO, IOBase
from collections import defaultdict, deque

def r():
    return int(input())
def rm():
    return map(int,input().split())
def rl():
    return list(map(int,input().split()))

n,m,a=rm()
b=rl()
c=rl()
ini=a
b.sort()
c.sort(reverse=True)
shares=0
shares = a//b[0]
a = a%b[0]
a = a + shares*c[0]
print(max(ini,a))

n,m,b=map(int,input().split())
import math
a1=list(map(int,input().split()))
a2=list(map(int,input().split()))
if min(a1) < max(a2):
    s = math.floor(b/min(a1))
    b -= min(a1)*s
    b += s * max(a2)
print(b)

n, m, d = map(int, input().split())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
k = min(arr1)
j = max(arr2)
if k >= j:
    print(d)
else :
    print(d%k + (d//k)*j)

n,m,r = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
if min(a) >= max(b):
    print(r)
else:
    print((r//min(a))*max(b)+(r%min(a)))

n,m,r=map(int,input().split())
s=list(map(int,input().split()))
b=list(map(int,input().split()))
c=min(s)
p=r//c
x=r%c
if c>=max(b):
    print(r)
else:
    q=max(b)*p
    print(x+q)

a,b,c = map(int,input().split())
l = list(map(int,input().split()))
m = list(map(int,input().split()))
if min(l)>=max(m):print(c)
else:print(c+(max(m)-min(l))*(c//min(l)))

n,m,r=map(int,input().split())
b = list(map(int, input().split()))
c= list(map(int, input().split()))
k=min(b)
p=max(c)
if p>k:
    d=r%k
    print(p*(r//k)+d)
else:
    print(r)

'''input
2 2 50
5 7
4 2

'''

RI = lambda : [int(x1) for x1 in raw_input().split()]
rw = lambda : raw_input().strip()
import sys

n,m,b = RI()
A = RI()
B = RI()
mi = min(A)
mx = max(B)

sh = b/mi
left = b%mi
print max(sh*mx + left,b)

import sys
# sys.stdin = open('input.txt','r')
n,m,r = map(int, input().split())
s = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
s.sort()
b.sort()
if b[-1] > s[0]:
	print(r - (r//s[0])*s[0] + b[-1] * (r//s[0]))
else:
	print(r)

from sys import *
from math import *
n,m,r=map(int,stdin.readline().split())
a=list(map(int,stdin.readline().split()))
b=list(map(int,stdin.readline().split()))
if min(a)>max(b):
    print(r)
else:
    x=r//min(a)
    ans=r%min(a)
    y=x*max(b)
    ans+=y
    print(ans)

n,m,r=map(int,input().split())
s=list(map(int,input().split()))
b=list(map(int,input().split()))
x=min(s)
sh=r//x
a=r%x
a+=max(b)*sh
print(max(a,r))

a,b,c= input().split()
buy= list(map(int,input().split()))
sell= list(map(int,input().split()))

buyat = min(buy)
buy.remove(buyat)
sellat= max(sell)

number= int(c)//buyat
money= int(c)- number*buyat

if buyat<sellat:
    ans= number*sellat + money
else:
    ans= c
print(ans)

n, m ,r = map(int, input().split())
s = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
s.sort()
b.sort(key = lambda x: -x)
if s[0] < b[0]:
    number = r // s[0]
    r -= number * s[0]
    r += number * b[0]
print(r)

n, m ,r = map(int, input().split())
s = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
first = min(s)
second = max(b)
if first < second:
    number = r // first
    r -= number * first
    r += number * second
print(r)

n, m,x = map(int, input().split())
datn = list(map(int, input().split()))
datm = list(map(int, input().split()))
if max(datm) < min(datn):
    print(x)
else:
    a,res = divmod(x, min(datn))
    res += a * max(datm)
    print(res)

n,m,r=map(int,input().split())
s=list(map(int,input().split()))
b=list(map(int,input().split()))

s.sort()
b.sort(reverse=True)
rr=r
share=0

i=0
while r>0 and i<n:
	share+=r//s[i]
	r-=(r//s[i])*s[i]
	i+=1
i=0
ans=r+b[0]*share

print(max(ans,rr))

n,m,k=map(int,input().split())
l1=list(map(int,input().split()))
l2=list(map(int,input().split()))
x=[]
K=min(l1)
D=max(l2)
if D<=K:
    print(k)
    exit()
ans=k//K*D
k=k-k//K*K
print(ans+k)

i=lambda:map(int,input().split())
_,_,r=i()
s=min(i())
b=max(s,*i())
print(r%s+r//s*b)

for _ in range(1):
  #n=int(input())
  #a=sorted(list(map(int, input().split())))
  a,b,c=map(int, input().split())
  x=list(map(int, input().split()))
  y=list(map(int, input().split()))
  p=min(x)
  q=max(y)
  if p>=q: print(c)
  else: print(c//p*q+c%p)

# cf 1150 A 900
n, m, r = map(int, input().split())
B = [*map(int, input().split())]
S = [*map(int, input().split())]

B.sort()
S.sort(reverse=True)

org, p = r, 0
for i in range(min(len(B), len(S))):
    if S[i] > B[i]:
        while r >= B[i]:
            p += S[i] - B[i]
            r -= B[i]

print(org + p)

n, m, r = map(int, input().split())
count = 0
sp = min(list(map(int, input().split())))
w = max(list(map(int, input().split())))
print(max(r, r // sp * w + r % sp))

from sys import stdin
from collections import defaultdict as dd
import math
def Main():
    n,m,r=map(int,stdin.readline().split())
    s=list(map(int,stdin.readline().split()))
    b=list(map(int,stdin.readline().split()))
    if min(s)>=max(b):
        print(r)
    else:
        a=r//min(s)
        print(r+(max(b)-min(s))*a)
if __name__=="__main__":
    Main()

n, m, r = map(int, input().split())
best_buy = min(map(int, input().split()))
best_sell = max(map(int, input().split()))
print(r + max(0, r // best_buy * (best_sell - best_buy)))

N, M, R = map(int, input().split())

b = min(map(int, input().split()))
s = max(map(int, input().split()))

a = R % b + R // b * s

print(max(R, a))

n, m, r = map(int, input().split())
k = r
s = list(map(int, input().split()))
b = list(map(int, input().split()))
r = (r // min(s)) * max(b) + (r - (r // min(s)) * min(s))
if k >= r:
	print(k)
else:
	print(r)

n, m, r = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort(reverse = True)
if a[0] >= b[0]:
    print(r)
    exit()
q = r // a[0]
r -= q * a[0]
r += q * b[0]
print(r)

n,m,r=map(int,input().split())
S=list(map(int,input().split()))
B=list(map(int,input().split()))
mini=min(S)
maxi=max(B)
if mini>=maxi:
	print(r)
else:
	b=r//mini
	r+=(maxi-mini)*b
	print(r)

n,m,r=[int(i) for i in input().split()]
s=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
smin=min(s)
bmax=max(b)
nsb=r//smin
rp=r-(nsb*smin)
if (rp+nsb*bmax)>r:
    print(rp+nsb*bmax)
else:
    print(r)

n,m,r=[int(x) for x in input().split()]
s=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
#print(s)
#print(b)
min=s[0]
max=b[0]
for x in range(1,n):
    if (s[x]<min):
        min=s[x]
for x in range(1,m):
    if(b[x]>max):
        max=b[x]
#print(min)
#print(max)
k=int(r/min)
total=r-(k*min)+(k*max)
if(total>r):
    print(total)
else:
    print(r)

n,m,r=map(int,input().split())
s=list(map(int,input().split()))
b=list(map(int,input().split()))
MIN=min(s)
MAX=max(b)
print (max(r,(r%MIN+MAX*(r//MIN))))

# your code goes here
n,m,r=map(int,input().split())
s=list(map(int,input().split()))
b=list(map(int,input().split()))
s.sort()
b.sort()
if(s[0]>=b[m-1]):
	print(r)
else:
		print((r//s[0])*b[m-1]+r%s[0])

import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,m,r=LI()
  l1=LI()
  l2=LI()

  l1.sort()
  l2.sort()

  x=r//l1[0]
  _r=r-x*l1[0]

  y=x*l2[-1]

  return max(r,_r+y)

# main()
print(main())

def myfunc(l1):
    return l1[-1]
def solution(l1,l2,l3):
    n,m,r = l1[0],l1[1],l1[2]
    l2.sort()
    l3.sort()
    l3.reverse()
    i=0
    ans=r
    while r>=0 and i<len(l2) and l3[0]-l2[i]>0:
        if r>=l2[i]:
            r-=l2[i]
            ans+=l3[0]-l2[i]
        else:
            i+=1
    return ans

def answer():
    l1 = [int(x) for x in input().split()]
    l2 = [int(x) for x in input().split()]
    l3 = [int(x) for x in input().split()]
    print(solution(l1,l2,l3))
answer()

n,m,r = map(int,input().split())
s = [*map(int,input().split())]
p = [*map(int,input().split())]
mm=min(s)
yy=max(p)
qq=r//mm
print(max(qq*yy+(r%mm),r))

a,b,c=map(int, input().split())
d=list(map(int, input().split()))
e=list(map(int, input().split()))
g=min(d)
h=max(e)
x=c-((c//g)*g)
if h>g:
  print(x+(c//g)*h)
else:
  print(c)

nmr = list(map(int, input().split()))
s = list(map(int, input().split()))
b = list(map(int, input().split()))
stocks = 0
minS = 1001
maxB = 0
for k in range(nmr[0]):
	minS = min(minS, s[k])
for k in range(nmr[1]):
	maxB = max(maxB, b[k])
if minS < maxB:
	stocks = (nmr[2] // minS)
	nmr[2] -= (stocks * minS)
	nmr[2] += (stocks * maxB)
print(nmr[2])

def strtoint(n,list):
 for i in range(n):
  list[i]=int(list[i])

n=input().split()
strtoint(3,n)
buin=input().split()
strtoint(n[0],buin)
buout=input().split()
strtoint(n[1],buout)

buin.sort()
buout.sort(reverse=True)

if buin[0]>buout[0]:
 print(n[2])
 exit(0)
else:
 print(n[2]+int(n[2]/buin[0])*(buout[0]-buin[0]))

line_one=list(map(int,input().split()))
line_two=list(map(int,input().split()))
line_three=list(map(int,input().split()))
r=line_one[2]

min_buy_price=min(line_two)
max_sell_price=max(line_three)

if(max_sell_price>min_buy_price):
    exchange=r%min_buy_price
    price=int(r/min_buy_price)*(max_sell_price)
    print(exchange+price)

else:
    print(r)

n,m,r=map(int,input().split())
b=list(map(int,input().split()))
s=list(map(int,input().split()))
count=0
r1=r
count+=int(r/min(b))
r1-=count*min(b)
r1+=max(s)*count

print(max(r,r1))

# bsdk idhar kya dekhne ko aaya hai, khud kr!!!
# import math
# from itertools import *
# import random
# import calendar
# import datetime
# import webbrowser

n, m, r = map(int, input().split())
buy = list(map(int, input().split()))
sell = list(map(int, input().split()))
originl_money = r
buy.sort()
sell.sort()
temp = r // buy[0]
r -= (temp * buy[0])
r += (temp * sell[-1])
if originl_money <= r:
    print(r)
else:
    print(originl_money)

func=lambda:map(int,input().split())
n,m,r=func()
min1 = min(func())
max1 = max(func())
s = r + max(0, r//min1 * max1  + r%min1 - r)
print(s)

n, m, r = map(int, input().split())
b=list(map(int,input().split()))
c=list(map(int,input().split()))
sum2=0
sum1=0
s=0
k=0
val=0
ans=0
j=0
div=0
j=max(n,m)
s=min(b)
k=max(c)
if s<=k:
    div=r//s
    val=k-s
    ans=r+(div*val)
    print(ans)
else:
    print(r)

import sys
# sys.stdin = open('input.txt','r')
n,m,r = map(int, input().split())
s = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
s[0] = min(s)
b[-1] = max(b)
if b[-1] > s[0]:
	print(r - (r//s[0])*s[0] + b[-1] * (r//s[0]))
else:
	print(r)

#!/usr/bin/python
# -*- coding: utf-8 -*-

if __name__ == "__main__":
    n, m, r = map(int, input().split())
    x  = min(map(int, input().split()))
    y  = max(map(int, input().split()))
    if (x>=y):
        print(r)
    else:
        print( (r//x)*y + r % x)

#!/usr/bin/env python

from sys import stdin, stderr

def solve(N, M, R, S, B):
   mn = min(S)
   mx = max(B)
   if mn >= mx:
      return R
   shares = R / mn
   return R - shares * mn + shares * mx

def main():
   N, M, R = map(int, stdin.readline().split())
   S = map(int, stdin.readline().split())
   B = map(int, stdin.readline().split())
   res = solve(N, M, R, S, B)
   print(res)

   return 0

if __name__ == '__main__': main()

n,m ,r  = raw_input().split(" ")
n,m,r = [int(n), int(m), int(r)]
morn = raw_input().split(" ")
night = raw_input().split(" ")

morn = [int(k) for k in morn]
night = [int(k) for k in night]

cp = min(morn)
sp = max(night)

if (sp<=cp):
	print(r)
else:
	can_buy = int(r/cp)
	tot = can_buy * (sp - cp)
	r += tot
	print(r)

n , m , r = [int(i) for i in raw_input().split()]
a = [int(i) for i in raw_input().split()]
b = [int(i) for i in raw_input().split()]
a = sorted(a)
b = sorted(b, reverse=True)
ans = r
if a[0] < b[0]:
    ans = r % a[0] + r / a[0] * b[0]

print ans

n, m, r = [int(t) for t in input().split(' ')]
s = [int(t) for t in input().split(' ')]
b = [int(t) for t in input().split(' ')]
print(max(r % min(s) + max(b) * (r // min(s)), r))

n, m, r = map(int, raw_input().split(' '))

s = list(map(int, raw_input().split(' ')))
b = list(map(int, raw_input().split(' ')))

res = max(r, (r / min(s)) * max(b) + (r % min(s)))

print res

n,m,r = [int(nmr) for nmr in raw_input().split(" ")]
s = [int(si) for si in raw_input().split(" ")]
b = [int(bi) for bi in raw_input().split(" ")]
print max(r, ( ( (r/min(s)) * max(b) ) + (r%min(s)) ) )

a,b,c = map(int, raw_input().split())
x = min(map(int, raw_input().split()))
y = max(map(int, raw_input().split()))
ans = c%x+max(c-(c%x), c/x*y)
print ans

n, m, r = map(int, raw_input().split())
s = map(int, raw_input().split())
b = map(int, raw_input().split())

buy_price = min(s)
sell_price = max(b)
shares = r // buy_price

print max(0, (sell_price - buy_price) * shares) + r

n, m, r = map(int,input().split())
buy_shares = list(map(int,input().split()))
sell_shares = list(map(int,input().split()))
a = r//min(buy_shares)
buy = min(buy_shares)*a
if max(sell_shares) > min(buy_shares):
	print(a*max(sell_shares)+r%min(buy_shares))
else:
	print(r)

n, m, r = map(int, input().split())
a = min(map(int, input().split()))
b = max(map(int, input().split()))
print(max(r%a + (r//a)*b, r))

n, m, r = map(int, raw_input().split())
l1 = map(int, raw_input().split())
l2 = map(int, raw_input().split())
a1 = min(l1)
a2 = max(l2)
profit = (r / a1) * a2 - (r / a1) * a1
profit = max(profit, 0)
print profit + r

n,m,r=map(int,input().split())
s=list(map(int,input().split()))
b=list(map(int,input().split()))
m1=min(s)
m2=max(b)
if m1<m2:
    u=r//m1
    r=r-u*m1
    p=u*m2
    r=r+p
    print(r)
else:
    print(r)

n, m, r = map(int, input().split())
s = sorted(list(map(int, input().split())))
b = max(list(map(int, input().split())))
money = r
i = 0
a = 0
while i < n and r // s[i] > 0:
    a += r // s[i]
    r -= s[i] * (r // s[i])
    i += 1
print(max(money, r + a * b))

n, m, r = map(int, input().split())
s = map(int, input().split())
b = map(int, input().split())

s_min = min (s)
b_max = max (b)

if s_min > b_max or r < s_min:
   print(r)
else:
   h = r - r // s_min * s_min
   print(r // s_min * b_max + h)

n, m, r = map(int, input().split())
lst1 = list(map(int, input().split()))
lst2 = list(map(int, input().split()))

"""
for i in lst1:
	print (i, end = " ")
for i in lst2:
	print(i, end = " ")
"""

x = min(lst1)
y = max(lst2)

sold = r // x * y
how = r - r // x * x
print(max(r, sold + how))

n, m, r = tuple(map(int, input().split()))
m1 = list(map(int, input().split()))
m2 = list(map(int, input().split()))

min1 = min(m1)
max1 = max(m2)

if min1 < max1:
    print(r // min1 * max1 + r % min1)
else:
    print(r)

#!/usr/bin/python

int_input = lambda: [int(i) for i in raw_input().split()]

n, m, r = int_input()
a = min(int_input())
b = max(int_input())

print max(r, r % a + r / a * b)

n, m, r = map(int, raw_input().split())
s = map(int, raw_input().split())
b = map(int, raw_input().split())
x = min(s)
y = max(b)
if x >= y:
    print r
else:
    z = r / x
    r -= z * x
    print r + z * y

n, m, r = map(int, input().split())
b = min(map(int, input().split()))
print(r //  b * max(b, *map(int, input().split())) + r % b)

def mai():
    a,b,c=input().split()
    n=int(a)
    m=int(b)
    tk=int(c)
    share=0
    s_price=[0 for i in range(m)]
    b_price=[0 for i in range(n)]

    a=input().split()
    for i in range(n):
        b_price[i]=int(a[i])
    a=input().split()
    for j in range(m):
        s_price[j]=int(a[j])

    s_price.sort(reverse=True)
    b_price.sort()

    if s_price[0] < b_price[0]:
        print(tk)
        return
    else:
        share=int(tk/b_price[0])
        b=tk % b_price[0]
        tk=tk-(share*b_price[0])

    s=share*s_price[0]
    print(tk+s)

mai()

n,m,r=map(int,input().split())
buy=list(map(int,input().split()))
sell=list(map(int,input().split()))
x=(r//min(buy))
left=r-(x*(min(buy)))
y=max(sell)*x
if (y+left)>r:
	print(y+left)
else:
	print(r)

import sys

input = sys.stdin.readline

n,m,r = list(map(int, input().split()))
morning = list(map(int, input().split()))
evening = list(map(int, input().split()))

tmp = 0
min_ = min(morning)

tmp = r//min_
tmp2 = r%min_
print(max(r, (tmp*max(evening)) + tmp2))

n,m,r = [int(i) for i in input().split()]
pok = [int(i) for i in input().split()]
pr = [int(i) for i in input().split()]
pk_m = min(pok)
p_m = max(pr)
ck = r+1
c =r //pk_m
r = r%pk_m
for j in range(c):
    r+=p_m
print(max(ck-1,r))

I = lambda: int(input())
IL = lambda: list(map(int, input().split()))

n, m, r = IL()
S = IL()
B = IL()

print(r // min(S) * max(*B, min(S)) + (r % min(S)))

n, m, r = map(int, input().split())
gm = list(map(int, input().split()))
gn = list(map(int, input().split()))
mn = min(gm)
s = r // mn
c = r % mn
rez = c + max(gn) * s
if min(gm) > max(gn):
    print(r)
else:
    print(rez)

n,m,r=map(int,input().split())
a1=list(map(int,input().split()))
a2=list(map(int,input().split()))
b1=min(a1)
b2=max(a2)
print(max(r,r%b1+r//b1*b2))

n, m, r = map(int, input().split())
s = map(int, input().split())
b = map(int, input().split())

s_min = min (s)
b_max = max (b)

if s_min >= b_max or r < s_min:
   print(r)
else:
   h = r - r // s_min * s_min
   print(r // s_min * b_max + h)

a = list(map(int,input().split()))
b = sorted(list(map(int,input().split())))
c = sorted(list(map(int,input().split())),reverse=True)
money = a[2]
gain = 0
for i in range(min(a[0],a[1])):
    if c[i]-b[i] > 0:
        stocks = money//b[0]
        money -= stocks*b[0]
        gain += (c[0])*stocks
print(money+gain)

n, m, r = map(int, input().split())

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

pri_min = min(l)

qut = r // pri_min
rem = r % pri_min
z = max(k)
#print(f"{pri_min} {qut} {rem} {z}")

if (z * qut)+rem >= r:
    print(z * qut+ rem)

else:
    print(r)

a=input().split()
b=input().split()
s=input().split()
maanie=int(a[2])
buy=1000
sell=1
for i in range(len(b)):
    if buy>int(b[i]):
        buy=int(b[i])
for i in range(len(s)):
    if sell<int(s[i]):
        sell=int(s[i])

if (buy<sell):
        maanie+=maanie//buy*(sell-buy)
print(maanie)

n, m, r= map(int, input().split())
s_ = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
#n ,m , r = 5, 6, 8
#s_ = [7, 7, 10, 5, 5]
#b= [5, 6, 2, 8, 1, 8]

s = []
for x in s_:
    if x not in s:
        s.append(x)
n = len(s)

if min(s)>=max(b):
    print(r)
else:
    quantity =[]
    balance = []
    for i in range (n):
        quantity.append(r//s[i])
        balance.append(r%s[i])
    best_quantity =max(quantity)
    best_balance = -1
    #print(balance)
    op = quantity.count(best_quantity)
    #print(op)
    for q in range (op):
        #print(balance[quantity.index(best_quantity)])
        if best_balance < balance[quantity.index(best_quantity)]:
            best_balance = balance[quantity.index(best_quantity)]
            #del quantity[quantity.index(best_quantity)]
            quantity[quantity.index(best_quantity)] = 0
            #quantity.insert(quantity.index(best_quantity), 0)
            #print(quantity)
        #print (best_balance)
    print(best_quantity*max(b)+best_balance)

[n, m, r] = list(map(int, input().split(" ")))
s = list(map(int, input().split(" ")))
b = list(map(int, input().split(" ")))

n = r % min(s) + (r // min(s))*max(b)
print(max(r, n))

buy_times, sell_times, cash = list(map(int, input().split()))
b = list(map(int, input().split()))
s = list(map(int, input().split()))

if min(b) >= max(s):
    print (cash)

else:
    top_stocks = cash // min(b)
    profit = top_stocks * max(s)
    if cash % 2 != 0:
        profit += 1
        print( profit)

from sys import stdin,stdout
i = lambda : map(int,stdin.readline().split())
p = lambda x: stdout.write(str(x)+" ")
pa = lambda list: stdout.write(" ".join(str(x) for x in list))

n,m,r = i()
b = i()
s = i()
buy = min(b)
sell = max(b)
if buy<sell:
	print sell*(r/buy) + r%buy
else:
	print r

n,m,r=map(int,input().split())
s=list(map(int,input().split()))
b=list(map(int,input().split()))
c=s[0]
for i in range(1,n):
    if (r//c)<(r//s[i]):
        c=s[i]

p=r//c
x=r%c
if c>min(b):
    print(r)
else:
    q=max(b)*p
    print(x+q)
    print(q,c,max(b))

n,m,r=map(int,input().split())
n1=list(map(int,input().split()))
m1=list(map(int,input().split()))
money=r
d=r
if n == 1:
    n2 = n1[0]
else:
    n2 = min(n1)
if m == 1:
    m2 = m1[0]
else :
    m2 = max(m1)

while n2<m2:
    if d>n2:
        d= d%n2
        c=(r-(r%n2))/n2
        money = money + (m2-n2)*c
        n1.pop(n1.index(n2))
    elif d!=0 and d > n2 and n2<m2:
        d= d%n2
        c=(r-(r%n2))/n2
        money = money + (m2-n2)*c
        n1.pop(n1.index(n2))
    else:
        break
print(int(money))

n, m, r = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
mx = 0
ans = 0
for x in a:
	ans = max(ans, r // x * max(b) + r % x)
print(ans)

a,b,c=[int(x) for x in input().split()]
a1 = list(map(int,input().strip().split()))[:a]
b1 = list(map(int,input().strip().split()))[:b]
c1=max(a1)
c2=min(a1)
c3=max(b1)
s=c1*c2
k=c3*c3
z=0
if(s<=k):
    z = c + k-s
else:
    z=c+0;
print(z)

valores = input()
valores = valores.split(' ')
r = int(valores[-1])

n = input()
n = n.split(' ')
for i in range(len(n)):
    n[i] = int(n[i])

m = input()
m = m.split(' ')
for i in range(len(m)):
    m[i] = int(m[i])

if min(n) > max(m):
	print(r)
elif min(n) < max(m):
	print(r-((r//min(n))*min(n))+((r//min(n))*(max(m))))

def solve():
    n,m,r = map(int, input().split())
    s = [int(k) for k in input().split()]
    b = [int(k) for k in input().split()]

    s.sort()
    b.sort()

    print (max((r//s[0]) * b[-1], r))

if __name__ == "__main__":
    solve()

n, m, r = [int(t) for t in input().split(' ')]
s = [int(t) for t in input().split(' ')]
b = [int(t) for t in input().split(' ')]
print(r % min(s) + max(b) * (r // min(s)))

n,m,r=map(int,input().split())
arr=list(map(int,input().split()))
arrb=list(map(int,input().split()))
arr.sort()
arrb.sort()
if(arr[0]>=arrb[m-1]):
    print(r)
else:
    buy=r//arr[0]
    r=r-(buy*arr[0])
    print(r)
    r=r+(buy*(arrb[m-1]))
    print(r)

n,m,r=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split() ))
x=min(a)
y=max(b)
if(x>=y):
    print(r)
else:
    print((r//x)*y)

n,m,r = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input(). split()))
u = min(a)
v = max(a)
if(v > u):
    s = r//u
    r = r%u
    r += s*v
print(r)

n,m,r=map(int,input().split())
s=min(map(int,input().split()))
b=max(map(int,input().split()))
print(b*(r//s)+r%s)

n, m, r = map(int, raw_input().split())
a = min(map(int, raw_input().split()))
b = max(map(int, raw_input().split()))
print r/a * b

def share():
    n, m, r = [int(x) for x in input().split()]
    s = []
    b = []
    for i in input().split():
        s.append(int(i))
    for i in input().split():
        b.append(int(i))
    s = min(s)
    b = max(b)
    ac = r // s
    rr = r % s
    result = ac * b + rr
    return print( max(result, r))

from sys import stdin,stdout
i = lambda : map(int,stdin.readline().split())
p = lambda x: stdout.write(str(x)+" ")
pa = lambda list: stdout.write(" ".join(str(x) for x in list))

n,m,r = i()
b = i()
s = i()
buy = min(b)
sell = max(b)
print sell*(r/buy) + r%buy

n, m, r = map(int, input().split())
s = [int(c) for c in input() if c != ' ']
b = [int(c) for c in input() if c != ' ']

if min (s) > max(b):
    print(r)
h = r - r // min(s) * min(s)
print(r // min(s) * max(b) + h)

n1,n2,k = map(int, input().split())
m = map(int, input().split())
e = map(int, input().split())
mi = min(m)
ma = max(e)
n = k//mi
left = k%mi
print((ma-mi)*n  + left)

import sys

inp = sys.stdin.readlines()
a,b,c=inp[0].split()
mi=min(int(x) for x in inp[1].split())
ma=max(int(x) for x in inp[2].split())
x=int(int(c)/mi)
rem=int(c)-x*mi
print(int(rem+x*ma))

n, m, r = map(int, input().split())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
a = min(l1)
b = max(l2)
if a < b:
    q = r // min(l1)
    w = q * b
    print((r - a * q) + w)
elif a > b:
    print(r)

n,m,r=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
mn=min(a)
mx=max(b)
t=r//mn
r=r%mn
r=r+t*mx
print(r)

import math
import heapq

n, m, r= map(int, input().split())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))

s = r//a[0]
r-=s*a[0]
print(r+s*b[-1])

m = list(map(int, input().split()))
b=list(map(int, input().split()))
s=list(map(int, input().split()))

money = m[-1]
min_price = min(b)
max_price = max(s)
money_left = 0

if money >= min_price:
    for i in range(money) :
        if money % min_price == 0:
           shares = int(money/min_price)
           break
        else:
            money -= 1
            money_left +=1

    profit = ((shares*max_price)+ money_left)
    if profit > m[-1]:
        print(profit)
    else:
        print(m[-1])

def solve():
    n,m,r = map(int, input().split())
    s = [int(k) for k in input().split()]
    b = [int(k) for k in input().split()]

    s.sort()
    b.sort()

    print (max((r//s[0]) * b[-1], r))

if __name__ == "__main__":
    solve()

a,b,c=[int(x) for x in input().split()]
a1 = list(map(int,input().strip().split()))[:a]
b1 = list(map(int,input().strip().split()))[:b]
c1=max(a1)
c2=min(a1)
c3=max(b1)
s=c1*c2
k=c3*c3
z=0
if(s<=k):
    z = c + k-s
else:
    z=c+0;
print(z)

def main():
    s = [int(x) for x in input().split()]
    r = s[2]
    buy = min([int(x) for x in input().split()])
    sell = max([int(x) for x in input().split()])
    morning = r // buy
    evening = morning * sell
    if evening >= r:
        ans = evening + r % buy
        print(ans)
    else:
        print(r)

main()

datos =input()
d = datos.split()

n = int(d[0])
m= int(d[1])
r = int(d[2])

s = input()
s1 = s.split()
sf = sorted(s1)

b = input()
b1 = b.split()
bf = sorted(b1)

C = int(sf[0])  #Valor Menor Compra
V = int(bf[-1]) #Valor Mayor Venta

if C < V:
    I = r// C
    Rinv = r - (C*I)
    G = I*V
    rf = G + Rinv
    print(rf)

else:
    print(r)

nmr=list(int(num) for num in input().split())
n=list(map(int,input().split()))
m=list(int(num) for num in input().split())
minimum_of_buying=min(n)
maximum_of_selling=max(m)
if(minimum_of_buying>maximum_of_selling):
	print(nmr[2])
else:
	if(len(m)==1):
		a=maximum_of_selling
	else:
		a=5
	print(nmr[2]+(a*maximum_of_selling)-(minimum_of_buying*a))

m,n,r=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
d=r//min(a)
if r<=d*(max(b)):
	print(d*(max(b))+r%d)
else:
	print(r)

n = input().split()
r = int(n[2])

a = input().split()
b = input().split()

mn = 1000000000000
mx = -1

for i in a:
    mn = min(mn,int(i))

d  = r %mn
r //= mn

for i in b:
    mx = max(mx,int(i))

print(mx * r + d)

n, m, r = map(int, input().split())
n_s = min(list(map(int, input().split())))
m_s = max(list(map(int, input().split())))
print((r % n_s) + m_s * r // n_s)

n,m,k = input().split(' ')
n = int(n)
m = int(m)
k = int(k)
a = list(map(int,input().split(' ')))
b = list(map(int,input().split(' ')))

aa = min(a)
bb = max(b)

cnt = k // aa
r = k % aa
#print(cnt,bb)
buy = cnt * bb

if buy > k-r:
  print((bb * cnt) + r)
else:
  print(0)

n,m,b = map(int,input().split())
l = list(map(int,input().split()))
h = list(map(int,input().split()))
print(b-min(l)*(b//min(l))+max(h)*(b//(min(l))))

n,m,b=map(int,input().split())

p=list(map(int,input().split()))
s=list(map(int,input().split()))

k=min(p)
k1=b//k
d=k1*k
if(b>d):
   r=b-d
else:
   r=0
z=max(s)
z=k1*z

if(b>=z):
   print(b)
else:
   print(z+r)

a,b,c = map(int, raw_input().split())
x = min(map(int, raw_input().split()))
y = min(map(int, raw_input().split()))
ans = c%x+max(c-(c%x), c/x*y)
print ans

money = int(input().split()[-1])
best_price = min(map(int, input().split()))
best_sell = max(map(int, input().split()))

actions = money // best_price
remaining = money % best_price

result = actions * best_sell + remaining
print(result)

n, m, r= map(int, input().split())
s = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
#n ,m , r = 2, 1, 10
#s = [5,4]
#b= [100]

if min(s)>=max(b):
    print(r)
else:
    quantity =[]
    balance = []
    for i in range (n):
        quantity.append(r//s[i])
        balance.append(r%s[i])
    best_quantity =max(quantity)
    best_balance = -1
    #print(balance)
    op = quantity.count(best_quantity)
    #print(op)
    for q in range (op):
        #print(balance[quantity.index(best_quantity)])
        if best_balance < balance[quantity.index(best_quantity)]:
            best_balance = balance[quantity.index(best_quantity)]
            #del quantity[quantity.index(best_quantity)]
            quantity.insert(quantity.index(best_quantity), 0)
            #print(quantity)
        #print (best_balance)
    print(best_quantity*max(b)+best_balance)

n1,n2,k = map(int, input().split())
m = map(int, input().split())
e = map(int, input().split())
mi = min(m)
ma = max(e)
n = k//mi
left = k%mi
print((ma-mi)*n  + left)

n,m,k = input().split(' ')
n = int(n)
m = int(m)
k = int(k)
a = list(map(int,input().split(' ')))
b = list(map(int,input().split(' ')))

aa = min(a)
bb = max(b)

cnt = k // aa
r = k % aa
#print(cnt,bb)
buy = cnt * bb

if buy > k-r:
  print((bb * cnt) + r)
else:
  print(r)

n,m,k = input().split(' ')
n = int(n)
m = int(m)
k = int(k)
a = list(map(int,input().split(' ')))
b = list(map(int,input().split(' ')))

aa = min(a)
bb = max(b)

cnt = k // aa
r = k % aa
#print(cnt,bb)
buy = cnt * bb

if buy > k:
  print((bb * cnt) + r)
else:
  print(cnt * aa)

nmr=list(int(num) for num in input().split())
n=list(map(int,input().split()))
m=list(int(num) for num in input().split())
minimum_of_buying=min(n)
maximum_of_selling=max(m)
if(minimum_of_buying>maximum_of_selling):
	print(nmr[2])
else:
	print(nmr[2]+(maximum_of_selling*maximum_of_selling)-(maximum_of_selling*minimum_of_buying))

d1=(input("AAA"))
d2=(input("AAA"))
d3=(input("AAA"))

L1=d1.split()
L2=d2.split()
L3=d3.split()
for i in L1:
	i=int(i)
for i in L2:
	i=int(i)
for i in L3:
	i=int(i)
n=L1[2]
if min(L2)>=max(L3):
	print(n)
else:
	a=(int(n)//int(min(L2)))*int(max(L3))+int(n)%int(min(L2))
	print(a)

def myfunc(l1):
    return l1[-1]
def solution(l1,l2,l3):
    n,m,r = l1[0],l1[1],l1[2]
    l2.sort()
    l3.sort()
    l3.reverse()
    i=0
    ans=r
    while r>0 and i<len(l2) and l3[0]-l2[i]>0:
        if r>l2[i]:
            r-=l2[i]
            ans+=l3[0]-l2[i]
        else:
            i+=1
    return ans

def answer():
    l1 = [int(x) for x in input().split()]
    l2 = [int(x) for x in input().split()]
    l3 = [int(x) for x in input().split()]
    print(solution(l1,l2,l3))
answer()

func=lambda:map(int,input().split())
n,m,r=func()
min1 = min(func())
max1 = max(func())
s = r//min1 * max1 + r%min1
print(s)

n,m,r = [int(i) for i in input().split()]
pok = [int(i) for i in input().split()]
pr = [int(i) for i in input().split()]
pk_m = min(pok)
p_m = max(pr)
c = r+1
c =r //pk_m
r = r%pk_m
for j in range(c):
    r+=p_m
print(max(c-1,r))

m = list(map(int, input().split()))
b=list(map(int, input().split()))
s=list(map(int, input().split()))

money = m[-1]
min_price = min(b)
max_price = max(s)
money_left = 0
for i in range(money):
    if money % min_price == 0:
       shares = int(money/min_price)
       break
    else:
        money -= 1
        money_left +=1

profit = ((shares*max_price)+ money_left)
if profit > money:
    print(profit)
else:
    print(money)

buy_times, sell_times, cash = list(map(int, input().split()))
b = list(map(int, input().split()))
s = list(map(int, input().split()))

if min(b) >= max(s):
    print (cash)

else:
    top_stocks = cash // min(b)
    profit = 5 * max(s)
    if cash % 2 != 0:
        profit += 1
        print( profit)

n, m, r= map(int, input().split())
s = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
#n ,m , r = 3, 4, 11
#s = [4, 2, 5]
#b= [4, 4, 5, 4]

if min(s)>=max(b):
    print(r)
else:
    quantity =[]
    balance = []
    for i in range (n):
        quantity.append(r//s[i])
        balance.append(r%s[i])
    best_quantity =max(quantity)
    best_balance = 0
    for q in range (quantity.count(best_quantity)):
        if best_balance < balance[quantity.index(best_quantity)]:
            best_balance = balance[quantity.index(best_quantity)]
            quantity.insert(quantity.index(best_quantity), 0)
    print(best_quantity*max(b)+best_balance)

N, M, R = map(int, input().split())

b = min(map(int, input().split()))
s = max(map(int, input().split()))

a = R % b + R // b * s

print(a,0)

n, m, r = [int(t) for t in input().split(' ')]
s = [int(t) for t in input().split(' ')]
b = [int(t) for t in input().split(' ')]
print(r % min(s) + max(b) * (r // min(s)))

def main():
    n=input()
    print(sum(int(x) for x in n.split()))

if __name__ == "__main__":
    main()

n,m,r = map(int,input().split())
ai = list(map(int,input().split()))
bi = list(map(int,input().split()))
if min(ai) >= max(bi):
    print(r)
else:
    a = r//min(ai)
    print(a*max(bi) + 1)

m,n,r=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
d=r//min(a)
if r<=d*(max(b)):
	print(d*(max(b))+r%d)
else:
	print(r)

n, m, r = (int(x) for x in input().split())
s = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

money = r % min(s)
num_stocks = int(r / min(s))

money_made = max(b) * num_stocks
money += money_made
print(money)

n,m,r=map(int,input().split())
s=list(map(int,input().split()))
b=list(map(int,input().split()))
c=s[0]
for i in range(1,n):
    if (r//c)<(r//s[i]):
        c=s[i]

p=r//c
x=r%c
if c>min(b):
    print(r)
else:
    q=max(b)*p
    print(x+q)

s = input().split()
n, m, r = int(s[0]), int(s[1]), int(s[2])
b = list(map(int, input().split()))
s = list(map(int, input().split()))
b_min = min(b)
s_max = max(s)
if b_min < s_max:
    print((r // b_min) * s_max)
else:
    print(r)

a,b,c=[int(x) for x in input().split()]
a1 = list(map(int,input().strip().split()))[:a]
b1 = list(map(int,input().strip().split()))[:b]
c1=max(a1)
c2=min(a1)
c3=max(b1)
s=c1*c2
k=c3*c3
z=0
if(s<=k):
    z = c + k-s
else:
    z=c+0;
print(z)

d1=(input("AAA"))
d2=(input("AAA"))
d3=(input("AAA"))

L1=d1.split()
L2=d2.split()
L3=d3.split()
for i in L1:
	i=int(i)
for i in L2:
	i=int(i)
for i in L3:
	i=int(i)
n=L1[2]
def aaa(n,L2,L3):
	if min(L2)>=max(L3):
		print(int(n))
		return n
	else:
		a=(int(n)//int(min(L2)))*int(max(L3))+int(n)%int(min(L2))
		print(int(a))
	return a

n, m, r = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
mx = 0
ans = 0
for x in a:
	ans = max(ans, r // x * max(b) + r % x)
print(ans)

nmr=list(int(num) for num in input().split())
n=list(map(int,input().split()))
m=list(int(num) for num in input().split())
minimum_of_buying=min(n)
maximum_of_selling=max(m)
if(minimum_of_buying>maximum_of_selling):
	print(nmr[2])
else:
	print(nmr[2]+(5*maximum_of_selling)-(5*minimum_of_buying))

n,m,k = input().split(' ')
n = int(n)
m = int(m)
k = int(k)
a = list(map(int,input().split(' ')))
b = list(map(int,input().split(' ')))

aa = min(a)
bb = max(b)

cnt = k // aa
r = k % aa
print(cnt,bb)
buy = cnt * bb

if buy > k-r:
  print((bb * cnt) + r)
else:
  print(r)

n, m, r = map(int,input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
if a[0] < b[m-1]:
  if a[0] > r:
    print('0')
  else:
    rr = r//a[0]
    rro = r%a[0]
    rr = rr * b[m-1]
    print(rr+rro)
else:
  print(r)

n,m,r = map(int,input().split(' '))
s1 =list( map(int,input().split(' ')))
s2 =list( map(int,input().split(' ')))
if(max(s2)>=max(s1)):
    min_s = min(s1)
    q = r//min_s
    r = r-min_s*q
    r += max(s2)*q
    print(r)
else:
    print(r)

N, M, R = map(int, input().split())

b = min(map(int, input().split()))
s = max(map(int, input().split()))

a = R % b + R // b * s

print(a,0)

d1=(input(""))
d2=(input(""))
d3=(input(""))

L1=d1.split()
L2=d2.split()
L3=d3.split()
for i in L1:
	i=int(i)
for i in L2:
	i=int(i)
for i in L3:
	i=int(i)
n=L1[2]

if min(L2)>=max(L3):
		print(int(n))

else:
		a=(int(n)//int(min(L2)))*int(max(L3))+int(n)%int(min(L2))
		print(int(a))

n1,n2,k = map(int, input().split())
m = map(int, input().split())
e = map(int, input().split())
mi = min(m)
ma = max(e)
n = k//mi
left = k%mi
print((ma-mi)*n  + left)

def main():
    n=input()
    print(sum(int(x) for x in n.split()))

if __name__ == "__main__":
    main()

[n, m, r] = list(map(int, input().split(" ")))
s = list(map(int, input().split(" ")))
b = list(map(int, input().split(" ")))

r = r % min(s) + (r // min(s))*max(b)
print(r)

def share():
    n, m, r = [int(x) for x in input().split()]
    s = []
    b = []
    for i in input().split():
        s.append(int(i))
    for i in input().split():
        b.append(int(i))
    s = min(s)
    b = max(b)
    ac = r // s
    rr = r % s
    result = ac * b + rr
    res = max(result, r)
    return print(res)

morning, evening, roubles=map(int, input().split())
buy=list(map(int, input().split()))
sell=list(map(int, input().split()))

mb=min(buy);b=roubles//mb
ms=max(sell);s=b*ms

if s>roubles:
	print(s+(roubles-(mb*b)))
else:
	print(roubles)

s = input().split()
n, m, r = int(s[0]), int(s[1]), int(s[2])
b = list(map(int, input().split()))
s = list(map(int, input().split()))
b_min = min(b)
s_max = max(s)
if b_min < s_max:
    print((r // b_min) * s_max)
else:
    print(r)

nmr=list(int(num) for num in input().split())
n=list(map(int,input().split()))
m=list(int(num) for num in input().split())
minimum_of_buying=min(n)
maximum_of_selling=max(m)
print(nmr[2])
print(minimum_of_buying)
print(maximum_of_selling)
if(minimum_of_buying>maximum_of_selling):
	print(nmr[2])
else:
	y=int(nmr[2]/minimum_of_buying)
	print(y)
	print(nmr[2]-(minimum_of_buying*y)+(maximum_of_selling*y))

n,m,r=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split() ))
x=min(a)
y=max(b)
if(x>=y):
    print(r)
else:
    print((r//x)*y)

a=input().split()
b=input().split()
s=input().split()
maanie=int(a[2])
buy=int(min(b))
sell=int(max(s))
if buy<sell:
    maanie+=maanie//buy*(sell-buy)
print(maanie)

n,m,r=map(int,input().split())
buy=list(map(int,input().split()))
sell=list(map(int,input().split()))
x=(r//min(buy))
left=r-(x*(min(buy)))
y=max(sell)*x
if y>r:
	print(y+left)
else:
	print(r)

n,m,r=map(int,input().split())
arr=list(map(int,input().split()))
arrb=list(map(int,input().split()))
arr.sort()
arrb.sort()
if(arr[0]>=arrb[m-1]):
    print(arr[0])
else:
    buy=r//arr[0]
    r=r-(buy*arr[0])
    r=r+buy*(arrb[m-1])
    print(r)


def solve(n, st, k):
    MOD = int(1e9 + 7)
    dp = [0] * (n + 1)
    prefix_sum = [0] * (n + 1)
    dp[st] = 1
    for times in range(k):
        prefix_sum[0] = 0
        for i in range(1, n + 1):
            prefix_sum[i] = prefix_sum[i - 1] + dp[i]
            if prefix_sum[i] >= MOD: prefix_sum[i] -= MOD
        for i in range(1, n + 1):
            t = prefix_sum[n] - prefix_sum[i] + prefix_sum[i - 1] - prefix_sum[i >> 1]
            while t < 0: t += MOD
            while t >= MOD: t -= MOD
            dp[i] = t
    return sum(dp) % MOD

def main():
    n, a, b, k = [int(i) for i in input().split()]
    if a > b:
        print(solve(n - b, a - b, k))
    else:
        print(solve(b - 1, b - a, k))

main()

# -*- coding:utf-8 -*-

"""

created by shuangquan.huang at 1/17/20

"""

import collections
import time
import os
import sys
import bisect
import heapq
from typing import List

def solve(N, A, B, K):
    MOD = 1000000007

    dp = [0 for _ in range(N+1)]
    dp[A] = 1
    for k in range(1, K+1):
        ndp = [0 for _ in range(N+1)]
        for x in range(1, N+1):
            d = abs(x-B)
            if d <= 1:
                continue
            l, r = max(x-d+1, 1), min(x+d, N+1)
            if l < x:
                ndp[l] = (ndp[l] + dp[x]) % MOD
                ndp[x] = (ndp[x] - dp[x]) % MOD
            if x < r:
                if x + 1 <= N:
                    ndp[x+1] = (ndp[x+1] + dp[x]) % MOD
                if r <= N:
                    ndp[r] = (ndp[r] - dp[x]) % MOD

        v = 0
        for x in range(N+1):
            v += ndp[x]
            v %= MOD
            ndp[x] = v

        dp = ndp

    return sum(dp) % MOD

N, A, B, K = map(int, input().split())
print(solve(N, A, B, K))

def solve(n, st, k):
    MOD = int(1e9 + 7)
    prev = [0] * (n + 1)
    current = [0] * (n + 1)
    prefix_sum = [0] * (n + 1)
    prev[st] = 1
    for times in range(k):
        prefix_sum[0] = 0
        for i in range(1, n + 1):
            prefix_sum[i] = prefix_sum[i - 1] + prev[i]
            if prefix_sum[i] >= MOD:
                prefix_sum[i] -= MOD
        for i in range(1, n + 1):
            current[i] = prefix_sum[n] - prefix_sum[i >> 1] - prev[i]
            while current[i] < 0: current[i] += MOD
            while current[i] >= MOD: current[i] -= MOD
        prev, current = current, prev
    return sum(prev) % MOD

def main():
    n, a, b, k = [int(i) for i in input().split()]
    if a > b:
        print(solve(n - b, a - b, k))
    else:
        print(solve(b - 1, b - a, k))

main()

def solve(n, st, k):
    MOD = int(1e9 + 7)
    dp = [0] * (n + 1)
    prefix_sum = [0] * (n + 1)
    dp[st] = 1
    for times in range(k):
        prefix_sum[0] = 0
        for i in range(1, n + 1):
            prefix_sum[i] = prefix_sum[i - 1] + dp[i]
            if prefix_sum[i] >= MOD: prefix_sum[i] -= MOD
        for i in range(1, n + 1):
            dp[i] = prefix_sum[n] - dp[i] - prefix_sum[i >> 1]
            while dp[i] < 0: dp[i] += MOD
            while dp[i] >= MOD: dp[i] -= MOD
    return sum(dp) % MOD

def main():
    n, a, b, k = [int(i) for i in input().split()]
    if a > b:
        print(solve(n - b, a - b, k))
    else:
        print(solve(b - 1, b - a, k))

main()

def solve(n, st, k):
    MOD = int(1e9 + 7)
    dp = [0] * (n + 1)
    prefix_sum = [0] * (n + 1)
    dp[st] = 1
    for times in range(k):
        prefix_sum[0] = 0
        for i in range(1, n + 1):
            prefix_sum[i] = prefix_sum[i - 1] + dp[i]
            if prefix_sum[i] >= MOD: prefix_sum[i] -= MOD
        for i in range(1, n + 1):
            dp[i] = prefix_sum[n] - prefix_sum[i] + prefix_sum[i - 1] - prefix_sum[i >> 1]
            while dp[i] < 0: dp[i] += MOD
            while dp[i] >= MOD: dp[i] -= MOD
    return sum(dp) % MOD

def main():
    n, a, b, k = [int(i) for i in input().split()]
    if a > b:
        print(solve(n - b, a - b, k))
    else:
        print(solve(b - 1, b - a, k))

main()

n,a,b,k=map(int,input().split())
dp=[[0 for i in range(n+2)] for j in range(2)]
dp[0][a]=1
now=1
last=0
mod=1000000007
for i in range(k):
    for j in range(1,n+1):
        d=max(abs(j-b)-1,0)
        if j!=n:
            dp[now][j+1]=(dp[last][j]%mod+dp[now][j+1]%mod)%mod
            dp[now][min(j+d+1,n+1)]=(dp[now][min(j+d+1,n+1)]-dp[last][j])%mod
        if j!=1:
            dp[now][j]=(dp[now][j]-dp[last][j])%mod
            dp[now][max(j-d,1)]=(dp[now][max(j-d,1)]%mod+dp[last][j]%mod)%mod
    for i1 in range(1,n+2):
        dp[now][i1]=(dp[now][i1]+dp[now][i1-1])%mod
        dp[last][i1]=0
    aux=now
    now=last
    last=aux
print(sum(dp[last])%mod)

#!/usr/bin/env python3
import io
import os
import sys

input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

def printd(*args, **kwargs):
    #print(*args, **kwargs, file=sys.stderr)
    #print(*args, **kwargs)
    pass

def get_str():
    return input().decode().strip()

def rint():
    return map(int, input().split())

def oint():
    return int(input())

mod = 1000000007
n, a, b, k = rint()
if a > b:
    a, b = n-a+1, n-b+1
a -= 1
b -= 1
printd(n, a, b, k)

d = [0]*n
d[a] = 1
ps = [0]*b
ps[0] = d[0]
for j in range(1, b):
    ps[j] = ps[j-1]+d[j]
    ps[j] %= mod
    while ps[j] > mod:
        ps[j] -= mod
printd(n, a, b, k)
printd(d, ps)
for i in range(k):
    for j in range(b):
        #b-t > t-j
        #2*t < b+j
        #t < (b+j)/2
        if (b+j)%2:
            t = (b+j)//2
        else:
            t = (b+j)//2 - 1
        if j == 0:
            d[j] = ps[t] - ps[j]
        else:
            d[j] = ps[t] - ps[j] + ps[j-1]
        d[j] %= mod
        while d[j] > mod:
            d[j] -= mod
        while d[j] <0:
            d[j] += mod
        #d[j] %=mod
    ps[0] = d[0]
    for j in range(1, b):
        ps[j] = (ps[j-1]+d[j])# %mod
        ps[j] %= mod
        while ps[j] > mod:
            ps[j] -= mod
        while ps[j] < 0:
            ps[j] += mod
        printd(d,ps)
ans = ps[b-1]
print(ans%mod)

#!/usr/bin/env python3
import io
import os
import sys

input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

def printd(*args, **kwargs):
    #print(*args, **kwargs, file=sys.stderr)
    #print(*args, **kwargs)
    pass

def get_str():
    return input().decode().strip()

def rint():
    return map(int, input().split())

def oint():
    return int(input())

mod = 1000000007
n, a, b, k = rint()
if a > b:
    a, b = n-a+1, n-b+1
a -= 1
b -= 1
printd(n, a, b, k)

d = [0]*n
d[a] = 1
ps = [0]*b
ps[0] = d[0]
for j in range(1, b):
    ps[j] = ps[j-1]+d[j]
    ps[j] %= mod
printd(n, a, b, k)
printd(d, ps)
for i in range(k):
    for j in range(b):
        #b-t > t-j
        #2*t < b+j
        #t < (b+j)/2
        if (b+j)%2:
            t = (b+j)//2
        else:
            t = (b+j)//2 - 1
        if j == 0:
            d[j] = ps[t] - ps[j]
        else:
            d[j] = ps[t] - ps[j] + ps[j-1]
        d[j] %= mod
        #d[j] %=mod
    ps[0] = d[0]
    for j in range(1, b):
        ps[j] = (ps[j-1]+d[j])# %mod
        ps[j] %= mod
        printd(d,ps)
ans = ps[b-1]
print(ans%mod)

#!/usr/bin/env python3
import io
import os
import sys

input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

def printd(*args, **kwargs):
    #print(*args, **kwargs, file=sys.stderr)
    #print(*args, **kwargs)
    pass

def get_str():
    return input().decode().strip()

def rint():
    return map(int, input().split())

def oint():
    return int(input())

mod = 1000000007
n, a, b, k = rint()
if a > b:
    a, b = n-a+1, n-b+1
a -= 1
b -= 1
printd(n, a, b, k)

d = [0]*n
d[a] = 1
ps = [0]*b
ps[0] = d[0]
for j in range(1, b):
    ps[j] = ps[j-1]+d[j]
    while ps[j] > mod:
        ps[j] -= mod
printd(n, a, b, k)
printd(d, ps)
for i in range(k):
    for j in range(b):
        #b-t > t-j
        #2*t < b+j
        #t < (b+j)/2
        if (b+j)%2:
            t = (b+j)//2
        else:
            t = (b+j)//2 - 1
        if j == 0:
            d[j] = ps[t] - ps[j]
        else:
            d[j] = ps[t] - ps[j] + ps[j-1]
        while d[j] > mod:
            d[j] -= mod
        while d[j] <0:
            d[j] += mod
        #d[j] %=mod
    ps[0] = d[0]
    for j in range(1, b):
        ps[j] = (ps[j-1]+d[j])# %mod
        while ps[j] > mod:
            ps[j] -= mod
        while ps[j] < 0:
            ps[j] += mod
        printd(d,ps)
ans = ps[b-1]
print(ans%mod)

#!/usr/bin/env python3
import io
import os
import sys

input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

def printd(*args, **kwargs):
    #print(*args, **kwargs, file=sys.stderr)
    #print(*args, **kwargs)
    pass

def get_str():
    return input().decode().strip()

def rint():
    return map(int, input().split())

def oint():
    return int(input())

mod = 1000000007
n, a, b, k = rint()
if a > b:
    a, b = n-a+1, n-b+1
a -= 1
b -= 1
printd(n, a, b, k)

d = [0]*n
d[a] = 1
ps = [0]*b
ps[0] = d[0]
for j in range(1, b):
    ps[j] = ps[j-1]+d[j]
    while ps[j] > mod:
        ps[j] -= mod
    ps[j] %= mod
printd(n, a, b, k)
printd(d, ps)
for i in range(k):
    for j in range(b):
        #b-t > t-j
        #2*t < b+j
        #t < (b+j)/2
        if (b+j)%2:
            t = (b+j)//2
        else:
            t = (b+j)//2 - 1
        if j == 0:
            d[j] = ps[t] - ps[j]
        else:
            d[j] = ps[t] - ps[j] + ps[j-1]
        while d[j] > mod:
            d[j] -= mod
        while d[j] <0:
            d[j] += mod
        d[j] %= mod
        #d[j] %=mod
    ps[0] = d[0]
    for j in range(1, b):
        ps[j] = (ps[j-1]+d[j])# %mod
        while ps[j] > mod:
            ps[j] -= mod
        while ps[j] < 0:
            ps[j] += mod
        ps[j] %= mod
        printd(d,ps)
ans = ps[b-1]
print(ans%mod)

from sys import stdin, stdout
from collections import Counter, defaultdict
from itertools import permutations, combinations
raw_input = stdin.readline
pr = stdout.write

def in_num():
    return int(raw_input())

def in_arr():
    return map(int,raw_input().split())

def pr_num(n):
    stdout.write(str(n)+'\n')

def pr_arr(arr):
    pr(' '.join(map(str,arr))+'\n')

# fast read function for total integer input

def inp():
    # this function returns whole input of
    # space/line seperated integers
    # Use Ctrl+D to flush stdin.
    return map(int,stdin.read().split())

range = xrange # not for python 3.0+
mod=10**9+7
n,a,b,k=in_arr()
dp=[[0 for i in range(n+1)] for j in range(k+1)]
dp[0][a-1]=1
dp[0][a]=(-1)%mod
b-=1
for i in range(k):
    temp=0
    for j in range(n):
        temp=(temp+dp[i][j])%mod

        x=int(abs(b-j))
        x-=1
        if x<=0:
            continue
        dp[i+1][max(0,j-x)]=(dp[i+1][max(0,j-x)]+temp)%mod
        dp[i+1][min(n,j+x+1)]=(dp[i+1][min(n,j+x+1)]-temp)%mod
        dp[i+1][j]=(dp[i+1][j]-temp)%mod
        dp[i+1][j+1]=(dp[i+1][j+1]+temp)%mod

ans=0
temp=0
for i in range(n):
    temp+=dp[k][i]
    temp%=mod
    ans+=temp
    ans%=mod
pr_num(ans)

from sys import stdin, stdout
from collections import Counter, defaultdict
from itertools import permutations, combinations
raw_input = stdin.readline
pr = stdout.write

def in_num():
    return int(raw_input())

def in_arr():
    return map(int,raw_input().split())

def pr_num(n):
    stdout.write(str(n)+'\n')

def pr_arr(arr):
    pr(' '.join(map(str,arr))+'\n')

# fast read function for total integer input

def inp():
    # this function returns whole input of
    # space/line seperated integers
    # Use Ctrl+D to flush stdin.
    return map(int,stdin.read().split())

range = xrange # not for python 3.0+
mod=10**9+7
n,a,b,k=in_arr()
dp=[[0 for i in range(n+1)] for j in range(k+1)]
dp[0][a-1]=1
dp[0][a]=(-1)%mod
b-=1
for i in range(k):
    temp=0
    for j in range(n+1):
        temp=(temp+dp[i][j])%mod

        if i and int(abs(b-j))>1:
            temp-=dp[i-1][j]
            temp%=mod
        dp[i][j]=temp
        if j<n:
            x=int(abs(b-j))
            x-=1
            if x<=0:
                continue
            dp[i+1][max(0,j-x)]=(dp[i+1][max(0,j-x)]+temp)%mod
            dp[i+1][min(n,j+x+1)]=(dp[i+1][min(n,j+x+1)]-temp)%mod
            #dp[i+1][j]=(dp[i+1][j]-1)%mod
            #dp[i+1][j+1]=(dp[i+1][j+1]+1)%mod
        if i and int(abs(b-j))>1:
            temp+=dp[i-1][j]
            temp%=mod

ans=0
temp=0
for i in range(n):
    temp+=dp[k][i]
    temp%=mod
    if int(abs(i-b))>1:
        temp-=dp[k-1][i]
        temp%=mod
    ans+=temp
    ans%=mod

    if int(abs(i-b))>1:
        temp+=dp[k-1][i]
        temp%=mod
pr_num(ans)

#!/usr/bin/env python3
from sys import stdin

MOD = int(1e9)+7

def solve(tc):
    n, a, b, k = map(int, stdin.readline().split())

    dp = [1 for i in range(n+1)]
    dp[b] = 0
    prefix = [1 for i in range(n+1)]
    for i in range(k):
        for j in range(1, n+1):
            prefix[j] = prefix[j-1] + dp[j]
            prefix[j] %= MOD

        for j in range(1, b-1):
            dist = b - j
            start = max(0, j-dist)
            end = min(b-1, j+dist-1)
            dp[j] = prefix[j-1] - prefix[start]
            if dp[j] < 0:
                dp[j] += MOD
            dp[j] %= MOD
            dp[j] += prefix[end] - prefix[j]
            if dp[j] < 0:
                dp[j] += MOD
            dp[j] %= MOD

        dp[b-1] = dp[b] = 0
        if b+1 <= n:
            dp[b+1] = 0

        for j in range(b+2, n+1):
            dist = j - b
            start = max(b, j-dist)
            end = min(n, j+dist-1)
            dp[j] = prefix[j-1] - prefix[start]
            if dp[j] < 0:
                dp[j] += MOD
            dp[j] %= MOD
            dp[j] += prefix[end] - prefix[j]
            if dp[j] < 0:
                dp[j] += MOD
            dp[j] %= MOD

    print(dp[a])

tc = 1
solve(tc)

n,a,b,k=map(int,input().split())
dp=[[0 for i in range(n+2)] for j in range(2)]
dp[0][a]=1
now=1
last=0
mod=1000000007
for i in range(k):
    for j in range(1,n+1):
        d=max(abs(j-b)-1,0)
        if j!=n:
            dp[now][j+1]=(dp[last][j]+dp[now][j+1])%mod
            dp[now][min(j+d+1,n+1)]=(dp[now][min(j+d+1,n+1)]-dp[last][j])%mod
        if j!=1:
            dp[now][j]=(dp[now][j]-dp[last][j])%mod
            dp[now][max(j-d,1)]=(dp[now][max(j-d,1)]+dp[last][j])%mod
    for i1 in range(1,n+2):
        dp[now][i1]=(dp[now][i1]+dp[now][i1-1])%mod
        dp[last][i1]=0
    aux=now
    now=last
    last=aux
print(sum(dp[last])%mod)

from sys import stdin, stdout
from collections import Counter, defaultdict
from itertools import permutations, combinations
raw_input = stdin.readline
pr = stdout.write

def in_num():
    return int(raw_input())

def in_arr():
    return map(int,raw_input().split())

def pr_num(n):
    stdout.write(str(n)+'\n')

def pr_arr(arr):
    pr(' '.join(map(str,arr))+'\n')

# fast read function for total integer input

def inp():
    # this function returns whole input of
    # space/line seperated integers
    # Use Ctrl+D to flush stdin.
    return map(int,stdin.read().split())

range = xrange # not for python 3.0+
mod=10**9+7
n,a,b,k=in_arr()
dp=[[0 for i in range(n+1)] for j in range(k+1)]
dp[0][a-1]=1
dp[0][a]=-1
b-=1
for i in range(k):
    temp=0
    for j in range(n+1):
        temp=(temp+dp[i][j])%mod
        if i and int(abs(b-j))>1:
            temp-=dp[i-1][j]
            temp%=mod
        if j<n:
            x=int(abs(b-j))
            x-=1
            if x<=0:
                continue
            dp[i+1][max(0,j-x)]=(dp[i+1][max(0,j-x)]+temp)%mod
            dp[i+1][min(n,j+x+1)]=(dp[i+1][min(n,j+x+1)]-temp)%mod
            #dp[i+1][j]=(dp[i+1][j]-1)%mod
            #dp[i+1][j+1]=(dp[i+1][j+1]+1)%mod
        if i and int(abs(b-j))>1:
            temp+=dp[i-1][j]
            temp%=mod

ans=0
temp=0
for i in range(n):
    temp+=dp[k][i]
    temp%=mod
    if int(abs(i-b))>1:
        temp-=dp[k-1][i]
        temp%=mod
    ans+=temp
    ans%=mod

    if int(abs(i-b))>1:
        temp+=dp[k-1][i]
        temp%=mod
pr_num(ans)

#!/usr/bin/env python3
from sys import stdin

MOD = int(1e9)+7

def solve(tc):
    n, a, b, k = map(int, stdin.readline().split())

    dp = [1 for i in range(n+1)]
    dp[b] = 0
    prefix = [1 for i in range(n+1)]
    for i in range(k):
        for j in range(1, n+1):
            prefix[j] = prefix[j-1] + dp[j]
            prefix[j] %= MOD

        for j in range(1, b-1):
            dist = b - j
            start = max(0, j-dist)
            end = min(b-1, j+dist)
            dp[j] = prefix[j-1] - prefix[start] + MOD
            dp[j] %= MOD
            dp[j] += prefix[end] - prefix[j] + MOD
            dp[j] %= MOD

        dp[b-1] = dp[b] = 0
        if b+1<=n:
            dp[b+1] = 0

        for j in range(b+2, n+1):
            dist = j - b
            start = max(b, j-dist)
            end = min(n, j+dist)
            dp[j] = prefix[j-1] - prefix[start] + MOD
            dp[j] %= MOD
            dp[j] = prefix[end] - prefix[j] + MOD
            dp[j] %= MOD

    print(dp[a])

tc = 1
solve(tc)

n,a,b,k=map(int,input().split())
dp=[[0 for i in range(n+1)] for j in range(2)]
dp[0][a]=1
now=1
last=0
mod=1000000007
for i in range(k):
    for j in range(1,n+1):
        d=max(abs(j-b)-1,0)
        if j!=n:
            dp[now][j+1]=(dp[last][j]+dp[now][j+1])%mod
            dp[now][min(j+d+1,n)]=(dp[now][min(j+d+1,n)]-dp[last][j])%mod
        if j!=1:
            dp[now][j]=(dp[now][j]-dp[last][j])%mod
            dp[now][max(j-d,1)]=(dp[now][max(j-d,1)]+dp[last][j])%mod
    for i1 in range(1,n+1):
        dp[now][i1]=(dp[now][i1]+dp[now][i1-1])%mod
        dp[last][i1]=0
    aux=now
    now=last
    last=aux
print(sum(dp[last])%mod)

n,a,b,k=map(int,input().split())
dp=[[0 for i in range(n+1)] for j in range(a)]
dp[0][a]=1
now=1
last=0
mod=1000000007
for i in range(k):
    for j in range(1,n+1):
        d=abs(j-b)-1
        if j!=n:
            dp[now][j+1]=(dp[last][j]+dp[now][j+1])%mod
            dp[now][min(j+d+1,n)]=(dp[now][min(j+d+1,n)]+dp[last][j])%mod
        if j!=1:
            dp[now][j]=(dp[now][j]-dp[last][j])%mod
            dp[now][max(j-d,1)]=(dp[now][max(j-d,1)]+dp[last][j])%mod
    for i in range(1,n+1):
        dp[now][i]=(dp[now][i]+dp[now][i-1])%mod
        dp[last][i]=0
    aux=now
    now=last
    last=aux
print(sum(dp[last])%mod)

#!/usr/bin/env python3
import io
import os
import sys

input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

def printd(*args, **kwargs):
    #print(*args, **kwargs, file=sys.stderr)
    #print(*args, **kwargs)
    pass

def get_str():
    return input().decode().strip()

def rint():
    return map(int, input().split())

def oint():
    return int(input())

mod = 1000000007
n, a, b, k = rint()
a -= 1
b -= 1

d = [0]*n
d[a] = 1
ps = [0]*n
ps[0] = d[0]
for j in range(1, n):
    ps[j] = ps[j-1]+d[j]
printd(n, a, b, k)
printd(d, ps)
for i in range(k):
    d = [0]*n
    for j in range(1, b):
        d[j] = ps[j-1]
    for j in range(b):
        #b-t > t-j
        #2*t < b+j
        #t < (b+j)/2
        if (b+j)%2:
            t = (b+j)//2
        else:
            t = (b+j)//2 - 1
        d[j] += ps[t] - ps[j]
    ps = [0]*n
    ps[0] = d[0]
    for j in range(1, n):
        ps[j] = (ps[j-1]+d[j])%mod
    printd(d,ps)

print(ps[n-1]%mod)