#include <bits/stdc++.h>
using namespace std;
long long int M = 1000000007;
long long int powmod(long long int n, long long int k, long long int m) {
  long long int res = 1;
  while (k) {
    if (k & 1) {
      res = (res * n) % m;
    }
    n = (n * n) % m;
    k /= 2;
  }
  return res;
}
long long int inv(long long int value) { return powmod(value, M - 2, M); }
int main() {
  ios_base::sync_with_stdio(0);
  string line;
  int k;
  long long int result = 0;
  cin >> line;
  int n = line.size();
  cin >> k;
  long long int qn = powmod(2, ((long long int)n) * k, M);
  long long int q = powmod(2, n, M);
  long long int k2 = powmod(2, k, M);
  int idx = 1;
  for (int i = 0; i < n; ++i) {
    char v = line[i];
    if (v == '0' || v == '5') {
      result = (result + idx) % M;
    }
    idx = (idx * 2) % M;
  }
  long long int kpart = ((qn - 1) * inv(q - 1)) % M;
  result = (result * kpart) % M;
  cout << result << endl;
  return 0;
};
