n = int(eval(input()))

happy = 0

if n%500 == 0:

    print((2*n))

else:

    while n > 0:

        if n == 0:

            break

        n-=500

        if n<0:

            n+=500

            n-=5

            if n<0:

                n+=5

                break

            else:

                happy+=5

        else:

            happy+=1000

    print(happy)

x = int(eval(input()))

total = 0

a = int(x / 500)

b = x % 500

c = int(b / 5)

total = a * 1000 + c *5

print(total)
n = int(eval(input()))
happy = 0
if n % 500 == 0:
    print((2 * n))
else:
    while n > 0:
        if n == 0:
            break
        n -= 500
        if n < 0:
            n += 500
            n -= 5
            if n < 0:
                n += 5
                break
            else:
                happy += 5
        else:
            happy += 1000
    print(happy)

x = int(eval(input()))
total = 0
a = int(x / 500)
b = x % 500
c = int(b / 5)
total = a * 1000 + c * 5
print(total)

-n = int(eval(input())) -happy = 0 -if n % 500 == 0: -    print((2 * n)) -else: -    while n > 0: -        if n == 0: -            break -        n -= 500 -        if n < 0: -            n += 500 -            n -= 5 -            if n < 0: -                n += 5 -                break -            else: -                happy += 5 -        else: -            happy += 1000 -    print(happy) +x = int(eval(input())) +total = 0 +a = int(x / 500) +b = x % 500 +c = int(b / 5) +total = a * 1000 + c * 5 +print(total)