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;
const long double PI = 2 * acos(0.0);
void print(vector<bool> &a) {
  for (bool i : a) {
    cout << i << " ";
  }
  cout << "\n";
}
void print(vector<int> &a) {
  for (int i : a) {
    cout << i << " ";
  }
  cout << "\n";
}
void print(vector<char> &a) {
  for (char i : a) {
    cout << i << " ";
  }
  cout << "\n";
}
void print(vector<long long> &a) {
  for (long long i : a) {
    cout << i << " ";
  }
  cout << "\n";
}
void print(vector<vector<int> > &a) {
  for (vector<int> i : a) {
    print(i);
  }
  cout << "\n";
}
void print(vector<vector<long long> > &a) {
  for (vector<long long> i : a) {
    print(i);
  }
  cout << "\n";
}
void print(vector<double> &a) {
  for (double i : a) {
    cout << i << " ";
  }
  cout << "\n";
}
void print(vector<long double> &a) {
  for (long double i : a) {
    cout << i << " ";
  }
  cout << "\n";
}
void print(vector<pair<long long, long long> > &a) {
  for (pair<long long, long long> i : a) {
    cout << i.first << " " << i.second << "\n";
  }
  cout << "\n";
}
void print(deque<pair<long long, long long> > &a) {
  for (pair<long long, long long> i : a) {
    cout << i.first << " " << i.second << "\n";
  }
  cout << "\n";
}
long long dist_sq(pair<long long, long long> a, pair<long long, long long> b) {
  return ((a.first - b.first) * (a.first - b.first) +
          (a.second - b.second) * (a.second - b.second));
}
long long po(long long a, long long b) {
  if (b <= 0)
    return 1;
  else if (b == 1)
    return a;
  long long vl = po((a * a), b / 2);
  if (b % 2 == 0)
    return vl;
  else
    return (vl)*a;
}
long long pomod(long long a, long long b) {
  a = a % 1000000007LL;
  if (b <= 0)
    return 1 % 1000000007LL;
  else if (b == 1)
    return a % 1000000007LL;
  long long vl = pomod((a * a) % 1000000007LL, b / 2);
  vl = vl % 1000000007LL;
  if (b % 2 == 0)
    return vl;
  else
    return ((vl)*a) % 1000000007LL;
}
long long pomod(long long a, long long b, long long mo) {
  a = a % mo;
  if (b <= 0)
    return 1 % mo;
  else if (b == 1)
    return a % mo;
  long long vl = pomod((a * a) % mo, b / 2);
  vl = vl % mo;
  if (b % 2 == 0)
    return vl;
  else
    return ((vl)*a) % mo;
}
long long factmod(long long n, long long mo) {
  long long val = n;
  long long ans = 1;
  while (val >= 1) {
    ans = (ans * val) % 1000000007LL;
    val--;
  }
  return ans;
}
long long inv(long long a, long long mo) { return pomod(a, mo - 2, mo); }
long long floorlog2(long long n) {
  long long h = 0;
  long long p = 1;
  while (p <= n) {
    h++;
    p *= 2;
  }
  return h - 1;
}
long long floorlog2(long long n, long long b) {
  long long h = 0;
  long long p = 1;
  while (p <= n) {
    h++;
    p *= b;
  }
  return h - 1;
}
struct trie {
  long long occ = 0;
  trie *ch[2];
};
struct trie *new_trie() {
  trie *root = new trie;
  root->occ = 1;
  root->ch[0] = NULL;
  root->ch[1] = NULL;
  return root;
}
long long bit_to_ll(const string &bits) {
  int ln = bits.length();
  long long p = 1;
  long long ans = 0;
  for (long long i = (ln - 1); i >= (0); i--) {
    if (bits[i] == '1') {
      ans += p;
    }
    p *= 2;
  }
  return ans;
}
string ll_to_bit(const long long &el) {
  string ans = "";
  long long tmp = el;
  while (tmp != 0) {
    int d = tmp % 2;
    if (d) {
      ans = "1" + ans;
    } else {
      ans = "0" + ans;
    }
    tmp /= 2;
  }
  int ln = ans.length();
  while (ans.length() != 33) {
    ans = "0" + ans;
  }
  return ans;
}
void insert(trie *root, const long long &el) {
  string str = ll_to_bit(el);
  int len = str.length();
  trie *temp = root;
  for (long long i = (0); i <= (len - 1); i++) {
    char c = str[i];
    if (c == '0') {
      if (temp->ch[0] == NULL) {
        temp->ch[0] = new_trie();
      } else {
        temp->ch[0]->occ++;
      }
      temp = temp->ch[0];
    } else {
      if (temp->ch[1] == NULL) {
        temp->ch[1] = new_trie();
      } else {
        temp->ch[1]->occ++;
      }
      temp = temp->ch[1];
    }
  }
}
void del(trie *root, const long long &el) {
  string str = ll_to_bit(el);
  int len = str.length();
  trie *temp = root;
  for (long long i = (0); i <= (len - 1); i++) {
    char c = str[i];
    if (c == '0') {
      if (temp->ch[0] == NULL) {
        return;
      } else {
        temp->ch[0]->occ--;
      }
      temp = temp->ch[0];
    } else {
      if (temp->ch[1] == NULL) {
        return;
      } else {
        temp->ch[1]->occ--;
      }
      temp = temp->ch[1];
    }
  }
}
long long maxxor(trie *root, const long long &el) {
  string str = ll_to_bit(el);
  int len = str.length();
  trie *temp = root;
  long long mx = el;
  string maxstring = "";
  for (long long i = (0); i <= (len - 1); i++) {
    char c = str[i];
    if (c == '0') {
      if (temp->ch[1] == NULL || temp->ch[1]->occ == 0) {
        maxstring = maxstring + "0";
        temp = temp->ch[0];
      } else {
        maxstring = maxstring + "1";
        temp = temp->ch[1];
      }
    } else {
      if (temp->ch[0] == NULL || temp->ch[0]->occ == 0) {
        maxstring = maxstring + "0";
        temp = temp->ch[1];
      } else {
        maxstring = maxstring + "1";
        temp = temp->ch[0];
      }
    }
  }
  return bit_to_ll(maxstring);
}
void del_trie(trie *root) {
  if (root->ch[1] != NULL) {
    del_trie(root->ch[1]);
  }
  if (root->ch[0] != NULL) {
    del_trie(root->ch[0]);
  }
  delete root;
}
vector<vector<int> > dist(105, vector<int>(105, 0));
vector<vector<bool> > seen(105, vector<bool>(105, 0));
vector<vector<pair<int, int> > > par(105,
                                     vector<pair<int, int> >(105,
                                                             make_pair(0, 0)));
int main(void) {
  ios_base::sync_with_stdio(false);
  string second;
  string bad;
  int k;
  cin >> second;
  cin >> bad;
  cin >> k;
  second = "#" + second;
  int n = second.size();
  n = n - 1;
  long long val1 = 0;
  long long val2 = 0;
  long long val3 = 0;
  long long p = 29;
  map<long long, bool> m1;
  map<long long, bool> m2;
  map<long long, bool> m3;
  long long ans = 0;
  for (long long i = (1); i <= (n); i++) {
    val1 = (long long)((second[i] - 'a') + 1LL);
    val1 = val1 % 1125899906842597LL;
    val2 = (long long)((second[i] - 'a') + 1LL);
    int bd = 0;
    if (bad[second[i] - 'a'] == '0') {
      bd++;
    }
    if (!m1[val1]) {
      if (bd <= k) {
        ans++;
      }
    }
    m1[val1] = true;
    for (long long j = (i + 1); j <= (n); j++) {
      if (bad[second[j] - 'a'] == '0') {
        bd++;
      }
      val1 = ((val1 * p) % 1125899906842597LL +
              (long long)((second[j] - 'a') + 1LL)) %
             1125899906842597LL;
      if (!m1[val1]) {
        if (bd <= k) {
          ans++;
        } else {
          break;
        }
      }
      m1[val1] = true;
    }
  }
  cout << ans;
  return 0;
}
