#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int A[a], i;
  for (i = 0; i < a; ++i) {
    A[i] = b;
  }
  int x1, y1, z;
  for (i = 0; i < c; ++i) {
    cin >> x1 >> y1 >> z;
    for (int j = x1 - 1; j < y1; ++j) {
      A[j] = min(A[j], z);
    }
  }
  int tot = 0;
  for (auto x : A) {
    tot += x * x;
  }
  cout << tot << endl;
}
