#include <bits/stdc++.h>
using namespace std;
int d2x[] = {1, -1, 0, 0, 1, -1, 1, -1};
int d2y[] = {0, 0, 1, -1, 1, -1, -1, 1};
int d3x[] = {1, -1, 0, 0, 0, 0};
int d3y[] = {0, 0, 1, -1, 0, 0};
int d3z[] = {0, 0, 0, 0, 1, -1};
struct edge {
  int from, to, w;
  edge(int from, int to, int w) : from(from), to(to), w(w) {}
  bool operator<(const edge& e) const { return w > e.w; }
};
const double EPS = (1e-9);
string a;
long long e, res = 0LL, r;
int cntA = 0, cntB = 0;
bool flag;
long long power(long long num, long long p);
inline void calculate();
vector<vector<long long> > zero(int n, int m);
vector<vector<long long> > identity(int n);
vector<vector<long long> > mulMat(const vector<vector<long long> >& a,
                                  const vector<vector<long long> >& b);
vector<vector<long long> > powMat(const vector<vector<long long> >& a,
                                  long long k);
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  cin >> a >> e;
  for (int i = 0; i < ((int)((a).size())); ++i) {
    if (a[i] == '5' || a[i] == '0') {
      ++cntA;
    } else {
      if (cntA) {
        calculate();
        cntA = 0;
      }
      cntB = i + 1;
    }
  }
  if (cntA) {
    calculate();
  }
  r = power(2, ((int)((a).size())));
  vector<vector<long long> > A = zero(2, 2);
  vector<vector<long long> > B = zero(2, 1);
  A[0][0] = r;
  A[1][0] = 1;
  A[1][1] = 1;
  B[0][0] = 1;
  A = powMat(A, e);
  B = mulMat(A, B);
  cout << ((B[1][0] % 1000000007) * (res % 1000000007)) % 1000000007;
  return 0;
}
long long power(long long num, long long p) {
  if (p == 0) return 1LL;
  long long x = power(num, p / 2) % 1000000007;
  if (p % 2 == 0)
    return (x * x) % 1000000007;
  else
    return ((((num % 1000000007) * x) % 1000000007) * x) % 1000000007;
}
inline void calculate() {
  res %= 1000000007;
  res += (power(2, cntB) * (power(2, cntA) - 1)) % 1000000007;
  res %= 1000000007;
}
vector<vector<long long> > zero(int n, int m) {
  return vector<vector<long long> >(n, vector<long long>(m, 0));
}
vector<vector<long long> > identity(int n) {
  vector<vector<long long> > ret = zero(n, n);
  for (int i = 0; i < ((int)((ret).size())); ++i) ret[i][i] = 1;
  return ret;
}
vector<vector<long long> > mulMat(const vector<vector<long long> >& a,
                                  const vector<vector<long long> >& b) {
  vector<vector<long long> > ret =
      zero(((int)((a).size())), ((int)((b[0]).size())));
  for (int i = 0; i < ((int)((a).size())); ++i)
    for (int k = 0; k < ((int)((a[0]).size())); ++k)
      for (int j = 0; j < ((int)((b[0]).size())); ++j) {
        ret[i][j] += (a[i][k] * b[k][j]) % 1000000007;
        ret[i][j] %= 1000000007;
      }
  return ret;
}
vector<vector<long long> > powMat(const vector<vector<long long> >& a,
                                  long long k) {
  if (k == 0) return identity(((int)((a).size())));
  if (k % 2 == 1) return mulMat(a, powMat(a, k - 1));
  return powMat(mulMat(a, a), k / 2);
}
