m = int(1e9)+7
n = int(input().strip())
s = list(map(int, list('0'+input().strip())))
dp = [[0]*8 for i in range(n+1)]
dp[0][0] = 1
for i in range(1, n+1):
for j in range(8):
dp[i][j] += dp[i-1][j]
for k in range(8):
dp[i][(k*10+s[i])%8] += dp[i-1][k]
for j in range(8):
dp[i][j] %= m
print((dp[n][0]-1+m)%m)
bSA9IGludCgxZTkpKzcKCm4gPSBpbnQoaW5wdXQoKS5zdHJpcCgpKQpzID0gbGlzdChtYXAoaW50LCBsaXN0KCcwJytpbnB1dCgpLnN0cmlwKCkpKSkKCmRwID0gW1swXSo4IGZvciBpIGluIHJhbmdlKG4rMSldCmRwWzBdWzBdID0gMQoKZm9yIGkgaW4gcmFuZ2UoMSwgbisxKToKICAgIGZvciBqIGluIHJhbmdlKDgpOgogICAgICAgIGRwW2ldW2pdICs9IGRwW2ktMV1bal0KICAgICAgICAKICAgIGZvciBrIGluIHJhbmdlKDgpOgogICAgICAgIGRwW2ldWyhrKjEwK3NbaV0pJThdICs9IGRwW2ktMV1ba10KICAgICAgICAKICAgIGZvciBqIGluIHJhbmdlKDgpOgogICAgICAgIGRwW2ldW2pdICU9IG0KCnByaW50KChkcFtuXVswXS0xK20pJW0p