#include <bits/stdc++.h>
using namespace std;
int cnt[100000], c[500], l[500], r[500], head[500], tail[500], sum[26][100001];
char str[100001];
int main() {
  scanf("%s", str);
  int n = strlen(str), m, L, R;
  scanf("%d%d%d", &m, &L, &R);
  for (int i = 0; i < m; i++) {
    char letter[10];
    scanf("%s%d%d", letter, &l[i], &r[i]);
    c[i] = letter[0];
    head[i] = tail[i] = 0;
  }
  for (int i = 0; i < 26; i++) {
    sum[i][0] = 0;
    for (int j = 0; j < n; j++) {
      sum[i][j + 1] = sum[i][j];
      if (str[j] - 'a' == i) sum[i][j + 1]++;
    }
  }
  memset(cnt, 0, sizeof(cnt));
  long long ans = 0;
  int tot = 0;
  for (int i = 0; i < n; i++) {
    if (L == 0) tot++;
    for (int j = 0; j < m; j++) {
      int ch = c[j] - 'a';
      while (tail[j] <= i) {
        int tmp = sum[ch][i + 1] - sum[ch][tail[j]];
        if (l[j] > tmp || tmp > r[j]) break;
        if (cnt[tail[j]] == R) tot--;
        cnt[tail[j]]++;
        if (cnt[tail[j]] == L) tot++;
        tail[j]++;
      }
      while (head[j] < tail[j]) {
        int tmp = sum[ch][i + 1] - sum[ch][head[j]];
        if (l[j] <= tmp && tmp <= r[j]) break;
        if (cnt[head[j]] == L) tot--;
        cnt[head[j]]--;
        if (cnt[head[j]] == R) tot++;
        head[j]++;
      }
      if (l[j] == 0 && r[j] == 0 && head[j] == tail[j]) {
        head[j]++;
        tail[j]++;
      }
    }
    ans += tot;
  }
  printf("%I64d\n", ans);
  return 0;
}
