#include <bits/stdc++.h>
using namespace std;
struct Node {
  char c;
  Node* next[26];
  Node() {
    c = '#';
    for (long long i = 0; i < 26; i++) next[i] = NULL;
  }
  Node(char a) {
    c = a;
    for (long long i = 0; i < 26; i++) next[i] = NULL;
  }
  long long getCount() {
    long long ans = 1;
    for (long long i = 0; i < 26; i++) {
      if (next[i] != NULL) ans += next[i]->getCount();
    }
    return ans;
  }
};
int main() {
  int k, n;
  string s, good;
  cin >> s >> good >> k;
  n = s.size();
  Node* head = new Node;
  for (int i = 0; i < n; i++) {
    int badCount = 0;
    Node* curr = head;
    for (int j = i; j < n; j++) {
      badCount += (1 - (good[s[j] - 'a'] - '0'));
      if (badCount > k) break;
      if (curr->next[s[j] - 'a'] == NULL)
        curr->next[s[j] - 'a'] = new Node(s[j]);
      curr = curr->next[s[j] - 'a'];
    }
  }
  long long cnt = head->getCount() - 1;
  cout << cnt << endl;
}
