#include <bits/stdc++.h>
using namespace std;
long long p = 37;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  string A;
  cin >> A;
  string B;
  cin >> B;
  vector<bool> bad(B.size());
  for (int i = 0; i < B.size(); i++) {
    bad[i] = !(bool)(B[i] - '0');
  }
  long long k;
  cin >> k;
  vector<long long> cuantos(A.size() + 1, 0);
  for (int i = 1; i < cuantos.size(); i++) {
    cuantos[i] = cuantos[i - 1] + (long long)(bad[A[i - 1] - 'a']);
  }
  long long ans = 0;
  vector<long long> hashing(cuantos.size(), 0);
  for (int i = hashing.size() - 1; i >= 0; i--) {
    hashing[i] = A[i - 1] * p;
    if (i < hashing.size() - 1) {
      hashing[i] += (hashing[i + 1] * p);
    }
  }
  map<long long, int> mapa;
  vector<long long> po(cuantos.size() + 1, 1);
  for (int i = 1; i < po.size(); i++) po[i] = po[i - 1] * p;
  for (int i = 0; i < A.size(); i++) {
    for (int j = i; j < A.size(); j++) {
      long long tengo = cuantos[j + 1] - cuantos[i];
      if (tengo <= k) {
        long long hashi = hashing[i + 1];
        if (j + 2 < hashing.size()) hashi -= (hashing[j + 2] * po[j - i + 1]);
        if (mapa[hashi] == 0) {
          mapa[hashi] = 1;
          ans++;
        }
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
