#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long N = 1e5 + 7;
const long long p = 13331;
long long kol[26][1507];
string str, s;
long long k;
bool check(long long l, long long r) {
  long long cnt = 0;
  for (int i = 0; i <= 25; i++) {
    if (str[i] == '0') cnt += kol[i][r] - kol[i][l - 1];
  }
  return cnt <= k;
}
void solve() {
  cin >> s;
  long long n = s.size();
  cin >> str >> k;
  s = '.' + s;
  for (int i = 0; i <= 25; i++)
    for (int j = 1; j <= n; j++) {
      if (s[j] - 'a' == i)
        kol[i][j] = kol[i][j - 1] + 1;
      else
        kol[i][j] = kol[i][j - 1];
    }
  vector<unsigned long long> v;
  for (int i = 1; i <= n; i++) {
    unsigned long long hesh = 0;
    for (int j = i; j <= n; j++) {
      hesh *= p;
      hesh += (s[j] - 'a' + 1);
      if (check(i, j)) v.push_back(hesh);
    }
  }
  set<unsigned long long> s;
  for (auto x : v) s.insert(x);
  cout << s.size();
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  unsigned long long t24 = 1;
  while (t24--) {
    solve();
    cout << "\n";
  }
}
