#include <bits/stdc++.h>
using namespace std;
long long int modpow(long long int a, long long int n, long long int temp) {
  long long int res = 1, y = a;
  while (n > 0) {
    if (n & 1) res = (res * y) % temp;
    y = (y * y) % temp;
    n /= 2;
  }
  return res % temp;
}
char ch[1000006];
int main() {
  long long int i, sz, ans = 0, calc, c1, a;
  scanf("%s", ch);
  scanf("%lld", &a);
  sz = strlen(ch);
  cerr << "sz"
       << ": " << sz << " | "
       << "a"
       << ": " << a << endl;
  ;
  calc = modpow(2, sz * a, (int)(1e9 + 7)) - 1;
  c1 = modpow(2, sz, (int)(1e9 + 7)) - 1;
  calc = calc * modpow(c1, (int)(1e9 + 7) - 2, (int)(1e9 + 7));
  calc %= (int)(1e9 + 7);
  for (i = 0; i < sz; ++i) {
    if (ch[i] == '0' || ch[i] == '5') {
      c1 = modpow(2, i, (int)(1e9 + 7));
      ans += c1 * calc;
      ans %= (int)(1e9 + 7);
    }
  }
  printf("%lld\n", ans);
  return 0;
}
