#include <bits/stdc++.h>
using namespace std;
const unsigned int MODULO = 1000000007;
const int INF = 100000000;
template <class T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
struct Node {
  int childs[26];
  Node() { memset(childs, -1, sizeof(int) * 26); }
};
bool vailds[2000];
int k;
class trie_tree {
  vector<Node> nodes;
  int add_node() {
    nodes.push_back(Node());
    return ((int)(nodes).size()) - 1;
  }

 public:
  trie_tree() { clear(); }
  void clear() {
    nodes.clear();
    add_node();
  }
  int size() const { return ((int)(nodes).size()) - 1; }
  int add(const char* s, int idx) {
    int cur = 0;
    int sm = 0;
    for (int i = idx; s[i] && sm + vailds[i] <= k; sm += vailds[i++]) {
      int nxt = nodes[cur].childs[s[i] - 'a'];
      if (nxt == -1) {
        nxt = add_node();
        nodes[cur].childs[s[i] - 'a'] = nxt;
      }
      cur = nxt;
    }
    return cur;
  }
  void check(const char* s, int idx) {
    int cur = 0;
    int sm = 0;
    for (int i = idx; s[i] && sm + vailds[i] <= k; sm += vailds[i++]) {
      int nxt = nodes[cur].childs[s[i] - 'a'];
      if (nxt == -1) break;
      cur = nxt;
    }
    add(s, idx);
  }
};
string s, vaild;
int main() {
  cin >> s >> vaild >> k;
  for (int i = 0; i < (((int)(s).size())); i++)
    vailds[i] = (vaild[s[i] - 'a'] - '0' == 0);
  trie_tree tr;
  for (int i = 0; i < (((int)(s).size())); i++) {
    tr.check(s.c_str(), i);
  }
  cout << tr.size() << endl;
  return 0;
}
