#include <iostream>
#include <cstdlib>
#include <cmath>
using namespace std;

int quez_count(int n)
{
	int i = 10;
	int res = 0; 
	while(i < n){
		res += (i - i/10)*log10(i);
		i *= 10;
	}
	res += (n - i/10)*log10(i)+ceil(log10(n));
	return res;	
}

int koala_count(int n)
{
	int log = log10( n ) + 1;
	return ( n + 1 ) * log  - ( pow( 10,  log) - 1 ) / ( 10 - 1 );
}

void test()
{
	srand( time( NULL ) );
	cout << "Testing..." << endl;
	for( int i = 0; i< 10; ++i)
	{
		int r = rand() % 100000000 + 100000000;
		cout << r << " : " << quez_count( r ) << " : " << koala_count( r ) << endl;
	}
}

int main() {
	int repeats = 100000,
	    size = 9500000000;
	test();

	clock_t start = clock();
	for( int i = 0; i< repeats; ++i)
	{
		int r = rand() % size + size;
		quez_count( r );
	}
	cout << "Time on quez's solution:" <<(double(clock()-start)/CLOCKS_PER_SEC) << "seconds"<<endl;

	start = clock();
	for( int i = 0; i< repeats; ++i)
	{
		int r = rand() % size + size;
		koala_count( r );
	}
	cout << "Time on koala's solution:" <<(double(clock()-start)/CLOCKS_PER_SEC) << "seconds"<<endl;
	
	
	
	return 0;
}