fork download
  1. m = int(1e9)+7
  2.  
  3. n = int(input().strip())
  4. s = list(map(int, list('0'+input().strip())))
  5.  
  6. dp = [[0]*8 for i in range(n+1)]
  7. dp[0][0] = 1
  8.  
  9. for i in range(1, n+1):
  10. for j in range(8):
  11. dp[i][j] += dp[i-1][j]
  12.  
  13. for k in range(8):
  14. dp[i][(k*10+s[i])%8] += dp[i-1][k]
  15.  
  16. for j in range(8):
  17. dp[i][j] %= m
  18.  
  19. print((dp[n][0]-1+m)%m)
Success #stdin #stdout 0s 9992KB
stdin
3
968
stdout
3