#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
long long quick_mod(long long a, long long b, long long m) {
  long long ans = 1;
  while (b) {
    if (b & 1) {
      ans = (ans * a) % m;
      b--;
    }
    b /= 2;
    a = a * a % m;
  }
  return ans;
}
int main() {
  char s[111111];
  int n, k;
  long long ans, q;
  while (cin >> s >> k) {
    ans = 0;
    n = strlen(s);
    q = quick_mod(2, n, MOD);
    for (int i = 0; i < n; i++) {
      if (s[i] == '0' || s[i] == '5') {
        ans += quick_mod(2, i, MOD) % MOD;
        ans %= MOD;
      }
    }
    ans = ans * (quick_mod(q, k, MOD) - 1 + MOD) % MOD *
          quick_mod(q - 1, MOD - 2, MOD) % MOD;
    cout << ans << endl;
  }
  return 0;
}
