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):
total = int(input())

x_500 = int(total/500)
x_5   = int((total-x_500*500)/5) 

print(x_500*1000 + x_5*5)

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

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

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

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

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

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

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

n_500 = x//500
n_5 = (x-n_500*500)//5

print(n_500*1000 + n_5*5)

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

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

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

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

if __name__ == '__main__':
    main()

Solution (Python):






from sys import stdin,setrecursionlimit










setrecursionlimit(10**6+1)
input=stdin.readline

x=int(input().rstrip())
ans=0
ans+=(x//500)*1000
x%=500
print(ans+(x//5)*5)

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

a, m = divmod(X, 500)
a5, m5 = divmod(m, 5)

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

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

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

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

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

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

C = 0
D = 0

if X >= 500:
    C = X // 500
    X = X - (500 * C)
if X >= 5:
    D = X // 5

total = (1000 * C) + (5 * D)

print(total)

Solution (Python):

import math

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

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

C = 0
D = 0

if X >= 0 and X <= 10 ** 9:
    while True:
        if X >= 500:
            C = X // 500
            X = X - (500 * C)
        elif X >= 5:
            D = X // 5
            X = X - (5 * D)
        else:
            break

total = (1000 * C) + (5 * D)

print(total)

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

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

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

C = 0
P = 0
D = 0
L = 0

if X >= 0 and X <= 10 ** 9:
    while True:
        if X >= 500:
            C = X // 500
            P = 500 * C
            X = X - P
        elif X >= 5:
            D = X // 5
            L = 5 * D
            X = X - L
        else:
            break

total = (1000 * C) + (5 * D)

print(total)

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

C = 0
P = 0
D = 0
L = 0
total = 0

if X >= 0 and X <= 10 ** 9:
    while True:
        if X >= 500:
            C = X // 500
            P = 500 * C
            X = X - P
        elif X >= 5:
            D = X // 5
            L = 5 * D
            X = X - L
        else:
            break
man = 1000 * C
t   = 5 * D

total = man + t

print(total)

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

ans1=x//500
ans2=(x%500)//5

print(ans1*1000+ans2*5)

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

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

happiness = 1000 * n_500 + 5 * n_5
print(happiness)

Solution (Python):
S=int(input())
a_500=S//500

S_temp=S-500*a_500

a_5=S_temp//5

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

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    X=I()
    ans=(X//500)*1000
    ans+=((X%500)//5)*5
    print(ans)

main()

Solution (Python):
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n = int(readline())

res = n//500
ans = 0
ans += res*1000

n -= 500*res

res = n//5

ans += res*5

print(ans)

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

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

count500 = int(X/500)
remain = X%500
count5 = int(remain/5)

print(1000 * count500 + 5 * count5)

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

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

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

k = int(x/500)
t = int((x-500*k)/5)

print(1000*k+5*t)

Solution (Python):
import sys
n = int(input())
f=0
ff=0
if n<5:
    print(0)
    sys.exit(0)

f=int(n/500)
n%=500
ff=int(n/5)

print(f*1000+ff*5)

Solution (Python):
import sys
def resolve():
    X = int(input())
    uresisa1000 = X // 500
    uresisa5 = (X - uresisa1000 * 500) // 5
    print(1000 * uresisa1000 + 5 * uresisa5)



if __name__ == "__main__":
    resolve()

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

fi_hun = X // 500
five = (X - (500*fi_hun)) // 5

print(fi_hun*1000+five*5)

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

Solution (Python):

s = int(input())
happy = 0
if s >= 500:
    happy += 1000 * (s // 500)
    s = s % 500
if s >= 5:
    happy += 5 * (s // 5)

print(happy)

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

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

Solution (Python):


X = int(input())

gohyaku = X // 500
nokori = X % 500
goen = nokori // 5


print(gohyaku * 1000 + goen * 5)

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

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

C = 0
P = 0
D = 0
L = 0
total = 0

if X >= 0 and X <= 10 ** 9:
    while True:
        if X >= 500:
            C = X // 500
            P = 500 * C
            X = X - P
        elif X >= 5:
            D = X // 5
            L = 5 * D
            X = X - L
        else:
            break
man = 1000 * C
t   = 5 * D

total = man + t

print(total)

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

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

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

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

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

Solution (Python):
def happy(sum):
    num_of_500 = int(sum/500)
    num_of_5 = int((sum-num_of_500*500)/5)
    return num_of_500*1000 + num_of_5*5

x = int(input())
print(int(happy(x)))

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

Solution (Python):
X = int(input())
a = 0
b = 0
c = 0
d = 0
if X >= 500:
	a = X%500
	b = X-X%500
	if a >=5:
		c = a%5
		d = a-a%5
else:
	if X >= 5:
		c = X%5
		d = X-X%5
print(2*b+d)

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

Solution (Python):
z = input()

uire = (int(z)//500) * 1000 + ((int(z)%500)//5) * 5

print(uire)

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

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

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

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

print(a*1000+c*5)

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

x=n//500

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

print(x*1000+y*5)

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

Solution (Python):
x=int(input())
coin=[[500,1000],[5,5]]
ans=0
for c,h in coin:
  num = x // c
  ans += num*h
  x %= c
print(ans)

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

n=X//500
m=(X-500*n)//5

ans=1000*n+5*m
print(ans)

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

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

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

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

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

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

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

print(a*1000 + c*5)

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

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

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

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

print(happiness)

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

q,r=divmod(n,500)
res+=q*1000
q,r=divmod(r,5)
res+=q*5
print(res)

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

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

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

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

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

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

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

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

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

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

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

f = int(x / 500) * 1000

s = int((x % 500) / 5) * 5

print(f + s)

Solution (Python):

def main():
    X = int(input())
    five_hundreds, remaining = divmod(X, 500)
    happiness = five_hundreds * 1000 + (remaining // 5) * 5
    print(happiness)


if __name__ == "__main__":
    main()

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

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

Solution (Python):
x=int(input())
ans=0
if x>=500:

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

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

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

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

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

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

Solution (Python):

from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect

def LI(): return [int(x) for x in sys.stdin.readline().split()]


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


def LS(): return [list(x) for x in sys.stdin.readline().split()]


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


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


sys.setrecursionlimit(1000000)
mod = 1000000007


def solve():
    x = I()
    goh = x // 500 * 1000
    x -= goh//1000 * 500
    go = x // 5 * 5
    print(goh+go)
    return


if __name__ == "__main__":
    solve()

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

Solution (Python):

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

Solution (Python):
x = int(input())
y = 0
z = 0
while x >= 500:
    y += 1
    x -= 500
while x >= 5:
    z += 1
    x -= 5
print(y*1000 + z*5)

Solution (Python):
x = int(input())
if x < 500:
    print(x//5*5)
else:
    div_500 = x // 500
    nokori = x - div_500 * 500
    div_5 = nokori // 5
    print(div_500 * 1000 + div_5 * 5)

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

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

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

print(a)

Solution (Python):
n = int(input())
y = 0
if(n==0):
  print(y)
elif(n%500==0):
  y = int(n/500)*1000
  print(y)
else:
  j = n%500
  y = int(n//500)*1000 + int(j//5)*5
  print(y)

Solution (Python):
n=int(input())
ans=0
a=0
c=0
d=0
b=[500,100,50,10,5,1]
a=n//b[0]
c=n%b[0]
d=c//b[4]

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

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

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

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

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

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

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

Solution (Python):

x = int(input())
a = x // 500
b = (x - a * 500) // 5
ans = a * 1000 + b * 5
print("{}".format(ans))

Solution (Python):

yen = int(input())
a = yen // 500
b = (yen % 500) // 5
print(1000*a + 5*b)

Solution (Python):
X = int(input())
if X >0:   
    num = X / 500
    w = X-(int(num)*500)
    p = w / 5   
    sum = (int(num)*1000)+(int(p)*5)
else:
     sum = 0   
print(sum)

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

print(1000*n500+5*n5)

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

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

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

print(a)

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

coin1 = int(X / 500)
coin2 = int((X % 500) / 5)

print(coin1*1000 + coin2*5)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

y = x // 500
y = y * 1000

z = x % 500 // 5
z = z * 5

print(y + z)

Solution (Python):
N = int(input())
F=0
FF=0
FFF=0
FFFF = 0
if(N>=500):
    F=N/500
    FFF = int(F)
FFFF = (N-(500*FFF))
if(FFFF>5):
    FF=int(FFFF/5)
print((int(F)*1000)+FF*5)

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

Solution (Python):
sel='B'

if sel=='A':
    S=input()
    if S[2]==S[3] and S[4]==S[5]:
        print('Yes')
    else:
        print('No')

if sel=='B':
    X=int(input())
    ans=0
    ans+=(X//500)*1000
    ans+=((X%500)//5)*5
    print(ans)

if sel=='C':
    K,N=map(int,input().split())
    A=[int(i) for i in input().split()]
    d=[A[0]+K-A[-1]]
    for i in range(N-1):
        d.append(A[i+1]-A[i])
    d.sort()
    print(K-d[-1])

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

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

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

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

print(cnt)

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

Solution (Python):

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

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

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

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



pleasure = 0

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

print(pleasure)

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

Solution (Python):

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

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

while x>=5:
    if x>=500:
        x=x-500
        ans = ans + 1000
    elif x>=5:
        x = x - 5
        ans = ans + 5

print(ans)

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

c = s%500
c = c//5
print(ans+c*5)

Solution (Python):
from sys import maxsize as infinity


def exchange(amount: int) -> int:
    dp = [0] * (amount + 1)

    for to_exchange in range(amount + 1):
        dp[to_exchange] = 0

        for (coin, gain) in [(500, 1000), (5, 5), (100, 0), (50, 0), (10, 0), (1, 0)]:
            if coin <= to_exchange:
                dp[to_exchange] = max(
                    dp[to_exchange],
                    gain + dp[to_exchange - coin]
                )

    return dp[amount]


amount = int(input())
n_500, new_amount = divmod(amount, 500)
n_5, new_amount_2 = divmod(new_amount, 5)

print(n_500 * 1000 + n_5 * 5)

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

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

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

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

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

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

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


if __name__ == '__main__':
    main()

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

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

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

c500 = 0
c5 = 0

c500 = X // 500
X = X % 500

c5 = X // 5

ans = 1000 * c500 + 5 * c5
print(ans)

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

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

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

Solution (Python):
import sys
def fastio():
    from io import StringIO
    from atexit import register
    global input
    sys.stdin = StringIO(sys.stdin.read())
    input = lambda : sys.stdin.readline().rstrip('\r\n')
    sys.stdout = StringIO()
    register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()

INF = 10**20
MOD = 10**9 + 7
I = lambda:list(map(int,input().split()))

from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br

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

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

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

Solution (Python):
X=int(input())
big_ple=X//500*1000
remain=X%500
small_ple=remain//5*5
Sum=big_ple+small_ple
 
if X<5:
    print(0)
elif X<500:
    print(small_ple)
else:
     print(Sum)

Solution (Python):


x = int(input())

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

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

Solution (Python):

import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

from decimal import *

























def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

inf = float('inf')
mod = 1000000007




def main():
	X = inputInt()
	ans = 0
	ans2 = 0

	ans += X // 500
	tmp = X % 500
	ans = ans * 1000

	ans2 += tmp // 5
	ans2 = ans2 * 5


	print(ans+ ans2)







def int_sqrt2(n):
    def f(prev):
        while True:
            m = (prev + n / prev) / 2
            if m >= prev:
                return prev
            prev = m

    return f(int(math.sqrt(n) * (1 + 1e-10)))



def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res


def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y



def H(n, r, mod=10**9+7):
	
	
    return combination(n+r-1, r, mod)

class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        
        
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

if __name__ == "__main__":
	main()

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

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

bigPoint = int(money/500) * 1000

smallMoney = money - int(money/500)*500

smallPoint = int(smallMoney/5) * 5

print(bigPoint+smallPoint)

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


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






total = a * 1000 + b * 5

 
print(total)

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

Solution (Python):

x = int(input())
uresi =0
uresi = (x//500) *1000

amari = x%500


uresi += (amari//5) *5

print(uresi)

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

a = X//500
X -= 500 * a

b = X//5

print(1000*a+5*b)

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

    quo1 = X // 500
    rem = X % 500
    quo2 = rem // 5

    ans = int(quo1 * 1000 + quo2 * 5)
    print('{}'.format(ans))

if __name__ == '__main__':
    main()

Solution (Python):
n=input()
c=0
while n>=500:
    n-=500
    c+=1000
for i in range(1,n+1):
    if i%5==0:
        c+=5
print c

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

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

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

grad = int(a/500)*1000
r = a%500
grad = grad + int(r/5)*5
print(grad)

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

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

u500 = X // 500
u5 = (X % 500) // 5

print(1000 * u500 + 5 * u5)

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

five_hundred_cnt = 0
five_cnt = 0

if x >= 500:
    five_hundred_cnt = x // 500
    x %= 500
if x >= 5:
    five_cnt = x // 5

print(1000*five_hundred_cnt + 5*five_cnt)

Solution (Python):
X = int(input())
happiness = 0
while X > 0:
    if X >= 500:
        temp = int(X / 500)
        X = X - (500 * temp)
        happiness = 1000 * temp
    else:
        temp = int(X / 5)
        X = X - (500 * temp)
        happiness = happiness + (5 * temp)
        break
print(happiness)

Solution (Python):
X = int(input())
happiness = 0
while X > 0:
    if X >= 500:
        temp = int(X / 500)
        X = X - (500 * temp)
        happiness = 1000 * temp
    else:
        temp = int(X / 5)
        X = X - (500 * temp)
        happiness = happiness + (5 * temp)
        break
print(happiness)

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

Solution (Python):
x = int(input())
coins = [0,0,0,0,0,0]
coins[0] = x // 500
x -= 500 * coins[0]
coins[4] = x // 5
x -= 5 * coins[4]

h = coins[0] * 1000 + coins[4] * 5
print(h)

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

Solution (Python):
line = int(input().strip())

result = 0
result = int(line / 500) * 1000
rest = int(line % 500)

result += int(rest / 5) * 5

print(result)

Solution (Python):
X = int(input())
if X>=0 and X<=10**9:
    a, b = divmod(X, 500)
    if X >= 500:
        c = int(b/5)
        d = int(a*1000) + c*5
        print(d)
    elif X >= 5 and X <500:
        c = int(X/5)*5
        print(c)
    else:
        print(0)

Solution (Python):
X = int(input())
happiness = 0
while X > 0:
    if X >= 500:
        temp = int(X / 500)
        X = X - (500 * temp)
        happiness = 1000 * temp
    else:
        temp = int(X / 5)
        X = X - (500 * temp)
        happiness = happiness + (5 * temp)
        break
print(happiness)

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

print(1000*a + 5*c)

Solution (Python):
X = int(input())
happiness = 0
while X > 0:
    if X >= 500:
        temp = int(X / 500)
        X = X - (500 * temp)
        happiness = 1000 * temp
    else:
        temp = int(X / 5)
        X = X - (500 * temp)
        happiness = happiness + (5 * temp)
        break
print(happiness)

Solution (Python):
X = int(input())
happiness = 0
while X > 0:
    if X >= 500:
        temp = int(X / 500)
        X = X - (500 * temp)
        happiness = 1000 * temp
    else:
        temp = int(X / 5)
        X = X - (500 * temp)
        happiness = happiness + (5 * temp)
        break
print(happiness)

Solution (Python):
X = int(input())
happiness = 0
while X > 0:
    if X >= 500:
        temp = int(X / 500)
        X = X - (500 * temp)
        happiness = 1000 * temp
    else:
        temp = int(X / 5)
        X = X - (500 * temp)
        happiness = happiness + (5 * temp)
        break
print(happiness)

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

happiness_500 = int(money/500)
happiness_5 = int((money%500)/5)
print(happiness_500*1000+happiness_5*5)

Solution (Python):
I = input().split()
X = int(I[0])

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

print(U)

Solution (Python):
s = int(input())
print(s//500 * 1000 + s%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())
happiness = 0
while X > 0:
    if X >= 500:
        temp = int(X / 500)
        X = X - (500 * temp)
        happiness = 1000 * temp
    else:
        temp = int(X / 5)
        X = X - (500 * temp)
        happiness = happiness + (5 * temp)
        break
print(happiness)

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

o = int(L/500)*1000
f = int((L%500)/5)*5

print(o+f)

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

print(happiness_point)

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

count = 0

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

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

print(count)

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

ct = n // 500

ost = n - ct * 500

ans = ct * 1000 + (ost // 5) * 5

print(ans)

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):
X = int(input())
happiness = 0
while X > 0:
    if X >= 500:
        temp = int(X / 500)
        X = X - (500 * temp)
        happiness = 1000 * temp
    else:
        temp = int(X / 5)
        X = X - (500 * temp)
        happiness = happiness + (5 * temp)
        break
print(happiness)

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