#include <bits/stdc++.h>
using namespace std;
int main() {
  int x, y, z, sum = 0, a, b, c, d[1000];
  cin >> x >> y >> z;
  for (int i = 1; i <= x; i++) d[i] = y;
  for (int i = 1; i <= z; i++) {
    cin >> a >> b >> c;
    for (int j = a; j <= b; j++) {
      d[j] = min(d[j], c);
    }
  }
  for (int i = 1; i <= x; i++) {
    sum = sum + d[i] * d[i];
  }
  cout << sum << endl;
}
