#include <bits/stdc++.h>
using namespace std;
char s[100004];
long long k, mod = 1000000007;
long long qpow(long long n, long long m) {
  long long ans = 1;
  for (; m; m >>= 1) {
    if (m & 1) ans = ans * n % mod;
    n = n * n % mod;
  }
  return ans;
}
int main() {
  scanf("%s %lld", s, &k);
  int l = strlen(s);
  long long p = 0, q = 0;
  for (int i = 0; i < l; i++)
    if (s[i] == '0' || s[i] == '5') p = (p + qpow(2, i)) % mod;
  q = (qpow(2, k * l) - 1) * qpow(qpow(2, l) - 1, mod - 2) % mod;
  printf("%lld\n", p * q % mod);
}
