#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000000 + 10;
const int MAXM = 200000 + 10;
struct Tariff {
  int l;
  int r;
  int c;
  int p;
};
struct Dot {
  int x;
  int seg_idx;
  bool is_left;
};
Tariff input[MAXM];
vector<Dot> dots;
pair<long long, long long> arr[MAXM], tree[4 * MAXM];
void update(int v, int tl, int tr, int pos) {
  if (pos > tr || pos < tl) return;
  if (tr == tl) {
    tree[v].first = arr[pos].first;
    tree[v].second = arr[pos].second;
  } else {
    int tm = (tl + tr) / 2;
    update(v * 2, tl, tm, pos);
    update(v * 2 + 1, tm + 1, tr, pos);
    tree[v].first = tree[v * 2].first + tree[v * 2 + 1].first;
    tree[v].second = tree[v * 2].second + tree[v * 2 + 1].second;
  }
}
long long get_sum(int v, int tl, int tr, int L, int R, int k) {
  if (tl > tr) return 0;
  if (tl > R || tr < L) return 0;
  if (tl == tr) {
    if (false) cerr << "TL " << tl << endl;
    if (false) cerr << v << " " << tl << " " << tr << " " << k << endl;
    return k * 1ll * tree[v].second / tree[v].first;
  }
  if (tree[v * 2].first == k)
    return tree[v * 2].second;
  else if (tree[v * 2].first > k) {
    int tm = (tl + tr) / 2;
    return get_sum(v * 2, tl, tm, L, R, k);
  } else {
    int tm = (tl + tr) / 2;
    if (false) cerr << "TREE[v * 2].second " << tree[v * 2].second << endl;
    return tree[v * 2].second +
           get_sum(v * 2 + 1, tm + 1, tr, L, R, k - tree[v * 2].first);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, k, m;
  cin >> n >> k >> m;
  for (int i = 1; i <= m; ++i) {
    cin >> input[i].l >> input[i].r >> input[i].c >> input[i].p;
  }
  sort(input + 1, input + m + 1,
       [](const Tariff& x, const Tariff& y) { return x.p < y.p; });
  for (int i = 1; i <= m; ++i) {
    if (false) cerr << i << " " << input[i].c << " " << input[i].p << endl;
  }
  for (int i = 1; i <= m; ++i) {
    dots.push_back({input[i].l, i, true});
    dots.push_back({input[i].r, i, false});
  }
  sort(dots.begin(), dots.end(), [](const Dot& a, const Dot& b) {
    if (a.x == b.x)
      return !a.is_left && b.is_left;
    else
      return a.x < b.x;
  });
  for (auto i : dots) {
    if (false) cerr << i.x << " " << i.is_left << endl;
  }
  int l_p = 0, r_p = 0;
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    while (r_p < dots.size()) {
      if (dots[r_p].x > i) break;
      if (dots[r_p].is_left) {
        arr[dots[r_p].seg_idx] = {
            input[dots[r_p].seg_idx].c,
            input[dots[r_p].seg_idx].c * 1ll * input[dots[r_p].seg_idx].p};
        update(1, 1, m, dots[r_p].seg_idx);
        if (false) cerr << "SEG IDX: " << dots[r_p].seg_idx << endl;
        if (false)
          cerr << "ADD: " << input[dots[r_p].seg_idx].l << " "
               << input[dots[r_p].seg_idx].r << " "
               << input[dots[r_p].seg_idx].c << " "
               << input[dots[r_p].seg_idx].p << endl;
      }
      ++r_p;
    }
    while (l_p < dots.size()) {
      if (dots[l_p].x >= i) break;
      if (!dots[l_p].is_left) {
        arr[dots[l_p].seg_idx] = {0, 0};
        update(1, 1, m, dots[l_p].seg_idx);
        if (false) cerr << "SEG IDX: " << dots[r_p].seg_idx << endl;
        if (false)
          cerr << "REMOVE: " << input[dots[l_p].seg_idx].l << " "
               << input[dots[l_p].seg_idx].r << " "
               << input[dots[l_p].seg_idx].c << " "
               << input[dots[l_p].seg_idx].p << endl;
      }
      ++l_p;
    }
    if (false) cerr << "ROOT: " << tree[1].second << endl;
    if (k >= tree[1].first)
      ans += tree[1].second;
    else
      ans += get_sum(1, 1, m, 1, m, k);
    if (false) cerr << "ANS = " << ans << endl;
  }
  cout << ans << endl;
  return 0;
}
