#include <bits/stdc++.h>
using namespace std;
long long powMod(long long a, long long b) {
  if (!b) return 1;
  if (b % 2) return (a * powMod(a, b - 1)) % 1000000007;
  long long p = powMod(a, b / 2);
  return (p * p) % 1000000007;
}
int main() {
  int i, k;
  long long n, x, a, res = 0;
  string str;
  vector<int> pos;
  cin >> str >> k;
  n = str.length();
  for (i = 0; i < n; i++) {
    if (str[i] == '0' || str[i] == '5') {
      x = 1;
      x = (x * powMod(2, i)) % 1000000007;
      x = (x * (powMod(2, n * k) - 1)) % 1000000007;
      a = powMod(powMod(2, n) - 1, 1000000007 - 2);
      x = (x * a) % 1000000007;
      res = (res + x) % 1000000007;
    }
  }
  cout << res << endl;
  return 0;
}
