#include <bits/stdc++.h>
using namespace std;
long long mpow(long long x, long long n) {
  long long ret = 1;
  while (n) {
    if (n % 2) ret *= x, ret %= 1000000007;
    x *= x;
    x %= 1000000007;
    n /= 2;
  }
  return ret;
}
int main() {
  long long n, i, ret = 0, po, ans, k;
  char c[200000];
  scanf("%s", c);
  n = strlen(c);
  cin >> k;
  po = 1;
  for (i = 0; i < n; i++) {
    if (c[i] == '0' || c[i] == '5') ret += po, ret %= 1000000007;
    po <<= 1, po %= 1000000007;
  }
  po = mpow(2, n);
  ans = (mpow(po, k) - 1 + 1000000007) % 1000000007;
  ans *= mpow((po - 1 + 1000000007) % 1000000007, 1000000007 - 2);
  ans %= 1000000007;
  ans *= ret;
  ans %= 1000000007;
  cout << ans;
}
