peterverebics/CodeNet_Python_118 huggingface dataset:
x = int(input())

cnt_500 = 0
cnt_5 = 0
while x > 4:
    if x >= 500:
        x -= 500
        cnt_500 += 1
    else:
        x -= 5
        cnt_5 += 1

print(1000*cnt_500+5*cnt_5)
x = int(input())
print(x//500 * 1000 + (x%500)//5 * 5)
# -*- coding: utf-8 -*-
X = int(input())
count = 0
while X >= 500:
    X -= 500
    count += 1000
while X >= 5:
    X -= 5
    count += 5
print(count)
X = int(input())
ans = 0
while X > 5:
  if (X-500) >= 0 : 
    ans += 1000
    X -= 500
  elif (X-5) >= 0 : 
    ans += 5
    X -= 5
print(ans)
money_val = int(input())

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

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

print(ans)
def resolve():
    x = int(input())
    n500, x = divmod(x, 500)
    n5 = x // 5
    res = n500 * 1000 + n5 * 5
    print(res)


if __name__ == "__main__":
    resolve()
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

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

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

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

    print(ans)

if __name__ == "__main__":
    main()
X = int(input())

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

X %= 500

ans += (X // 5) * 5
print(ans)
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)
X = int(input())

c500 = X // 500
c5 = (X - (c500 * 500)) // 5

print(c500 * 1000 + c5 * 5)
x = int(input())
ans = 0

a = int(x / 500)
ans = ans + a * 1000

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

print(ans)
y = int(input())
a=(y//500)
b=(y-a*500)//5
print(a*1000+b*5)
x=int(input())
happiness = 0
if x>=500:
    ans = divmod(x,500)
    happiness += 1000*ans[0]
    x = ans[1]

if x>=5:
    ans =divmod(x,5)
    happiness += 5*ans[0]

print(happiness)
x = int(input())

x2 = x//500
x3 = (x-x2*500)//5
print(x2*1000+x3*5)
X = int(input())
A = X // 500
B = X - A*500
C = B // 5
print(A*1000+C*5)
x = int(input())
big = x // 500
small = x % 500 // 5
grace = big*1000 + small*5
print(grace)
x = int(input())

large_coin = x//500
x -= large_coin*500
small_coin = x//5

print(large_coin*1000+small_coin*5)
N = input()

x = int(N)

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

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

print(a*1000+c*5)
x = int(input())

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

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

if __name__ == '__main__':
    main()
x = int(input())
ans = x // 500 * 1000 + x % 500 // 5 * 5
print(ans)
X=int(input())

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

tmp=X
total=0

result=[]

result.append(int(tmp/500))

tmp=tmp%500

result.append(int(tmp/5))

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

print(total)
X=int(input())
a,b=divmod(X,500)
c=b//5
print(int(a*1000+c*5))
import itertools
import math
import fractions
import functools
x = int(input())
hp = 0

hp = x//500 * 1000
x = x - x//500 * 500

hp += x//5 *5
print(hp)
n = int(input())
a = n % 500
b = int((n - a)/500)
c = a % 5
d = int((a - c)/5)
print(1000*b + d*5)
x = int(input())
ha = 0

if x >= 500:
  ha  += (x // 500)*1000
  x %= 500
  
if x >= 5:
  ha += (x // 5)*5
 
print(ha)
X = int(input())

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

ans += X // 5 * 5

print (ans)
#author : dokueki

import sys


def IOE():
    sys.stdin = open("input.txt", "r")
    sys.stdout = open("output.txt", "w")


def main():
    n = int(sys.stdin.readline())
    print((n//500)*1000+(((n-(n//500)*500))//5)*5)


if __name__ == "__main__":
    #IOE()
    main()
n = int(input())
cnt = 0
cnt += 1000 * (n // 500)
cnt += 5*((n % 500) // 5)
print(cnt)
inputText1 = input()
# inputText1 = "1000000000"
inputNumber1 = int(inputText1)
c500 = 0
c5 = 0
c500 = inputNumber1 // 500
inputNumber1 = inputNumber1 % 500
c5 = inputNumber1 // 5
print((c500 * 1000) + (c5 * 5))
x = int(input())
# a,b = map(int, input().split())
# l = list(map(int, input().split()))

ans = 0
r5 = int(x/500)
x= x- 500*r5
r1 = int(x/5)
print(r5*1000 + r1*5)
n=int(input())
i=0
t=0
while(n>499):
    i+=1
    n+=-500
while(n>4):
    t+=1
    n+=-5
r=1000*i+5*t
print(r)
x = int(input())
a = x // 500
print((x // 500) * 1000 + ((x - 500 * a) // 5) * 5)
x = int(input())
q, r = divmod(x, 500)
print(q*1000 + (r // 5) * 5)
X=int(input())
A=X//500
A2=X%500
B=A2//5
ans=(A*1000+B*5)
print(ans)
from sys import stdin
def main():
    readline=stdin.readline
    x=int(readline())
    y=x//500
    print(y*1000+((x-y*500)//5)*5)
        
if __name__=="__main__":
    main()
x = int(input())
coins = [500, 5]
happy = [0] * 2
for coin in coins:
    if coin == 500:
        happy[0] = x // coin
    elif coin == 5:
        happy[1] = x // coin
    x = x % coin

print(1000 * happy[0] + 5 * happy[1])
x = int(input())
res = 0
res += 1000*(x//500)
res += ((x%500) // 5) * 5
print(res)
x = int(input())
ans = 0
ans += x//500 * 1000
x %= 500
ans += x//5 * 5
print(ans)
n = int(input())

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

print(a*1000+b*5)
X = int(input())
ans = (X // 500)*1000
ans += ((X % 500) // 5)*5
print(ans)
def main(money):
    happiness = 0

    happiness += (money // 500) * 1000
    money = money % 500

    happiness += (money // 5) * 5

    print(happiness)


main(int(input()))
X = int(input())
k = X % 500
ans = (X // 500)*1000
ans += (k // 5)*5

print(ans)
def main():
    X = int(input())
    n500 = X//500
    X -= n500*500
    n5 = X//5
    print(1000*n500+5*n5)
main()
def LI():
    return list(map(int, input().split()))


X = int(input())
ans = X//500*1000
X = X % 500
ans += X//5*5
print(ans)
#2020-03-28
#ABC
S = int(input())
count = int(S / 500)
sum = 1000 * count
S = S - 500*count
sum = sum + 5*(int(S/5))
print(sum)
n = int(input())
#a,b = map(int,input().split())
#L = list(map(int,input().split()))
n1 = n//500
n2 = (n-n1*500)//5
#print(n1,n2)
print(n1*1000 + n2*5)
x = int(input())
ans = 0
ans = (x//500) * 1000
x = x%500
ans += (x//5) * 5
print(ans)
X = int(input())

A = 0
B = 0

if X >= 500:
    A = X // 500
    X = X % 500
if X >= 5:
    B = X // 5
    X = X % 5

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

div, mod = divmod(x, 500)

print(div * 1000 + mod // 5 * 5)
x = int(input())
p_1000 = x // 500
y = x % 500
p_5 = y // 5
print(p_1000 * 1000 + p_5 * 5)
n = int(input())
ans = 0
if n//500>0:
    ans += 1000 * (n//500)
    n = n - 500 * (n//500)
if n//5>0:
    ans += 5 * (n//5)
print(ans)
X = int(input())
happ = (X // 500) * 1000
X = X % 500
happ += (X // 5) * 5
print(happ)
# -*- coding: utf-8 -*-
x = int(input())

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

print(int(v_1000*1000 + v_5*5))
X=int(input())
C=X//500
c=(X-X//500*500)//5
print(C*1000+c*5)
X = int(input())

FH = X//500
F = X%500//5

print(FH*1000+F*5)
num = int(input())

happiest = 0
happy = 0

if num >= 500:
  happiest = int(num/500)
  num = num % 500
if num >= 5:
  happy = int(num/5)

print(int(happiest*1000+happy*5))
x=int(input())
k= x%500
l= k//5
m=x//500
print(1000*m + l*5)
s = int(input())
print((s//500)*1000+(s%500)//5*5)
X = int(input())
ans = X // 500 * 1000
X %= 500
ans += X // 5 * 5
print(ans)
x= int(input());  s = 0
while(x>=5):
    if x >= 500:
        s += 1000;        x -= 500
    elif x >= 5:
        s += 5;        x -= 5
print(s)
X = int(input())

total = 0

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

print(a * 1000 + b * 5)
x = int(input())
a = x // 500
x -= a * 500
ans = 0
ans += 1000 * a 
b = x // 5 
ans += 5 * b 
print(ans)
import math
import itertools
import statistics
#import collections
x = int(input())
#A = (map(int, input().split()))

total = 0
total += (x//500) *1000
x = x%500

total += (x//100)* 20 *5
x = x%100
total += (x//50) *10*5
x = x%50
total += (x//10) * 2*5
x = x%10
total += (x//5) *5

print(total)
X=int(input())

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

d=X//5
point2=d*5

sum=point1+point2
print(sum)
X = int(input())
# print(X)

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

# print(list)

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

c = a+b


print(c)
n=int(input());
ans = n//500
n-=ans*500
ans*=1000
ans+=n//5*5
print(ans)
X = int(input())
a = X // 500
b = (X - a*500) // 5
print(1000*a + 5*b)
x=int(input())

ans=(x//500)*1000+((x%500)//5)*5
print(ans)
x = int(input())
# 500円をできるだけ多く残りを5円にする。
n500 = x // 500
left = x - 500 * (x//500)
n5 = left // 5
print(n500*1000+n5*5)
X = int(input())

a = X // 500

b = X % 500 // 5

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

print(a*1000+c*5)
x = int(input())

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

ans = 0
ans += X//500 * 1000
X = X-X//500 * 500
ans += X//5 * 5
print(ans)
N = int(input())
NN = N // 500
MM = N % 500
LL = MM // 5
#print(NN, LL)
print(NN * 1000 + LL * 5)
x=int(input())
print(x//500*1000 + (x%500)//5*5)
x=int(input())
def money(x):
    if x==0:
        return 0
    cnt500=0
    cnt5=0

    while x>=500:
        x-=500
        cnt500+=1
    if x==0:
        return cnt500*1000
    
    while x>=5:
        x-=5
        cnt5+=1
    return cnt500*1000+cnt5*5
print(money(x))
N = int(input())
a = N//500
N = N-500*a
b = N//5
print(1000*a + 5 * b)
import sys
from sys import exit
from math import gcd, factorial, ceil, floor, sqrt
from bisect import bisect_left, bisect_right
from copy import deepcopy
from heapq import heapify, heappop, heappush
from itertools import permutations, combinations, product, accumulate
from collections import defaultdict, deque
sys.setrecursionlimit(10**7)

ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(map(int, input().split()))

X = ii()
a = X//500 * 1000
b = (X-X//500*500)//5 * 5
print(a+b)
X = int(input())
ans = 0
ans += (X // 500) * 1000
X = X % 500
ans += (X // 5) * 5
print(ans)
X = int(input())
ans = X//500 * 1000
ans += (X%500)//5 * 5
print(ans)
X = int(input())

sou = (X // 500) * 1000
resid = ((X % 500) // 5) * 5
print(sou + resid)
n = int(input())
res = (n//500) * 1000 + ((n % 500)//5)*5
print(res)
x = int(input())
ans = 0
while(x > 5):
  if x >= 500:
    ans += (x // 500) * 1000
    x = x % 500
    continue
  if x >= 5:
    ans += (x // 5) * 5
    x = x % 5
    continue    

    
print(ans)
x = int(input())
fh = x//500
x -= fh*500
f = x//5
print(fh*1000+f*5)
x= int(input())
print((x//500)*1000 + (x % 500)//5*5)
x = int(input())


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

ans = 0
ans += x//500 * 1000
x %= 500
ans += x//5 * 5
print(ans)
X=int(input())
print(1000*(X//500)+5*((X%500)//5))
#!/usr/bin/env python3
import sys


def solve(X: int):
    gohyaku = X // 500
    nokori = X % 500
    go = nokori // 5
    print(1000*gohyaku + 5 * go)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    solve(X)

if __name__ == '__main__':
    main()
x = int(input())

count_a = x// 500
x = x%500
x = x% 100
x = x%50
x = x%10
count_b = x // 5

print(count_a*1000+count_b*5)
X = int(input())

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

print(happiness)
x = int(input())
ans = 0

ans += (x // 500) * 1000
x -= (x // 500) * 500
print(x, ans)
ans += (x // 5) * 5
x = int(input())
Y = [500, 100, 50, 5, 1]
ans = 0
for i in Y:
    if i == 500:
       ans +=  (x // i)*1000
    elif i == 5:
        ans +=  (x // i)*5
    x -= (x//i)*i
    if x == 0:
        break
print(ans)
coin = int(input())
coin = coin * 2

if coin == 0:
    print(0)
else:
    print(coin)
x = int(input())
print((x//500*1000) + (x%1000//5*5))
X=int(input()) #1200
a=X//500 #2
b=(X-500*a)//5  #
print(a+b)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-*-

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()
n=int(input())
tener=int(n/500)
res=n-tener
fiver=int(res/5)
print((tener*1000)+(fiver*5))
# 計算
X = 1000000000
uresisa_500yen = (X // 500) * 1000
mod = (X % 500)
uresisa_5yen = (mod // 5) * 5

uresisa_total = uresisa_500yen + uresisa_5yen
print(uresisa_total)
X = int(input())

#500
X_500 = X // 500 * 2
#5
X_5 = (X % 500) // 5 * 5

print(X_500 + X_5)
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
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 LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

INF = float('inf')

def solve():
    x = II()

    t = x // 500
    x = x - 500 * t

    t2 = x % 5
    # print(t, t2)
    print(1000*t + 5 * t2)


if __name__ == '__main__':
    solve()
x = int(input())
gold = x % 500
silver = (x - 500*gold) % 5
fun = gold*1000 + silver*5
print(fun)
x = int(input())
t = x//500
print(t * 1000 + ((x - 500 * t) % 5) * 5)
a = int(input())
print(a//5*500+a//5*5)
x = int(input())

num_500 = int(x / 500)

amari = x - num_500

num_5 = int(amari / 5)

print(1000 * num_500 + 5 * num_5)
b=int(input())
if b>=10:
      overall=b*2
      print(overall)
elif b<=9 and b>0:
      print(b)
elif b<=0:
      print(0)
a=int(input())
if a % 500 == 0:
  print(a * 2)
else:
  print(round(a,-2) * 2 + int((a % 500) / 5) * 5)
inp = int(input())
add = int(inp / 500) * 1000
add += ((inp % 100) % 5) * 5
print(add)
X = int(input())
a = X // 500

Y = X - 500 * a
b = Y // 5
print(a)
print(a * 1000 + b * 5)
x = int(input())
happy = 0

happy += 1000*(x//500)
happy += 5*((x%500)%5)
print(happy)
N = int(input())
A = N//500
B = (N-A)//5
print(A*1000+B*5)
n = int(input())
a = n//500
b = a//5
print(1000*a+b)
en=int(input())

res=en/500+(en%500)/5

print(res)
X = int(input())
u = 1000*(X//500) + 5*((X%1000)//5)
print(u)
s = int(input())
print((s//500)*1000 +  ((s%500)%5)*5 )
x=int(input())
happiness=0
if(x>500):
	sum_amount=x//500
	happiness+=sum_amount*1000
	diff=x-happiness/2	
	z=int(diff/5)
	happiness+=z*5
	print(happiness)	

elif(x<500):
	k=int(x/5)
	ans=k*5
	print(ans)
x = int(input())
print(1000*(x//500) + 5*((x%500)%5))
coin = int(input())
siawase = 0
if coin >= 500:
    siawase = siawase + int(coin / 500) * 1000
    amari = coin % 500
    print(siawase)
    print(amari)
    siawase = siawase + int(amari / 5) *5
elif coin >= 5:
    siawase = siawase + int(coin / 5) * 5
    
print(int(siawase))
en=int(input())

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

print(a*1000+b*5)
X=int(input())
if X>=5:
	div500=X//500
	X=X-div500*500
	div5=X//5
	print(div500*1000+div5*5)
n=int(input())
print(1000*(n//500) + 5*((n//500)//5))
input_X = int(input())

result_500 = input_X // 500
result_500ureshi = result_500 * 1000
result_5ureshi = (input_X - result_500 * 500) // 5 * 5

print(result_500ureshi)
print(result_5ureshi)
result = int(result_500ureshi + result_5ureshi)
print(result)
n=int(input())
print(1000*(n//500)+5*((n-(n%500)*500)%5))
x = int(input())
ans = x // 500 * 1000 + x % 1000 // 5 * 5
print(ans)
import bisect,collections,copy,itertools,math,string
def I(): return int(input())
def S(): return input()
def LI(): return list(map(int,input().split()))
def LS(): return list(input().split())
##################################################
X = I()
_500 = X//500
_nokori = (X%500)//5
print(_nokori)
print(_500*1000+_nokori*5)
# B - Golden Coins
X = int(input())
ans = 1000*(X%500)
X //= 500
ans += 5*(X%5)
print(ans)
X = int(input())

#500
X_500 = X // 500 * 2
#5
X_5 = (X % 500) // 5

print(X_500 + X_5)
x=int(input())
u=0##初期

## x=500*a+50*b+c d=50*b+c
a=x//500
d=x%500
b=d%5

print(a*1000+b*5)
en=int(input())

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

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

print(a+b)
import math
x = input()
if len(x) > 3:
    y = int(x)/100
    y = math.floor(y)
    a = (y * 200) + (int(x[-2])*10)
    print(a)
elif len(x) == 1:
    print(0)
x = int(input())
print(x//500*500*2+x%500)
n=int(input())
c=n//500
if c!=0:
    n-=(c*500)
    k=n//5
    print(c*1000+k*5)
else:
    print(c*1000)
x = int(input())
ans = 0
ans += (x // 500) * 1000
ans += ((x % 1000) // 5) * 5
print(ans)
x = int(input())

c500, r500 = map(int, divmod(x, 500))
c5 = int(x % 5)

ans1 = c500 * 1000 + c5 * 5

print(c500 * 1000 + c5 * 5)
# coding:utf-8
coin = int(input())
reward = (coin // 500) *1000
reward += int(((coin - (reward / 2)) // 5) * 10)
print(reward)
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

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

print(total)
X = int(input('Enter Input: '))
if X > 5:
    a = int(X/500)
    b = X % 500
    c = int(b/5)
    d = a * 1000 + c * 5
    print(d)
else:
    print(0)
num = int(input())

hap1000 = num/500
hap5    = (num-hap1000*500)/5

print(int(1000*hap1000+5*hap5))
x=int(input())
a=x//500
y=x-(500*a)
b=y//5
print(a*1000+b*1)
x=int(input())
x-=(x//500)*500
y=x//5
print((x//500)*1000+5*y)
n = int(input())
print(1000 * (n // 500) + (n % 500) // 5)
#500円通貨1枚につき1000
#5円通貨1枚につき5
#高橋君はx円持ってる
#利用できる通貨は500円,100円,10円,5円,1円
#入力 1024

x=input()
x1=int(x) 

#まず入力を500で何回われるかを数えその回数で割り,残った値を変数に格納
r=x1/500
x2=x1%500

#同じ操作を5でおこなう
r1=x2/5
x3=x2%5

sam=(r*1000)+(r1*5)

print("sam")
X = int(input())

a, mod = divmod(X, 500)
b = mod % 5

print(a * 1000 + b * 5)
X = int(input())
happiness = (X//500)*1000+((X%100)//5)*5
print (happiness)
x=int(input())
import math
a=x//500
b=(x-a*500)//50
print(1000*a+5*b)
X = int(input())
total = 0

C = 0
D = 0

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)
print()
x = int(input())
HP = 0

if x < 5:
  print(0)

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

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

print(HP)
x = int(input())
print((x/500)*1000 + ((x%500)/5)*5)
X = input()
Y = int(X) / 500
Z = (int(X) - Y * 500) / 5
print(Y * 1000 + Z * 5)
i=int(input())

print((i//500)*1000+(i-(i//500*500)//5*5))
yen = int(input())
count = 0

while yen - 500 > 0:
    yen -= 500
    count += 1000

while yen - 5 > 0:
    yen -= 5
    count += 5

print(count)
X = int(input());
happy = 0;

if(X >= 500):
    n = X // 500;
    # print(n);
    happy += n * 1000;
    # print(happy);
    m = X % 500;
    if(m >= 5):
        l = m // 5;
        happy += l * 5;
    
print(happy);
# -*- coding: <encoding name> -*-

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

ans = 0

ans += (n // 500)*1000
n -= 500*(n // 500)
ans += (n % 5)*5
print(ans)
x = int(input())
Y = [500, 100, 50, 10, 5, 1]
ans = 0
for i in Y:
    if i == 500:
       ans +=  (x // i)*1000
    elif i == 5:
        ans +=  (x // i)*5
    x -= (x//i)*i
    if x == 0:
        break
print(ans)
money = int(input())

num_500 = int(money / 500)

remaining = int(money % 500)

num_5 = int(remaining / 5)

print('{}'.format(num_500 * 1000 + num_5 * 500 ))
n = int(input())

total = 0

total += (n//500)

n %= 500#合計枚数を減らす

total += (n//5)*5#5円玉に交換する

print(total)
X = int(input())
 
a = X // 500
b = (X % 500) // 5
 
print(a + b)
X = int(input())
a, b = 0, 0

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

print(1000 * a + 5 * b)
a=int(input())
if a % 500 == 0:
  print(a * 2)
else:
  if a < 1000:
  	print(int(a/100) * 100 + int((a % 100) / 5) * 5)
  else:
    print(round(a,-2) * 2 + int((a % 500) / 5) * 5)
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
            
        coin = coin - 1


print(fivet_yen + five_yen)
L=[500,100,50,10,5,1]
X=int(input())
happiness_points=0
for i in L:
  if X//i!=0:
    if i==500:
      happiness_points+=1000
    elif i==5:
      happiness_points+=5
    else:
      None
n = int(input())
print(n%500%5*5+n//500*1000)
hap=0
yen=int(input())
hap=1000*(yen//500)+(yen%5)*5
X = int(raw_input())

print(X/500 + (X%500)/5)
def resolve():
    s = int(input())
    zandaka = s % 500
    zandaka2 = zandaka % 5
    ureshii_500 = (s - zandaka)/500*1000
    ureshii2 = (zandaka - zandaka2)/5*5
    goukei = ureshii2 + ureshii_500
    print(goukei)

resolve()
x=int(input())
happiness=0
if(x>500):
	sum_amount=x//500
	happiness+=sum_amount*1000
	diff=x-happiness/2	
	z=int(diff/5)
	happiness+=z*5
	print(happiness)	

elif(x<500):
	k=int(x/5)
	ans=k*5
	print(ans)
elif(x==0):
	print(x)
X = int(input())

C = 0
D = 0

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

div = x//500
rem = x-div*500
res = div*1000 + (rem//5)*5
X = int(input())
hap_yen = int(X / 500)
to_hap_yen = hap_yen * 1000
remain_X = X - (hap_yen * 500)
remain_hap_yen = (remain_X / 5) * 5
total_hap_yen = to_hap_yen + remain_hap_yen
print(int(total_hap_yen))
x = int(input())
 
if x%500 == 0:
  print(x*2)
else:
  ans = x//500 + (x//5)*5
  print(ans)
N = int(input())

print(N/500*1000+N%500/5*5)
inp = input()
inp = int(float(inp))
aaa =0
bbb =0
nega = 0
big = 0

if 0 <= inp and inp <= 10**9:
    if 500 <= inp:
        big = (inp // 500)
        sma = big % 500
        if 5 <= sma:
          nega = (sma // 5)
      
        aaa = 1000*big
        bbb = 5*nega
        print(aaa + bbb)
    elif 5 <= inp:
        nega = (inp // 5)
        bbb = 5*nega
        print(bbb)
else:
    print(0)
X = int(input())
d, v = divmod(X, 500)
print(d * 1000 + v * 5)
data = int(input())
result = (data // 1000) * 2000
data %= 1000
result += (data // 5) * 5
print(result)
x=int(input())
a=500
b=5
if x>=500:
  num=(x//500*1000)+(x-x//500*500)//500
  print(num)
else:
  num=x//5
  print(num)
x = int(input())

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

print(a + c)
x = int(input())
m500 = x // 500
m5 = (x - (x // 500) * 500) % 5

ans = m500 * 1000 + m5 * 5
print(ans)
a = int(input())

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

num_500 = x / 500

amari = x - num_500

num_5 = amari / 5

print(1000 * num_500 + 5 * num_5)
price = int(input())
num500 = int(price / 500)
price = price - (num500 * 500)
num5 = int(price % 5)
print(num500 * 1000 + num5 * 5)
import math
n=int(input())
t=(n//500)*1000
s=(n-t*500//5)*5
print(t+s)
X = int(input())
counta = 0
countb = 0
while X%500 == 0:
  counta +=1
  X//=500
  
while X%5==0:
  countb +=1
  X//=5
print(1000*counta+5*countb)
X=int(input())
a=int(X//500)
X=X%500
b=int(X//5)
print(a+b)
n=int(input())
cnt=0
c=0
d=0
e=0
if n==0:
    print(0)
if int(n/500)>0:
    cnt=int(n/500)
    n=n%500
if int(n/100)>0:
    d=int(n/100)
    n=n%100
if int(n/50)>0:
    e=int(n/50)
    n=n%50
if int(n/5)>0:
    c=int(n/5)
    n=n%5
print(cnt*1000+c*5+d*0+e*0)
# -*- coding: utf-8 -*-
s = int(input())
happy = 0
if s >= 500:
    happy += 1000 * (s // 500)
    s = s % 500
if s >= 5:
    happy += 5 * (s // 500)

print(happy)
a = int(input())
b = a / 500
c = b * 1000
d = (a % 500) / 5
e = d * 5
print(c + e)
X = int(input())

ans = int(X/500)*1000
X -= int(X/500)

ans = int(X/5)*5

print(ans)
money = int(input())
c_500 = money/500
c_5 = (money%500)/5
print(1000*c_500+5*c_5)