#include <bits/stdc++.h>
using namespace std;
const int N = 300300;
const int MOD = 2e9 + 7;
int main() {
  ios_base::sync_with_stdio(0);
  int n, b = 0, e = 0, ans = 0, d;
  cin >> n >> b >> e;
  vector<int> v(n + 1, b);
  for (int i = 0; i < e; i++) {
    int x, y, c;
    cin >> x >> y >> c;
    for (int j = x; j <= y; j++) {
      v[j] = min(c, v[j]);
    }
  }
  for (int i = 1; i <= n; i++) {
    ans += v[i] * v[i];
  }
  cout << ans;
}
