#include <bits/stdc++.h>
using namespace std;
int build[55];
bool cmp(int x, int y) { return x > y; }
int main() {
  ios::sync_with_stdio(0);
  int n, h, m;
  int l, r, x, ans = 0;
  cin >> n >> h >> m;
  for (int i = 1; i <= n; i++) build[i] = h;
  for (int i = 1; i <= m; i++) {
    cin >> l >> r >> x;
    for (int i = l; i <= r; i++) build[i] = min(build[i], x);
  }
  for (int i = 1; i <= n; i++) ans += build[i] * build[i];
  cout << ans << endl;
  return 0;
}
