#include <bits/stdc++.h>
using namespace std;
const int LMAX = 100005;
const int KMAX = 505;
const int THETA = 26;
char s[LMAX];
struct constraint {
  int low, high;
  char ch;
} C[KMAX];
int N, L, R, K, Left[KMAX], Right[KMAX], rcount;
int cnt[THETA][LMAX], NR[LMAX];
inline int countch(int left, int right, int ch) {
  return cnt[ch - 'a'][right] - cnt[ch - 'a'][left - 1];
}
inline void incr(int pos) {
  if (NR[pos] >= L && NR[pos] <= R) --rcount;
  ++NR[pos];
  if (NR[pos] >= L && NR[pos] <= R) ++rcount;
}
inline void decr(int pos) {
  if (NR[pos] >= L && NR[pos] <= R) --rcount;
  --NR[pos];
  if (NR[pos] >= L && NR[pos] <= R) ++rcount;
}
int main() {
  cin >> s + 1;
  N = strlen(s + 1);
  cin >> K >> L >> R;
  for (int i = 0; i < K; ++i) cin >> C[i].ch >> C[i].low >> C[i].high;
  for (int i = 1; i <= N; ++i) {
    for (int j = 0; j < THETA; ++j) cnt[j][i] = cnt[j][i - 1];
    ++cnt[s[i] - 'a'][i];
  }
  for (int i = 0; i < K; ++i) Left[i] = 1;
  long long ans = 0;
  for (int i = 1; i <= N; ++i) {
    if (L == 0 && NR[i] == 0) ++rcount;
    for (int j = 0; j < K; ++j) {
      if (countch(1, i, C[j].ch) < C[j].low) continue;
      while (Right[j] + 1 <= i && countch(Right[j] + 1, i, C[j].ch) >= C[j].low)
        incr(++Right[j]);
      while (countch(Left[j], i, C[j].ch) > C[j].high) decr(Left[j]++);
    }
    ans += rcount;
  }
  cout << ans << "\n";
  return 0;
}
