Problem:
 Score : 200 points    Problem Statement Takahashi loves gold coins. He gains 1000  happiness points for each 500 -yen coin he has and gains 5 happiness points for each 5 -yen coin he has. (Yen is the currency of Japan.)  Takahashi has X yen. If he exchanges his money so that he will gain the most happiness points, how many happiness points will he earn?  (We assume that there are six kinds of coins available: 500 -yen, 100 -yen, 50 -yen, 10 -yen, 5 -yen, and 1 -yen coins.)      Constraints  0 \leq X \leq 10^9  X is an integer.         Input Input is given from Standard Input in the following format:  X       Output Print the maximum number of happiness points that can be earned.        Sample Input 1 1024      Sample Output 1 2020  By exchanging his money so that he gets two 500 -yen coins and four 5 -yen coins, he gains 2020 happiness points, which is the maximum number of happiness points that can be earned.       Sample Input 2 0      Sample Output 2 0  He is penniless - or yenless.       Sample Input 3 1000000000      Sample Output 3 2000000000  He is a billionaire - in yen.

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

Solution (Python):
n=int(input())
x=(n%500)

print((n//500)*1000+x - x%5)

Solution (Python):
x = int(input())
ans = 0
ans += x//500*1000
ans += (x%500)//5*5
print(ans)

Solution (Python):
def main():
    x = int(input())
    a = x // 500
    b = (x - 500 * a) // 5
    ans = int(a * 1000 + b * 5)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
x = int(input())
ans = 0

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

print(ans)

Solution (Python):

x=int(input())
k=0
s=0

if x//500>0:
    k=x//500
    s+=k*1000
    x=x-k*500
if x//5>0:
    k=x//5
    s+=k*5
    x=x-k*5
print(s)

Solution (Python):
cnt = int(input())

hp = 0
if cnt >= 500:
    hp += (1000 * (cnt // 500))
    cnt %= 500
hp += (5 * (cnt // 5))

print(hp)

Solution (Python):
X = int(input())

x500 = X // 500

print(1000 * x500 + (X - 500 * x500) // 5 * 5)

Solution (Python):
x = int(input())
print(x//500*1000+(x-x//500*500)//5*5)

Solution (Python):
X = int(input())
 
thousand = X // 500
rest = X - thousand * 500
five = rest // 5
 
print(1000 * thousand + 5 * five)

Solution (Python):
X = int(input())



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

print(happiness)

Solution (Python):
x = int(input())
ans = 1000*(x // 500) + 5*((x % 500) // 5)
print(ans)

Solution (Python):
x=int(input())
total=0
total+=(x//500)
x-=total*500
total=total*1000
total+=(x//5)*5
print(total)

Solution (Python):
x = int(input())
l = divmod(x,500)
m = l[0]
n = l[1]//5
print(1000*m+5*n)

Solution (Python):
X=int(input())
a=X%500
to=X//500*1000+a//5*5
print(to)

Solution (Python):
x = int(input())
h500 = x // 500
h5 = (x%500) //5
print(h500 * 1000 + h5* 5)

Solution (Python):
x =int(input())
ans = 0
ans += x//500*1000
x -= x//500*500
ans +=x//5*5
print(ans)

Solution (Python):
X = int(input())

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

print(a * 1000 + b * 5)

Solution (Python):
X = int(input())

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

Solution (Python):
def sep():
    return map(int,input().strip().split(" "))
def lis():
    return list(sep())
import sys
sys.setrecursionlimit(10**6)

n=int(input())
k=(n//500)*1000
t=((n%(500))//5)*5
print(k+t)

Solution (Python):
x = int(input())
print(1000*(x//500)+5*((x-(500*(x//500)))//5))

Solution (Python):
x=int(input())

h1=x//500
h2=(x%500)//5

print(h1*1000+h2*5)

Solution (Python):
N = int(input())
count1 = N // 500
count2 = ( N%500 ) // 5
print( 1000*count1 + 5*count2 )

Solution (Python):
x = int(input())

a = x // 500
x = x - a * 500
b = x // 5

print(1000*a+5*b)

Solution (Python):
X = int(input())
happy = (X // 500) * 1000 + ((X % 500) // 5) * 5
print(happy)

Solution (Python):
x = int(input())
n500 = x // 500
n5 = (x % 500) // 5
print(n500 * 1000 + n5 * 5)

Solution (Python):
X = int(input())
yen500, yen5 = divmod(X, 500)
yen5 = yen5 // 5
print(yen500 * 1000 + yen5 * 5)

Solution (Python):
X = int(input())

thousand = X // 500
rest = X - thousand * 500
five = rest // 5

print(1000 * thousand + 5 * five)

Solution (Python):
x = int(input())
coins = [500, 5]

ans = 0

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

ans += (x // 5) * 5

print(ans)

Solution (Python):
S =int(input())
joy_500 = (S // 500) * 1000
joy_5 = ((S-(joy_500 // 2)) // 5) * 5
print(joy_500+joy_5)

Solution (Python):
X = int(input())
gohyaku,X = divmod(X,500)
go,X = divmod(X,5)
print(1000*gohyaku+5*go)

Solution (Python):
x = int(input())
c1 = x//500
x -= 500*c1
c2 = x//5
print(1000*c1 + 5*c2)

Solution (Python):
x = int(input())

print(x//500*1000 + x%500//5*5)

Solution (Python):
x = int(input())

print(x//500*1000 + x%500//5*5)

Solution (Python):
'''
問題：
    高橋君は金色の硬貨が好きです。
    自分が持っている 500円硬貨 1枚につき 1000、
    5円硬貨 1枚につき 5の嬉しさ を得ます。

    高橋君は X 円を持っています。
    これを高橋君の嬉しさが最大になるように両替したとき、高橋君の嬉しさはいくらになりますか？

    (なお、利用できる硬貨は 500 円玉、100 円玉、50 円玉、10 円玉、5円玉、1 円玉の 6 種類とします。)
'''

'''
    Xは整数
    0 ≦ X ≦ 1,000,000,000
'''
class Yorokobi:
    def __init__(self, money, yorokobi):
        self.money = money
        self.yorokobi = yorokobi

    def calc_yorokobi(self, credit):    
        return (credit // self.money) * self.yorokobi


input_x = int(input())

yorokobi_500 = Yorokobi(500, 1000)
yorokobi_5 = Yorokobi(5, 5)

result = 0  
if input_x >= 500:
    result += yorokobi_500.calc_yorokobi(input_x)   
    result += yorokobi_5.calc_yorokobi(input_x % 500)   
else:
    result += yorokobi_5.calc_yorokobi(input_x)

print(result)

Solution (Python):
def resolve():
    x = int(input())
    ans = 0
    ans += x//500*1000
    ans += x%500//5*5
    print(ans)
resolve()

Solution (Python):
X=int(input())
ureshisa_500=(X//500)*1000
ureshisa_5=(X%500//5)*5

print(ureshisa_500+ureshisa_5)

Solution (Python):
x=int(input())
a=(x//500)*1000
b=((x%500)//5)*5
print(a+b)

Solution (Python):

X = int(input())
h1000 = int(X/500)
h5 = int((X%500)/5)
print(h1000 * 1000 + h5*5)

Solution (Python):
'''
問題：
    高橋君は金色の硬貨が好きです。
    自分が持っている 500円硬貨 1枚につき 1000、
    5円硬貨 1枚につき 5の嬉しさ を得ます。

    高橋君は X 円を持っています。
    これを高橋君の嬉しさが最大になるように両替したとき、高橋君の嬉しさはいくらになりますか？

    (なお、利用できる硬貨は 500 円玉、100 円玉、50 円玉、10 円玉、5円玉、1 円玉の 6 種類とします。)
'''

'''
    Xは整数
    0 ≦ X ≦ 1,000,000,000
'''
class A:
    def __init__(self, money, yorokobi):
        self.money = money
        self.yorokobi = yorokobi

    def calc_yorokobi(self, credit):    
        return int(credit / self.money) * self.yorokobi

    
        






input_x = int(input())

yorokobi_500 = A(500, 1000)
yorokobi_5 = A(5, 5)

result = 0  
if input_x >= 500:
    
    result += yorokobi_500.calc_yorokobi(input_x)   
    
    result += yorokobi_5.calc_yorokobi(input_x % 500)   
    
else:
    result += yorokobi_5.calc_yorokobi(input_x)

print(result)

Solution (Python):
input_X = int(input())

result_500 = input_X // 500
result_500ureshi = result_500 * 1000
result_5ureshi = (input_X - result_500 * 500) // 5 * 5

result = int(result_500ureshi + result_5ureshi)
print(result)

Solution (Python):
'''
問題：
    高橋君は金色の硬貨が好きです。
    自分が持っている 500円硬貨 1枚につき 1000、
    5円硬貨 1枚につき 5の嬉しさ を得ます。

    高橋君は X 円を持っています。
    これを高橋君の嬉しさが最大になるように両替したとき、高橋君の嬉しさはいくらになりますか？

    (なお、利用できる硬貨は 500 円玉、100 円玉、50 円玉、10 円玉、5円玉、1 円玉の 6 種類とします。)
'''

'''
Xは整数
0 ≦ X ≦ 1,000,000,000
'''



input_x = int(input())

ret1 = input_x // 500  
ret2 = ret1 * 1000  
ret3 = input_x - (ret1 * 500)   
ret4 = ret3 // 5 
ret5 = ret4 * 5 
print(ret2 + ret5)

Solution (Python):
X = int(input())

syou = int(X/500)
syou_second = int((X - syou*500)/5)
ans = syou*1000 + syou_second*5
print(ans)

Solution (Python):
x = int(input())
m = divmod(x, 500)

print(m[0] * 1000 + m[1] // 5 * 5)

Solution (Python):
X = int(input())
ans = (X // 500) * 1000 + ((X % 500) // 5) * 5
print(ans)

Solution (Python):
x = int(input())

def answer(x: int) -> int:
    ans = 1000 * (x // 500)
    x %= 500
    ans += 5 * ((x - 500 * (x // 500)) // 5)
    return ans

print(answer(x))

Solution (Python):
X=int(input())
x=X//500
y=X%500//5
print(1000*x+5*y)

Solution (Python):
X=int(input())
big=X//500
small=(X%500)//5
print(1000*big+5*small)

Solution (Python):
X=int(input())
C=X//500
c=(X-X//500*500)//5
print(C*1000+c*5)

Solution (Python):
X = int(input())
ans, rem = divmod(X, 500)
ans *= 1000
ans += rem // 5 * 5
print(ans)

Solution (Python):



from math import gcd
from itertools import combinations,permutations,accumulate, product 

from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq














import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7


INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
    return int(readline())
X = I()
m500 = X//500
rest = X - 500 * m500
print(m500 * 1000 + 5 * (rest//5))

Solution (Python):
x = int(input())
ans = 0
 
ans += (x // 500) * 1000
x -= (x // 500) * 500
ans += (x // 5) * 5
 
print(ans)

Solution (Python):
n = int(input())
print(n // 500 * 1000 + n % 500 // 5 * 5)

Solution (Python):
X = int(input())

res = X // 500 * 1000
X %= 500
res += X // 5 * 5

print(res)

Solution (Python):
x = int(input())

print((x//500)*1000+((x-500*(x//500))//5)*5)

Solution (Python):
import sys
X = int(input())
A = X//500
B = (X - A*500)//5
print(A*1000+B*5)

Solution (Python):
X = int(input())
ans = 1000*(X//500)
X -= 500*(X//500)
ans += 5*(X//5)
print(ans)

Solution (Python):
x = int(input())
print(x//500*1000+x%500//5*5)

Solution (Python):
x = int(input())
ans, r = divmod(x, 500)
ans *= 1000
ans += (r//5)*5
print(ans)

Solution (Python):
X = int(input())
n = X//500
ans = 1000*n
m = X%500
k = m//5
ans += 5*k
print(ans)

Solution (Python):
x = int(input())
ans = (x // 500) * 1000
x -= (x // 500) * 500
print(ans+(x//5)*5)

Solution (Python):
import sys
input = sys.stdin.readline
X = int(input())
res = X // 500 * 1000
print(res + (X % 500) // 5 * 5)

Solution (Python):
x = int(input())
print(x//500 * 1000 + (x%500)//5 * 5)

Solution (Python):
X = int(input())
print((X // 500) * 1000 + ((X % 500) // 5) * 5)

Solution (Python):
x = int(input())
a = x // 500
b = (x - a * 500) // 5
print(500 * 2 * a + 5 * b)

Solution (Python):
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))

Solution (Python):
def atc_160b(X: int) -> int:
    return X // 500 * 1000 + X % 500 // 5 * 5


X_input = int(input())
print(atc_160b(X_input))

Solution (Python):
n = int(input())
k = 0
k += (n//500)*1000
n = n%500
k += (n//5)*5
print(k)

Solution (Python):
n=int(input())
d,m=divmod(n,500)
print(d*1000+m//5*5)

Solution (Python):
x = int(input())

ans = 0

div_500, x = divmod(x, 500)
div_5, x = divmod(x, 5)

ans = div_500 * 1000 + div_5 * 5
print(ans)

Solution (Python):
X = int(input())

five_hundred = int(X / 500)
five = int((X - five_hundred*500)/5)
print(five_hundred*1000+five*5)

Solution (Python):
X = int(input())




s = X // 500
a = X % 500
t = a // 5
print(s*1000 + t*5)

Solution (Python):



X = int(input())

kiri_happy = X // 500
inaho_happy = (X - (500 * kiri_happy)) // 5

answer = (kiri_happy * 1000) + (inaho_happy * 5)

print(answer)

Solution (Python):



X = int(input())

kiri_happy = X // 500
inaho_happy = (X - (500 * kiri_happy)) // 5

answer = (kiri_happy * 1000) + (inaho_happy * 5)

print(answer)

Solution (Python):
x = int(input())
ans = 0
ans += 1000*(x//500)
x %= 500
ans += 5*(x//5)
print(ans)

Solution (Python):
X = int(input())
happy = 0
big_fun = 0
small_fun = 0
big_fun = X // 500
X = X % 500
small_fun = X // 5

happy = big_fun * 1000 + small_fun * 5

print(happy)

Solution (Python):
x = int(input())

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

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

Solution (Python):
x = int(input())

five_hand = 500
five = 5
glad = 0

if x >= five_hand:
    glad = glad + (x // five_hand) * 1000
    x = x % five_hand

if x >= five:
    glad = glad + (x // five) * 5
    x = x % five

print(glad)

Solution (Python):
X = int(input())
Y = X % 500
answer = (X // 500 * 1000 + Y // 5 * 5)
print(answer)

Solution (Python):
x = int(input())
g_happy = 0


g_happy += 1000 * (x // 500)

x -= 500 * (x // 500)

g_happy += 5 * (x // 5)
print(g_happy)

Solution (Python):
x = int(input())

bigmoney_number = x // 500
bigmoney = x // 500 * 1000
smallmoney = (x - bigmoney_number * 500) // 5 * 5

print(bigmoney + smallmoney)

Solution (Python):
X = int(input())

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

print(happy)

Solution (Python):
X = int(input())
s = X // 500
a = X % 500
t = a // 5
print(s*1000 + t*5)

Solution (Python):
x = int(input())
answer = 0
answer = (x//500)*1000
x = x%500
answer += (x//5)*5
print(answer)

Solution (Python):
x=int(input())
n=x//500
m=x%500
k=m//5
print(1000*n+5*k)

Solution (Python):
X = int(input())
ans = int(X/500) * 1000 + int((X - int(X/500)*500)/5)*5
print(ans)

Solution (Python):
i = int(input())
a = 0
a += (i // 500) * 1000
i = i % 500
a += (i // 5) * 5
print(a)

Solution (Python):
money = int(input())

count_div_500, left_after_500 = divmod(money, 500)
count_div_5, left_after_5 = divmod(left_after_500, 5)

print(count_div_500 * 1000 + count_div_5 * 5)

Solution (Python):
X = int(input())

happy1 = X // 500
X -= 500 * happy1
happy2 = X // 5
print(happy1*1000 + happy2*5)

Solution (Python):
X=int(input())
print(((X//500)*1000)+(((X%500)//5)*5))

Solution (Python):
def answer(x: int) -> int:
    dict = {500: 1000, 5: 5}
    happiness = 0

    for coin in sorted(dict, reverse=True):
        q, x = divmod(x, coin)
        happiness += dict[coin] * q

    return happiness


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


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    X = int(input())
    fh = X // 500
    X = X-fh*500
    fv = X//5

    print(fh*1000+fv*5)


main()

Solution (Python):
X = int(input())

a =  X // 500 * 1000    
b = (X % 500)// 5 * 5    

print(a + b)

Solution (Python):
X = int(input())

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

Solution (Python):
X = int(input())

sum = 0
gohyakumai =X//500

sum = gohyakumai*1000

goenmai = (X%500)//5

sum = goenmai *5 +sum

print (sum)

Solution (Python):
X=int(input())

def answer(X:int):
    return(int(X/500)*1000+int(X%500/5)*5)

print(answer(X))

Solution (Python):
x = int(input())

cnt_500 = 0
cnt_5 = 0
while x > 4:
    if x >= 500:
        x -= 500
        cnt_500 += 1
    else:
        x -= 5
        cnt_5 += 1

print(1000*cnt_500+5*cnt_5)

Solution (Python):
X = int(input())

gohyaku = X // 500
X = X - (gohyaku * 500)
goen = X // 5

print(gohyaku * 1000 + goen * 5)

Solution (Python):

money = int(input())


hcnt_500 = money // 500
money = money - (hcnt_500 * 500)
hcnt_5 = (money // 5)
hcnt = (hcnt_500 * 1000) + (hcnt_5 * 5)
print(hcnt)

Solution (Python):
X = int(input())

happy = X // 500 * 1000
happy += X % 500 // 5 * 5

print(happy)

Solution (Python):
X=int(input())

joy=0
joy=(X//500)*1000+((X%500)//5)*5

print(joy)

Solution (Python):
def main():
    x = int(input())

    a = x // 500
    b = (x - (a * 500)) // 5
    c = (a * 1000) + (b * 5)
    print(c)


if __name__ == '__main__':
    main()

Solution (Python):
x=int(input())
ans=0
ans += x//500*1000
x %= 500
ans += x//5*5
print(ans)

Solution (Python):
x = int(input())

a = x // 500
b = (x - (a * 500)) // 5
c = (a * 1000) + (b * 5)
print(c)

Solution (Python):
x = int(input())
v, m = x // 500 * 1000, x % 500
v += m // 5 * 5
print(v)

Solution (Python):
X = int(input())
print(((X//500)*1000) + (X%500)//5*5)

Solution (Python):
x = int(input())

a = x//500
b = x-(a*500)
c = b//5
d = (a*1000)+(c*5)
print(d)

Solution (Python):
n = int(input())
res = 0
a = n // 500
n %= 500
b = n // 5
print(1000*a + 5*b)

Solution (Python):
k = input()
k = int(k)

n1 = 0
n2 = 0

while k >= 500:
    n1 += 1
    k -= 500

while k >= 5:
    n2 += 1
    k -= 5

ans = n1 * 1000 + n2 * 5
print(ans)

Solution (Python):

def main():
    x = int(input())
    sum_m=0
    while x>=500:
        x -= 500
        sum_m+=1000
    while x >=5:
        x -= 5
        sum_m+= 5
    print(sum_m)
if __name__ == "__main__":
    main()

Solution (Python):
money = int(input())

gohyakuen = money // 500

goen = (money-(gohyakuen*500)) // 5

happy = 1000 * gohyakuen + 5 * goen

print(happy)

Solution (Python):
X = int(input())
ans = (X//500)*1000 + ((X%500)//5)*5
print(ans)

Solution (Python):


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)

Solution (Python):
x = int(input())
ans = 0
ans += (x // 500) * 1000
x -= (ans//1000) * 500
ans += (x // 5) * 5
print(ans)

Solution (Python):
n = int(input())
a = n//500
b = n%500
c = b//5
print(1000*a + 5*c)

Solution (Python):
X = int(input())
ans = (X//500)*1000 + ((X%500)//5)*5
print(ans)

Solution (Python):
n = int(input())
c = n // 500
d = n % 500
print(1000 * c + 5 * (d // 5))

Solution (Python):
x = int(input())
print((x//500)*1000+(x%500//5)*5)

Solution (Python):


x = int(input())
fh=x//500
x = x - (500*fh)
f = x//5
print(1000*fh+5*f)

Solution (Python):
x = int(input())

x, xm = divmod(x, 500)
y = xm // 5
print(x*1000 + y*5)

Solution (Python):
x = int(input())
ans = 0
while x >= 500:
    x -= 500
    ans += 1000

while x >= 5:
    x -= 5
    ans += 5
print(ans)

Solution (Python):
x = int(input())
hap = x // 500
hap2 = (x - hap*500)//5
ans = hap*1000 + hap2*5
print(ans)

Solution (Python):
x=int(input())
a = x//500
b = x%500
c = b//5

print(a*1000+c*5)

Solution (Python):
x = int(input())

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

print(hc500 * 1000 + hc5 * 5)

Solution (Python):
x = int(input())
ans = x // 500 * 1000
x = x % 500
ans += x // 5 * 5
print(ans)

Solution (Python):
N=int(input());M=N//500;M*=1000;X=500*(N//500);N-=X;M+=(N//5)*5;print(M)

Solution (Python):
x=int(input())

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

print(a*1000+b*5)

Solution (Python):
x = int(input())
a = x // 500
x %= 500
b = x // 5
print(1000*a + 5*b)

Solution (Python):
n=int(input())
k=n//500
n -= k*500
n //= 5
print(k*1000+n*5)

Solution (Python):
x=int(input())
gohyaku=0
goen=0
while x>5:
    x-=500
    gohyaku+=1
if x==5:
    goen+=1
elif 0<=x<5:
    pass
elif x<0:
    x+=500
    gohyaku-=1
    while x>=5:
        goen+=1
        x-=5
print(gohyaku*1000+goen*5)

Solution (Python):
X=input()
x=int(X)
f=int(x//500)
k=int(x%500)
F=int(k//5)
f*=1000
F*=5
print(f+F)

Solution (Python):
X = int(input())

q, r = divmod(X, 500)
H = q * 1000 + ((r // 5) * 5)
print(H)

Solution (Python):
a=int(input())
b=a//500
c=(a-b*500)//5
print(1000*b+5*c)

Solution (Python):
x = int(input())
print((x // 500) * 1000 + ((x%500)//5)*5)

Solution (Python):
x = int(input())

c_500 = x // 500
r_500 = x % 500
c_5 = r_500 // 5

print(c_500 * 1000 + c_5 * 5)

Solution (Python):
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)

Solution (Python):
x = int(input())
a = x // 500
b = x % 500 // 5
print(a*1000 + b*5)

Solution (Python):
X = int(input())
happy = 0

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

happy += (X // 5) * 5

print(happy)

Solution (Python):

from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def R(n): return [sys.stdin.readline().strip() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [SL() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]

def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]

dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
MOD = 1000000007
INF = float("inf")

sys.setrecursionlimit(1000000)

def main():
    X = I()
    print((X // 500) * 1000 + ((X % 500) // 5) * 5)

if __name__ == '__main__':
    main()

Solution (Python):
X = int(input())
quot1, rem = divmod(X,500)
quot2 = rem // 5
print(quot1*1000 + quot2*5)

Solution (Python):
X = int(input())
ans = 0
if X >= 500:
  ans += (X//500)*1000
  ans += ((X%500)//5)*5
else:
  ans += (X//5)*5
print(ans)

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

Solution (Python):
X = int(input())

a = X // 500
X = X % 500
b = X // 5

print(a*1000+b*5)

Solution (Python):
x=int(input())
print(x//500*1000+x%500//5*5)

Solution (Python):
x = int(input())

h = x // 500 * 1000 + (x % 500) // 5 * 5
print(h)

Solution (Python):
x=int(input())
y=x//500
z=x-y*500
w=z//5
print(1000*y+5*w)

Solution (Python):

X = int(input())
SUM = 0


(X * 1000 / 500)

Z = X // 500
A = X % 500
SUM = SUM + (Z * 1000)

B = A // 5
SUM = SUM + (B * 5)

print(int(SUM))

Solution (Python):
X = int(input())

print(2*X - X%500 - X%5)

Solution (Python):
X = int(input())

A = 0
B = 0

if X >= 500:
    A = X // 500
    X = X % 500
if X >= 5:
    B = X // 5
    X = X % 5

print(A * 1000 + B * 5)

Solution (Python):

X=int(input())

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

print(Happiness)

Solution (Python):
x = int(input())
a = int(x/500) * 1000 + x % 500 - x % 5
print(a)

Solution (Python):
x=int(input())
cnt=0
while x>=500:
    x-=500
    cnt+=1000

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

print(cnt)

Solution (Python):
n=int(input())

if n>=500:
	s=(n//500)*1000
	ans=n-(s//2)
	s+=(ans//5)*5;
	print(s)
	
else:
	print((n//5)*5)

Solution (Python):
import sys
from sys import exit
from math import gcd, factorial, ceil, floor, sqrt
from bisect import bisect_left, bisect_right
from copy import deepcopy
from heapq import heapify, heappop, heappush
from itertools import permutations, combinations, product, accumulate
from collections import defaultdict, deque
sys.setrecursionlimit(10**7)

ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(map(int, input().split()))

X = ii()
a = X//500 * 1000
b = (X-X//500*500)//5 * 5
print(a+b)

Solution (Python):
x = int(input())

print((x // 500) * 1000 + (x % 500) //5 * 5)

Solution (Python):
X=int(input())

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

Solution (Python):
x = int(input())
count_500 = 0
count_5 = 0
count_500 = x // 500
x -= 500 * count_500
count_5 = x // 5
x -= 5 * count_5
print(1000 * count_500 + 5 * count_5)

Solution (Python):
X = int(input())
A = X // 500
B = X % 500

C = B // 5

ans = A * 1000 + C * 5
print(ans)

Solution (Python):
X = int(input())

p = X // 500
q = X % 500
r = q // 5

print(p*1000+r*5)

Solution (Python):
X=int(input())
a=int(X/500)
s=1000*a
X-=500*a
b=int(X/5)
s+=5*b
print(s)

Solution (Python):
def main():
    x = int(input())

    coin_500 = x // 500
    coin_5 = x % 500 // 5

    ans = coin_500 * 1000 + coin_5 * 5

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
X = int(input())
print(1000 * (X // 500) + 5 * ((X - 500 * (X // 500)) // 5))

Solution (Python):
n = int(input())

shou500 = n//500

shou5 = (n-shou500*500)//5

print(shou500*1000+shou5*5)

Solution (Python):
x=int(input())
num=x//500
ans=1000*num
x-=500*num
ans+=5*(x//5)
print(ans)

Solution (Python):
X=int(input())
sen=X//500
X=X%500
go=X//5
print(1000*sen + 5*go)

Solution (Python):
x = int(input())
y500 = x//500
x -= y500*500
y5 = x//5
print(y500*1000+y5*5)

Solution (Python):


import sys
def I(): return int(sys.stdin.readline().rstrip())

X = I()
print(1000*(X//500) + 5*((X % 500)//5))

Solution (Python):
N = int(input())
div,mod = divmod(N,500)
div2 = mod//5
print(1000*div + 5*div2)

Solution (Python):
X = int(input())

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

Solution (Python):
X = int(input())
print(X//500*1000 + X%500//5*5)

Solution (Python):
x=int(input())
a=x//500
x=x%500
b=x//5
print(1000*a+5*b)

Solution (Python):
n = int(input())
print(n // 500 * 1000 + n % 500 // 5 * 5)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

X = int(input())
big_coin, amari = divmod(X, 500)
print(big_coin*1000+(amari//5)*5)

Solution (Python):
x = int(input())
count = 0

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

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

print(count)

Solution (Python):
x=int(input())
a=x//500
b=x%500
c=b//5
print(1000*a+5*c)

Solution (Python):
import sys

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

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

Solution (Python):
X = int(input())
a = X//500
b = X%500
c = b//5
print(a*1000+c*5)

Solution (Python):
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  
def LS2(): return list(sys.stdin.readline().rstrip())  

X = I()
X -= X % 5
X //= 5
print(1000*(X//100) + 5*(X % 100))

Solution (Python):
N = int(input())
ans = N//500 * 1000
N = N%500
ans += N//5 * 5
print(ans)

Solution (Python):
x = int(input())

div, mod = divmod(x, 500)

print(div * 1000 + mod // 5 * 5)

Solution (Python):
x=int(input())

cnt = x//500

x-=cnt*500

print(5*(x//5) + 1000*cnt)

Solution (Python):
def LI():
    return list(map(int, input().split()))


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

Solution (Python):
X = int(input())
n = X//500
m = (X%500)//5
print(1000*n+5*m)

Solution (Python):
x=int(input())
ans=(x//500)*1000
x%=500
ans+=(x//5)*5
print(ans)

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

Solution (Python):
x=int(input()) 
a=x//500
rem=x%500
b=rem//5
ans=a*1000+b*5
print(ans)

Solution (Python):
X=int(input())
ans=1000*(X//500)+5*((X-(X//500*500))//5)
print(ans)

Solution (Python):

import sys
import numpy as np

n = int(input())
ans = (n // 500) * 1000
n -= (n // 500) * 500
ans += (n // 5) * 5
print(ans)

Solution (Python):



from fractions import gcd
from itertools import combinations,permutations,accumulate, product 

from collections import deque,defaultdict,Counter
import decimal
import re
import math















import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7


from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
  return int(readline())
n = I()
m500 = n//500
n -= 500 * m500
m5 = n//5
print(1000 * m500 + m5 * 5)

Solution (Python):

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

Solution (Python):
x = int(input())
ans = 0

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

print(ans)

Solution (Python):
X = int(input())
ans = 0
ans += (X // 500) * 1000
X %= 500
ans += (X // 5) * 5
print(ans)

Solution (Python):
X = int(input())
Y = X//500
Z = (X-Y*500)//5
print(Y*1000+Z*5)

Solution (Python):
n = int(input())
ans = 0
ans += n // 500 * 1000
n %= 500
ans += n // 5 * 5
print(ans)

Solution (Python):
X = int(input())
ans = X//500*1000
X = X % 500
ans += X//5*5
print(ans)

Solution (Python):
X = int(input())
n = X//500
m = X%500
n1 = m//5
print(n*1000+n1*5)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inl = lambda: [int(x) for x in sys.stdin.readline().split()]
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))


def solve():
    x = ini()
    a = x // 500
    ans = a * 1000
    x %= 500
    b = x // 5
    ans += b * 5
    debug(a, b)
    return ans


print(solve())

Solution (Python):
x = int(input())
q, r = divmod(x, 500)
ans = q*1000
ans += (r//5)*5
print(ans)

Solution (Python):
x = int(input())
ans = x//500 * 1000
x -= x//500 * 500
ans += x//5 * 5
print(ans)

Solution (Python):
x=int(input())  
a=x//500
rem=x-a*500
b=rem//5
ans=a*1000+b*5
print(ans)

Solution (Python):
n = int(input())
s = n//500
m = n%500
x = m//5
r = s*1000
c = x*5
print(r+c)

Solution (Python):
x = int(input())
c500 = x //500
r500 = x % 500
c5 = r500 //5
print(c500*1000+c5*5)

Solution (Python):
x=int(input())
n=x//500
m=x%500//5
ans=1000*n+5*m
print(ans)

Solution (Python):
X = int(input())

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

Solution (Python):
s = int(input())

c = s // 500
d = s % 500

e = d //5

h = c*1000 + e*5

print(h)

Solution (Python):
X = int(input())
n = X//500
m = X % 500//5
ans = n*1000 + m*5
print(ans)

Solution (Python):
X = int(input())

num_500 = X // 500
num_5 = (X % 500) // 5

print(1000 * num_500 + 5 * num_5)

Solution (Python):
x = int(input())

result = 1000 * (x // 500)
x -= 500 * (x // 500)
result += 5 * (x // 5)
print(result)

Solution (Python):
X = int(input())

c500 = X // 500
c5 = (X -(c500 * 500)) // 5
answer = (c500 * 1000) + (c5 * 5)

print(answer)

Solution (Python):
x=int(input())
print(x//500*1000+(x%500)//5*5)

Solution (Python):
X=int(input())
print((X//500)*1000+((X%500)//5)*5)

Solution (Python):
def resolve():
    X = int(input())
    ans = (X//500)*1000
    ans += ((X%500)//5)*5
    print(ans)


if '__main__' == __name__:
    resolve()

Solution (Python):
X=int(input())
h500=X//500
h5=(X-h500*500)//5
print(h500*1000+h5*5)

Solution (Python):
x = int(input())
a = x//500
b = x%500
c = b//5
print(a*1000 + c*5)

Solution (Python):
X = int(input())

happiness = 0
X_remaining = X

happiness = happiness + (int(X_remaining / 500)*1000)
X_remaining = X_remaining % 500

happiness = happiness + (int(X_remaining / 5)*5)

print(happiness)

Solution (Python):
money=int(input())
s=int(money/500)
print(s*1000+int((money-500*s)/5)*5)

Solution (Python):
x = int(input())
yen500 = x//500
yen5 = (x%500)//5
print(1000*yen500 + 5*yen5)

Solution (Python):
X = int(input())

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

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

Solution (Python):
x = int(input())
ans = 0
if x >= 500:
    ans += (x//500)*1000
    x -= (x//500)*500
if x >= 5:
    ans += (x//5)*5
print(ans)

Solution (Python):
x = int(input())

money1 = x // 500
x %= 500
money2 = x // 5

ans = money1 * 1000 + money2 * 5
print(ans)