#include <bits/stdc++.h>
using namespace std;
long long ans = 0;
long long mod(long long l, long long r = 1) {
  return ((l % 1000000007) * (r % 1000000007)) % 1000000007;
}
long long pow1(long long base, long long exp) {
  if (exp == 0) return 1;
  if (exp == 1) return base % 1000000007;
  long long tmp = pow1(base, exp / 2);
  if (exp % 2 == 0)
    return mod(tmp, tmp);
  else
    return mod(mod(tmp, tmp), base);
}
int main() {
  string x;
  while (cin >> x) {
    ans = 0;
    long long k;
    cin >> k;
    long long n = x.size();
    long long Constant =
        mod(pow1(2, k * n) - 1, pow1((pow1(2, n) - 1), 1000000007 - 2));
    Constant %= 1000000007;
    for (int i = 0; i < n; i++) {
      if (x[i] == '0' || x[i] == '5') {
        ans += mod(pow1(2, i), Constant);
        ans %= 1000000007;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
