#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long inf = 1e18 + 7;
const long long N = 1505;
const long long mod1 = 1e9 + 9;
vector<long long> g[N];
void setIO(string second) {
  freopen((second + ".in").c_str(), "r", stdin);
  freopen((second + ".out").c_str(), "w", stdout);
}
template <typename T_vector>
void output_vector(const T_vector &v, bool add_one = false,
                   long long start = -1, long long end = -1) {
  if (start < 0) start = 0;
  if (end < 0) end = v.size();
  for (long long i = start; i < end; i++)
    cout << v[i] + (add_one ? 1 : 0) << (i < end - 1 ? ' ' : '\n');
}
long long power(long long a, long long b, long long m) {
  long long pp = (b == 0) ? 1 : power(a, b >> 1, m);
  pp = (pp * pp) % m;
  if (b & 1) pp = (pp * a) % m;
  return pp;
}
long long pre[N], h[N], pp[N], h1[N], pp1[N];
set<pair<long long, long long> > second;
void solve_test_case() {
  string a, b;
  cin >> a >> b;
  long long n = a.size();
  long long k;
  cin >> k;
  a.insert(a.begin(), '0');
  long long c = 1, c1 = 1;
  pre[0] = h[0] = h1[0] = 0;
  pp[0] = 1;
  pp1[0] = 1;
  for (long long i = 1; i <= n; i++) {
    pre[i] = pre[i - 1] + ('1' - b[a[i] - 'a']);
    h[i] = (h[i - 1] + ((a[i] - 'a' + 1) * c) % mod) % mod;
    h1[i] = (h1[i - 1] + ((a[i] - 'a' + 1) * c1) % mod1) % mod1;
    c = (c * 31) % mod;
    c1 = (c1 * 37) % mod1;
    pp[i] = (pp[i - 1] * 31) % mod;
    pp1[i] = (pp1[i - 1] * 37) % mod1;
  }
  for (long long i = 1; i <= n; i++) {
    long long p = power(pp[i - 1], mod - 2, mod);
    long long p1 = power(pp1[i - 1], mod1 - 2, mod1);
    for (long long j = i; j <= n; j++) {
      long long hh = ((h[j] - h[i - 1]) * p) % mod;
      hh = (hh + mod) % mod;
      long long hh1 = ((h1[j] - h1[i - 1]) * p1) % mod1;
      hh1 = (hh1 + mod1) % mod1;
      if ((pre[j] - pre[i - 1]) <= k) second.insert(make_pair(hh, hh1));
    }
  }
  cout << second.size();
}
signed main() {
  long long t;
  t = 1;
  while (t--) {
    solve_test_case();
  }
  return 0;
}
