#include <bits/stdc++.h>
using namespace std;
const int NMAX = 1e5 + 10;
vector<int> ap[30];
int s[NMAX], ans;
struct Restrict {
  char c;
  int l, r;
} constr[510];
int k, l, r;
void change_poz(int poz, int by) {
  if (l <= s[poz] && s[poz] <= r) ans--;
  s[poz] += by;
  if (l <= s[poz] && s[poz] <= r) ans++;
}
void add_ch(int poz, char c) {
  if (l == 0) ans++;
  ap[c].push_back(poz);
  for (int i = 1; i <= k; i++) {
    int st = constr[i].l, dr = constr[i].r;
    if (constr[i].c == c) {
      if (ap[c].size() > dr) {
        int nr = ap[c].size();
        int a = (dr + 1 != nr ? ap[c][nr - dr - 2] + 1 : 0);
        int b = (dr != 0 ? ap[c][nr - dr - 1] : poz);
        for (int j = a; j <= b; j++) change_poz(j, -1);
      }
      if (ap[c].size() >= st && st != 0) {
        int nr = ap[c].size();
        int a = (nr != st ? ap[c][nr - st - 1] + 1 : 0),
            b = (st != 0 ? ap[c][nr - st] : poz);
        for (int j = a; j <= b; j++) change_poz(j, 1);
      }
    }
    if (st == 0) change_poz(poz, 1);
  }
}
void solve() {
  string s;
  cin >> s;
  cin >> k >> l >> r;
  for (int i = 1; i <= k; i++) {
    cin >> constr[i].c >> constr[i].l >> constr[i].r;
    constr[i].c -= 'a';
  }
  long long rez = 0;
  for (int i = 0; i < s.size(); i++) {
    add_ch(i, s[i] - 'a');
    rez += ans;
  }
  cout << rez << '\n';
}
int main() {
  solve();
  return 0;
}
