#include <bits/stdc++.h>
using namespace std;
vector<long long> use[1000005];
struct Node {
  long long l, r;
  long long c, v;
};
Node st[1000005 * 4];
pair<long long, long long> plan[200005];
void Build(long long l, long long r, long long index) {
  st[index].l = l;
  st[index].r = r;
  if (l == r) {
    st[index].c = 0;
    st[index].v = 0;
    return;
  }
  long long mid = (l + r) / 2;
  st[index].c = 0;
  st[index].v = 0;
  Build(l, mid, index * 2);
  Build(mid + 1, r, index * 2 + 1);
}
void updata(long long index, long long target, long long cnt, long long value) {
  if (st[index].l == st[index].r) {
    st[index].c += cnt;
    st[index].v += value;
    return;
  }
  long long mid = st[index * 2].r;
  if (target <= mid) {
    updata(index * 2, target, cnt, value);
  } else {
    updata(index * 2 + 1, target, cnt, value);
  }
  st[index].c = st[index * 2].c + st[index * 2 + 1].c;
  st[index].v = st[index * 2].v + st[index * 2 + 1].v;
  return;
}
long long query(long long index, long long sum_cnt) {
  if (sum_cnt >= st[index].c) {
    return st[index].v;
  }
  if (st[index].l == st[index].r) {
    return st[index].v / st[index].c * sum_cnt;
  }
  long long c_left = st[index * 2].c;
  if (c_left >= sum_cnt) {
    return query(index * 2, sum_cnt);
  } else {
    return st[index * 2].v + query(index * 2 + 1, sum_cnt - c_left);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, k, m;
  cin >> n >> k >> m;
  for (long long i = 1; i <= m; i++) {
    long long l, r, c, p;
    cin >> l >> r >> c >> p;
    plan[i].first = c;
    plan[i].second = p;
    use[l].push_back(i);
    use[r + 1].push_back(-i);
  }
  Build(1, 1000005, 1);
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    if (use[i].size() != 0) {
      for (long long j = 0; j < use[i].size(); j++) {
        long long id = use[i][j];
        if (id > 0) {
          long long c = plan[id].first;
          long long p = plan[id].second;
          updata(1, p, c, p * c);
        } else {
          id = -id;
          long long c = plan[id].first;
          long long p = plan[id].second;
          updata(1, p, -c, -p * c);
        }
      }
    }
    ans += query(1, k);
  }
  cout << ans << endl;
  return 0;
}
