#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T modinv(T a, T n) {
  T i = n, v = 0, d = 1;
  while (a > 0) {
    T t = i / a, x = a;
    a = i % x;
    i = x;
    x = d;
    d = v - t * x;
    v = x;
  }
  return (v + n) % n;
}
long long modpow(long long n, long long k, long long mod) {
  if (k == 0) return 1LL;
  long long ans = 1;
  while (k > 0) {
    if (k & 1) ans = (ans * n) % mod;
    k >>= 1;
    n = (n * n) % mod;
  }
  return ans % mod;
}
template <class T>
struct Fraction {
  T a, b;
  Fraction(T a = 0, T b = 1);
  string toString();
};
template <class T>
Fraction<T>::Fraction(T a, T b) {
  T d = GCD(a, b);
  a /= d;
  b /= d;
  if (b < 0) a = -a, b = -b;
  this->a = a;
  this->b = b;
}
template <class T>
string Fraction<T>::toString() {
  ostringstream sout;
  sout << a << "/" << b;
  return sout.str();
}
template <class T>
Fraction<T> operator+(Fraction<T> p, Fraction<T> q) {
  return Fraction<T>(p.a * q.b + q.a * p.b, p.b * q.b);
}
template <class T>
Fraction<T> operator-(Fraction<T> p, Fraction<T> q) {
  return Fraction<T>(p.a * q.b - q.a * p.b, p.b * q.b);
}
template <class T>
Fraction<T> operator*(Fraction<T> p, Fraction<T> q) {
  return Fraction<T>(p.a * q.a, p.b * q.b);
}
template <class T>
Fraction<T> operator/(Fraction<T> p, Fraction<T> q) {
  return Fraction<T>(p.a * q.b, p.b * q.a);
}
template <class T>
string str(T Number) {
  string Result;
  ostringstream convert;
  convert << Number;
  Result = convert.str();
  return Result;
}
int StringToNumber(const string &Text) {
  istringstream ss(Text);
  int result;
  return ss >> result ? result : 0;
}
template <class T>
inline vector<pair<T, int> > FACTORISE(T n) {
  vector<pair<T, int> > R;
  for (T i = 2; n > 1;) {
    if (n % i == 0) {
      int C = 0;
      for (; n % i == 0; C++, n /= i)
        ;
      R.push_back(make_pair(i, C));
    }
    i++;
    if (i > n / i) i = n;
  }
  if (n > 1) R.push_back(make_pair(n, 1));
  return R;
}
template <class T>
inline T TOTIENT(T n) {
  vector<pair<T, int> > R = FACTORISE(n);
  T r = n;
  for (int i = 0; i < R.size(); i++) r = r / R[i].first * (R[i].first - 1);
  return r;
}
template <class T>
inline T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
double rnd(float d) { return floor(d + 0.49); }
int main() {
  string s;
  cin >> s;
  int k = ({
    int x;
    scanf("%d", &x);
    x;
  });
  long long ans = 0;
  long long n = ((int)(s).size());
  long long t = (modpow(2, n, 1000000007) - 1 + 1000000007);
  long long inv = modpow(t + 1000000007, 1000000007 - 2, 1000000007);
  for (long long i = 0; i < n; i++) {
    if ((s[i] - 48) % 5 == 0) {
      ans = (ans + modpow(2, i, 1000000007)) % 1000000007;
    }
  }
  cout << (ans * (modpow(2, (k)*n, 1000000007) - 1 + 1000000007) % 1000000007 *
           inv) %
              1000000007
       << "\n";
  return 0;
}
