#include <bits/stdc++.h>
using namespace std;
int n, L, R, m, l[505], r[505], a[100050], b[505];
int lp[505], rp[505], cnt_l[505], cnt_r[505], cnt[100050];
bool judge(int x) { return x >= L && x <= R; }
long long cal() {
  long long ans = 0;
  int w, now = 0;
  memset(cnt, 0, sizeof(cnt));
  for (int i = 1; i <= n; i++) {
    if (judge(0)) now++;
    for (int j = 1; j <= m; j++) {
      w = (a[i] == b[j]);
      cnt_l[j] += w;
      cnt_r[j] += w;
      while (rp[j] < i && cnt_r[j] >= l[j]) {
        rp[j]++;
        w = (a[rp[j]] == b[j]);
        cnt_r[j] -= w;
        cnt[rp[j]]++;
        if (!judge(cnt[rp[j]] - 1) && judge(cnt[rp[j]]))
          now++;
        else if (judge(cnt[rp[j]] - 1) && !judge(cnt[rp[j]]))
          now--;
      }
      while (lp[j] < rp[j] && cnt_l[j] > r[j]) {
        lp[j]++;
        w = (a[lp[j]] == b[j]);
        cnt_l[j] -= w;
        cnt[lp[j]]--;
        if (!judge(cnt[lp[j]] + 1) && judge(cnt[lp[j]]))
          now++;
        else if (judge(cnt[lp[j]] + 1) && !judge(cnt[lp[j]]))
          now--;
      }
    }
    ans += now;
  }
  return ans;
}
int main() {
  char str[100050];
  while (scanf("%s", str) != EOF) {
    n = strlen(str);
    for (int i = 0; i < n; i++) a[i + 1] = str[i] - 'a';
    scanf("%d%d%d", &m, &L, &R);
    for (int i = 1; i <= m; i++) {
      scanf("%s%d%d", str, l + i, r + i);
      b[i] = str[0] - 'a';
      cnt_l[i] = cnt_r[i] = lp[i] = rp[i] = 0;
    }
    printf("%I64d\n", cal());
  }
  return 0;
}
