#include <bits/stdc++.h>
using namespace std;
void read_file(bool outToFile = true) {}
int n;
int K;
char str[100000 + 1 + 9];
map<int, map<long long, int> > memo;
int pwr(int x, long long n) {
  if (n == 0) return 1;
  int ret;
  if (n % 2 == 1)
    return ret = 1LL * x * pwr(x, n - 1) % (1000000007);
  else
    return ret = pwr(1LL * x * x % (1000000007), n / 2);
}
int mod_inv(int x) { return pwr(x, (1000000007) - 2); }
int main() {
  read_file();
  while (scanf("%s", str) != EOF) {
    n = strlen(str);
    scanf("%d", &K);
    int ans = 0;
    int _2_nk = pwr(2, 1LL * n * K);
    int num = _2_nk - 1;
    if (num < 0) num += (1000000007);
    int _2_n = pwr(2, n);
    int den = _2_n - 1;
    if (den < 0) den += (1000000007);
    den = mod_inv(den);
    num = 1LL * num * den % (1000000007);
    for (int i = 0; i < n; i++) {
      if (str[i] == '0' || str[i] == '5') {
        int _2_i = pwr(2, i);
        int nw = 1LL * _2_i * num % (1000000007);
        ans += nw;
        ans %= (1000000007);
      }
    }
    printf("%d\n", ans);
  }
}
