#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);
int /*<<< orphan*/ scanf(char *, long *, long *, ...);
long trunc(long);
int main() {
  long int a, b, i, z, j, c, d, e;
  static long int count = 0;
  scanf("%ld %ld", &a, &b);
  for (i = 1; i <= b; i++) {
    scanf("%ld %ld %ld", &c, &d, &e);
    count = count + (d - c + 1) * e;
  }
  z = trunc(count / a);
  printf("%ld", z);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xebe(%rip),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdx
mov    $0x0,%al
call   1050 <scanf@plt>
movq   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jg     11b8 <main+0x88>
lea    0xe8e(%rip),%rdi
lea    -0x38(%rbp),%rsi
lea    -0x40(%rbp),%rdx
lea    -0x48(%rbp),%rcx
mov    $0x0,%al
call   1050 <scanf@plt>
mov    0x2eb4(%rip),%rax
mov    -0x40(%rbp),%rcx
sub    -0x38(%rbp),%rcx
add    $0x1,%rcx
imul   -0x48(%rbp),%rcx
add    %rcx,%rax
mov    %rax,0x2e99(%rip)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    115d <main+0x2d>
mov    0x2e81(%rip),%rax
cqto
idivq  -0x10(%rbp)
mov    %rax,%rdi
call   1040 <trunc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xe2c(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x30,%rsp
lea    0xec0(%rip),%rdi
lea    0x28(%rsp),%rsi
lea    0x8(%rsp),%rdx
xor    %eax,%eax
call   1050 <scanf@plt>
cmpq   $0x0,0x8(%rsp)
jle    11c2 <main+0x92>
lea    0xe9c(%rip),%r14
lea    0x20(%rsp),%r15
lea    0x18(%rsp),%r12
lea    0x10(%rsp),%r13
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0x18(%rsp),%rax
sub    0x20(%rsp),%rax
add    $0x1,%rax
imul   0x10(%rsp),%rax
add    0x2e92(%rip),%rax
mov    %rax,0x2e8b(%rip)
add    $0x1,%rbx
cmp    0x8(%rsp),%rbx
jl     1180 <main+0x50>
jmp    11c9 <main+0x99>
mov    0x2e77(%rip),%rax
mov    0x28(%rsp),%rcx
mov    %rax,%rdx
or     %rcx,%rdx
shr    $0x20,%rdx
je     11e1 <main+0xb1>
cqto
idiv   %rcx
jmp    11e5 <main+0xb5>
xor    %edx,%edx
div    %ecx
mov    %rax,%rdi
call   1040 <trunc@plt>
lea    0xe14(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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