#include <bits/stdc++.h>
using namespace std;
int ans, K, a[1666], good[33];
int tree[2000000][26];
int main() {
  string s, t;
  cin >> s >> t >> K;
  for (int i = 0; i < s.size(); i++) a[i] = s[i] - 'a';
  for (int i = 0; i < t.size(); i++) good[i] = t[i] - '0';
  for (int i = 0; i < s.size(); i++) {
    int rt = 0, cnt = 0;
    for (int j = i; j < s.size(); j++) {
      if (good[a[j]] == 0 && ++cnt > K) break;
      if (tree[rt][a[j]] == 0)
        rt = tree[rt][a[j]] = ++ans;
      else
        rt = tree[rt][a[j]];
    }
  }
  cout << ans << endl;
  return 0;
}
