#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long x[111111];
long long mul(long long x, long long y) { return x * y % mod; }
long long sq(long long a, long long n) {
  long long ans = 1;
  long long tmp = a;
  while (n) {
    if (n & 1) ans = (ans * tmp) % mod;
    tmp = (tmp * tmp) % mod;
    n /= 2;
  }
  return ans;
}
int main() {
  char a[111111];
  int aa, k;
  scanf("%s%d", a, &k);
  aa = strlen(a);
  x[0] = 1;
  for (int i = 1; i <= aa; ++i) x[i] = (x[i - 1] << 1) % mod;
  long long ans = 0;
  for (int i = 0; i < aa; ++i) {
    if (a[i] == '5' || a[i] == '0') {
      ans += x[i];
      ans %= mod;
    }
  }
  ans = ans *
        mul((sq(2LL, (long long)aa * k) % mod + mod - 1) % mod,
            sq((sq(2LL, aa) + mod - 1) % mod, mod - 2)) %
        mod;
  cout << ans << endl;
  return 0;
}
