#include <bits/stdc++.h>
using namespace std;
long long int square(long long int x, int n) {
  if (n == 0)
    return 1;
  else if (n == 1)
    return x;
  else if (n % 2 == 0)
    return square((x * x) % 1000000007, (n / 2));
  else
    return (x * square((x * x) % 1000000007, ((n - 1) / 2))) % 1000000007;
}
long long int fast_pow(long long base, long long n, long long M) {
  if (n == 0) return 1;
  if (n == 1) return base;
  long long halfn = fast_pow(base, n / 2, M);
  if (n % 2 == 0)
    return (halfn * halfn) % M;
  else
    return (((halfn * halfn) % M) * base) % M;
}
long long int findMMI_fermat(long long int n, long long int M) {
  return fast_pow(n, M - 2, M);
}
int main() {
  string a;
  cin >> a;
  long long int k, len, i, count = 0, p, x, y;
  cin >> k;
  len = a.length();
  p = square(2, len);
  for (i = 0; i < len; i++) {
    if ((a[i] == '0') || (a[i] == '5')) {
      y = (square(2, i) * (square(p, k) - 1)) % 1000000007;
      x = findMMI_fermat((p - 1), 1000000007);
      x = (x * y) % 1000000007;
      count = (count + x) % 1000000007;
    }
  }
  cout << count;
  return 0;
}
