#include <bits/stdc++.h>
using namespace std;
map<long long int, int> mp;
int main() {
  string s, t;
  int n;
  cin >> s >> t >> n;
  for (int i = 0; i < s.length(); i++) {
    long long int hash_val = 0;
    int cnt = 0;
    for (int j = i; j < s.length(); j++) {
      if (t[s[j] - 'a'] == '0') cnt++;
      if (cnt > n) break;
      hash_val = hash_val * 29 + (long long int)(s[j] - 'a' + 1);
      mp[hash_val] = 1;
    }
  }
  cout << mp.size() << endl;
}
