#include <bits/stdc++.h>
using namespace std;
const long long mod = 4611686018427387847ll;
int in() {
  int a;
  scanf("%d", &a);
  return a;
}
long long mul(long long a, long long b, long long m) {
  long long k = (long long)((long double)a * b / m);
  long long r = a * b - m * k;
  while (r < 0) r += m;
  while (r >= m) r -= m;
  return r;
}
vector<long long> ha, po;
const int INF = ~(1 << 31);
int main() {
  string s;
  cin >> s;
  string p;
  cin >> p;
  int k = in();
  set<char> ap;
  for (int i = 0; i < p.size(); ++i) {
    if (p[i] == '0') ap.insert('a' + i);
  }
  vector<int> pr(s.size() + 1, 0);
  for (int i = 0; i < s.size(); ++i) {
    pr[i + 1] = pr[i];
    if (ap.count(s[i]) > 0) {
      pr[i + 1]++;
    }
  }
  long long pp = 31;
  po.push_back(1);
  for (int i = 0; i < s.size() + 2; ++i) po.push_back(mul(po.back(), pp, mod));
  ha.push_back(0);
  for (int i = 0; i < s.size(); ++i)
    ha.push_back((ha.back() + mul((s[i] + 1 - 'a'), po[i], mod)) % mod);
  int ans = 0;
  for (int i = 1; i <= s.size(); ++i) {
    set<long long> res;
    for (int j = 0; j + i <= s.size(); ++j) {
      long long h = mul((ha[j + i] - ha[j] + mod), po[s.size() - j + 2], mod);
      if (pr[j + i] - pr[j] <= k) res.insert(h);
    }
    ans += res.size();
  }
  cout << ans << endl;
  return 0;
}
