#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
long long a[3000000], c;
int main() {
  string s, v;
  int k, i, j;
  cin >> s >> v >> k;
  int n = s.length();
  for (i = 0; i < n; i++) {
    int kk = k;
    long long h = 0;
    for (j = i; j < n; j++) {
      if (v[s[j] - 97] == '0') {
        kk--;
        if (kk < 0) break;
      }
      h = (h * 131) ^ s[j];
      a[c++] = h;
    }
  }
  sort(a, a + c);
  cout << unique(a, a + c) - a;
}
