#include <iostream> 
#include <cmath> 
#include <sstream> 
#include <cassert> 

using namespace std;

#define For(i,a,b) for(int i=(int)(a);i<=(int)(b);++i)

class SequenceSum {
	public:
		
		string checkInput(long long N){
			if (N<1 || N>1000000000000000LL)
				return "N should be from 1 to 10^15 inclusive";
			return "";
		}
		
		long long digits(long long N){
	    long long ten[19], n[21], buf, res=0;
	    ten[0]=1LL;
	    For(i,1,18) ten[i]=10LL*ten[i-1];
	    buf = N; n[0]=0;
	    do {
		    n[++n[0]] = buf%10LL;
		    buf /= 10LL;
	    } while (buf);
	
	    int group = 1;
	    while (ten[group-1] <= N){
		    if (group < n[0]) {
			    res += group*(ten[group]-ten[group-1]);
		    } else {
			    res += group*(N-ten[group-1]+1);
		    }
		    ++group;
	    }
	
	    return res;
    }

    long long digit_count(long long digit, long long group, long long place, long long N){
	    if (place < 1 || place > group || group < 1 || digit<1 || digit > 9) return 0;
	
	    long long ten[19], n[21], buf, res=0;
	    ten[0]=1LL;
	    For(i,1,18) ten[i]=10LL*ten[i-1];
	    buf = N; n[0]=0;
	    do {
		    n[++n[0]] = buf%10LL;
		    buf /= 10LL;
	    } while (buf);
	
	
	    buf = ten[group-1];
	    if (place < group) buf += digit*ten[place-1];
	    else buf = digit*ten[place-1];
	    if (buf > N) return 0;
	
	    long long full_blocks_count=0, full_block_size=0, last_block_size=0;
	    long long first_block_sign=0, block_inner_sign=0, block_outer_sign=0;
	
	    full_block_size = ten[place-1];
	    if (group < n[0]) {
		    full_blocks_count = ten[group-place];
		    if (group > place) full_blocks_count -= ten[group-place-1];
	    } else {
		    if (place == group){
			    if (n[place] == digit) {
			      last_block_size = N%ten[n[0]-1] + 1;
			    } else {
				    full_blocks_count = 1;
			    }
		    } else {
			    full_blocks_count = N/ten[place]-ten[group-place-1];
			    if (digit < n[place]) {
				    ++full_blocks_count;
			    } else if (digit == n[place]) {
			      last_block_size = N%ten[place-1] + 1;
			      if (last_block_size == full_block_size) {
			  	    last_block_size = 0;
			  	    ++full_blocks_count;
			      }
		      }
		    }
	    }
	    
	    buf = digit*ten[place-1];
	    if (group > place) buf += ten[group-1];
	    buf = digits(buf-1)+group-place;
	    first_block_sign = (buf%2 ? -1 : 1);
	    block_inner_sign = ((group-1)%2 ? 1 : -1);
	
	    buf = digit*ten[place-1];
	    if (group > place) buf += ten[group-1];
	    if (group > place+1) buf += ten[place];
	    buf = digits(buf-1)+group-place;
	    buf = (buf%2 ? -1 : 1);
	    block_outer_sign = (buf == first_block_sign ? 1 : -1);
	
	    long long block_sum = (block_inner_sign == 1 ? digit*full_block_size*first_block_sign : (full_block_size%2 ? digit*first_block_sign : 0LL));
	    res = (block_outer_sign ==1 ? block_sum*full_blocks_count : (full_blocks_count%2 ? block_sum : 0LL));
	
	    long long last_sign = (block_outer_sign == 1 ? first_block_sign : (full_blocks_count%2 ? -first_block_sign : first_block_sign)); 
	
	    res += (block_inner_sign == 1 ? digit*last_block_size*last_sign : (last_block_size%2 ? digit*last_sign : 0LL));
	
	    return res;
    }
		
		long long getSum(long long N){
			// First let's check input
			string check = checkInput(N);
			if (check!="") {
				cout << check << endl;
				assert(false);
			}
			
			long long res=0, d=1;
	    int group = 1;
	    
	    while (d <= N) {
		    For(place,1,group) For(digit,1,9) 
		      res += digit_count(digit,group,place,N);
		    ++group;
		    d *= 10LL;
	    }
	    
	    return res;
		}
		
};

int main(){

//	freopen("input.txt","rt",stdin);
//	freopen("output.txt","wt",stdout);
	
	long long N;
	cin >> N;
	
	SequenceSum A;
	cout << A.getSum(N);
	
	return 0;
}
