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++14 (GCC 5.4.1) (judge verdict: Accepted)


#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
using namespace std;
const int MAX_N = int(1e6) + 10;
const long long int MOD=1e9+7;
const long long int INF=1e18;
typedef long long int ll;
typedef unsigned long long int llu;


// const int N=1e6+5;
// vector<int>v[N];
// int bb[N];
// int lca[N][20];
// int depth[N];
// int aa[N];
// int ans=0;

// bitset<1000055>isleaf;

// int n,k,x;

// void dfs(int i,int p,int l){
//     lca[i][0]=p;
//     for(int j=1;j<=19;j++){
//         lca[i][j]=lca[lca[i][j-1]][j-1];
//     }

//     depth[i]=l+1;
//     int c=0;

//     for(auto &it:v[i]){
//         if(it!=p){
//             c++;
//             dfs(it,i,l+1);
//         }
//     }

//     isleaf[i]=(!c);
//     if(isleaf[i]==1)
//     cout<<i<<" "<<isleaf[i]<<endl;
// }

// void dfs2(int i,int p,int sum){
//      aa[i]+=sum;
//      ans=max(ans,aa[i]);
//      for(auto &it:v[i]){
//         if(it!=p){
//             dfs2(it,i,aa[i]);
//         }
//      }
// }

// void fun(int x){
//     int x1=depth[x];
//     if(k>=x1){
//         aa[1]+=1;
//         return;
//     }
//     int xx=k;
//     for(int i=19;i>=0;i--){
//         if(xx&(1<<i)){
//             x=lca[x][i];
//         }
//     }
//     aa[x]+=1;
// }
// int main(){

//     ios_base::sync_with_stdio(false);
//     cin.tie(NULL);
//     cout.tie(NULL);
    
//     cin>>n>>k>>x;

//     for(int i=1;i<=x;i++){
//         cin>>bb[i];
//     }

//     for(int i=0;i<n-1;i++){
//         int x,y;
//         cin>>x>>y;
//         v[x].push_back(y);
//         v[y].push_back(x);
//     }

//     dfs(1,0,0);

//     for(int i=1;i<=x;i++){
//         if(isleaf[bb[i]]==true)
//         fun(bb[i]);
//         else{
//             aa[bb[i]]+=1;
//         }
//     }

//     dfs2(1,0,0);

//     cout<<ans<<endl;



    

// }    
    
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
    


inline ll mul(ll a,ll b){
    a=(a+MOD)%MOD;
    b=(b+MOD)%MOD;
    ll c=a*b;
    c=(c+MOD)%MOD;
    return c;
}
inline ll add(ll a,ll b){
    a=(a+MOD)%MOD;
    b=(b+MOD)%MOD;
    ll ans=(a+b);
    ans=(ans+MOD)%MOD;
    return ans;
}
ll power(ll a,ll b,ll c){
    ll ans=1;
    while(b){
        if(b&1){
            ans=mul(ans,a);
        }
        a=mul(a,a);
        b=b/2;
    }
    return ans;
}

/* ordered_set A;
   A.insert(x);
   A.erase(x);
   A.order_of_key(x) // no of elements less than (<) x
   *A.find_by_order(k-1) // kth smallest element
*/

vector<int> suffix_tree(string s){
    int n=s.size();
    int x=max(n,27);
    vector<int>p(n),c(n),pn(n),cn(n),cnt(x,0);

    for(int i=0;i<n;i++){
        cnt[s[i]-'0']++;
    }

    for(int i=1;i<x;i++){
        cnt[i]+=cnt[i-1];
    }
    

    for(int i=n-1;i>=0;i--){
        int x=(s[i]-'0');
        p[--cnt[x]]=i;
    }

    c[p[0]]=0;
    int classes=1;

    for(int i=1;i<n;i++){
        if(s[p[i]]!=s[p[i-1]]){
            classes++;
        }
        c[p[i]]=classes-1;
    }

    for(int h=0;(1<<h)<n;h++){

        for(int i=0;i<n;i++){
            pn[i]=p[i]-(1<<h);
            if(pn[i]<0){
                pn[i]+=n;
            }
        }

        fill(cnt.begin(),cnt.end(),0);

        for(int i=0;i<n;i++){
            cnt[c[pn[i]]]++;
        }

        for(int i=1;i<x;i++){
            cnt[i]+=cnt[i-1];
        }

        for(int i=n-1;i>=0;i--){
            p[--cnt[c[pn[i]]]]=pn[i];
        }

        cn[p[0]]=0;
        classes=1;

        for(int i=1;i<n;i++){
            pair<int,int> curr={c[p[i]],c[(p[i]+(1<<h))%n]};
            pair<int,int> prev={c[p[i-1]],c[(p[i-1]+(1<<h))%n]};
            if(curr!=prev){
                classes++;
            }

            cn[p[i]]=classes-1;
        }

        c.swap(cn);


    }

    return p;

}
vector<int>cyclic_shifts(string s){
    vector<int>v=suffix_tree(s);
    return v;
}


int main(){

    
    ll x;
    cin>>x;

    ll ans=0;

    ans+=(x/500)*1000LL;
    x-=(x/500)*500;
    ans+=(x/5)*5LL;

    cout<<ans<<endl;



    
    
}