#include <bits/stdc++.h>
using namespace std;
long long int power(long long int a, long long int p) {
  if (p == 0) return 1;
  if (p == 1) return a;
  if (p % 2 == 0) {
    long long int c = power(a, p / 2);
    long long int d = (c * c) % 1000000007;
    return d;
  } else {
    long long int c = power(a, p - 1);
    long long int d = (c * a) % 1000000007;
    return d;
  }
}
int main() {
  long long int a, b, c, d, i, j, k, l, m, n, r;
  string s1, s2;
  cin >> s1 >> r;
  l = s1.size();
  k = 0;
  for (i = 0; i < s1.size(); i++) {
    if (s1[i] == '0' || s1[i] == '5') {
      m = power(2, i) % 1000000007;
      a = power(2, l);
      b = power(a, r);
      b = (b + 1000000007 - 1) % 1000000007;
      c = power(a - 1, 1000000007 - 2);
      b = (b * c) % 1000000007;
      b = (b * m) % 1000000007;
      k = (k + b) % 1000000007;
    }
  }
  cout << k << endl;
  return 0;
}
