#include <bits/stdc++.h>
using namespace std;
string s;
char c[26];
int tree[2000005][26];
int sz;
void insert(string &s) {
  int ct = 0;
  int n = s.length();
  for (int i = 0; i < n; i++) {
    if (tree[ct][s[i] - 97] == 0) {
      tree[ct][s[i] - 97] = ++sz;
    }
    ct = tree[ct][s[i] - 97];
  }
}
void dfs(int k, int ct, int n, int &res) {
  int nv, val;
  for (int i = 0; i < 26; i++) {
    nv = n + (c[i] == '0');
    val = tree[ct][i];
    if (nv <= k && val != 0) {
      res++;
      dfs(k, val, nv, res);
    }
  }
}
int main() {
  int k;
  cin >> s;
  scanf("%s", c);
  scanf("%d", &k);
  string t = "";
  int n = s.length();
  for (int i = n - 1; i >= 0; i--) {
    t = s[i] + t;
    insert(t);
  }
  int res = 0;
  dfs(k, 0, 0, res);
  cout << res << endl;
}
