#include <bits/stdc++.h>
using namespace std;
const long long BASE = 29;
const long long MOD = 10000000000000000LL;
map<long long, bool> m;
long long base[2000];
string s, good;
int main() {
  int k;
  cin >> s >> good >> k;
  int len = s.length();
  base[0] = 1;
  for (int i = 1; i <= len; i++) base[i] = (base[i - 1] * BASE) % MOD;
  for (int i = 0; i < len; i++) {
    long long hash = 0;
    int cnt = 0;
    for (int j = i; j < len; j++) {
      cnt += good[s[j] - 'a'] == '0';
      if (cnt > k) break;
      hash = (hash + (long long)(s[j] - 'a' + 1) * base[j - i]) % MOD;
      m[hash] = true;
    }
  }
  cout << m.size() << endl;
  return 0;
}
