#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  string v;
  int k;
  cin >> s >> v >> k;
  int n = s.length();
  set<long long> st;
  int L = 0, R = 0;
  int baaaaadsum = 0;
  long long h = 0, p1 = 10007, p2 = 1e16l + 371l;
  while (L < n) {
    R = L;
    h = 0;
    baaaaadsum = 0;
    while (R < n) {
      baaaaadsum += (v[s[R] - 'a'] == '0');
      h *= p1;
      h %= p2;
      h += s[R] - 'a' + 1;
      if (baaaaadsum <= k) {
        st.insert(h);
      } else {
        break;
      }
      R++;
    }
    L++;
  }
  cout << st.size() << endl;
}
