x = int(eval(input()))

count = 0



while (x >= 500):

    count += 1000

    x = x-500

while (x >= 5):

    if x > 5:

        count += 5

        x = x-5

print(count)
#別回答

x = int(eval(input()))



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

# 別回答
x = int(eval(input()))
print(((x // 500 * 1000) + ((x % 500) // 5 * 5)))

+# 別回答 -count = 0 -while x >= 500: -    count += 1000 -    x = x - 500 -while x >= 5: -    if x > 5: -        count += 5 -        x = x - 5 -print(count) +print(((x // 500 * 1000) + ((x % 500) // 5 * 5)))