#include <bits/stdc++.h>
using namespace std;
char s[100004];
int k;
long long f(long long a, long long b, long long &x, long long &y) {
  long long ans, t;
  if (b == 0) {
    x = 1, y = 0;
    return a;
  }
  ans = f(b, a % b, x, y);
  t = x, x = y, y = t - (a / b) * y;
  return ans;
}
long long p(long long base, long long n) {
  long long r = 1;
  while (n) {
    if (n & 1) r = (r * base) % 1000000007;
    base = (base * base) % 1000000007;
    n >>= 1;
  }
  return r;
}
int main() {
  while (scanf("%s %d", s, &k) != EOF) {
    long long a1 = 0;
    int len = strlen(s);
    for (int i = 0; i < len; i++) {
      if (s[i] == '0' || s[i] == '5') {
        a1 = (a1 + p(2, i)) % 1000000007;
      }
    }
    long long q = p(2, len);
    long long q1 = (q + 1000000007 - 1) % 1000000007;
    long long X, Y;
    f(q1, 1000000007, X, Y);
    X = (X + 1000000007) % 1000000007;
    long long qn_x = (p(q, k) - 1) * X % 1000000007;
    long long ans = (a1 * qn_x) % 1000000007;
    cout << ans << endl;
  }
  return 0;
}
