#include <bits/stdc++.h>
using namespace std;
const int maxn = 400500;
const int inf = 1e9;
int n, s, t, cnt, tot, m, k;
struct node {
  int l, r, c, p;
} a[maxn];
int sz[maxn * 4], mn[maxn * 4], mx[maxn * 4], tagmn[maxn * 4], tagmx[maxn * 4],
    c[maxn];
long long ans;
void up(int i) {
  mn[i] = min(mn[i * 2], mn[i * 2 + 1]);
  mx[i] = max(mx[i * 2], mx[i * 2 + 1]);
}
void build(int i, int l, int r) {
  mn[i] = mx[i] = k;
  tagmn[i] = tagmx[i] = 0;
  if (l == r) {
    sz[i] = (c[l + 1] - c[l]);
    return;
  }
  int mid = (l + r) / 2;
  build(i * 2, l, mid);
  build(i * 2 + 1, mid + 1, r);
  sz[i] = sz[i * 2] + sz[i * 2 + 1];
  up(i);
}
void down(int i) {
  if (tagmn[i])
    mn[i * 2] -= tagmn[i], mn[i * 2 + 1] -= tagmn[i], tagmn[i * 2] += tagmn[i],
        tagmn[i * 2 + 1] += tagmn[i];
  if (tagmx[i])
    mx[i * 2] -= tagmx[i], mx[i * 2 + 1] -= tagmx[i], tagmx[i * 2] += tagmx[i],
        tagmx[i * 2 + 1] += tagmx[i];
  tagmn[i] = 0;
  tagmx[i] = 0;
}
void dfs(int i, int l, int r, int c, int p) {
  int x = min(mn[i], c);
  mn[i] -= x;
  mx[i] -= x;
  tagmn[i] += x;
  tagmx[i] += x;
  ans += 1ll * x * p * sz[i];
  c -= x;
  if (l == r || c == 0) return;
  down(i);
  int mid = (l + r) / 2;
  if (mx[i * 2]) dfs(i * 2, l, mid, c, p);
  if (mx[i * 2 + 1]) dfs(i * 2 + 1, mid + 1, r, c, p);
  up(i);
}
void cg(int i, int l, int r, int L, int R, int c, int p) {
  if (L <= l && r <= R) {
    dfs(i, l, r, c, p);
    return;
  }
  down(i);
  int mid = (l + r) / 2;
  if (L <= mid) cg(i * 2, l, mid, L, R, c, p);
  if (R > mid) cg(i * 2 + 1, mid + 1, r, L, R, c, p);
  up(i);
}
bool cmp(node a, node b) { return a.p < b.p; }
void dfs2(int i, int l, int r) {
  printf("%d %d %d %d %d %d %d\n", i, l, r, mn[i], mx[i], tagmn[i], tagmx[i]);
  if (l == r) return;
  int mid = (l + r) / 2;
  dfs2(i * 2, l, mid);
  dfs2(i * 2 + 1, mid + 1, r);
}
int main() {
  scanf("%d%d%d", &n, &k, &m);
  int mmx = 0;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d%d", &a[i].l, &a[i].r, &a[i].c, &a[i].p);
    c[++cnt] = a[i].l, c[++cnt] = a[i].r + 1;
    mmx = max(mmx, a[i].r + 1);
  }
  c[++cnt] = mmx;
  sort(c + 1, c + 1 + cnt);
  cnt = unique(c + 1, c + 1 + cnt) - c - 1;
  build(1, 1, cnt - 1);
  sort(a + 1, a + 1 + m, cmp);
  for (int i = 1; i <= m; i++) {
    a[i].l = lower_bound(c + 1, c + 1 + cnt, a[i].l) - c;
    a[i].r = lower_bound(c + 1, c + 1 + cnt, a[i].r + 1) - c;
    cg(1, 1, cnt - 1, a[i].l, a[i].r - 1, a[i].c, a[i].p);
  }
  printf("%lld\n", ans);
  return 0;
}
