You are planning to build housing on a street. There are $n$ spots available on the street on which you can build a house. The spots are labeled from $1$ to $n$ from left to right. In each spot, you can build a house with an integer height between $0$ and $h$.

In each spot, if a house has height $a$, you will gain $a^2$ dollars from it.

The city has $m$ zoning restrictions. The $i$-th restriction says that the tallest house from spots $l_i$ to $r_i$ (inclusive) must be at most $x_i$.

You would like to build houses to maximize your profit. Determine the maximum profit possible.


-----Input-----

The first line contains three integers $n$, $h$, and $m$ ($1 \leq n,h,m \leq 50$) — the number of spots, the maximum height, and the number of restrictions.

Each of the next $m$ lines contains three integers $l_i$, $r_i$, and $x_i$ ($1 \leq l_i \leq r_i \leq n$, $0 \leq x_i \leq h$) — left and right limits (inclusive) of the $i$-th restriction and the maximum possible height in that range.


-----Output-----

Print a single integer, the maximum profit you can make.


-----Examples-----
Input
3 3 3
1 1 1
2 2 3
3 3 2

Output
14

Input
4 10 2
2 3 8
3 4 7

Output
262



-----Note-----

In the first example, there are $3$ houses, the maximum height of a house is $3$, and there are $3$ restrictions. The first restriction says the tallest house between $1$ and $1$ must be at most $1$. The second restriction says the tallest house between $2$ and $2$ must be at most $3$. The third restriction says the tallest house between $3$ and $3$ must be at most $2$.

In this case, it is optimal to build houses with heights $[1, 3, 2]$. This fits within all the restrictions. The total profit in this case is $1^2 + 3^2 + 2^2 = 14$.

In the second example, there are $4$ houses, the maximum height of a house is $10$, and there are $2$ restrictions. The first restriction says the tallest house from $2$ to $3$ must be at most $8$. The second restriction says the tallest house from $3$ to $4$ must be at most $7$.

In this case, it's optimal to build houses with heights $[10, 8, 7, 7]$. We get a profit of $10^2+8^2+7^2+7^2 = 262$. Note that there are two restrictions on house $3$ and both of them must be satisfied. Also, note that even though there isn't any explicit restrictions on house $1$, we must still limit its height to be at most $10$ ($h=10$).

Difficulty: EASY
Tags: Implementation

Starter code:

Solutions:
(n, h, m) = map(int, input().split())
li = [h] * (n + 1)
for _ in range(m):
	(l, r, x) = map(int, input().split())
	for i in range(l, r + 1):
		li[i] = min(li[i], x)
res = 0
for i in range(1, n + 1):
	res += li[i] * li[i]
print(res)


(N, H, M) = map(int, input().split())
L = [0] * M
R = [0] * M
X = [0] * M
for i in range(M):
	(L[i], R[i], X[i]) = map(int, input().split())
ans = 0
i = 1
while i <= N:
	best = H
	for j in range(M):
		if L[j] <= i <= R[j]:
			best = min(best, X[j])
	ans = ans + best * best
	i = i + 1
print(ans)


import sys

def get_array():
	return list(map(int, sys.stdin.readline().split()))

def get_ints():
	return list(map(int, sys.stdin.readline().split()))

def input():
	return sys.stdin.readline().strip()
inf = float('inf')

def main():
	(n, h, m) = get_ints()
	arr = [inf] * n
	for tc in range(m):
		(l, r, x) = get_ints()
		l -= 1
		r -= 1
		for i in range(l, r + 1):
			arr[i] = min(arr[i], x)
	ans = 0
	for i in arr:
		if i == inf:
			ans += h ** 2
		else:
			ans += i ** 2
	print(ans)

def __starting_point():
	main()
__starting_point()


(n, h, m) = map(int, input().split())
a = [h] * n
c = 0
for i in range(m):
	(l, r, x) = map(int, input().split())
	for j in range(l - 1, r):
		a[j] = min(h, x, a[j])
for i in a:
	c += i * i
print(c)


(n, h, m) = map(int, input().split())
t = [h for x in range(n)]
for i in range(m):
	(l, r, mh) = map(int, input().split())
	for i in range(l - 1, r):
		t[i] = min(t[i], mh)
print(sum(map(lambda p: p * p, t)))


(n, h, m) = [int(i) for i in input().split()]
a = [h] * n
for _ in range(m):
	(l, r, x) = [int(i) for i in input().split()]
	for j in range(l - 1, r):
		a[j] = min(a[j], x)
print(sum([i * i for i in a]))


ln = [int(i) for i in input().split(' ')]
n = ln[0]
h = ln[1]
m = ln[2]
r = [h] * n
for i in range(0, m):
	ln = [int(i) for i in input().split(' ')]
	for j in range(ln[0], ln[1] + 1):
		r[j - 1] = min(r[j - 1], ln[2])
s = 0
for i in r:
	s += i * i
print(s)


(n, h, m) = map(int, input().split())
tab = []
i = 0
for i in range(n):
	tab.append(h)
k = 0
i = 0
j = 0
for i in range(m):
	(l, r, x) = map(int, input().split())
	while l <= r:
		tab[l - 1] = min(tab[l - 1], x)
		l = l + 1
l = 0
for j in range(n):
	l = tab[j] ** 2 + l
print(l)


(n, h, m) = map(int, input().split())
d = [h] * n
s = 0
for i in range(m):
	(l, r, x) = map(int, input().split())
	for i in range(l - 1, r):
		d[i] = min(d[i], x)
for i in d:
	s += i * i
print(s)


(n, h, m) = list(map(int, input().strip().split()))
res = []
for _ in range(m):
	(l, r, x) = list(map(int, input().strip().split()))
	res.append((l, r, x))
spots = [h] * (n + 1)
for (l, r, x) in res:
	for j in range(l, r + 1):
		spots[j] = min(x, spots[j])
profit = 0
for i in range(1, len(spots)):
	profit += spots[i] ** 2
print(profit)


(n, h, m) = map(int, input().split())
height = [h] * n
for _ in range(m):
	(l, r, x) = map(int, input().split())
	for i in range(l - 1, r):
		if x < height[i]:
			height[i] = x
height = [height[i] * height[i] for i in range(n)]
print(sum(height))


(n, h, m) = map(int, input().split())
a = [list(map(int, input().split())) for i in range(m)]
b = [int(h) for i in range(n)]
for i in range(m):
	for j in range(a[i][0] - 1, a[i][1]):
		b[j] = min(a[i][2], b[j])
ans = 0
for i in range(len(b)):
	ans = ans + b[i] ** 2
print(ans)


(n, h, m) = map(int, input().split())
amh = [h] * n
for _ in range(m):
	(l, r, x) = map(int, input().split())
	for i in range(l - 1, r):
		amh[i] = min(amh[i], x)
ans = 0
for x in amh:
	ans += x ** 2
print(ans)


(n, h, m) = list(map(int, input().split()))
maksi = [h] * n
tab = [[] for i in range(m)]
for i in range(m):
	tab[i] = list(map(int, input().split()))
for i in range(m):
	l = tab[i][0]
	r = tab[i][1]
	for j in range(l - 1, r):
		maksi[j] = min(maksi[j], tab[i][2])
wyn = 0
for i in range(n):
	wyn += maksi[i] ** 2
print(wyn)


(n, h, m) = [int(t) for t in input().split(' ')]
limit = [h] * n
for _ in range(m):
	(l, r, x) = [int(t) for t in input().split(' ')]
	l -= 1
	r -= 1
	for i in range(l, r + 1):
		limit[i] = min(limit[i], x)
print(sum((a ** 2 for a in limit)))


IL = lambda : list(map(int, input().split()))
(n, h, m) = IL()
R = [h] * n
for i in range(m):
	(l, r, x) = IL()
	for j in range(l - 1, r):
		R[j] = min(R[j], x)
print(sum((r ** 2 for r in R)))


(n, h, m) = map(int, input().split())
lrxi = [list(map(int, input().split())) for i in range(m)]
houses = [h] * (n + 1)
for i in range(m):
	for j in range(lrxi[i][0], lrxi[i][1] + 1):
		houses[j] = min(houses[j], lrxi[i][2])
ans = 0
for i in range(1, n + 1):
	ans += houses[i] ** 2
print(ans)


X = list(map(int, input().split()))
House = [X[1] for i in range(X[0])]
for i in range(X[2]):
	Temp = list(map(int, input().split()))
	for j in range(Temp[0] - 1, Temp[1]):
		House[j] = min(House[j], Temp[2])
print(sum((i ** 2 for i in House)))


(n, h, m) = map(int, input().split())
l = []
r = []
x = []
for i in range(m):
	(tl, tr, tx) = map(int, input().split())
	l.append(tl)
	r.append(tr)
	x.append(tx)
d = dict()
for i in range(1, n + 1):
	d[i] = h
for i in range(len(l)):
	for j in range(l[i], r[i] + 1):
		d[j] = min(d[j], x[i])
ans = 0
for i in d.keys():
	ans = ans + d[i] ** 2
print(ans)


import sys
input = sys.stdin.readline
(n, h, m) = map(int, input().split())
arr = []
for i in range(n):
	arr.append(h)
for i in range(m):
	(l, r, x) = map(int, input().split())
	for j in range(l - 1, r):
		arr[j] = min(arr[j], x)
count = 0
for i in range(n):
	count += arr[i] ** 2
print(count)


def build(p, i, j):
	if i == j:
		tree[p] = h ** 2
	else:
		c = (i + j) // 2
		build(p * 2 + 1, i, c)
		build(p * 2 + 2, c + 1, j)
		tree[p] = tree[p * 2 + 1] + tree[p * 2 + 2]

def updateRange(n, i, j, l, r, x):
	if i > j or i > r or j < l:
		return
	if i == j:
		tree[n] = tree[n] if tree[n] < x ** 2 else x ** 2
		return
	m = (i + j) // 2
	updateRange(n * 2 + 1, i, m, l, r, x)
	updateRange(n * 2 + 2, m + 1, j, l, r, x)
	tree[n] = tree[n * 2 + 1] + tree[n * 2 + 2]
(n, h, m) = map(int, input().split())
tree = [0] * n * 8
build(0, 0, n - 1)
for i in range(m):
	(l, r, x) = map(int, input().split())
	updateRange(0, 0, n - 1, l - 1, r - 1, x)
print(tree[0])


(n, h, m) = list(map(int, input().split()))
ans = [h] * n
for i in range(m):
	(l, r, x) = list(map(int, input().split()))
	for j in range(l - 1, r):
		ans[j] = min(ans[j], x)
cnt = 0
for i in range(n):
	cnt += ans[i] * ans[i]
print(cnt)


(n, h, m) = map(int, input().split())
spots = [h for _ in range(n)]
for _ in range(m):
	(l, r, x) = map(int, input().split())
	l -= 1
	for i in range(l, r):
		if spots[i] > x:
			spots[i] = x
profit = 0
for ht in spots:
	profit += ht ** 2
print(profit)


from math import *
(n, h, m) = list(map(int, input().split(' ')))
a = list()
for i in range(n):
	a.append(h)
for j in range(1, m + 1):
	(l, r, x) = list(map(int, input().split(' ')))
	for li in range(l - 1, r):
		if x <= h:
			a[li] = min(x, a[li])
lk = 0
for k in range(n):
	lk = lk + a[k] * a[k]
print(lk)


(n, h, m) = map(int, input().split())
ans = [-1] * (n + 1)
while m:
	(l, r, x) = map(int, input().split())
	for i in range(l, r + 1):
		if ans[i] == -1:
			ans[i] = x ** 2
		elif ans[i] > x ** 2:
			ans[i] = x ** 2
	m -= 1
for i in range(1, n + 1):
	if ans[i] == -1:
		ans[i] = h ** 2
print(sum(ans[1:]))


l = list(map(int, input().split()))
lp = []
for _ in range(l[2]):
	l1 = list(map(int, input().split()))
	lp.append(l1)
h_list = [l[1]] * l[0]
for i in lp:
	for j in range(i[0] - 1, i[1]):
		if h_list[j] > i[2]:
			h_list[j] = i[2]
su = 0
for i in h_list:
	su += i ** 2
print(su)


(n, h, m) = map(int, input().strip().split())
restriction = [h] * (n + 2)
profit = 0
for i in range(m):
	(l, r, x) = map(int, input().strip().split())
	for i in range(l, r + 1):
		restriction[i] = min(restriction[i], x)
for i in range(1, n + 1):
	profit += restriction[i] ** 2
print(profit)


(n, h, m) = [int(i) for i in input().split(' ')]
houses = [h] * n
for i in range(m):
	(l, r, x) = [int(i) for i in input().split(' ')]
	for i in range(l, r + 1):
		if houses[i - 1] > x:
			houses[i - 1] = x
s = 0
for i in houses:
	s += i ** 2
print(s)


(n, h, m) = list(map(int, input().strip().split()))
buil = [h] * n
for i in range(m):
	(l, r, x) = list(map(int, input().strip().split()))
	for j in range(l - 1, r):
		buil[j] = min(buil[j], x)
op = 0
for i in buil:
	op += i * i
print(op)


def main():
	(n, h, m) = map(int, input().split())
	ls = [h for i in range(n)]
	for i in range(m):
		(a, b, c) = map(int, input().split())
		for j in range(a - 1, b):
			ls[j] = min(ls[j], c)
	ans = 0
	for i in ls:
		ans += i * i
	print(ans)
main()


(n, h, m) = map(int, input().split())
l = [h ** 2] * n
for i in range(m):
	(a, b, c) = map(int, input().split())
	for j in range(a - 1, b):
		l[j] = min(c ** 2, l[j])
print(sum(l))


(n, maxh, rest) = list(map(int, input().strip().split()))
a = [maxh] * n
for i in range(rest):
	(l, r, m) = list(map(int, input().strip().split()))
	for i in range(l - 1, r):
		a[i] = min(a[i], m)
print(sum((i * i for i in a)))


(n, h, m) = [int(x) for x in input().split()]
houses = [h] * n
for i in range(m):
	(l, r, x) = [int(x) for x in input().split()]
	for j in range(l - 1, r):
		houses[j] = min(houses[j], x)
mx = 0
for j in range(n):
	mx += houses[j] * houses[j]
print(mx)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(a, b):
	ans = 1
	while b > 0:
		if b % 2 == 1:
			ans *= a
		a *= a
		b //= 2
	return ans

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def solve():
	(n, h, m) = sep()
	arr = [h] * n
	for i in range(m):
		(l, r, x) = sep()
		l -= 1
		r -= 1
		for j in range(l, r + 1):
			arr[j] = min(arr[j], x)
	ans = 0
	for i in range(n):
		ans += arr[i] ** 2
	print(ans)
testcase(1)


(n, h, m) = map(int, input().split())
spots = [h for x in range(n)]
for s in range(m):
	(l, r, x) = map(int, input().split())
	if l == r:
		spots[l - 1] = x if spots[l - 1] > x else spots[l - 1]
	else:
		for v in range(l - 1, r - 1 + 1):
			if spots[v] > x:
				spots[v] = x
res = 0
for k in spots:
	res += k * k
print(res)


def main_function():
	(n, h, m) = [int(i) for i in input().split(' ')]
	restrictions = [[int(i) for i in input().split(' ')] for i in range(m)]
	houses = [h for i in range(n)]
	profit = 0
	for i in restrictions:
		for d in range(i[0], i[1] + 1):
			if i[2] < houses[d - 1]:
				houses[d - 1] = i[2]
	for i in houses:
		profit += i ** 2
	return profit
print(main_function())


(n, h, m) = list((int(a) for a in input().split()))
row = list((h for _ in range(n)))
for _ in range(m):
	(l, r, x) = list((int(a) for a in input().split()))
	for i in range(l - 1, r):
		if x < row[i]:
			row[i] = x
r = sum((x ** 2 for x in row))
print(r)


def main():
	(n, h, m) = map(int, input().strip().split())
	restricts = [list(map(int, input().strip().split())) for _ in range(m)]
	houses = list()
	for house in range(1, n + 1):
		house_height = h
		for (l, r, x) in restricts:
			if house >= l and house <= r:
				house_height = min(house_height, x)
		houses.append(house_height ** 2)
	print(sum(houses))
main()


(n, h, m) = map(int, input().split())
ans = 0
A = [h for i in range(n)]
for i in range(m):
	(a, b, x) = map(int, input().split())
	for i in range(a - 1, b):
		A[i] = min(x, A[i])
for i in A:
	ans += i ** 2
print(ans)


(n, h, m) = map(int, input().split())
s = [h] * n
for i in range(m):
	(l, r, x) = map(int, input().split())
	for j in range(l, r + 1):
		if x < s[j - 1]:
			s[j - 1] = x
ans = 0
for i in range(n):
	ans += s[i] * s[i]
print(ans)


n_h_m = input().split()
n = int(n_h_m[0])
h = int(n_h_m[1])
m = int(n_h_m[2])
max_h = [h for _ in range(n)]
for i in range(m):
	l_r_x = input().split()
	l = int(l_r_x[0])
	r = int(l_r_x[1])
	x = int(l_r_x[2])
	for j in range(l - 1, r):
		if max_h[j] > x:
			max_h[j] = x
r = 0
for num in max_h:
	r += num * num
print(r)


(n, h, m) = map(int, input().split())
a = [h] * n
for i in range(m):
	(l, r, x) = map(int, input().split())
	for i in range(l - 1, r):
		a[i] = min(a[i], x)
ans = 0
for elem in a:
	ans += elem ** 2
print(ans)


(n, h, m) = (int(x) for x in input().split())
cost = [h] * (n + 1)
for i in range(m):
	(l, r, hh) = (int(x) for x in input().split())
	for j in range(l, r + 1):
		if cost[j] > hh:
			cost[j] = hh
sum = 0
for i in range(1, len(cost)):
	sum += cost[i] ** 2
print(sum)


(n, h, m) = input().split()
A = []
for i in range(0, int(n)):
	A.append(int(h))
for i in range(0, int(m)):
	(l, r, x) = input().split()
	l = int(l)
	r = int(r)
	x = int(x)
	q = l - 1
	while q < r:
		if A[q] >= x:
			A[q] = x
		q += 1
sum = 0
for z in A:
	sum += z * z
print(sum)


import atexit
import io
import sys
_I_B = sys.stdin.read().splitlines()
input = iter(_I_B).__next__
_O_B = io.StringIO()
sys.stdout = _O_B

@atexit.register
def write():
	sys.__stdout__.write(_O_B.getvalue())

def main():
	(n, h, m) = map(int, input().split())
	a = [h] * n
	for _ in range(m):
		(l, r, x) = map(int, input().split())
		for i in range(l - 1, r):
			a[i] = min(a[i], x)
	s = 0
	for i in a:
		s += i * i
	print(s)
main()


(n, h, m) = input().strip().split(' ')
n = int(n)
h = int(h)
m = int(m)
home = [h for i in range(n)]
for i in range(m):
	(a, b, x) = input().strip().split(' ')
	a = int(a)
	b = int(b)
	x = int(x)
	a -= 1
	b -= 1
	while a <= b:
		if home[a] > x:
			home[a] = x
		a += 1
sum = 0
for i in range(n):
	sum += home[i] * home[i]
print(sum)


(n, h, m) = map(int, input().split())
houses = [h for i in range(n)]
for i in range(m):
	(l, r, x) = map(int, input().split())
	for i in range(l - 1, r):
		houses[i] = min(x, houses[i])
ans = 0
for house in houses:
	ans += house ** 2
print(ans)


(n, h, m) = [int(thing) for thing in input().split()]
max_profit = 0
dictionary = {}
for i in range(1, n + 1):
	dictionary[i] = 3.14
for i in range(m):
	(l, r, x) = [int(thing) for thing in input().split()]
	for this in range(l, r + 1):
		if dictionary[this] is not 3.14:
			if dictionary[this] > x:
				dictionary[this] = x
		else:
			dictionary[this] = x
for that in range(1, n + 1):
	if dictionary[that] is 3.14:
		max_profit += h ** 2
	else:
		max_profit += dictionary[that] ** 2
print(max_profit)


from math import *
from itertools import *
(n, h, m) = map(int, input().split(' '))
a = [h] * n
for i in range(m):
	(l, r, x) = map(int, input().split(' '))
	for k in range(l - 1, r):
		a[k] = min(a[k], x)
mx = 0
for i in a:
	mx += i * i
print(mx)


import sys
sys.setrecursionlimit(10000)
input = sys.stdin.readline

def linp():
	return list(map(int, input().split()))

def mapinp():
	return map(int, input().split())
out = sys.stdout.write
(n, h, m) = mapinp()
arr = [h] * n
for _ in range(m):
	(l, r, val) = mapinp()
	for i in range(l - 1, r):
		if val < arr[i]:
			arr[i] = val
ans = sum(map(lambda x: x ** 2, arr))
print(ans)


(n, h, m) = map(int, input().split())
arr = [h] * n
for _ in range(m):
	(l, r, x) = map(int, input().split())
	l -= 1
	r -= 1
	for i in range(l, r + 1):
		arr[i] = min(arr[i], x)
print(sum([x * x for x in arr]))


from sys import stdin
(n, h, m) = map(int, stdin.readline().strip().split())
max_heights = [h] * n
for _ in range(m):
	(l, r, max_height) = map(int, stdin.readline().strip().split())
	for i in range(l - 1, r):
		max_heights[i] = min(max_heights[i], max_height)
max_profit = 0
for height in max_heights:
	max_profit += height * height
print(max_profit)


(n, h, m) = [int(i) for i in input().split()]
t = [h for _ in range(n)]
for _ in range(m):
	(l, r, x) = [int(j) for j in input().split()]
	for a in range(l - 1, r):
		t[a] = min(t[a], x)
print(sum(map(lambda w: w * w, t)))


(n, h, m) = map(int, input().split())
k = []
total = 0
for _ in range(m):
	k.append(list(map(int, input().split())))
for i in range(n):
	o = h
	for l in range(m):
		if k[l][0] <= i + 1 <= k[l][1]:
			if k[l][2] <= o:
				o = k[l][2]
	total += o ** 2
print(total)


(n, h, m) = map(int, input().split())
ans = [h for _ in range(n)]
for i in range(m):
	(a, b, c) = map(int, input().split())
	(a, b) = (a - 1, b - 1)
	for j in range(a, b + 1):
		ans[j] = min(c, ans[j])
ans_s = 0
for item in ans:
	ans_s += item * item
print(ans_s)


x = input().split()
for i in range(0, 3):
	x[i] = int(x[i])
h = [x[1]] * x[0]
for i in range(0, x[2]):
	a = input().split()
	for j in range(0, 3):
		a[j] = int(a[j])
	r = int(a[0]) - 1
	for jj in range(r, a[1]):
		h[jj] = min(h[jj], a[2])
ans = 0
for i in range(0, x[0]):
	ans += h[i] * h[i]
print(ans)


import os
import heapq
import sys, threading
import math
import bisect
import operator
from collections import defaultdict
sys.setrecursionlimit(10 ** 5)
from io import BytesIO, IOBase

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def power(x, p, m):
	res = 1
	while p:
		if p & 1:
			res = res * x % m
		x = x * x % m
		p >>= 1
	return res

def inar():
	return [int(k) for k in input().split()]

def lcm(num1, num2):
	return num1 * num2 // gcd(num1, num2)

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def main():
	(n, h, m) = inar()
	freq = [-1] * (n + 1)
	take = []
	for i in range(m):
		take.append(list(map(int, input().split())))
	take = sorted(take, key=lambda x: x[2])
	for i in range(m):
		for j in range(take[i][0], take[i][1] + 1):
			if freq[j] == -1:
				freq[j] = take[i][2]
	ans = 0
	for i in range(1, n + 1):
		if freq[i] == -1:
			ans += h * h
		else:
			ans += freq[i] ** 2
	print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import io, sys, atexit, os
import math as ma
from sys import exit
from decimal import Decimal as dec
from itertools import permutations
from random import randint as rand

def li():
	return list(map(int, input().split()))

def num():
	return map(int, input().split())

def nu():
	return int(input())

def find_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def lcm(x, y):
	gg = find_gcd(x, y)
	return x * y // gg
mm = 1000000007
yp = 0

def solve():
	t = 1
	for _ in range(t):
		(n, h, m) = num()
		a = [99999999] * (n + 2)
		for i in range(m):
			(x, y, z) = num()
			for j in range(x, y + 1):
				a[j] = min(a[j], z * z)
		ss = 0
		for i in range(1, n + 1):
			if a[i] == 99999999:
				ss += h * h
			else:
				ss += a[i]
		print(ss)
solve()


(n, h, m) = map(int, input().split())
a = [0] * m
b = [0] * m
c = [0] * m
for i in range(0, m):
	(a[i], b[i], c[i]) = map(int, input().split())
p = [h] * n
for i in range(0, n):
	for j in range(0, m):
		if a[j] <= i + 1 <= b[j] and c[j] <= p[i]:
			p[i] = c[j]
s = 0
for i in range(0, n):
	s = s + p[i] * p[i]
print(s)


(n, h, m) = map(int, input().split())
A = []
B = []
C = n * [h]
s = 0
for i in range(m):
	A.append(list(map(int, input().split())))
for j in range(m):
	for k in range(A[j][0] - 1, A[j][1]):
		C[k] = min(C[k], A[j][2])
for p in range(n):
	s += C[p] ** 2
print(s)


(n, h, m) = map(int, input().split())
finals = [h for i in range(n)]
for i in range(m):
	(l, r, x) = map(int, input().split())
	for i in range(l - 1, r):
		finals[i] = min(finals[i], x)
print(sum(map(lambda w: w * w, finals)))


(n, h, m) = map(int, input().split())
a = [h] * (n + 1)
a[0] = 0
for _ in range(m):
	(l, r, x) = map(int, input().split())
	for j in range(l, r + 1):
		a[j] = min(x, a[j])
print(sum([e * e for e in a]))


def main():
	(n, h, m) = list(map(int, input().split()))
	restrictions = [h for _ in range(n)]
	for i in range(m):
		(l, r, x) = list(map(int, input().split()))
		for j in range(l, r + 1):
			restrictions[j - 1] = min(restrictions[j - 1], x)
	res = 0
	for x in range(n):
		res += restrictions[x] ** 2
	print(res)

def __starting_point():
	main()
__starting_point()


(n, h, m) = map(int, input().split())
u = [h] * n
for i in range(m):
	(l, r, x) = map(int, input().split())
	for j in range(l - 1, r):
		if u[j] == h:
			u[j] = x
		else:
			u[j] = min(u[j], x)
ans = 0
for i in range(n):
	ans += u[i] * u[i]
print(ans)


(n, h, m) = list(map(int, input().split()))
sum1 = 0
a = [h] * (n + 1)
a[0] = 0
for i in range(m):
	(l, r, x) = list(map(int, input().split()))
	for j in range(l, r + 1):
		a[j] = min(a[j], x)
for i in a:
	sum1 += i ** 2
print(sum1)


import sys

def main():
	inp = list(map(int, sys.stdin.read().strip().split()))
	l = [inp[1]] * inp[0]
	for i in range(3, len(inp), 3):
		(m, n, h) = inp[i:i + 3]
		for j in range(m - 1, n):
			if h < l[j]:
				l[j] = h
	return sum((i ** 2 for i in l))
print(main())


(n, h, m) = map(int, input().split())
high = [h] * 100
for i in range(m):
	(l, r, x) = map(int, input().split())
	for j in range(l, r + 1):
		high[j] = min(high[j], x)
ans = 0
for i in range(1, n + 1):
	ans = ans + high[i] ** 2
print(ans)


(n, h, m) = map(int, input().split())
dom = [h] * (n + 1)
for y in range(m):
	(l, r, h) = map(int, input().split())
	for i in range(l, r + 1):
		dom[i] = min(dom[i], h)
otv = 0
for i in range(1, n + 1):
	otv += dom[i] ** 2
print(otv)


(n, h, m) = map(int, input().split())
a = []
ans = 0
for i in range(n):
	a.append(h)
for i in range(m):
	(x, y, z) = map(int, input().split())
	for j in range(x - 1, y, 1):
		if a[j] > z:
			a[j] = z
for i in range(n):
	ans += a[i] * a[i]
print(ans)


(n, h, m) = tuple(map(int, input().split()))
mas = [h] * n
for i in range(m):
	(l, r, x) = tuple(map(int, input().split()))
	for j in range(l - 1, r):
		mas[j] = min(mas[j], x)
print(sum([i * i for i in mas]))


(n, h, m) = list(map(int, input().split()))
l = []
r = []
x = []
for i in range(m):
	(L, R, X) = list(map(int, input().split()))
	l.append(L)
	r.append(R)
	x.append(X)
t = [h ** 2] * n
for j in range(len(l)):
	for k in range(l[j] - 1, r[j]):
		t[k] = min(t[k], x[j] ** 2)
print(sum(t))


def main():
	(n, h, m) = map(int, input().split())
	rest = []
	for i in range(m):
		(l, r, x) = map(int, input().split())
		rest.append((l, r, x))
	rest.sort()
	ans = [float('inf')] * n
	for i in range(rest[0][0]):
		ans[i] = h
	max_right = 0
	for i in range(m):
		(l, r, x) = (rest[i][0], rest[i][1], rest[i][2])
		for j in range(l - 1, r):
			ans[j] = min(ans[j], x)
		max_right = max(max_right, r)
	for i in range(max_right, n):
		ans[i] = h
	profit = 0
	for i in ans:
		profit += i ** 2
	print(profit)
main()


S = input().split()
N = int(S[0])
H = int(S[1])
M = int(S[2])
places = [H] * N
for i in range(0, M):
	S = input().split()
	start = int(S[0])
	end = int(S[1])
	height = int(S[2])
	for j in range(start - 1, end):
		places[j] = min(places[j], height)
sum = 0
for i in places:
	sum += i * i
print(sum)


from math import *
from collections import *
from bisect import *
import sys
input = sys.stdin.readline
t = 1
while t:
	t -= 1
	(n, h, m) = map(int, input().split())
	r = []
	for i in range(m):
		(l, r1, x) = map(int, input().split())
		r.append([l, r1, x])
	r.sort()
	st = 1
	i = 0
	rr = 0
	while st <= n:
		ss = h
		for i in range(m):
			if st >= r[i][0] and st <= r[i][1]:
				ss = min(ss, r[i][2])
		rr += ss * ss
		st += 1
	print(rr)


import math
from decimal import *
getcontext().prec = 30
(n, h, m) = map(int, input().split())
a = [h * h] * (n + 1)
for i in range(m):
	(l, r, h1) = map(int, input().split())
	for j in range(l, r + 1):
		a[j] = min(a[j], h1 * h1)
ans = sum(a) - a[0]
print(ans)


(n, h, m) = list(map(int, input().split()))
arr = [h for i in range(n)]
for i in range(m):
	(l, r, d) = list(map(int, input().split()))
	l -= 1
	for j in range(l, r):
		arr[j] = min(arr[j], d)
ans = 0
for i in arr:
	ans += i ** 2
print(ans)


(n, h, m) = map(int, input().strip().split())
zone_list = []
height_max = [h for _ in range(n)]
for _ in range(m):
	(l, r, x) = map(int, input().strip().split())
	zone_list.append((l, r, x))
	for i in range(l, r + 1):
		height_max[i - 1] = min(height_max[i - 1], x)
profit = 0
for i in range(n):
	profit += height_max[i] ** 2
print(profit)


(n, h, r) = map(int, input().split(' '))
house = {x: h for x in range(1, n + 1)}
for _ in range(r):
	(l, r, x) = map(int, input().split(' '))
	for i in range(l, r + 1):
		if x < house[i]:
			house[i] = x
s = 0
for i in range(1, n + 1):
	s += house[i] ** 2
print(s)


import sys
line1 = input()
line1 = line1.split()
n = int(line1[0])
h = int(line1[1])
m = int(line1[2])
profit = []
for i in range(0, n):
	profit.append(h)
for i in range(0, m):
	line = input()
	lines = line.split()
	l = int(lines[0])
	r = int(lines[1])
	x = int(lines[2])
	for j in range(l - 1, r):
		profit[j] = min(x, profit[j])
total = 0
for i in range(0, n):
	total += profit[i] * profit[i]
print(total)


nhr = input().split()
n = int(nhr[0])
h = int(nhr[1])
r = int(nhr[2])
l = n * [h]
for i in range(r):
	s = input().split()
	for i in range(int(s[0]) - 1, int(s[1])):
		if int(s[2]) < l[i]:
			l[i] = int(s[2])
su = 0
for i in range(n):
	su += l[i] ** 2
print(su)


I = lambda : map(int, input().split())
(n, h, m) = I()
A = [h] * n
for _ in range(m):
	(L, R, x) = I()
	for i in range(L - 1, R):
		A[i] = min(x, A[i])
print(sum((a * a for a in A)))


from math import *
from collections import *
(n, h, m) = map(int, input().split())
a = [h for i in range(n)]
for i in range(m):
	(u, v, x) = map(int, input().split())
	for j in range(u - 1, v):
		a[j] = min(a[j], x)
ans = 0
for i in a:
	ans += i * i
print(ans)


(n, h, m) = [int(i) for i in input().split()]
a = []
for i in range(n):
	a.append(h)
for i in range(m):
	b = [int(i) - 1 for i in input().split()]
	for j in range(b[0], b[1] + 1):
		if a[j] > b[2] + 1:
			a[j] = b[2] + 1
s = 0
for i in a:
	s += i * i
print(s)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
(n, h, m) = map(int, input().split())
a = [h] * n
for i in range(m):
	(l, r, x) = map(int, input().split())
	for j in range(l - 1, r):
		a[j] = min(a[j], x)
su = 0
for i in range(n):
	su += a[i] * a[i]
print(su)


(n, h, m) = [int(i) for i in input().split()]
a = [h] * n
for I in range(m):
	(l, r, x) = [int(i) for i in input().split()]
	if x <= h:
		for i in range(l - 1, r):
			a[i] = min(a[i], x)
ans = 0
for i in a:
	ans += i ** 2
print(ans)


(n, h, m) = map(int, input().split())
opm = []
for i in range(n):
	opm.append(h)
for i in range(m):
	(a, b, c) = map(int, input().split())
	for j in range(a - 1, b):
		if c < opm[j]:
			opm[j] = c
apm = []
for item in opm:
	apm.append(item ** 2)
print(sum(apm))


(N, h, M) = map(int, input().split())
a = 0
A = [0]
for n in range(0, N):
	A.append(h)
for m in range(0, M):
	(l, r, x) = map(int, input().split())
	for k in range(l, r + 1):
		A[k] = min(A[k], x)
for i in A:
	a = a + i ** 2
print(a)


from itertools import repeat
import math
(n, h, m) = map(int, input().split())
hs = list(repeat(h, n))
for i in range(m):
	(l, r, x) = map(int, input().split())
	for j in range(l, r + 1):
		if hs[j - 1] > x:
			hs[j - 1] = x
rs = [i ** 2 for i in hs]
res = sum(rs)
print(res)


import math

def solve():
	(n, h, m) = map(int, input().split())
	lst = [h for i in range(n)]
	for i in range(m):
		(l, r, x) = map(int, input().split())
		l -= 1
		for i in range(l, r):
			lst[i] = min(lst[i], x)
	profit = 0
	for i in lst:
		profit += i * i
	print(profit)
	return
t = 1
while t > 0:
	t -= 1
	solve()


(n, h, m) = map(int, input().split())
cnt = 0
arr = []
for i in range(n + 1):
	arr.append(h)
while m > 0:
	(l, r, x) = map(int, input().split())
	for i in range(l, r + 1):
		arr[i] = min(arr[i], x)
	m -= 1
for i in range(1, n + 1):
	cnt += arr[i] ** 2
print(cnt)


from math import *
from cmath import *
from itertools import *
from decimal import *
from fractions import *
from sys import *
for _ in range(1):
	(n, h, m) = map(int, input().split())
	a = [h] * n
	ans = 0
	for x in range(m):
		(l, r, k) = map(int, input().split())
		for y in range(l, r + 1):
			a[y - 1] = min(a[y - 1], k)
	for x in range(n):
		ans += a[x] * a[x]
	print(ans)


from collections import defaultdict
d = defaultdict(list)
(n, H, m) = map(int, input().strip().split())
for i in range(m):
	(a, b, h) = map(int, input().strip().split())
	for j in range(a, b + 1):
		d[j].append(h)
sums = 0
for i in range(1, n + 1):
	if i not in d:
		sums += pow(H, 2)
	else:
		sums += pow(min(d[i]), 2)
print(sums)


(n, h, m) = map(int, input().split())
A = []
for i in range(n):
	A.append(h)
for i in range(m):
	(l, r, x) = map(int, input().split())
	for j in range(l - 1, r):
		A[j] = min(x, A[j])
ans = 0
for i in range(n):
	ans += A[i] ** 2
print(ans)


(n, h, m) = [int(x) for x in input().split(' ')]
a = [h] * n
for i in range(m):
	(li, ri, xi) = [int(x) for x in input().split(' ')]
	for j in range(li, ri + 1):
		if xi < a[j - 1]:
			a[j - 1] = xi
cnt = 0
for x in a:
	cnt += x ** 2
print(cnt)


(n, h, m) = map(int, input().split())
ar = [0] + [h] * n
for i in range(m):
	(l, r, x) = map(int, input().split())
	for i in range(l, r + 1):
		ar[i] = min(ar[i], x)
print(sum(map(lambda x: x ** 2, ar)))


import sys
from math import ceil
input = sys.stdin.readline
(n, h, m) = map(int, input().split())
houses = [h for i in range(n + 1)]
for i in range(m):
	(l, r, x) = map(int, input().split())
	for j in range(l, r + 1):
		houses[j] = min(houses[j], x)
houses.pop(0)
print(sum([x * x for x in houses]))


(N, H, M) = map(int, input().split())
st = [H] * (N + 1)
for _ in range(M):
	(l, r, x) = map(int, input().split())
	for i in range(l, r + 1):
		st[i] = min(st[i], x)
print(sum((a ** 2 for a in st[1:])))


(n, h, m) = map(int, input().split())
q = [i for i in range(1, n + 1)]
z = []
d = dict()
for i in range(m):
	(l, r, x) = map(int, input().split())
	for i in range(l, r + 1):
		if i in q:
			q.remove(i)
		if i in d:
			if d[i] > x:
				d[i] = x
		else:
			d[i] = x
s = len(q) * (h * h)
for i in d:
	s = s + d[i] * d[i]
print(s)


values = input()
(n, h, m) = values.split()
houses = list()
h2 = list()
for i in range(int(n)):
	houses.append(int(h))
for i in range(int(m)):
	val = input()
	(l, r, x) = val.split()
	for j in range(int(l) - 1, int(r)):
		if houses[j] > int(x):
			houses[j] = int(x)
for num in houses:
	h2.append(num ** 2)
print(sum(h2))


(nb_house, max_height, nb_restriction) = [int(x) for x in input().split()]
heights = [max_height] * nb_house
for _ in range(nb_restriction):
	(l, r, mh) = [int(x) for x in input().split()]
	for i in range(l - 1, r):
		heights[i] = min(heights[i], mh)
profit = sum([x * x for x in heights])
print(profit)


(n, h, m) = map(int, input().strip().split())
restrictions = []
for i in range(m):
	restrictions.append([int(i) for i in input().strip().split()])
ans = 0
check = []
for i in range(1, n + 1):
	in_range = False
	current_max = h
	for res in restrictions:
		if res[0] <= i <= res[1]:
			in_range = True
			if res[2] < current_max:
				current_max = res[2]
	if not in_range:
		ans += h * h
		check.append(h)
	else:
		check.append(current_max)
		ans += current_max * current_max
print(ans)


(n, h, m) = map(int, input().split())
a = []
d = {}
su = 0
for i in range(m):
	(x, y, z) = map(int, input().split())
	for j in range(x, y + 1):
		if j in d:
			d[j] = min(d[j], z)
		else:
			d[j] = z
for i in range(n):
	if i + 1 in d:
		su += d[i + 1] ** 2
	else:
		su += h ** 2
print(su)


(n, h, m) = map(int, input().split())
hmax = [h] * (n + 1)
for j in range(m):
	(l, r, x) = map(int, input().split())
	for i in range(l, r + 1):
		hmax[i] = min(hmax[i], x)
res = 0
for i in range(1, n + 1):
	res += hmax[i] * hmax[i]
print(res)


z = [int(n) for n in input().split()]
s = [z[1] for n in range(z[0])]
for n in range(z[2]):
	d = [int(n) for n in input().split()]
	for n in range(d[0] - 1, d[1]):
		s[n] = d[2] if s[n] > d[2] else s[n]
m = 0
for n in s:
	m += n ** 2
print(m)


(n, h, m) = (int(i) for i in input().split())
buildings = [h for i in range(n + 1)]
for i in range(m):
	(l, r, x) = (int(j) for j in input().split())
	for j in range(l, r + 1):
		buildings[j] = min(x, buildings[j])
s = 0
for i in range(1, n + 1):
	s += buildings[i] ** 2
print(s)


(n, h, m) = map(int, input().split())
b = [h] * n
while m:
	m -= 1
	(l, r, x) = map(int, input().split())
	for i in range(l - 1, r):
		b[i] = min(b[i], x)
print(sum([x ** 2 for x in b]))


(n, h, m) = map(int, input().split())
heights = []
for _ in range(n):
	heights.append(h)
for _ in range(m):
	(l, r, x) = map(int, input().split())
	for index in range(l - 1, r):
		if heights[index] > x:
			heights[index] = x
print(sum(map(lambda i: i * i, heights)))


import math
(n, h, m) = map(int, input().split())
arr = [h for i in range(n)]
for i in range(m):
	(i1, i2, max) = map(int, input().split())
	for j in range(i1 - 1, i2):
		if arr[j] > max:
			arr[j] = max
print(sum((i * i for i in arr)))


table = {}
(n, h, m) = [int(x) for x in input().split()]
for i in range(1, n + 1):
	table[i] = h
l = [0 for i in range(m)]
r = [0 for i in range(m)]
x = [0 for i in range(m)]
for i in range(m):
	(x1, x2, x3) = input().split()
	l[i] = int(x1)
	r[i] = int(x2)
	x[i] = int(x3)
for i in range(m):
	for a in range(l[i], r[i] + 1):
		if table[a] > x[i]:
			table[a] = x[i]
res = 0
for (key, value) in table.items():
	res += value ** 2
print(res)


(a, b, c) = map(int, input().split())
k = int(0)
s = []
for pp in range(a):
	s.append(b * b)
for _ in range(c):
	(d, e, f) = map(int, input().split())
	x = d - 1
	while x < e:
		if s[x] > f * f:
			s[x] = f * f
		x = x + 1
print(sum(s))


(n, h, m) = map(int, input().split())
a = [0] + [h] * n
regs = []
for _ in range(m):
	(l, r, x) = map(int, input().split())
	regs.append((l, r, x))
for (l, r, x) in regs:
	for i in range(l, r + 1):
		if a[i] > x:
			a[i] = x
b = [0] * (n + 1)
for i in range(n + 1):
	b[i] = a[i] ** 2
print(sum(b))


import sys
import math
fileoperation = 0
if fileoperation:
	orig_stdout = sys.stdout
	orig_stdin = sys.stdin
	inputfile = open('W:/Competitive Programming/input.txt', 'r')
	outputfile = open('C:/Users/njhab/Desktop/output.txt', 'w')
	sys.stdin = inputfile
	sys.stdout = outputfile
mod = 1000000007

def nospace(l):
	ans = ''.join((str(i) for i in l))
	return ans
t = 1
for tt in range(t):
	(n, h, m) = map(int, sys.stdin.readline().split(' '))
	a = []
	for i in range(n):
		a.append(h)
	for i in range(m):
		(l, r, x) = map(int, sys.stdin.readline().split(' '))
		for j in range(l - 1, r):
			a[j] = min(a[j], x)
	ans = 0
	for aa in a:
		ans += aa * aa
	print(ans)
if fileoperation:
	sys.stdout = orig_stdout
	sys.stdin = orig_stdin
	inputfile.close()
	outputfile.close()


from sys import stdin, stdout
for _ in range(1):
	(n, mx, r) = list(map(int, stdin.readline().split()))
	ans = [mx] * n
	for qq in range(r):
		(l, r, v) = list(map(int, stdin.readline().split()))
		l -= 1
		for i in range(l, r):
			ans[i] = min(v, ans[i])
	print(sum((v * v for v in ans)))


(n, h, m) = map(int, input().split())
a = [3000] * 55
for _ in range(m):
	(l, r, x) = map(int, input().split())
	for i in range(l, r + 1):
		if x * x < a[i]:
			a[i] = x * x
s = 0
for i in range(1, n + 1):
	if a[i] == 3000:
		s += h * h
	else:
		s += a[i]
print(s)


(n, h, m) = map(int, input().split())
kek = [h] * n
for i in range(m):
	(l, r, x) = map(int, input().split())
	for q in range(l - 1, r):
		kek[q] = min(kek[q], x)
cnt = 0
for u in kek:
	cnt += u ** 2
print(cnt)


import math
import os
import random
import re
import sys

def return_input_tuple():
	return tuple(map(int, input().split(' ')))
(n, h, m) = return_input_tuple()
result = 0
rest_arr = [h] * n
for _ in range(0, m):
	(l, r, x) = return_input_tuple()
	for i in range(l - 1, r):
		rest_arr[i] = min(x, rest_arr[i])
result = sum([x * x for x in rest_arr])
print(result)


(n, h, m) = [int(i) for i in input().split()]
house = [h] * (n + 1)
house[0] = 0
for i in range(m):
	(l, r, ma) = [int(i) for i in input().split()]
	for i in range(l, r + 1):
		house[i] = min(ma, house[i])
res = 0
for v in house:
	res += v ** 2
print(res)


(n, h, m) = map(int, input().split())
buildings = [h for _ in range(n)]
for i in range(m):
	(l, r, x) = map(int, input().split())
	for b in range(l - 1, r):
		buildings[b] = min(x, buildings[b])
money = 0
for a in buildings:
	money += a ** 2
print(money)


(n, h, m) = map(int, input().split())
ls = [h] * n
profit = 0
for i in range(m):
	(l, r, x) = map(int, input().split())
	currentSpot = l
	while currentSpot < r + 1:
		if ls[currentSpot - 1] > x:
			ls[currentSpot - 1] = x
		currentSpot += 1
for i in ls:
	profit += i ** 2
print(profit)


gi = lambda : list(map(int, input().strip().split()))
(n, h, m) = gi()
l = [h] * (n + 1)
l[0] = 0
for k in range(m):
	(x, y, v) = gi()
	for j in range(x, y + 1):
		l[j] = min(v, l[j])
print(sum([e * e for e in l]))


(a, b, c) = map(int, input().split())
d = [b] * 60
for i in range(0, c):
	(e, f, g) = map(int, input().split())
	for j in range(e, f + 1):
		if d[j] > g:
			d[j] = g
b = 0
for i in range(1, a + 1):
	b += d[i] * d[i]
print(b)


(x, y, z) = map(int, input().split())
a = [y for i in range(x)]
for i in range(z):
	(l, r, h) = map(int, input().split())
	for i in range(l - 1, r):
		a[i] = min(a[i], h)
print(sum([i * i for i in a]))


(n, h, m) = map(int, input().split())
result = [h] * n
for _ in range(m):
	(x, y, l) = map(int, input().split())
	for i in range(x - 1, y):
		if result[i] > l:
			result[i] = l
print(sum(map(lambda x: x * x, result)))


def maxProfit(n, h, rest):
	profit = [h] * n
	for r in rest:
		for i in range(r[0] - 1, r[1]):
			if r[2] < profit[i]:
				profit[i] = r[2]
	return sum([i * i for i in profit])
(n, h, m) = map(int, input().split())
rest = []
for _ in range(m):
	(a, b, c) = map(int, input().split())
	rest.append((a, b, c))
print(maxProfit(n, h, rest))


(n, h, m) = [int(i) for i in input().split()]
restrictions = list()
for i in range(m):
	restrictions.append([int(k) for k in input().split()])
max_profit = 0
max_height = {i: h for i in range(1, n + 1)}
for r in restrictions:
	for i in range(r[0], r[1] + 1):
		max_height[i] = min(max_height[i], r[2])
for v in max_height.values():
	max_profit += v ** 2
print(max_profit)


(n, h, m) = map(int, input().split())
ab = [-1 for i in range(n)]
l = []
r = []
x = []
for i in range(m):
	(a, b, c) = map(int, input().split())
	for j in range(a - 1, b):
		if ab[j] == -1:
			ab[j] = c
		elif ab[j] > c:
			ab[j] = c
for i in range(n):
	if ab[i] == -1:
		ab[i] = h
count1 = 0
for i in range(n):
	count1 += ab[i] * ab[i]
print(count1)


(n, h, m) = [int(x) for x in input().split()]
counter = 0
a = [h] * n
for i in range(m):
	(l, r, x) = [int(x) for x in input().split()]
	for i in range(l - 1, r):
		a[i] = min(a[i], x, h)
for item in a:
	counter += item ** 2
print(counter)


def main():
	s = [int(x) for x in input().split()]
	n = s[0]
	h = s[1]
	m = s[2]
	high = [h] * n
	ans = 0
	for i in range(m):
		s = [int(x) for x in input().split()]
		a = s[0] - 1
		b = s[1]
		c = s[2]
		for i in range(a, b):
			high[i] = min(c, high[i])
	for i in range(n):
		ans += high[i] ** 2
	print(ans)
main()


def main():
	[n_spots, max_height, n_restrictions] = [int(_) for _ in input().split()]
	buildings = [0] + [max_height] * n_spots
	for _ in range(n_restrictions):
		[left, right, limit] = [int(_) for _ in input().split()]
		for i in range(left, right + 1):
			if buildings[i] > limit:
				buildings[i] = limit
	print(sum((x ** 2 for x in buildings)))
main()


(housesNum, maxHeight, restrictionsNum) = map(int, input().split())
money = 0
heightRestrictions = []
for i in range(housesNum):
	heightRestrictions.append(51)
for restriction in range(restrictionsNum):
	(left, right, cap) = map(int, input().split())
	if heightRestrictions[left - 1] == 51 or heightRestrictions[left - 1] > cap:
		heightRestrictions[left - 1] = cap
	if heightRestrictions[right - 1] == 51 or heightRestrictions[right - 1] > cap:
		heightRestrictions[right - 1] = cap
	for i in range(left - 1, right):
		if len(range(left - 1, right)) > 1:
			if heightRestrictions[i] == 51 or heightRestrictions[i] > cap:
				heightRestrictions[i] = cap
for i in range(len(heightRestrictions)):
	if heightRestrictions[i] == 51:
		heightRestrictions[i] = maxHeight
	money += heightRestrictions[i] ** 2
print(money)


T_ON = 0
DEBUG_ON = 1
MOD = 998244353

def solve():
	(n, h, m) = read_ints()
	A = [h for _ in range(n)]
	for i in range(m):
		(l, r, x) = read_ints()
		for j in range(l - 1, r):
			A[j] = min(A[j], x)
	total = 0
	for a in A:
		total += a * a
	print(total)

def main():
	T = read_int() if T_ON else 1
	for i in range(T):
		solve()

def debug(*xargs):
	if DEBUG_ON:
		print(*xargs)
from collections import *
import math
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def read_int():
	return int(input())

def read_ints():
	return list(map(int, input().split()))

def print_nums(nums):
	print(' '.join(map(str, nums)))

def YES():
	print('YES')

def Yes():
	print('Yes')

def NO():
	print('NO')

def No():
	print('No')

def First():
	print('First')

def Second():
	print('Second')

def fib(n):
	(a, b) = (0, 1)
	for _ in range(n):
		(a, b) = (b, a + b)
	return a

def fib_ns(n):
	assert n >= 1
	f = [0 for _ in range(n + 1)]
	f[0] = 0
	f[1] = 1
	for i in range(2, n + 1):
		f[i] = f[i - 1] + f[i - 2]
	return f

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def xgcd(a, b):
	(x0, x1, y0, y1) = (0, 1, 1, 0)
	while a != 0:
		((q, a), b) = (divmod(b, a), a)
		(y0, y1) = (y1, y0 - q * y1)
		(x0, x1) = (x1, x0 - q * x1)
	return (b, x0, y0)

def lcm(a, b):
	d = gcd(a, b)
	return a * b // d

def is_even(x):
	return x % 2 == 0

def is_odd(x):
	return x % 2 == 1

def modinv(a, m):
	(g, x, _) = xgcd(a, m)
	if g != 1:
		raise Exception('gcd(a, m) != 1')
	return x % m

def mod_add(x, y):
	x += y
	while x >= MOD:
		x -= MOD
	while x < 0:
		x += MOD
	return x

def mod_mul(x, y):
	return x * y % MOD

def mod_pow(x, y):
	if y == 0:
		return 1
	if y % 2:
		return mod_mul(x, mod_pow(x, y - 1))
	p = mod_pow(x, y // 2)
	return mod_mul(p, p)

def mod_inv(y):
	return mod_pow(y, MOD - 2)

def mod_div(x, y):
	return mod_mul(x, mod_inv(y))

def is_prime(n):
	if n == 1:
		return False
	for i in range(2, int(n ** 0.5) + 1):
		if n % i:
			return False
	return True

def gen_primes(n):
	P = [True for _ in range(n + 1)]
	P[0] = P[1] = False
	for i in range(int(n ** 0.5) + 1):
		if P[i]:
			for j in range(2 * i, n + 1, i):
				P[j] = False
	return P
main()


(n, h, m) = input().split()
(n, h, m) = (int(n), int(h), int(m))
li = [h ** 2] * n
for i in range(m):
	(l, r, x) = map(int, input().split())
	for j in range(l - 1, r):
		if li[j] > x ** 2:
			li[j] = x ** 2
print(sum(li))


import sys
from bisect import bisect_left, bisect_right, insort
from collections import deque, Counter
from math import gcd, sqrt, factorial, ceil, log10, log2
from itertools import permutations
from heapq import heappush, heappop, heapify
inf = float('inf')
mod = 1000000007

def factorial_p(n, p):
	ans = 1
	if n <= p // 2:
		for i in range(1, n + 1):
			ans = ans * i % p
	else:
		for i in range(1, p - n):
			ans = ans * i % p
		ans = pow(ans, p - 2, p)
		if n % 2 == 0:
			ans = p - ans
	return ans

def nCr_p(n, r, p):
	ans = 1
	while n != 0 or r != 0:
		(a, b) = (n % p, r % p)
		if a < b:
			return 0
		ans = ans * factorial_p(a, p) * pow(factorial_p(b, p), p - 2, p) * pow(factorial_p(a - b, p), p - 2, p) % p
		n //= p
		r //= p
	return ans

def prime_sieve(n):
	flag = n % 6 == 2
	sieve = bytearray((n // 3 + flag >> 3) + 1)
	for i in range(1, int(n ** 0.5) // 3 + 1):
		if not sieve[i >> 3] >> (i & 7) & 1:
			k = 3 * i + 1 | 1
			for j in range(k * k // 3, n // 3 + flag, 2 * k):
				sieve[j >> 3] |= 1 << (j & 7)
			for j in range(k * (k - 2 * (i & 1) + 4) // 3, n // 3 + flag, 2 * k):
				sieve[j >> 3] |= 1 << (j & 7)
	return sieve

def prime_list(n):
	res = []
	if n > 1:
		res.append(2)
	if n > 2:
		res.append(3)
	if n > 4:
		sieve = prime_sieve(n + 1)
		res.extend((3 * i + 1 | 1 for i in range(1, (n + 1) // 3 + (n % 6 == 1)) if not sieve[i >> 3] >> (i & 7) & 1))
	return res

def binary(number):
	result = 0
	while number:
		result = result + 1
		number = number & number - 1
	return result

def is_prime(n):
	if n < 5 or n & 1 == 0 or n % 3 == 0:
		return 2 <= n <= 3
	s = (n - 1 & 1 - n).bit_length() - 1
	d = n >> s
	for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]:
		p = pow(a, d, n)
		if p == 1 or p == n - 1 or a % n == 0:
			continue
		for _ in range(s):
			p = p * p % n
			if p == n - 1:
				break
		else:
			return False
	return True

def count_iterations(a, b):
	ct = 0
	while a != 0 and b != 0:
		temp = a
		a = b
		b = temp % a
		ct += 1
	return ct

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
(n, h, m) = get_ints()
Arr = [0] * (n + 1)
visited = [False] * (n + 1)
for i in range(m):
	(l, r, x) = get_ints()
	for j in range(l, r + 1):
		if visited[j] == True:
			Arr[j] = min(Arr[j], x)
			visited[j] = True
		else:
			Arr[j] = x
			visited[j] = True
tot = 0
for i in range(1, n + 1):
	if visited[i] == False:
		Arr[i] = h
		visited[i] = True
for i in range(1, n + 1):
	tot += Arr[i] * Arr[i]
print(tot)


(n, h, m) = map(int, input().split())
l = [h] * (n + 1)
while m:
	(a, r, x) = map(int, input().split())
	for i in range(a, r + 1):
		l[i] = min(x, l[i])
	m -= 1
t = 0
for i in range(1, n + 1):
	t += l[i] ** 2
print(t)


def main():
	(n, h, m) = map(int, input().split())
	spots = [h] * n
	for _ in range(m):
		(l, r, x) = map(int, input().split())
		for i in range(l - 1, r):
			spots[i] = min(spots[i], x)
	ret = sum([a ** 2 for a in spots])
	print(ret)
main()


def rest(a, k, n, h, m):
	(i, j, v) = (k[0], k[1], k[2])
	for o in range(i, j + 1):
		a[o - 1] = min(a[o - 1], v)
l = list(map(int, input().split()))
(n, h, m) = (l[0], l[1], l[2])
a = [h for i in range(n)]
for y in range(m):
	rest(a, list(map(int, input().split())), n, h, m)
print(sum([d ** 2 for d in a]))


def main():
	(n, h, m) = map(int, input().split())
	h = [h] * (n + 1)
	for i in range(m):
		(l, r, mh) = list(map(int, input().split()))
		for j in range(l, r + 1):
			h[j] = min(h[j], mh)
	s = 0
	for i in h[1:]:
		s += i ** 2
	print(s)
main()


(n, h, m) = map(int, input().split())
houses = [h] * n
for i in range(m):
	tmp = list(map(int, input().split()))
	for j in range(tmp[0] - 1, tmp[1]):
		if tmp[2] <= houses[j]:
			houses[j] = tmp[2]
total = 0
for i in houses:
	total += i * i
print(total)


(n, h, m) = map(int, input().split())
houses = [h] * (n + 1)
for _ in range(0, m):
	(l, r, x) = map(int, input().split())
	for i in range(l, r + 1):
		if houses[i] < x and houses[i] != h:
			pass
		else:
			houses[i] = x
profit = 0
for i in range(1, len(houses)):
	profit += houses[i] ** 2
print(profit)


(n, h, m) = map(int, input().split())
mat = [h] * n
for _ in range(m):
	(x, y, z) = map(int, input().split())
	for i in range(x - 1, y):
		mat[i] = min(mat[i], z)
res = 0
for i in mat:
	res += i ** 2
print(res)


(n, h, m) = map(int, input().split())
a = [h] * n
for _ in range(m):
	(l, r, c) = map(int, input().split())
	for i in range(l - 1, r):
		a[i] = min(a[i], c)
print(sum((k ** 2 for k in a)))


(n, h, m) = map(int, input().split())
house = [h] * n
bla = 0
for i in range(m):
	(l, r, x) = map(int, input().split())
	for j in range(l, r + 1):
		house[j - 1] = min(house[j - 1], x)
for i in house:
	bla += i ** 2
print(bla)


(n, h, m) = map(int, input().split())
a = [h] * n
for _ in range(m):
	(l, r, x) = map(int, input().split())
	a = [min(a[i], x) if l - 1 <= i < r else a[i] for (i, h) in enumerate(a)]
print(sum([x ** 2 for x in a]))


import sys
inputlines = sys.stdin.readlines()
inputnumbers = [[int(numchar) for numchar in line.split()] for line in inputlines]
numspots = inputnumbers[0][0]
maxheight = inputnumbers[0][1]
numrestrictions = inputnumbers[0][2]
restrictions = [maxheight] * numspots
for restriction in inputnumbers[1:numrestrictions + 1]:
	(left, right, height) = restriction
	for i in range(left - 1, right):
		restrictions[i] = min(restrictions[i], height)
print(sum([x ** 2 for x in restrictions]))


x = input().split()
n = int(x[0])
h = int(x[1])
m = int(x[2])
proff = int(0)
arr = [0] * 50
for i in range(n):
	arr[i] = h
for i in range(m):
	a = input().split()
	k = [int(s) for s in a]
	s = k[0] - 1
	while s < k[1]:
		arr[s] = min(arr[s], k[2])
		s += 1
for q in range(n):
	proff += arr[q] ** 2
print(proff)


(n, h, m) = list(map(int, input().split()))
arr = n * [h]
for i in range(m):
	(l, r, x) = list(map(int, input().split()))
	for j in range(len(arr)):
		if j >= l - 1 and j <= r - 1:
			if arr[j] > x:
				arr[j] = x
ans = 0
for k in arr:
	ans += k ** 2
print(ans)


import sys
import math
import bisect

def main():
	(n, h, m) = map(int, input().split())
	A = [h] * n
	for i in range(m):
		(l, r, x) = map(int, input().split())
		l -= 1
		r -= 1
		for j in range(l, r + 1):
			A[j] = min(A[j], x)
	ans = 0
	for a in A:
		ans += a ** 2
	print(ans)
main()


(n, h, m) = map(int, input().split())
rs = [h] * n
for i in range(m):
	(l, r, x) = map(int, input().split())
	for k in range(l - 1, r):
		rs[k] = min(x, rs[k])
print(sum((x * x for x in rs)))


from collections import defaultdict
(n, h, m) = map(int, input().split())
Dict = [1000001] * (n + 1)
for _ in range(m):
	(l, r, x) = map(int, input().split())
	for i in range(l, r + 1):
		Dict[i] = min(x, Dict[i])
Ans = 0
for i in range(1, n + 1):
	if Dict[i] != 1000001:
		Ans += Dict[i] ** 2
	else:
		Ans += h ** 2
print(Ans)


from sys import stdin, stdout
from math import *

def main():
	(n, h, m) = [int(x) for x in stdin.readline().split()]
	a = [h] * (n + 1)
	a[0] = 0
	for i in range(m):
		(l, r, x) = [int(x) for x in stdin.readline().split()]
		for j in range(l, r + 1):
			a[j] = min(a[j], x)
	res = sum([x * x for x in a[1:n + 1]])
	stdout.write(str(res))
	return 0
main()


line = 0
array = []
line = input()
line = line.split()
dic = {}
for i in range(len(line)):
	line[i] = int(line[i])
for _ in range(line[2]):
	array.extend(list(map(int, input().rstrip().split())))
ans = 0
for i in range(len(array) - 1, 0, -3):
	for x in range(array[i - 2], array[i - 1] + 1):
		if x in dic:
			if dic[x] > array[i]:
				del dic[x]
				dic[x] = array[i]
		else:
			dic[x] = array[i]
for i in dic:
	ans += dic[i] * dic[i]
num = line[0] - len(dic)
ans += num * line[1] * line[1]
print(ans)


(n, h, m) = map(int, input().split())
v = [h for _ in range(n)]
for _ in range(m):
	(l, r, x) = map(int, input().split())
	for i in range(l - 1, r):
		v[i] = min(v[i], x)

def suma(v):
	ret = 0
	for i in v:
		ret += i * i
	return ret
print(suma(v))


(n, h, m) = map(int, input().split())
min_restr = [h] * n
restrictions = []
for i in range(m):
	(l, r, r_h) = map(int, input().split())
	for j in range(l, r + 1):
		min_restr[j - 1] = min(min_restr[j - 1], r_h)
sol = sum(map(lambda x: x * x, min_restr))
print(sol)


from math import inf
a = input().split()
for x in range(len(a)):
	a[x] = int(a[x])
n_posti = a[0]
altezza_max = a[1]
n_restrizione = a[2]
l = []
for x in range(n_restrizione):
	l.append(input().split())
dizio = {}
for x in range(1, n_posti + 1):
	dizio[x] = inf
for x in range(n_restrizione):
	a = int(l[x][0])
	b = int(l[x][1])
	c = int(l[x][2])
	while a < b + 1:
		if dizio[a] > c:
			dizio[a] = c
		a += 1
guadagno = 0
for x in dizio:
	if dizio[x] == inf:
		guadagno += altezza_max * altezza_max
	else:
		guadagno += dizio[x] * dizio[x]
print(guadagno)


(n, h, m) = list(map(int, input().split()))
a = [h] * n
for i in range(m):
	(l, r, x) = list(map(int, input().split()))
	for k in range(l - 1, r):
		a[k] = min(a[k], x)
sqa = [t * t for t in a]
print(sum(sqa))


(n, h, m) = map(int, input().split())
l = [h] * n
for i in range(0, m):
	(p, r, x) = map(int, input().split())
	for j in range(p - 1, r):
		if l[j] > x:
			l[j] = x
		else:
			pass
c = 0
for i in range(n):
	c = c + l[i] * l[i]
print(c)


(n, h, m) = map(int, input().split())
total = 0
arr = [0] + [-1] * n
ranges = []
for i in range(m):
	(l, r, x) = map(int, input().split())
	ranges.append((l, r, x))
ranges.sort(key=lambda x: x[2])
for ran in ranges:
	(l, r, x) = ran
	for i in range(l, r + 1):
		if arr[i] == -1:
			arr[i] = x
for i in range(1, n + 1):
	if arr[i] == -1:
		arr[i] = h
for ele in arr:
	total += ele ** 2
print(total)


from math import *
[n, h, m] = list(map(int, input().split(' ')))
x = [h for i in range(n)]
sum = 0
for i in range(m):
	[l, r, y] = list(map(int, input().split(' ')))
	for j in range(l - 1, r):
		x[j] = min(x[j], y)
for i in range(n):
	sum += x[i] ** 2
print(sum)


(num_houses, max_height, num_restrictions) = map(int, input().split())
limits = [list(map(int, input().split())) for _ in range(num_restrictions)]
array = [None] * num_houses
for i in limits:
	for j in range(i[1] - i[0] + 1):
		if array[i[0] + j - 1] is None or i[2] < array[i[0] + j - 1]:
			array[i[0] + j - 1] = i[2]
profit = 0
for i in array:
	if i is None:
		profit += max_height ** 2
	else:
		profit += i ** 2
print(profit)


(n, h, m) = map(int, input().split())
A = [51] * n
temp = 0

def engine(l, r, x):
	for i in range(l - 1, r):
		if x < A[i]:
			A[i] = x
for i in range(m):
	(l, r, x) = map(int, input().split())
	engine(l, r, x)
for i in A:
	if i == 51:
		temp += pow(h, 2)
		continue
	temp += pow(i, 2)
print(temp)


import sys
(n, h, m) = map(int, input().split())
city = [h for _ in range(n)]
for r in range(m):
	(l, r, x) = map(int, input().split())
	for i in range(l - 1, r):
		city[i] = min(city[i], x)
print(sum([a * a for a in city]))


(n, h, m) = map(int, input().split())
d = {}
for i in range(m):
	(a, b, c) = map(int, input().split())
	for k in range(a, b + 1):
		try:
			d[k] = min(d[k], c)
		except:
			d[k] = c
for i in range(1, n + 1):
	try:
		d[i] += 0
	except:
		d[i] = h
profit = 0
for (k, v) in d.items():
	profit += v ** 2
print(profit)


(n, h, m) = list(map(int, input().split()))
h2 = h ** 2
c = [h2] * n
for _ in range(m):
	(l, r, x) = list(map(int, input().split()))
	x2 = x ** 2
	for i in range(l - 1, r):
		if c[i] > x2:
			c[i] = x2
print(sum(c))


(n, h, m) = input().split()
(n, h, m) = (int(n), int(h), int(m))
s = {}
for i in range(m):
	(l, r, x) = input().split()
	(l, r, x) = (int(l), int(r), int(x))
	for j in range(l - 1, r):
		if j + 1 not in s:
			s[j + 1] = x ** 2
		elif s[j + 1] > x ** 2:
			s[j + 1] = x ** 2
for i in range(1, n + 1):
	if i not in s:
		s[i] = h ** 2
total = 0
for i in s.values():
	total += i
print(total)


a = input().split()
n = int(a[0])
h = int(a[1])
m = int(a[2])
x = [h] * n
for i in range(m):
	a = input().split()
	for j in range(int(a[0]) - 1, int(a[1])):
		if x[j] > int(a[2]):
			x[j] = int(a[2])
sum = 0
for i in range(n):
	sum += x[i] ** 2
print(sum)


(n, h, m) = map(int, input().split())
t = []
ans = 0
for _ in range(m):
	t.append(list(map(int, input().split())))
for i in range(1, n + 1):
	x = h
	for y in range(m):
		if t[y][0] <= i <= t[y][1] and t[y][2] < x:
			x = t[y][2]
	ans += x ** 2
print(ans)


def go():
	(n, h, m) = list(map(int, input().split(' ')))
	houses = [h] * n
	for _ in range(m):
		(l, r, x) = [int(w) for w in input().split(' ')]
		l -= 1
		r -= 1
		for i in range(l, r + 1):
			houses[i] = min(houses[i], x)
	answer = 0
	for i in range(n):
		answer += houses[i] ** 2
	return answer
print(go())


(N, H, x) = map(int, input().split())
U = []
U.append(0)
for j in range(1, N + 1):
	U.append(H)
for i in range(x):
	(L, R, t) = map(int, input().split())
	for J in range(L, R + 1):
		if U[J] > t:
			U[J] = t
ans = 0
for x in range(1, N + 1):
	ans += U[x] * U[x]
print(ans)


(n, h, m) = list(map(int, input().split()))
out = [h for i in range(n)]
for i in range(m):
	(l, r, x) = list(map(int, input().split()))
	l -= 1
	r -= 1
	for j in range(l, r + 1):
		if out[j] > x:
			out[j] = x
s = sum([z * z for z in out])
print(s)


ii = lambda : int(input())
mi = lambda : map(int, input().split())
li = lambda : list(mi())
si = lambda : input()
(n, h, m) = mi()
a = [h] * n
for _ in range(m):
	(l, r, c) = mi()
	l -= 1
	r -= 1
	for i in range(l, r + 1):
		a[i] = min(a[i], c)
s = 0
for i in range(n):
	s += a[i] ** 2
print(s)


(n, h, m) = (int(i) for i in input().split())
heights_l = {}
for i in range(m):
	(a, b, hh) = (int(i) for i in input().split())
	for j in range(a, b + 1):
		if j not in heights_l:
			heights_l[j] = hh
		elif hh < heights_l[j]:
			heights_l[j] = hh
count = 0
for i in range(1, n + 1):
	if i in heights_l:
		count += heights_l[i] ** 2
	else:
		count += h ** 2
print(count)


cin = lambda : map(int, input().split())
(n, h, m) = cin()
li = [h] * n
while True:
	m = m - 1
	if m < 0:
		break
	(l, r, x) = cin()
	for i in range(l - 1, r):
		if li[i] > x:
			li[i] = x
print(sum([x * x for x in li]))


(n, h, m) = map(int, input().split())
s = [h] * n
sum = 0
for i in range(m):
	(l, r, x) = map(int, input().split())
	for k in range(l - 1, r):
		s[k] = min(x, s[k])
for j in range(len(s)):
	sum = sum + s[j] * s[j]
print(sum)


inp = input().split(' ')
n = int(inp[0])
max_height = int(inp[1])
restrictions = int(inp[2])
restriction_map = [max_height for x in range(n)]
for x in range(restrictions):
	restr = [int(y) for y in input().split(' ')]
	for z in range(restr[0] - 1, restr[1]):
		if restriction_map[z] > restr[2]:
			restriction_map[z] = restr[2]
profit = [x ** 2 for x in restriction_map]
print(sum(profit))


(n, h, m1) = map(int, input().split())
m = 0
d = {}
for i in range(m1):
	(l, r, x) = map(int, input().split())
	for j in range(l, r + 1):
		if j in d:
			if d[j] > x:
				d[j] = x
		else:
			d[j] = x
m = 0
for i in range(1, n + 1):
	if i in d:
		m += d[i] * d[i]
	else:
		m += h * h
print(m)


(n, h, m) = map(int, input().strip().split())
max_h = [h] * n
for _ in range(m):
	(l, r, x) = map(int, input().strip().split())
	for i in range(l - 1, r):
		if max_h[i] > x:
			max_h[i] = x
print(sum([x ** 2 for x in max_h]))


(n, h, m) = map(int, input().split())
d = [h] * n
for i in range(m):
	(a, b, c) = map(int, input().split())
	for j in range(a - 1, b):
		d[j] = min(d[j], c)
num = 0
for i in d:
	num += i * i
print(num)


(n, h, m) = map(int, input().split())
gr = [h] * 100
for i in range(m):
	(l, r, hh) = map(int, input().split())
	for j in range(l, r + 1):
		gr[j] = min(gr[j], hh)
an = 0
for i in range(1, n + 1):
	an = an + gr[i] ** 2
print(an)


[n, h, m] = list(map(int, input().split(' ')))
arr = []
for x in range(n + 1):
	arr.append(999)
for i in range(m):
	[start, end, limit] = list(map(int, input().split(' ')))
	while start <= end:
		if arr[start] > limit:
			arr[start] = limit
		start = start + 1
profit = 0
for x in range(n + 1):
	if arr[x] == 999:
		arr[x] = h
	profit = profit + arr[x] * arr[x]
print(profit - arr[0] * arr[0])


values = input()
(n, h, m) = values.split(' ')
(n, h, m) = (int(n), int(h), int(m))
restr = []
dollars = 0

def isvalid(n):
	if n >= 1 and n <= 50:
		return True
	else:
		return False
if isvalid(n) and isvalid(h) and isvalid(m):
	for i in range(m):
		restrictions = input()
		(res1, res2, res3) = restrictions.split(' ')
		(res1, res2, res3) = (int(res1), int(res2), int(res3))
		if res1 <= res2 and res2 <= n and (res3 <= h):
			restr.append([res1, res2, res3])
for num in range(1, n + 1):
	temp = 0
	flag = 0
	for rest in restr:
		if num >= rest[0] and num <= rest[1]:
			if temp == 0 and flag == 0:
				flag = 1
				temp = rest[2]
			elif temp > rest[2]:
				temp = rest[2]
	if temp == 0 and flag == 0:
		temp = h
	dollars += pow(temp, 2)
print(dollars)


(n, h, r) = map(int, input().strip().split(' '))
ls = [h] * n
for _ in range(r):
	(l, r, mh) = map(int, input().strip().split(' '))
	for ind in range(l - 1, r):
		ls[ind] = min(ls[ind], mh)
ans = 0
for val in ls:
	ans += val * val
print(ans)


(n, h, m) = map(int, input().split())
l = [h for i in range(n)]
a = h
for i in range(m):
	(li, ri, xi) = map(int, input().split())
	for j in range(li, ri + 1):
		if xi < l[j - 1]:
			l[j - 1] = xi
			a = xi
s = 0
for i in range(n):
	s += l[i - 1] ** 2
print(s)


def solve(n, h, m, a):
	s = 0
	for i in range(1, n + 1):
		maxi = h
		for (l, r, x) in a:
			if l <= i <= r:
				maxi = min(x, maxi)
		s += maxi ** 2
	return s

def main():
	(n, h, m) = list(map(int, input().split()))
	a = [tuple(map(int, input().split())) for _ in range(m)]
	print(solve(n, h, m, a))
main()


i = lambda : map(int, input().split())
(n, h, m) = i()
v = [h] * n
for _ in range(m):
	(l, r, x) = i()
	for a in range(l - 1, r):
		v[a] = min(v[a], x)
print(sum((x * x for x in v)))


(n, k, m) = map(int, input().split())
l = []
a = 0
for i in range(m):
	l.append(list(map(int, input().split())))
for i in range(1, n + 1):
	x = k
	for j in range(m):
		if l[j][0] <= i <= l[j][1] and l[j][2] < x:
			x = l[j][2]
	a += x ** 2
print(a)


(n, h, m) = map(int, input().split())
ans = 0
l = []
for x in range(m):
	temp = list(map(int, input().split()))
	l.append(temp)
for x in range(1, n + 1):
	flag = True
	temp = 10 ** 10
	for y in l:
		if x in range(y[0], y[1] + 1):
			temp = min(temp, y[2])
			flag = False
	if not flag:
		ans += temp ** 2
	else:
		ans += h ** 2
print(ans)


(n, h, m) = map(int, input().split())
w = list()
ans = 0
for i in range(n):
	w.append(h)
for i in range(m):
	(l, r, x) = map(int, input().split())
	l -= 1
	r -= 1
	for j in range(l, r + 1, 1):
		if x < w[j]:
			w[j] = x
for i in range(n):
	ans += w[i] * w[i]
print(ans)


t = list(map(int, input().split(' ')))
n = t[0]
h = t[1]
m = t[2]
s = [h] * n
for i in range(m):
	t = list(map(int, input().split(' ')))
	l = t[0]
	r = t[1]
	x = t[2]
	for j in range(l - 1, r, 1):
		s[j] = min(s[j], x)
q = 0
for i in range(n):
	q = q + s[i] ** 2
print(q)


(n, h, m) = map(int, input().split())
l = [0 for i in range(n)]
p = 0
for k in range(m):
	(a, b, c) = map(int, input().split())
	for i in range(a - 1, b):
		if l[i] == 0:
			if c == 0:
				l[i] = 'a'
			else:
				l[i] = c
		elif l[i] == 'a':
			continue
		elif c < l[i]:
			if c == 0:
				l[i] = 'a'
			else:
				l[i] = c
for i in range(n):
	if l[i] == 0:
		p += h ** 2
	elif l[i] == 'a':
		continue
	else:
		p += l[i] ** 2
print(p)


(n, h, m) = map(int, input().split())
a = []
d = dict()
for i in range(m):
	(l, r, x) = map(int, input().split())
	a.append([l, r, x])
mc = 0
for i in range(1, n + 1):
	mh = None
	r = 0
	for j in a:
		if i >= j[0] and i <= j[1] and (mh == None or mh > j[2]):
			mh = j[2]
			r = 1
	if r == 0:
		mh = h
	mr = mh * mh
	mc = mc + mr
print(mc)


(n, h, m) = map(int, input().split())
v = []
for i in range(n):
	v.append(h)
for i in range(m):
	(l, r, x) = map(int, input().split())
	for j in range(l - 1, r):
		v[j] = min(v[j], x)
s = sum([i * i for i in v])
print(s)


v = [0] * 1005
(x, y, z) = map(int, input().split())
for i in range(1, x + 1):
	v[i] = y
for i in range(1, z + 1):
	(a, b, c) = map(int, input().split())
	for j in range(a, b + 1):
		v[j] = min(v[j], c)
sum = 0
for i in range(1, x + 1):
	sum += v[i] * v[i]
print(sum)


(n, h, m) = map(int, input().split())
A = [h] * n
for i in range(m):
	(l, r, mh) = map(int, input().split())
	for i in range(l - 1, r):
		A[i] = min(A[i], mh)
ans = 0
for i in A:
	ans += i ** 2
print(ans)


(n, h, m) = map(int, input().split())
height = [h for i in range(n)]
for i in range(m):
	(l, r, x) = map(int, input().split())
	for j in range(l - 1, r):
		height[j] = min(height[j], x)
res = sum((i ** 2 for i in height))
print(res)


(n, h, m) = map(int, input().split())
s = [h] * (n + 1)
while m:
	(a, r, x) = map(int, input().split())
	for i in range(a, r + 1):
		s[i] = min(x, s[i])
	m -= 1
k = 0
for i in range(1, n + 1):
	k += s[i] ** 2
print(k)


(n, h, m) = map(int, input().split())
y = []
z = []
for i in range(m):
	(l, r, x) = map(int, input().split())
	y.append([l, r, x])
for i in range(n):
	z.append(h ** 2)
for i in range(m):
	for j in range(y[i][0] - 1, y[i][1]):
		if y[i][2] ** 2 <= z[j]:
			z[j] = y[i][2] ** 2
print(sum(z))


from collections import defaultdict as dicc
(n, h, cases) = map(int, input().split())
dic = dicc()
while cases:
	cases -= 1
	(l, r, x) = map(int, input().split())
	for i in range(l, r + 1):
		if i not in dic or dic[i] > x:
			dic[i] = x
profit = 0
for spot in range(1, n + 1):
	if spot not in dic:
		profit += h ** 2
	else:
		profit += min(h, dic[spot]) ** 2
print(profit)


(n, h, m) = [int(s) for s in input().split()]
arr = [-1 for i in range(n)]
for i in range(m):
	(a, b, max) = [int(s) for s in input().split()]
	for j in range(a - 1, b):
		if arr[j] == -1:
			arr[j] = max
		elif max < arr[j]:
			arr[j] = max
sum = 0
for i in range(n):
	if arr[i] == -1:
		sum += h ** 2
	else:
		sum += arr[i] ** 2
print(sum)


from functools import reduce
(n, h, m) = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(m)]
ans = [0]
for i in range(n):
	temp = float('Inf')
	for t in x:
		if t[0] - 1 <= i <= t[1] - 1:
			temp = min(temp, t[2])
	ans.append(min(h, temp))
print(reduce(lambda x, y: x + y * y, ans))


(n, h, m) = [int(s) for s in input().split(' ')]
restrictions = [h] * n
for i in range(m):
	(l, r, x) = [int(s) for s in input().split(' ')]
	for j in range(l - 1, r):
		restrictions[j] = min(restrictions[j], x)
print(sum([y ** 2 for y in restrictions]))


(n, h, m) = list(map(int, input().split()))
arr = [h] * (n + 1)
for i in range(1, m + 1):
	(l, r, x) = list(map(int, input().split()))
	for j in range(l, r + 1):
		if x < arr[j]:
			arr[j] = x
Sum = 0
for i in range(1, n + 1):
	Sum += arr[i] ** 2
print(Sum)


(n, h, m) = map(int, input().split())
res = 0
houses = [h for i in range(n)]
for i in range(m):
	(li, ri, xi) = map(int, input().split())
	for j in range(li - 1, ri):
		houses[j] = min(houses[j], xi)
print(sum(list(map(lambda x: x ** 2, houses))))


s = input()
s = s.split()
n = int(s[0])
h = int(s[1])
m = int(s[2])
l = []
r = []
x = []
for i in range(m):
	s = input()
	s = s.split()
	l.append(int(s[0]))
	r.append(int(s[1]))
	x.append(int(s[2]))
w = []
for i in range(n):
	w.append(h)
for i in range(n):
	for j in range(m):
		if l[j] - 1 <= i and r[j] - 1 >= i:
			if w[i] > x[j]:
				w[i] = x[j]
p = 0
for i in range(n):
	p += w[i] ** 2
print(p)


(n, h, m) = map(int, input().split())
l = [h] * n
for _ in range(m):
	(a, b, c) = map(int, input().split())
	for i in range(a - 1, b):
		l[i] = min(l[i], c)
s = 0
for i in range(n):
	s += l[i] * l[i]
print(s)


(n, h, r) = map(int, input().split())
w = []
for i in range(r):
	l = list(map(int, input().split()))
	w.append(l)
p = []
for j in range(r):
	for i in range(w[j][0], w[j][1] + 1):
		s = [i, w[j][2]]
		p.append(s)
t = []
for i in range(len(p)):
	for j in range(len(p)):
		if i != j:
			if p[i][0] == p[j][0]:
				if p[i][1] > p[j][1]:
					t.append(p[i])
if len(t) > 0:
	for i in range(len(t)):
		if t[i] in p:
			p.remove(t[i])
u = []
for i in range(len(p)):
	if p[i] not in u:
		u.append(p[i])
m = []
for i in range(len(u)):
	d = u[i][1] ** 2
	m.append(d)
f = n - len(m)
plus = 0
for i in range(f):
	plus = plus + h ** 2
q = plus + sum(m)
print(q)


(n, h, m) = map(int, input().split())
ogr = [list(map(int, input().split())) for i in range(m)]
grd = [h for i in range(n)]
for i in ogr:
	x = i[2]
	for j in range(i[0] - 1, i[1]):
		if x < grd[j]:
			grd[j] = x
s = 0
for i in grd:
	s += i * i
print(s)


(n, h, m) = [int(num) for num in input().split()]
arr = [h ** 2 for _ in range(0, n)]
for _ in range(m):
	(l, r, x) = [int(num) for num in input().split()]
	for i in range(l - 1, r):
		if arr[i] > x ** 2:
			arr[i] = x ** 2
print(sum(arr))


import sys
line = sys.stdin.readline().strip()
(n, h, m) = map(int, line.split())
heights = [h] * n
for i in range(m):
	line = sys.stdin.readline().strip()
	(l, r, x) = map(int, line.split())
	for spot in range(l - 1, r):
		heights[spot] = min(heights[spot], x)
profits = map(lambda x: x * x, heights)
print(sum(profits))


(n, h, m) = map(int, input().split())
l1 = [h] * n
a = 0
for i in range(m):
	(l, r, x) = map(int, input().split())
	for j in range(l - 1, r):
		if l1[j] > x:
			l1[j] = x
for i in l1:
	a = a + i * i
print(a)


(n, h, m) = map(int, input().split())
k = [-1] * n
for i in range(m):
	(a, b, c) = map(int, input().split())
	for j in range(a - 1, b):
		if k[j] == -1:
			k[j] = c ** 2
		elif k[j] > c ** 2:
			k[j] = c ** 2
for i in range(n):
	if k[i] == -1:
		k[i] = h ** 2
print(sum(k))


si = lambda : input()
ii = lambda : int(input())
mi = lambda : map(int, input().split())
li = lambda : list(mi())
(n, h, m) = mi()
L = [h for x in range(0, n)]
for x in range(0, m):
	(l, r, t) = mi()
	L[l - 1:r] = [min(t, x) for x in L[l - 1:r]]
profit = 0
for x in L:
	profit += x ** 2
print(profit)


(n, h, m) = map(int, input().split())
arr = [h] * n
for i in range(m):
	(l, r, x) = map(int, input().split())
	for j in range(l - 1, r):
		arr[j] = min(arr[j], x)
su = 0
for x in arr:
	su += x * x
print(su)


(n, h, m) = list(map(int, input().split(' ')))
a = [h for _ in range(n)]
for line in range(m):
	(l, r, x) = list(map(int, input().split(' ')))
	for indx in range(l - 1, r):
		a[indx] = min(a[indx], x)
print(sum((x * x for x in a)))


(n, h, m) = map(int, input().split())
d = dict()
for _ in range(m):
	(l, r, res) = map(int, input().split())
	for i in range(l, r + 1):
		if i in d:
			d[i] = min(d[i], res)
		else:
			d[i] = res
ans = 0
for i in range(1, n + 1):
	if i in d:
		ans += d[i] * d[i]
	else:
		ans += h * h
print(ans)


line = input().split(' ')
n = int(line[0])
max_h = int(line[1])
m = int(line[2])
ar = []
for i in range(m):
	l = input()
	l = [int(j) for j in l.split(' ')]
	ar.append(l)
ar.sort(key=lambda x: (x[2], x[0]))
built = [0] * n
profit = 0
for m in ar:
	for i in range(m[0], m[1] + 1):
		if built[i - 1] == 0:
			profit += m[2] ** 2
			built[i - 1] = 1
profit += (n - sum(built)) * max_h ** 2
print(profit)


(n, h, r) = map(int, input().split())
(s, b) = (0, [])
for x in range(r):
	a = list(map(int, input().split()))
	b.append(a)
for x in range(1, n + 1):
	c = []
	for y in range(r):
		if x in range(b[y][0], b[y][1] + 1):
			c.append(b[y][2])
	if c == []:
		s += h * h
	else:
		s += min(c) * min(c)
print(s)


(n, h, m) = list(map(int, input().split()))
l = [0] * m
r = [0] * m
x = [0] * m
total = 0
for i in range(m):
	(l[i], r[i], x[i]) = list(map(int, input().split()))
a = [h] * n
for i in range(m):
	for j in range(l[i] - 1, r[i]):
		if a[j] > x[i]:
			a[j] = x[i]
for i in a:
	total = total + i ** 2
print(total)


def main():
	(n, h, m) = (int(x) for x in input().split())
	hs = [h] * n
	for i in range(m):
		(l, r, x) = (int(x) for x in input().split())
		for j in range(l - 1, r):
			if hs[j] > x:
				hs[j] = x
	ans = 0
	for x in hs:
		ans += x * x
	print(ans)
main()


def solve():
	(N, H, M) = map(int, input().split())
	sc = [H for i in range(N)]
	for i in range(M):
		(l, r, h) = map(int, input().split())
		for j in range(l - 1, r):
			sc[j] = min(sc[j], h)
	return sum([a * a for a in sc])
print(solve())


(a, b, c) = input().split()
d = {}
for i in range(int(c)):
	(l, r, x) = input().split()
	for i in range(int(l), int(r) + 1):
		if i not in d:
			d[i] = int(x)
		if int(x) < d[i]:
			d[i] = int(x)
total = 0
for i in range(1, int(a) + 1):
	if i in d:
		total = total + d[i] ** 2
	else:
		total = total + int(b) ** 2
print(total)


def solution(l1, l2):
	n = l1[0]
	m = l1[1]
	l3 = [m for x in range(n)]
	i = 0
	while i < len(l2):
		l = l2[i][0]
		r = l2[i][1]
		h = l2[i][2]
		j = l - 1
		while j <= r - 1:
			l3[j] = min(h, l3[j])
			j += 1
		i += 1
	ans = 0
	for x in l3:
		ans += x ** 2
	print(ans)

def answer():
	l1 = [int(x) for x in input().split()]
	l2 = []
	while l1[2]:
		l2.append([int(x) for x in input().split()])
		l1[2] -= 1
	solution(l1, l2)
answer()


def getn():
	return int(input())

def getns():
	return [int(x) for x in input().split()]
(n, h, m) = getns()
hs = [h] * (n + 1)
for i in range(m):
	(l, r, x) = getns()
	for i in range(l, r + 1):
		hs[i] = min(hs[i], x)
ans = 0
for i in range(1, n + 1):
	ans += hs[i] * hs[i]
print(ans)


(n, h, m) = map(int, input().split())
d = list((999 for i in range(n + 1)))
s = 0
for i in range(m):
	(a, b, k) = map(int, input().split())
	for j in range(a, b + 1):
		if k < d[j]:
			d[j] = k
for i in range(1, n + 1):
	if d[i] == 999:
		s += h * h
	else:
		s += d[i] * d[i]
print(s)


from math import sqrt

def main():
	(n, h, m) = [int(v) for v in input().split()]
	data = []
	for i in range(m):
		(l, r, x) = [int(v) for v in input().split()]
		data.append((l, r, x))
	s = 0
	for i in range(1, n + 1):
		min_v = h
		for (l, r, x) in data:
			if l <= i <= r:
				min_v = min(min_v, x)
		s += min_v * min_v
	print(s)
main()


import math
import bisect
import heapq
from collections import defaultdict

def egcd(a, b):
	if a == 0:
		return (b, 0, 1)
	else:
		(g, x, y) = egcd(b % a, a)
		return (g, y - b // a * x, x)

def mulinv(b, n):
	(g, x, _) = egcd(b, n)
	if g == 1:
		return x % n
primes = []

def isprime(n):
	for d in range(2, int(math.sqrt(n)) + 1):
		if n % d == 0:
			return False
	return True

def argsort(ls):
	return sorted(range(len(ls)), key=ls.__getitem__)

def f(p=0):
	if p == 1:
		return map(int, input().split())
	elif p == 2:
		return list(map(int, input().split()))
	else:
		return int(input())
(n, h, m) = f(1)
dl = [h] * (n + 1)
for i in range(m):
	(a, b, t) = f(1)
	for j in range(a, b + 1):
		dl[j] = min(dl[j], t)
res = 0
for i in range(1, n + 1):
	res += dl[i] ** 2
print(res)


(a, b, c) = input().split()
(a, b, c) = (int(a), int(b), int(c))
v = []
s = 0
d = {}
min = 50
max = 0
for i in range(c):
	v.append(input().split())
	for j in range(int(v[i][0]), int(v[i][1]) + 1):
		if int(v[i][0]) < min:
			min = int(v[i][0])
		if int(v[i][1]) > max:
			max = int(v[i][1])
		if j not in d or int(d[j]) > int(v[i][2]):
			d[j] = int(v[i][2])
for i in range(1, min):
	d[i] = b
for i in range(max + 1, a + 1):
	d[i] = b
for i in range(1, a + 1):
	s += int(d[i]) * int(d[i])
print(s)


(n, h, m) = map(int, input().split())
a = [list(map(int, input().split())) for i in range(m)]
a.sort(key=lambda x: x[2])
count = 0
mest = 0
b = [0 for i in range(n)]
for i in range(len(a)):
	for j in range(a[i][0] - 1, a[i][1]):
		if b[j] == 0:
			b[j] = 1
			count += min(h, a[i][2]) ** 2
			mest += 1
print(count + (n - mest) * h ** 2)


from random import random
import math
import re
import fractions
(N, H, M) = map(int, input().split(' '))
result = [H] * N
for _ in range(M):
	(s, e, h) = map(int, input().split(' '))
	for i in range(s - 1, e):
		result[i] = min(h, result[i])
print(sum(map(lambda x: x * x, result)))


(n, h, m) = map(int, input().split())
k = [h] * (n + 1)
for _ in range(m):
	(l, r, x) = map(int, input().split())
	for i in range(l, r + 1):
		k[i] = min(k[i], x)
t = 0
for i in range(1, n + 1):
	t += k[i] ** 2
print(t)


(n, h, m) = map(int, input().split())
a = []
q = 0
for i in range(0, m):
	a.append(list(map(int, input().split())))
for i in range(1, n + 1):
	p = [h]
	for j in range(0, len(a)):
		if a[j][0] <= i <= a[j][1]:
			p.append(a[j][2])
	q = q + min(p) ** 2
print(q)


(n, h, m) = list(map(int, input().split()))
A = [h] * n
for _ in range(m):
	(l, r, x) = list(map(int, input().split()))
	for i in range(l - 1, r):
		A[i] = min(A[i], x)
s = 0
for a in A:
	s += a * a
print(s)


import sys
import math
input = sys.stdin.readline

def inp():
	return int(input())

def inara():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
(n, h, m) = invr()
ara = [h] * (n + 1)
for _ in range(m):
	(l, r, x) = invr()
	for i in range(l, r + 1):
		ara[i] = min(ara[i], x)
ans = 0
for i in range(1, n + 1):
	ans += ara[i] * ara[i]
print(ans)


(n, h, m) = list(map(int, input().split()))
height = [h] * n
for i in range(m):
	r = list(map(int, input().split()))
	for j in range(r[0] - 1, r[1]):
		height[j] = min(height[j], r[2])
res = 0
for i in height:
	res += i ** 2
print(res)


(n, h, m) = map(int, input().split())
l = list()
r = list()
x = list()
for i in range(m):
	(a, b, c) = map(int, input().split())
	l.append(a)
	r.append(b)
	x.append(c)
Z = [0] + [h] * n
c = 0
for i in range(m):
	for j in range(l[i], r[i] + 1):
		Z[j] = min(x[i], Z[j])
s = 0
for i in Z:
	s += i * i
print(s)


(a, b, c) = map(int, input().split())
r = [b] * (a + 1)
m = []
res = 0
for i in range(c):
	m.append(list(map(int, input().split())))
m.sort()
for i in range(c):
	for j in range(m[i][0], m[i][1] + 1):
		if r[j] > m[i][2]:
			r[j] = m[i][2]
for i in r:
	res += i ** 2
print(res - b ** 2)


(n, h, m) = list(map(int, input().split()))
a = [h] * n
for i in range(m):
	(li, ri, xi) = list(map(int, input().split()))
	a[li - 1:ri] = [xi if x > xi else x for x in a[li - 1:ri]]
print(sum([x ** 2 for x in a]))


from collections import defaultdict, deque
from heapq import heappush, heappop
from math import inf
ri = lambda : map(int, input().split())

def solve():
	(n, h, m) = ri()
	res = []
	for _ in range(m):
		(x, y, mx) = ri()
		x -= 1
		y -= 1
		res.append((x, y, mx))

	def valid(pos, cand):
		for (x, y, mx) in res:
			if x <= pos <= y and cand > mx:
				return False
		return True
	ans = 0
	for i in range(n):
		for j in range(h, -1, -1):
			if valid(i, j):
				ans += j ** 2
				break
	print(ans)
t = 1
while t:
	t -= 1
	solve()


import math, itertools, fractions, heapq, collections, bisect, sys, queue, copy
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def LS():
	return sys.stdin.readline().split()

def S():
	return input()

def main():
	(n, h, m) = LI()
	l = [h] * n
	for _ in range(m):
		(a, b, c) = LI()
		for i in range(a - 1, b):
			l[i] = min(l[i], c)
	ans = 0
	for x in l:
		ans += x * x
	return ans
print(main())


exec('n, h, m = [int(i) for i in input().split()]\ndata = [h]*n\nfor j in range(m):\n   l, r, x = [int(i) for i in input().split()] \n   for k in range(l-1,r):\n       data[k] = min(data[k], x)\nprint(sum([i**2 for i in data]))')


def getkey(item):
	return item[2]
a = list(map(int, input().split(' ')))
t = [a[1] for i in range(1, a[0] + 1)]
k = []
for i in range(a[2]):
	b = list(map(int, input().split(' ')))
	k.append((b[0], b[1], b[2]))
k.sort(key=getkey, reverse=True)
for i in k:
	for j in range(i[0] - 1, i[1]):
		t[j] = i[2]
s = 0
for i in range(0, len(t)):
	s += t[i] ** 2
print(s)


from bisect import bisect_right as br
from bisect import bisect_left as bl
from collections import *
from itertools import *
import functools
import sys
from math import *
from decimal import *
from copy import *
from heapq import *
getcontext().prec = 30
MAX = sys.maxsize
MAXN = 10 ** 5 + 10
MOD = 10 ** 9 + 7

def isprime(n):
	n = abs(int(n))
	if n < 2:
		return False
	if n == 2:
		return True
	if not n & 1:
		return False
	for x in range(3, int(n ** 0.5) + 1, 2):
		if n % x == 0:
			return False
	return True

def mhd(a, b, x, y):
	return abs(a - x) + abs(b - y)

def numIN(x=' '):
	return map(int, sys.stdin.readline().strip().split(x))

def charIN(x=' '):
	return sys.stdin.readline().strip().split(x)

def arrIN():
	return list(numIN())

def dis(x, y):
	a = y[0] - x[0]
	b = x[1] - y[1]
	return (a * a + b * b) ** 0.5

def lgcd(a):
	g = a[0]
	for i in range(1, len(a)):
		g = math.gcd(g, a[i])
	return g

def ms(a):
	msf = -MAX
	meh = 0
	st = en = be = 0
	for i in range(len(a)):
		meh += a[i]
		if msf < meh:
			msf = meh
			st = be
			en = i
		if meh < 0:
			meh = 0
			be = i + 1
	return (msf, st, en)

def res(ans, t):
	print('Case #{}: {}'.format(t, ans))
(n, h, m) = numIN()
ans = [h] * (n + 1)
for _ in range(m):
	(l, r, x) = numIN()
	for i in range(l, r + 1):
		ans[i] = min(x, ans[i])
print(sum((i ** 2 for i in ans[1:])))


(n, h, m) = map(int, input().split())
profit = 0
l1 = []
for i in range(0, m):
	(l, r, x) = map(int, input().split())
	l1.append((x, l, r))
l1.sort()
l2 = [1] * n
for item in l1:
	x = item[0]
	l = item[1]
	r = item[2]
	for i in range(l, r + 1):
		if l2[i - 1] == 1:
			profit = profit + x ** 2
			l2[i - 1] = 0
profit = profit + l2.count(1) * h ** 2
print(profit)


s = input().split()
n = int(s[0])
h = int(s[1])
m = int(s[2])
v = []
for i in range(n):
	v.append(h)
while m > 0:
	m -= 1
	s = input().split()
	l = int(s[0])
	r = int(s[1])
	c = int(s[2])
	l -= 1
	r -= 1
	for i in range(l, r + 1):
		v[i] = min(v[i], c)
ans = 0
for i in range(n):
	ans += v[i] * v[i]
print(ans)


(n, h, m) = map(int, input().split())
a = [100 for i in range(n)]
for i in range(m):
	(l, r, x) = map(int, input().split())
	for j in range(l - 1, r):
		a[j] = min(x, a[j])
for i in range(n):
	if a[i] == 100:
		a[i] = h
su = 0
for i in a:
	su += i * i
print(su)


from math import *
(n, h, m) = map(int, input().split())
d = [h] * n
for i in range(m):
	(l, r, x) = map(int, input().split())
	for j in range(l - 1, r):
		d[j] = min(d[j], x)
ans = 0
for i in d:
	ans += i * i
print(ans)


(n, h, m) = map(int, input().split())
restrictions = []
for _ in range(m):
	(a, b, c) = map(int, input().split())
	restrictions += [(a, b, c)]
result = 0
for i in range(1, n + 1):
	current = h
	for (a, b, c) in restrictions:
		if a <= i and i <= b:
			current = min([current, c])
	result += current ** 2
print(result)


(n, h, m) = map(int, input().split())
li = [h] * n
for i in range(m):
	(l, r, maxh) = map(int, input().split())
	for i in range(l - 1, r):
		li[i] = min(maxh, li[i])
c = 0
for i in li:
	c += i * i
print(c)


(n, h, m) = map(int, input().split())
l = [h] * (n + 1)
while m:
	(ll, r, x) = map(int, input().split())
	for i in range(ll, r + 1):
		l[i] = min(x, l[i])
	m -= 1
su = 0
for i in range(1, n + 1):
	su += l[i] ** 2
print(su)


import sys
input = sys.stdin.readline
(n, h, m) = list(map(int, input().split()))
a = [h] * n
for i in range(m):
	(b, c, d) = list(map(int, input().split()))
	a[b - 1:c] = [min(x, d) for x in a[b - 1:c]]
print(sum([x ** 2 for x in a]))


(n, h, m) = map(int, input().split())
a = [h] * n
for _ in range(m):
	(l, r, x) = map(int, input().split())
	for i in range(l - 1, r):
		a[i] = min(a[i], x)
p = 0
for i in range(n):
	p += a[i] * a[i]
print(p)


(n, h, m) = map(int, input().split())
seen = [h] * n
for i in range(m):
	(l, r, x) = map(int, input().split())
	for j in range(l - 1, r):
		if seen[j] > x:
			seen[j] = x
summ = 0
for i in seen:
	summ += i * i
print(summ)


(n, h, m) = list(map(int, input().split()))
dp = [h for _ in range(n)]
for _ in range(m):
	(l, r, x) = list(map(int, input().split()))
	for i in range(l - 1, r):
		dp[i] = min(dp[i], x)
ans = 0
for x in dp:
	ans += x * x
print(ans)


import sys
import math
import copy

def _num():
	return int(sys.stdin.readline().strip())

def _listofnums():
	return list(map(int, sys.stdin.readline().strip().split()))

def _string():
	return sys.stdin.readline().strip()
(n_spots, max_h, n_restrictions) = _listofnums()
restrictions = []
for _ in range(n_restrictions):
	restrictions.append(_listofnums())
houses = [max_h for _ in range(n_spots + 1)]
houses[0] = 0
for r in restrictions:
	for i in range(r[0], r[1] + 1):
		houses[i] = min(houses[i], r[2])
res = sum([n ** 2 for n in houses])
print(res)


(n, h, m) = map(int, input().split())
d = [[h] for i in range(n)]
s = []
for i in range(m):
	(a, b, c) = map(int, input().split())
	for j in range(a - 1, b):
		d[j].append(c)
for i in d:
	s.append(min(i))
print(sum((x ** 2 for x in s)))


List = input().split()
N = int(List[0])
H = int(List[1])
M = int(List[2])
Num = []
for i in range(N):
	Num.append(H)
for i in range(M):
	List = input().split()
	l = int(List[0])
	r = int(List[1])
	x = int(List[2])
	for j in range(r - l + 1):
		if Num[j + l - 1] > x:
			Num[j + l - 1] = x
Sum = 0
for i in range(N):
	Sum += pow(Num[i], 2)
print(Sum)


(n, h, m) = [int(x) for x in input().split(' ')]
dollars = 0
houses = [h] * n
for i in range(m):
	(l, r, x) = [int(x) for x in input().split(' ')]
	for j in range(l, r + 1):
		houses[j - 1] = min(x, houses[j - 1])
print(sum([a * a for a in houses]))


(n, h, m) = (int(x) for x in input().split())
a = [h ** 2] * (n + 1)
a[0] = 0
for i in range(m):
	(l, r, x) = (int(x) for x in input().split())
	for j in range(l, r + 1):
		a[j] = min(a[j], min(x, h) ** 2)
a.sort()
print(sum(a[len(a) - n:len(a)]))


import math
read = lambda : map(int, input().split())

def codeforce1164A():
	(n, h, m) = read()
	p = [h] * (n + 1)
	for _ in range(m):
		(l, r, limit) = read()
		for i in range(l, r + 1):
			p[i] = min(limit, p[i])
	res = 0
	for i in range(1, n + 1):
		res += p[i] ** 2
	print(res)
codeforce1164A()


(n, h, m) = map(int, input().split())
a = []
s = 0
for i in range(m):
	(l, r, x) = map(int, input().split())
	b = [l, r, x]
	a.append(b)
for i in range(1, n + 1):
	x = []
	for j in range(m):
		if i in range(a[j][0], a[j][1] + 1):
			x.append(a[j][2])
	if len(x) == 0:
		s += h ** 2
	else:
		s += min(x) ** 2
print(s)


(n, h, m) = [int(item) for item in input().split()]
x = [h ** 2 for _ in range(n)]
for _ in range(m):
	(l, r, xi) = [int(item) for item in input().split()]
	for u in range(l - 1, r):
		x[u] = min(xi ** 2, x[u])
print(sum(x))


def minimum(a, b):
	if a <= b:
		return a
	else:
		return b
(n, h, m) = list(map(int, input().split()))
x = []
mn = [h] * (n + 1)
for i in range(0, m):
	x.append(list(map(int, input().split())))
for j in range(1, n + 1):
	p = 0
	for i in range(0, m):
		if x[i][1] >= j and x[i][0] <= j:
			mn[j] = minimum(mn[j], x[i][2])
			p = p + 1
	if p == 0:
		mn[j] = h
u = 0
for j in range(1, n + 1):
	u = u + mn[j] ** 2
print(u)


def main():
	from sys import stdin, stdout

	def read():
		return stdin.readline().rstrip('\n')

	def read_array(sep=None, maxsplit=-1):
		return read().split(sep, maxsplit)

	def read_int():
		return int(read())

	def read_int_array(sep=None, maxsplit=-1):
		return [int(a) for a in read_array(sep, maxsplit)]

	def write(*args, **kwargs):
		sep = kwargs.get('sep', ' ')
		end = kwargs.get('end', '\n')
		stdout.write(sep.join((str(a) for a in args)) + end)

	def write_array(array, **kwargs):
		sep = kwargs.get('sep', ' ')
		end = kwargs.get('end', '\n')
		stdout.write(sep.join((str(a) for a in array)) + end)
	(n, h, m) = read_int_array()
	restr = [h] * n
	for _ in range(m):
		(l, r, x) = read_int_array()
		for i in range(l - 1, r):
			restr[i] = min(restr[i], x)
	write(sum((x * x for x in restr)))
main()


(n, h, m) = [int(i) for i in input().split()]
S = []
for i in range(n):
	S.append(h)
for i in range(m):
	(l, r, x) = [int(k) for k in input().split()]
	for j in range(l - 1, r):
		if x < S[j]:
			S[j] = x
sum = S[0] * S[0]
for i in range(1, n):
	sum += S[i] * S[i]
print(sum)


(n, h, l) = map(int, input().split())
m = [list(map(int, input().split())) for i in range(l)]
li = [h] * n
for i in range(l):
	for j in range(m[i][0] - 1, m[i][1]):
		li[j] = min(m[i][2], li[j])
ans = 0
for i in li:
	ans += i ** 2
print(ans)


(n, h, m) = [int(x) for x in input().split()]
hi = [h] * n
amt = 0
for i in range(0, m):
	(a, b, c) = [int(x) for x in input().split()]
	for j in range(a - 1, b):
		hi[j] = min(hi[j], c)
for i in range(0, n):
	amt += hi[i] * hi[i]
print(amt)


def sol(n, h, r):
	a = [h] * n
	for lrx in r:
		[l, r, x] = lrx
		for i in range(l - 1, r):
			a[i] = min(a[i], x)
	return sum((v ** 2 for v in a))
[n, h, m] = [int(x) for x in input().split()]
r = []
for _ in range(m):
	r.append([int(x) for x in input().split()])
print(sol(n, h, r))


(n, h, m) = map(int, input().split())
s = [h] * n
for i in range(m):
	x = list(map(int, input().split()))
	for j in range(x[0] - 1, x[1]):
		s[j] = min(s[j], x[2])
print(sum((i ** 2 for i in s)))


n = list(map(int, list(input().split())))
vect = [n[0], n[1], n[2]]
houses = []
limits = []
for i in range(vect[2]):
	m = list(map(int, list(input().split())))
	a = [m[0], m[1], m[2]]
	limits.append(a)
house = list(range(1, vect[0] + 1))
while limits:
	minimal = []
	for j in limits:
		minimal.append(j[2])
	num = minimal.index(min(minimal))
	house_d = []
	for foo in house:
		if foo in list(range(limits[num][0], limits[num][1] + 1)):
			houses.append(limits[num][2])
			house_d.append(foo)
	for foo in house_d:
		house.remove(foo)
	limits.remove(limits[num])
for i in range(vect[0] - len(houses)):
	houses.append(vect[1])
print(sum([x ** 2 for x in houses]))


(n, h, m) = map(int, input().split())
import math
ar = [math.inf] * n
for i in range(m):
	(l, r, x) = map(int, input().split())
	for k in range(l - 1, r):
		ar[k] = min(ar[k], x)
for i in range(len(ar)):
	if ar[i] == math.inf:
		ar[i] = h
s = 0
for i in ar:
	s = s + i ** 2
print(s)


(n, h, m) = map(int, input().split())
tab = [h ** 2 for i in range(n)]
for i in range(m):
	(left, right, hMax) = map(int, input().split())
	for a in range(left - 1, right):
		tab[a] = min(tab[a], hMax ** 2)
print(sum(tab))


(n, h, m) = map(int, input().split())
rest = []
for i in range(m):
	rest.append(list(map(int, input().split())))
maxH = [h] * n
for (l, r, x) in rest:
	for i in range(l - 1, r):
		maxH[i] = min(x, maxH[i])
print(sum((x ** 2 for x in maxH)))


(n, h, m) = map(int, input().split())
x = [h for i in range(n)]
for i in range(m):
	(a, b, c) = map(int, input().split())
	for j in range(a - 1, b):
		if x[j] > c:
			x[j] = c
counter = 0
for i in x:
	counter += i ** 2
print(counter)


import sys

class Main:

	def __init__(self):
		self.buff = None
		self.index = 0

	def next(self):
		if self.buff is None or self.index == len(self.buff):
			self.buff = self.next_line()
			self.index = 0
		val = self.buff[self.index]
		self.index += 1
		return val

	def next_line(self):
		return sys.stdin.readline().split()

	def next_ints(self):
		return [int(x) for x in sys.stdin.readline().split()]

	def next_int(self):
		return int(self.next())

	def solve(self):
		(n, h, m) = self.next_ints()
		hh = [h for _ in range(0, n)]
		for _ in range(0, m):
			(l, r, x) = self.next_ints()
			for i in range(l, r + 1):
				hh[i - 1] = min(hh[i - 1], x)
		print(sum((a ** 2 for a in hh)))
Main().solve()


(n, h, m) = map(int, input().split())
places = [h] * n
for _ in range(m):
	(l, r, m_h) = map(int, input().split())
	for i in range(l - 1, r):
		places[i] = min(m_h, places[i])
sum = 0
for home in places:
	sum += home ** 2
print(sum)


(n, h, m) = map(int, input().split(' '))
borders = []
for i in range(m):
	borders.append(tuple(map(int, input().split(' '))))
heights = [h for i in range(n)]
for b in borders:
	for x in range(b[0], b[1] + 1):
		heights[x - 1] = min(heights[x - 1], b[2])
profit = 0
for i in heights:
	profit += i * i
print(profit)


x = input().split()
proff = int(0)
arr = [int(x[1])] * 50
for i in range(int(x[2])):
	a = input().split()
	a = [int(i) for i in a]
	s = a[0] - 1
	while s < a[1]:
		arr[s] = min(arr[s], a[2])
		s += 1
for q in range(int(x[0])):
	proff += arr[q] ** 2
print(proff)


(n, h, m) = map(int, input().split())
height = [h] * n
for _ in range(m):
	(a, b, c) = map(int, input().split())
	for i in range(a - 1, b):
		height[i] = min(height[i], c)
print(sum((i ** 2 for i in height)))


(a, b, c) = map(int, input().split())
z = [b for _ in range(a)]
for _ in range(c):
	(m, n, o) = map(int, input().split())
	for j in range(m, n + 1):
		if o <= z[j - 1]:
			z[j - 1] = o
m = [i ** 2 for i in z]
print(sum(m))


(n, h, m) = map(int, input().split())
a = {}
for i in range(n):
	a[i + 1] = h
b = {}
for i in range(m):
	(l, r, x) = map(int, input().split())
	i = l
	while i < r + 1:
		b[i] = x
		if b[i] < a[i]:
			a[i] = b[i]
		i = i + 1
b = []
for i in a.values():
	b.append(i)
s = 0
for i in range(len(b)):
	s = s + b[i] ** 2
print(s)


(n, h, m) = map(int, input().split())
lst = [h] * n
for i in range(m):
	(l, r, x) = map(int, input().split())
	for j in range(l - 1, r):
		lst[j] = min(x, lst[j])
sum = 0
for i in lst:
	sum = sum + i * i
print(sum)


ints = [int(x) for x in input().split()]
n = ints[0]
h = ints[1]
m = ints[2]
maxheights = [h for i in range(n)]
for i in range(m):
	integers = [int(x) for x in input().split()]
	for j in range(integers[0] - 1, integers[1]):
		maxheights[j] = min(maxheights[j], integers[2])
maxSum = 0
for i in range(n):
	maxSum = maxSum + maxheights[i] ** 2
print(maxSum)


(n, h, m) = map(int, input().split(' '))
ht = [0] + [h] * n
for i in range(m):
	(l, r, x) = map(int, input().split(' '))
	for p in range(l, r + 1):
		ht[p] = min(ht[p], x)
print(sum(map(lambda x: x * x, ht)))


(n, h, r) = input().split()
n = int(n)
h = int(h)
r = int(r)
l = [h] * n
pr = 0
for i in range(0, r):
	(a, b, c) = input().split()
	for j in range(int(a) - 1, int(b)):
		if l[j] > int(c):
			l[j] = int(c)
for i in range(0, n):
	pr = pr + l[i] * l[i]
print(pr)


(n, h, m) = [int(i) for i in input().split()]
lrx = [[int(j) for j in input().split()] for i in range(m)]
a = [h] * n
for i in lrx:
	for j in range(i[0], i[1] + 1):
		a[j - 1] = min(a[j - 1], i[2])
print(sum(map(lambda i: i ** 2, a)))


import sys, os
f = lambda : list(map(int, input().split()))
if 'local' in os.environ:
	sys.stdin = open('./input.txt', 'r')

def solve():
	(n, h, m) = f()
	hei = [h] * n
	for i in range(m):
		(a, b, c) = f()
		a -= 1
		b -= 1
		for j in range(a, b + 1):
			hei[j] = min(hei[j], c)
	ans = 0
	for i in range(n):
		ans += hei[i] ** 2
	print(ans)
solve()


(n, h, m) = map(int, input().split())
houses = []
for i in range(0, n):
	houses.append(h)
for i in range(0, m):
	(li, ri, xi) = map(int, input().split())
	for j in range(li - 1, ri):
		houses[j] = min(houses[j], xi)
profit = 0
for i in range(0, n):
	profit = profit + houses[i] ** 2
print(profit)


(n, h, m) = map(int, input().split())
ans = [0 for i in range(n)]
for i in range(m):
	(l, r, c) = map(int, input().split())
	for i in range(l - 1, r):
		if c == 0:
			ans[i] = -1
		if ans[i] == 0:
			ans[i] = c
		else:
			ans[i] = min(ans[i], c)
for i in range(n):
	if ans[i] == 0:
		ans[i] = h
ak = 0
for i in range(n):
	if ans[i] == -1:
		pass
	else:
		ak += ans[i] ** 2
print(ak)


(n, h, m) = map(int, input().split())
lis = [h] * n
sum = 0
for i in range(m):
	(l, r, x) = map(int, input().split())
	for i in range(l - 1, r):
		if lis[i] > x:
			lis[i] = x
		else:
			continue
for i in lis:
	sum = sum + i * i
print(sum)


(n, h, m) = map(int, input().split(' '))
ans = 0
height_list = [0] + [h] * n
for _ in range(m):
	(l, r, x) = map(int, input().split(' '))
	for i in range(l, r + 1):
		height_list[i] = min(height_list[i], x)
print(sum(map(lambda x: x ** 2, height_list[:n + 1])))


(n, h, m) = map(int, input().split())
rest = []
for i in range(m):
	rest.append(tuple(map(int, input().split())))
houses = [h for i in range(n)]
for i in rest:
	for j in range(i[0] - 1, i[1]):
		if i[2] < houses[j]:
			houses[j] = i[2]
print(sum([n ** 2 for n in houses]))


(n, h, m) = map(int, input().split())
height = [h] * (n + 1)
height[0] = 0
for _ in range(m):
	(l, r, x) = map(int, input().split())
	for i in range(l, r + 1):
		height[i] = min(height[i], x)
profit = 0
for h in height:
	profit += h * h
print(profit)


(n, h, m) = map(int, input().split())
usl = [list(map(int, input().split())) for i in range(m)]
sum = 0
for i in range(1, n + 1):
	x = h
	for u in usl:
		if u[0] <= i <= u[1]:
			x = min(x, u[2])
	sum += x * x
print(sum)


(n, h, m) = map(int, input().split())
a = [h for i in range(n)]
for i in range(m):
	(l, r, mh) = map(int, input().split())
	for j in range(l - 1, r):
		a[j] = min(a[j], mh)
s = 0
for i in range(n):
	s += a[i] ** 2
print(s)


(n, h, m) = [int(i) for i in input().strip().split(' ')]
money = [h] * n
for _ in range(m):
	(l, r, area_h) = [int(i) for i in input().strip().split(' ')]
	for inx in range(l - 1, r):
		if money[inx] > area_h:
			money[inx] = area_h
print(sum((m ** 2 for m in money)))


(n, h, m) = map(int, input().split())
it = [h for i in range(n)]
for i in range(m):
	(l, r, x) = map(int, input().split())
	for j in range(l - 1, r):
		if it[j] > x:
			it[j] = x
res = 0
for i in it:
	res += i ** 2
print(res)


(n, h, m) = map(int, input().split())
arr = []
for i in range(m):
	arr1 = list(map(int, input().split()))
	arr.append(arr1)
ans = 0
for i in range(1, n + 1):
	h1 = h
	for j in range(m):
		if arr[j][0] <= i <= arr[j][1]:
			h1 = min(h1, arr[j][2])
	ans += h1 * h1
print(ans)


(n, h, m) = map(int, input().split())
a = []
for i in range(m):
	(l, r, x) = map(int, input().split())
	a.append((l, r, x))
a.sort(key=lambda x: x[2], reverse=True)
ans = [h] * (n + 1)
ans[0] = 0
for i in a:
	(l, r, x) = (i[0], i[1], i[2])
	for j in range(l, r + 1):
		ans[j] = x
out = 0
for i in ans:
	out += i * i
print(out)


(a, b, c) = map(int, input().split())
d = []
f = []
s = 0
for _ in ' ' * c:
	(z, e, q) = map(int, input().split())
	f += [[q, z, e]]
f = sorted(f)
for i in f:
	for j in range(i[1], i[2] + 1):
		if j not in d:
			d.append(j)
			s += i[0] ** 2
print(s + b ** 2 * (a - len(d)))


(n, h, m) = map(int, input().split())
pro = 0
lst = [h] * n
for i in range(m):
	(li, ri, xi) = map(int, input().split())
	for j in range(li - 1, ri):
		if xi < lst[j]:
			lst[j] = xi
for k in lst:
	pro += k * k
print(pro)


fuck = lambda : map(int, input().split())
(N, H, comand) = fuck()
distance = [H] * N
for _ in range(comand):
	(x, y, val) = fuck()
	for idx in range(x - 1, y):
		distance[idx] = min(val, distance[idx])
print(sum((x * x for x in distance)))


[n, h, m] = input().split()
n = int(n)
h = int(h)
m = int(m)
li = []
for i in range(n):
	li.append(-1)
for i in range(m):
	[l, r, x] = input().split()
	l = int(l)
	r = int(r)
	x = int(x)
	for j in range(l - 1, r):
		if li[j] == -1 or li[j] > x:
			li[j] = x
for i in range(len(li)):
	if li[i] == -1:
		li[i] = h
	li[i] = li[i] ** 2
print(sum(li))


(n, h, m) = list((int(a) for a in input().split()))
place = [h] * n
for i in range(0, m):
	(l, r, k) = list((int(a) for a in input().split()))
	for j in range(l - 1, r):
		place[j] = min(place[j], k)
su = 0
for i in place:
	su += i * i
print(su)


def main():
	line = input()
	(n, h, m) = [int(x) for x in line.split()]
	heights = [h] * n
	for i in range(m):
		line = input()
		(i, j, limit) = [int(x) for x in line.split()]
		for k in range(i - 1, j):
			if heights[k] > limit:
				heights[k] = limit
	print(sum(map(lambda x: x ** 2, heights)))
main()


nhm = list(map(int, input().split()))
a = [nhm[1]] * nhm[0]
for i in range(nhm[2]):
	b = list(map(int, input().split()))
	for j in range(b[0] - 1, b[1]):
		a[j] = min(a[j], b[2])
print(sum([i * i for i in a]))