#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1501;
int p1[N], p2[N], h1[N], h2[N];
int isGood[26];
void hashFunction(string& s, int p[], int h[], int b, int m) {
  int len = s.length();
  p[0] = 1;
  for (int i = 1; i < len; i++) {
    p[i] = (1LL * p[i - 1] * b) % m;
  }
  h[0] = s[0] - 'a' + 1;
  for (int i = 1; i < len; i++) {
    h[i] = ((1LL * h[i - 1] * b) % m + (s[i] - 'a' + 1)) % m;
  }
}
int subHash(int p[], int h[], int l, int r, int m) {
  int res = h[r];
  if (l > 0) {
    res = (res - (1LL * h[l - 1] * p[r - l + 1]) % m + m) % m;
  }
  return res;
}
int main() {
  string s;
  cin >> s;
  int n = s.length();
  string temp;
  cin >> temp;
  for (int i = 0; i < 26; i++) {
    isGood[i] = temp[i] - '0';
  }
  int k;
  cin >> k;
  vector<int> preSum(n);
  preSum[0] = isGood[s[0] - 'a'];
  for (int i = 1; i < n; i++) {
    preSum[i] = preSum[i - 1] + isGood[s[i] - 'a'];
  }
  hashFunction(s, p1, h1, 29, 1e9 + 7);
  hashFunction(s, p2, h2, 31, 1e9 + 9);
  set<pair<int, int> > st;
  for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
      int good = preSum[j];
      if (i > 0) {
        good -= preSum[i - 1];
      }
      int bad = (j - i + 1) - good;
      if (bad <= k) {
        int res1 = subHash(p1, h1, i, j, 1e9 + 7);
        int res2 = subHash(p2, h2, i, j, 1e9 + 9);
        st.insert({res1, res2});
      }
    }
  }
  printf("%d", st.size());
  return 0;
}
