#include <bits/stdc++.h>
using namespace std;
const int INF = ~(1 << 31);
const double E = exp(1.0);
const double Pi = 4 * atan(1.0);
int solve(int);
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int T, i;
  T = 1;
  for (i = 1; i <= T; ++i) {
    int x = solve(i);
  }
  return 0;
}
int n, m;
const int N = 1e5 + 5;
const int md = 1e9 + 7;
char a[N];
long long mpow(long long a, long long b, long long md = 1e9 + 7) {
  if (b == 0) return 1;
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % md;
    b >>= 1;
    a = a * a % md;
  }
  return ans;
}
long long niYuan(long long a, long long b) { return mpow(a, b - 2, b); }
int solve(int T) {
  int i, j;
  cin >> a;
  int k;
  cin >> k;
  long long n = (long long)strlen(a);
  long long ans = 0;
  long long p = mpow(2, n, md);
  for (i = 0; i <= n - 1; ++i) {
    if (a[i] == '0' || a[i] == '5') {
      ans = (ans + mpow(2, i, md) * (mpow(2, k * n) - 1) % md *
                       niYuan((p - 1 + md) % md, md) % md) %
            md;
    }
  }
  cout << ans << '\n';
  return 0;
}
