#include <bits/stdc++.h>
using namespace std;
string a;
long long n;
long long const MOD = 1000000007;
long long power(long long a, long long b) {
  long long k = 1;
  for (; b; b >>= 1, a = a * a % MOD)
    if (b & 1) k = (k * a) % MOD;
  return k;
}
int main() {
  long long base = 0, bi = 0;
  cin >> a;
  cin >> n;
  for (int i = 0; i < a.size(); i++)
    if (a[i] == '5' || a[i] == '0') base = (base + power(2, i)) % MOD;
  long long base1 = (power(2, a.size()) - 1 + MOD) % MOD;
  base1 = power(base1, MOD - 2);
  bi = ((power(2, (n * a.size())) - 1 + MOD) % MOD) * (base1 % MOD) % MOD;
  cout << (bi * base) % MOD << endl;
  return 0;
}
