#include <bits/stdc++.h>
using namespace std;
int n, k;
long long val = 0, ml;
long long total = 0;
long long pow(long long a, long long b, long long MOD) {
  long long x = 1, y = a;
  while (b > 0) {
    if (b % 2 == 1) {
      x = (x * y);
      if (x > MOD) x %= MOD;
    }
    y = (y * y);
    if (y > MOD) y %= MOD;
    b /= 2;
  }
  return x;
}
long long modInverse(long long a, long long m) { return pow(a, m - 2, m); }
long long ret = 1;
long long pw(int v) {
  if (v == 1) {
    return 2;
  }
  if (v == 0) {
    return 1;
  }
  if (v % 2 == 0) {
    ret = pw(v / 2);
    ret = ret * ret;
    ret = ret % 1000000007;
    return ret;
  } else {
    ret = pw(v / 2);
    ret = ret * ret;
    ret = ret % 1000000007;
    ret = ret * 2;
    ret = ret % 1000000007;
    return ret;
  }
}
void calc(int i) {
  long long ty;
  ty = pw(i);
  ty = ty * ml;
  ty = ty % 1000000007;
  total = total + ty;
  total %= 1000000007;
}
int main() {
  int i, j, f;
  char s[100100];
  cin >> s;
  cin >> k;
  n = strlen(s);
  int m = n;
  long long a = pw(m);
  long long inv =
      pow((pw(m) - 1 + 1000000007) % 1000000007, 1000000007 - 2, 1000000007);
  long long ans =
      ((pow(a, k, 1000000007) - 1) * inv % 1000000007 + 1000000007) %
      1000000007;
  ml = ans;
  for (i = 0; s[i] != '\0'; i++) {
    if (s[i] == '0' || s[i] == '5') {
      calc(i);
    }
  }
  cout << total << "\n";
  cin >> i;
  return 0;
}
