#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000006;
long long num[MAXN << 2];
long long sum[MAXN << 2];
long long N;
void pushup(int rt) {
  num[rt] = num[rt << 1] + num[rt << 1 | 1];
  sum[rt] = sum[rt << 1] + sum[rt << 1 | 1];
}
void update(int P, int C, int l, int r, int rt) {
  if (l == r) {
    num[rt] += C;
    sum[rt] += 1ll * P * C;
    return;
  }
  int m = (l + r) / 2;
  if (P <= m)
    update(P, C, l, m, rt << 1);
  else
    update(P, C, m + 1, r, rt << 1 | 1);
  pushup(rt);
}
long long query(int K, int l, int r, int rt) {
  if (l == r) {
    if (l == MAXN) {
      return 0;
    }
    if (K > 0) {
      return 1ll * K * l;
    } else
      return 0;
  }
  int m = (l + r) / 2;
  if (num[rt << 1] >= K) {
    return query(K, l, m, rt << 1);
  } else {
    return sum[rt << 1] + query(K - num[rt << 1], m + 1, r, rt << 1 | 1);
  }
}
vector<pair<int, int> > C[MAXN];
vector<pair<int, int> > O[MAXN];
int main() {
  int K, M;
  scanf("%d%d%d", &N, &K, &M);
  int l, r, c, p;
  for (int i = 0; i < M; i++) {
    scanf("%d%d%d%d", &l, &r, &c, &p);
    C[l].push_back(make_pair(p, c));
    O[r].push_back(make_pair(p, c));
  }
  long long ans = 0;
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j < C[i].size(); j++)
      update(C[i][j].first, C[i][j].second, 1, MAXN, 1);
    ans += query(K, 1, MAXN, 1);
    for (int j = 0; j < O[i].size(); j++)
      update(O[i][j].first, -O[i][j].second, 1, MAXN, 1);
  }
  cout << ans << endl;
  return 0;
}
