#include <bits/stdc++.h>
using namespace std;
long long p1[1005000], p2[1005000], h1[1005000], h2[1005000], n;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s, c;
  long long k;
  map<long long, long long> m;
  cin >> s >> c >> k;
  s = " " + s;
  n = s.size() + 1;
  for (int i = 1; i < s.size(); i++) {
    m[i] = m[i - 1];
    if (c[s[i] - 'a'] == '0') m[i]++;
  }
  p1[0] = p2[0] = 1;
  for (int i = 1; i <= s.size() + 10; i++) {
    p1[i] = p1[i - 1] * 31 % 1000000007;
    p2[i] = p2[i - 1] * 4096 % 998244353;
  }
  for (int i = 1; i < s.size(); i++) {
    h1[i] = (h1[i - 1] + (s[i] - 'a' + 1) * p1[i] % 1000000007) % 1000000007;
    h2[i] = (h2[i - 1] + (s[i] - 'a' + 1) * p2[i] % 998244353) % 998244353;
  }
  set<pair<long long, long long> > ans;
  for (int i = 1; i < s.size(); i++)
    for (int j = i; j < s.size(); j++)
      if (m[j] - m[i - 1] <= k) {
        long long x = (h1[j] - h1[i - 1] + 1000000007) % 1000000007 *
                      p1[n - i] % 1000000007;
        long long y =
            (h2[j] - h2[i - 1] + 998244353) % 998244353 * p2[n - i] % 998244353;
        ans.insert({x, y});
      }
  cout << ans.size();
  return 0;
}
