"""
制約がヒントっぽいな。
桁DPで解ける

dp[i][j][k] => 2進数表記でa+bの左からi桁目まで見る。i桁目がjになるような場合の数。kは未満フラグ。配るDPで解く。

"""
L = input()
N = len(L)
mod = 10**9 +7
dp = [[[0]*2 for _ in range(2)]for _ in range(N)]
dp[0][1][0] = 2
for i in range(1,N):
    dp[i][1][1] = 2

for i in range(N-1):
    x = int(L[i+1])
    for j in range(2):
        for k in range(2):
            for l in range(2):
                if not k and l > x:
                    continue
                if k or l < x:
                    nxFlag = 1
                else:
                    nxFlag = 0
                if l == 0:
                    dp[i+1][l][nxFlag] += dp[i][j][k]
                else:
                    dp[i+1][l][nxFlag] += dp[i][j][k]*2
                dp[i+1][l][nxFlag]%=mod
ans = (sum(dp[-1][1])+sum(dp[-1][0])+1)%mod
print(ans) """
制約がヒントっぽいな。
桁DPで解ける

dp[i][j][k] => 2進数表記でa+bの左からi桁目まで見る。i桁目がjになるような場合の数。kは未満フラグ。配るDPで解く。

""" L = input() L input() input N = len(L) N len(L) len L mod = 10**9 +7 mod 10**9 +7 10**9 10 9 7 [[0]*2 for _ in range(2)]for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [[0]*2 for _ in range(2)] dp = [[[0]*2 for _ in range(2)]for _ in range(N)] dp [[[0]*2 for _ in range(2)]for _ in range(N)] dp[0][1][0] = 2 dp[0][1][0] [1] [0] dp 0 1 0 2 for i in range(1,N):
    dp[i][1][1] = 2 i range(1,N) range 1 N dp[i][1][1] = 2 dp[i][1][1] [1] [i] dp i 1 1 2 for i in range(N-1):
    x = int(L[i+1])
    for j in range(2):
        for k in range(2):
            for l in range(2):
                if not k and l > x:
                    continue
                if k or l < x:
                    nxFlag = 1
                else:
                    nxFlag = 0
                if l == 0:
                    dp[i+1][l][nxFlag] += dp[i][j][k]
                else:
                    dp[i+1][l][nxFlag] += dp[i][j][k]*2
                dp[i+1][l][nxFlag]%=mod i range(N-1) range N-1 N 1 x = int(L[i+1]) x int(L[i+1]) int L[i+1] L i+1 i 1 for j in range(2):
        for k in range(2):
            for l in range(2):
                if not k and l > x:
                    continue
                if k or l < x:
                    nxFlag = 1
                else:
                    nxFlag = 0
                if l == 0:
                    dp[i+1][l][nxFlag] += dp[i][j][k]
                else:
                    dp[i+1][l][nxFlag] += dp[i][j][k]*2
                dp[i+1][l][nxFlag]%=mod j range(2) range 2 for k in range(2):
            for l in range(2):
                if not k and l > x:
                    continue
                if k or l < x:
                    nxFlag = 1
                else:
                    nxFlag = 0
                if l == 0:
                    dp[i+1][l][nxFlag] += dp[i][j][k]
                else:
                    dp[i+1][l][nxFlag] += dp[i][j][k]*2
                dp[i+1][l][nxFlag]%=mod k range(2) range 2 for l in range(2):
                if not k and l > x:
                    continue
                if k or l < x:
                    nxFlag = 1
                else:
                    nxFlag = 0
                if l == 0:
                    dp[i+1][l][nxFlag] += dp[i][j][k]
                else:
                    dp[i+1][l][nxFlag] += dp[i][j][k]*2
                dp[i+1][l][nxFlag]%=mod l range(2) range 2 if not k and l > x:
                    continue
                 not k and l > x not k k l > x l x continue if k or l < x:
                    nxFlag = 1
                else:
                    nxFlag = 0
                 k or l < x k l < x l x nxFlag = 1 nxFlag 1 nxFlag = 0 nxFlag 0 if l == 0:
                    dp[i+1][l][nxFlag] += dp[i][j][k]
                else:
                    dp[i+1][l][nxFlag] += dp[i][j][k]*2
                 l == 0 l 0 dp[i+1][l][nxFlag] += dp[i][j][k] dp[i+1][l][nxFlag] [l] [i+1] dp i+1 i 1 l nxFlag dp[i][j][k] [j] [i] dp i j k dp[i+1][l][nxFlag] += dp[i][j][k]*2 dp[i+1][l][nxFlag] [l] [i+1] dp i+1 i 1 l nxFlag dp[i][j][k]*2 dp[i][j][k] [j] [i] dp i j k 2 dp[i+1][l][nxFlag]%=mod dp[i+1][l][nxFlag] [l] [i+1] dp i+1 i 1 l nxFlag mod ans = (sum(dp[-1][1])+sum(dp[-1][0])+1)%mod ans (sum(dp[-1][1])+sum(dp[-1][0])+1)%mod sum(dp[-1][1])+sum(dp[-1][0])+1 sum(dp[-1][1])+sum(dp[-1][0]) sum(dp[-1][1]) sum dp[-1][1] [-1] dp -1 1 sum(dp[-1][0]) sum dp[-1][0] [-1] dp -1 0 1 mod print(ans) print ans dp = [[[0]*2 for _ in range(2)]for _ in range(N)] [[[0]*2 for _ in range(2)]for _ in range(N)] dp mod = 10**9 +7 10**9 +7 mod nxFlag = 0 0 nxFlag x = int(L[i+1]) int(L[i+1]) x ans = (sum(dp[-1][1])+sum(dp[-1][0])+1)%mod (sum(dp[-1][1])+sum(dp[-1][0])+1)%mod ans L = input() input() L N = len(L) len(L) N nxFlag = 1 1 nxFlag
"""
制約がヒントっぽいな。
桁DPで解ける

dp[i][j][k] => 2進数表記でa+bの左からi桁目まで見る。i桁目がjになるような場合の数。kは未満フラグ。配るDPで解く。

"""
L = input()
N = len(L)
mod = 10**9 +7
dp = [[[0]*2 for _ in range(2)]for _ in range(N)]
dp[0][1][0] = 2
for i in range(1,N):
    dp[i][1][1] = 2

for i in range(N-1):
    x = int(L[i+1])
    for j in range(2):
        for k in range(2):
            for l in range(2):
                if not k and l > x:
                    continue
                if k or l < x:
                    nxFlag = 1
                else:
                    nxFlag = 0
                if l == 0:
                    dp[i+1][l][nxFlag] += dp[i][j][k]
                else:
                    dp[i+1][l][nxFlag] += dp[i][j][k]*2
                dp[i+1][l][nxFlag]%=mod
ans = (sum(dp[-1][1])+sum(dp[-1][0])+1)%mod
print(ans)