#include <bits/stdc++.h>
using namespace std;
long long max(long long a, long long b) {
  if (a > b)
    return a;
  else
    return b;
}
long long min(long long a, long long b) {
  if (a < b)
    return a;
  else
    return b;
}
template <typename... T>
void in(T&... args) {
  ((cin >> args), ...);
}
template <typename... T>
void out(T&&... args) {
  ((cout << args << " "), ...);
}
template <typename... T>
void outl(T&&... args) {
  ((cout << args << '\n'), ...);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  long long n = s.size();
  string freq;
  cin >> freq;
  long long k;
  cin >> k;
  set<pair<long long, long long>> st;
  for (long long i = 0; i < n; i++) {
    long long hash1 = 0;
    long long p1 = 1;
    long long hash2 = 0;
    long long p2 = 1;
    long long bad = 0;
    for (long long j = i; j < n; j++) {
      hash1 = (hash1 + ((s[j] - 'a' + 1) * p1) % (long long)(1e9 + 7)) %
              (long long)(1e9 + 7);
      hash2 = (hash2 + ((s[j] - 'a' + 1) * p2 * p1) % (long long)(1e9 + 7)) %
              (long long)(1e9 + 7);
      p2 = (p2 * 53) % (long long)(1e9 + 7);
      p1 = (p1 * 31) % (long long)(1e9 + 7);
      if (freq[s[j] - 'a'] == '0') bad++;
      if (bad > k) break;
      st.insert({hash1, hash2});
    }
  }
  cout << st.size() << '\n';
  return 0;
}
