#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const int M = 505;
int f[N][26], n;
int app[N], L, R, k;
int vl[M], vr[M], c[M];
int pl[M], pr[M];
char s[N];
long long ans, res;
void add(int x, int v) {
  res -= (L <= app[x] && app[x] <= R);
  app[x] += v;
  res += (L <= app[x] && app[x] <= R);
}
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (int i = (int)(1); i <= (int)(n); i++)
    for (int j = (int)(0); j <= (int)(25); j++)
      f[i][j] = f[i - 1][j] + (s[i] == j + 'a');
  scanf("%d%d%d", &k, &L, &R);
  for (int i = (int)(1); i <= (int)(k); i++) {
    scanf("%s%d%d", s, &vl[i], &vr[i]);
    pl[i] = 0;
    pr[i] = 0;
    c[i] = s[0] - 'a';
  }
  for (int i = (int)(1); i <= (int)(n); i++) {
    res += (L == 0);
    for (int j = (int)(1); j <= (int)(k); j++) {
      for (; pl[j] + 1 <= i && f[i][c[j]] - f[pl[j]][c[j]] >= vl[j];
           add(++pl[j], 1))
        ;
      for (; pr[j] + 1 <= i && f[i][c[j]] - f[pr[j]][c[j]] > vr[j];
           add(++pr[j], -1))
        ;
    }
    ans += res;
  }
  printf("%lld\n", ans);
}
