num = (int(eval(input())))

ans1 = 0

ans2 = 0

while num >= 500:

    ans1 += 1

    num -= 500



while num >= 5:

    ans2 += 1

    num -= 5



print(((ans1*1000)+(ans2*5)))
x = int(eval(input()))

count = 0



while x >= 500:

    count += 1000

    x -= 500



while x >= 5:

    count += 5

    x -= 5



print(count)
num = int(eval(input()))
ans1 = 0
ans2 = 0
while num >= 500:
    ans1 += 1
    num -= 500
while num >= 5:
    ans2 += 1
    num -= 5
print(((ans1 * 1000) + (ans2 * 5)))

x = int(eval(input()))
count = 0
while x >= 500:
    count += 1000
    x -= 500
while x >= 5:
    count += 5
    x -= 5
print(count)

-num = int(eval(input())) -ans1 = 0 -ans2 = 0 -while num >= 500: -    ans1 += 1 -    num -= 500 -while num >= 5: -    ans2 += 1 -    num -= 5 -print(((ans1 * 1000) + (ans2 * 5))) +x = int(eval(input())) +count = 0 +while x >= 500: +    count += 1000 +    x -= 500 +while x >= 5: +    count += 5 +    x -= 5 +print(count)