#include <bits/stdc++.h>
using namespace std;
char s[110000], c[510][10];
int sum[510][110000], a[510], cnt[510], p[510], q[510], l[510], r[510], L, R, d;
long long ans;
int main() {
  scanf("%s", s + 1);
  int N = strlen(s + 1), M;
  scanf("%d%d%d", &M, &L, &R);
  int i, j;
  for (i = 1; i <= M; i++) scanf("%s%d%d", c[i], &l[i], &r[i]);
  for (j = 1; j <= N; j++) {
    d += !L;
    for (i = 1; i <= M; i++) {
      sum[i][j] = sum[i][j - 1] + (s[j] == *c[i]);
      if (sum[i][j] >= l[i]) {
        int &p = ::p[i], &q = ::q[i], *s = sum[i];
        if (!p && !q) {
          p = q = 1;
          if (a[1] == L - 1) ++d;
          if (a[1] == R) --d;
          ++a[1];
        }
        while (s[j] - s[p - 1] > r[i]) {
          if (a[p] == R + 1) ++d;
          if (a[p] == L) --d;
          --a[p];
          ++p;
        }
        while (q < j && s[j] - s[q] >= l[i]) {
          ++q;
          if (a[q] == L - 1) ++d;
          if (a[q] == R) --d;
          ++a[q];
        }
      }
    }
    ans += d;
  }
  printf("%I64d\n", ans);
}
