#include <bits/stdc++.h>
using namespace std;
const int INF = 2000000000;
const double EPS = 1e-9;
int mods(int a, int b) { return (b + (a % b)) % b; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, h, m, l, r, x, ans = 0, restrictions[55];
  cin >> n >> h >> m;
  for (int i = 0; i < n; i++) restrictions[i] = h;
  while (m--) {
    cin >> l >> r >> x;
    l--;
    r--;
    for (int i = l; i <= r; i++) restrictions[i] = min(restrictions[i], x);
  }
  for (int i = 0; i < n; i++) ans += (restrictions[i] * restrictions[i]);
  cout << ans << '\n';
  return 0;
}
