s = int(eval(input()))

count1=-1

count2=-1

while s>=0:

 s=s-500

 count1=count1 +1

s=s+500

if s==0:

  yasashisa=count1*1000

  print(yasashisa)

else:

   while s >=0:

     s=s-5

     count2=count2 +1

   yasashisa=count1*1000+count2* 5

   print(yasashisa)







s=int(eval(input()))

a= s//500

b=(s%500)//5

yasashisa=a*1000+b*5

print(yasashisa)
s = int(eval(input()))
count1 = -1
count2 = -1
while s >= 0:
    s = s - 500
    count1 = count1 + 1
s = s + 500
if s == 0:
    yasashisa = count1 * 1000
    print(yasashisa)
else:
    while s >= 0:
        s = s - 5
        count2 = count2 + 1
    yasashisa = count1 * 1000 + count2 * 5
    print(yasashisa)

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

-count1 = -1 -count2 = -1 -while s >= 0: -    s = s - 500 -    count1 = count1 + 1 -s = s + 500 -if s == 0: -    yasashisa = count1 * 1000 -    print(yasashisa) -else: -    while s >= 0: -        s = s - 5 -        count2 = count2 + 1 -    yasashisa = count1 * 1000 + count2 * 5 -    print(yasashisa) +a = s // 500 +b = (s % 500) // 5 +yasashisa = a * 1000 + b * 5 +print(yasashisa)