#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 23;
const int MOD = 1e8;
const int N = 1500 + 100;
struct node {
  int nxt[26];
  bool en;
};
struct trie {
  int sz;
  node arr[N * N];
  trie() { sz = 0; };
  void add(const string &s) {
    int p = 0;
    for (int i = 0; i < (((int)(s).size())); ++i) {
      int c = s[i] - 'a';
      if (arr[p].nxt[c] == 0) {
        arr[p].nxt[c] = ++sz;
      }
      p = arr[p].nxt[c];
    }
    arr[p].en = true;
  }
  int mv(int p, int c) { return arr[p].nxt[c]; }
} tr;
bool mark[N * N];
int main() {
  ios_base::sync_with_stdio(0);
  string s, good;
  int k;
  cin >> s >> good >> k;
  for (int i = 0; i < (((int)(s).size())); ++i) {
    tr.add(s.substr(i));
  }
  for (int i = 0; i < (((int)(s).size())); ++i) {
    int nrk = 0;
    int p = 0;
    for (int j = (i); j < (((int)(s).size())); ++j) {
      int c = s[j] - 'a';
      nrk += good[c] == '0';
      if (nrk > k) break;
      p = tr.mv(p, c);
      mark[p] = true;
    }
  }
  int ans = 0;
  ans = accumulate(mark, mark + N * N, ans,
                   [](int &ans, bool v) { return ans += v; });
  cout << ans << "\n";
  return 0;
}
