#include <bits/stdc++.h>
using namespace std;
int const MOD = 1000000007;
char str[100005];
long long mult(long long a, int n, long long MOD) {
  long long s = 1;
  while (n) {
    if (n & 1) s = s * a % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return s;
}
void exGcd(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    x = 1;
    y = 1;
    return;
  }
  exGcd(b, a % b, y, x);
  y -= a / b * x;
}
int main() {
  int n;
  while (scanf("%s", str) != EOF) {
    scanf("%d", &n);
    long long exp = 1;
    long long t = mult(2, strlen(str), MOD);
    long long sum = 0;
    long long s, x, y;
    exGcd(t - 1, MOD, y, x);
    for (int i = 0; str[i]; i++) {
      if (str[i] == '0' || str[i] == '5') {
        s = (mult(t, n, MOD) - 1) * y % MOD;
        s = s * exp % MOD;
        sum = (sum + s) % MOD;
      }
      exp *= 2;
      while (exp >= MOD) exp -= MOD;
    }
    cout << (sum + MOD) % MOD << endl;
  }
  return 0;
}
