#include <bits/stdc++.h>
using ll = long long;
const int maxn = 2e5 + 997;
char s[maxn], c[maxn];
int f[maxn], L, R, l[maxn], r[maxn], l1[maxn], r1[maxn], k, n;
std::vector<int> v[111];
ll ans, tmp;
int cal(int x) { return L <= f[x] && f[x] <= R; }
void mdf(int x, int y) {
  tmp -= cal(x);
  f[x] += y;
  tmp += cal(x);
}
void update(int i, int lim) {
  int len = v[c[i] - 'a'].size();
  int x = c[i] - 'a';
  while (len > r[i] && l1[i] <= v[x][len - r[i] - 1]) {
    mdf(l1[i], -1);
    l1[i]++;
  }
  if (l[i])
    while ((len >= l[i] && r1[i] < v[x][len - l[i]])) {
      r1[i]++;
      mdf(r1[i], 1);
    }
  else
    while (r1[i] < lim) {
      r1[i]++;
      mdf(r1[i], 1);
    }
}
int main() {
  scanf("%s", s + 1);
  n = std::strlen(s + 1);
  scanf("%d%d%d", &k, &L, &R);
  for (int i = 1; i <= k; ++i) {
    char opt[10];
    scanf("%s%d%d", opt + 1, &l[i], &r[i]);
    c[i] = opt[1];
    l1[i] = 1;
    r1[i] = 0;
  }
  for (int i = 1; i <= n; ++i) {
    v[s[i] - 'a'].push_back(i);
    tmp += cal(i);
    for (int j = 1; j <= k; ++j) update(j, i);
    ans += tmp;
  }
  printf("%lld", ans);
  return 0;
}
