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