#include <bits/stdc++.h>
template <class T>
inline T bigmod(T p, T e, T M) {
  long long int ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return (T)ret;
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T modinverse(T a, T M) {
  return bigmod(a, M - 2, M);
}
template <typename T>
T nCr(T n, T r) {
  if (r > n - r) r = n - r;
  int ans = 1, i;
  for (i = 1; i <= r; i++) {
    ans *= n - r + i;
    ans /= i;
  }
  return ans;
}
using namespace std;
bool value[27];
struct node {
  node* next[26 + 1];
  node() {
    for (int i = 0; i < 26; i++) next[i] = NULL;
  }
} * root;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(0);
  int testCase = 1;
  for (int t = 1; t <= testCase; t++) {
    string s, ch;
    cin >> s >> ch;
    int k;
    cin >> k;
    for (int i = 0; i < ch.size(); i++) {
      if (ch[i] == '0')
        value[i] = false;
      else
        value[i] = true;
    }
    root = new node();
    long long int res = 0;
    for (int i = 0; i < s.size(); i++) {
      node* curr = root;
      int cnt = 0;
      for (int j = i; j <= s.size() - 1; j++) {
        int id = s[j] - 'a';
        if (value[id] == false) cnt++;
        if (cnt > k) break;
        if (curr->next[id] == NULL) {
          curr->next[id] = new node();
          res++;
        }
        curr = curr->next[id];
      }
    }
    cout << res << endl;
  }
}
