#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, h, m;
  cin >> n >> h >> m;
  vector<int> heights(n + 1, h);
  for (int i = 0; i < m; i++) {
    int a, b;
    int x;
    cin >> a >> b >> x;
    for (int j = a; j <= b; j++) {
      heights[j] = min(heights[j], x);
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) ans += (heights[i] * heights[i]);
  cout << ans << "\n";
}
