#include <bits/stdc++.h>
using namespace std;
unsigned long long ppw(unsigned long long a, int n) {
  unsigned long long result = 1;
  unsigned long long temp = a;
  while (n > 0) {
    if (n % 2) result = (result * temp) % 1000000007;
    n >>= 1;
    temp = (temp * temp) % 1000000007;
  }
  return result;
}
int main() {
  string s;
  int n;
  cin >> s >> n;
  unsigned long long b = 1;
  unsigned long long a = 0;
  for (int i = 0; i < s.length(); ++i) {
    char c = s[i];
    if (c == '0' || c == '5') a += b;
    b <<= 1;
    if ((i % 16) == 0) {
      a = a % 1000000007;
      b = b % 1000000007;
    }
  }
  b = b % 1000000007;
  a = a % 1000000007;
  unsigned long long r = a, a0 = a;
  unsigned long long u = (ppw(b, n) - 1 + 1000000007) % 1000000007;
  unsigned long long d = (b - 1 + 1000000007) % 1000000007;
  r = (a0 * ((u * ppw(d, 1000000007 - 2)) % 1000000007)) % 1000000007;
  cout << r << endl;
  return 0;
}
