#include <bits/stdc++.h>
inline int read() {
  char ch = getchar();
  int ret = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  for (; ch >= '0' && ch <= '9'; ch = getchar()) ret = ret * 10 + ch - '0';
  return ret * f;
}
using namespace std;
const int INF = 1 << 30;
const int maxn = 1000000 + 10;
struct Line {
  int l, r, c, p;
  inline void input() {
    l = read();
    r = read();
    c = read();
    p = read();
  }
  inline bool operator<(const Line &rhs) const { return p < rhs.p; }
} a[maxn];
struct Node {
  long long cnt, price;
  Node *lc, *rc;
  Node() {
    cnt = price = 0;
    lc = rc = NULL;
  }
  inline void up() {
    cnt = lc->cnt + rc->cnt;
    price = lc->price + rc->price;
  }
} * root;
void build(Node *&p, int l, int r) {
  p = new Node();
  if (l == r) return;
  build(p->lc, l, ((l + r) >> 1));
  build(p->rc, ((l + r) >> 1) + 1, r);
  p->up();
}
void updata(Node *p, int l, int r, int pos, int id) {
  if (l == r) {
    p->cnt = a[id].c;
    p->price = 1ll * a[id].p * p->cnt;
    return;
  }
  if (pos <= ((l + r) >> 1))
    updata(p->lc, l, ((l + r) >> 1), pos, id);
  else
    updata(p->rc, ((l + r) >> 1) + 1, r, pos, id);
  p->up();
}
long long query(Node *p, int l, int r, int k, int &pos, int &sum) {
  if (l == r) {
    pos = l;
    return 0;
  }
  if (p->lc->cnt >= k)
    return query(p->lc, l, ((l + r) >> 1), k, pos, sum);
  else
    return query(p->rc, ((l + r) >> 1) + 1, r, k - p->lc->cnt, pos,
                 sum += p->lc->cnt) +
           p->lc->price;
}
struct OPT {
  int id, k;
  OPT(int id = 0, int k = 0) : id(id), k(k) {}
};
vector<OPT> vc[maxn];
int main() {
  int n, k, m;
  cin >> n >> k >> m;
  for (int i = 1; i <= m; ++i) a[i].input();
  sort(a + 1, a + m + 1);
  for (int i = 1; i <= m; ++i)
    vc[a[i].l].push_back(OPT(i, 1)), vc[a[i].r + 1].push_back(OPT(i, -1));
  long long ans = 0;
  build(root, 1, m);
  for (int i = 1; i <= n; ++i) {
    for (int j = 0, Sz = vc[i].size(); j < Sz; ++j) {
      OPT t = vc[i][j];
      if (t.k == 1)
        updata(root, 1, m, t.id, t.id);
      else
        updata(root, 1, m, t.id, 0);
    }
    if (root->cnt <= k)
      ans += root->price;
    else {
      int pos, sum = 0;
      ans += query(root, 1, m, k, pos, sum);
      ans += 1ll * a[pos].p * (k - sum);
    }
  }
  cout << ans << endl;
  return 0;
}
