#template

def inputlist(): return [int(j) for j in input().split()]

from collections import Counter

#template

#issueから始める

X = int(eval(input()))

k = X //500

ans = 0

ans += 1000*k

X -= 500*k

l = X //5

ans += 5*l

print(ans)
N = int(eval(input()))

d = N // 500

mod = N % 500

d2 = mod // 5

print((d*1000+d2*5))
# template
def inputlist():
    return [int(j) for j in input().split()]


from collections import Counter

# template
# issueから始める
X = int(eval(input()))
k = X // 500
ans = 0
ans += 1000 * k
X -= 500 * k
l = X // 5
ans += 5 * l
print(ans)

N = int(eval(input()))
d = N // 500
mod = N % 500
d2 = mod // 5
print((d * 1000 + d2 * 5))

-# template -def inputlist(): -    return [int(j) for j in input().split()] - - -from collections import Counter - -# template -# issueから始める -X = int(eval(input())) -k = X // 500 -ans = 0 -ans += 1000 * k -X -= 500 * k -l = X // 5 -ans += 5 * l -print(ans) +N = int(eval(input())) +d = N // 500 +mod = N % 500 +d2 = mod // 5 +print((d * 1000 + d2 * 5))