#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const double EPS = 1e-9;
const double PI = acos(-1.);
char s[1600];
char buff[150];
bool bad[150];
set<pair<long long, long long> > hashes;
long long p1, p2, M1;
int main() {
  p1 = 909091;
  p2 = 1000007;
  M1 = 1000000131;
  scanf("%s\n%s", s, buff);
  for (int i = 0; i < 26; ++i)
    if (buff[i] == '0') bad[i + 'a'] = true;
  int K;
  scanf("%d", &K);
  int len = strlen(s);
  for (int i = 0; i < len; ++i) {
    int cnt = 0;
    long long h1, h2;
    h1 = h2 = 0;
    for (int j = i; j < len; ++j) {
      if (bad[s[j]]) ++cnt;
      if (cnt > K) break;
      h1 = (h1 * p1 + s[j]) % M1;
      h2 = h2 * p2 + s[j];
      hashes.insert(pair<long long, long long>(h1, h2));
    }
  }
  printf("%d\n", hashes.size());
  return 0;
}
