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())
x_500 = int(x / 500)
x_5 = int((x - 500 * x_500) / 5)

happy = x_500 * 1000 + x_5 * 5

print(happy)

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

x, y = X // 500, X % 500
z = y // 5
print(1000 * x + 5 *z)

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

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

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

print(a*1000 + 5*b)

Solution (Python):
if __name__ == "__main__":
    x = int(input())
    ans = 0

    if x >= 500:
        tmp = x // 500
        ans += tmp * 1000
        x = x % 500
    
    if x >= 5:
        tmp = x // 5
        ans += tmp * 5
    
    print(ans)

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

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

Solution (Python):
coins = int(input())
happiness = 0


def happiness_point(remainder, num, point, all_point):
    result = divmod(remainder, num)
    all_point += result[0] * point
    remainder = result[1]
    return remainder, all_point


if coins / 500 >= 1:
    coins, happiness = happiness_point(coins, 500, 1000, happiness)

if coins / 5 >= 1:
    coins, happiness = happiness_point(coins, 5, 5, happiness)

print(happiness)

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

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

Y = X//500
Z = (X - Y*500)//5
X = Y*1000 + Z*5
print(X)

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

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

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

print(ans)

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

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

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

a = 0


gold_coin = [500,5]
point = [1000,5]

for i in range(2):
    a = a + (X//gold_coin[i])*point[i]
    X = X%gold_coin[i]

print(a)

Solution (Python):
X = input()
X = int(X)
y = X//500
z = X%500
a = z//5 

A = 1000*y+5*a
print(A)

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

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

print(ans)

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

else:
    print((X//5)*5)

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

Solution (Python):
from __future__ import print_function

import sys
sys.setrecursionlimit(500000)

import re
import array
import copy
import functools
import operator

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd

import collections
import itertools
import bisect

import random
import time

import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
from queue import Queue

from itertools import accumulate

from collections import deque
from collections import Counter

from operator import mul
from functools import reduce

input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


def lcm(n, m):
    return int(n * m / gcd(n, m))


def coprimize(p, q):
    common = fractions.gcd(p, q)
    return (p // common, q // common)


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def find_gcd(list_l):
    x = reduce(gcd, list_l)
    return x


def main():
    n = int(input().strip())
    print(n//500*1000+n%500//5*5)


if __name__ == '__main__':
    main()

Solution (Python):
x = int(input())
fh , mod = divmod(x , 500)
f , mod = divmod(mod , 5)
ans = (fh * 1000) + (f * 5)
print(ans)

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

Solution (Python):
import math
a = int(input())
a1 = math.floor(a / 500)
a2 = a % 500
a3 = math.floor(a2 / 5)

print(a1 * 1000 + a3 * 5)

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

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


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

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

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

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

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

gh = X//500
g = X%500//5

print(gh * 1000 + g * 5)

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

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

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

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

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

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

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

print(a*1000 + b*5)

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

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

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

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

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

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

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

ans = 0

while n >= 500:
    n -= 500
    ans += 1000
while n >= 5:
    n -= 5
    ans += 5

print(ans)

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

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

print(a*1000+5*b)

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


X1 = X // 500
X2 = X % 500
X3 = X2 // 5

cnt = X1 * 1000 + X3*5

print(cnt)

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

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

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

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

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

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

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

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

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

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

Solution (Python):
x = int(input())
n500 = 0
n5 = 0
n500 = x // 500
x = x - n500*500
n5 = x // 5
x = x - n5*5

print(1000*n500 + 5*n5)

Solution (Python):
def nyu():
    X= int(input())
    return X


def check(X ):
    sum = 0

    x = X

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


            
X = nyu()
check(X)

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

Solution (Python):
X = int(input())
counta = 0
countb = 0
while X>=500:
  counta +=1
  X -= 500
  
while X>=5:
  countb +=1
  X -= 5
print(1000*counta+5*countb)

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

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

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

print(coin_500*1000 + coin_5*5)

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

i = 0
while a >= 500:
    i = i+1
    a = a-500

j = 0
while a >= 5:
    j = j+1
    a = a-5

print(1000*i+5*j)

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

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

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

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

print(p)

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

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

Solution (Python):
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    X = int(_in[0])  
    
    cnt = (X//500)*1000+((X%500)//5)*5
    
    print(cnt)

Solution (Python):
x =int(input())
total =0
count =0
for i in range(x):
    if 500*i ==x:
        count =i*1000
        break
    elif 500*i > x:
        total =abs(500*(i-1) -x)
        count =(i-1) *1000
        
        break
if total ==0:
    print(count)
else:
    for i in range(x):
        if 5*i ==total:
            count +=i*5
            break
        elif 5*i >total:
            count +=(i-1)*5
            break
    print(count)

Solution (Python):
x =int(input())
total =0
count =0
for i in range(x):
    if 500*i ==x:
        count =i*1000
        break
    elif 500*i > x:
        total =abs(500*(i-1) -x)
        count =(i-1) *1000
        
        break
if total ==0:
    print(count)
else:
    for i in range(x):
        if 5*i ==total:
            print("aa")
            count +=i*5
        elif 5*i >total:
            count +=(i-1)*5
            
            
            break
    print(count)

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

count_500 = 0
count_5 = 0
if X >= 500:
    count_500 += int(X/500)
    X = X%500
    if X >= 5:
        count_5 += int(X/5)
        X = X%5
else:
    count_5 += int(X/5)
    X = X%5

print(count_500*1000 + count_5*5)

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

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

Solution (Python):
import math
X=int(input())
fun=0

fh=math.floor(X/500)
rest=X-(fh*500)
f=math.floor(rest/5)
fun=fh*1000+f*5

print(fun)

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

Solution (Python):
money = int(input())
 
max500 = money // 500
rem500 = money % 500
 
max5 = rem500 // 5
 
happiness = max500 * 1000 + max5 * 5
 
print(happiness)

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

A = N//500
B = (N-A*500)//5

print(A*1000+B*5)

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

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

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

Solution (Python):

x = int(input())


div_500 = x // 500
div_5 = (x - div_500 * 500) // 5


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

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

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

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

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

Solution (Python):
x = int(input())
ans = 0
ans = ans + int(x/500)*1000
x = x- int(x/500)*500
ans = ans + int(x/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())
print(X//500*1000+(X-X//500*500)//5*5)

Solution (Python):
def happinessCalculator(money):
	points = 0
	if money == 0:
		return points
	while money >= 500:
		money -= 500
		points += 1000
	while money >= 5:
		money -= 5
		points += 5
	return points

print(happinessCalculator(int(input())))

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

Solution (Python):



X = int(input())

n_500, n_5 = 0, 0
rem = 0

n_500 = X // 500
rem = X % 500
n_5 = rem // 5
print(n_500 * 1000 + n_5 * 5)

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

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

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

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

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

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

Solution (Python):
money = int(input())
five_hun = money // 500
remainder = money % 500
five = remainder // 5
remainder = remainder % 5
print(five_hun * 1000 + five * 5)

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

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

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

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

happy_500 = 0
if X>=500:
    happy_500 = X//500
X = X-happy_500*500
happy_5 = 0
if X>=5:
    happy_5 = X//5
print(happy_500*1000+happy_5*5)

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

print(a * 1000 + b * 5)

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

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

A = N // 500
B = (N % 500) // 5

print(int(A)*1000 + int(B)*5)

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

Solution (Python):

import sys
input = sys.stdin.buffer.readline


from collections import defaultdict

con = 10 ** 9 + 7

def getlist():
	return list(map(int, input().split()))


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

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

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

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

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

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

Solution (Python):
X = int(input())
happy = 0
d_500, m_500 = divmod(X, 500)
d_5, m_5 = divmod(m_500, 5)
print(d_500 * 1000 + d_5 * 5)

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

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

print(ans)

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

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

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

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

print(int(Y*1000+Z*5))

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

Solution (Python):

url = "https://atcoder.jp//contests/abc160/tasks/abc160_b"

def main():
    N = int(input())
    n, m = divmod(N, 500)
    
    print((1000 * (N // 500)) + (5 * ((N % 500) // 5)))

if __name__ == '__main__':
    main()

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

Solution (Python):
import math
X=int(input())
f_hand=math.floor(X/500)
amari=X%500
go=math.floor(amari/5)
happy=f_hand*1000+go*5
print(happy)

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

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


hap = x // 500
ppy = (x - hap * 500) // 5

print(hap * 1000 + ppy * 5)

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

Solution (Python):
n = int(input())
s = [500,5]
y = [1000,5]
cnt = 0
for i in range(2):
        t = n//s[i]
        n -= t*s[i]
        cnt += t*y[i]

    

print(cnt)

Solution (Python):

def main():
	happy_count = 0
	money = int(input())
	happy_count = (money // 500) * 1000
	money -= (money//500) * 500
	happy_count += (money//5) * 5
	print(happy_count)
		

if __name__ == "__main__":
	main()

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

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

print(a*1000+b*5)

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

print(ans)

Solution (Python):
x = int(input())
BG, mod = divmod(x, 500)
SG = mod// 5
HP = BG * 1000 + SG * 5
print(HP)

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

q = X // 500
mod = X % 500

mmod =  mod // 5
mmmod = mmod * 5

print(mmmod+q*1000)

Solution (Python):


def main():
    *X, = map(int, open(0).read().split())
    
    a = X[0] // 500
    
    b = (X[0] % 500) // 5
    
    H = a * 1000 + b *5
    print(H)



main()

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

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

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

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

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)*1000
y=x%500
b=(y//5)*5
print(a+b)

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

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

max = 0
for i in range(X//500+1):
    happy = 1000*i + ((X-500*i)//5)*5
    if max < happy:
        max = happy

print(max)

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

print(a+b)

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

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

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

coins500 = int(money/500)
coins5 = int(int(money%500)/5)

happiness = (coins500*1000)+(coins5*5)

print(happiness)

Solution (Python):
N = int(input())
fiveh = (N-(N%500))/500
tfiveh = fiveh*(1000)
five = ((N%500)-((N%500)%5))/5
tfive = five*5
print(int(tfiveh)+int(tfive))

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

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

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

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

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

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

c_500=0
c_5=0


while x >= 500:
    x = x - 500
    c_500 += 1

while x >= 5:
    x = x- 5
    c_5 += 1



happy = c_500*1000 + c_5 * 5

print(happy)

Solution (Python):
x=int(input())
print((x//500)*1000+((x-(500*(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())
joy = X//500*1000
X = X%500
joy += X//5*5

print(joy)

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

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


if __name__ == "__main__":
    main()

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

h500 = (X // 500) * 1000
h5 = ((X % 500) // 5) * 5

print(h500 + h5)

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

happy = 0

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

happy += int(X/5) * 5

print(happy)

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

print(int(a*1000+c*5))

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

Solution (Python):

x = int(input())

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

Solution (Python):


import sys
import math

sys.setrecursionlimit(10 ** 6)

input_line = input()
x = int(input_line)

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

ans += (x // 5) * 5

print(ans)

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

points = 0

points += 1000 * (X//500)



if X > (X//500)*500:
    tm = X - (X//500)*500
    points += 5 * ((tm)//5)

print(points)

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

d_500, m = divmod(X, 500)
d_5, m = divmod(m, 5)
print(d_500 * 1000 + d_5 * 5)

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


quot = x//500
rem = x%500

print((1000 * quot) + (rem//5 * 5) )

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

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

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

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

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

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

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

print(1000 * a + 5 * b)

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

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

print(1000 * a + 5 * b)

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

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

Solution (Python):
import math
x = int(input())
ans500 = math.floor(x / 500) * 1000
ans5 = math.floor((x % 500) / 5) * 5
print(ans500 + ans5)

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

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

Solution (Python):
x = int(input())
r = x % 500
a = x // 500

b = r // 5

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

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

num_of_five_hundred, rest = divmod(money, 500)
num_of_five = int(rest / 5)

print(num_of_five_hundred*1000 + num_of_five*5)

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

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

Solution (Python):
X=int(input())
ans,cal,cal2=0,0,0

while(X>=5):
    if X>=500:
        X=X-500
        cal+=1
    else :
        X=X-5
        cal2+=1


ans=cal*1000+cal2*5

print(ans)

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

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

Solution (Python):
n=int(input())
ans=0
ans+=(n//500)*1000
n=n%500
ans+=(n//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())
count = 0

while (x >= 500):
    count += 1000
    x = x-500
while (x >= 5):
    if x > 5:
        count += 5
        x = x-5
print(count)

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


if __name__ == "__main__":
    main()

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

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

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

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

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

fh = x//500
f = (x - fh*500)//5

print(int(fh*1000 + f*5))

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

Solution (Python):
X=int(input())
ha=0
while (X>=500):
  ha+=1000
  X-=500

while(X>=5):
  ha+=5
  X-=5
  
print(ha)

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

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

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

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

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

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

print(a*1000+b*5)

Solution (Python):
class atcorder:
    
    money=int(input())
    
    a=money/500
    b=money%500
    c=b/5
    ans=int(a)*1000+int(c)*5
    print(ans)

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

Solution (Python):

DATA = """
1000000000
""".split("\n")

def get_debug_line():
	for i in DATA:
		yield i

if 1:
	get_line = input
else:
	get_line = get_debug_line().__next__
	get_line()

X = [int(i) for i in get_line().strip().split(" ")][0]

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

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

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

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

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

Solution (Python):
x= int(input())
eq=0
eq= x//500
eq2= eq*1000
eq3= x%500
eq4= eq3//5
eq5= eq4*5
print(eq2+eq5)

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

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

Solution (Python):
def main():

    X = int(input())
    ans = 1000*(X // 500) + 5 *((X - X//500 *500) // 5)
    return ans

if __name__ == '__main__':
    print(main())

Solution (Python):
def main():

    X = int(input())
    ans = 1000*(X // 500) + 5 *((X - X//500 *500) // 5)
    return ans

if __name__ == '__main__':
    print(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())
print((x//500)*1000+x%500//5*5)

Solution (Python):

import sys
sys.setrecursionlimit(10**8)
INF = float("inf")


def solve(X: int):
    ans = 0
    ans += (X // 500)*1000
    X = X % 500
    ans += (X//5)*5
    print(ans)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  
    solve(X)


if __name__ == '__main__':
    main()

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

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

q1, mod1 = divmod(x, 500)
q2, mod2 = divmod(mod1, 5)

print(q1*1000 + q2*5)

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

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

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

happy = 0
th = num//500


happy = happy + 1000*th
num = num - 500*th

fv = num//5

happy = happy + fv*5

print(happy)

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

num_500 = x // 500
num_5 = x % 500 // 5
happy = 1000 * num_500 + 5 * num_5
print(happy)

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

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

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

print(a*1000+b*5)

Solution (Python):
from sys import stdin

X = list(map(int, (stdin.readline().strip().split())))[0]
count=0
while(True):
    num=0
    if X//500>=1:
        num=X//500
        X-=500*num
        count+=1000*num
        continue
    if X//5>=1:
        num=X//5
        X -= 5 * num
        count += 5*num
    else:break
print(count)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
 
X = INT()
ans = X//500*1000

X = X%500
ans += X//5*5

print(ans)

Solution (Python):
def f(x):
    joy = x // 500 * 1000
    x %= 500
    joy += x // 5 * 5
    print(joy)

x = int(input())
f(x)

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

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

u = 1000*a + 5*c
print(u)

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

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

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

Solution (Python):
N = int(input())
cnt = 0
A = N//500
B = (N%500)//5


print((A*1000)+(B*5))

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

happy=0

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

print(happy)

Solution (Python):
x = int(input())
if x == 0:
    print(0)
else:
    happiness = 0

    y500 = x // 500
    happiness += y500 * 1000

    x -= 500 * (x//500)

    y5 = x // 5
    happiness += y5 * 5
    x -= 5 * (x // 5)

    print(happiness)

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

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

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

Solution (Python):
pt_500 = 1000
pt_5 = 5
pt_sum = 0

money = int(input())

pt_sum = pt_sum + (money//500)*pt_500 + ((money%500)//5)*pt_5

print(pt_sum)

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

ans = 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())
print(x // 500 * 1000 + x % 500 // 5 * 5)

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

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

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

h = 0

while x != 0:
    if x >= 500:
        h += 1000
        x -= 500
        continue
    elif x >= 5:
        h += 5
        x -= 5
    else:
        break
        
print (h)

Solution (Python):


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

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

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

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

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

tot+=(s//500)*1000
s-=tot/2
tot+=(s//5)*5

print(str(int(tot)))

Solution (Python):
inp = input()
inp1 = int(inp)
gohyaku = inp1 // 500
amari = inp1 % 500
gozyu = amari // 5
print(gohyaku * 1000 + gozyu * 5)