n=int(eval(input()))



k = 0

l = 0

while n>=500:

  n = n-500

  k = k+1



  

while n>5:

  n -= 5 #n=n-5

  l += 1

  



print((k*1000+ l*5  ))
n=int(eval(input()))



k = n//500

l = (n-500*k)//5



print((k*1000+ l*5  ))
n = int(eval(input()))
k = 0
l = 0
while n >= 500:
    n = n - 500
    k = k + 1
while n > 5:
    n -= 5  # n=n-5
    l += 1
print((k * 1000 + l * 5))

n = int(eval(input()))
k = n // 500
l = (n - 500 * k) // 5
print((k * 1000 + l * 5))

-k = 0 -l = 0 -while n >= 500: -    n = n - 500 -    k = k + 1 -while n > 5: -    n -= 5  # n=n-5 -    l += 1 +k = n // 500 +l = (n - 500 * k) // 5