S = int(eval(input()))

G = 500

GG = 5



g_count = 0

gg_count= 0



while S >= G:

  S = S - G

  g_count += 1

while S >= GG:

  S = S - GG

  gg_count += 1

print((g_count*1000 + gg_count*5))

N = int(eval(input()))

NN = N // 500

MM = N % 500

LL = MM // 5

#print(NN, LL)

print((NN * 1000 + LL * 5))
S = int(eval(input()))
G = 500
GG = 5
g_count = 0
gg_count = 0
while S >= G:
    S = S - G
    g_count += 1
while S >= GG:
    S = S - GG
    gg_count += 1
print((g_count * 1000 + gg_count * 5))

N = int(eval(input()))
NN = N // 500
MM = N % 500
LL = MM // 5
# print(NN, LL)
print((NN * 1000 + LL * 5))

-S = int(eval(input())) -G = 500 -GG = 5 -g_count = 0 -gg_count = 0 -while S >= G: -    S = S - G -    g_count += 1 -while S >= GG: -    S = S - GG -    gg_count += 1 -print((g_count * 1000 + gg_count * 5)) +N = int(eval(input())) +NN = N // 500 +MM = N % 500 +LL = MM // 5 +# print(NN, LL) +print((NN * 1000 + LL * 5))