#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-3;
const int INF = (long double)(1e9);
const long long mod = (int)(1e+9 + 7);
const int N = (int)(2e3);
int days_month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
long long ekn;
long long inverse;
long long expo(long long b, long long e) {
  long long prod = 1;
  while (e != 0) {
    if (e & 1) prod = (1LL * prod * b) % mod;
    b = (1LL * b * b) % mod;
    e >>= 1;
  }
  return prod % mod;
}
int f(int i) {
  long long prod = (1LL * expo(2, i) * (ekn - 1)) % mod;
  prod = (prod * inverse) % mod;
  return prod;
}
int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  int n = int(s.size());
  ekn = expo(2, 1LL * k * n);
  inverse = expo(expo(2, n) - 1, mod - 2);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] != '0' && s[i] != '5') continue;
    ans += f(i);
    if (ans >= mod) ans -= mod;
  }
  cout << ans;
  return 0;
}
