peterverebics/CodeNet_Python_118 huggingface dataset:
import math

line = input()
money = int(line)
happy = 0

calc_500 = math.floor(money / 500)

if calc_500 >= 1:
  happy += calc_500 * 1000
  money -= calc_500 * 500
  calc_5 = math.floor(money / 5)
  
  if calc_5 >= 1:
      happy += calc_5 * 5
      print(str(happy))
  else:
      print(str(happy))
else:
    calc_5 = math.floor(money / 5)
    if calc_5 >= 1:
      happy += calc_5 * 5
      print(str(happy))
    else:
      print(str(happy))
S =int(input())
joy_500 = (S // 500) * 1000
joy_5 = ((S-(joy_500 // 2)) // 5) * 5
print(joy_500+joy_5)
div500, rem = divmod(int(input()), 500)
print(div500 * 1000 + rem // 5 * 5)
s = int(input())

c = s // 500
d = s % 500

e = d //5

h = c*1000 + e*5

print(h)
x = int(input())

ans = (x//500)*1000 +((x%500)//5)*5

print(ans)
#  =========     /\       /|    |====/|
#      |        /  \       |    |   / |
#      |       /____\      |    |  /  |
#      |      /      \     |    | /   |
#  ========= /        \  =====  |/====|  
#  code

def main():
    x = int(input())
    ans = 0
    ans += (x // 500) * 1000
    x -= (x // 500) * 500
    ans += (x // 5) * 5
    print(ans)
    return

if __name__ == "__main__":
    main()
x = int(input())

c500 = x // 500
x %= 500
c005 = x // 5

print(c500 * 1000 + c005 * 5)
import numpy as np
X = int(input())

A = int(X / 500)
B = int(int(X % 500) / 5)

print(A * 1000 + B * 5)
x = int(input())
ans = 1000 * (x // 500)
ans += 5 * ((x % 500) // 5)
print(ans)
X = int(input())
a = X // 500
X %= 500
print(1000 * a + 5 * (X // 5))
x=int(input())

thousands=(x-x%500)/500
fives=(x%500-(x%500)%5)/5

happiness=int(1000*thousands+5*fives)

print(happiness)
x = int(input())
num_500 = x // 500
x -= num_500 * 500
num_5 = x // 5
print(1000 * num_500 + 5 * num_5)
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#l = list(map(int, input().split()))

x = int(input())

ans = 0

ans += x // 500 * 1000

ans += x % 500 // 5 * 5

print(ans)
X=int(input())


a=X//500
b=(X%500)//5
print(1000*a+5*b)
X = int(input())
s = X // 500
a = X % 500
t = a // 5
print(s*1000 + t*5)
x = int(input())
gohyaku = x // 500
goen = (x -500*gohyaku) // 5
print(gohyaku*1000 + 5 * goen)
x = int(input())

h_500 = x//500*1000
h_5 = (x%500)//5*5

print(h_500+h_5)
X = int(input())
amari = X % 500

print((X // 500)*1000 + (amari // 5 *5))
import sys


def main():
    input = sys.stdin.buffer.readline
    x = int(input())
    a, b = divmod(x, 500)
    c = b // 5
    print(1000 * a + 5 * c)


if __name__ == "__main__":
    main()
X = int(input())
print((X//500)*1000+((X%500)//5)*5)
x=int(input())
s=x//500
a=(x-500*s)//5
print(1000*s+5*a)
def solve():
    X = int(input())
    n_500 = X // 500
    X -= n_500 * 500
    n_5 = X // 5
    
    print(n_500 * 1000 + n_5 * 5)

if __name__ == '__main__':
    solve()
X = int(input())
print((X//500*1000)+(X % 500)//5*5)
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))

def main():
    X = int(input())
    luck = (X // 500) * 1000 + (X % 500) // 5 * 5
    print(luck)

if __name__ == '__main__':
    main()
# coding: utf-8


def solve(*args: str) -> str:
    x = int(args[0])
    a = x//500
    b = (x-(500*a))//5

    return str(1000*a+5*b)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))
no=int(input())
temp=no
th=0
f=0
if(temp>=500):
  th=temp//500
  temp=temp%500

if(temp>=5):
  f=temp//5
  temp=temp%5

print((th*1000)+(f*5))
num = (int(input()))
ans1 = 0
ans2 = 0
while num >= 500:
    ans1 += 1
    num -= 500

while num >= 5:
    ans2 += 1
    num -= 5

print((ans1*1000)+(ans2*5))
x=int(input());ans=0
while x>=500:
  x-=500
  ans+=1000
while x>=5:
  x-=5
  ans+=5
print(ans)
X = int(input())
print(X//500*1000 + (X-X//500*500)//5*5)
X = int(input())

ans = (X // 500) * 1000
ans += ( ((X % 500) // 5) * 5 )

print(ans)
x = int(input())
k = 0
while x >= 500:
  x -= 500
  k += 1000
while x >= 5:
  x -= 5
  k += 5
print(k)
x = int(input())

ans = 1000 * (x // 500) + 5 * ((x - (x // 500) * 500) // 5)
print(ans)
n=input()
c=0
while n>=500:
    n-=500
    c+=1000
for i in range(1,n+1):
    if i%5==0:
        c+=5
print c
x = int(input())

n_500 = int(x / 500)
h = 1000 * n_500
x -= 500 * n_500

n_5 = int(x / 5)
h += 5 * n_5

print(int(h))
import sys
input = sys.stdin.readline
n=int(input())
a = n//500
b = n%500
b = b//5
print(a*1000+b*5)
n = int(input())
a = (n//500)*1000
b = ((n%500)//5)*5
print(a + b)
X = int(input())
gold = 0

while X >= 500:
  X = X - 500
  gold += 1000

while X >= 5:
  X = X - 5
  gold += 5

print(gold)
def main():
  x = int(input())

  ans = 0

  while x >= 500:
    x -= 500
    ans += 1000

  while x >= 5:
    x -= 5
    ans += 5

  print(ans)

main()
X = int(input())
X_head = X // 500
X_under = X % 500 // 5
print(X_head * 1000 + X_under * 5)
x = int(input())

y500 = x // 500 
y5 = (x % 500) // 5
print(y500 * 1000 + y5 * 5)
def main():
    x = int(input())
    c = 0

    c += 1000 * (x//500)
    x -= 500 * (x//500)

    c += 5 * (x//5)
    print(c)
    return
main()
#入力
##1*1行列
X=int(input())#1*1の整数を格納

T=X//500
S=(X%500)//5

print((T*1000)+(S*5))
X = int(input())
print(X//500*1000+(X-X//500*500)//5*5)
X = int(input())

fhun = X // 500

amari = X % 500

five = amari // 5

print(fhun*1000 + five*5)
x=int(input())
total=0
total+=(x//500)
x-=total*500
total=total*1000
total+=(x//5)*5
print(total)
x = int(input())
ans = 0
ans += 1000*(x//500)
x %= 500
ans += 5*(x//5)
print(ans)
#!/usr/bin/python3
import sys
input = lambda: sys.stdin.readline().strip()
x = int(input())
print(1000 * (x // 500) + 5 * (x % 500 // 5))
x=int(input())

result=x//500*1000+x%500//5*5
print(result)
s = int(input())

a = s // 500
b = (s - (s // 500) * 500) // 5
ans = a * 1000 + b * 5

print(ans)
# -*- coding: utf-8 -*-


def main():
    import sys
    input = sys.stdin.readline

    x = int(input())
    ans = 0

    p, q = divmod(x, 500)
    ans += 1000 * p
    ans += q // 5 * 5

    print(ans)


if __name__ == '__main__':
    main()
"""
500 -> 1000
5 -> 5
"""
ans = 0
n = int(input())
if n >= 500:
    goh = n // 500
    zan = n % 500
    ans += goh*1000
    n = zan
if n < 500 and n != 0:
    g = n // 5
    ans += g*5

print(ans)
X=int(input())
g500=X//500
g5=(X%500)//5
print(g500*1000+g5*5)
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline
    n=int(readline())
    print((n//500)*1000 + ((n%500)//5)*5)
    #n,m,k=map(int, readline().rstrip().split())
    #arr=list(map(int, readline().rstrip().split()))
    #n=int(readline())
    #ss=readline().rstrip()
    #yn(1)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------
X=int(input())
a=X//500
b=(X%500)//5
print(1000*a+5*b)
x = int(input())
a=x//500
print(a*1000+(x-(a*500))//5*5)
#!/usr/bin/env python3
import sys
import collections as cl


def II(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


def LI(): return list(map(int, sys.stdin.readline().split()))


def main():
    N = II()
    big = N // 500
    N -= big*500
    small = N // 5
    print(big*1000 + small * 5)


main()
money = int(input())
happy = int(money/500)*1000 + int(money%500/5)*5
print(happy)
x = int(input())

go = x//500
x = x%500
f = x//5

print((go*1000)+(f*5))
x = int(input())

t = x // 500

x_new = x - 500 * t 

t_2 = x_new // 5

print(1000*t + 5 * t_2)
x = int(input())
a = x//500
b = (x%500)//5
print(1000*a + 5*b)
X = int(input())
m = X//500
n = (X-500*m) //5
print(m*1000+n*5)
x = int(input())

a = x // 500

x2 = x - (500 * a)

b = x2 // 5

ans = (1000 * a) + (5 * b)

print(ans)
x = int(input())
cnt1 = x // 500
cnt2 = (x-cnt1*500)//5
ans = cnt1*1000 + cnt2*5
print(ans)
ans = int(input())
print((ans // 500 * 1000) + ((ans % 500) // 5 * 5))
money = int(input())
points = (money//500)*1000 + (money % 500)//5*5
print(points)
X = int(input())
a = 0
b = 0
a = X//500
if a != 0:
    X %= 500*a

b = X//5
print(a*1000+b*5)
x = int(input())
print((x // 500) * 1000 + (x % 500 // 5) * 5)
X = int(input())
 
cnt = X//500
new_X = X - cnt * 500
ncnt = new_X // 5
print(cnt*1000 + ncnt*5)
x = int(input())
res = (x // 500) * 1000 + (x % 500 // 5) * 5
print(res)
a=input()
a=int(a)
result=0
while a>=500:
  a=a-500
  result=result+1000

while a>=5:
  a=a-5
  result=result+5
  
print(result)
X = int(input())
res = 0
res += int(X / 500) * 1000
res += int((X % 500) / 5) * 5
print(res)
import sys
input=sys.stdin.readline
x=int(input())
y=x//500
ans=y*1000
x=x-y*500
z=x//5
ans+=z*5
print(ans)
x=int(input())
ans=(x//500)*1000
rem=x%500
ans+=(rem//5)*5
print(ans)
i = int(input())
big = i // 500
last = i - (big*500)
mini = last // 5

print((big*1000)+(mini*5))
X = int(input())
a = X // 500
b = (X - a * 500) // 5
print(a * 1000 + b * 5)
X = int(input())

ans = X // 500 * 1000

X %= 500

ans += X // 5 * 5

print (ans)
x = int(input())

ans = 0

while x - 500 >= 0:
    ans += 1000
    x -= 500

while x - 5 >= 0:
    ans += 5
    x -= 5

print(ans)
X=int(input())

a=(X//500)*1000
b=((X%500)//5)*5
ans=a+b
print(ans)
s = int(input())
happy_500 = s//500
happy_5 = (s%500)//5
print(happy_500*1000+happy_5*5)
s=int(input())
res=(s//500)*1000+((s%500)//5)*5
print(res)
x = int(input())

ans = 0
num = x//500
ans += 1000*num

num = (x-500*num)//5
ans += num*5

print(ans)
X=int(input())

a=X//500*1000
b=(X-X//500*500)//5*5
print(a+b)
total = int(input())

x_500 = int(total/500)
x_5   = int((total-x_500*500)/5) 

print(x_500*1000 + x_5*5)
X = int(input())
A_500 = X // 500 * 1000
A_5 = X % 500 // 5 * 5
print(A_500 + A_5)
def main():
        X = int(input())

        ans = 0

        coins = [500,5]
        happy = [1000,5]

        for i in range(2):
                ans += X//coins[i]*happy[i]
                X = X%coins[i]

        print("{}".format(ans))

if __name__=="__main__":
        main()
n=int(input())
a=n//500
b=n-a*500
c=b//5
print(a*1000+c*5)
x = int(input())
ans = 0
ans += (x//500)*1000
x %= 500
ans += (x//5)*5
print(ans)
X = int(input())
a = X // 500
b = (X - 500 * a) // 5
print(a*1000 + b*5)
X = int(input())
a =  (X // 500)
b = ((X - a * 500) // 5)
print(a* 1000 + b* 5)
num = int(input())

num2 = num % 500
gre = (num // 500) * 1000

num3 = (num2 // 5) * 5
gre += num3

print(gre)
n=int(input())
ans=1000*(n//500)
n%=500
ans+=5*(n//5)
print(ans)
from math import*
n=int(input())
y= floor(n/500)
if (n-y)==0:
    print(1000*y)
else:
    x=n-y*500
    ans=(floor(x/5))*5+1000*y
    print(ans)
n=int(input())
ans=(n //500)*1000+((n % 500) // 5)*5
print(ans)
x = int(input())

ureshisa=(x//500)*1000 + 5*((x%500)//5)

print(ureshisa)
x=int(input())
a=x//500
b=(x-500*a)//5
print(1000*a+5*b)
originPrice = int(input())

glad = 0

glad += (originPrice // 500) * 1000
originPrice %= 500
glad += (originPrice // 5) * 5

print(glad)
x = int(input())
ureshi = (x//500)*1000
ureshi = ureshi + ((x%500)//5)*5
print(ureshi)
#n=int(input())
#a,b=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
x=int(input())

ans=(x//500)*1000
md=x%500
ans+=(md//5)*5

print(ans)
X = int(input())
happy = 0

if X//500 >= 1:
	happy += 1000*(X//500)
	X -= 500*(X//500)
if X//5 >= 1:
	happy += 5*(X//5)
	X -= 5*(X//5)
print(happy)
X = int(input())

golden = int(X / 500)
normal = int((X-500*golden)/5)
print(golden*1000+normal*5)
n = int(input())
print(n // 500 * 1000 + (n % 500) // 5 * 5)
def solve(x):
    ans = 0
    p = x // 500
    q = (x % 500) // 5
    return p * 1000 + q * 5

x = int(input())
print(solve(x))
X = int(input())
count_500 = X // 500
count_5 = (X - 500*count_500) // 5

print(count_500*1000+count_5*5)
x=int(input())
ans=0
ans+=(x//500)*1000
x%=500
ans+=(x//5)*5
print(ans)
x = int(input())
print((x//500)*1000+(x%500)//5*5)
X = int(input())
A = 0
while True:
    if X >= 500:
        X -= 500
        A += 1000
    elif X > 0:
        X -= 5
        A += 5
    if X < 5:
        print(A)
        break
x = int(input())

num_500 = x // 500
num_5 = x % 500 // 5
happy = 1000 * num_500 + 5 * num_5
print(happy)
money = int(input())
 
max500 = money // 500
rem500 = money % 500
 
max5 = rem500 // 5
 
happiness = max500 * 1000 + max5 * 5
 
print(happiness)
X=int(input())
A=X//500
B=(X-A*500)//5
print(A*1000+B*5)
x = int(input())
happy = (x//500)*1000
x %= 500
happy += (x//5)*5
print(happy)
def main():
    x=int(input())
    h=x//500 * 1000
    x%=500
    h+=x//5 * 5
    print(h)
main()
x = int(input())

ans = 0
while True:
    if x >= 500:
        x -= 500
        ans += 1000
    else:
        break

while True:
    if x >= 5:
        x -= 5
        ans += 5
    else:
        break
print(ans)
x = int(input())

sen_ure = x // 500
go_ure = (x - sen_ure * 500) // 5

print(sen_ure * 1000 + go_ure * 5)
x = int(input())
ans = 0

while x>=5:
    if x>=500:
        x=x-500
        ans = ans + 1000
    elif x>=5:
        x = x - 5
        ans = ans + 5

print(ans)
x = int(input())
ans = 0
ans+=1000*(x//500)
x%=500
ans+=5*(x//5)
print(ans)
x = int(input())
h = x//500
g=(x%500)//5
print(1000*h+g*5)
X = int(input())
if (X >= 0) and (X <= 10**9):
    print((X // 500) * 1000 + (((X - ((X // 500) * 500)) // 5) * 5))
x = int(input())
hap = 0
a = int(x/(500))
hap +=a*1000
x %= 500
a = int(x/(5))
hap +=a*5
print(hap)
x = int(input())
res = 0
res += (x // 500) * 1000
x %= 500
res += (x // 5) * 5
print(res)
N = int(input())

a = int(N // 500)
b = int( (N - a *500)//5 )

print(int(a*1000+b*5))
x = int(input())
y = x//500
z = (x-y*500)//5
print(y*1000+z*5)
X = int(input())

ans = 0
ans += X // 500 * 1000
cnt = X // 500

X -= 500*cnt
print(ans+X//5*5)
x = int(input())

ans, xxx = divmod(x, 500)
ans *= 1000
ans += (xxx//5) * 5

print(ans)
X=int(input())
fif=X//500
five=(X%500)//5
print(fif*1000+five*5)
X = int(input())

happy = 0
n500 = X // 500
happy += n500*1000
X -= n500*500
happy += (X // 5)*5

print(happy)
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def resolve():
    X = ir()
    a = X//500
    b = (X-a*500)//5
    print(a*1000+b*5)
resolve()
i=int(input())
print(((i//500)*1000)+(((i%500)//5)*5))
X = int(input())

C500 = X // 500
X = X % 500
C5 = X // 5

print(C500*1000+C5*5)
x = int(input())
ans = 0
x_ = x//500
ans += 1000*x_
ans += 5*((x-(x_*500))//5)
print(ans)
# ABC160

X = int(input())

ans = 0
coin_500 = 0
coin_5 = 0
coin_500 = X//500
X = X - coin_500*500
coin_5 = X//5
print(coin_500*1000+coin_5*5)
n=int(input())
y5=n//500
n=n%500
y2=n//5
print(y5*1000+y2*5)
x = int(input())
a, m = divmod(x, 500)
b, _ = divmod(m, 5)
ans = a * 1000 + b * 5
print(ans)
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

X = I()

num = X//500
print(num*1000 + ((X-num*500)//5) *5)
m=int(input())

print((m//500)*1000+((m%500)//5)*5)
import math

yen = int(input())
coin500 = math.floor(yen / 500)
yen -= (coin500 * 500)
coin5 = math.floor(yen / 5)

happiness = (coin500 * 1000) + (coin5 * 5)
print(happiness)
x=int(input())
print((x//500)*1000+((x % 500)//5)*5)
X=int(input())
a=X//500
b=(X-500*a)//5
print(a*1000+b*5)
import sys
X = int(input())
A = X//500
B = (X - A*500)//5
print(A*1000+B*5)
x = int(input())

num_500 = int(x//500)
num_5 = int((x-500*num_500)//5)

ans = 1000*num_500 + 5*num_5

print(ans)
n=int(input())
ans=0
ans+=(n//500)*1000
ans+=((n%500)//5)*5
print(ans)
X = int(input())
A = X // 500
B = X - A * 500
C = B // 5

print(1000 * A + 5 * C)
X = int(input())

Y = X//500
Z = X - Y*500
S = Z//5

ans = print(Y*1000 + S*5)
x = int(input())
print((x//500) * 1000 + ((x % 500) // 5) * 5)
a = int(input())
b = a // 500
c = a % 500
d = c // 5
e = b * 1000 + d *5
print(e)
n = int(input())
f = (n // 500)
print(1000 * f + 5 * ((n - f*500) // 5))
X=int(input())

a=X//500
b=(X%500)//5
print(a*1000+b*5)
S = int(input())

score = 0

score += (S//500)*1000

S = S%500

score += (S//5)*5

print(score)
X=int(input())
a=X//500
if X%500==0:
    print(a*1000)
else:
    b=(X-500*a)//5
    print(a*1000+b*5)
X = int(input())
if X>=500:
  a = X//500
  b = X%500
  result = (1000*a)+5*(b//5)
else:
  result = 5*(X//5)
print(result)
X = int(input())
print( (X//500)*1000 + ((X%500)//5)*5 )
X = int(input())
print(((X // 500) * 1000) + (((X - ((X // 500) * 500)) // 5) * 5))
x = int(input())

y = x//500
1000*y

z = (x - 500*y)//5
#print(x,y,z)

print(1000*y + 5*z)
X = int(input())
a = int(X // 500)
b = int(a*1000)
c = int(X - a*500)
d = int(c // 5)
d = int(d*5)
print(b + d)
n = int(input())
print(int(n//500*1000+(n%500)//5*5))
X = int(input())

medal_500 = X // 500
medal_5 =  (X % 500) // 5

answer = medal_500*1000 + medal_5*5
print(answer)
x = int(input())
a,b = x//500, x%500
print(a*1000 + (b//5)*5 )
X=int(input())
count=1000*(X//500)
count+=5*((X%500)//5)
print(count)
x = int(input())

c_500 = 0
c_5 = 0
while True:
    temp = x - 500
    if temp < 0:
        break
    else:
        c_500 += 1
        x = temp

while True:
    temp = x - 5
    if temp < 0:
        break
    else:
        c_5 += 1
        x = temp

print(c_500 * 2 * 500 + c_5 * 5)
x=int(input())
a=x//500
b=(x%500)//5
print((a*1000)+(b*5))
a = int(input())
b = a//500
c = (a%500)//5
print(b*1000+c*5)
x = int(input())

hc500 = x //  500
hc5 = (x - 500*hc500) // 5

print(hc500 * 1000 + hc5 * 5)
s = int(input())

ans = 0

ans += (s // 500) * 1000

s = s % 500

ans += (s // 5) * 5

print(ans)
n=int(input())

k = n//500
l = (n-500*k)//5

print(k*1000+ l*5  )
a=int(input())
ans_k=int(a/500)*1000
ans_k2=int((a%500)/5)*5
ans=int(ans_k+ans_k2)
print(ans)
x = int(input())
happiness = 0
if  x >= 500:
  q = x // 500
  happiness = q * 1000
  x = x % 500
if  x >= 5:
  q = x // 5
  happiness = happiness + q * 5
print(happiness)
import math
from collections import defaultdict
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:input()

"""========main code==============="""

t=ii()
ans=0
k=t//500
ans+=(k*1000)
t-=(k*500)
#print(t)
p=t//5
ans+=p*5
print(ans)
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

x = int(input())

h1000 = x//500
x -= h1000*500

h5 = x//5

print(h1000*1000+h5*5)
x = int(input())

a = int(x/500)
x = x - int(a*500)

b = int(x/5)

print(a*1000 + b*5)
x = int(input())
a = x//500
x -= a*500
b = x//5
print(1000*a+5*b)
x = int(input())
print((1000 * (x // 500)) + (5 * ((x%500)//5)))
X = int(input())
happy = 0

happy += (X // 500) * 1000
X %= 500

happy += (X // 5) * 5

print(happy)
x = int(input())
coins = [500, 5]
joy = 0
for coin in coins:
  val = x // coin
  x = x % coin
  if coin == 500:
    joy += val * 1000
  elif coin == 5:
    joy += val * 5
print(joy)
x = int(input())
a = x // 500
b = x % 500
print(a*1000 + (b // 5)*5)
x = int(input())

a = x//500

b = (x - 500*(x//500))//5

print(a*1000+5*b)
x = int(input())

fh = x // 500

r = max(x - (fh*500),0)

f = r // 5

print((fh*1000) + (f * 5))
X=int(input());print(X//500*1000+X%500//5*5)
x = int(input())
coin_500 = x // 500
coin_5 = (x - (coin_500 * 500)) // 5
print(coin_500 * 1000 + coin_5 * 5)
x = int(input())
ans = x//500*1000 + ((x-(x//500)*500)//5)*5
print(ans)
import math
s = int(input())
big_g= math.floor(s/500)*1000
small_g = math.floor((s%500)/5)*5
ans = big_g + small_g
print (ans)
n = int(input())
a=n//500
n=n%500
b=n//5
print(1000*a+5*b)
X=int(input())


a = X // 500
b = (X - a * 500) // 5
#c = (X - a * 500 - b * 100) // 50
#d = (X - a*500 - b*100 - c*50) // 10
#e = (X - a*500 - b*100 - c*50 - d*10) // 5

#print(a,b,c,d,e)

total = a * 1000 + b * 5

 
print(total)
X = int(input())

a, mod = divmod(X, 500)
b = mod // 5

print(a * 1000 + b * 5)
n = int(input())
print((n-n%500)*2+n%500-n%5)
x = int(input())

gohyaku = (x//500)
answer = 0

if gohyaku > 0:
    x = x % 500
    answer += 1000 * gohyaku

goen = ( x // 5)

if goen > 0:
    answer += 5 * goen

print(answer)
input = raw_input

x = int(input())
d1 = x // 500
x -= d1 * 500
out = d1 * 1000

d2 = x // 5
out += d2 * 5

print(out)
x = int(input())
a = x//500
b = x%500//5
print(1000*a+5*b)
x = int(input())
g1 = (x // 500) * 1000
g5 = ((x % 500) // 5) * 5
print(g1 + g5)
x = int(input())
a = x // 500
y = x - a*500
b = y // 5
answer = a * 1000 + b * 5
print(answer)
a=int(input())
print((a//500)*1000+((a%500)//5)*5)
x = int(input())

ans = 0

l500 = x // 500

#print(l500)#
x -= l500 * 500
#print(x)#
l5 = x // 5
#print(l5)#
print(l500 * 1000 + l5 * 5)
#print('                  ')#
N=int(input());M=N//500;M*=1000;X=500*(N//500);N-=X;M+=(N//5)*5;print(M)
X = int(input())

ans = (X//500) * 1000
ans += (X%500) // 5 * 5

print(ans)
X = int(input())

c500, X = divmod(X, 500)
c5, X = divmod(X, 5)

print(c500 * 1000 + c5 * 5)
import sys

X = int(sys.stdin.readline().strip())

r1 = X // 500
r2 = (X - 500*r1) // 5

print(r1*1000 + r2*5)
s = input()
s = int(s)

if s < 500:
    happy5 = s // 5
    happy = 5 * happy5
    print(happy)
else:
    happy500 = s//500
    
    happy5 = s%500
    happy5 = happy5//5
    
    happy = 1000*happy500 + 5*happy5
    print(happy)
x=int(input())
a=int(x/500)
y=x-(500*a)
b=int(y/5)
print(a*1000+b*5)
X = int(input())
h = X // 500
s = X - 500 * h
f = s // 5
print(h * 1000 + f * 5)
x=int(input())
re_500=x//500
re_50=(x-(500*re_500))//5

print(re_500*1000+re_50*5)
x=int(input())
ans=0
xx=x//500
amari=x%500
ans+=1000*xx+5*(amari//5)
print(int(ans))
x = int(input())
a, b = divmod(x, 500)
c, d = divmod(b, 5)
print(1000 * a + 5 * c)
x = int(input())
ans = (x // 500) * 1000
x %= 500
ans += (x // 5) * 5
print(ans)
x=int(input())
a=x//500
b=(x%500)//5
print(1000*a+5*b)
x = int(input())

n_500 = x // 500
y = x % 500

n_5 = y //5

print(1000*n_500 + 5*n_5)
x = int(input())

a = x // 500
b = (x - ((x // 500) * 500)) // 5
print(a * 1000 + b * 5)
X=int(input())
q, mod = divmod(X,500)
q2, mod2 = divmod(mod,5)
uresisa = q*1000+q2*5
print(uresisa)
n = int(input())

ans = 0

ans += (n // 500) * 1000
n = n % 500

ans += (n // 5) * 5
print(ans)
X = int(input())

happy_500 = X // 500
happy_5 = (X % 500) // 5

print(1000 * happy_500 + 5 * happy_5)
a = int(input())

count = 0
count += (a//500)*1000
count += ((a%500)//5 * 5)

print(count)
def main():
    X = int(input())
    ans = (X // 500) * 1000
    X = X % 500
    ans += (X // 5) * 5
    print(ans)


if __name__ == '__main__':
    main()
X = int(input())
print(X//500*1000+X % 500//5*5)
X = int(input())

q_500, mod_500 = divmod(X, 500)
q_5, mod_5 = divmod(mod_500, 5)

print(q_500*1000+q_5*5)
X = int(input())
if 0 <= X <= pow(10, 9):
    max500Coins = int(X/500)
    X = X % 500
    max5Coins = int(X/5)
    X = X % 5
    numberOFHappinessCoins = max500Coins*1000 + max5Coins*5
    print(numberOFHappinessCoins)
x = int(input())
count500 = x // 500 
x -= 500 * count500
count5 = x // 5
print(count500*1000 + count5*5)
X = int(input())
ans = 0
ans += (X // 500) * 1000
X -= (X // 500) * 500
ans += (X // 5) * 5

print(ans)
X = int(input())
s = 0
p = 0
while X >= 500:
    X = X - 500
    s = s + 1
while X >= 5:
    X = X - 5
    p = p + 1
print(1000*s+5*p)
x = int(input())
a = x//500
y = x - 500*a
b = y//5
print(1000*a + 5*b)
x=int(input())
ans=1000*(x//500)
x=x%500
ans=ans+5*(x//5)
print(ans)
x = int(input())
a = x//500
b = (x - a*500)//5
print(a*1000 + b*5)
X = int(input())
ans = 0
div, mod = divmod(X, 500)
ans += div*1000
div, mod = divmod(mod, 5)
ans += div*5
print(ans)
x = int(input())

a = x//500
b = x % 500//5

print(a*1000+b*5)
x = int(input())

r = 0
divider = ((500,1000), (5, 5))
for i in divider:
    x, remain = divmod(x, i[0])
    r += x * i[1]
    x = remain

print(r)
def solve(string):
    x = int(string)
    return str(x // 500 * 1000 + x % 500 // 5 * 5)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))
x=int(input())
y=x%500
z=y%5
a=(x-y)*2
b=(y-z)
print(a+b)
x=int(input())
happy500=x//500
happy5=(x-(x//500)*500)//5
print(happy500*1000+happy5*5)
x = int(input())

happy = 0
a = int(x/500)
happy = a*1000
a = int((x-(a*500))/5)
happy += a*5

print(happy)