#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 28;
const int mod = (int)1e9 + 7;
const double eps = 1e-6;
const double pi = acos(-1.0);
int n, m;
char a[100010];
long long quick(long long a, long long b, long long mod) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % mod;
    b >>= 1;
    a = a * a % mod;
  }
  return ans % mod;
}
int main() {
  while (~scanf("%s%d", a, &n)) {
    long long len = strlen(a);
    long long ans = 0;
    long long tt = (quick(2, n * len % (mod - 1), mod) - 1 + mod) % mod;
    long long ttt = (quick(2, len, mod) - 1 + mod) % mod;
    long long niv = quick(ttt, mod - 2, mod);
    long long tttt = tt * niv % mod;
    if (tt < 0) tt += mod;
    for (int i = len - 1; i >= 0; i--) {
      if (a[i] == '0' || a[i] == '5') {
        long long tmp = tttt * quick(2, i, mod) % mod;
        ans = (ans + tmp) % mod;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
