Problem: Katya recently started to invent programming tasks and prepare her own contests. What she does not like is boring and simple constraints. Katya is fed up with all those "N does not exceed a thousand" and "the sum of ai does not exceed a million" and she decided to come up with something a little more complicated.

The last problem written by Katya deals with strings. The input is a string of small Latin letters. To make the statement longer and strike terror into the people who will solve the contest, Katya came up with the following set of k restrictions of the same type (characters in restrictions can be repeated and some restrictions may contradict each other): 

  * The number of characters c1 in a string is not less than l1 and not more than r1. 
  * ... 
  * The number of characters ci in a string is not less than li and not more than ri. 
  * ... 
  * The number of characters ck in a string is not less than lk and not more than rk. 



However, having decided that it is too simple and obvious, Katya added the following condition: a string meets no less than L and not more than R constraints from the above given list.

Katya does not like to compose difficult and mean tests, so she just took a big string s and wants to add to the tests all its substrings that meet the constraints. However, Katya got lost in her conditions and asked you to count the number of substrings of the string s that meet the conditions (each occurrence of the substring is counted separately).

Input

The first line contains a non-empty string s, consisting of small Latin letters. The length of the string s does not exceed 105.

The second line contains three space-separated integers k, L and R (0 ≤ L ≤ R ≤ k ≤ 500).

Next k lines contain Katya's constrictions in the following form "ci li ri". All letters ci are small Latin letters, li and ri are integers (0 ≤ li ≤ ri ≤ |s|, where |s| is the length of string s). Letters ci are not necessarily different.

Output

Print a single number — the number of substrings that meet the constrictions.

Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cout stream or the %I64d specificator.

Examples

Input

codeforces
2 0 0
o 1 2
e 1 2


Output

7


Input

codeforces
2 1 1
o 1 2
o 1 2


Output

0

Note

In the first test we should count the number of strings that do not contain characters "e" and "o". All such strings are as follows (in the order of occurrence in the initial string from the left to the right): "c", "d"', "f", "r", "rc", "c", "s".

In the second test we cannot achieve fulfilling exactly one of the two identical constrictions, so the answer is 0.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
char str[100005], sym[502];
int l[502], r[502], k, L, R;
int check() {
  int n = strlen(str), ans = 0;
  for (int rr = 0; rr < n; rr++) {
    int ans1 = 0;
    for (int ll = 0; ll <= rr; ll++) {
      int cnt = 0;
      for (int i = 0; i < k; i++) {
        int num = 0;
        for (int j = ll; j <= rr; j++) num += str[j] == sym[i];
        if (num >= l[i] && num <= r[i]) cnt++;
      }
      if (cnt >= L && cnt <= R) ans1++;
    }
    cout << rr << " " << ans1 << endl;
    ans += ans1;
  }
  return ans;
}
vector<int> let[26];
long long solve() {
  pair<int, int> v[1002];
  int n = strlen(str);
  long long ans = 0;
  for (int i = 0; i < 26; i++) let[i].push_back(0);
  for (int i = 0; i < n; ++i) {
    let[str[i] - 'a'].push_back(i + 1);
    int len = 0;
    for (int j = 0; j < k; ++j) {
      if (let[sym[j] - 'a'].size() < l[j] + 1) continue;
      int ind = ((int)let[sym[j] - 'a'].size() - r[j] - 1);
      if (ind < 0) ind = 0;
      int ll = let[sym[j] - 'a'][ind],
          rr = l[j] == 0 ? i + 1
                         : let[sym[j] - 'a'][let[sym[j] - 'a'].size() - l[j]];
      if (ll <= rr) {
        v[len++] = make_pair(ll, -1);
        v[len++] = make_pair(rr, 1);
      }
    }
    sort(v, v + len);
    int sum = 0, ind = 0;
    for (int j = 0; j < len; ++j) {
      if (sum >= L && sum <= R) ans += v[j].first - ind;
      sum -= v[j].second;
      ind = v[j].first;
      while (j + 1 < len && v[j] == v[j + 1]) {
        ++j;
        sum -= v[j].second;
        ind = v[j].first;
      }
    }
    if (sum >= L && sum <= R) ans += i - ind + 1;
  }
  return ans;
}
int Cur;
struct item {
  item(int _pos = 0, int _ind = 0, int _type = 0)
      : pos(_pos), ind(_ind), type(_type){};
  int pos, ind, type;
  int getIndex() {
    if (pos < 0) return pos;
    if (pos < let[sym[ind] - 'a'].size()) return let[sym[ind] - 'a'][pos] + 1;
    return Cur + (type == -1);
  }
};
bool operator<(item& a, item& b) {
  return a.getIndex() < b.getIndex() ||
         a.getIndex() == b.getIndex() && a.type > b.type;
}
long long solve2() {
  item v[1002];
  int n = strlen(str);
  long long ans = 0;
  for (int i = 0; i < k; i++) {
    v[2 * i] = item(-r[i] - 1, i, 1);
    v[2 * i + 1] = item(-l[i], i, -1);
  }
  for (int i = 0; i < n; ++i) {
    Cur = i;
    let[str[i] - 'a'].push_back(i);
    for (int j = 0; j < 2 * k; j++) {
      if (sym[v[j].ind] == str[i]) v[j].pos++;
    }
    for (int j = 2 * k - 1; j >= 0; j--) {
      for (int t = j + 1; t < 2 * k; t++) {
        if (v[t] < v[t - 1])
          swap(v[t - 1], v[t]);
        else
          break;
      }
    }
    int ans1 = 0, sum = 0, ind = 0, index;
    int was[502] = {0};
    memset(was, 1, sizeof(was));
    for (int j = 0; j < 2 * k; j++) {
      was[v[j].ind] *= -1;
      if (v[j].type == was[v[j].ind]) continue;
      index = v[j].getIndex();
      if (sum >= L && sum <= R && index >= 0) ans1 += index - ind;
      sum += v[j].type;
      if (index >= 0) ind = index;
      while (j + 1 < 2 * k && v[j + 1].getIndex() == index &&
             v[j + 1].type == v[j].type) {
        sum += v[j].type, j++;
      }
    }
    if (sum >= L && sum <= R) ans1 += i - ind + 1;
    ans += ans1;
  }
  return ans;
}
int main() {
  gets(str);
  int n = strlen(str);
  cin >> k >> L >> R;
  for (int i = 0; i < k; i++) cin >> sym[i] >> l[i] >> r[i];
  cout << solve2() << endl;
  return 0;
}