#include <bits/stdc++.h>
using namespace std;
const int maxx = 1e6 + 100;
vector<pair<int, int> > in[maxx], out[maxx];
struct node {
  int l;
  int r;
  long long sum;
  long long num;
} p[maxx << 2];
int n, m, k;
void init() {
  for (int i = 0; i <= n; i++) {
    in[i].clear();
    out[i].clear();
  }
}
inline void pushup(int cur) {
  p[cur].num = p[cur << 1].num + p[cur << 1 | 1].num;
  p[cur].sum = p[cur << 1].sum + p[cur << 1 | 1].sum;
}
inline void build(int l, int r, int cur) {
  p[cur].l = l;
  p[cur].r = r;
  p[cur].num = 0;
  p[cur].sum = 0;
  if (l == r) return;
  int mid = l + r >> 1;
  build(l, mid, cur << 1);
  build(mid + 1, r, cur << 1 | 1);
}
inline void update(int num, int pos, int cur) {
  int L = p[cur].l;
  int R = p[cur].r;
  if (L == R) {
    p[cur].num += num;
    p[cur].sum += (long long)num * (long long)L;
    return;
  }
  int mid = L + R >> 1;
  if (pos <= mid)
    update(num, pos, cur << 1);
  else
    update(num, pos, cur << 1 | 1);
  pushup(cur);
}
inline long long query(int num, int cur) {
  int L = p[cur].l;
  int R = p[cur].r;
  if (L == R) return (long long)L * min(p[cur].num, (long long)num);
  if (num <= p[cur << 1].num)
    return query(num, cur << 1);
  else
    return (p[cur << 1].sum + query(num - p[cur << 1].num, cur << 1 | 1));
}
int main() {
  int l, r, x, y;
  while (~scanf("%d%d%d", &n, &k, &m)) {
    init();
    for (int i = 1; i <= m; i++) {
      scanf("%d%d%d%d", &l, &r, &x, &y);
      in[l].push_back(make_pair(x, y));
      out[r].push_back(make_pair(x, y));
    }
    long long ans = 0;
    build(1, maxx, 1);
    for (int i = 1; i <= n; i++) {
      for (int j = 0; j < in[i].size(); j++)
        update(in[i][j].first, in[i][j].second, 1);
      ans += query(k, 1);
      for (int j = 0; j < out[i].size(); j++)
        update(-out[i][j].first, out[i][j].second, 1);
    }
    printf("%lld\n", ans);
  }
  return 0;
}
