#include <bits/stdc++.h>
using namespace std;
struct hash_pair {
  template <class T1, class T2>
  size_t operator()(const pair<T1, T2> &p) const {
    auto hash1 = hash<T1>{}(p.first);
    auto hash2 = hash<T2>{}(p.second);
    return hash1 ^ hash2;
  }
};
template <class type>
void displaySingle(type &arr) {
  for (auto i : arr) cout << i << " ";
  cout << endl;
}
template <class type>
void displayDouble(type &arr) {
  for (auto i : arr) cout << i.first << " " << i.second << endl;
}
template <class type>
void display2D(type &arr) {
  for (auto i : arr) {
    for (auto j : arr[i]) {
      printf("%d ", j);
    }
    printf("\n");
  }
}
int main() {
  int n, h, r;
  scanf("%d %d %d", &n, &h, &r);
  vector<int> input(n + 1, h);
  for (int i = 0; i < r; i++) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    for (int j = a; j <= b; j++) input[j] = min(input[j], c);
  }
  long long unsigned int sum = 0;
  for (int i = 1; i < input.size(); i++) sum += input[i] * input[i];
  cout << sum << endl;
  return 0;
}
