money=int(eval(input()))

happines=0

while money>=500:

  happines+=1000

  money-=500

while money>=5:

  happines+=5

  money-=5

print(happines)
money=int(eval(input()))

happines=0

while money>=500:

  happines+=1000

  money-=500

while money>=100:

  happines+=100

  money-=100

while money>=5:

  happines+=5

  money-=5

print(happines)
money = int(eval(input()))
happines = 0
while money >= 500:
    happines += 1000
    money -= 500
while money >= 5:
    happines += 5
    money -= 5
print(happines)

money = int(eval(input()))
happines = 0
while money >= 500:
    happines += 1000
    money -= 500
while money >= 100:
    happines += 100
    money -= 100
while money >= 5:
    happines += 5
    money -= 5
print(happines)

+while money >= 100: +    happines += 100 +    money -= 100