#include <bits/stdc++.h>
using namespace std;
const long long mod = (long long)1e6 + 3;
const int inf = (int)1e9;
const long long INF = (long long)2e18;
const int base = 1000 * 1000 * 1000;
const int maxn = 1001;
const long double pi = acosl(-1.0);
const long double eps = 1e-6;
struct plan {
  int day, c, p;
};
bool Comp(plan a, plan b) { return a.day < b.day; }
struct Tree {
  int size;
  vector<long long> tk;
  vector<long long> sum;
  Tree(int n) {
    size = 1;
    while (size <= n) size <<= 1;
    tk.resize(size * 2, 0);
    sum.resize(size * 2, 0);
  }
  pair<int, long long> binary(int v, int tl, int tr, long long k) {
    while (v < size) {
      int mid = (tl + tr) / 2;
      if (tk[2 * v] < k) {
        k -= tk[2 * v];
        v = 2 * v + 1;
        tl = mid + 1;
      } else {
        v = 2 * v;
        tr = mid;
      }
    }
    return make_pair(tl, min(k, tk[v]));
  }
  void update(int v, int tl, int tr, int pos, long long val) {
    if (tl == tr) {
      tk[v] += val;
      sum[v] += 1ll * pos * val;
      return;
    }
    int mid = (tl + tr) / 2;
    if (pos <= mid)
      update(2 * v, tl, mid, pos, val);
    else
      update(2 * v + 1, mid + 1, tr, pos, val);
    tk[v] = tk[2 * v] + tk[2 * v + 1];
    sum[v] = sum[2 * v] + sum[2 * v + 1];
  }
  long long getVal(int v, int tl, int tr, int l, int r) {
    if (l > r) return 0;
    if (tl == l && tr == r) {
      return sum[v];
    }
    int mid = (tl + tr) / 2;
    long long a = getVal(2 * v, tl, mid, l, min(mid, r));
    long long b = getVal(2 * v + 1, mid + 1, tr, max(l, mid + 1), r);
    return a + b;
  }
};
void solve() {
  int n, k, m;
  scanf("%d %d %d", &n, &k, &m);
  vector<plan> L(m), R(m);
  int N = 0;
  for (int i = 0; i < m; i++) {
    int l, r, c, p;
    scanf("%d %d %d %d", &l, &r, &c, &p);
    L[i] = {l, c, p};
    R[i] = {r + 1, c, p};
    N = max(N, p);
  }
  sort(L.begin(), L.end(), Comp);
  sort(R.begin(), R.end(), Comp);
  int ul = 0, ur = 0;
  long long ans = 0;
  Tree tree(N);
  for (int i = 1; i <= n; i++) {
    while (ul < m && L[ul].day == i) {
      tree.update(1, 0, tree.size - 1, L[ul].p, L[ul].c);
      ul++;
    }
    while (ur < m && R[ur].day == i) {
      tree.update(1, 0, tree.size - 1, R[ur].p, -1 * R[ur].c);
      ur++;
    }
    pair<int, long long> pos = tree.binary(1, 0, tree.size - 1, k);
    ans += tree.getVal(1, 0, tree.size - 1, 0, pos.first - 1) +
           1ll * pos.first * pos.second;
  }
  printf("%I64d", ans);
}
int main() {
  cin.sync_with_stdio(0);
  cout.sync_with_stdio(0);
  solve();
  return 0;
}
