#include <bits/stdc++.h>
using namespace std;
long long power(long long base, long long exp) {
  if (exp == 0) return 1;
  long long a = power(base, exp / 2);
  if (exp % 2 == 0)
    return (a * a) % 1000000007;
  else
    return (((a * a) % 1000000007) * base) % 1000000007;
}
int main() {
  string str;
  cin >> str;
  long long i, j, k, l, m;
  cin >> i;
  l = str.length();
  j = power(2, l);
  j = (power(j, i) - 1 + 1000000007) % 1000000007;
  k = 0;
  for (m = 0; m < str.length(); m++) {
    if (str[m] == '0' || str[m] == '5') k = (k + power(2, m)) % 1000000007;
  }
  j = (j * k) % 1000000007;
  k = (power(2, int(str.length())) - 1 + 1000000007) % 1000000007;
  k = power(k, 1000000007 - 2) % 1000000007;
  j = (j * k) % 1000000007;
  cout << j << endl;
  return 0;
}
