#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int qian[1505];
char str[1505];
char tmp[1550];
string ss;
map<string, int> m;
set<long long> s;
char gb[30];
int main() {
  int k, ans = 0;
  scanf("%s", str);
  scanf("%s", gb);
  scanf("%d", &k);
  int ct = 0;
  int len = strlen(str);
  for (int i = 1; i < (len + 1); ++i) {
    if (gb[str[i - 1] - 'a'] == '0')
      qian[i] = qian[i - 1] + 1;
    else {
      qian[i] = qian[i - 1];
    }
  }
  for (int i = 1; i < (len + 1); ++i) {
    long long tmp = 0;
    for (int j = i; j < (len + 1); ++j) {
      if (qian[j] - qian[i - 1] > k) break;
      tmp = tmp * 1000000007 + str[j - 1];
      s.insert(tmp);
    }
  }
  cout << s.size() << endl;
  return 0;
}
