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