# -*- coding:utf-8 -*-
class Solution:
    def checkNum(self,x):
            num=0
            while x :
                if (x%10)==1:
                    num+=1
                x=x//10
            
            return num
    def NumberOf1Between1AndN_Solution(self, n):
        if n==0:
            return 0
        elif 1<=n<10:
            return 1
        elif n==10:
            return 2
        elif 10<n<20:
            return 1+n-10+1+1
        elif n==20:
            return 12
        elif 21<=n<=100:
            return (n-21)//10+13
        cnt=0
        for i in range(1,n+1):
            cnt+=self.checkNum(i)
        
        return cnt
        
        
        
        
            
        # write code here