#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 7;
struct Tree {
  int l, r;
  long long int color, sum;
} tree[maxn << 2];
vector<pair<int, int> > plan[maxn];
void build(int l, int r, int pos) {
  tree[pos].l = l;
  tree[pos].r = r;
  tree[pos].color = tree[pos].sum = 0;
  if (l == r) return;
  int mid = (l + r) >> 1;
  build(l, mid, pos << 1);
  build(mid + 1, r, (pos << 1) | 1);
}
void update(int c, int p, int pos) {
  tree[pos].color += c;
  tree[pos].sum += 1ll * c * p;
  if (tree[pos].l == tree[pos].r) return;
  int mid = (tree[pos].l + tree[pos].r) >> 1;
  if (p > mid)
    update(c, p, (pos << 1) | 1);
  else if (p <= mid)
    update(c, p, pos << 1);
}
long long int query(long long int val, int pos) {
  if (val <= 0) return 0;
  if (tree[pos].color <= val) return tree[pos].sum;
  if (tree[pos].l == tree[pos].r) return val * tree[pos].l;
  int mid = (tree[pos].l + tree[pos].r) >> 1;
  return query(min(val, tree[pos << 1].color), pos << 1) +
         query(val - tree[pos << 1].color, (pos << 1) | 1);
}
int main() {
  int n, k, m;
  scanf("%d%d%d", &n, &k, &m);
  for (int i = 0; i < m; i++) {
    int l, r, c, p;
    scanf("%d%d%d%d", &l, &r, &c, &p);
    plan[l].push_back(make_pair(c, p));
    plan[r + 1].push_back(make_pair(-c, p));
  }
  build(1, maxn - 5, 1);
  long long int ans = 0;
  for (int i = 1; i <= n; i++) {
    int len = plan[i].size();
    for (int j = 0; j < len; j++)
      update(plan[i][j].first, plan[i][j].second, 1);
    ans += query(min(1ll * k, tree[1].color), 1);
  }
  printf("%lld", ans);
  return 0;
}
