#include <bits/stdc++.h>
using namespace std;
long long bigmod(long long a, long long b, long long m) {
  long long ret = 1, p = a;
  while (b) {
    if (b & 1) ret = (ret * p) % m;
    p = (p * p) % m;
    b >>= 1;
  }
  return ret % m;
}
long long egcd(long long a, long long b, long long &x, long long &y) {
  if (a == 0) {
    x = 0, y = 1;
    return b;
  }
  long long _x, _y;
  long long g = egcd(b % a, a, _x, _y);
  x = _y - (b / a) * _x;
  y = _x;
  return g;
}
long long modinv(long long n, long long m) {
  long long inv, del;
  long long g = egcd(n, m, inv, del);
  return g == 1 ? (inv + m) % m : -1;
}
const int mod = 1e9 + 7;
long long p[100010];
int main() {
  string s;
  int k;
  cin >> s >> k;
  int m = s.size();
  p[0] = 1;
  for (int i = 1; i <= m; i++)
    p[i] = (p[i - 1] + p[i - 1] >= mod ? p[i - 1] + p[i - 1] - mod
                                       : p[i - 1] + p[i - 1]);
  long long inv = modinv(p[m] - 1 + mod, mod);
  long long ans = 0;
  for (int i = 0; i < m; i++) {
    if (s[i] == '0' || s[i] == '5') {
      long long got =
          (p[i] * (bigmod(p[m], k, mod) - 1 + mod) % mod) * inv % mod;
      ans = (ans + got >= mod ? ans + got - mod : ans + got);
    }
  }
  cout << ans;
  return 0;
}
