#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
const double eps = 1e-9;
int n, k, m;
struct stuff {
  int l, r, c, p;
  bool operator<(const stuff &x) const { return p < x.p; }
} a[200005];
struct event {
  int id, x, iof;
  bool operator<(const event &e) const { return x < e.x; }
};
vector<event> e;
long long cant[200005 * 4], cost[200005 * 4];
void update(int ini, int fin, int lv, int pos, int v) {
  if (ini == fin) {
    if (v == 1) {
      cant[lv] = a[ini].c;
      cost[lv] = 1ll * a[ini].c * a[ini].p;
    } else
      cant[lv] = cost[lv] = 0;
    return;
  }
  int piv = (ini + fin) >> 1;
  if (pos <= piv)
    update(ini, piv, lv * 2, pos, v);
  else
    update(piv + 1, fin, lv * 2 + 1, pos, v);
  cant[lv] = cant[lv * 2] + cant[lv * 2 + 1];
  cost[lv] = cost[lv * 2] + cost[lv * 2 + 1];
}
pair<long long, long long> query(int ini, int fin, int lv, int a, int b) {
  if (a > fin || b < ini) return pair<long long, long long>(0, 0);
  if (a <= ini && b >= fin)
    return pair<long long, long long>(cant[lv], cost[lv]);
  int piv = (ini + fin) >> 1;
  pair<long long, long long> l = query(ini, piv, lv * 2, a, b);
  pair<long long, long long> r = query(piv + 1, fin, lv * 2 + 1, a, b);
  return pair<long long, long long>(l.first + r.first, l.second + r.second);
}
int find_p(int ini, int fin, int lv, int v) {
  if (ini == fin) return ini;
  int piv = (ini + fin) >> 1;
  if (cant[lv * 2] >= v) return find_p(ini, piv, lv * 2, v);
  return find_p(piv + 1, fin, lv * 2 + 1, v - cant[lv * 2]);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k >> m;
  for (int i = 1; i <= m; i++) cin >> a[i].l >> a[i].r >> a[i].c >> a[i].p;
  sort(a + 1, a + 1 + m);
  for (int i = 1; i <= m; i++) {
    e.push_back({i, a[i].l, 1});
    e.push_back({i, a[i].r + 1, -1});
  }
  sort(e.begin(), e.end());
  int pos = 0;
  long long sol = 0;
  for (int x = 1; x <= n; x++) {
    while (pos < 2 * m && e[pos].x == x) {
      update(1, m, 1, e[pos].id, e[pos].iof);
      pos++;
    }
    if (cant[1] <= k) {
      sol += cost[1];
      continue;
    }
    int p = find_p(1, m, 1, k);
    pair<long long, long long> v = query(1, m, 1, 1, p - 1);
    sol += v.second + 1ll * (k - v.first) * a[p].p;
  }
  cout << sol << '\n';
  return 0;
}
