#include <bits/stdc++.h>
using namespace std;
bool check[26];
string Q;
int k;
set<long long> ans;
inline void solve() {
  long long s = Q.length();
  for (int i = 0; i < s; ++i) {
    long long counter = 0;
    long long hash = 0;
    for (int j = i; j < s; j++) {
      hash = (hash * 256 + Q[j]) % 34027797218763967;
      if (check[Q[j] - 'a']) ++counter;
      if (counter <= k) ans.insert(hash);
    }
  }
  cout << ans.size() << '\n';
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.precision(10), cout << fixed;
  cin >> Q;
  for (int i = 0; i < 26; ++i) {
    char c;
    cin >> c;
    if (c == '0') check[i] = 1;
  }
  cin >> k;
  solve();
  return 0;
}
