#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 *, int);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  int N, Q, a, b;
  scanf("%d %d", &N, &Q);
  int arr[N + 1];
  int sum[N + 1];
  char str[10];
  int i;
  arr[0] = 0;
  for (i = 1; i <= N; i++) {
    scanf("%d", &arr[i]);
    sum[i] = sum[i - 1] + arr[i];
  }
  while (Q--) {
    scanf("%s %d %d", str, &a, &b);
    printf("%d\n", sum[b] - sum[a - 1]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xecd(%rip),%rdi
xor    %eax,%eax
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,%ecx
mov    %rsp,%rax
mov    %rax,-0x20(%rbp)
lea    0xf(,%rcx,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rax
sub    %rdx,%rax
mov    %rax,-0x50(%rbp)
mov    %rax,%rsp
mov    %rcx,-0x28(%rbp)
mov    -0x8(%rbp),%ecx
add    $0x1,%ecx
lea    0xf(,%rcx,4),%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x48(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x30(%rbp)
movl   $0x0,(%rax)
movl   $0x1,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11fa <main+0xda>
mov    -0x50(%rbp),%rsi
movslq -0x40(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x50(%rbp),%rcx
mov    -0x48(%rbp),%rax
mov    -0x40(%rbp),%edx
sub    $0x1,%edx
movslq %edx,%rdx
mov    (%rax,%rdx,4),%edx
movslq -0x40(%rbp),%rsi
add    (%rcx,%rsi,4),%edx
movslq -0x40(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    11a1 <main+0x81>
jmp    11ff <main+0xdf>
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
je     1255 <main+0x135>
lea    -0x3a(%rbp),%rsi
lea    0xde2(%rip),%rdi
lea    -0x10(%rbp),%rdx
lea    -0x14(%rbp),%rcx
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x48(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
sub    (%rax,%rcx,4),%esi
lea    0xdbe(%rip),%rdi
call   1030 <printf@plt>
jmp    11ff <main+0xdf>
movl   $0x0,-0x4(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
lea    0xecb(%rip),%rdi
lea    -0x2c(%rbp),%rsi
lea    -0x30(%rbp),%rdx
xor    %eax,%eax
call   1040 <scanf@plt>
mov    %rsp,-0x40(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%rcx
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
mov    %rcx,%r12
sub    %rax,%r12
mov    %r12,%rsp
neg    %rax
mov    -0x2c(%rbp),%edx
lea    0x1(%rdx),%esi
mov    %rsp,%r14
lea    0xf(,%rsi,4),%rsi
and    $0xfffffffffffffff0,%rsi
sub    %rsi,%r14
mov    %r14,%rsp
movl   $0x0,(%rcx,%rax,1)
test   %edx,%edx
jle    11cc <main+0xac>
add    $0x4,%r12
xor    %r13d,%r13d
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
lea    (%r12,%r13,1),%rsi
lea    0xe5b(%rip),%rdi
xor    %eax,%eax
call   1040 <scanf@plt>
add    (%r12,%rbx,4),%r15d
mov    %r15d,0x4(%r14,%rbx,4)
movslq -0x2c(%rbp),%rax
add    $0x1,%rbx
add    $0x4,%r13
cmp    %rax,%rbx
jl     11a0 <main+0x80>
subl   $0x1,-0x30(%rbp)
jb     1226 <main+0x106>
lea    -0x4a(%rbp),%r15
lea    -0x38(%rbp),%r12
lea    -0x34(%rbp),%r13
lea    0xe24(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nop
lea    0xe09(%rip),%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
xor    %eax,%eax
call   1040 <scanf@plt>
movslq -0x34(%rbp),%rax
mov    (%r14,%rax,4),%esi
movslq -0x38(%rbp),%rax
sub    -0x4(%r14,%rax,4),%esi
mov    %rbx,%rdi
call   1030 <printf@plt>
subl   $0x1,-0x30(%rbp)
jae    11f0 <main+0xd0>
mov    -0x40(%rbp),%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%d %d\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [9 x i8] c"%s %d %d\00"
@.str.3 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca [10 x i8]
%10 = alloca i32
store i32 0, i32* %1
%11 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %2, i32* %3)
%12 = load i32, i32* %2
%13 = add nsw i32 %12, 1
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %6
%16 = alloca i32, i64 %14
store i64 %14, i64* %7
%17 = load i32, i32* %2
%18 = add nsw i32 %17, 1
%19 = zext i32 %18 to i64
%20 = alloca i32, i64 %19
store i64 %19, i64* %8
%21 = getelementptr inbounds i32, i32* %16, i64 0
store i32 0, i32* %21
store i32 1, i32* %10
br label %22
22: ; preds = %44, %0
%23 = load i32, i32* %10
%24 = load i32, i32* %2
%25 = icmp sle i32 %23, %24
br i1 %25, label %26, label %47
26: ; preds = %22
%27 = load i32, i32* %10
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %16, i64 %28
%30 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %29)
%31 = load i32, i32* %10
%32 = sub nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %20, i64 %33
%35 = load i32, i32* %34
%36 = load i32, i32* %10
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %16, i64 %37
%39 = load i32, i32* %38
%40 = add nsw i32 %35, %39
%41 = load i32, i32* %10
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i32, i32* %20, i64 %42
store i32 %40, i32* %43
br label %44
44: ; preds = %26
%45 = load i32, i32* %10
%46 = add nsw i32 %45, 1
store i32 %46, i32* %10
br label %22
47: ; preds = %22
br label %48
48: ; preds = %52, %47
%49 = load i32, i32* %3
%50 = add nsw i32 %49, -1
store i32 %50, i32* %3
%51 = icmp ne i32 %49, 0
br i1 %51, label %52, label %66
52: ; preds = %48
%53 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%54 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %53, i32* %4, i32* %5)
%55 = load i32, i32* %5
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i32, i32* %20, i64 %56
%58 = load i32, i32* %57
%59 = load i32, i32* %4
%60 = sub nsw i32 %59, 1
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i32, i32* %20, i64 %61
%63 = load i32, i32* %62
%64 = sub nsw i32 %58, %63
%65 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %64)
br label %48
66: ; preds = %48
store i32 0, i32* %1
%67 = load i8*, i8** %6
%68 = load i32, i32* %1
ret i32 %68
}

LLVM IR (-O2):
@.str = [6 x i8] c"%d %d\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [9 x i8] c"%s %d %d\00"
@.str.3 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [10 x i8]
%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 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %1, i32* %2)
%11 = load i32, i32* %1
%12 = add nsw i32 %11, 1
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
%15 = alloca i32, i64 %13
%16 = load i32, i32* %1
%17 = add nsw i32 %16, 1
%18 = zext i32 %17 to i64
%19 = alloca i32, i64 %18
%20 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
store i32 0, i32* %15
%21 = icmp slt i32 %16, 1
br i1 %21, label %22, label %26
22: ; preds = %26, %0
%23 = load i32, i32* %2
%24 = add nsw i32 %23, -1
store i32 %24, i32* %2
%25 = icmp eq i32 %23, 0
br i1 %25, label %54, label %38
26: ; preds = %0, %26
%27 = phi i32 [ %32, %26 ], [ undef, %0 ]
%28 = phi i64 [ %34, %26 ], [ 1, %0 ]
%29 = getelementptr inbounds i32, i32* %15, i64 %28
%30 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %29)
%31 = load i32, i32* %29
%32 = add nsw i32 %31, %27
%33 = getelementptr inbounds i32, i32* %19, i64 %28
store i32 %32, i32* %33
%34 = add nuw nsw i64 %28, 1
%35 = load i32, i32* %1
%36 = sext i32 %35 to i64
%37 = icmp slt i64 %28, %36
br i1 %37, label %26, label %22
38: ; preds = %22, %38
%39 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %20, i32* %3, i32* %4)
%40 = load i32, i32* %4
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i32, i32* %19, i64 %41
%43 = load i32, i32* %42
%44 = load i32, i32* %3
%45 = add nsw i32 %44, -1
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i32, i32* %19, i64 %46
%48 = load i32, i32* %47
%49 = sub nsw i32 %43, %48
%50 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %49)
%51 = load i32, i32* %2
%52 = add nsw i32 %51, -1
store i32 %52, i32* %2
%53 = icmp eq i32 %51, 0
br i1 %53, label %54, label %38
54: ; preds = %38, %22
ret i32 0
}