#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
int n, k, m;
struct node {
  int num, val;
  node(){};
  node(int nn, int vv) {
    num = nn;
    val = vv;
  }
};
vector<node> vec[maxn];
struct N {
  int l, r;
  long long sum, num;
} t[maxn << 2];
void build(int rt, int l, int r) {
  t[rt].l = l;
  t[rt].r = r;
  t[rt].num = t[rt].sum = 0;
  if (l == r) return;
  int mid = (l + r) >> 1;
  build(rt << 1, l, mid);
  build(rt << 1 | 1, mid + 1, r);
}
void pushup(int rt) {
  t[rt].sum = t[rt << 1].sum + t[rt << 1 | 1].sum;
  t[rt].num = t[rt << 1].num + t[rt << 1 | 1].num;
}
void update(int rt, long long num, int pos) {
  if (t[rt].l == t[rt].r) {
    t[rt].num += num;
    t[rt].sum += num * t[rt].l;
    return;
  }
  int mid = (t[rt].l + t[rt].r) >> 1;
  if (pos <= mid)
    update(rt << 1, num, pos);
  else
    update(rt << 1 | 1, num, pos);
  pushup(rt);
}
long long query(int rt, int k) {
  if (t[rt].l == t[rt].r) return min((long long)k, t[rt].num) * t[rt].l;
  if (t[rt].num <= k) return t[rt].sum;
  if (t[rt << 1].num >= k) return query(rt << 1, k);
  return t[rt << 1].sum + query(rt << 1 | 1, k - t[rt << 1].num);
}
int main() {
  scanf("%d%d%d", &n, &k, &m);
  int l, r, c, p, mx = 0;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d%d", &l, &r, &c, &p);
    vec[l].push_back(node(c, p));
    vec[r + 1].push_back(node(-c, p));
    mx = max(mx, p);
  }
  build(1, 1, mx);
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < vec[i].size(); j++) {
      update(1, vec[i][j].num, vec[i][j].val);
    }
    ans += query(1, k);
  }
  printf("%lld\n", ans);
  return 0;
}
