#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0;
  int f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + (ch ^ 48);
  return x * f;
}
void print(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) print(x / 10);
  putchar(x % 10 + '0');
}
const int N = 1000010;
struct tree {
  int l, r;
  long long siz, v;
} t[N << 2];
void build(int now, int l, int r) {
  t[now].l = l, t[now].r = r;
  if (l == r) return;
  int mid = l + r >> 1;
  build(now << 1, l, mid), build(now << 1 | 1, mid + 1, r);
}
void pushup(int now) {
  t[now].siz = t[now << 1].siz + t[now << 1 | 1].siz;
  t[now].v = t[now << 1].v + t[now << 1 | 1].v;
}
void update(int now, int pos, long long c) {
  if (t[now].l == t[now].r) {
    t[now].siz += c, t[now].v = t[now].siz * pos;
    return;
  }
  int mid = t[now].l + t[now].r >> 1;
  if (pos <= mid)
    update(now << 1, pos, c);
  else
    update(now << 1 | 1, pos, c);
  pushup(now);
}
long long query(int now, long long k) {
  if (t[now].l == t[now].r) return min(t[now].siz, k) * t[now].l;
  int mid = t[now].l + t[now].r >> 1;
  if (k <= t[now << 1].siz)
    return query(now << 1, k);
  else
    return t[now << 1].v + query(now << 1 | 1, k - t[now << 1].siz);
}
int T, k, m, n;
long long ans;
struct PLAN {
  int l, r, c, p;
} a[N];
vector<int> add[N], del[N];
int main() {
  T = read(), k = read(), m = read();
  for (int i = 1; i <= m; i++) {
    a[i].l = read(), a[i].r = read(), a[i].c = read(), a[i].p = read();
    add[a[i].l].push_back(i), del[a[i].r].push_back(i);
    n = max(n, a[i].p);
  }
  build(1, 1, n);
  for (int i = 1; i <= T; i++) {
    for (int j : add[i]) update(1, a[j].p, a[j].c);
    ans += query(1, k);
    for (int j : del[i]) update(1, a[j].p, -a[j].c);
  }
  print(ans), putchar('\n');
}
