#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
vector<int> ch[26];
vector<pair<int, int> > con[26];
char s[1000007];
int sat[1000007];
int before[1000007];
int k, L, R;
int main() {
  gets(s);
  int n = strlen(s);
  for (int i = 0; i < n; i++) {
    before[i] = ch[s[i] - 'a'].size();
    ch[s[i] - 'a'].push_back(i);
  }
  cin >> k >> L >> R;
  char t[10];
  for (int i = 0; i < k; i++) {
    int a, b;
    cin >> t >> a >> b;
    con[t[0] - 'a'].push_back(make_pair(a, b));
  }
  int now = 0;
  long long answer = 0;
  memset(sat, 0, sizeof(sat));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 26; j++)
      for (typeof(con[j].begin()) it = con[j].begin(); it != con[j].end();
           it++) {
        if (j == s[i] - 'a') {
          if (it->first <= 1 && it->second >= 1) ++sat[i];
        } else {
          if (it->first == 0) ++sat[i];
        }
      }
    if (sat[i] >= L && sat[i] <= R) ++now;
    for (typeof(con[s[i] - 'a'].begin()) it = con[s[i] - 'a'].begin();
         it != con[s[i] - 'a'].end(); it++) {
      if (before[i] >= it->second) {
        for (int j = before[i] - it->second - 1 < 0
                         ? 0
                         : ch[s[i] - 'a'][before[i] - it->second - 1] + 1;
             j <= min(i - 1, ch[s[i] - 'a'][before[i] - it->second]); ++j) {
          if (sat[j] >= L && sat[j] <= R) --now;
          --sat[j];
          if (sat[j] >= L && sat[j] <= R) ++now;
        }
      }
    }
    for (typeof(con[s[i] - 'a'].begin()) it = con[s[i] - 'a'].begin();
         it != con[s[i] - 'a'].end(); it++) {
      if (before[i] + 1 >= it->first) {
        int bound = before[i] - it->first + 1 < ch[s[i] - 'a'].size()
                        ? ch[s[i] - 'a'][before[i] - it->first + 1]
                        : i;
        for (int j = before[i] - it->first < 0
                         ? 0
                         : ch[s[i] - 'a'][before[i] - it->first] + 1;
             j <= min(i - 1, bound); ++j) {
          if (sat[j] >= L && sat[j] <= R) --now;
          ++sat[j];
          if (sat[j] >= L && sat[j] <= R) ++now;
        }
      }
    }
    answer += now;
  }
  cout << answer << endl;
  return 0;
}
