#include <bits/stdc++.h>
using namespace std;
long long modpow(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a) % 1000000007;
    a = (a * a) % 1000000007;
    b >>= 1;
  }
  return res;
}
long long modinv(long long a) { return modpow(a, 1000000007 - 2); }
int main() {
  char s[100009];
  int k;
  scanf("%s", s);
  scanf("%d", &k);
  int len = strlen(s), i;
  long long ans = 0;
  long long factor = (modpow(modpow(2, len), k) + 1000000007 - 1) % 1000000007;
  factor = (factor * modinv((modpow(2, len) + 1000000007 - 1) % 1000000007)) %
           1000000007;
  for (i = 0; i < len; i++) {
    if (s[i] == '0' || s[i] == '5') {
      ans = (ans + modpow(2, i)) % 1000000007;
    }
  }
  ans = (ans * factor) % 1000000007;
  printf("%I64d\n", ans);
  return 0;
}
