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


H = 0

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

H = 1000 * div_500 + 5 * div_5

print(H)

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



n = x // 500
m = (x % 500) // 5

ans = 1000*n + 5*m


print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(4100000)

x = int(input())
a = 1
ans = 0 
while a >= 0:
    if x >= 500:
        x -= 500
        ans += 1000
    else:
        break
while a >= 0:
    if x >= 5:
        x -= 5
        ans += 5
    else:
        break
print(str(ans))

Solution (Python):
def main():
    x = int(input())
    ans = 0
    while(x > 5):
        if x >= 500:
            ans += 1000
            x -= 500
        else:
            ans += 5
            x -= 5

    print(ans)


if __name__ == "__main__":
    main()

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

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

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

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

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

Solution (Python):
X = int(input())
if X % 500 == 0:
    print(int(X / 500 * 1000))
else:
    w = X % 500
    f = (X - w) / 500 * 1000
    n = w % 5
    l = (w - n) / 5 * 5
    print(int(f + l))

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

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

Solution (Python):
a=input();
a=int(a);
happy=0;
while a>499:
	a=a-500;
	happy=happy+1000;
while a>4:
	a=a-5;
	happy=happy+5;
print(happy);

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

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


y=x%500
z=y%5    
count=(x-y)/500
count1=(y-z)/5
    
print(int(round(1000*count + 5*count1)))

Solution (Python):

X = int(input())

n_500 = int(X/500)
n_5 = int((X - n_500 * 500)/5)

print(1000* n_500 + 5 * n_5)

Solution (Python):
X = input()

five_h = int(X) // 500
X = int(X)%500

five = int(X) // 5
X = int(X)%5

print(1000*five_h+5*five)

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


count = 0
list = {}
for i in range(10**9):
    if (i * 500) > X:
        list["500"] = (i-1)
        X = X - 500 * (i - 1)
        break
for i in range(10**9):
    if (i * 5) > X:
        list["5"] = (i-1)
        X = X - 5 * (i - 1)
        break



a = list["500"]*1000
b = list["5"]*5

c = a+b


print(c)

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

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

print(c*5 + a*1000)

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

Solution (Python):
money = int(input())
ft = 0
f  = 0

while money >= 500:
  money = money - 500
  ft = ft + 1


while money >= 5:
  money = money - 5
  f = f + 1


happy = ft * 1000 + f * 5
print (happy)

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

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

Solution (Python):
s=int(input())
h=0
while True:
    if s>=500:
        a=s//500
        h +=1000*a
        s=s%500
        
    elif s>=5:
        a=s//5
        h +=5*a
        s=s%5
    else:
        break
    
print(str(h))

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

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

n1 = X//500
n2 = (X-500*n1)//5

print(n1*1000+n2*5)

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

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

n1 = X//500
n2 = (X-500*n1)//5

print(n1*1000+n2*5)

Solution (Python):
def fun(s):
    a,b=0,0
    a+=s//500
    s=s-(a*500)
    b+=(s//5)
    s=s-(b*5)
    print(a*1000+b*5)
    
s=int(input())
fun(s)

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

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

d,m = divmod(n,500)

d2,m2 = divmod(m,5)

print(1000 * d + 5 * d2)

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

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

result = int(a/500) * 1000
b = a % 500
result += int(b/5) * 5

print(result)

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

ans = 0

a = x // 500
ans += 1000 * a
x -= 500 * a

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

Solution (Python):

x = int(input())


q500 = x // 500
mod500 = x % 500
q5 = mod500 // 5


print(q500 * 1000 + q5 * 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 
c = b//5 
d = (a*1000) + (c*5) 

print (d)

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

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

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

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

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


gohyaku = X // 500
X = X-gohyaku * 500
ans = gohyaku * 1000


go = X // 5
ans = ans + go * 5

print(ans)

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


p = 0

while X > 4:
  if X > 499:
    N = X // 500
    X = X - 500 * N
    p = p + 1000 * N
  if X > 4:
    n = X // 5
    X = X - 5 * n
    p = p + 5 * n

print(p)

Solution (Python):
x=input()
x=int(x)
y1=x//500
y2=(x-y1*500)//5

print(1000*y1+5*y2)

Solution (Python):
n = int(input())
s=n//500
r=n%500

r=r//5
print(s*1000+r*5)

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

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

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

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

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

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

a = int(N / 500)
b = int((N % 500) / 5)

x = a * 1000 + b * 5

print(x)

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

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

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

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

a=S//500

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

c=a*1000+b*5

print(c)

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

Solution (Python):
X = int(input())
a, a_mod = divmod(X,500)
b, b_mod = divmod(a_mod,5)
ans =  a * 1000 + b * 5 
print(ans)

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

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

x = int(input())
p = x//500
q = (x%500)//5
print(p*1000+q*5)

Solution (Python):
n=int(input())
h=0
while n>4:
    if n >=500:
        r=n//500
        h+=1000*r
        n=n%(r*500)
    else:
        r=n//5
        h+=5*r
        n=n%(r*5)
print(h)

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

Solution (Python):
def calc(x):
    s=0
    if(x==0):
        s=0
    else:
        p=x//500
        q=x%500
        s=s+p*1000+(q//5)*5
    return s
x=int(input())
print(calc(x))

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

Solution (Python):



X = int(input())

Y500 = 0
Y5 = 0

Y500 = X // 500

x = X % 500

Y5 = x // 5

print((Y500 * 1000) + (Y5 * 5))

Solution (Python):
x = int(input())
count = 0
if x >= 500:
  count += (x // 500) * 1000
  t = x % 500
  count += (t // 5) * 5
  print(count)
elif x < 500 and x >= 5:
  count += (x // 5) * 5
  print(count)
else:
  print(0)

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

Solution (Python):

x=int(input())

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

s=(1000*a)+(b)
print(s)

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


main()

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

a = X * 0.01 // 5 

pointa = a * 1000

b = X - a * 500


pointb = b // 5 * 5


z = round(pointa + pointb)
print(z)

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

Solution (Python):
x = input()

a = int(int(x)/5) 
b = int(a%100)
a = int(a/100)
print(1000*a+5*b)

Solution (Python):
x=int(input())
hund_number=x//500
hund_happy=hund_number*1000
five_number=(x-hund_number*500)//5
five_happy=five_number*5
sum_happy=hund_happy+five_happy
print(sum_happy)

Solution (Python):
i = int(input())
i_500 = divmod(i,500)
i_5 = divmod(i_500[1],5)
print(i_500[0]*1000+i_5[0]*5)

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


happy=0

while(s>=500):
  s=s-500
  happy+=1000
while(s>=5):
  s=s-5
  happy+=5
print(happy)

Solution (Python):
temp0=int(input())
n500=int(temp0/500)
temp1=temp0-n500*500
n5=int(temp1/5)
print(n500*1000+n5*5)

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

Solution (Python):

import numpy as np
from functools import *
import sys
sys.setrecursionlimit(100000)


def is_kaibun(kaibun):
    for i in range(len(kaibun)//2):
        if kaibun[i] != kaibun[-i-1]:
            return False
    return True


X=int(input())

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

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

Solution (Python):
X = int(input())
y_500 = X // 500
x_500 = X % 500
y_5 = x_500 // 5
x_5 = x_500 % 5

z = y_500 * 1000 + y_5 * 5
print(z)

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

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

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


mod = n% 5
n=n-mod

sum=0
s5=n//500
sum+=s5 *1000
n =n-(s5*500)
sum+=n//5 *5 

print(sum)

Solution (Python):

X = int(input())


a_500 =0
a_100 =0
a_50 =0
a_10 =0
a_5 =0
a_1 =0


a_500,amari = divmod(X,500)
a_5,amari = divmod(amari,5)


koufuku = a_500 * 1000 + a_5 * 5
print(koufuku)

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

Solution (Python):

x = int(input())

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

Solution (Python):


x = int(input())

ans = 0

q, mod = divmod(x, 500)
ans += q*1000

q, mod = divmod(mod, 5)
ans += q*5

print(ans)

Solution (Python):
X=int(input())
ans=0
A=X//500

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

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

n500=x//500
rr=x%500
n5=rr//5
print(1000*n500+5*n5)

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

h1k = X // 500

h5 = (X - h1k * 500) // 5

happiness = h1k*1000 + h5*5

print(happiness)

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

h1000 = int(money / 500)
money = money - h1000 * 500
h5 = int(money / 5)

print(h1000 * 1000 + h5 * 5)

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

point=0
point+=int(money/500)*1000
money%=500

point+=int(money/5)*5
money%=5
print(point)

Solution (Python):

x = int(input())

v_1000 = int(x/500)
v_5 = int((x - 500 * v_1000)/5)

print(int(v_1000*1000 + v_5*5))

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

while X - 500 >= 0:
    ans += 1000
    X -= 500
while X - 5 >= 0:
    ans += 5
    X -= 5

print(ans)

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

happy = 0

n = int(s / 500)
happy += n * 1000
s = s - (n * 500)

n = int(s / 5)
happy += n * 5

print(happy)

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

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

k = (a//500)*1000
l = ((a%500)//5)*5

b = k + l

print(b)

Solution (Python):
N = int(input())
if N >= 500:
    t = N//500
    a = N%500
    if a >= 5:
        f = a//5
        print(1000*t+f*5)
    else:
        print(1000*t)
elif N >= 5:
    f = N//5
    print(f*5)
else:
    print("0")

Solution (Python):

import sys
input = sys.stdin.readline




'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''



x=int(input())
cnt=0
while x-500>=0:
    cnt += 1000*(x//500)
    x%=500
    
while x-5>=0:
    cnt+= 5*(x//5)
    x %= 5
print(cnt)

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

n500 =n//500
n5 = (n - 500*n500)//5

print(1000*n500 + 5 * n5)

Solution (Python):
N=int(input())
a = N//500
ans1 = a*1000

b = N-(a*500)
b = b//5
ans2 = b*5
ans = ans1+ans2
print(ans)

Solution (Python):
X = int(input())
if 0 <= X <= pow(10, 9):
    max500Coins = int(X/500)
    X = X % 500
    max5Coins = int(X/5)
    X = X % 5
    numberOFHappinessCoins = max500Coins*1000 + max5Coins*5
    print(numberOFHappinessCoins)

Solution (Python):
x=int(input())
ans=0
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):
N=int(input())
a = N//500
ans1 = a*1000

b = N-(a*500)
b = b//5
ans2 = b*5
ans = ans1+ans2
print(ans)

Solution (Python):
x = int(input())
u = 0
def a(x,u):
    if x>=500:
        u+=1000 * (x // 500)
        x = x % 500
        a(x,u)
    elif x>=5:
        u+=5 * (x // 5)
        x = x % 5
        a(x,u)
    else:
        print(u)
a(x,u)

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

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

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

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

print(ans)

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

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

a = int(coin / 500) * 1000
remain = coin % 500
b = int(remain / 5) * 5

print(a + b)

Solution (Python):


a = int(input())

a2=a//500
a=a-a2*500
a3=a//5
ans=a2*1000+a3*5
print(ans)

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

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

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

Solution (Python):
def main():
    s = int(input())
    uresisa500 = int(s/500)
    amari = s%500
    uresisa5 = int(amari/5)
    print(uresisa500*1000+uresisa5*5)
    
if __name__ == '__main__':
    main()

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

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

q1 = x // 500
mod_500 = x % 500

q2 = mod_500 // 5
mod_5 = mod_500 % 5

print(q1*1000 + q2*5)

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

i = 0

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

ans = 1000*i + 5*a

print(ans)

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

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

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

Y = int(2 * (X - A))
Z = int(A - B)
print(Y + Z)

Solution (Python):



import math

x = int(input())

n500 = int(x / 500)
l500 = int(x % 500)

n5 = int(l500 / 5)

print(n500 * 1000 + n5 * 5)

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

gohyaku = (x//500)
answer = 0

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

goen = ( x // 5)

if goen > 0:
    answer += 5 * goen

print(answer)

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

Solution (Python):


x = 0

def format_input(filename = None):
	global x
	if filename == None:
		x = int(input())

	elif filename == '__random__':
		from random import randint as rng
		x = rng(0, 10**9)
		print(x)

def get_answer():
	num_of_500s = x // 500
	residue = x % 500
	num_of_5s = residue // 5

	answer = num_of_500s * 1000 + num_of_5s * 5

	return answer

if __name__ == '__main__':
	format_input()

	ans = get_answer()
	print(ans)

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

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

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

A=X-X//500*500
B=A-A//100*100
C=B-B//50*50
D=C-C//10*10
E=D//5
app=X//500*1000 + E*5

F=A//5
maxi=X//500*1000 + F*5

print(max([app,maxi]))

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

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

print(happy)

Solution (Python):
from sys import stdin,stdout
Pi = lambda x: stdout.write(str(x) + '\n')
S = lambda x: x*(x+1) // 2
I = lambda x: 1+(2*x)
R = lambda:stdin.readline()
Ri = lambda x:map(int,x.split())
Rs = lambda x:map(str,x.split())
Rf = lambda x:map(float,x.split())
 
def main():	
	
	for x in stdin:
		n = int(x)
		ans = (n//500)*1000
		n %= 500
		ans += (n//5)*5
		Pi(ans)



if __name__=='__main__':
	main()

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


quotient = x // 500
remainder = x % 500

presure_1 = 1000 * quotient + (remainder // 5) * 5

presure_2 = (x // 5) * 5

if presure_1 >= presure_2:
  print(presure_1)
else:
  print(presure_2)

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

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

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

Solution (Python):
import math

X = int(input())


def main():
    def main0(x, acc):
        if x >= 500:
            acc += math.floor(x / 500) * 1000
            return main0(x % 500, acc) 
        
        
        
        
        
        
        elif x >= 5:
            acc += math.floor(x / 5) * 5
            return main0(x % 5, acc) 
        else:
            return acc

    return main0(X, 0)

print(main())

Solution (Python):



X = int(input())

preasure = 0

preasure += 1000 * int(X//500)
preasure += X % 500 // 5 * 5

print(int(preasure))

Solution (Python):


n = int(input())

n500 = int(n / 500)

n5 = int(n-n500*500)
n5 = int(n5 / 5)

happy = n500 * 1000 + n5 * 5

print(happy)

Solution (Python):

from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


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




BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")



if __name__ == "__main__":
    main()

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

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

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

Solution (Python):


s = int(input())

ans = 0

ans += (s // 500) * 1000

s = s % 500

ans += (s // 5) * 5

print(ans)

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

Solution (Python):
n = int(input())
pl = 0
 
q, mod = divmod(n, 500)
pl += q * 1000

q, mod = divmod(mod, 5)
pl += q * 5

print(pl)

Solution (Python):
X = int(input())
cnt_a = 0
cnt_b = 0

while X >= 500:
    cnt_a += 1
    X -= 500
while X >= 5:
    cnt_b += 1
    X -= 5

happiness = 1000 * cnt_a + 5 * cnt_b

print(happiness)

Solution (Python):


import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

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

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

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

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

if X >= 500:
  gohyaku = X // 500
  nokori = X - (gohyaku * 500)
  go = nokori // 5

  uresi = (1000 * gohyaku) + (5 * go)

else:
  go = X // 5
  uresi = (5 * go)

print(uresi)

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

    Sen = X // 500
    
    XX = X - Sen * 500
    
    go = XX // 5

    print (str(Sen * 1000 + go * 5))


if __name__ == '__main__':
    main()

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

Solution (Python):

X=int(input())

changes=[500,100,50,10,5,1]

tmp=X
total=0

result=[]

result.append(int(tmp/500))

tmp=tmp%500

result.append(int(tmp/5))

total+=result[0]*1000
total+=result[1]*5

print(total)

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,b = divmod(x,500)

c = b//5

print(a*1000+c*5)

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

Solution (Python):
x=int(input())
ans=0
a, y=divmod(x,500)
b, z=divmod(y,5)
ans=a*1000+b*5
print(ans)

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

s_1000 = ss / 500
s_under = ss - 500*int(s_1000)
s_5 = int(s_under) / 5

s_sum = 1000*int(s_1000) + 5*int(s_5)

print(s_sum)

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

K500 = x // 500

tmp = x - 500 * K500

K5 = tmp // 5

ans = 1000 * K500 + 5 * K5

print(ans)

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):
i=int(input())
a=int(i/500)
b=int((i-500*a)/5)
print(int(1000*a+5*b))

Solution (Python):
X=int(input())
k=X%500
f=X-k
s=f*2
d=k%5
s1=k-d
print(s+s1)

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

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

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

print(a*1000+b*5)

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

a=0
b=0
aper=0
if x!=0:
    a=x//500
    aper=x%500

if aper != 0:

    b= aper//5
    bper = aper%5

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

print(int(result))

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

Solution (Python):
"""
"""


def int_as_array(num): return list(map(int, [y for y in str(num)]))


def array_as_int(arr): return int(''.join(map(str, arr)))


def read_int(): return int(input())


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


def array_to_string(arr, sep=' '): return sep.join(map(str, arr))


def matrix_to_string(arr, sep=' '): return '[\n' + '\n'.join(
    [sep.join(map(str, row)) for row in arr]) + '\n]'


coins = {
    500: 1000,
    100: 0,
    50: 0,
    10: 0,
    5: 5,
    1: 0
}


def solve(number):
    points = 0
    points += (number // 500) * 1000
    number = number % 500
    points += (number // 5) * 5
    number = number % 5
    return points


T = read_int()

print(solve(T))

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

Solution (Python):
from sys import stdin


def get_result(data):
    N = data[0]
    q, mod = divmod(N, 500)
    q_5, _ = divmod(mod, 5)
    return q * 1000 + q_5 * 5


if __name__ == '__main__':
    data = list(map(int, stdin.readline().rstrip('\n').split(' ')))
    result = get_result(data)
    print(result)

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

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

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

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

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

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

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

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

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10


def solve():
    x = II()
    ans = x // 500 * 1000
    ans += (x % 500) // 5 * 5
    print(ans)
    return



if __name__ == '__main__':
    solve()

Solution (Python):
input_value = input()
input_int = int(input_value)
division_500 = int(input_int / 500)
happiness_500 = division_500 * 1000
happiness_5 = int((input_int - division_500 * 500) / 5) * 5
print(happiness_500 + happiness_5)

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

B=int(A/500)
ans1=int(B*1000)

C=int(A%500)
D=int(C/5)

ans2=int(D*5)

print(int(ans1+ans2))

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

rest = x
ureshisa = 0

ureshisa += (rest // 500) * 1000
rest = rest % 500

ureshisa += (rest // 5) * 5

print(ureshisa)

Solution (Python):
x = input()
x = int(x)
co_500 = x // 500
amari_500 = x % 500
co_5 = amari_500 // 5
amari_5 = amari_500 % 5
co_1 = amari_5
print(1000*co_500 + 5*co_5)

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

ans1 = X // 500

calc1 = X -(500*ans1)
ans2 = calc1 // 5

ans = ans1 *1000 + ans2 *5

print(ans)

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

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

n500, amari = divmod(x, 500)
p = n500* 1000 + (amari//5)*5
print(p)

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

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

Solution (Python):
X = int(input())
x = X
L = []
for i in 500,100,50,10,5,1:
    a = x // i
    x -= i * a
    L.append(a)
for i in 100*L[1], 50*L[2], 10*L[3]:
    L[4] += i // 5
ans = 1000*L[0] + 5*L[4]
print(ans)

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

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

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

print(five_handreds * 1000 + five * 5)

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

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

Solution (Python):
import math
def main():
    arg = getInput(input())
    
    ans = process(arg)
    print(ans)
    
def process(arg):
    yen500 = math.floor(arg / 500)
    amari = arg % 500
    yen5 = math.floor(amari / 5)
    ans = 1000 * yen500
    ans = ans + yen5 * 5

    return ans

def getInput(input):
    
    n = 1
    
    ret = None

    if n == 1:
        pass
        
        
        ret = int(input)
        
        
        
    else:
        for x in range(n):
            
            ret = input[x]

    return ret

if __name__ == '__main__':
    main()

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

Solution (Python):
X = int(input())
coin500 = 0
coin5 = 0
coin500, X = divmod(X, 500)
coin5 = X // 5
print(coin500*1000+coin5*5)

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

Solution (Python):


import sys
import math


N = int(input())
ppp = N // 500
NN = N-500*ppp
pp = NN //5
ans = 1000*ppp+5*pp
print(ans)