#include <bits/stdc++.h>
using namespace std;
const int N = 1507;
const long long p = 31;
const long long m = 122749283;
const long long m2 = 459059071;
vector<long long> p_pow(N);
vector<long long> inv_pow(N);
vector<long long> h(N + 1, 0LL);
vector<long long> p_pow2(N);
vector<long long> inv_pow2(N);
vector<long long> h2(N + 1, 0LL);
long long ppow(long long a, long long b, long long x) {
  if (b == 0) return 1LL;
  if (b == 1) return a;
  return ppow(a * a % x, b / 2, x) * (b % 2 ? a : 1LL) % x;
}
long long inv(long long var, long long x) { return ppow(var, x - 2, x) % x; }
void stringHashing(string const& s) {
  int n = s.size();
  inv_pow[0] = p_pow[0] = 1LL;
  inv_pow2[0] = p_pow2[0] = 1LL;
  long long pinv = inv(p, m);
  long long pinv2 = inv(p, m2);
  for (int i = 1; i < n; i++) {
    p_pow[i] = (p_pow[i - 1] * p) % m;
    inv_pow[i] = (inv_pow[i - 1] * pinv) % m;
  }
  for (int i = 0; i < n; i++)
    h[i + 1] = (h[i] + (s[i] - 'a' + 1) * p_pow[i]) % m;
  for (int i = 1; i < n; i++) {
    p_pow2[i] = (p_pow2[i - 1] * p) % m2;
    inv_pow2[i] = (inv_pow2[i - 1] * pinv2) % m2;
  }
  for (int i = 0; i < n; i++)
    h2[i + 1] = (h2[i] + (s[i] - 'a' + 1) * p_pow2[i]) % m2;
}
void solve() {
  string s;
  cin >> s;
  stringHashing(s);
  map<int, bool> binary;
  for (char foo = 'a', x; foo <= 'z'; ++foo) {
    cin >> x;
    binary[foo - 'a'] = x - '0';
  }
  int n = (long long)s.size(), k;
  cin >> k;
  int ans = 0;
  map<pair<int, int>, bool> visited;
  for (int l = 1; l <= n; l++) {
    int current = 0;
    for (int i = 0; i <= n - l; i++) {
      long long xp = (h[i + l] + m - h[l - 1]) % m;
      xp = (xp * inv_pow[l - 1]) % m;
      long long xp2 = (h2[i + l] + m2 - h2[l - 1]) % m2;
      xp2 = (xp2 * inv_pow2[l - 1]) % m2;
      if (!binary[s[l + i - 1] - 'a']) {
        current++;
      }
      if (current <= k && !visited[{xp, xp2}]) {
        ans++;
        visited[{xp, xp2}] = 1;
      }
    }
  }
  cout << ans << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(20);
  int t = 1;
  while (t--) solve();
  return 0;
}
