#include <bits/stdc++.h>
using namespace std;
template <typename T>
using V = vector<T>;
const int INF = 1e9 + 5;
const int maxn = 1500 * 1500;
string a, bad;
int n, k, res = 0;
int tot = 0, nxt[maxn][26];
void add(int start) {
  int cur = 0;
  for (int i = start; i < n; i++) {
    if (!nxt[cur][a[i] - 'a']) nxt[cur][a[i] - 'a'] = ++tot;
    cur = nxt[cur][a[i] - 'a'];
  }
}
void dfs(int node, int tot) {
  for (int i = 0; i < (int)(26); ++i)
    if (nxt[node][i]) {
      int tmp = tot + (bad[i] == '0' ? 1 : 0);
      if (tmp <= k) res++, dfs(nxt[node][i], tmp);
    }
}
int main() {
  for (int i = 0; i < (int)(maxn); ++i)
    for (int j = 0; j < (int)(26); ++j) nxt[i][j] = 0;
  cin >> a >> bad >> k;
  n = (int)a.size();
  for (int i = 0; i < (int)a.size(); i++) add(i);
  dfs(0, 0);
  cout << res;
}
