#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cerr.tie(nullptr);
  long long n, h, m;
  cin >> n >> h >> m;
  vector<long long> a(n, h);
  for (long long i = 0; i < m; ++i) {
    long long l, r, x;
    cin >> l >> r >> x;
    --l;
    --r;
    for (long long j = l; j <= r; ++j) a[j] = min(a[j], x);
  }
  long long sol = 0;
  for (auto& i : a) {
    sol += i * i;
  }
  cout << sol << '\n';
}
