#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int n, m, h;
  cin >> n >> h >> m;
  int a[n];
  for (int i = 0; i < n; i++) a[i] = h;
  while (m--) {
    int l, r, x;
    cin >> l >> r >> x;
    l--;
    r--;
    for (int i = l; i <= r; i++) a[i] = min(x, a[i]);
  }
  long long int s = 0;
  for (int i = 0; i < n; i++) s += (a[i] * a[i]);
  cout << s;
}
