#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const double pi = acos(-1.0);
const double eps = 1e-9;
const int dX[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int dY[] = {0, 0, -1, 1, 1, -1, -1, 1};
template <class S, class T>
ostream& operator<<(ostream& o, pair<S, T>& a) {
  o << a.first << " " << a.second;
  return o;
}
template <class S, class T>
istream& operator>>(istream& i, pair<S, T>& a) {
  i >> a.first >> a.second;
  return i;
}
template <class S, class T>
ostream& operator<<(ostream& o, map<S, T>& a) {
  for (typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
    o << (*it) << "\n";
  return o;
}
template <class S>
ostream& operator<<(ostream& o, vector<S>& a) {
  for (typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
    o << *it << " ";
  return o;
}
template <class S>
ostream& operator<<(ostream& o, vector<vector<S> >& a) {
  for (typeof((a).begin()) it = (a).begin(); it != (a).end(); it++) {
    o << (*it) << "\n";
  }
  return o;
}
template <class S>
ostream& operator<<(ostream& o, set<S>& a) {
  for (typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
    o << *it << " ";
  return o;
}
template <class S, class T>
bool& operator==(pair<S, T>& a, pair<S, T>& b) {
  return a.first == b.first && a.second == b.second;
}
inline bool isInt(double x) { return x == floor(x); }
inline long long modPow(long long b, long long e, long long m = mod) {
  long long s = 1;
  while (e) {
    if (e & 1) s = (s * b) % m;
    b = (b * b) % m;
    e >>= 1;
  }
  return s;
}
inline long long modInv(long long a, long long m = mod) {
  return modPow(a, m - 2, m);
}
const long long MAX = 1001;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0);
  long long i, k, ans = 0, mul;
  string s;
  cin >> s;
  cin >> k;
  mul = (((modPow(2, ((long long)(s).size()) * k) - 1 + mod) % mod) *
         (modInv((modPow(2, ((long long)(s).size())) - 1 + mod) % mod))) %
        mod;
  for (i = (0); (((1) > 0) - ((1) < 0)) * i <
                (((1) > 0) - ((1) < 0)) * (((long long)(s).size()));
       i += (1)) {
    if (s[i] == '0' || s[i] == '5') {
      ans = (ans + modPow(2, i)) % mod;
    }
  }
  ans = (ans * mul) % mod;
  cout << ans;
  return 0;
}
