#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long b) {
  if (b == 0)
    return 1;
  else if (b % 2 == 0)
    return power((a * a) % 1000000007, b / 2);
  else
    return (a * power((a * a) % 1000000007, b / 2)) % 1000000007;
}
int main() {
  ios_base::sync_with_stdio(false);
  long long k, i, x, ans = 0;
  string s;
  cin >> s >> k;
  x = ((power(2, s.length() * k) - 1) *
       power(power(2, s.length()) - 1, 1000000007 - 2)) %
      1000000007;
  for (i = 0; i < s.length(); i++) {
    if (s[i] == '5' || s[i] == '0') {
      ans += (power(2, i) * x) % 1000000007;
      ans %= 1000000007;
    }
  }
  cout << ans << "\n";
  return 0;
}
