n=int(eval(input()))



x=n//500



y=(n-x*500)//5



print((x*1000+y*5))
n = int(eval(input()))



shou500 = n//500



shou5 = (n-shou500*500)//5



print((shou500*1000+shou5*5))
n = int(eval(input()))
x = n // 500
y = (n - x * 500) // 5
print((x * 1000 + y * 5))

n = int(eval(input()))
shou500 = n // 500
shou5 = (n - shou500 * 500) // 5
print((shou500 * 1000 + shou5 * 5))

-x = n // 500 -y = (n - x * 500) // 5 -print((x * 1000 + y * 5)) +shou500 = n // 500 +shou5 = (n - shou500 * 500) // 5 +print((shou500 * 1000 + shou5 * 5))