#include <bits/stdc++.h>
using namespace std;
const int MAX = 100010;
long long quick_Mod(long long n) {
  long long ans = 1;
  long long x = 2;
  while (n) {
    if (n & 1) ans = ans * x % 1000000007;
    n = n >> 1;
    x = x * x % 1000000007;
  }
  return ans;
}
void ex_gcd(long long a, long long b, long long &gcd, long long &x,
            long long &y) {
  if (b == 0) {
    gcd = a;
    y = 0;
    x = 1;
    return;
  } else {
    ex_gcd(b, a % b, gcd, y, x);
    y -= x * (a / b);
  }
}
long long inverse(long long a) {
  long long gcd, x, y;
  ex_gcd(a, 1000000007, gcd, x, y);
  if (gcd == 1)
    return (x % 1000000007 + 1000000007) % 1000000007;
  else
    return -1;
}
int main() {
  char s[MAX];
  long long k;
  scanf("%s", s);
  scanf("%I64d", &k);
  long long len = strlen(s);
  long long ans = 0;
  for (int i = 0; i < len; i++) {
    if (s[i] == '0' || s[i] == '5') {
      ans += quick_Mod(i) * inverse(quick_Mod(len) - 1) % 1000000007 *
             (quick_Mod(k * len) - 1) % 1000000007;
    }
  }
  printf("%I64d\n", (ans % 1000000007 + 1000000007) % 1000000007);
  return 0;
}
