peterverebics/CodeNet_Python_118 huggingface dataset:
X=int(input())
A=0
B=0
C=0
D=0
while A<=X:
  A+=500
  B+=1000
while C<=X//500:
  C+=5
  D+=5
print(B+D)
x = int(input())
a = 500
b = 5
q = x // a
mod = x % a
if q > 0:
  c = q * 1000
elif mod // b > 0:
  d = (mod // b) * 5
  print('c + d')
else:
  print('0')
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 = inp-(big * 500)
    if 5 <= sma:
      nega = (sma // 5)
      
  aaa = 1000*big
  bbb = 5*nega
  print(aaa + bbb)
else:
  print(0)
n=int(input())
k=n%500
n -= k*500
n //= 5
print(k*1000+n*5)
S = int(input())

S500 = S/500

S_nokori = S-S500*500

S5 = S_nokori/5

print(1000*S500 + 5*S5)
import os

def main():
	happy_count = 0
	money = int(input())
	str_money = str(money)
	happy_count = (money // 500) * 1000
	str_money = str_money[-2:]
	print((int(str_money)//5) * 5 + happy_count)
		

if __name__ == "__main__":
	main()
def resolve():
    s = int(input())
    zandaka = s % 500
    ureshii_500 = (s - zandaka)/500*1000
    goukei = ureshii_500+zandaka
    print(goukei)

resolve()
import math

X = int(input())
happy_1000 = X//500
X = math.floor(X/500)
happy_5 = X//5
res = happy_1000*1000 + happy_5*5
print(res)
X = int(input())

C = 0
D = 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(str(total))
X = int(input())

num1000 = X // 500
r500 = X % 1000
num5 = r500 // 5

print(num1000 * 1000 + num5 * 5)
n = int(input())

div_500, mod_500 = divmod(n,500)
if mod_500 > 0:
    div_5, mod = divmod(mod_500, 5)
    print(div_500*1000 + div_5*5)
else:
    print(div_500*100)
# -*- coding: <encoding name> -*-

x = int(input())
print(1000 * (x // 500) + (x % 500) // 5)
coin = int(input())
siawase = 0
if coin >= 500:
    siawase = siawase + coin / 500 * 1000
    amari = coin % 500
    siawase = siawase + amari/5 *5
elif coin >= 5:
    siawase = siawase + coin / 5 * 5
    
print(int(siawase))
x = int(input())
a = (x/500)*1000
x -= 500*(x/500)
b = 5*(x/5)
print(a+b)
user_input = eval(input()) * 2
print(user_input if user_input <= 2020 else 2020)
def main():
    X = int(input())
    cnt500 = 0
    cnt5 = 0

    while X > 0:
        if X >= 500:
            X -= 500
            cnt500 += 1

        if 500 > X >= 0:
            X -= 5
            cnt5 += 1

    print(cnt5*5 + cnt500*1000)


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

ans = 0
end = False
if n / 500 >= 1:
    ans += n // 500 * 1000
    if n % 500 != 0:
        n = n % 500
    else:
        end = True
    if n / 5 >= 1 and not end:
        ans += n // 5 * 5
print(ans)
x = int(input())
yen_500 = 0
yen_5 = 0
amari = 0
happy = 0

if x> 500:
    yen_500 = x//500
    amari = x - 500 * yen_500
    yen_5 = amari//5
    happy = 1000 * yen_500 + 5 * yen_5
    print(happy)
else:
    yen_5 = x//5
    happy = 5 * yen_5
    print(happy)
#import collections
import sys
input = sys.stdin.readline

#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''
#import copy
#import numpy as np

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

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

c_500 = x // 500
x = c_500 * 500
c_5 = x // 5

print(c_500 * 1000 + c_5 * 5)
n=int(input())
print(1000*(n//500)+5*((n-(n//500)*500)%5))
x = int(input())

ans = x // 500 + (x - (x // 500) * 500) // 5
print(ans)
money = int(input())

bigPoint = int(money/500) * 1000

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

smallPoint = int(smallMoney/5) * 5

print(bigPoint+smallPoint)
import sys

n = int(input())

buf = 0            #嬉しさポイント
m = 0               #残金

if n == 0:
    print("0")
    sys.exit()

def check(x,buf):
    if x >= 500:
        m = x%500
        buf += (x//500)*1000
        buf = check(m,buf)
        return buf
    elif x >= 5:
        m = x%5
        buf += (x//5)*5
        return buf

kei = check(n,buf)
print(kei)
X = int(input())
print(1000 * (X // 500) + 5 * (X - 500 * (X // 500)) // 5)
n = int(input())
s=n//500
r=n%500
print(r)
r=r//5
print(s*1000+r*5)
M=int(input())
e,M=divmod(M,500)
e*=1000
e+=(M%5)*5
print(e)
X = int(input())

print(
    1000 * (X // 500) + 5 * ((X % 1000) // 5)
)
X=int(input())
ans=0
if X>=500:
  ans+=X//500
  X=X-ans*500
if X>=5:
  ans+=X//5
print(ans)
n = int(input())
cnt = (n // 1000) * 2000
n -= (n // 1000) * 1000
cnt += (n // 5) * 5
print(cnt)
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 = int(inp / 500)
    sma = inp-(big * 500)
    if 5 <= sma:
      nega = int(sma / 5)
      
  aaa = 1000*big
  bbb = 5*nega
  print(aaa + bbb)
x = int(input())
print(x // 500 * 1000 + x // 5 * 5)
x = int(input())

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

ans1 = c500 * 1000 + c5 * 5

print(c500 * 1000 + c5 * 5)
X = int(input())
cnt=0
while (not X == 0) and (X%500==0) or (X%5==0):
  if X%500==0:
    cnt+=1000
    X - 500
  elif X%5 == 0:
    cnt+=5
    X-5
  else:
    break
    
print(cnt)
X = int(input())
m500 = X // 500
X -= m500 * 500
m5 = X // 5
print(1000 * m500 + 100 * m5)
x = int(input())
print(x//500*1000+(x%1000)//5*5)
c5, c2 = (500, 5)
yens = int(input())
happiness = 0
while yens > 5:
    #print(yens)
    if yens > c5:
        happiness += 1000 * (yens // c5)
        #yens %= c5
        #print(yens)
        yens %= c5
    elif yens > c2 :
        happiness += 5 * (yens // c2)
        yens %= c2 
        
print(happiness)
X = int(input())

ans = 0

ans = X // 500
X = X % 500

ans = X // 5

print(ans)
X = int(input())

yen500 = X // 500
nokori = X - yen500
yen5 = nokori // 5

print(yen500 * 1000 + yen5 * 5)
x = int(input())
print(x // 500 * 1000 + x % 5 * 5)
# coding: utf-8

# 標準入力 <int>
X = int(input())

u500 = 0
u5 = 0

u500 = X // 500

x = X % 1000

u5 = x // 5

print((u500 * 1000) + (u5 * 5))
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()
yen = int(input())
if yen < 5:
    print(0)
elif yen < 500:
    print(int(yen/5)*5)
else:
    ran = int(yen/500)*500
    if (int(str(ran)[-3:])>=500 and int(str(ran)[-3:])<600):
        print((ran*2)-int(str(ran)[-2:]))
    else:
        print((ran*2)-int(str(ran)[-3:]))
n= int(input())
c=0
a =n//500
c+=a*1000
a=n//5
c+=a
print(c)
x = int(input())
a = x//500
b = x % 500
print(a*1000+b*5)
x = int(input())
ans = x//500*1000 + (x%1000)//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)
n = int(input())
a = int(n/500)

amari = n%500

b = amari/5
ans = int(a*1000+b*5)
print(ans)
yen = int(input())
'''
happy= 0
while yen > 499:
  yen -= 500
  happy += 1000

while yen > 4:
  yen -=5
  happy += 5
'''
happy = 1000 * int(yen//500) + 5 * (yen - (500 * int(yen//500)))//5

print(happy)
import math
x = input()
if len(x) > 2:
    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())
ans = 0
ans += 1000*x//500 + 5*(x%500)//5
print(ans)
x = int(input())

ans = 0

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

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

print(ans)
X = int(input())

'''
500: 1000
5: 5
'''

ans = 0
if X > 500:
    x500 = X // 500
    ans += x500 * 1000
    X -= 500 * x500
    #print('x500: {}'.format(x500))

if X > 5:
    x5 = X // 5
    ans += x5 * 5
    X -= 5 * x5
    #print('x5: {}'.format(x5))

print(ans)
# B - Golden Coins
# https://atcoder.jp/contests/abc160/tasks/abc160_b

# 所持金
X = int(input())

# 嬉しさ(= 残金計算時にも使用)
happy = 0

# 500円玉,5円玉の最大両替枚数
max_five_hundred = int(X/500)
max_five = (X-(max_five_hundred*500))/5

# 各硬化の枚数をもとに嬉しさを算出
print(int((max_five_hundred*1000)+(max_five*5)))
X = int(input())
print(int(X/500)*1000+int((X-500*int(X/500))/500)*5)
user_input = (eval(input()) // 500)
print(user_input * 1000 + ((user_input % 500) * 2) * 5)
X = int(input())

gh = X//500
g = X%500//5

print(gh * 1000 + g * 1)
money = int(input())
big = money // 500
amari = money % 500
small = amari // 5
print(big + small)
X = int(input())
print((X // 500) * 1000 + (X // 500) // 5 * 5)
n = int(input())
s=n//500
r=n%500
r=r//5
print(s*1000+r)
X = int(input())

num_500 = X // 500
num_5 = (X - (X // 500)*500 ) % 5

print(1000*num_500 + 5 * num_5)
yen = int(input())
if yen < 5:
    print(0)
elif yen < 500:
    print(int(yen/5)*5)
else:
    ran = int(yen/5)*5
    print((ran*2)-int(str(ran)[-2:]))
x = int(input())

a = [500, 100, 50, 5, 1]
b = [0, 0, 0, 0, 0]

for i in range(5):
    b[i] = x // a[i]
    x = x % a[i]

print(b[0] * 1000 + b[3]*5)
X = int(input())
A = 0
B = 0

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

A5 = (X % 500) % 5 * 5
A = A500 + A5

B = (X - X % 5)
B = B / 5 * 5
print(int(max(A, B)))
x=int(input())
h=(x//500)*1000
x%=500
h+=x//5
print(h)
x = int(input())
s = 1000*(x//500) + (x%500)
print(s)
X = int(input())

count=(X//500)*1000
X=X//500
count+=(X//5)*5

print(count)
x = int(input())
happiness = 0
if  x > 500:
  q = x // 500
  happiness = q * 1000
  x = x % 500
if  x > 5:
  q = x // 5
  happiness = happiness + q * 5
  x = x % 500
print(happiness)
#create date: 2020-03-28 21:01

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    x = ni()
    print(1000*(x//500) + 5*((x % 100)//5))

if __name__ == "__main__":
    main()
x = int(input())
glad = 0

while True:
    if x < 5:
        break
    if x > 500:
        glad += x // 500 * 1000
        x = x % 500
    else:
        glad += x // 5 * 5
        x = x % 5
print(glad)
X=int(input())
A=0
G=0
N=0
M=0
Z=0
N=int(X/500)
M=int(X%500)
Z=int(M/5)
N=N+Z
for i in range(0,N):
    if X-500:
        X=X-500
        G=G+1000
    elif X-5:
        X=X-5
        G=G+5
    else:
        break
        
print(G)
yen=int(input())
hap=1000*(yen//500)+(yen%5)*5
print(hap)
x = int(input())

xx = x
c500, xx = divmod(xx, 500)
c5 = xx % 5

ans1 = c500 * 1000 + c5 * 5

xx = x
c5 = xx % 5

ans2 = c5 * 5

print(max(ans1, ans2))
x = int(input())
point = 0
while x != 0:
    if x >= 50:
        result = x // 50
        summ = (50 * result)*2
        point = point + summ
        remainder = x % 50
        x = remainder
    if x >= 5:
        result = x // 5
        summ = 5 * result
        point = point + summ
        break;
print(point)
X = int(input())
A = 0
while True:
    if X >= 500:
        X -= 500
        A += 1000
    else:
        X -= 5
        A += 5
    if X < 5:
        print(A)
        break
coininput = input()
last = coininput
coininput = int(coininput)
fivehunred = 0
onehunred = 0
fifty = 0
ten = 0
five = 0
if coininput >= 0 and coininput <= 1000000000:
    fivehunred = round(coininput / 500) * 1000
    onehunred = round(round(coininput % 500) / 100) * 100
    fifty = round(round(coininput % 100) / 50) * 50
    ten = round(round(coininput % 50) / 10) * 10
    if int(last[len(last) - 1]) >= 5:
        five = round(round(coininput % 10) / 5)
    else:
        five = 0
    total = fivehunred + onehunred + fifty + ten + five
    print(total)
else:
    print()
X = int(input('Enter Input: '))
if X in range(0, 10**9):
    if X > 500:
        a = int(X/500)
        b = X % 500
        c = int(b/5)
        d = a * 1000 + c * 5
        print(d)
    elif X <500 and X>5:
        a = int(X/5)
        d = a * 5
        print(d)
n = int(input())

a = n // 500
m = n % 500
b = m % 5

ans = a*1000 + b*5
print(ans)
X = int(input())
print(1000*(X//500)+5*((X%500)/5))
x=int(input())
i=0
j=0
while i*500<x:
  i+=1

x-=(i-1)*500
while j*5<x:
  j+=1
print((i-1)*1000+(j-1)*5)
x = int(input())

happy = 0

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

a = x-(a*500)
happy += a*5

print(happy)
X = int(input())

a = 0
b = 0
t = 0

if X >= 500:
    a = X//500
    t = X%500

if t > 0:
    b = t//5

print(1000*a+5*b)
n = int(input())
sum = 0
for i in range(1000000):
  if 0<=n-500:
    n=n-500
    sum+=1000
  elif 0<n<500:
    if 0<n-5:
      sum+=5
      n=n-5
print(sum)
a = int(input())
print(2*(a//500) + (a - a//500)//5)
X = int(input())
if X in range(0, 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)
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)
X =int(input())
answer = (X//500)*1000+((X%500)//5)*6
print(answer)
x = int(input())
q, mod = divmod(x, 500)
print(q*2000 + 5*(mod//5))
X = 0

happiness500 = int(X / 500)
happiness5 = int((X%500/5))

print(happiness500*1000+happiness5*5)
x = int(input())

num_500 = x / 500

amari = x - num_500

num_5 = int(amari / 5)

print(1000 * num_500 + 5 * num_5)
# -*- coding: utf-8 -*-

X = int(input())

a = int(X/500)
b = (X-500*a)%5
print("{}".format(1000*a+5*b))
X=int(input())
a=X/500
X%=500
b=X/5
print(1000*a+5*b)
x = int(input())
point = 0
while x != 0:
    if x >= 100:
        result = x // 100
        summ = (100 * result)*2
        point = point + summ
        remainder = x % 100
        x = remainder
    if x >= 5:
        result = x // 5
        summ = 5 * result
        point = point + summ
        break;
print(point)
a=int(input())
if a % 500 == 0:
  print(a * 2)
else:
  if a < 1000:
    print(int(a/500) * 1000 + int((a % 500) / 5) * 5)
  else:
    print(round(a,-2) * 2 + int((a % 500) / 5) * 5)
a=int(input())
b=a%500
print(a//500+b//5)
x=int(input())
i=0
u=0
while 500<=x:
    x-=500
    i+=1
while x>=5:
    x-=5
    u+=1
print(5*i+u)
X = int(input())
a = 0
b = 0
ans = 0

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

ans = 1000*a + 5*b
print(ans)
s=int(input())
temp=0
temp+=(s//500)*500
s=s//500
temp+=(s//5)*5
print(temp)
#coin : happy
#500 : 1000
#5 : 5
X = int(input())
x500 = X // 500 * 1000
x5 = (X - x500) // 5 * 5
print((x500 + x5)*2)
X=int(input())
a=int((X/500))*1000
X=X-((X/500)-1)*1000
b=int(X/5)*5
print(a-b)
coin = int(input("Enter your coin to exchange: "))
if coin>= 100:
	print(2*coin)
elif coin<=50:
  print(coin)
else:
  print("Invalid")
x = int(input())

c500, x = divmod(x, 500)
c5 = x % 5

print(c500 * 1000 + c5 * 5)
x = int(input())
print(x // 500 * 2 + x % 500 // 5 * 5)
x=int(input())
i=0
j=0
if 500<= x:
  while i*500<x:
    i+=1
  i-=1
  x-=500*i
if 5<=x:
  while j*5<x:
    j+=1
  j-=1
if i==0 and j==0:
  print(0)
else:
  print(1000*i+5*j)
a=int(input())
b=a//500
c=(a-b)//5
print(1000*b+5*c)
num = int(input().strip())
ans = 0
ans += (num//500)*1000
num = num%500
ans += (num//5)
print(ans)
def main():
  n = int(input())
  
  a = int(n/500)
  b = n % 500
  
  c = b / 5
  d = b % 5
  
  glad = int(1000 * a + 5 * c)
  
  print(glad)
  
main()
def yen(word):
    h = 5
    y = ((word * h) / 500) * 100 
    #if (ar[2] == ar[3]) and (ar[4] == ar[5]):
     # return 'Yes'
    #else:
     # return 'No'
    return y

if __name__ == '__main__':

    ar = int(input())

    result = yen(ar)
    print(result)
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="")
inp = int(input())
add = int(inp / 500) * 1000
add += int((inp % 100) / 5) * 5
print(add)
X = int(input())

temp = (X //500)
sen = temp * 1000
nokori = X - (temp * 500)

go = (nokori % 5) * 5

print(sen + go)
a=int(input())
h=0
val=a
if val>500:
  c=int(val//500)
  h=h+1000*c
  val-=c*500
if val>5:
  c=int(val//5)
  h+=5*c
  val-=c*5
print(h)
x = int(input())
p = 0
if x / 500 > 1:
    p += 1000 * int(x / 500)
    x -= int(x / 500) * 500
if x / 5 > 1:
    p += 5 * int(x / 5)
print(p)
x = int(input())
ha = 0

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


def happiness_point(remainder, num, point, all_point):
    result = divmod(remainder, num)
    all_point += result[0] * point
    remainder = result[1]
    return remainder, all_point


if coins / 500 > 1:
    coins, happiness = happiness_point(coins, 500, 1000, happiness)

if coins / 5 > 1:
    coins, happiness = happiness_point(coins, 5, 5, happiness)

print(happiness)
X = int(input())

a = X * 0.01 // 5 

pointa = a * 1000

b = X - a * 500


pointb = b // 5 * 5



print(pointa + pointb)
x = int(input())

q_1 = x//500
r_1 = x%500

r_2 = r_1//5

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

y = x / 500
z = (x % 500) / 5

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

ans = x//500

ans_2 = (x-x%500)//5

print(ans**1000+ans_2*5)
X = int(input())

A, B = divmod(X, 500)
C, D = divmod(X, 5)

print((A * 1000) + (C * 5))
X=int(input())
a=X//500
if X//500==0:
    print(a*1000)
else:
    b=(X-500*a)//5
    print(a*1000+b*5)
X = int(input("input:"))
uresisa_500yen = (X // 500) * 1000
mod = (X % 500)
uresisa_5yen = (mod // 5) * 5

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

print(1000*(n//500)+5*(n//5))
def solve():
  val = int(input())
  print(val/500 * 1000 + (val%500)/5 * 5)
solve()
x=int(input())
print(1000*(x//500)+5*((x%1000)//5))
X = int(input())

H = 0
if X > 500:
    H = (X // 500) * 1000
H += ((X % 500) // 5) * 5

print(H)
x = int(input())
a = x // 500
b = x % 500
b /= 5
print(int(a * 1000 + b * 5))
s = int(input())
count1=-1
count2=-1
while s>=0:
 s=s-500
 count1=count1 +1
s=s+500
print(count1)
if s==0:
  yasashisa=count1*1000
  print(yasashisa)
else:
   while s >=0:
     s=s-5
     count2=count2 +1
   yasashisa=count1*1000+count2* 5
   print(yasashisa)
x = int(input())
five_hundred = 1000 * (x // 500)
five = 5 * (x % 500) // 5
print(five_hundred + five)
X = int(input())
happy = (X // 500) * 1000 + ((X % 500) // 5) * 5
happy
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)
temp0=int(input())
n500=int(temp0/500)
temp1=temp0-n500*500
n5=int(temp1/5)
n500*1000+n5*5
import math

N = int(input())
#print(N)

A = math.floor(N / 500)
#print(A)
N = N - A * 500
#print(N)
B = math.floor(N / 5)
print(B)

AA = A * 1000
BB = B * 5
print(AA + BB)
Y = input()
X = int(Y)
A = (X//500)*1000
B = (X-X//500*500)
print(A+B)
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)
x = int(input())
c1 = 0
c2 = 0

c1 = x // 500
x %= 500
c2 = x % 5

print(c1 * 1000 + c2 * 5)
X = int(input())

Y = X%500

Z = Y%5

print((X//500)*1000+5*Z)
t=int(input())
count=0
while(t>500):
  count+=1000
  t-=500
while(t>5):
  count+=5
  t-=5
print(count)
X=int(input())
print((X//500)*2+(X%500)//5)
X = int(input())

ans=0

if X < 500:
    print((X // 5) * 5)
else:
    ans += (X // 500)*1000
    X -= (X//500)*500
    ans += (X//5)*5

print(ans)
from sys import stdin


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


if __name__ == '__main__':
    data = list(map(int, stdin.readline().rstrip('\n').split(' ')))
    result = get_result(data)
    print(result)
X = int(input())
 
div = int(X/500)
mod = int(X%500)
hap = 0
 
if div != 0:
  hap = div*2
q = int(mod/5)
hap += q*5
 
print(hap)
x = int(input())

if x%500 == 0:
  print(x*2)
else:
  ans = x//500 + (x//5)*5
  print(ans)
X = int(input())
a = X%500
print(a*1000+a%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)
elif(x==0):
	print(0)
elif(x==1):
	print(1)
x = int(input())
thou = x // 1000
x -= thou * 1000
fiv = x // 5
print(thou * 1000 * 2 + fiv * 5)
a = int(input())
if a==0:
    print(0)
b = a//500
c = a%500
if c!=0:
    d = c//5
    print((b*1000)+d*5)
elif c==0:
    print(b*1000)
x = int(input())
a = x // 500
b = (x - a) // 5
print(1000*a + 5*b)
a=int(input())
ans=a//500+(a-(a//500)*500)//5
print(ans)
x=int(input())

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

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

total = (X//500)*1000 + (X%500)//5*5
x = int(input())
# a,b = map(int, input().split())
# l = list(map(int, input().split()))

ans = 0

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

res500 = X // 500
X %= 500
res5 = X // 5
print(res500 + res5)
x = input()

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

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

a = n//500
b = (n - a * 500) //5
ans = a * 1000 + b
print(ans)
a = int(input())
result = 0

if (a % 500) != 0:
    result = int(a/500) * 1000
    b = a % 500
    result += int(b/5) * 5

print(result)
x = int(input())
a = x//500
b = (x % 1000) //5
print(1000*a + 5*b)
yen = int(input())
if yen < 5:
    print(0)
elif yen < 500:
    print(int(yen/5)*5)
else:
    ran = int(yen/5)*5
    print((ran*2)-int(str(ran)[-3:]))
x = int(input())
a = x // 500
print((x // 500) * 1000 + x - 500 * a)
#　%%まず500円を持ちうる個数を確認する
X = int(input())
count1 = int(X/500) #500円の枚数
print(count1)

# %%　500円玉の合計額を引いた値から、5円玉を確認する
deducation = X - count1 * 500

count2 = int(deducation / 5)
print(count2)

# %%　スコアを計算する
uresisa = count1 * 1000 + count2 * 5
print(uresisa)

# %%
X = int(input())

ans = 0
if X > 500:
  a = X // 500
  ans += (1000 * a)
  X -= (500 * a)
  
if X > 5:
  a = X // 5
  ans += (5 * a)
  
print(ans)
x=int(input())
cnt=1000*(x%500)
x//=500
cnt+=5*(x%5)
print(cnt)
X = int(input())
print(X / 500 + (X % 500) / 5)
x = int(input())

ans = 0

l500 = x // 500

x -= l500 * 500

l5 = x // 5

print(l500 + l5)
money = int(input())

happy = 0

happy += (money / 500) * 1000

money -= (money / 500) * 500

happy += (money / 5) * 5

print(happy)
n=int(input())
cnt=0
c=0
if n==0:
    print(0)
if int(n/500)>0:
    cnt=int(n/500)
    n=n%500
#if int(n/100)>0:
#    c=int(n/100)
#n=n%100
#if int(n/50)>0:
#    d=int(n/50)
#n=n%50
if int(n/5)>0:
    c=int(n/5)
    n=n%5
print(cnt*1000+c*5)
x=int(input())
a=x//500
b=(x-a)//5
print(a*1000+b*5)
x = int(input())

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

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

print(ans)
X = int(input())

if X == 0:
    print('高橋君は一文無しです。')
elif X > 10 ** 9:
    print('高橋君は大富豪です。')
else:
    point_thousand = X // 500
    point_five = (X - (point_thousand * 500)) // 5
    total = (point_thousand * 1000) + (point_five * 5)
    print('500円硬貨' + str(point_thousand) + '枚。5円硬貨' + str(point_five) + '枚を含むように両替することで' +
          str(total) + 'の嬉しさを得ます。これが嬉しさの最大です。')
X = int(input())
ans = 0
ans += (X // 500) * 1000
res = X % 1000
ans += (res // 5) * 5
print(ans)
# -*- coding: <encoding name> -*-

x = int(input())
print(1000 * (x // 500) + 5 * (x % 500))
x = int(input())
a = x//500
b = (x%500)//5
print(a+b)
X = int(input())
print(1000*(X//500)+5*((X-X//500)//5))
x = int(input())
result = 0
if x > 499:
    n = x // 500
    result += n * 1000
    x -= n * 500
if x > 4:
    n = x // 5
    result += n * 5
    x -= n * 5
result += x * 1
print(result)