#include <bits/stdc++.h>
using namespace std;
const int N = 100000;
const int K = 500;
const int NN = N + 13;
const int KK = K + 13;
int n;
char s[NN];
int k, L, R;
int c[KK], lf[KK], rg[KK];
vector<int> occ[26 + 3];
int cntGood, okRules[N];
int ptr[26];
void dec(char c, int rg) {
  if (ptr[int(c)] < rg) return;
  int lfidx = (ptr[int(c)] - rg - 1 >= 0 ? occ[c][ptr[int(c)] - rg - 1] : -1);
  int rgidx = occ[c][ptr[int(c)] - rg] - (rg == 0);
  for (int i = lfidx + 1; i <= rgidx; i++) {
    okRules[i]--;
    if (okRules[i] == R)
      cntGood++;
    else if (okRules[i] == L - 1)
      cntGood--;
  }
}
void inc(char c, int lf) {
  if (lf == 0) return;
  if (ptr[int(c)] + 1 < lf) return;
  int lfidx = (ptr[int(c)] - lf >= 0 ? occ[c][ptr[int(c)] - lf] : -1);
  int rgidx = occ[c][ptr[int(c)] - lf + 1] - (lf == 1);
  for (int i = lfidx + 1; i <= rgidx; i++) {
    okRules[i]++;
    if (okRules[i] == L)
      cntGood++;
    else if (okRules[i] == R + 1)
      cntGood--;
  }
}
int main() {
  gets(s);
  n = strlen(s);
  int i, j;
  for (i = 0; i < n; i++) s[i] -= 'a';
  for (i = 0; i < n; i++) occ[int(s[i])].push_back(i);
  scanf("%d %d %d\n", &k, &L, &R);
  for (i = 0; i < k; i++)
    scanf("%c %d %d\n", &c[i], &lf[i], &rg[i]), c[i] -= 'a';
  long long ans = 0;
  memset(ptr, -1, sizeof(ptr));
  for (i = 0; i < n; i++) {
    char curc = s[i];
    ptr[int(curc)]++;
    for (j = 0; j < k; j++)
      if ((curc == c[j] && lf[j] <= 1 && 1 <= rg[j]) ||
          (curc != c[j] && lf[j] == 0))
        okRules[i]++;
    if (L <= okRules[i] && okRules[i] <= R) cntGood++;
    for (j = 0; j < k; j++) {
      if (curc != c[j]) continue;
      inc(curc, lf[j]);
      dec(curc, rg[j]);
    }
    ans += cntGood;
  }
  printf("%lld\n", ans);
  return 0;
}
