#include <bits/stdc++.h>
using namespace std;
void require(bool cond, const string& message = "Runtime error") {
  if (!cond) {
    cerr << message << endl;
    assert(false);
  }
}
string text;
int L, R;
struct Restriction {
  char c;
  int l, r;
  int lp, rp;
  int lcnt, rcnt;
};
ostream& operator<<(ostream& os, const Restriction& r) {
  os << "Restriction(" << r.c << "," << r.l << "," << r.r;
  os << ";" << r.lp << "," << r.rp << ";" << r.lcnt << "," << r.rcnt;
  os << ")" << endl;
  return os;
}
template <class T>
void print(ostream& os, const vector<T>& a) {
  for (int i = 0; i < int(a.size()); ++i) {
    if (i > 0) os << " ";
    os << a[i];
  }
  os << endl;
}
vector<Restriction> r;
vector<int> x;
void readData() {
  cin >> text;
  int k;
  cin >> k >> L >> R;
  r.resize(k);
  for (int i = 0; i < int(k); ++i) {
    cin >> r[i].c >> r[i].l >> r[i].r;
    r[i].rp = r[i].lp = 0;
    r[i].lcnt = r[i].rcnt = 0;
  }
}
bool good(const string& s) {
  int c = 0;
  for (int i = 0; i < int(r.size()); ++i) {
    int t = 0;
    for (int j = 0; j < int(s.size()); ++j) {
      if (s[j] == r[i].c) {
        ++t;
      }
    }
    if (t >= r[i].l && t <= r[i].r) {
      ++c;
    }
  }
  return L <= c && c <= R;
}
int naive() {
  int ret = 0;
  for (int j = 0; j < int(text.length() + 1); ++j) {
    for (int i = 0; i < int(j); ++i) {
      string s = text.substr(i, j - i);
      if (good(s)) {
        ++ret;
      }
    }
  }
  return ret;
}
bool inside(int x, int l, int r) { return l <= x && x <= r; }
void solve() {
  int n = x.size();
  int satR = 0;
  x.resize(text.length());
  long long ans = 0;
  for (int prefix = 0; prefix < int(x.size()); ++prefix) {
    for (int i = 0; i < int(r.size()); ++i) {
      Restriction& rr = r[i];
      if (r[i].c == text[prefix]) {
        ++rr.lcnt;
        ++rr.rcnt;
      }
      while (rr.lcnt > rr.r && rr.lp <= prefix) {
        if (!inside(x[rr.lp], L, R) && inside(x[rr.lp] - 1, L, R)) {
          ++satR;
        }
        if (inside(x[rr.lp], L, R) && !inside(x[rr.lp] - 1, L, R)) {
          --satR;
        }
        --x[rr.lp];
        if (text[rr.lp] == rr.c) {
          --rr.lcnt;
        }
        ++rr.lp;
      }
      while (rr.rcnt >= rr.l && rr.rp <= prefix) {
        if (!inside(x[rr.rp], L, R) && inside(x[rr.rp] + 1, L, R)) {
          ++satR;
        }
        if (inside(x[rr.rp], L, R) && !inside(x[rr.rp] + 1, L, R)) {
          --satR;
        }
        ++x[rr.rp];
        if (text[rr.rp] == rr.c) {
          --rr.rcnt;
        }
        ++rr.rp;
      }
    }
    if (L == 0) {
      ++satR;
    }
    ans += satR;
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  readData();
  solve();
  return 0;
}
