#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const long long MOD = 1000000007;
char str[N];
int r[N];
long long quick_mod(long long a, long long b) {
  long long ans = 1;
  a %= MOD;
  while (b) {
    if (b & 1) {
      ans = ans * a % MOD;
      b--;
    }
    b >>= 1;
    a = a * a % MOD;
  }
  return ans;
}
int main() {
  long long K;
  int i, j, k;
  while (cin >> str >> K) {
    k = 0;
    int len = strlen(str);
    for (i = 0; i < len; i++) {
      if (str[i] == '0' || str[i] == '5') r[k++] = i;
    }
    long long ans = 0;
    long long temp, temp2;
    for (i = 0; i < k; i++) {
      temp = quick_mod(2, r[i]) * (quick_mod(2, K * len) - 1) % MOD;
      temp2 = quick_mod(2, len) - 1;
      temp2 = quick_mod(temp2, MOD - 2);
      ans += temp * temp2 % MOD;
      ans %= MOD;
    }
    cout << ans << endl;
  }
  return 0;
}
