#include <bits/stdc++.h>
using namespace std;
int mult(long long x) {
  int q = 2;
  int r = 1;
  while (x > 0) {
    if (x & 1) {
      r = (r * 1ll * q) % 1000000007;
      x--;
    } else {
      q = (q * 1ll * q) % 1000000007;
      x = (x >> 1);
    }
  }
  return r;
}
int sum(int k, int l) {
  if (1 == k) return 1;
  if (k & 1) {
    k--;
    return (sum(k, l) + mult(k * 1ll * l)) % 1000000007;
  }
  return (sum(k / 2, l) * 1ll * (1 + mult((k / 2) * 1ll * l))) % 1000000007;
}
int main() {
  string a;
  int k, i;
  cin >> a;
  cin >> k;
  int r = 0;
  for (i = 0; i < a.length(); i++) {
    if (a[i] == '0' || a[i] == '5') r = (r + mult(i)) % 1000000007;
  }
  int buf = sum(k, a.length());
  r = (r * 1ll * buf) % 1000000007;
  cout << r << endl;
  return 0;
}
