#include <bits/stdc++.h>
using namespace std;
long long b[1505], Pow[1505];
int bad[1505], n, m, k, ans;
map<long long, int> Use;
string S;
char ok[30];
long long Get(int x, int y) { return b[y] - b[x - 1] * Pow[y - x + 1]; }
int main() {
  ios_base::sync_with_stdio(0);
  cin >> S;
  int n = S.size();
  S = ' ' + S;
  for (int i = 1; i <= 26; i++) cin >> ok[i];
  Pow[0] = 1;
  for (int i = 1; i <= n; i++) {
    Pow[i] = Pow[i - 1] * 1637;
    b[i] = b[i - 1] * 1637 + S[i] - 'a' + 1;
    bad[i] = bad[i - 1] + (ok[S[i] - 'a' + 1] == '0');
  }
  cin >> k;
  for (int i = 1; i <= n; i++)
    for (int j = i; j <= n; j++) {
      if ((bad[j] - bad[i - 1]) > k) continue;
      if (Use[Get(i, j)] == 0) {
        Use[Get(i, j)] = 1;
        ans++;
      }
    }
  cout << ans;
}
