#include <bits/stdc++.h>
using namespace std;
int n, k, L, R;
int l[600], r[600], c[600];
int sm[100010][26];
int has[100010], nowl[600], nowr[600];
int ans;
void check(int pos) {
  for (int i = 1; i <= k; i++) {
    while (nowr[i] < n && sm[nowr[i] + 1][c[i]] - sm[pos - 1][c[i]] <= r[i] ||
           nowr[i] < pos) {
      nowr[i]++;
      has[nowr[i]]++;
      if (has[nowr[i]] == L) ans++;
      if (has[nowr[i]] == R + 1) ans--;
    }
    while (nowl[i] <= n && sm[nowl[i]][c[i]] - sm[pos - 1][c[i]] < l[i] ||
           nowl[i] < pos ||
           (nowr[i] == pos && nowl[i] == pos && r[i] == 0 &&
            sm[pos][c[i]] - sm[pos - 1][c[i]])) {
      if (nowl[i]) {
        has[nowl[i]]--;
        if (has[nowl[i]] == R) ans++;
        if (has[nowl[i]] == L - 1) ans--;
      }
      nowl[i]++;
    }
  }
}
void Work() {
  long long Ans = 0;
  check(1);
  for (int i = 1; i <= n; i++) {
    Ans += ans;
    if (i < n) check(i + 1);
    if (has[i] <= R && has[i] >= L) ans--;
  }
  cout << Ans << endl;
}
char st[100010];
void Init() {
  scanf("%s", st + 1);
  scanf("%d%d%d", &k, &L, &R);
  for (int i = 1; i <= k; i++) {
    char ch;
    do ch = getchar();
    while (ch < 'a' || ch > 'z');
    c[i] = ch - 'a';
    scanf("%d%d", &l[i], &r[i]);
  }
  n = strlen(st + 1);
  if (!L) ans = n;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < 26; j++) sm[i][j] = sm[i - 1][j];
    sm[i][st[i] - 'a']++;
  }
}
int main() {
  Init();
  Work();
  return 0;
}
