AtCoder Beginner Contest 160 - Golden Coins

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-----
1024

-----Sample Output-----
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.

Source: atcoder | Difficulty: EASY


Solutions:
num = int(input(''))
ans = 0
if num / 500 > 0:
	ans += int(num / 500) * 1000
	num = num % 500
if num / 5 > 0:
	ans += int(num / 5) * 5
	num /= 5
print(ans)


x = int(input())
coins = [500, 5]
ans = 0
ans += x // 500 * 1000
x = x % 500
ans += x // 5 * 5
print(ans)


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


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


x = int(input())
thousand = x // 500
rest = x - thousand * 500
five = rest // 5
print(thousand * 1000 + five * 5)


def i_input():
	return int(input())

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

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

def i_row(N):
	return [int(input()) for _ in range(N)]

def i_row_list(N):
	return [list(map(int, input().split())) for _ in range(N)]
X = i_input()
cnt500 = X // 500
cnt5 = (X - cnt500 * 500) // 5
print(cnt500 * 1000 + cnt5 * 5)


X = int(input())
thousand = X // 500
rest = X - thousand * 500
five = rest // 5
print(1000 * thousand + 5 * five)


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


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


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


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


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


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


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


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


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


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


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


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


x = int(input())

def answer(x: int) -> int:
	ans = 1000 * (x // 500)
	x %= 500
	ans += 5 * ((x - 500 * (x // 500)) // 5)
	return ans
print(answer(x))


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


N = int(input())
L = N % 500
a = L - L % 5
print(a + N // 500 * 1000)


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


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


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


happy = 0
money = int(input())
(coin, money) = divmod(money, 500)
happy += 1000 * coin
(coin, money) = divmod(money, 5)
happy += 5 * coin
print(happy)


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


N = int(input())
N1 = N // 500
N2 = N % 500 // 5
print(N1 * 1000 + N2 * 5)


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


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


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


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


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


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


class Yorokobi:

	def __init__(self, money, yorokobi):
		self.money = money
		self.yorokobi = yorokobi

	def calc_yorokobi(self, credit):
		return credit // self.money * self.yorokobi
input_x = int(input())
yorokobi_500 = Yorokobi(500, 1000)
yorokobi_5 = Yorokobi(5, 5)
result = 0
if input_x >= 500:
	result += yorokobi_500.calc_yorokobi(input_x)
	result += yorokobi_5.calc_yorokobi(input_x % 500)
else:
	result += yorokobi_5.calc_yorokobi(input_x)
print(result)


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


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


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


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


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


X = int(input())
happy500 = X // 500
happy5 = (X - happy500 * 500) // 5
answer = happy500 * 1000 + happy5 * 5
print(answer)


X = int(input())
num_500 = X // 500
num_5 = X % 500 // 5
grad = num_500 * 1000 + num_5 * 5
print(grad)


S = int(input())
P = S // 500
Q = S % 500
R = Q // 5
print(1000 * P + 5 * R)


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


x = int(input())
l = divmod(x, 500)
m = l[0]
n = l[1] // 5
print(1000 * m + 5 * n)


input_X = int(input())
result_500 = input_X // 500
result_500ureshi = result_500 * 1000
result_5ureshi = (input_X - result_500 * 500) // 5 * 5
result = int(result_500ureshi + result_5ureshi)
print(result)


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


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


x = int(input())
y = x % 500
z = y % 5
a = (x - y) * 2
b = y - z
print(a + b)


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


X = int(input())
answer = 0
a = X // 500
b = X - 500 * a
c = b // 5
if a >= 0 and c >= 0:
	print(a * 1000 + c * 5)
elif X % 500 == 0:
	print(a * 1000)
elif X < 500:
	print(c * 5)
elif X == 0:
	print(0)


x = int(input())
(a, r) = divmod(x, 500)
b = r // 5
print(a * 1000 + b * 5)


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


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


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


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


def main():
	x = int(input())
	f = x // 500
	rest = x - f * 500
	s = rest // 5
	total = f * 1000 + s * 5
	return total

def __starting_point():
	print(main())
__starting_point()


N = int(input())
A = N // 500
N %= 500
B = N // 5
print(A * 1000 + B * 5)


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


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


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


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


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


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


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


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


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


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


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


input_x = int(input())
ret1 = input_x // 500
ret2 = ret1 * 1000
ret3 = input_x - ret1 * 500
ret4 = ret3 // 5
ret5 = ret4 * 5
print(ret2 + ret5)


def __starting_point():
	x = int(input())
	ans = x // 500
	if ans > 0:
		x = x - 500 * ans
		ans *= 1000
	ans += x // 5 * 5
	print(ans)
__starting_point()


X = int(input())
(yen500, yen5) = divmod(X, 500)
yen5 = yen5 // 5
print(yen500 * 1000 + yen5 * 5)


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


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


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


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


amount = int(input())
c500 = amount // 500
r500 = amount % 500
c5 = r500 // 5
print(c500 * 1000 + c5 * 5)


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


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


X = int(input())
count = 0
kouka500 = X // 500 * 1000
count += kouka500
kouka5 = X % 500 // 5 * 5
count += kouka5
print(count)


def atc_160b(X: int) -> int:
	return X // 500 * 1000 + X % 500 // 5 * 5
X_input = int(input())
print(atc_160b(X_input))


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


x = int(input())
k = 0
s = 0
if x // 500 > 0:
	k = x // 500
	s += k * 1000
	x = x - k * 500
if x // 5 > 0:
	k = x // 5
	s += k * 5
	x = x - k * 5
print(s)


cnt = int(input())
hp = 0
if cnt >= 500:
	hp += 1000 * (cnt // 500)
	cnt %= 500
hp += 5 * (cnt // 5)
print(hp)


X = int(input())
Y = X % 500
print((X - Y) * 2 + (Y - Y % 5))


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


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


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


n = int(input())
r = n // 500
s = (n - r * 500) // 5
print(r * 1000 + s * 5)


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


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


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


X = int(input())
s = X // 500
t = X % 500
u = t // 5
print(s * 1000 + u * 5)


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


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


x = int(input())
m = divmod(x, 500)
print(m[0] * 1000 + m[1] // 5 * 5)


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

def __starting_point():
	main()
__starting_point()


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


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


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


X = int(input())
(ans, rem) = divmod(X, 500)
ans *= 1000
ans += rem // 5 * 5
print(ans)


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


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


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


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


x = int(input())
gold_coin = x // 500
left_coin = x % 500
bronze_coin = left_coin // 5
happiness = gold_coin * 1000 + bronze_coin * 5
print(happiness)


X = int(input())
t = 500
print(X // t * 2 * t + X % t // 5 * 5)


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


from math import gcd
from itertools import combinations, permutations, accumulate, product
from collections import deque, defaultdict, Counter
import decimal
import re
import math
import bisect
import heapq
import sys
sys.setrecursionlimit(10000000)
mod = 10 ** 9 + 7
INF = float('inf')
from sys import stdin
readline = stdin.readline

def readInts():
	return list(map(int, readline().split()))

def readTuples():
	return tuple(map(int, readline().split()))

def I():
	return int(readline())
X = I()
m500 = X // 500
rest = X - 500 * m500
print(m500 * 1000 + 5 * (rest // 5))


X = int(input())
a = X % 500
b = a % 5
print(2 * X - a - b, end='')


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


def readinput():
	n = int(input())
	return n

def main(n):
	ureshii = n // 500 * 1000
	n = n % 500
	ureshii += n // 5 * 5
	return ureshii

def __starting_point():
	n = readinput()
	ans = main(n)
	print(ans)
__starting_point()


S = int(input())
joy_500 = S // 500 * 1000
joy_5 = (S - joy_500 // 2) // 5 * 5
print(joy_500 + joy_5)


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


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


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


X = int(input())
R = X % 5
r = (X - R) % 500
print(r + (X - R - r) * 2)


k = eval(input())
print(k // 500 * 1000 + k % 500 // 5 * 5)