#include <bits/stdc++.h>
using namespace std;
double EPS = 1e-9;
int INF = 1e9 + 7;
;
long long INFLL = 1e17;
double pi = acos(-1);
int dirx[8] = {-1, 0, 0, 1, -1, -1, 1, 1};
int diry[8] = {0, 1, -1, 0, -1, 1, -1, 1};
const int maxn = 1e6 + 5;
int n, K, m;
pair<pair<long long, long long>, pair<long long, long long> > arr[maxn];
vector<int> ins[maxn], rem[maxn];
struct BIT {
  long long bit[maxn];
  void upd(int pos, long long v) {
    for (++pos; pos < maxn; pos += pos & -pos) bit[pos] += v;
  }
  long long query(int pos) {
    long long ans = 0;
    for (++pos; pos > 0; pos -= pos & -pos) ans += bit[pos];
    return ans;
  }
  int bit_search(long long v) {
    long long sum = 0;
    int pos = 0;
    for (int i = 20; i >= 0; i--) {
      if (pos + (1 << i) < maxn && sum + bit[pos + (1 << i)] < v) {
        sum += bit[pos + (1 << i)];
        pos += (1 << i);
      }
    }
    return pos + 1;
  }
} core, cost;
int main() {
  cin >> n >> K >> m;
  for (int k = (int)0; k < (int)m; k++) {
    int l, r, c, p;
    cin >> l >> r >> c >> p;
    arr[k] = {{p, c}, {l, r}};
  }
  sort(arr, arr + m);
  for (int k = (int)0; k < (int)m; k++) {
    int l = arr[k].second.first;
    int r = arr[k].second.second;
    ins[l].push_back(k);
    rem[r + 1].push_back(k);
  }
  long long ans = 0;
  for (int k = (int)1; k < (int)n + 1; k++) {
    for (auto x : ins[k]) {
      core.upd(x, arr[x].first.second);
      cost.upd(x, (long long)arr[x].first.first * arr[x].first.second);
    }
    for (auto x : rem[k]) {
      core.upd(x, -arr[x].first.second);
      cost.upd(x, (long long)-arr[x].first.first * arr[x].first.second);
    }
    int x = core.bit_search(K);
    if (x == maxn) {
      ans += cost.query(x - 1);
    } else {
      ans += cost.query(x - 1);
      ans += (long long)arr[x - 1].first.first * (K - core.query(x - 1));
    }
  }
  cout << ans << endl;
}
