#include <bits/stdc++.h>
const int maxn = 1e5 + 5;
using namespace std;
int k, ans;
char a[maxn];
int A[maxn];
int powmod(int a, long long b) {
  int tmp = 1;
  while (b) {
    if (b & 1) tmp = (long long)tmp * a % 1000000007;
    a = (long long)a * a % 1000000007;
    b >>= 1;
  }
  return tmp;
}
int main() {
  while (cin >> a >> k) {
    int len = strlen(a), ans = 0;
    int j = 0;
    for (int i = 0; i < len; i++)
      if (a[i] == '5' || a[i] == '0') A[j++] = i;
    int a1 = 0;
    for (int i = 0; i < j; i++) {
      a1 = (long long)(a1 + powmod(2, A[i])) % 1000000007;
    }
    int Q2 = powmod(2, len);
    int Q1 = (powmod(Q2, k) - 1 + 1000000007) % 1000000007;
    Q2 = (Q2 - 1 + 1000000007) % 1000000007;
    Q1 = (long long)Q1 * powmod(Q2, 1000000007 - 2) % 1000000007;
    ans = (long long)a1 * Q1 % 1000000007;
    cout << ans << endl;
  }
  return 0;
}
