#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, long long);
int /*<<< orphan*/ scanf(char *, int *, int *, ...);
int main() {
  int n, m, a, b, k, i;
  long long int c = 0, t;
  scanf("%d%d", &n, &m);
  while (m--) {
    scanf("%d%d%d", &a, &b, &k);
    t = b - a + 1;
    t *= k;
    c += t;
  }
  c /= n;
  printf("%lld\n", c);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x28(%rbp)
lea    0xec4(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
je     11a8 <main+0x88>
lea    0xe98(%rip),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
lea    -0x18(%rbp),%rcx
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x14(%rbp),%eax
sub    -0x10(%rbp),%eax
add    $0x1,%eax
cltq
mov    %rax,-0x30(%rbp)
movslq -0x18(%rbp),%rax
imul   -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    114d <main+0x2d>
movslq -0x8(%rbp),%rcx
mov    -0x28(%rbp),%rax
cqto
idiv   %rcx
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xe43(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
lea    0xece(%rip),%rdi
xor    %ebx,%ebx
lea    0x1c(%rsp),%rsi
lea    0xc(%rsp),%rdx
xor    %eax,%eax
call   1040 <scanf@plt>
subl   $0x1,0xc(%rsp)
jb     11a3 <main+0x83>
lea    0xeab(%rip),%r14
lea    0x18(%rsp),%r15
lea    0x14(%rsp),%r12
lea    0x10(%rsp),%r13
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x14(%rsp),%eax
sub    0x18(%rsp),%eax
add    $0x1,%eax
cltq
movslq 0x10(%rsp),%rcx
imul   %rax,%rcx
add    %rcx,%rbx
subl   $0x1,0xc(%rsp)
jae    1170 <main+0x50>
movslq 0x1c(%rsp),%rcx
mov    %rbx,%rax
or     %rcx,%rax
shr    $0x20,%rax
je     11be <main+0x9e>
mov    %rbx,%rax
cqto
idiv   %rcx
jmp    11c4 <main+0xa4>
mov    %ebx,%eax
xor    %edx,%edx
div    %ecx
lea    0xe3c(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%d%d\00"
@.str.1 = [7 x i8] c"%d%d%d\00"
@.str.2 = [6 x i8] c"%lld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
%9 = alloca i64
store i32 0, i32* %1
store i64 0, i64* %8
%10 = call i32 (i8*, i32*, i32*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %2, i32* %3)
br label %11
11: ; preds = %15, %0
%12 = load i32, i32* %3
%13 = add nsw i32 %12, -1
store i32 %13, i32* %3
%14 = icmp ne i32 %12, 0
br i1 %14, label %15, label %29
15: ; preds = %11
%16 = call i32 (i8*, i32*, i32*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32* %4, i32* %5, i32* %6)
%17 = load i32, i32* %5
%18 = load i32, i32* %4
%19 = sub nsw i32 %17, %18
%20 = add nsw i32 %19, 1
%21 = sext i32 %20 to i64
store i64 %21, i64* %9
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = load i64, i64* %9
%25 = mul nsw i64 %24, %23
store i64 %25, i64* %9
%26 = load i64, i64* %9
%27 = load i64, i64* %8
%28 = add nsw i64 %27, %26
store i64 %28, i64* %8
br label %11
29: ; preds = %11
%30 = load i32, i32* %2
%31 = sext i32 %30 to i64
%32 = load i64, i64* %8
%33 = sdiv i64 %32, %31
store i64 %33, i64* %8
%34 = load i64, i64* %8
%35 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 %34)
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"%d%d\00"
@.str.1 = [7 x i8] c"%d%d%d\00"
@.str.2 = [6 x i8] c"%lld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %1 to i8*
%7 = bitcast i32* %2 to i8*
%8 = bitcast i32* %3 to i8*
%9 = bitcast i32* %4 to i8*
%10 = bitcast i32* %5 to i8*
%11 = call i32 (i8*, i32*, i32*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %1, i32* %2)
%12 = load i32, i32* %2
%13 = add nsw i32 %12, -1
store i32 %13, i32* %2
%14 = icmp eq i32 %12, 0
br i1 %14, label %30, label %15
15: ; preds = %0, %15
%16 = phi i64 [ %26, %15 ], [ 0, %0 ]
%17 = call i32 (i8*, i32*, i32*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32* %3, i32* %4, i32* %5)
%18 = load i32, i32* %4
%19 = load i32, i32* %3
%20 = add i32 %18, 1
%21 = sub i32 %20, %19
%22 = sext i32 %21 to i64
%23 = load i32, i32* %5
%24 = sext i32 %23 to i64
%25 = mul nsw i64 %22, %24
%26 = add nsw i64 %25, %16
%27 = load i32, i32* %2
%28 = add nsw i32 %27, -1
store i32 %28, i32* %2
%29 = icmp eq i32 %27, 0
br i1 %29, label %30, label %15
30: ; preds = %15, %0
%31 = phi i64 [ 0, %0 ], [ %26, %15 ]
%32 = load i32, i32* %1
%33 = sext i32 %32 to i64
%34 = sdiv i64 %31, %33
%35 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 %34)
ret i32 0
}