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 in C++ (GCC 9.2.1) (judge verdict: Accepted)

#include<bits/stdc++.h>
#pragma GCC optimize("O2")
#include <stdio.h>


using namespace std;
#define newl "\n"
#define ll long long
#define ull unsigned long long

#define forV(v)     for(auto &x : v) cout << x << ' '
#define fo(i,n)     for (ll i = 0; i < n; ++i)
#define FOR(i,k,n)  for (auto i = k; i <= n; ++i)
#define FORR(i,k,n) for (auto i = k; i >= n; --i)

#define deb(x) cout << #x << " = " << x << endl
#define deb2(x, y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); ++it)
#define mod 1000000007
#define PI 3.1415926535897932384626
#define FormulaToConvertMicrosecondsToSeconds(duration) duration / 1e+6

typedef pair<int, int>  pii;
typedef pair<ll, ll>     pl;
typedef vector<int>      vi;
typedef vector<ll>       vl;
typedef vector<pii>    vpii;
typedef vector<pl>      vpl;
typedef vector<vi>      vvi;
typedef vector<vl>      vvl;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());

void getVecIndex(vector<int> v, int K) {
	auto it = find(all(v), K);

	if (it != v.end()) {
		cout << distance(v.begin(), it);
	}
	else
		cout << -1;
}

bool isPrime(int num) {
	if (num <= 1)
		return false;

	if (num == 2)
		return true;

	if (num % 2 == 0)
		return false;

	int counter = 3;

	while ((counter * counter) <= num) {
		if (num % counter == 0) {
			return false;
		} else {
			counter += 2;
		}
	}

	return true;
}

ull mpow(ull base, ull exp) {
	base %= mod;
	ull result = 1;
	while (exp > 0) {
		if (exp & 1) result = (static_cast<ull>(result * base)) % mod;
		base = (static_cast<ull>(base * base)) % mod;
		exp >>= 1;
	}
	return result;
}

ll binarySearch(int a[], int l, int r, int x)
{
	while (l <= r)
	{
		int mid_index = l + (r - l) / 2;

		if (a[mid_index] == x)
			return mid_index;
		else if ( x > a[mid_index])
		{
			l = mid_index + 1;
		}
		else if ( x < a[mid_index])
		{
			r = mid_index - 1;
		}
	}
	return -1;
}

void permuteString(string s)
{
	sortall(s);

	do {
		cout << s << newl;
	} while (next_permutation(all(s)));

}

void permuteArray(int array[], int n)
{
	sort(array, array + n);

	do {
		FOR(i, 0, n - 1)
		cout << array[i] << ' ';

		cout << newl;
	} while (next_permutation(array, array + n));
}

void permuteVector(vector<int> v)
{
	sortall(v);

	do {
		forV(v);

		cout << newl;
	} while (prev_permutation(all(v)));
}


ull largestPrimeFactor(ull n)
{
	for (int factor = 2; factor * factor <= n; ++factor)
	{
		while (n % factor == 0 and n != factor)
			n /= factor;
	}

	return n;
}

ull numberOfDivisors(ull n)
{
	ull divisors = 0;
	if (n == 1)
		return 1;


	for (ull i = 1; i * i <= n; ++i) // we need to CHECK at least sqrt(n) TIMES (inclusive) if 'i' is a divisor of n.
	{
		if (n % i == 0)
		{
			divisors += 2;
		}
	}
	return divisors;
}

// greatest common divisor
ll gcd( ll a, ll b )
{
	if (b == 0)
	{
		return a;
	}
	else
	{
		return gcd( b, a % b );
	}
}
// least common multiplication
ll lcm (ll a, ll b)
{
	return (a * b) / gcd(a, b);
}


// ∈

//=======================
void solve() //Task A. Double Cola!!! Two teams composing !
{


	ull yens; cin >> yens;

	int happ = 0;

	while (yens >= 500) {
		yens -= 500;
		happ += 1000;
	}


	while (yens >= 5) {
		yens -= 5;
		happ += 5;
	}
	cout << happ;
}
/* TESTS:


*/

int32_t main()
{
	//--------------------------------
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	auto t1 = std::chrono::high_resolution_clock::now();

	int t = 1;
	//cin >> t;
	while (t--) {
		solve(); cout << newl;
	}

	auto t2 = std::chrono::high_resolution_clock::now();
	auto duration = std::chrono::duration_cast<std::chrono::microseconds>( t2 - t1 ).count();

	cerr << "\nDuration of the algo: " << FormulaToConvertMicrosecondsToSeconds(duration) << " secs" << newl << newl;
	return 0;
}