#include <bits/stdc++.h>
using namespace std;
struct node {
  long long int counter, pc;
};
node tree[1000000 << 2];
node merge(node l, node r) {
  node ret;
  ret.counter = l.counter + r.counter;
  ret.pc = l.pc + r.pc;
  return ret;
}
void update(int idx, int st, int ed, long long int price, long long int cnt,
            int KIND) {
  if (st == ed) {
    tree[idx].counter += cnt * KIND;
    tree[idx].pc += (price * cnt * KIND);
    return;
  }
  int mid = (st + ed) / 2, l = 2 * idx, r = l + 1;
  if (price <= mid)
    update(l, st, mid, price, cnt, KIND);
  else
    update(r, mid + 1, ed, price, cnt, KIND);
  tree[idx] = merge(tree[l], tree[r]);
}
node range(int idx, int st, int ed, int i, int j) {
  if (i < 0 || j < 0 || i > j) return {0, 0};
  if (st == i && ed == j) return tree[idx];
  int mid = (st + ed) / 2, l = 2 * idx, r = l + 1;
  if (j <= mid) return range(l, st, mid, i, j);
  if (i > mid) return range(r, mid + 1, ed, i, j);
  return merge(range(l, st, mid, i, mid), range(r, mid + 1, ed, mid + 1, j));
}
long long int query(int idx, int st, int ed, int k) {
  if (st == ed) return st;
  int mid = (st + ed) / 2, l = 2 * idx, r = l + 1;
  if (tree[l].counter >= k) return query(l, st, mid, k);
  return query(r, mid + 1, ed, k - tree[l].counter);
}
long long int get_cost(int k) {
  long long int p = query(1, 1, 1000000, k);
  node soFar = range(1, 1, 1000000, 1, p - 1);
  long long int ret = soFar.pc;
  long long int take =
      min(k - soFar.counter, range(1, 1, 1000000, p, p).counter);
  return ret + take * p;
}
vector<pair<int, int> > add[1000000 + 5];
vector<pair<int, int> > rmv[1000000 + 5];
int main() {
  int n, k, m, i;
  int l, r, c, p;
  scanf("%d %d %d", &n, &k, &m);
  for (i = 1; i <= m; i++) {
    scanf("%d %d %d %d", &l, &r, &c, &p);
    add[l].push_back({c, p});
    rmv[r + 1].push_back({c, p});
  }
  long long int sum = 0;
  for (i = 1; i <= n; i++) {
    for (auto x : add[i]) update(1, 1, 1000000, x.second, x.first, +1);
    for (auto x : rmv[i]) update(1, 1, 1000000, x.second, x.first, -1);
    sum += get_cost(k);
  }
  cout << sum << endl;
  return 0;
}
