#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long i, j, n, h, m, x, l, r;
  cin >> n >> h >> m;
  long long arr[n + 10];
  for (i = 1; i <= n; i++) arr[i] = h;
  for (i = 1; i <= m; i++) {
    cin >> l >> r >> x;
    for (j = l; j <= r; j++) arr[j] = min(x, arr[j]);
  }
  long long total = 0;
  for (i = 1; i <= n; i++) {
    total += (arr[i] * arr[i]);
  }
  cout << total << endl;
}
