x = int(eval(input()))

count = 0

count_2 = 0

while x > 0:

    if (x >= 500):

        x -= 500

        count += 1

    else:

        break



while x > 0:

    if (x >= 5):

        x -= 5

        count_2 += 1

    else:

        break



print((1000 * count + 5 * count_2))
X = int(eval(input()))



res = X // 500 * 1000

X %= 500

res += X // 5 * 5



print(res)

x = int(eval(input()))
count = 0
count_2 = 0
while x > 0:
    if x >= 500:
        x -= 500
        count += 1
    else:
        break
while x > 0:
    if x >= 5:
        x -= 5
        count_2 += 1
    else:
        break
print((1000 * count + 5 * count_2))

X = int(eval(input()))
res = X // 500 * 1000
X %= 500
res += X // 5 * 5
print(res)

-x = int(eval(input())) -count = 0 -count_2 = 0 -while x > 0: -    if x >= 500: -        x -= 500 -        count += 1 -    else: -        break -while x > 0: -    if x >= 5: -        x -= 5 -        count_2 += 1 -    else: -        break -print((1000 * count + 5 * count_2)) +X = int(eval(input())) +res = X // 500 * 1000 +X %= 500 +res += X // 5 * 5 +print(res)