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())

five_hundred_yen = int(x/500)
five_yen = int((x-five_hundred_yen*500)/5)

print(five_hundred_yen*1000 + five_yen*5)

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

Solution (Python):
X = int(input())
count_five_hundred = int(X // 500)
count_five = int((X % 500) // 5)

max_happiness = count_five_hundred * 1000 + count_five * 5

print(max_happiness)

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

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

happy = 0

while X>=0:
  X -= 500
  happy += 1000

X += 500
happy -= 1000

while X>=0:
  X -= 5
  happy += 5
  
happy -= 5
  
print(happy)

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

Solution (Python):

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

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

Solution (Python):
import sys
readline=sys.stdin.buffer.readline
s=int(readline().rstrip())
print((s//500)*1000 + ((s%500)//5)*5)

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

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

check1, mod = divmod(X, 500)
check2, mod = divmod(mod, 5)
ans = 1000 * check1 + 5 * check2
print(ans)

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

p = 0
p += 1000*(x//500) + 5*((x%500)//5)

print(p)

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

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

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

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

en500 =0
amari = 0
en5 =0

kotae= divmod(kingaku,500)
en500 = int(kotae[0]) * 1000
amari = int(kotae[1])

kotae2= divmod(amari,5)
en5 = kotae2[0] *5

print(en500+en5)

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

Solution (Python):
money = int(input())
happy = 0
while 500 <= money:
  money -= 500
  happy += 1000
while 5 <= money:
  money -= 5
  happy += 5
print(happy)

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

if money_val < 5:
    print(0)
elif money_val < 500:
    print((money_val // 5)*5)
else:
    fivehun_num = (money_val // 500)
    five_num = money_val - (500*fivehun_num)
    five_num = five_num // 5
    print((fivehun_num*1000) + (five_num*5))

Solution (Python):


total = int(input())

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

point = a*1000 + b*5

print(point)

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

ureshisa = input_money//500 * 1000
input_money = input_money%500

if input_money > 0:
    ureshisa += input_money//5 * 5
    input_money = input_money%5

print(ureshisa)

Solution (Python):
def solve():
    N = int(input())
    a = N//500
    s = str(N)
    b = (N - a * 500) // 5

    return a*1000 + b*5

print(solve())

Solution (Python):
input_line = int(input())
Hcounter = 0
tmp = input_line

for i in range(input_line,499,-500):
  Hcounter+= 1000
  tmp -= 500

for j in range(tmp,4,-5):
  Hcounter+= 5

print(Hcounter)

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

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

happiness = 0

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

print(happiness)

Solution (Python):
import math
x = int(input())
ans = 0
if math.floor(x/500) >=1 :
    ans += math.floor(x/500)*1000
    x -= math.floor(x/500)*500
if x > 0 and math.floor(x/5) >=1 :
    ans +=  math.floor(x/5)*5
print(ans)

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

sho, ama = divmod(a,500)
sho2, ama2 = divmod(ama,5)

print( sho*1000+sho2*5 )

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

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

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

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

x -= 500 * (x // 500)

ans += (x // 5) * 5

print(ans)

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

x =int( x - (x%5))
y =int( x - (x%500))

z =int( y*2 + x%500)

print(z)

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

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

n1 = int(s / 500)
n1_re = int(s % 500)

n2 = int(n1_re / 5)

result = (n1 * 1000) + (n2 * 5)

print(result)

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

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

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

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

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

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

Solution (Python):
s = int(input())
q, mod = divmod(s, 500)
q2, mod2 = divmod(mod, 5)
print(q*1000+q2*5)

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

print(1000*a + 5*b)

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

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

y = x // 500
z = (x - y*500) // 5

ans = y * 1000 + z * 5
print(ans)

Solution (Python):
x = int(input())
n_500yen = 0
n_5yen = 0

n_500yen = x // 500
amari = x % 500

n_5yen = amari // 5

presure = 1000 * n_500yen + 5 * n_5yen
print(presure)

Solution (Python):
input=input()
oq, omod = divmod(int(input), 500)
tq, tmod = divmod(int(omod), 5)
to=oq*1000
tt=tq*5
t=to+tt
print(t)

Solution (Python):
X = int(input())
dama500 = X // 500
dama5 = (X - dama500 * 500) // 5

print(dama500 * 1000 + dama5 * 5)

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

Solution (Python):
happy=0

input=int(input())
happy500=(input//500) * 1000
change=input%500
happy5=(change//5) * 5
happy=happy500+happy5
print(happy)

Solution (Python):
s = int(input())
data = [500, 5, 100, 50, 10, 1]
ans = []
if s == 0:
    print(0)
    quit()
for i in range(len(data)):
    r = s // data[i]
    ans.append(r)
    s %= data[i]
print(ans[0]*1000 + ans[1]*5)

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

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

if(x == 0):
    print(0)
else:
    x500 = (x // 500) * 1000
    x5 = ((x % 500) // 5) * 5
    print(x500 + x5)

Solution (Python):
c2u = {
    500: 1000,
    100: 0,
    50: 0,
    10: 0,
    5: 5,
    1: 0
}

X = int(input())

X0 = X
coin = {}
if X0 // 500 > 0:
    coin[500]  = X0 // 500
    X0 -= 500 * coin[500]
if X0 // 5 > 0:
    coin[5]  = X0 // 5
    X0 -= 5 * coin[5]
if X0 // 100 > 0:
    coin[100]  = X0 // 100
    X0 -= 100 * coin[100]
if X0 // 50 > 0:
    coin[50]  = X0 // 50
    X0 -= 50 * coin[50]
if X0 // 10 > 0:
    coin[10]  = X0 // 10
    X0 -= 10 * coin[10]
coin[1] = X0

u = 0
for k, v in coin.items():
    u += c2u[k] * v
print(u)

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

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


if a<500:
  a//=5
  a*=5
  print(a)
    
    
  
else:
  c=a//500
  d=c*500
  e=d*2
  a-=d
  a//=5
  a*=5
  print(a+e)

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

if(X>=500):
    n=X//500
    point1=n*1000
    X=X-500*n
else:
    point1=0

d=X//5
point2=d*5

sum=point1+point2
print(sum)

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


a = int(data / 500)
h = a * 1000

data = data - 500 * a

b = int(data / 5)
h += b * 5

print(h)

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

a = 0
b = 0
t = 0

if X >= 500:
    a = X//500
    t = X%500
    if t != 0:
        b = t//5

else:
    b = X//5

print(1000*a+5*b)

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

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

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

ans = 0
ans = a*1000 + b*5

print(ans)

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

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

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

Solution (Python):
input_line = int(input())
Hcounter = 0
tmp = input_line

for i in range(input_line,499,-500):
  Hcounter+= 1000
  tmp -= 500

for j in range(tmp,4,-5):
  Hcounter+= 5

print(Hcounter)

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

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

a = S // int(500)

b = S - a * 500

c = b // 5

print(a*1000 + c*5)

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

now=X
ans=0
ans+=1000*(now//500)


now=now%500

ans+=5*(now//5)

print(ans)

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

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

y = x%500
z = x - y
hap = 0

while z >= 500:
  z -= 500
  hap += 1000
  
while y >= 5:
  y -= 5
  hap += 5
  
print(hap)

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
from re import split
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce
from copy import deepcopy
import re

sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7

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

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

def calc(number, coin):
  n = number // coin
  amari = number % coin
  return n, amari


n500, amari = calc(X, 500)
n5, amari = calc(amari, 5)

print('{}'.format(n500 * 1000 + n5 * 5))

Solution (Python):

X = int(input())

coin_500 = X // 500
mod = X % 500

coin_5 = mod // 5

print(1000 * coin_500 + 5 * coin_5)

Solution (Python):
X = input()

x = int(X)

gosen = x // 500

goen = (x - 500* gosen) // 5

happy = gosen * 1000 + goen * 5

print(happy)

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

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

print(happy)

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

Solution (Python):
import sys


x = int(input())
x1 = x // 500
x %= 500
x2 = x // 5

ans = 1000 * x1 + 5 * x2
print(ans)

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

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

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

a = math.floor(x/500)
a_1000 = a*1000

amari = x % 500
b = math.floor(amari/5)
b_5 = b*5

print(a_1000 + b_5)

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

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

Solution (Python):

x = input()
x = int(x)

happy = 0

if 500 <= x :
    sho_a = (x // 500)
    happy = sho_a * 1000
    x = x - (sho_a * 500)
    sho_b = x // 5
    happy = happy + sho_b * 5
else : 
    sho_b = x // 5
    happy = sho_b * 5

print(happy)

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

Solution (Python):
a = int(input())
A = a%500
b = a//500
c = a-(b*500)
d = c//5

X = (a/500)*1000
Y = b*1000 + d*5
Z = (a//5)*5

if a == 0:
    print(0)
elif a < 5:
    print(0)
elif A == 0:
    print(int(X))
elif b>0 and d > 0:
    print(int(Y))
elif b>0 and d < 0:
    print(int(b*1000))
elif b == 0 and d > 0:
    print(int(Z))
elif b == 0 and d < 0:
    print(0)

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

Solution (Python):
def coins(c):
    if c>= 500:
        c1 = c//500
        c2 = (c-500*c1)//5
        
        s = c1*1000 + c2*5
        print(s)
    else:
        c2 = c//5
        print(c2*5)

def io():
    c = int(input())
    coins(c)

if __name__=='__main__':
    io()

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

five_hundred_coin = (num // 500)
rest = (num % 500)
five_coin = (rest // 5)

presure = (five_hundred_coin * 1000) + (five_coin * 5)

print(presure)

Solution (Python):
import bisect,collections,copy,itertools,math,string
def I(): return int(input())
def S(): return input()
def LI(): return list(map(int,input().split()))
def LS(): return list(input().split())

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

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

a = [500, 5, 100, 50, 1]
b = [0, 0, 0, 0, 0]

for i in range(5):
    b[i] = x // a[i]
    x = x % a[i]

print(b[0] * 1000 + b[1]*5)

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

happiness = 0
if X >= 500:
    happiness += (X//500)*1000
    X = X%500
happiness += (X//5)*5

print(happiness)

Solution (Python):
money = int(input())
fh = money // 500
money -= 500 * fh
goen = money // 5

point = 1000 * fh + 5 * goen
print(point)

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

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

n500 = X // 500

X = X % 500

n5 = X // 5

print(n500 * 1000 + n5 * 5)

Solution (Python):
N=int(input())
big=N/500
ans=1000*int(big)
small=500*(big-int(big))
while True:
	if small>5:
		ans+=5
		small-=5
	else:
		break
print(ans)

Solution (Python):
sum = int(input())
golds = [500, 5]

happy = 0
for gold in golds:
    if gold == 500:
        happy += 1000 * (sum // gold)
    if gold == 5:
        happy += 5 * (sum // gold)
    sum = sum % gold

print(happy)

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

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

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

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

Solution (Python):
X = int(input())
remain = X
if X // 500 != 0:
    a = remain // 500
    remain = X - 500*a
else:
    a = 0
if remain // 5 !=0:
    b = remain // 5
    remain == b + remain % 5
else:
    b = 0
result = 1000*a + 5*b 
print(str(result))

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

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

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

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

print(1000*a+5*b)

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

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

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

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

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

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

num_500 = X // 500
num_5 = (X - num_500 * 500) // 5

print(num_500 * 1000 + num_5 * 5)

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

if X >= 500:
    a, b = divmod(X, 500)
    if b >= 5:
        c, d = divmod(b, 5)
    else:
        c = 0
else:
    a = 0
    c, d = divmod(X, 5)

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

Solution (Python):
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007



def main():
	money = int(input())
	num_gohyaku = money // 500
	nokori = money%500
	num_five  = nokori // 5
	shiawase = num_gohyaku * 1000 + num_five * 5
	print(shiawase)
	
	

isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)

Solution (Python):
import sys
input = sys.stdin.readline
X = input()
intx = int(X)

gohyakuX = int(intx / 500)
nokori = intx - (gohyakuX * 500)
nokoriX = int(nokori / 5)

result = gohyakuX * 1000 + nokoriX * 5
print(result)

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

a500, mod500 = divmod(i, 500)
a5, mod5 = divmod(mod500, 5)
print (a500 * 1000 + a5 * 5)

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


ans = 0
flag = True
flag2 = True

while flag:

    if N < 500:
        flag = False
    else:
        ans += 1000
        N-= 500

while flag2:

    if N < 5:
        flag2 = False
    else:
        ans+=5
        N -= 5

print(ans)

Solution (Python):
import math


num = int(input())


c_500 = math.floor(num / 500)
num2 = num - c_500 * 500

c_5 = math.floor(num2/5)



print(c_500 * 1000 +c_5 * 5)

Solution (Python):
x = int(input())
list = [500, 5,100, 50, 10, 1]
ans_list = [0, 0, 0, 0, 0]
for i in range(5):
    ans_list[i] = int(x / list[i])
    x -= (list[i] * ans_list[i])
ans = ans_list[0] * 1000 + ans_list[1] * 5
print(ans)

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

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



print(a*1000+b*5)

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

b = math.floor(a / 500)

c = math.floor(a % 500)

d = math.floor(c / 5)

e = b * 1000 + d * 5
print(e)

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

ureshisa = 0

ureshisa += x//500*1000

amari = x%500

ureshisa += amari//5*5

print(ureshisa)

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

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

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

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

coi = [500, 5]
ans = 0
for i in coi:
    y = x//i
    x -= i * y
    if i == 500:
        ans += 1000 * y 
    elif i == 5:
        ans += 5 * y
print(ans)

Solution (Python):
x = int(input())
happy = 0
while x >= 500 :
    happy += 1000 * int(x/500)
    x = x%500


while x >= 5 :
    happy += 5 * int(x/5)
    x = x%5


print(happy)

Solution (Python):

X = int(input())


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


print(ans)

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

q_500, mod = divmod(X, 500)

q_5, mod_2 = divmod(mod, 5)

print(q_500*1000+q_5*5)

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

Solution (Python):
have = int(input())
first = have//500
remain = have - 500*first
second = remain//5
happy = first*1000+second*5
print(happy)

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

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

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

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

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

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

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

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

y=x % 500

max=0
max=1000*(x//500)+5*(y//5)
print(max)

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

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

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

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

s = a * 1000 + b * 5

print(s)

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

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


happy = 0
a = money // 500
money -= 500*a
happy += a*1000
b = money // 5
happy += b*5

print(happy)

Solution (Python):
X = int(input())
answer = [0]
A = 0
while 4 < X:
  if X >= 500:
    answer.append(1000)
    X -= 500
  elif 499 >= X >= 5:
    answer.append(5)
    X -= 5
for i in answer:
  A += i
print(A)

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

b,s = x // 500,(x % 500)//5
print(b*1000 + s*5)

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

x500 = x // 500

x -= x500*500

x5 = x // 5

ans = x500*1000+x5*5

print(ans)

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

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

Solution (Python):
x = int(input())
x1 = (x%500)
a = (x1//5)*5
a2 = (x//500)*1000


print(a+a2)

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

Solution (Python):
import math

def solution():
    x = int(input())
    xx = math.floor(x / 500)
    if xx == 0:
        point = math.floor(x / 5) * 5
    else:
        point = xx * 1000
        xx = x - 500 * xx
        point = point + math.floor(xx / 5) * 5
    print(point)

solution()

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

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

Solution (Python):
s = input()
q = int(s) //500
mod = int(s) % 500

mod2 = int(mod) // 5

N = 1000 * int(q) + 5 * int(mod2)

print(N)

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

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

Solution (Python):
n = int(input())
s = 0
if n>= 500:
    res = n//500
    s = 1000*res
    n = n - res * 500
if n>=5:
    res = n//5
    s = s + res*5
print(s)

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

good1000 = x // 500
x500 = x % 500

good5 = x500 // 5

res = 1000 * good1000 + 5 * good5
print(res)

Solution (Python):
import sys, re
import math
 
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()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7



x = INT()
if x == 0:
    print(0)
else:
    a = math.floor(x / 500)
    b = math.floor((x - (a * 500)) / 5)
    print(a * 1000 + b * 5)

Solution (Python):
import sys


def input() -> str:
    return sys.stdin.readline().rstrip("\r\n")


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

if __name__ == "__main__":

    main()

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

q = X // 500
happiness += 1000 * q
X -= q * 500

q = X // 5
happiness += 5 * q

print(happiness)

Solution (Python):

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

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

sum = 0

while True:
  if n >= 500:
    sum += 1000
    n -= 500
  else:
    break
while True:
  if n >= 5:
    sum += 5
    n -= 5
  else:
    break
print(sum)

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)*1000
b=((X%500)//5)*5

print(a+b)

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

Solution (Python):
X = int(input())
num_500 = int(X / 500)
nokori = X - (500 * num_500)
num_5 = int(nokori / 5)

print(num_500 * 1000 + num_5 * 5)

Solution (Python):
x = int(input())
if x < 500:
    coin_5 = x // 5
    print(5*coin_5)
else:
    coin_500 = x // 500
    x = x % 500
    coin_5 = x // 5
    print(1000*coin_500 + 5*coin_5)

Solution (Python):
import math
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))
mod = 10**9 + 7 
sys.setrecursionlimit(1000010)

X = ni()

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

print(a * 1000 + b * 5 )

Solution (Python):
x = int(input())
coins = [500, 5]
happy = [0] * 2
for coin in coins:
    if coin == 500:
        happy[0] = x // coin
    elif coin == 5:
        happy[1] = x // coin
    x = x % coin

print(1000 * happy[0] + 5 * happy[1])

Solution (Python):
S = int(input())
FFNum = int(S/500)
perse500Num = S%500
FNum = int(perse500Num/5)
print(int(FFNum*1000+FNum*5))

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

ans = 0

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

print(ans)

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

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

while True:
    if s < 5:
        break
    if s - 500 >= 0:
        s = s-500
        h += 1000
    elif s - 5 >= 0:
        s = s-5
        h += 5

print(h)

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

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

a = x // 500
x -= a * 500

b = x // 5

print(a * 1000 + b * 5)

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

if x == 0:
    print(0)
else:
    q1 = x // 500
    mod = x % 500

    mod2 = mod // 5

    print(1000 * q1 + 5 * mod2)

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

Solution (Python):
X=int(input())
answer=0
answer+=int(X/500)*1000

x=X%500
answer+=int(x/5)*5

print(answer)

Solution (Python):




x = int(input())
num500, leftover_from500 = divmod(x, 500)
num5, _ = divmod(leftover_from500, 5)
happiness = 1000*num500 + 5*num5
print(happiness)

Solution (Python):

import sys


def solve(X: int):

    k = (X //500)*1000

    p = (X%500)//5*5
    print(k+p)
    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):
X = int(input())
print(max((X//500)*1000+((X-(X//500)*500)//5)*5,(X//5)*5))

Solution (Python):
import math

X = int(input())
happy_1000 = X//500
X = math.floor(X%500)
happy_5 = X//5
res = happy_1000*1000 + happy_5*5
print(res)

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

coins = [500, 5]

g = 0
for c in coins:
  n = x//c
  if c==500:
    g+=n*1000
  if c==5:
    g+=n*5
  x -= n*c
  
print(g)

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



ans = 0
r5 = int(x/500)
x= x- 500*r5
r1 = int(x/5)
print(r5*1000 + r1*5)

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

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

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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


    return

if __name__ == '__main__':
    main()

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

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

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

print((b*1000) + (c*5))

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

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

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

Solution (Python):

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

    n_500 = int(x / 500)
    n_5 = int((x - n_500*500)/ 5 )
    print(n_500*1000 + n_5*5)

Solution (Python):

from math import *
x = int(input())

res = int(x/500)
res *=1000
m = x%500
p = int(m/5)
p*=5
res += p
print(res)

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

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

print(ans)

Solution (Python):
from sys import stdin
x = int(stdin.readline().rstrip())

ans = 0
th = x//500
nokori = x-500*th
five = nokori//5
print(1000*th + 5*five)

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

hpy = []

a = int(x / 500)
aa = int(x % 500)
b = int(aa / 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):
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)

Solution (Python):
def no_of_500(X):
  return X/500

def rem(X):
  return X%500

def no_of_5(X):
  return rem(X)/5

def happiness_points(X):
  return (no_of_500(X)*1000)+(no_of_5(X)*5)

X=input()
print(happiness_points(X))

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

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

a = X//500
answer = a * 1000
b = X - a*500

c = b//5

answer_2 = c * 5
aa = answer + answer_2

print(aa)

Solution (Python):
x = int(input())
f = x//500
g = x%500
h = g//5
j = h*5
k = f*1000 + j
print(k)

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

Solution (Python):
import math

x=int(input())

ans = math.floor(x / 500) * 1000
x = x % 500
ans += math.floor(x / 5) * 5
print(ans)

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

happiness500 = int(X / 500)
happiness5 = int((X%500/5))

print(happiness500*1000+happiness5*5)

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

n500 = s // 500
ds = s - n500 * 500
n5 = ds // 5

print(n500 * 1000 + n5 * 5)

Solution (Python):
import math

X = int(input())
x = math.floor(X // 500)*1000
y = X - math.floor(X // 500)*500
y = math.floor(y // 5)*5
print(x+y)

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

Solution (Python):
a=int(input())
n1=a//500
s1=a%500
n2=s1//5

print(n1*1000+n2*5)

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

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

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