#include <bits/stdc++.h>
const long long M = 1e9 + 7;
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, h, m, sum = 0;
  cin >> n >> h >> m;
  vector<long long> v(n, h);
  for (long long i = 0; i < m; i++) {
    long long l, r, x;
    cin >> l >> r >> x;
    for (long long j = l; j <= r; j++) {
      v[j - 1] = min(v[j - 1], x);
    }
  }
  for (long long i = 0; i < n; i++) {
    sum += (v[i] * v[i]);
  }
  cout << sum;
  return 0;
}
