#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, h, m;
    int v[1000];
    scanf("%d%d%d", &n, &h, &m);
    for (int i = 1; i <= n; i++) v[i] = h;
    for (int i = 0; i < m; i++)
    {
        int l, r, x;
        scanf("%d%d%d", &l, &r, &x);
        for (int j = l; j <= r; j++)
            v[j] = min(v[j], x);
    }
    long long ans = 0;
    for (int i = 1; i <= n; i++) ans += 1ll * v[i] * v[i];
    printf("%lld", ans);
    return 0;
}
