#include <bits/stdc++.h>
double const EPS = 3e-8;
using namespace std;
template <class T>
T gcd(T a, T b) {
  return (b != 0 ? gcd<T>(b, a % b) : a);
}
template <class T>
T lcm(T a, T b) {
  return (a / gcd<T>(a, b) * b);
}
template <class T>
inline bool read(T &x) {
  int c = getchar();
  int sgn = 1;
  while (~c && c < '0' || c > '9') {
    if (c == '-') sgn = -1;
    c = getchar();
  }
  for (x = 0; ~c && '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0';
  x *= sgn;
  return ~c;
}
string inp;
int Add[150];
set<long long> Ans[1505];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> inp;
  int i;
  char c;
  for (i = 'a'; i <= 'z'; i++) {
    cin >> c;
    Add[i] = c - '0';
  }
  long long Now, tot, mx;
  cin >> mx;
  for (int i = 0; i < inp.size(); i++) {
    Now = 0;
    tot = 0;
    for (int j = i; j < inp.size(); j++) {
      tot += !Add[inp[j]];
      if (tot > mx) break;
      Now = (Now * 117) + inp[j];
      Ans[j - i + 1].insert(Now);
    }
  }
  long long Res = 0;
  for (int i = 1; i <= 1500; i++) Res += Ans[i].size();
  cout << Res << endl;
  return 0;
}
