#include <bits/stdc++.h>
using namespace std;
long long func(long long n) {
  if (n == 0) return 1;
  long long tmp = func(n / 2);
  tmp = (tmp * tmp) % 1000000007;
  if (n % 2) return (tmp * 2) % 1000000007;
  return tmp;
}
long long d, x, y;
void extendedEuclid(long long A, long long B) {
  if (B == 0) {
    d = A;
    x = 1;
    y = 0;
  } else {
    extendedEuclid(B, A % B);
    long long temp = x;
    x = y;
    y = temp - (A / B) * y;
  }
}
long long modInverse(long long A, long long M) {
  extendedEuclid(A, M);
  return (x % M + M) % M;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  string s;
  cin >> s;
  long long k;
  cin >> k;
  long long ans = 0;
  long long b, c;
  b = (func((long long)s.size()) - 1 + 1000000007) % 1000000007;
  c = (func(k * (long long)s.size()) - 1 + 1000000007) % 1000000007;
  b = modInverse(b, 1000000007);
  c = (b * c) % 1000000007;
  for (long long i = (long long)s.size() - 1; i >= 0; i--) {
    if (s[i] == '0' || s[i] == '5') {
      ans += (func(i) * c) % 1000000007;
      ans %= 1000000007;
    }
  }
  cout << ans;
  return 0;
}
