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):
def count_section_by_zero(data):
  count = 0
  flg = False
  start = 0
  for i, d in enumerate(data):
    if flg is False and d != 0:
      count += 1
      flg = True
      
    if d == 0:
      flg = False
  return count

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

def input_list_str():
  return list(map(str, input().split()))

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


def divide_two(arg):
  c = 0
  while True:
    if c >= 2:
      break
    if arg % 2 != 0:
      break
    arg //= 2
    c += 1
  return c


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def main():
  x = int(input())
  x_500 = 0
  x_5 = 0
  if x >= 500:
    x_500 = x//500
  x -= x_500 * 500
  if x >= 5:
    x_5 = x//5
  print(int(x_500*1000 + x_5 *5))
import math
import fractions
import collections
import itertools
from functools import reduce
main()

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

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

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

big_cnt = 0
sml_cnt = 0

all_money_mod = all_money

while(all_money_mod >= 500):
  all_money_q = all_money // 500
  all_money_mod = all_money % 500
  
  big_cnt += all_money_q
  
  if all_money_mod < 500:
    break
  
  all_money = all_money_mod

all_money = all_money_mod
  
while(all_money_mod >= 5):
  all_money_q = all_money // 5
  all_money_mod = all_money % 5
  
  sml_cnt += all_money_q
  
  if all_money_mod < 5:
    break
  
  all_money = all_money_mod
  
hapiness = big_cnt * 1000 + sml_cnt * 5
print(hapiness)

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

Solution (Python):
x = int(input())
t = divmod(x, 500)
print(t[0]*1000 + (t[1]//5)*5)

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

point = 0
if X//500 > 0:
    s = X//500
    point += s*1000
    X = X - 500*s
if X//5 > 0:
    s = X//5
    point += s*5
    X = X - 5*s
if X//100 > 0:
    s = X//100
    X = X - 100*s
if X//50 > 0:
    s = X//50
    X = X - 50*s
if X//10 > 0:
    s = X//10
    X = X - 10*s
if X//1 > 0:
    s = X//1
    X = X - 1*s

print(point)

Solution (Python):
X = int(input())
A = 0
B = 0

A = X - X % 500
A500 = A / 500 * 1000

A5 = X % 500 - (X % 500) % 5
A5 = A5 / 5 * 5
A = int(A500) + int(A5)
B = (X - X % 5)
B = int(B / 5 * 5)

print(int(max(A, B)))

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())
a=n//500
n=n%500

e=n//5
n=n%5

ans=a*1000+e*5


print(ans)

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

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

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

Solution (Python):

money = int(input())

gohyaku = money // 500
tmp_money = money - (500 * gohyaku)

goen = tmp_money // 5

print(int((gohyaku * 1000) + (goen * 5)))

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

ans = 0

ans += (n//500)*1000

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

print(ans)

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

neko = money // 500

amari = money % 500 

koneko = amari // 5

siawase = neko * 1000 + koneko * 5

print(siawase)

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

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

print(x + y)

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

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

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

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

Solution (Python):

coin = int(input())
reward = (coin // 500) *1000
coin = coin - (coin // 500)*500
reward +=  (coin // 5) * 5
print(reward)

Solution (Python):
import math

x = (int)(input())
ret = 0

fh = math.floor((x / 500))
ret = ret + fh * 1000
x = x - fh * 500

f = math.floor((x / 5))
ret = ret + f * 5

print("{}".format(ret))

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

Solution (Python):
user_input = eval(input())
print((user_input // 500) * 1000 + ((user_input % 500) // 5) * 5)

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

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

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

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

    
print(h)

Solution (Python):

X = int(input(""))

X500 = X//500
X_a = X%500

X5 = X_a//5

happy = X500*1000 + X5*5

print(happy)

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


five_hundred_coins = money // 500
five_yes_coins     = (money - five_hundred_coins*500) // 5

print(five_hundred_coins*1000+five_yes_coins*5)

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

coin500 = X % 500
resultcoin500 = X // 500

resultcoin5 = coin500 // 5

print(resultcoin5*5+resultcoin500*1000)

Solution (Python):
import sys
input = sys.stdin.readline
from collections import defaultdict, Counter

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

Solution (Python):
inp = input()
inp = int(float(inp))
aaa = 0
bbb = 0
yyy = 0

if 0 < inp and inp <= 10**9:
  if 500 <= inp:
    big = inp // 500
    aaa = big * 1000
    amari = inp % 500
    if 5 <= amari:
      smo = amari //5
      bbb = smo *5
    print(aaa+bbb)
  elif 5 <= inp:
    hhh = inp // 5
    yyy = hhh * 5
    print(yyy)
else:
  print(0)

Solution (Python):
X = eval(input())
if 0 <= X <= 10 ** 9:
    print((X // 500) * 1000 +((X % 500) // 5) * 5)

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

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

print(a + b)

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

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

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

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

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

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

main()

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

count = 0
count += (a//500)*1000
count += ((a%500)//5 * 5)

print(count)

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

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

hoge = int(a) * 1000
fuga = int(b) * 5

print(hoge + fuga)

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

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

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

if n >= 500:
    q, mod = divmod(n, 500)
    uresisa = uresisa + (q * 1000)
    n = n - (500 * q)

q, mod = divmod(n, 5)
uresisa = uresisa + (q * 5)

print(uresisa)

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

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

Solution (Python):
intInput = int(input())
a, b, c, d, e, f = 500, 100, 50, 10, 5, 1
sumResult = 0

num500 = intInput // 500
mod500 = intInput % 500
sumResult += num500 * 1000
num5 = mod500 // 5
sumResult += num5 * 5
print(sumResult)

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

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

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

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

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

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

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

Solution (Python):
import numpy as np







x = int(input())
n500 = x//500
n5 = (x - n500*500 )//5
ans = n500 * 1000 + n5 * 5
print(ans)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

s=int(g/500)

d=int(g%500)

f=int(d/5)

io=s*1000+f*5

print(io)

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

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

if n < 500:
  while n % 5 != 0:
    n -= 1
    if n % 5 == 0:
      print(n)
      exit()
      
b = n % 500
a = n - b

ans = a*2
    
while b %5 != 0:
  b-=1
  if b%5 == 0:
    ans += b
    
print(ans)

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

joy_500 = int(B/500)*1000
next1 = B % 500
if next1 == 0:
    print(joy_500)
else:
    joy_5 = int(next1/5)*5
    next2 = next1 % 5
    print(joy_500 + joy_5)

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

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

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

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

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

print(f*1000+ff*5)

Solution (Python):
X = int(input())
i = 0
fain = 0

while i == 0:
    while 500 <= X:
        X -= 500
        fain += 1000
        
    if 5 <= X:
        X -= 5
        fain += 5
    else:
        i += 1

print(fain)

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())
q, mod = divmod(X, 500)
print(q*1000+mod // 5*5)

Solution (Python):
X = int(input())
if X>=500:
    hap_yen = int(X / 500)
    to_hap_yen = hap_yen * 1000
    remain_X = X - (hap_yen * 500)
    remain_hap_yen = int(remain_X / 5)
    remain_hap_yen1=remain_hap_yen*5
    total_hap_yen = to_hap_yen + remain_hap_yen1
    print(int(total_hap_yen))
else:
    hap_yen=int(X/5)
    total_hap_yen=hap_yen*5
    print(total_hap_yen)

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

Solution (Python):

x = input()
Happy_500 = int(x)//500
amari = int(x)%500
Happy_5 = amari//5
Happy = Happy_500*1000 + Happy_5*5
print(Happy)

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


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

glad = a * 1000 + b * 5

print(glad)

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

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

print(1000*a+5*c)

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


def dvd(a, b):
    cnt = 0
    while a >= b and a is not 0:
        a = a - b
        cnt += 1
    if b == 500:
        return b * 2 * cnt, a
    else:
        return b * cnt, a


print(dvd(x, 500)[0] + dvd(dvd(x, 500)[1], 5)[0])

Solution (Python):
import math




data = int(input())


big_coins = data//500
left_over = data%500
small_coins = left_over//5

happy = big_coins*1000 + small_coins*5

print(happy)

Solution (Python):


I =int(input())




    
if I>=500:
    J=I//500
    
    K=J*500*2
    
    
    P=I-500*J
    if P==0:
        print(K)
    
    if P>=5:
        Q=P//5
        R=Q*5
        
        A=K+R
        print(A)

if I<500:
        M=I//5
        A=M*5
        
        
        print(A)

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

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

Solution (Python):
X = int(input())
if (X >= 0) and (X <= 10**9):
    H = X // 500
    G = (X - (H * 500)) // 5
    Y = (H * 1000) + (G * 5)
    print(Y)

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

val500, val5 = 0, 0

while (x >= 500):
    x = x - 500
    val500 += 1
while (x >= 5):
    x = x - 5
    val5 += 1

print(val500 * 1000 + val5 * 5)

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

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

Solution (Python):
user_input = eval(input())
print((user_input // 500) * 1000 + ((user_input % 500) // 5) * 5)

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

Y = X%500

print((X - Y)*2 + (Y - Y%5))

Solution (Python):
X = int(input())
if (X >= 0) and (X <= 10**9):
    print((X // 500) * 1000 + (((X - ((X // 500) * 500)) // 5) * 5))

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

Solution (Python):
coin = int(input())
fivet_yen = 0
five_yen = 0
if coin == 0:
    print(0)
else:
   while(coin > 0):
    if coin >= 500:
        coin = coin - 500
        fivet_yen = fivet_yen + 1000
    else:
        if coin >= 5:
            coin = coin - 5
            five_yen   = five_yen + 5
        else:  
            coin = coin - 1
   print(fivet_yen + five_yen)

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

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

Solution (Python):
coin = int(input())
fivet_yen = 0
five_yen = 0
if coin == 0:
    print(0)
else:
   while(coin > 0):
    if coin >= 500:
        coin = coin - 500
        fivet_yen = fivet_yen + 1000
    else:
        if coin >= 5:
            coin = coin - 5
            five_yen   = five_yen + 5
        else:  
            coin = coin - 1
   print(fivet_yen + five_yen)

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

n_500 = n // 500
n_ = n % 500
n_5 = n_ // 5

print(1000 * n_500 + 5 * n_5)

Solution (Python):
import sys

input = sys.stdin.readline

X = int(input())

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

print(1000*a + 5*b)

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

count = 0  
count = (X//500)*1000
amari = X%500
count += (amari//5)*5

print(count)

Solution (Python):
inputText1 = input()

inputNumber1 = int(inputText1)
c500 = 0
c5 = 0
c500 = inputNumber1 // 500
inputNumber1 = inputNumber1 % 500
c5 = inputNumber1 // 5
print((c500 * 1000) + (c5 * 5))

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

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

ans = 0

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

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

Solution (Python):


import math
X = int(input())
LX = X / 500
Amari = X % 500
SX = Amari / 5

print(math.floor(LX) * 1000 + math.floor(SX)* 5)

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

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

Solution (Python):
import numpy as np
X = int(input())

A = int(X / 500)
B = int(int(X % 500) / 5)

print(A * 1000 + B * 5)

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

num_500 = int(X/500)
num_5 = int((X - num_500*500)/5)
happy = num_500*1000 + num_5*5
print(happy)

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

x=0
while(n>=5):
	if (n>=500):
		x+=1000;
		n-=500;
	elif(n>=5):
		x+=5;
		n-=5;
print(x)

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

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

c=S//500
g =S%500
k =g//5
h =1000*c +5*k
print(h)

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

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

print(ans)

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

Solution (Python):
x = int(input())
res = 0
while x > 4:
    if x >=500:
        res += 1000
        x-=500
    else:
        while x>= 5:
            x -= 5
            res+= 5
print(res)

Solution (Python):
from sys import stdin

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

counter = 0
for i in range(2000000):
    if x - 500 >= 0:
        x = x - 500
        counter += 1000
    else:
        break
for i in range(102):
    if x - 5 >= 0:
        x = x - 5
        counter += 5
    else:
        break

print(counter)

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

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

s_500 = int(s / 500)
s_5   = int((s-s_500*500) / 5)

print(s_500*1000 + s_5*5)

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

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

Solution (Python):
import math

x = int(input())

p = 0
p += math.floor(x/500)*1000

x -= p/1000*500
p += math.floor(x/5)*5

print(p)

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

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

print(happy)

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

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

Solution (Python):

"""
Created on Thu Dec 19 22:37:09 2019

@author: lucifer
"""
n=int(input())
if n%500==0:
  print(1000*int(n/500))
else:
  s=int(n/500)
  x=1000*s+int((n-(s*500))/5)*5
  print(x)

Solution (Python):
import sys

for X in sys.stdin:
    X=int(X)
    res=(int(X/500))*1000 +int((X%500)/5)*5
    print(res)

Solution (Python):
x = int(input())
f = int(x/500) 

if x % 500 != 0:
    c = int((x-500*f)/5)
    print(1000*f + 5*c)
elif x % 500 == 0:
    print(1000*f)

Solution (Python):
c=int(input())
u=0
if c%500<500:
    u+=(1000*(c//500))
    x=c-(c//500*500)
if x%5<5:
    u+=(5*(x//5))

print(u)

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

print(ans)

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

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

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

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

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

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

if x >= 500:
    golden_coins += (x // 500) * 1000
    x %= 500

if x >= 5:
    golden_coins += (x // 5) * 5
    x %= 5
print(golden_coins)

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

n_500, rem = divmod(tot, 500)
n_5 = rem // 5

print(str(n_500 * 1000 + n_5 * 5))

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

nOf1000 = X//500*1000
remainMo = X%500
nOf500 = remainMo//5*5

print(nOf1000+nOf500)

Solution (Python):
a=int(input())
k=0
c=a//500
d=a%500
s=d//5
s1=a-d
print(c*1000+s*5)

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

hapiness1000 = (x//500)*1000
hapiness5 = ((x%500)//5)*5

print(hapiness1000+hapiness5)

Solution (Python):
X = int(input())
a_500 = 0
a_5 = 0

if(X >=500):
    a_500 = X//500
    X = X - 500*a_500
else:
    pass

if(X >=5):
    a_5 = X//5
    X = X - 5*a_5
else:
    pass

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

Solution (Python):
a=int(input())
h=0
if a>=500:
	c=a//500
	h+=c*1000
	a-=c*500

if a>=5:
	d=a//5
	h+=d*5
	a-=d*500

print(h,end="")

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

a,b = divmod(x,500)
b = int(b/5)

print(a * 1000 + b * 5)

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

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):
S = int(input())
happy1000 = int(S/500)

happy5 = int((S-happy1000*500)/5)

print(happy1000*1000+happy5*5)

Solution (Python):
n=int(input())
q, mod = divmod( n,500)
gm, mad =  divmod(mod,5)

if mod==0:
     print(q*1000)
elif  mod!=0:
    print(q*1000+gm*5)

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

if x >= 500:
    golden_coins += (x // 500) * 1000
    x %= 500

if x >= 5:
    golden_coins += (x // 5) * 5
    x %= 5
print(golden_coins)

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

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

Solution (Python):
X = int(input())
coin = int(X/500)
normal_coin = int((X - (coin * 500))/5)
golden_coin_point = coin*1000
normal_coin_point = normal_coin*5
print(golden_coin_point+normal_coin_point)

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

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

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

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

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

res_500 = X // 500

rem_500 = X % 500

res_5 = rem_500 // 5

print(1000 * res_500 + 5 * res_5)

Solution (Python):



from sys import stdin


def main():
    X = int(stdin.readline())

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


if __name__ == "__main__":
    main()

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

Solution (Python):
i = int(input())
big = i // 500
last = i - (big*500)
mini = last // 5

print((big*1000)+(mini*5))

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

Solution (Python):


X=int(input())

T=X//500
S=(X%500)//5

print((T*1000)+(S*5))

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



div, mod = divmod(x, 500)




divdiv, modmod = divmod(mod, 5)




print((div * 1000) + (divdiv * 5))

Solution (Python):
x = int(input())
m500 = 0
m5 = 0
if (x >= 500):
    m500 = x // 500
x = x - m500 * 500
if (x >= 5):
    m5 = x // 5

ans = m500 * 1000 + m5 * 5
print(ans)

Solution (Python):
X=input()
y=int(X)
z=0
while y>=500:
   y-=500
   z+=1
a=0
while y>=5:
    y-=5
    a+=1
   
result=z*1000+a*5
str_result=str(result)
print(str_result)

Solution (Python):

def main():
    pocket = int(input())

    if(pocket<5):
        num_500 = 0
        num_005 = 0
    elif(pocket<500):
        num_500 = 0
        num_005 = int(pocket/5)
    else:
        num_500 = int(pocket/500)
        num_005 = int((pocket-(500*num_500))/5)

    val = 1000*num_500 + 5*num_005

    print(val)

main()

Solution (Python):

X = int(input())
if X<500:
    print((X//5)*5)
else:
    print((X//500)*1000+((X%500)//5)*5)

Solution (Python):
import math
X = int(input())
A = X/500
A=math.floor(A)
Q=1000*A
D=A*500
Y=X-D
B = Y/5
B = math.floor(B)
B= 5*B
print(int(Q+B))

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

Solution (Python):
a = int(input())
sen = a // 500
go = (a % 500) // 5
print('{}'.format(sen*1000+go*5))

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

Solution (Python):
coins = [500, 5, 100, 50, 10, 1]
uresimi = {500: 1000, 5: 5}


def get_uresimi(money, coin_type):
    coin_count = money // coin_type
    if coin_count == 0:
        return 0, money
    surplus = money % (coin_type * coin_count)
    uresisa = uresimi.get(coin_type, 0) * coin_count
    return uresisa, surplus


m = int(input())
uresii = 0
for c in coins:
    u, m = get_uresimi(m, c)
    uresii += u

print(uresii)

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

uresi = (X // 500) * 1000
X = X % 500

uresi += (X // 5) * 5
X = X % 5

print(uresi)

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

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

Solution (Python):
S = int(input())
G = 500
GG = 5

g_count = 0
gg_count= 0

while S >= G:
  S = S - G
  g_count += 1
while S >= GG:
  S = S - GG
  gg_count += 1
print(g_count*1000 + gg_count*5)

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

h=0

h1=int(x/500)

x-=h1*500

h+=h1*1000

h2=int(x/5)

h+=h2*5

print(h)

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

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

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

Solution (Python):
import math

X = int(input())
total_500 = 0
total_5 = 0
total_count = 0

if(X >= 500):
    total_500 = math.floor(X/500)
    total_count += total_500 * 1000
    X -= total_500 * 500

if(X >= 5):
    total_5 = math.floor(X/5)
    total_count += total_5 * 5
    X -= total_5 * 5

print(total_count)

Solution (Python):
K = 0
N = 0
N = int(input())
if N >= 500:
  K = N // 500
  N = N - (500*K)

L = N // 5

M = K * 1000 + L * 5
print(M)

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

Solution (Python):
import sys; sys.setrecursionlimit(2147483647); input = sys.stdin.readline
from math import floor, ceil, sqrt, factorial, log
from collections import Counter, defaultdict, deque
from operator import itemgetter
INF = float('inf'); MOD = 10**9+7
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(MI())
def LIR(n): return [LI() for i in range(n)]
def IS(): return input().rstrip()

def main():
    X = I()
    a = 0
    if X >= 500:
        a += (X//500)*1000
        X = X%500
    if X >= 5:
        a += (X//5)*5
    print(a)

if __name__ == '__main__':
    main()

Solution (Python):
money = int(input())
coin500, money = divmod(money, 500)
coin5, _ = divmod(money, 5)
print(coin500 * 1000 + coin5 * 5)

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

s=0
t=0

if X>=500:
    s=1000*(X//500)

if  (X-500*(X//500))>=5:
    b=(X-500*(X//500))//5
    t=5*b

print(int(s+t))

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

Solution (Python):

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

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

fivehun = int(x / 500)
x = x % 500
five = int(x / 5)

print(fivehun*1000+five*5)

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

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

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

print(1000*a + 5*b)

Solution (Python):
from sys import stdin,stdout

input = stdin.readline
print = stdout.write

n = int(input())

coins = [500,5]
d = {500:1000,5:5}

ans = 0

for i in coins:
    if i<=n:
        
        ans+= ((n//i) * d[i])
        n = n%i
        
print(str(ans))

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

while X > 0:
    if X - 500 >= 0:
        happy += 1000 * (X // 500)
        X -= 500 * (X // 500)
    elif X - 5 >= 0:
        happy += 5 * (X // 5)
        X -= 5 * (X // 5)
    elif X - 1 >= 0:
        X -= 1

print(happy)

Solution (Python):

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

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

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

print(a * 1000 + b * 5)

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

Solution (Python):
x=int(input())
c_con=x//500
con=c_con*1000

x=x-500*c_con
x_con=x//5
con+=x_con*5

print(con)

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

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

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

Solution (Python):
if __name__ == "__main__":
    X = int(input())
    A = X // 500 * 1000 + X % 500 // 5 * 5
    print(A)