import math
a = raw_input()
n = len(a)
k = int(raw_input())
mod = 1000000007
p2 = 1
s = 0
for i in range(n):
    if a[i] == '0' or a[i] == '5':
        s+=p2
    p2=(p2*2)%mod;
inv = pow(pow(2,n,mod)-1,mod-2,mod)
ans = s*(pow(2,n*k,mod)-1)*inv%mod
print ans

76401b52cfd1df139e4908c28118e7e9f2870250
import math
a = raw_input()
n = len(a)
k = int(raw_input())
mod = 1000000007
p2 = 1
s = 0
for i in range(n):
    if a[i] == '0' or a[i] == '5':
        s+=p2
    p2=(p2*2)%mod;
inv = pow(pow(2,n,mod)-1,mod-2,mod)
ans = s*(pow(2,n*k,mod)-1)*inv%mod
print ans
