x = int(eval(input()))

# a,b = map(int, input().split())

# l = list(map(int, input().split()))



ans = 0

r5 = int(x/500)

x= x- 500*r5

r1 = int(x/5)

print((r5*1000 + r1*5))



from collections import deque

s = int(eval(input()))



big = int(s/500)

s = s- big*500



print((big*1000 +int(s/5)*5))

x = int(eval(input()))
# a,b = map(int, input().split())
# l = list(map(int, input().split()))
ans = 0
r5 = int(x / 500)
x = x - 500 * r5
r1 = int(x / 5)
print((r5 * 1000 + r1 * 5))

from collections import deque

s = int(eval(input()))
big = int(s / 500)
s = s - big * 500
print((big * 1000 + int(s / 5) * 5))

-x = int(eval(input())) -# a,b = map(int, input().split()) -# l = list(map(int, input().split())) -ans = 0 -r5 = int(x / 500) -x = x - 500 * r5 -r1 = int(x / 5) -print((r5 * 1000 + r1 * 5)) +from collections import deque + +s = int(eval(input())) +big = int(s / 500) +s = s - big * 500 +print((big * 1000 + int(s / 5) * 5))