#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T gcd(T x, T y) {
  if (!y) return x;
  return gcd(y, x % y);
}
const int INF = 1e9;
const int MOD = 1e9 + 7;
long long mpow(long long a, long long b, long long c) {
  long long ret = 1;
  while (b) {
    if (b & 1) ret = (ret * a) % c;
    b >>= 1;
    a = (a * a) % c;
  }
  return ret;
}
long long f(long long y, long long k) {
  long long x = mpow(y - 1, MOD - 2, MOD);
  long long x1 = (mpow(y, k + 1, MOD) - 1);
  return (x1 * x) % MOD;
}
int main(int argc, char* argv[]) {
  if (argc == 2 or argc == 3) freopen(argv[1], "r", stdin);
  if (argc == 3) freopen(argv[2], "w", stdout);
  ios::sync_with_stdio(false);
  string s;
  long long k;
  cin >> s >> k;
  long long y = mpow(2, s.length(), MOD), ans = 0;
  for (__typeof(0) i = 0; i < s.length(); i += 1) {
    if (s[i] == '5' or s[i] == '0') {
      ans += (mpow(2, i, MOD) * f(y, k - 1)) % MOD;
    }
  }
  ans = (ans + MOD) % MOD;
  cout << ans << endl;
  return 0;
}
