#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200007;
struct Node {
  long long coresum = 0;
  long long costsum = 0;
} tr[4 * MAXN];
void update(int u, int l, int r, int idx, long long core, long long cost) {
  if (l == r) {
    tr[u].coresum += core;
    tr[u].costsum += core * cost;
    return;
  }
  int mid = (l + r) / 2;
  if (idx <= mid)
    update(u * 2, l, mid, idx, core, cost);
  else
    update(u * 2 + 1, mid + 1, r, idx, core, cost);
  tr[u].coresum = tr[u * 2].coresum + tr[u * 2 + 1].coresum;
  tr[u].costsum = tr[u * 2].costsum + tr[u * 2 + 1].costsum;
}
long long query(int u, int l, int r, long long need) {
  if (l == r) {
    assert(tr[u].coresum >= 0);
    if (tr[u].coresum == 0) return 0;
    return min(need, tr[u].coresum) * (tr[u].costsum / tr[u].coresum);
  }
  int mid = (l + r) / 2;
  long long bam = tr[u * 2].coresum;
  long long ans;
  if (need <= bam) {
    ans = query(u * 2, l, mid, need);
  } else {
    ans = tr[u * 2].costsum + query(u * 2 + 1, mid + 1, r, need - bam);
  }
  return ans;
}
struct data {
  int l, r;
  long long core, cost;
  bool operator<(const data& p) const { return cost < p.cost; }
};
vector<int> event[10 * MAXN];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, k, m;
  cin >> n >> k >> m;
  vector<data> vd(m);
  for (int i = 0; i < m; i++) {
    cin >> vd[i].l >> vd[i].r >> vd[i].core >> vd[i].cost;
  }
  sort(vd.begin(), vd.end());
  for (int i = 1; i <= m; i++) {
    event[vd[i - 1].l].push_back(i);
    event[vd[i - 1].r + 1].push_back(-i);
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int id : event[i]) {
      if (id > 0) {
        update(1, 1, m, id, vd[id - 1].core, vd[id - 1].cost);
      } else {
        id = -id;
        update(1, 1, m, id, -vd[id - 1].core, vd[id - 1].cost);
      }
    }
    long long g = query(1, 1, m, k);
    ans += g;
  }
  cout << ans << '\n';
  return 0;
}
