#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:512000000")
template <class T>
T sqr(T a) {
  return a * a;
}
int main() {
  string s, bad;
  int k;
  cin >> s >> bad >> k;
  int n = s.length();
  vector<pair<long long, long long> > v;
  long long pr1 = 13, pr2 = 1103;
  for (int i = 0; i < n; ++i) {
    int curk = 0;
    long long h1 = 0, h2 = 0;
    for (int j = i; j < n; ++j) {
      if (bad[s[j] - 'a'] == '0') ++curk;
      if (curk > k) break;
      h1 = h1 * pr1 + s[j];
      h2 = h2 * pr2 + s[j];
      v.push_back(make_pair(h1, h2));
    }
  }
  sort((v).begin(), (v).end());
  v.erase(unique((v).begin(), (v).end()), v.end());
  cout << (int)(v).size() << endl;
  return 0;
}
