#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
int dx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int dy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
void solve() {
  string second, mask;
  int k;
  cin >> second >> mask >> k;
  set<ll> sm;
  ll p = 31, m = 1e16 + 9;
  int ans = 0;
  for (int i = 0; i < second.length(); i++) {
    ll h = 0;
    int cnt = 0;
    for (int j = i; j < second.length(); j++) {
      if (mask[second[j] - 'a'] == '0') cnt++;
      h = ((h * p) % m + second[j]) % m;
      if (cnt <= k) {
        if (sm.count(h) == 0) {
          sm.insert(h);
          ans++;
        }
      }
    }
  }
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll t = 1;
  while (t--) {
    solve();
  }
}
