#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long double PI = acosl(-1);
const long long infl = 3e18;
const int inf = 2e9;
const int nmax = 2e5 + 10;
const int MAXLG = log2(nmax) + 1;
long long bigmod(long long a, long long p, long long m = mod) {
  long long res = 1, x = a;
  while (p) {
    if (p & 1) res = (res * x) % m;
    x = (x * x) % m, p /= 2;
  }
  return res;
}
long long modinv(long long a) { return bigmod(a, mod - 2); }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string a;
  int k;
  cin >> a >> k;
  long long asz = a.size();
  long long ans = 0;
  long long c = modinv((bigmod(2, asz) - 1 + mod) % mod);
  for (int i = 0; i < asz; i++) {
    if (a[i] == '0' or a[i] == '5') {
      long long z = asz * k;
      z %= (mod - 1);
      ans = (ans + (bigmod(2, i) * (bigmod(2, z) - 1) % mod + mod) % mod) % mod;
    }
  }
  ans = ans * c % mod;
  cout << ans << endl;
}
