#include <bits/stdc++.h>
using namespace std;
using vl = vector<long long>;
using pl = pair<long long, long long>;
using ll = long long int;
using vb = vector<bool>;
using vs = vector<string>;
using vvl = vector<vector<ll>>;
void read(vector<ll> &v, ll &n) {
  for (ll i = 0; i < n; ++i) cin >> v[i];
}
void write(vl &v) {
  for (ll i = 0; i < v.size(); ++i) cout << v[i] << " ";
  cout << endl;
}
void print() { cout << endl; }
void solve() {
  string s1, s2;
  cin >> s1 >> s2;
  ll badlim, badcnt, n = s1.size(), p = 31, curr, q, res = 0, curr2,
                     mod = 1e9 + 7, mod2 = 1e9 + 9;
  cin >> badlim;
  unordered_set<ll> st, st2;
  for (int i = 0; i < n; i++) {
    curr = curr2 = badcnt = 0;
    p = q = 1;
    for (int j = i; j < n; j++) {
      if (s2[int(s1[j] - 'a')] == '0') ++badcnt;
      if (badcnt > badlim) break;
      curr = (curr + (ll(s1[j] - 'a' + 1) * p)) % mod;
      curr2 = (curr2 + (ll(s1[j]) * q)) % mod2;
      if (st.find(curr) == st.end() || st2.find(curr2) == st2.end()) ++res;
      st.insert(curr);
      st2.insert(curr2);
      p = (p * 31) % mod;
      q = (q * 131) % mod2;
    }
  }
  cout << res << endl;
  return;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ;
  solve();
  return 0;
}
