#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vc = vector<char>;
using vvc = vector<vc>;
const ll mod1 = 1e9 + 7, inf = 1e18, mult1 = 91138323, mod2 = 972663749,
         mult2 = 97266353;
int main() {
  string s;
  cin >> s;
  int n = (int)s.size(), k;
  vi a(26);
  vvi dp(n, vi(n));
  for (int i = 0; i < 26; i++) {
    char x;
    cin >> x;
    a[i] = (x == '1' ? 0 : 1);
  }
  cin >> k;
  set<pair<ll, ll>> vals;
  for (int i = 0; i < n; i++) {
    dp[i][i] = a[s[i] - 'a'];
    ll hash_val1 = (ll)s[i], hash_val2 = (ll)s[i];
    if (dp[i][i] <= k) vals.insert({hash_val1, hash_val2});
    for (int j = i + 1; j < n; j++) {
      dp[i][j] = dp[i][j - 1] + a[s[j] - 'a'];
      hash_val1 = ((mult1 * hash_val1) % mod1 + (ll)s[j]) % mod1;
      hash_val2 = ((mult2 * hash_val2) % mod2 + (ll)s[j]) % mod2;
      if (dp[i][j] <= k) vals.insert({hash_val1, hash_val2});
    }
  }
  cout << vals.size();
  return 0;
}
