#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;
char str[maxn];
long long qp(long long a, long long b) {
  long long ret = 1;
  while (b) {
    if (b & 1) ret = ret * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return ret;
}
long long inv(long long a) { return qp(a, mod - 2); }
void solve(long long);
int main() {
  scanf("%s", str);
  long long k;
  cin >> k;
  solve(k);
  return 0;
}
void solve(long long k) {
  long long n = (long long)strlen(str);
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    if (str[i] == '0' || str[i] == '5') {
      long long tmp = (qp(2, n * k + i) - qp(2, i) + mod) % mod;
      tmp = tmp * inv(qp(2, n) - 1) % mod;
      ans = (ans + tmp) % mod;
      while (ans < 0) ans += mod;
    }
  }
  cout << ans << endl;
  return;
}
