You've got string s, consisting of small English letters. Some of the English letters are good, the rest are bad.

A substring s[l...r] (1 ≤ l ≤ r ≤ |s|) of string s = s1s2...s|s| (where |s| is the length of string s) is string  slsl + 1...sr.

The substring s[l...r] is good, if among the letters  sl, sl + 1, ..., sr there are at most k bad ones (look at the sample's explanation to understand it more clear).

Your task is to find the number of distinct good substrings of the given string s. Two substrings s[x...y] and s[p...q] are considered distinct if their content is different, i.e. s[x...y] ≠ s[p...q].

Input

The first line of the input is the non-empty string s, consisting of small English letters, the string's length is at most 1500 characters.

The second line of the input is the string of characters "0" and "1", the length is exactly 26 characters. If the i-th character of this string equals "1", then the i-th English letter is good, otherwise it's bad. That is, the first character of this string corresponds to letter "a", the second one corresponds to letter "b" and so on.

The third line of the input consists a single integer k (0 ≤ k ≤ |s|) — the maximum acceptable number of bad characters in a good substring.

Output

Print a single integer — the number of distinct good substrings of string s.

Examples

Input

ababab
01000000000000000000000000
1


Output

5


Input

acbacbacaa
00000000000000000000000000
2


Output

8

Note

In the first example there are following good substrings: "a", "ab", "b", "ba", "bab".

In the second example there are following good substrings: "a", "aa", "ac", "b", "ba", "c", "ca", "cb".
#include <bits/stdc++.h>
using namespace std;
long long pwr(long long a, long long b, long long mod) {
  a %= mod;
  if (a < 0) a += mod;
  long long ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % mod;
    a = (a * a) % mod;
    b /= 2;
  }
  return ans;
}
long long pwr(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans *= a;
    a *= a;
    b /= 2;
  }
  return ans;
}
long long gcd(long long a, long long b) {
  while (b) {
    long long temp = a;
    a = b;
    b = temp % b;
  }
  return a;
}
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
long long modularInverse(long long a, long long m) {
  assert(false);
  return pwr(a, m - 2, m);
}
const int mod = 1000000007;
class Hash {
 private:
  static long long X[2], MOD[2];
  static vector<vector<int> > xpwr;
  Hash() {}
  static vector<vector<int> > precomputePowers(int limit) {
    vector<vector<int> > xpwr;
    xpwr.resize(1 + max(X[0], X[1]));
    xpwr[X[0]].resize(limit + 1);
    xpwr[X[1]].resize(limit + 1);
    xpwr[X[0]][0] = 1;
    xpwr[X[1]][0] = 1;
    for (int i = 1; i <= limit; ++i)
      xpwr[X[0]][i] = ((long long)xpwr[X[0]][i - 1] * X[0]) % MOD[0],
      xpwr[X[1]][i] = ((long long)xpwr[X[1]][i - 1] * X[1]) % MOD[1];
    return xpwr;
  }
  template <typename T>
  int hash(const T& s, long long X, long long MOD) {
    long long ans = 0;
    long long mul = 1;
    for (int i = 0; i < s.size(); ++i) {
      mul *= X;
      mul %= MOD;
      ans += s[i] * mul;
      ans %= MOD;
    }
    if (ans < 0) ans += MOD;
    return (int)ans;
  }
  static int replaceOneChar(int oldHash, int index, int oldVal, int newVal,
                            int X, int MOD) {
    long long mul = xpwr[X][index + 1];
    long long ans = oldHash + (newVal - oldVal) * mul;
    if (ans >= MOD || ans <= -MOD) ans %= MOD;
    if (ans < 0) ans += MOD;
    return (int)ans;
  }
  static int pushBackCharacter(int oldHash, int index, int newVal, int X,
                               int MOD) {
    long long mul = xpwr[X][index + 1];
    long long ans = oldHash + newVal * mul;
    if (ans >= MOD || ans <= -MOD) ans %= MOD;
    if (ans < 0) ans += MOD;
    return (int)ans;
  }
  static int pushFrontCharacter(int oldHash, int newVal, int X, int MOD) {
    long long ans = ((long long)oldHash + newVal) * X;
    if (ans >= MOD || ans <= -MOD) ans %= MOD;
    if (ans < 0) ans += MOD;
    return (int)ans;
  }
  static int mergeHash(int pre, int post, int prelen, int X, int MOD) {
    long long mul = xpwr[X][prelen];
    long long ans = pre + post * mul;
    if (ans >= MOD || ans <= -MOD) ans %= MOD;
    if (ans < 0) ans += MOD;
    return ans;
  }

 public:
  template <typename T>
  pair<int, int> hash(const T& s) {
    pair<int, int> ans;
    ans.first = hash(s, X[0], MOD[0]);
    ans.second = hash(s, X[1], MOD[1]);
    return ans;
  }
  static pair<int, int> replaceOneChar(const pair<int, int>& oldHash, int index,
                                       int oldVal, int newVal) {
    pair<int, int> ans;
    ans.first =
        replaceOneChar(oldHash.first, index, oldVal, newVal, X[0], MOD[0]);
    ans.second =
        replaceOneChar(oldHash.second, index, oldVal, newVal, X[1], MOD[1]);
    return ans;
  }
  static pair<int, int> pushBackCharacter(const pair<int, int>& oldHash,
                                          int index, int newVal) {
    pair<int, int> ans;
    ans.first = pushBackCharacter(oldHash.first, index, newVal, X[0], MOD[0]);
    ans.second = pushBackCharacter(oldHash.second, index, newVal, X[1], MOD[1]);
    return ans;
  }
  static pair<int, int> pushFrontCharacter(const pair<int, int>& oldHash,
                                           int newVal) {
    pair<int, int> ans;
    ans.first = pushFrontCharacter(oldHash.first, newVal, X[0], MOD[0]);
    ans.second = pushFrontCharacter(oldHash.second, newVal, X[1], MOD[1]);
    return ans;
  }
  static pair<int, int> mergeHash(const pair<int, int>& pre,
                                  const pair<int, int>& post, int prelen) {
    pair<int, int> ans;
    ans.first = mergeHash(pre.first, post.first, prelen, X[0], MOD[0]);
    ans.second = mergeHash(pre.second, post.second, prelen, X[1], MOD[1]);
    return ans;
  }
};
vector<vector<int> > Hash::xpwr = Hash::precomputePowers(1000000);
long long Hash::MOD[] = {999999937, 999999929};
long long Hash::X[] = {37, 31};
template <class T>
class DynamicHash {
 private:
  set<pair<int, int> > table;

 public:
  int size() { return table.size(); }
  bool insert(const T& s) { return table.insert(this->hash(s)).second; }
  bool insert(const pair<int, int>& p) { return table.insert(p).second; }
  bool find(const pair<int, int>& p) { return table.find(p) != table.end(); }
  bool find(const T& s) { return find(this->hash(s)); }
};
template <class T>
class StaticHash {
 private:
  vector<pair<int, int> > table;
  bool isReady;

 public:
  StaticHash() { isReady = false; }
  int size() { return table.size(); }
  void insert(const T& s) {
    if (isReady == true) {
      assert(0);
    }
    table.push_back(this->hash(s));
  }
  void insert(const pair<int, int>& p) {
    if (isReady == true) {
      assert(0);
    }
    table.push_back(p);
  }
  bool find(const pair<int, int>& p) {
    if (isReady == false) {
      sort(table.begin(), table.end());
      table.erase(unique(table.begin(), table.end()), table.end());
      isReady = true;
    }
    return binary_search(table.begin(), table.end(), p);
  }
  bool find(const T& s) { return find(this->hash(s)); }
};
string b;
inline int isBad(char x) { return b[x - 'a'] == '0'; }
int main() {
  std::ios::sync_with_stdio(false);
  DynamicHash<string> hashTable;
  string a;
  cin >> a >> b;
  int k;
  cin >> k;
  for (int i = 0; i < a.size(); ++i) {
    int j = i;
    int currentBad = 0;
    pair<int, int> currentHash(0, 0);
    while (j < a.size() && currentBad + isBad(a[j]) <= k) {
      currentHash = Hash::pushBackCharacter(currentHash, j - i, a[j]);
      hashTable.insert(currentHash);
      if (isBad(a[j])) ++currentBad;
      ++j;
    }
  }
  cout << hashTable.size();
}
