#include <bits/stdc++.h>
using namespace std;
const int MODE = 1000000007;
const int maxn = 100100;
long long power(long long a, long long n) {
  long long b = 1;
  while (n) {
    if (n & 1) {
      b *= a;
      b %= MODE;
    }
    n >>= 1;
    a *= a;
    a %= MODE;
  }
  return b;
}
long long k, ans, cur;
string num;
int main() {
  cin >> num >> k;
  for (int i = 0; i < num.length(); i++) {
    if (num[i] == '0' || num[i] == '5') {
      ans += power(2, i);
      ans %= MODE;
    }
  }
  cur += power(power(2, num.length()) - 1, MODE - 2) *
         (power(2, num.length() * k) - 1);
  cur %= MODE;
  ans *= cur;
  ans %= MODE;
  cout << ans;
}
