#include <bits/stdc++.h>
using namespace std;
const int MOD(1000000007);
const int INF((1 << 30) - 1);
const int MAXN(2002);
string s[MAXN];
int main() {
  string a, b;
  cin >> a >> b;
  int k;
  cin >> k;
  for (int i = 0; i < a.size(); i++) s[i] = a.substr(i, a.size() - i);
  sort(s, s + a.size());
  int ans = 0, cnt = 0;
  for (int j = 0; j < s[0].size(); j++) {
    if (b[s[0][j] - 'a'] == '0') cnt++;
    if (cnt <= k) ans++;
  }
  for (int i = 1; i <= a.size() - 1; i++) {
    cnt = 0;
    int j = 0;
    while (j < s[i].size() && j < s[i - 1].size() && s[i][j] == s[i - 1][j]) {
      if (b[s[i][j] - 'a'] == '0') cnt++;
      j++;
    }
    while (j < s[i].size()) {
      if (b[s[i][j] - 'a'] == '0') cnt++;
      if (cnt <= k) ans++;
      j++;
    }
  }
  cout << ans;
}
