#include <bits/stdc++.h>
using namespace std;
int a[30];
int po[1550];
pair<unsigned long long, unsigned long long> h[1550];
pair<unsigned long long, unsigned long long> p[1550];
pair<unsigned long long, unsigned long long> b = make_pair(29, 37);
map<pair<unsigned long long, unsigned long long>, bool> to;
pair<unsigned long long, unsigned long long> get(int l, int r) {
  if (l == 0) return h[r];
  return make_pair(h[r].first - h[l - 1].first * p[r - l + 1].first,
                   h[r].second - h[l - 1].second * p[r - l + 1].second);
}
int calc(int l, int r) {
  if (l == 0) return po[r];
  return po[r] - po[l - 1];
}
int main() {
  string s, t;
  cin >> s >> t;
  int k;
  long long ans = 0;
  cin >> k;
  for (int i = 0; i < t.size(); i++)
    if (t[i] == '1') a[i + 1]++;
  for (int i = 0; i < s.size() + 1; i++) {
    if (!a[s[i] - 96])
      po[i + 1] = po[i] + 1;
    else
      po[i + 1] = po[i];
  }
  p[0] = make_pair(1, 1);
  h[0] = make_pair(s[0] - 96, s[0] - 96);
  for (int i = 1; i < s.size(); i++) {
    h[i] = make_pair(h[i - 1].first * b.first + (s[i] - 96),
                     h[i - 1].second * b.second + (s[i] - 96));
    p[i] = make_pair(p[i - 1].first * b.first, p[i - 1].second * b.second);
  }
  for (int l = 1; l <= s.size(); l++) {
    for (int i = 0, j = l - 1; j < s.size(); i++, j++) {
      if (calc(i + 1, j + 1) <= k && !to[get(i, j)]) {
        ans++;
        to[get(i, j)] = true;
      }
    }
  }
  cout << ans;
}
