X =eval(input())

X=int(X)

point =0

while X>=5:

    if X>=500:

        X-=500

        point+=1000

    elif 5<=X<500:

        X-=5

        point+=5



print(point)
X =int(eval(input()))

a =int(X/500)

b=int((X%500)/5)

print((1000*a+5*b))

        
X = eval(input())
X = int(X)
point = 0
while X >= 5:
    if X >= 500:
        X -= 500
        point += 1000
    elif 5 <= X < 500:
        X -= 5
        point += 5
print(point)

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

-X = eval(input()) -X = int(X) -point = 0 -while X >= 5: -    if X >= 500: -        X -= 500 -        point += 1000 -    elif 5 <= X < 500: -        X -= 5 -        point += 5 -print(point) +X = int(eval(input())) +a = int(X / 500) +b = int((X % 500) / 5) +print((1000 * a + 5 * b))