#include <bits/stdc++.h>
using namespace std;
typedef struct x {
  struct x* ptr[26];
} node;
const long long lt = 100005;
long long mod = 1000000007;
long long k;
string num, s;
node* nnode() {
  node* tmp = (node*)malloc(sizeof(node));
  long long i;
  for (i = 0; i < 26; i++) tmp->ptr[i] = NULL;
  return tmp;
}
long long val(char c) { return (long long)c - (long long)'a'; }
node* insert(node* root) {
  long long i;
  for (i = 0; i < (long long)(s).size(); i++) {
    node* tmp = root;
    long long j;
    for (j = i; j < (long long)(s).size(); j++) {
      long long x = val(s[j]);
      if (tmp->ptr[x] == NULL) tmp->ptr[x] = nnode();
      tmp = tmp->ptr[x];
    }
  }
  return root;
}
long long calc(node* root, long long b) {
  long long i;
  long long anss = 0;
  for (i = 0; i < 26; i++) {
    if (root->ptr[i] != NULL) {
      if (num[i] == '0') b++;
      if (b <= k) {
        anss++;
        anss += calc(root->ptr[i], b);
      }
      if (num[i] == '0') b--;
    }
  }
  return anss;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> s >> num;
  cin >> k;
  node* root = nnode();
  root = insert(root);
  long long ans = calc(root, 0);
  cout << ans << endl;
  return 0;
}
