#include <bits/stdc++.h>
const long long MOD = 1e9 + 7;
long long QPow(long long x, long long y) {
  long long ans = 1, base = x % MOD;
  while (y) {
    if (y & 1) {
      ans = (ans * base) % MOD;
    }
    base = (base * base) % MOD;
    y >>= 1;
  }
  return ans;
}
long long Inv(long long x) { return QPow(x, MOD - 2); }
int main() {
  std::string a;
  int k;
  std::cin >> a >> k;
  long long ans = 0;
  for (int i = 0; i <= a.length() - 1; i++) {
    if (a[i] == '0' || a[i] == '5') {
      ans = (ans + QPow(2, i)) % MOD;
    }
  }
  printf("%lld", (((ans * (QPow(2, 1ll * a.length() * k) - 1)) % MOD) *
                  Inv(QPow(2, a.length()) - 1)) %
                     MOD);
  return 0;
}
