/****************************************************************************

	" Wake up with determination. Go to bed with satisfaction. "

******************************************************************************
*                                                                            *
*                       Author : Dhiraj Govindvira                           *
*                         Date : 28-Mar-2020 ~ Saturday                      *
*                         Time : 5:40:50 PM                                  *
*                                                                            *
*****************************************************************************/

#if __has_include("D:/dhiraj/Programming/debug.h")
    #include "D:/dhiraj/Programming/debug.h"
#else
    #include <bits/stdc++.h>
    using namespace std;
    #define d(...) 11
#endif

// Data Type ----------------------------------------------------------------

#define ull                 unsigned long long int
#define ll                  long long int
#define ld                  long double

// Loops --------------------------------------------------------------------

#define loop(i,s,e)         for(ll i=(s); i<(e); i++)
#define rloop(i,s,e)        for(ll i=(s); i>=(e); i--)
#define iter(it,var)        for(auto it=var.begin(); it!=var.end(); it++)
#define riter(it,var)       for(auto it=var.rbegin(); it!=var.rend(); it++)

// Stl ----------------------------------------------------------------------

#define ff                  first
#define ss                  second
#define vll                 vector<ll>
#define vvl                 vector<vll>
#define pll                 pair<ll,ll>
#define all(x)              x.begin(),x.end()
#define rall(x)             x.rbegin(),x.rend()

// Extra --------------------------------------------------------------------

#define fast                ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define print(any)          for(auto &i:any) cout<<i<<" "; nl;
#define precise(a)          cout<<fixed<<setprecision(a)
#define nl                  std::cout<<'\n'
#define INF                 LLONG_MAX
#define endl                '\n'

// Template -----------------------------------------------------------------

template <typename T> 
inline bool inrange(T a, T l, T r) {
    if(l>r) swap(l,r);
    return (a>=l and a<=r);
}
template <typename T, typename U> 
inline bool exist(T val, U &any) {
    return (any.find(val) != any.end());
}
// multiple input
template <typename T> 
inline void inp(T &any) {
    cin >> any;
}
template <typename T, typename... U> 
inline void inp(T &a,U &...b) {
    cin >> a; inp(b...);
}
// scan vector
template <typename T> 
inline istream& operator >> (istream &in, vector<T> &a) {
    for(auto &x : a) in >> x;
    return in;
}
// scan pair
template <typename T, typename U> 
inline istream& operator >> (istream &in, pair<T,U> &a) {
    in >> a.ff >> a.ss; 
    return in;
}

// Solve --------------------------------------------------------------------

void solve(ll &T)
{
    ll x;
    std::cin>>x;

    ll ans = (x/500)*1000;
    x %= 500;
    ans += (x/5)*5; 
    std::cout<<ans;
}

// Main ---------------------------------------------------------------------

int main()
{
    #ifdef Dhiraj
        freopen("D:/dhiraj/Programming/i1.txt","r",stdin);
        freopen("D:/dhiraj/Programming/o1.txt","w",stdout);
    #endif
    
    fast;
    int t = 1;
    loop(i,1,t+1)
    solve(i);
    return 0;
}

Measured memory_bytes: 256