public static void main(String[] args)
	{
		BigInteger sum = BigInteger.ZERO;
		for (int i = 1; i <= 10000; i++)
		{
			int n = i;
			while (n % 10 == 0)
				n /= 10;
			BigInteger N = new BigInteger(""+n);
			BigInteger current = new BigInteger(""+n);
			
			if (n == 9999)
				current = new BigInteger("11112222222222222222");
			
			while (true)
			{
				int firstInvalid = firstInvalid(current.toString());
				int firstZeroOrOne = firstZeroOrOne(current.toString());
				int firstZero = firstZero(current.toString());
				if (firstInvalid == -1)
				{
					sum = sum.add(current.divide(N));
					break;
				}
				
				if (firstZeroOrOne == -1)
					current = BigInteger.TEN.pow(current.toString().length());
				else
				{
					if (firstZero != firstZeroOrOne)
						current = new BigInteger(current.toString().substring(0,current.toString().length()-firstZeroOrOne-1)+TWO.multiply(BigInteger.TEN.pow(firstZeroOrOne)).toString());
					else
						current = new BigInteger(current.toString().substring(0,current.toString().length()-firstZeroOrOne-1)+BigInteger.TEN.pow(firstZeroOrOne).toString());
				}
				if (current.mod(N).equals(BigInteger.ZERO) == false)
				{
					BigInteger divisor = current.divide(N);
					current = N.multiply(divisor).add(N);
				}
			}
		}
		System.out.println(sum.toString());
	}