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 Rust (1.15.1) (judge verdict: Accepted)

#![allow(non_snake_case)]
#![allow(unused_imports)]
macro_rules!input{(source=$s:expr,$($r:tt)*)=>{let mut iter=$s.split_whitespace();let mut next=||{iter.next().unwrap()};input_inner!{next,$($r)*}};($($r:tt)*)=>{let stdin=std::io::stdin();let mut bytes=std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next=move||->String{bytes.by_ref().map(|r|r.unwrap()as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next,$($r)*}};}macro_rules!input_inner{($next:expr)=>{};($next:expr,)=>{};($next:expr,$var:ident:$t:tt$($r:tt)*)=>{let $var=read_value!($next,$t);input_inner!{$next$($r)*}};}macro_rules!read_value{($next:expr,($($t:tt),*))=>{($(read_value!($next,$t)),*)};($next:expr,[$t:tt;$len:expr])=>{(0..$len).map(|_|read_value!($next,$t)).collect::<Vec<_>>()};($next:expr,chars)=>{read_value!($next,String).chars().collect::<Vec<char>>()};($next:expr,usize1)=>{read_value!($next,usize)-1};($next:expr,$t:ty)=>{$next().parse::<$t>().expect("Parseerror")};}

use std::cmp::{min, max};
use std::collections::{HashMap, HashSet, VecDeque};
use std::mem::swap;


fn main() {
    input!{
        N: u32,
    }
    let ans = solve((N,));
    println!("{}", ans);
}

fn solve((X,): (u32,)) -> u32 {
    X/500*1000 + (X%500)/5*5
}


#[test]
fn test_solve() {
    //let cases = [("CBABA", 29), ("HEART", 55), ("EARTH", 28), ("IOI", 2)];
    //for (i, (S, a)) in cases.iter().enumerate() {
    //    assert_eq!(solve((S.as_bytes().to_vec(),)), *a, "#{}", i);
    //}
}


/*
    Copyright for the `input!` macro at line #3 is held by Hideyuki Tanaka, 2019.  The
    original macro is licensed under BSD 3-clause license.
 
    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions are met:
 
    1. Redistributions of source code must retain the above copyright notice, this
    list of conditions and the following disclaimer.
 
    2. Redistributions in binary form must reproduce the above copyright notice,
    this list of conditions and the following disclaimer in the documentation
    and/or other materials provided with the distribution.
 
    3. Neither the name of the copyright holder nor the names of its contributors
    may be used to endorse or promote products derived from this software
    without specific prior written permission.
 
    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
    ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
    OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/