#include <bits/stdc++.h>
using namespace std;
char s[100000 + 1];
long long modpow(long long x, long long n) {
  long long P = 1;
  while (n) {
    if (n & 1) P = P * x % 1000000007;
    n >>= 1;
    x = x * x % 1000000007;
  }
  return P;
}
int main() {
  while (scanf("%s", s) == 1) {
    int n = strlen(s), k;
    scanf("%d", &k);
    int A = 0, pot2 = 1;
    for (int i = 0; i < n; i++) {
      if (s[i] == '0' || s[i] == '5') A = (A + pot2) % 1000000007;
      pot2 = pot2 * 2 % 1000000007;
    }
    int B = (modpow(2, 1LL * n * k) - 1 + 1000000007) % 1000000007;
    B = 1LL * B *
        modpow((modpow(2, n) - 1 + 1000000007) % 1000000007, 1000000007 - 2) %
        1000000007;
    cout << 1LL * A * B % 1000000007 << endl;
  }
  return 0;
}
