Animesh has $n$ empty candy jars, numbered from ${1}$ to $n$, with infinite capacity. He performs $m$ operations. Each operation is described by $3$ integers, ${a}$, ${b}$, and ${k}$. Here, ${a}$ and ${b}$ are indices of the jars, and ${k}$ is the number of candies to be added inside each jar whose index lies between ${a}$ and ${b}$ (both inclusive).
Can you tell the average number of candies after $m$ operations?

Example    

$n=5$ 

$operations=[[1,2,10],[3,5,10]]$   

The array has $5$ elements that all start at ${0}$.  In the first operation, add $10$ to the first $2$ elements.  Now the array is $[10,10,0,0,0]$.  In the second operation, add $10$ to the last $3$ elements (3 - 5).  Now the array is $[10,10,10,10,10]$ and the average is 10.  Sincd 10 is already an integer value, it does not need to be rounded.  

Function Description   

Complete the solve function in the editor below.   

solve has the following parameters:   

int n: the number of candy jars   
int operations[m][3]: a 2-dimensional array of operations   

Returns   

int: the floor of the average number of canidies in all jars  

Input Format

The first line contains two integers, $n$ and $m$, separated by a single space. 

$m$ lines follow.  Each of them contains three integers, ${a}$, ${b}$, and ${k}$, separated by spaces.

Constraints

$3\leq n\leq10^7$ 

$1\leq m\leq10^5$ 

$1\leq a\leq b\leq N$ 

$0\leq k\leq10^6$

Sample Input
STDIN       Function
-----       --------
5 3         n = 5, operations[] size = 3
1 2 100     operations = [[1, 2, 100], [2, 5, 100], [3, 4, 100]]
2 5 100
3 4 100

Sample Output
160

Explanation

Initially each of the jars contains 0 candies  

0 0 0 0 0  

First operation:  

100 100 0 0 0  

Second operation:  

100 200 100 100 100  

Third operation: 

100 200 200 200 100  

Total = 800, Average = 800/5 = 160

Difficulty: EASY
Tags: Mathematics

Starter code:

Solutions:
inp = [int(a) for a in input().split()]
tot = 0
for i in range(inp[1]):
	inp1 = [int(a) for a in input().split()]
	tot += (inp1[1] - inp1[0] + 1) * inp1[2]
print(int(tot / inp[0]))


(numJars, numLines) = map(int, input().strip().split())
total = 0
for x in range(numLines):
	(a, b, k) = map(int, input().strip().split())
	total += (b - a + 1) * k
print(total // numJars)


line = input().split()
n = int(line[0])
m = int(line[1])
total = 0
for i in range(m):
	line = input().split()
	total += (int(line[1]) - int(line[0]) + 1) * int(line[2])
print(int(total / n))


import sys
line = sys.stdin.readline()
(n, m) = map(int, line.split())
total = 0
for i in range(m):
	line = sys.stdin.readline()
	(a, b, k) = map(int, line.split())
	total += (max(a, b) - min(a, b) + 1) * k
print(total // n)


inp = input().split(' ')
N = int(inp[0])
M = int(inp[1])
all = 0
for i in range(M):
	read = input().split(' ')
	a = int(read[0])
	b = int(read[1])
	k = int(read[2])
	all += (b - a + 1) * k
print(int(all / N))


(n, m) = [int(x) for x in input().split()]
ans = 0
for i in range(m):
	(a, b, k) = [int(x) for x in input().split()]
	ans = ans + k * (b - a + 1)
print(int(ans / n))


a = [int(i) for i in input().split(' ')]
count = 0
for i in range(a[1]):
	b = [int(i) for i in input().split(' ')]
	count += (b[1] - b[0] + 1) * b[2] / a[0]
print(int(count))


import sys
(N, M) = list(map(int, sys.stdin.readline().split()))
total = 0
for _ in range(M):
	(a, b, k) = list(map(int, sys.stdin.readline().split()))
	total += (b - a + 1) * k
print(total // N)


def main():
	n = list(map(int, input().split()))
	s = 0
	for i in range(n[1]):
		x = list(map(int, input().split()))
		s = s + (1 + x[1] - x[0]) * x[2]
	print(s // n[0])
main()


(n, m) = input().split()
(n, m) = [int(n), int(m)]
sum = 0
while m != 0:
	(a, b, k) = input().split()
	(a, b, k) = [int(a), int(b), int(k)]
	sum += k * (b - a + 1) / n
	m -= 1
print(int(sum))


line = input()
n = int(line.split(' ')[0])
m = int(line.split(' ')[1])
s = 0
for i in range(0, m):
	line = input()
	a = int(line.split(' ')[0])
	b = int(line.split(' ')[1])
	k = int(line.split(' ')[2])
	s = s + k * (b - a + 1)
print(int(s / n))


s = input()
s = s.split(' ')
n = int(s[0])
m = int(s[1])
jSum = 0
for i in range(m):
	s = input()
	s = s.split(' ')
	a = int(s[0])
	b = int(s[1])
	k = int(s[2])
	jSum += (b - a + 1) * k
print(int(jSum / n))


strng = input()
IN = strng.split(' ')
N = int(IN[0])
M = int(IN[1])
SUM = 0
for i in range(0, M):
	strng1 = input()
	IN1 = strng1.split(' ')
	a = int(IN1[0])
	b = int(IN1[1])
	k = int(IN1[2])
	SUM = SUM + (b - a + 1) * k
AVG = int(SUM / N)
print(AVG)


import sys
from collections import deque
import heapq
from math import *
from itertools import *
PI = pi
INF = 1000000000

def gl():
	return input()

def gs():
	return (x for x in input().split())

def gi():
	return int(input())

def gis():
	return [int(x) for x in input().split()]

def gf():
	return float(input())

def gfs():
	return [float(x) for x in input().split()]

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

def odd(x):
	return x % 2 == 1
sum = 0
(n, m) = gis()
for i in range(m):
	(a, b, k) = gis()
	sum += (b - a + 1) * k
print(floor(sum / n))


(N, M) = [int(x) for x in input().split()]
sum = 0
for i in range(M):
	(a, b, k) = [int(x) for x in input().split()]
	sum += (b - a + 1) * k
print(sum // N)


(N, M) = [int(x) for x in input().split()]
sum = 0
for i in range(M):
	(a, b, k) = [int(x) for x in input().split()]
	sum += (b - a + 1) * k
print(sum // N)


(N, M) = (int(k) for k in input().split())
cookies = 0
for i in range(M):
	(low, high, amount) = (int(k) for k in input().split())
	cookies += (high - low + 1) * amount
print(cookies // N)


(N, M) = [int(x) for x in input().split()]
count = 0
for _ in range(M):
	(a, b, n) = [int(x) for x in input().split()]
	count += (b - a + 1) * n
print(count // N)


a = [int(x) for x in input().split()]
n = a[0]
m = a[1]
tot = 0
for i in range(0, m):
	a = [int(x) for x in input().split()]
	tot += (a[1] - a[0] + 1) * a[2]
print(tot // n)


s = list(map(int, input().split(' ')))
n = s[0]
m = s[1]
x = 0
for _ in range(m):
	s = list(map(int, input().split(' ')))
	x += (s[1] - s[0] + 1) * s[2]
print(x // n)


import sys
lines = list(sys.stdin)
jars = int(lines[0].split()[0])
total = 0
for line in lines[1:]:
	(start, end, amount) = [int(k) for k in line.split()]
	total += (end - start + 1) * amount
print(int(total / jars))


import sys
import math
line = sys.stdin.readline().split()
N = int(line[0])
M = int(line[1])
a = []
b = []
k = []
for index in range(M):
	operation = sys.stdin.readline().split()
	a.append(int(operation[0]))
	b.append(int(operation[1]))
	k.append(int(operation[2]))
total = 0
for index in range(len(a)):
	number = b[index] - a[index] + 1
	total += number * k[index]
print(math.floor(total / N))


(n, m) = map(int, input().split())
tot = 0
for i in range(m):
	(a, b, k) = map(int, input().split())
	tot += (b - a + 1) * k
print(tot // n)


def fun():
	n = input()
	n1 = n.split()
	n2 = int(n1[0])
	m = int(n1[1])
	s = 0
	for i in range(m):
		ip = input()
		ip1 = ip.split()
		j = int(ip1[0])
		k = int(ip1[1])
		c = int(ip1[2])
		s = s + (k - j + 1) * c
	print(int(s / n2))
fun()


import sys
n = int(sys.stdin.readline().split(' ')[0])
sum = 0
for l in sys.stdin:
	l = l.rstrip('\n').split(' ')
	l = list(map(int, l))
	sum = sum + (l[1] - l[0] + 1) * l[2]
print(sum // n)


import sys
data = sys.stdin.readlines()
first = data[0].split()
SUM = 0
for line in range(1, int(first[1]) + 1):
	LIST = data[line].split()
	SUM += int(LIST[2]) * (int(LIST[1]) - int(LIST[0]) + 1)
print(SUM // int(first[0]))


s = input().strip().split()
n = int(s[0])
m = int(s[1])
b = 0
while m:
	m -= 1
	s = input().strip().split()
	p = int(s[1]) - int(s[0]) + 1
	b += int(s[-1]) * p
print(b // n)


(n, m) = (int(s) for s in input().split())
totalsum = 0
for i in range(m):
	(a, b, k) = (int(s) for s in input().split())
	totalsum += (b - a + 1) * k
print(int(totalsum / n))


(n, m) = [int(i) for i in input().strip().split()]
candies = 0
for j in range(0, m):
	(a, b, k) = [int(l) for l in input().strip().split()]
	candies += k * (b - a + 1)
avg_cand = int(candies / n)
print(avg_cand)


import sys
line = sys.stdin.readline().split(' ')
(numjars, numops) = (int(line[0]), int(line[1]))
ops = []
for i in range(numops):
	line = sys.stdin.readline().split(' ')
	ops.append((int(line[0]), int(line[1]), int(line[2])))
numcandies = 0
for i in range(numops):
	numcandies = numcandies + (ops[i][1] - ops[i][0] + 1) * ops[i][2]
print(numcandies // numjars)


(N, T) = [int(x) for x in input().split(' ')]
s = 0
for t in range(0, T):
	(a, b, c) = [int(x) for x in input().split(' ')]
	s += (b - a + 1) * c
print(s // N)


(N, M) = [int(x) for x in input().split()]
result = 0
while M > 0:
	(a, b, k) = [int(x) for x in input().split()]
	result += (b - a + 1) * k
	M -= 1
print(result // N)


import sys
sys.path
T = input()
Tc = T.split(' ', 2)
Operations = int(Tc[1])
L = []
for r in range(0, int(Tc[0])):
	L.append(0)
Total = 0
for x in range(0, Operations):
	S = input()
	Ss = S.split(' ', 3)
	a = int(Ss[0]) - 1
	b = int(Ss[1]) - 1
	k = int(Ss[2])
	Total = Total + (b - a + 1) * k
print(round(Total // len(L)))


(jar_count, op_count) = map(int, input().split())
candy_count = 0
for op in range(op_count):
	(a, b, k) = map(int, input().split())
	candy_count += (b - a + 1) * k
print(candy_count // jar_count)


(n, m) = map(int, input().split())
t = 0
for _ in range(m):
	(a, b, k) = map(int, input().split())
	t += (b - a + 1) * k
print(t // n)


line = input()
n1 = line.split()
n = int(n1[0])
m = int(n1[1])
total = 0
for i in range(1, m + 1):
	line2 = input()
	n2 = line2.split()
	i1 = int(n2[0])
	i2 = int(n2[1])
	val = int(n2[2])
	total = total + (i2 - i1 + 1) * val
avg = int(total / n)
print(avg)


import math
(N, M) = [int(x) for x in input().split()]
total = 0
jars = [0] * N
for step in range(M):
	(A, B, K) = [int(x) for x in input().split()]
	total += (B - A + 1) * K
print(str(math.floor(int(total) / N)))


import sys

def main():
	(n, m) = (int(i) for i in sys.stdin.readline().split())
	total = 0
	for _ in range(m):
		(a, b, k) = (int(i) for i in sys.stdin.readline().split())
		total += (b - a + 1) * k
	print(total // n)
main()


(n, m) = [int(x) for x in input().split()]
total = 0
for _ in range(m):
	(a, b, k) = [int(x) for x in input().split()]
	total += (b + 1 - a) * k
print(total // n)


import sys
import functools
[N, M] = [int(X) for X in sys.stdin.readline().split()]
operations = [tuple(sys.stdin.readline().split()) for X in range(M)]
f = lambda acc, op: acc + (int(op[1]) - int(op[0]) + 1) * int(op[2])
avg = functools.reduce(f, operations, 0) // N
print(avg)


import sys

def main():
	(N, T) = [int(n) for n in sys.stdin.readline().split(' ', 1)]
	testcases_list = []
	for t in range(T):
		testcase = [int(n) for n in sys.stdin.readline().split(' ', 2)]
		testcases_list.append(testcase)
	total = 0
	for testcase in testcases_list:
		total += (testcase[1] - testcase[0] + 1) * testcase[2]
	print(int(total / N))
main()


f = input().split(' ')
n = int(f[0])
m = int(f[1])
candy = [0 for i in range(n)]
c = 0
sum = 0
while m > c:
	q = input().split(' ')
	a = int(q[0])
	b = int(q[1])
	k = int(q[2])
	sum += (b - a + 1) * k
	c += 1
print(int(sum / n))


import sys
(n, m) = (int(i) for i in sys.stdin.readline().split())
sum = 0
for _ in range(m):
	(a, b, x) = (int(i) for i in sys.stdin.readline().split())
	sum += x * (b - a + 1)
sum = sum // n
sys.stdout.write(str(sum) + '\n')


import sys
import math
f = sys.stdin
input = [int(i) for i in f.readline().split()]
num_jars = input[0]
size = input[1]
i = 0
sum = 0
while i < size:
	vals = [int(i) for i in f.readline().split()]
	sum += vals[2] * (vals[1] - vals[0] + 1)
	i += 1
print(math.floor(sum / num_jars))


l = input().split()
cap = []
s = 0
for i in range(int(l[0])):
	cap.append(0)
for i in range(int(l[1])):
	x = input().split()
	a = int(x[0])
	b = int(x[1])
	k = int(x[2])
	s = s + (b - a + 1) * k
print(int(s / len(cap)))


(n, m) = input().split()
m = int(m)
sum = 0
for i in range(0, m):
	(a, b, c) = input().split()
	sum += (int(b) - int(a) + 1) * int(c)
print(sum // int(n))


line = input().split()
n = int(line[0])
m = int(line[1])
sum = 0
for x in range(0, m):
	line = input().split()
	a = int(line[0])
	b = int(line[1])
	k = int(line[2])
	sum += (b - a + 1) * k
print(sum // n)


from math import floor
(N, M) = input().split()
operations = []
for i in range(int(M)):
	(a, b, k) = input().split()
	operations.append((int(b) + 1 - int(a)) * int(k))
print(floor(sum(operations) / int(N)))


(N, M) = input().split()
N = eval(N)
M = eval(M)
sum = 0
for op in range(M):
	(ind1, ind2, ind3) = input().split()
	ind1 = int(ind1)
	ind2 = int(ind2)
	candy = int(ind3)
	sum += candy * (ind2 - ind1 + 1)
print(sum // N)


(N, T) = input().split(' ')
N = int(N)
T = int(T)
sumall = 0
for i in range(0, T):
	(A, B, C1) = input().split(' ')
	A = int(A)
	B = int(B)
	C1 = int(C1)
	sumall += (B + 1 - A) * C1
print(int(sumall / N))


import sys
(N, M) = list(map(int, sys.stdin.readline().split()))
total = 0
for _ in range(M):
	(a, b, k) = list(map(int, sys.stdin.readline().split()))
	total += (b - a + 1) * k
print(total // N)


line = input()
newLine = line.split()
N = int(newLine[0])
M = int(newLine[1])
total = 0
for j in range(M):
	line2 = input()
	newLine2 = line2.split()
	a = int(newLine2[0])
	b = int(newLine2[1])
	c = int(newLine2[2])
	distance = b - a + 1
	total = total + distance * c
print(total // N)


(n, m) = input().split()
n = int(n)
m = int(m)
sum = 0
l = [input().split() for j in range(m)]
for i in range(m):
	for j in range(3):
		l[i][j] = int(l[i][j])
for i in range(m):
	sum += (l[i][1] - l[i][0] + 1) * l[i][2]
print(int(sum / n))


import sys
lines = []
for line in sys.stdin:
	lines.append(line)
params = lines[0].split()
ops = lines[1:]
N = int(params[0])
M = int(params[1])
total = 0
for op in ops:
	op = op.split()
	a = int(op[0])
	b = int(op[1])
	m = int(op[2])
	added = (b - a + 1) * m
	total = total + added
print(int(total / N))


import sys
(numjars, numtests) = [int(x) for x in sys.stdin.readline().split()]
total = 0
while int(numtests) > 0:
	(start, end, numcandies) = [int(x) for x in sys.stdin.readline().split()]
	total += (end - start + 1) * numcandies
	numtests -= 1
print(int(total / numjars))


def getLine():
	return list(map(int, str(input()).split()))
(N, M) = getLine()
jars = [0]
for i in range(N):
	jars.append(0)
total = 0
for i in range(M):
	(a, b, k) = getLine()
	total += k * (b - a + 1)
print(total // N)


(njar, nops) = input().split()
(njar, nops) = (int(njar), int(nops))
tot = 0
for i in range(nops):
	(a, b, k) = input().split()
	(a, b, k) = (int(a), int(b), int(k))
	tot += (b - a + 1) * k
print(int(tot / njar))


from sys import stdin
(n, m) = map(int, stdin.readline().split())
total = 0
for i in range(m):
	(a, b, k) = map(int, stdin.readline().split())
	total += (b - a + 1) * k
print(total // n)


(N, M) = [int(x) for x in input().split()]
current = 0
for test in range(M):
	(a, b, k) = [int(x) for x in input().split()]
	current += (b - a + 1) * k
print(current // N)


(N, M) = map(int, input().strip().split())
cases = [list(map(int, input().strip().split())) for i in range(M)]
print(int(sum((x[2] * (x[1] - x[0] + 1) for x in cases)) / N))


(N, M) = [int(x) for x in input().split()]
result = 0
for line in range(M):
	(a, b, k) = [int(x) for x in input().split()]
	result += (b - a + 1) * k
print(result // N)


import sys
T = [int(i) for i in sys.stdin.readline().split()]
SUM = 0
for i in range(T[1]):
	ADD = [int(i) for i in sys.stdin.readline().split()]
	SUM += ADD[2] * (ADD[1] - ADD[0] + 1)
print(int(SUM / T[0]))


data = input()
list1 = data.split(' ')
N = int(list1[0])
t = int(list1[1])
sum = 0
while t > 0:
	line = input()
	list2 = line.split(' ')
	a = int(list2[0])
	b = int(list2[1])
	sum += (b - a + 1) * int(list2[2])
	t -= 1
print(int(sum / N))


(N, M) = [int(i) for i in input().split()]
candies = 0
for _ in range(M):
	(a, b, k) = [int(i) for i in input().split()]
	candies += k * (b - a + 1)
print(candies // N)


(N, M) = [int(x) for x in input().split(' ')]
total_candies = 0
for i in range(1, M + 1):
	(a, b, k) = [int(x) for x in input().split(' ')]
	total_candies += (b - a + 1) * k
print(int(total_candies / N))


def main():
	(N, M) = [int(i) for i in input().split()]
	result = 0
	for n in range(M):
		(a, b, k) = [int(i) for i in input().split()]
		result += (b - a + 1) * k
	print(int(result / N))
main()


(N, M) = [int(i) for i in str(input()).split()]
total = 0
for m in range(M):
	(a, b, k) = [int(i) for i in str(input()).split()]
	total += k * (b - a + 1)
print(total // N)


(n, m) = [int(x) for x in input().split()]
sum1 = 0
for _ in range(m):
	(a, b, k) = [int(x) for x in input().split()]
	sum1 += (b - a + 1) * k
print(sum1 // n)


(N, M) = input().split(' ')
total = 0
for i in range(0, int(M)):
	(a, b, k) = [int(x) for x in input().split(' ')]
	n = int(b - a + 1)
	total = int(total + n * k)
answer = int(total / int(N))
print(answer)


(N, M) = (int(s) for s in input().split())
t = 0
for i in range(M):
	(a, b, k) = (int(s) for s in input().split())
	t += k * (b - a + 1)
print(t // N)


(n, tests) = input().split()
n = int(n)
tests = int(tests)
sum = 0
for a in range(tests):
	(i, j, k) = input().split()
	(i, j, k) = (int(i), int(j), int(k))
	sum += (j - i + 1) * k
j = int(sum / n)
print(j)


(N, M) = str(input()).split()
res = 0
for i in range(int(M)):
	(a, b, k) = str(input()).split()
	res += (int(b) - int(a) + 1) * int(k)
print(res // int(N))


(n, tc) = map(int, input().split())
tot = 0
for c in range(tc):
	(a, b, k) = map(int, input().split())
	tot = tot + (b - a + 1) * k
print(int(tot / n))


x = [int(j) for j in input().split()]
n = x[0]
sum = 0
for i in range(x[1]):
	oper = [int(j) for j in input().split()]
	(a, b, k) = oper
	sum += (b - a + 1) * k
print(int(sum / n))


data = input().strip().split()
N = int(data[0])
M = int(data[1])
total = 0
for m in range(M):
	nums = input().strip().split()
	a = int(nums[0])
	b = int(nums[1])
	k = int(nums[2])
	total += k * (b - a + 1)
print(int(total / N))


import math

def get_num():
	a = input()
	a = a.split(' ')
	for i in range(len(a)):
		a[i] = eval(a[i])
	return a
line_1 = get_num()
N = line_1[0]
M = line_1[1]
total = 0
for e in range(M):
	line = get_num()
	total += line[2] * (line[1] - line[0] + 1)
print(math.floor(total / N))


from math import floor
(N, M) = [int(x) for x in input().split()]
sum = 0
for m in range(M):
	(a, b, k) = [int(x) for x in input().split()]
	sum += (b - a + 1) * k
print(floor(sum / N))


(n, m) = (int(x) for x in input().split())
candies = 0
for _ in range(m):
	(a, b, k) = (int(x) for x in input().split())
	candies += (b - a + 1) * k
print(int(candies / n))


(n, m) = map(int, input().split())
total = 0
for _ in range(m):
	(a, b, k) = map(int, input().split())
	total += k * (b - a + 1)
print(total // n)


(N, M) = input().split()
jars = [0 for i in range(int(N))]
ans = 0
for i in range(int(M)):
	(a, b, k) = input().split()
	n = (int(b) - int(a) + 1) * int(k)
	ans = ans + n
d = int(ans / int(N))
print(d)


import math
sum = 0
avg = 0
(N, M) = input().split(' ')
N = int(N)
M = int(M)
for i in range(M):
	(a, b, k) = input().split(' ')
	a = int(a)
	b = int(b)
	k = int(k)
	sum += k * (math.fabs(a - b) + 1)
avg = int(sum / N)
print(avg)


(N, M) = (int(i) for i in input().split())
total = 0
for i in range(M):
	(a, b, k) = (int(i) for i in input().split())
	total += (b - a + 1) * k
print(int(total / N))


(n, m) = map(int, input().split())
rt = 0
for i in range(m):
	(a, b, k) = map(int, input().split())
	rt += k * (b - a + 1)
print(rt // n)


from sys import stdin
(N, M) = map(int, stdin.readline().split())
total = 0
for _ in range(M):
	(a, b, k) = map(int, stdin.readline().split())
	total += (b - a + 1) * k
print(int(total / N))


x = input().split()
num = 0
for i in range(int(x[1])):
	y = input().split()
	num += (int(y[1]) - int(y[0]) + 1) * int(y[2])
print(int(num / int(x[0])))


(jars, operations) = str(input()).split()
jars = int(jars)
operations = int(operations)
candy = 0
for i in range(operations):
	(a, b, k) = str(input()).split()
	(a, b, k) = (int(a), int(b), int(k))
	candy += (b - a + 1) * k
print(candy // jars)


(N, M) = [int(x) for x in input().split()]
total = 0
for m in range(M):
	(i, j, k) = [int(x) for x in input().split()]
	total += (j - i + 1) * k
print(total // N)


line = input().split()
(N, M) = (int(line[0]), int(line[1]))
candies = 0
for m in range(M):
	(a, b, k) = [int(x) for x in input().split()]
	candies += k * (b - a + 1)
print(candies // N)


inp = input().split()
(N, M) = (int(inp[0]), int(inp[1]))
sum = 0
for i in range(M):
	inp = input().split()
	(a, b, k) = (int(inp[0]), int(inp[1]), int(inp[2]))
	sum += (b - a + 1) * k
print(sum // N)


import sys as s
rl = s.stdin.readline
(n, m) = rl().split(' ')
(m, n) = (int(m), int(n))
t = 0
for a in range(m):
	(b, c, d) = rl().split(' ')
	(b, c, d) = (int(b), int(c) + 1, int(d))
	t += abs(c - b) * d
s.stdout.write(str(t // n))


(N, M) = [int(e) for e in input().split()]
sum = 0
for m in range(M):
	(a, b, k) = [int(e) for e in input().split()]
	sum += (b - a + 1) * k
print(int(sum / N))


import sys
with sys.stdin as f:
	(n, m) = [int(x) for x in f.readline().split()]
	total = 0
	for i in range(m):
		(lb, ub, qty) = [int(x) for x in f.readline().split()]
		total += (ub - lb + 1) * qty
	print(total // n)


[N, M] = [int(i) for i in str(input()).split()]
tot = 0
for m in range(M):
	[a, b, k] = [int(i) for i in str(input()).split()]
	tot += (b - a + 1) * k
print(int(tot / N))


temp = input().split()
n = int(temp[0])
m = int(temp[1])
total = 0
for i in range(m):
	temp = input().split()
	a = int(temp[0])
	b = int(temp[1])
	k = int(temp[2])
	total += k * (b - a + 1)
print(int(total / n))


[N, M] = [int(x) for x in input().split()]
sum = 0
for _ in range(M):
	[a, b, k] = [int(x) for x in input().split()]
	sum += (b + 1 - a) * k
print(sum // N)


import sys
(N, M) = [int(item) for item in next(sys.stdin).split()]
total = 0
for i in range(M):
	(a, b, k) = [int(item) for item in next(sys.stdin).split()]
	total += k * (b - a + 1)
print(int(total / N))


import sys
inp = iter(sys.stdin)

def read_line():
	return (int(i) for i in next(inp).split())
(N, M) = read_line()
J = [0 for i in range(N)]
n_sum = 0
for _ in range(M):
	(a, b, k) = list((int(x) for x in read_line()))
	n_sum += (b - (a - 1)) * k
avarages = int(n_sum / N)
print(avarages)


def process():
	each_case = input()
	(a, b, candies) = each_case.split(' ')
	a = int(a)
	b = int(b)
	candies = int(candies)
	return (b + 1 - a) * candies
jars_test = input()
(jars, test) = jars_test.split(' ')
jars = int(jars)
test = int(test)
total = 0
for i in range(0, test):
	total += process()
res = int(total / jars)
print(res)