#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <utility>
#include <set>
#include <stack>
#include <vector>
#include <map>
#include <queue>
#define MAX_N 100005
#define MOD 1000000007
using namespace std;
inline long long int square(long long int x){ return ((x * x) % MOD); }
long long int fastexp(long long int b, long long int e){
if(e == 0) return 1;
if((e % 2) == 0) return (square(fastexp(b, e/2) % MOD) % MOD);
return ((b * fastexp(b, e-1)) % MOD);
}
char a[MAX_N];
long long int k, s, tmp, r, t, pot, len, p1;
int main(){
scanf("%s", a);
scanf("%I64d", &k);
s = 0;
len = strlen(a);
r = fastexp(2, len);
t = ((1 - fastexp(r, k)) / (1 - r)) % MOD;
pot = r / 2;
for(int i = len-1; i >= 0; i --){
if(a[i] == '0' || a[i] == '5'){
tmp = (pot * t) % MOD;
s = (s + tmp) % MOD;
}
pot /= 2;
}
printf("%I64d\n", s);
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPG1hdGguaD4KI2luY2x1ZGUgPHN0cmluZy5oPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8dXRpbGl0eT4KI2luY2x1ZGUgPHNldD4KI2luY2x1ZGUgPHN0YWNrPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8bWFwPgojaW5jbHVkZSA8cXVldWU+CgojZGVmaW5lIE1BWF9OIDEwMDAwNQojZGVmaW5lIE1PRCAxMDAwMDAwMDA3Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW5saW5lIGxvbmcgbG9uZyBpbnQgc3F1YXJlKGxvbmcgbG9uZyBpbnQgeCl7IHJldHVybiAoKHggKiB4KSAlIE1PRCk7IH0KCmxvbmcgbG9uZyBpbnQgZmFzdGV4cChsb25nIGxvbmcgaW50IGIsIGxvbmcgbG9uZyBpbnQgZSl7CiAgaWYoZSA9PSAwKSByZXR1cm4gMTsKICBpZigoZSAlIDIp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