#include <bits/stdc++.h>
using namespace std;
const unsigned long long b = 1000 * 1000 * 1000 + 7;
int main() {
  ios_base::sync_with_stdio(0);
  string s, x;
  int k;
  while (cin >> s >> x >> k) {
    int bad[128] = {0};
    for (int i = 0; i < 26; ++i) bad['a' + i] = '1' - x[i];
    vector<unsigned long long> v;
    unsigned long long t = 1;
    for (int len = 1; len <= s.size(); ++len) {
      unsigned long long h = 0;
      int c = 0;
      t *= b;
      for (int i = 0; i < len; ++i) {
        h = h * b + s[i];
        c += bad[s[i]];
      }
      if (c <= k) v.push_back(h);
      for (int i = len, j = 0; j + len < s.size(); ++i, ++j) {
        h = h * b + s[i] - t * s[j];
        c = c - bad[s[j]] + bad[s[i]];
        if (c <= k) v.push_back(h);
      }
    }
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    cout << v.size() << endl;
  }
  return 0;
}
