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

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

ans += 1000 * (X // 500)

X %= 500

ans += 5 * (X // 5)

print(ans)

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

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

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

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

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

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

Solution (Python):
X = int(input())
fhun = X//500
amari = X % 500
fiv = amari//5
ure = fhun*1000 + fiv*5

print(ure)

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

Solution (Python):
money=int(input())
happines=0
while money>=500:
  happines+=1000
  money-=500
while money>=100:
  happines+=100
  money-=100
while money>=5:
  happines+=5
  money-=5
print(happines)

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

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

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

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

num_500 = money // 500;
mod = money % 500;
num_5 = mod // 5;

point = num_500 * 1000 + num_5 * 5;

print(point)

Solution (Python):
import math
X=int(input())
A=math.floor(X/500)*1000+math.floor(X%500/5)*5
print('{:.0f}'.format(A))

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

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

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

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

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

print(a*1000+b*5)

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

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

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 = 0
joy = int(X / 500) * 1000
remainder = X % 500
joy += int(remainder / 5) * 5

print(joy)

Solution (Python):
import sys

X= int(input())

Happy = 0

q,mod = divmod(X,500)
Happy += q * 1000

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

print(Happy)

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

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

c1 = x // 500
x -= (c1 * 500)

c2 = x // 5

print(c1*1000 +c2*5)

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

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

n1 = 0
while True:
    x = x - 500
    if x < 0:
        x += 500
        break
    else:
        n1 += 1

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

print(n1*1000 + n2*5)

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

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

Solution (Python):
def resolve():
    X = int(input())
    goyaku = X // 500
    go = (X - (goyaku * 500)) // 5

    print((goyaku * 1000) + (go * 5))

resolve()

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

Solution (Python):
X = int(input())
p , mod = divmod(X, 500)
q = mod//5
print(p*1000+q*5)

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

happy = 0

fh = m // 500
m = m % 500

f = m // 5

happy = fh * 1000 + f*5

print(happy)

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

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

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

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

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

num500=x//500
remain=x-num500*500

num5=remain//5

print(num500*1000+num5*5)

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

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

d, m = divmod(X, 500)
print(d * 1000 + (m // 5) * 5)

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

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

print(a)

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

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

Solution (Python):
Yen = int(input())
Yen_500 = Yen//500
nokori = Yen - Yen_500*500
Yen_5   = nokori//5

print(Yen_500*1000+Yen_5*5)

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

big = x // 500
small = (x - big*500) // 5

print(big * 1000 + small * 5)

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

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

Solution (Python):


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

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

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

Solution (Python):
def happy(n):
  hap500 = (n // 500) * 1000
  n = n % 500
  hap5 = (n // 5) * 5
  return hap500 + hap5

string = int(input())
print(happy(string))

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

Solution (Python):
x = int(input())
count500 = 0
count5 = 0
while x >= 500:
    x -= 500
    count500 += 1
while x >= 5:
    x -= 5
    count5 += 1

print(count500 * 1000 + count5 * 5)

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

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

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

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

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

if x%500==0:
    point = (x/500)*1000
else:
    res = x
    point = 0
    while res > 500:
        point = point + 1000
        res = res - 500
    point= point + (res//5)*5
        
print(int(point))

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

Solution (Python):
import math as ma
X=int(input())
super=ma.floor(X/500)
Y=X-super*500
minus=ma.floor(Y/5)
tot=1000*super+5*minus
print(tot)

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

Solution (Python):
X = int(input())
count_500 = X // 500
count_5 = (X % 500) //5

print(count_500*1000+count_5*5)

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

Solution (Python):
num0=int(input())
sum0=0
high=int((num0-num0%500)/500)
date0=num0-high*500
low=int((date0-date0%5)/5)
print(high*1000+low*5)

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

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

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

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

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

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

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

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

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

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

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

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

y = 1000*a + 5*b

print(y)

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

gold = x // 500
x -= gold * 500

bronze = x // 5

print(gold*1000 + bronze*5)

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

gold = x // 500
x -= gold * 500

bronze = x // 5

print(gold*1000 + bronze*5)

Solution (Python):
money = int(input())
golden = money // 500

money -= golden*500
bronze = money //5

score = golden*1000 + bronze*5
print(score)

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

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

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

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

Solution (Python):
n = int(input())
s = 0
while n - 5 > 0:
  if n - 500 >= 0:
    n -= 500
    s += 1000
  elif n - 100 >= 0:
    n -= 100
    s += 100
  elif n - 50 >= 0:
    n -= 50
    s += 50
  elif n - 10 >= 0:
    n -= 10
    s += 10
  elif n - 5 > 0:
    n -= 5
    s += 5
  
   
   
print(s)

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())
print((X//500)*1000+((X-500*(X//500))//5)*5)

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

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

Solution (Python):
x=int(input())
a=0
b=0
while 500*(a+1)<=x:
    a+=1
    continue
while 5*(b+1)<=x-500*a:
    b+=1
    continue
print(1000*a+5*b)

Solution (Python):

x = int(input())
reward_500 = int(x / 500) * 1000
reward_50 = int((x % 500)/5) * 5
print(reward_500 + reward_50)

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

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

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

print(happiness)

Solution (Python):
import math
X=int(input())
a=math.floor(X/500)
b=int(X%500)

c=math.floor(b/5)

print(a*1000+c*5)

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

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

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

Solution (Python):
X = int(input())
S = int()
T = int()
S = (X//500)*1000
T = (X%500)//5*5

print(S + T)

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

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

print(1000*a + 5*b)

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

print(((a - b)*2) + b - c)

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

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

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

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

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

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

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

Solution (Python):
def main():
    x = int(input())
    ans = (x // 500) * 1000 + ((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())
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())

u = X // 500
X %= 500
v = X // 5

print(u * 1000 + v * 5)

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

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

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

print(gold)

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

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

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

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

Solution (Python):

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

Solution (Python):


int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solve():
    x = II()
    fh = x // 500
    x = x - fh * 500
    five = x // 5
    print(1000 * fh + 5 * five)


if __name__ == '__main__':
    solve()

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

n_500 = int(x/500)
n_5 = int((x%500)/5)

print(n_500*1000+n_5*5)

Solution (Python):
X=int(input())
if X>=500:
    y=X//500
    print(int(1000*y+(X-y*500)//5*5))
else:
    z=X//5
    print(int(z*5))

Solution (Python):
coin = int(input())
siawase = 0
if coin >= 500:
    siawase = siawase + int(coin / 500) * 1000
    amari = coin % 500
    siawase = siawase + int(amari / 5) *5
elif coin >= 5:
    siawase = siawase + int(coin / 5) * 5
    
print(int(siawase))

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

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

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

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

hM = X//500*1000
hT = (X - hM//2)//5*5
print(hM+hT)

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

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

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

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

print(happy)

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

a = X // 500 

b = (X % 500 ) // 5

print(a*1000 + b*5)

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

Solution (Python):
X=int(input())
P,Q=divmod(X,500)
R,S=divmod(Q,5)
print(P*1000+R*5)

Solution (Python):


X = int(input())

yen500 = X//500

yen5 = (X-yen500*500)//5

print(1000*yen500 + 5*yen5)

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

p = math.floor(X/500)
q = math.floor((X-(p*500))/5)
print((p * 1000) + (q * 5))

Solution (Python):
from sys import stdin
import math
import fractions

n = int(stdin.readline().rstrip())

x = int(n / 500)
y = int(int(n % 500) / 5)

print(x * 1000 + y * 5)

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

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

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

uresisa1=X//500*1000
uresisa2=(X-X//500*500)//5*5

print(uresisa1+uresisa2)

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

Solution (Python):
n = int(input())
happy = 0
if n%500 == 0:
    print(2*n)
else:
    while n > 0:
        if n == 0:
            break
        n-=500
        if n<0:
            n+=500
            n-=5
            if n<0:
                n+=5
                break
            else:
                happy+=5
        else:
            happy+=1000
    print(happy)

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

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

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

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

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

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

Solution (Python):
X = int(input())
A , B = divmod(X,500)
C = B//5

HAPPY = A*1000 + C*5

print(HAPPY)

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

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

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

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

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

if X % 500 == 0:
    print((X // 500) * 1000)
else:
    print((X // 500) * 1000 + ((X % 500) // 5) * 5)

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

if __name__ == "__main__":
    main()

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

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

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

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

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

Solution (Python):
import sys
import itertools
import bisect
from operator import itemgetter
 
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

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

Solution (Python):
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

x = ni()

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):
if __name__ == "__main__":
    X = int(input())
    A = X // 500 * 1000 + X % 500 // 5 * 5
    print(A)

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

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

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

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

Solution (Python):

X = int(input())
def func(X, i):
    a_i, X = X//i, X - X//i * i
    return a_i, X
a_500, X = func(X, 500)



a_5, X = func(X, 5)

print(a_500 * 1000 + a_5 * 5)

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

ans += (X // 5) * 5

print(ans)

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

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

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

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


if __name__ == '__main__':
    main()

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

Solution (Python):
from itertools import permutations
import sys

sys.setrecursionlimit(10 ** 6)
from bisect import *
from collections import *
from heapq import *

def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def SI(): return sys.stdin.readline()[:-1]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
int1 = lambda x: int(x) - 1
def MI1(): return map(int1, sys.stdin.readline().split())
def LI1(): return list(map(int1, sys.stdin.readline().split()))
p2D = lambda x: print(*x, sep="\n")
dij = [(1, 0), (0, 1), (-1, 0), (0, -1)]

def main():
    x=II()
    c,x=divmod(x,500)
    ans=c*1000+x//5*5
    print(ans)

main()

Solution (Python):
x = int(input())
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):
X = int(input())

A = X // 500
B = X % 500
C = B // 5

print(A*1000+C*5)

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

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

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

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

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

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

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

Solution (Python):
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


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


if __name__ == '__main__':
    main()

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


if __name__ == '__main__':
    main()

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

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

Solution (Python):
x = int(input())
a1, r1 = divmod(x, 500)
r2 = r1 // 5
print(a1*1000 + r2*5)

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

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

Solution (Python):
x=int(input())
u,v=divmod(x,500)
s,t=divmod(v,5)
print(1000*u+5*s)

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

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


if __name__ == '__main__':
    main()

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

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

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

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

Solution (Python):
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    x = int(input().rstrip('\n'))
    print(x // 500 * 1000 + (x - x // 500 * 500) // 5 * 5)


if __name__ == '__main__':
    solve()

Solution (Python):
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


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

    print(res)

if __name__ == '__main__':
    main()

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

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

Solution (Python):

"""
Created on Thu Mar 19 11:55:12 2020

@author: 17664
"""
happy = int(input())

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

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

Solution (Python):

cost_1 = int(input())

numbers_500 = int(cost_1 / 500)
cost_2 = cost_1 - (numbers_500 * 500)

numbers_5 = int(cost_2 / 5)
cost_3 = cost_2 - (numbers_5 *5)



print(int(numbers_500*1000 + numbers_5*5))

Solution (Python):
okane = input()
okane = int(okane)
shiawase1 = okane // 500
okane = okane - shiawase1 * 500
shiawase2 = okane // 5
okane = okane - shiawase2 * 5
shiawase = shiawase1 * 1000 + shiawase2 * 5
print(shiawase)

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

Solution (Python):



x = int(input())

happy_1 = (x // 500) * 1000
happy_2 = ((x % 500) // 5) * 5

print(happy_1 + happy_2)

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

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

Solution (Python):
a = list(map(int, input().split()))
X = a[0]

p = X%500
P = (X-p)*2

q = p%5
Q = p-q

print(P+Q)

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

div = x//500
rem = x-div*500
res = div*1000 + (rem//5)*5

print(res)

Solution (Python):


x = int(input())

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

print(n500*1000+n5*5)

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

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

s=int(X/500)
X=X-500*s
t=int(X/5)

print(s*1000+t*5)

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

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

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

a = x//500

b = x - 500*a

c = b//5
happiness = (a * 1000) + (c * 5)
print(happiness)

Solution (Python):

X = int(input())
happiness = 0

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

print(a * 1000 + b * 5)

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

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

p = m//500*1000 + m%500//5*5

print(p)

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

Solution (Python):
S = input()

U500 = int(S) // 500
U5 = (int(S) % 500)//5
happy = U500*1000+U5*5
print(str(happy))

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

i = int(X / 500)
X = X - (i * 500)
happy += i * 1000

i = int(X / 5)
X = X - (i * 5)
happy += i * 5

print(str(happy))

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

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

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

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

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

Solution (Python):
total = int(input())
num_500 = total // 500

remain = total - num_500 * 500
num_5 = remain // 5

print(num_500 * 1000 + num_5 * 5)

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

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

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

Solution (Python):
def main():
    x = int(input())
    res_1 = x // 500
    y = x % 500
    res_2 = y // 5
    res = res_1 * 1000 + res_2 * 5
    print(res)


if __name__ == "__main__":
    main()

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

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

happy = 1000*(int(x/500))

x %= 500

happy += 5 * (int(x/5))

print(happy)

Solution (Python):
from sys import exit, stdin
X = int(stdin.readline().rstrip())
Y = X // 500
Z = X % 500
print(Y*1000 + (Z//5)*5)

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

happy_1 = (X // 500) * 1000
happy_2 = ((X % 500) // 5) * 5

val = happy_1 + happy_2

print(val)

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

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

Solution (Python):
X = int(input())
a = 0
b = 0

if X < 500:
    if X % 5 == 0 :
        print(X)
    else:
        a = X // 5 * 5
        print(a)
elif X >= 500 :
    if X % 500 == 0 :
        print(X*2)
    else:
        a = X // 500 * 1000
        b = X % 500
        if b % 5 == 0 :
            print(a + b)
        else:
            b = b // 5 * 5
            print(a + b)

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

Solution (Python):


first_input = list(map(lambda x:int(x), input().split(" ")))





X = first_input[0]
num500 = X//500
num5 = (X-num500*500)//5

print(num500*1000+num5*5)

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

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

Solution (Python):
def s0():return input()
def s1():return input().split()
def s2(m):return [input() for x in range(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

x=n0()

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

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

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

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

joy_500 = int(a / 500)
joy_5 = int((a%500)/5)

sum_joy = joy_500*1000 + joy_5*5


print(sum_joy)

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

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

    num500 = X // 500

    num5 = (X - 500 * num500) // 5

    print(1000 * num500 + 5 * num5)


if __name__ == '__main__':
    main()

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

total += money // 500 * 1000
total += money % 500 // 5 * 5
print(total)

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

total += money // 500 * 1000
total += money % 500 // 5 * 5
print(total)