#include <bits/stdc++.h>
using namespace std;
const int N = 1000010;
const int oo = 1e9;
int n, lazy[4 * N], k, bit[N], m;
pair<int, int> seg[4 * N];
struct plan {
  int l, r, c, p;
  plan() {}
  bool operator<(const plan &rhs) const { return p < rhs.p; }
};
plan hv[N];
void add(int idx, int val) {
  while (idx <= n) {
    bit[idx] += val;
    idx += (idx & -idx);
  }
}
int get(int idx) {
  int res = 0;
  while (idx) {
    res += bit[idx];
    idx -= (idx & -idx);
  }
  return res;
}
void build(int n, int s, int e) {
  if (s == e) {
    seg[n] = make_pair(k, s);
    return;
  }
  build(2 * n, s, (s + e) / 2);
  build(2 * n + 1, (s + e) / 2 + 1, e);
  seg[n] = min(seg[2 * n], seg[2 * n + 1]);
}
void push(int n, int s, int e) {
  if (lazy[n]) {
    seg[n].first += lazy[n];
    if (s != e) {
      lazy[2 * n] += lazy[n];
      lazy[2 * n + 1] += lazy[n];
    }
    lazy[n] = 0;
  }
}
void update(int n, int s, int e, int l, int r, int val) {
  push(n, s, e);
  if (s > r || e < l) return;
  if (s >= l && e <= r) {
    lazy[n] += val;
    push(n, s, e);
    return;
  }
  update(2 * n, s, (s + e) / 2, l, r, val);
  update(2 * n + 1, (s + e) / 2 + 1, e, l, r, val);
  seg[n] = min(seg[2 * n], seg[2 * n + 1]);
}
pair<int, int> get(int n, int s, int e, int l, int r) {
  push(n, s, e);
  if (s > r || e < l) return make_pair(oo, oo);
  if (s >= l && e <= r) return seg[n];
  return min(get(2 * n, s, (s + e) / 2, l, r),
             get(2 * n + 1, (s + e) / 2 + 1, e, l, r));
}
bool isFull(int l, int r) { return get(r) - get(l - 1) == 0; }
int main() {
  cin >> n >> k >> m;
  for (int i = 0; i < m; ++i) {
    scanf("%d%d%d%d", &hv[i].l, &hv[i].r, &hv[i].c, &hv[i].p);
  }
  for (int i = 1; i <= n; ++i) add(i, 1);
  build(1, 1, n);
  sort(hv, hv + m);
  long long res = 0;
  for (int i = 0; i < m; ++i) {
    while (hv[i].c && !isFull(hv[i].l, hv[i].r)) {
      pair<int, int> gt = get(1, 1, n, hv[i].l, hv[i].r);
      long long cn = min(hv[i].c, gt.first);
      long long emp = get(hv[i].r) - get(hv[i].l - 1);
      res += 1ll * emp * cn * hv[i].p;
      hv[i].c -= cn;
      update(1, 1, n, hv[i].l, hv[i].r, -cn);
      while (1) {
        pair<int, int> atm = get(1, 1, n, hv[i].l, hv[i].r);
        if (atm.first) break;
        update(1, 1, n, atm.second, atm.second, oo);
        add(atm.second, -1);
      }
    }
  }
  cout << res << endl;
}
