#include <bits/stdc++.h>
using namespace std;
long long fastpower(long long power, long long base) {
  if (power == 0) return (1 % 1000000007);
  long long sum;
  sum = fastpower(power / 2, base) % 1000000007;
  sum = ((sum % 1000000007) * (sum % 1000000007)) % 1000000007;
  if (power & 1) sum = ((sum % 1000000007) * (base % 1000000007)) % 1000000007;
  return (sum % 1000000007);
}
int main() {
  ios::sync_with_stdio(0), ios_base::sync_with_stdio(0), cin.tie(0),
      cout.tie(0);
  ;
  string s;
  long long k, sum = 0;
  cin >> s >> k;
  long long rn =
      (fastpower((long long)s.size() * k, 2) - 1 + 1000000007) % 1000000007;
  long long r =
      (fastpower((long long)s.size(), 2) - 1 + 1000000007) % 1000000007;
  long long d = fastpower(1000000007 - 2, r);
  for (int i = 0; i < (int)s.size(); ++i) {
    if (s[i] == '0' || s[i] == '5') {
      long long a = fastpower(i, 2);
      sum = (sum % 1000000007 + a * rn % 1000000007 * d % 1000000007) %
            1000000007;
    }
  }
  cout << sum << "\n";
  return 0;
}
