#include <bits/stdc++.h>
using namespace std;
const int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
const int MAX = 2 * 1000 * 1000 + 10;
const long long INF = 1e18;
const int MOD = 1e9 + 7;
int has[26];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  string s, tmp;
  int k;
  cin >> s >> tmp >> k;
  for (int i = 0; i < 26; i++) has[i] += !(tmp[i] == '1');
  set<pair<long long, long long> > st;
  for (int i = 0; i < (int)(s).size(); i++) {
    long long b1, p1, b2, p2, h1(0), h2(0), m1(1), m2(1), ok = 0;
    b1 = 4395853, p1 = 1e9 + 7;
    b2 = 1234657, p2 = 1e9 + 9;
    for (int j = i; j < (int)(s).size(); j++) {
      ok += has[s[j] - 'a'];
      if (ok > k) break;
      h1 = h1 + m1 * (s[j] - 'a' + 1) % p1;
      h2 = h2 + m2 * (s[j] - 'a' + 1) % p2;
      m1 = m1 * b1 % p1;
      m2 = m2 * b2 % p2;
      st.insert({h1, h2});
    }
  }
  cout << (int)(st).size() << '\n';
}
