#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 */
scalar_t__ abs(int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *, ...);
int main(void) {
  int num, day, move, town = 0, temp, road[100000] = {0}, sum = 0, i;
  scanf("%d %d", &num, &day);
  for (i = 0; i < num - 1; i++) {
    scanf("%d", &temp);
    road[i + 1] = road[i] + temp;
  }
  for (i = 0; i < day; i++) {
    scanf("%d", &move);
    sum += abs(road[town + move] - road[town]);
    sum %= 100000;
    town += move;
  }
  printf("%d\n", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x61ab0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
lea    -0x61aa0(%rbp),%rdi
xor    %esi,%esi
mov    $0x61a80,%edx
call   1050 <memset@plt>
movl   $0x0,-0x61aa4(%rbp)
lea    0xe83(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
mov    $0x0,%al
call   1060 <scanf@plt>
movl   $0x0,-0x61aa8(%rbp)
mov    -0x61aa8(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11f3 <main+0xb3>
lea    0xe52(%rip),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
movslq -0x61aa8(%rbp),%rax
mov    -0x61aa0(%rbp,%rax,4),%ecx
add    -0x18(%rbp),%ecx
mov    -0x61aa8(%rbp),%eax
add    $0x1,%eax
cltq
mov    %ecx,-0x61aa0(%rbp,%rax,4)
mov    -0x61aa8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x61aa8(%rbp)
jmp    1196 <main+0x56>
movl   $0x0,-0x61aa8(%rbp)
mov    -0x61aa8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1281 <main+0x141>
lea    0xdf0(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x14(%rbp),%eax
add    -0x10(%rbp),%eax
cltq
mov    -0x61aa0(%rbp,%rax,4),%edi
movslq -0x14(%rbp),%rax
sub    -0x61aa0(%rbp,%rax,4),%edi
call   1030 <abs@plt>
mov    %rax,%rcx
movslq -0x61aa4(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x61aa4(%rbp)
mov    -0x61aa4(%rbp),%eax
mov    $0x186a0,%ecx
cltd
idiv   %ecx
mov    %edx,-0x61aa4(%rbp)
mov    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x61aa8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x61aa8(%rbp)
jmp    11fd <main+0xbd>
mov    -0x61aa4(%rbp),%esi
lea    0xd78(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x61ab0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x61a90,%rsp
lea    0x10(%rsp),%rdi
xor    %r12d,%r12d
mov    $0x61a80,%edx
xor    %esi,%esi
call   1050 <memset@plt>
lea    0xe96(%rip),%rdi
lea    0x8(%rsp),%rsi
lea    0x4(%rsp),%rdx
xor    %eax,%eax
call   1060 <scanf@plt>
cmpl   $0x2,0x8(%rsp)
jl     11bb <main+0x7b>
lea    0xe7a(%rip),%r14
lea    0xc(%rsp),%r15
xor    %ebx,%ebx
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    0xc(%rsp),%eax
add    0x10(%rsp,%rbx,4),%eax
mov    %eax,0x14(%rsp,%rbx,4)
add    $0x1,%rbx
movslq 0x8(%rsp),%rax
add    $0xffffffffffffffff,%rax
cmp    %rax,%rbx
jl     1190 <main+0x50>
cmpl   $0x0,0x4(%rsp)
jle    1233 <main+0xf3>
lea    0xe3a(%rip),%r14
mov    %rsp,%r15
xor    %ebp,%ebp
xor    %r12d,%r12d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
movslq (%rsp),%rax
movslq %ebx,%rbx
add    %rbx,%rax
mov    0x10(%rsp,%rax,4),%edi
sub    0x10(%rsp,%rbx,4),%edi
call   1030 <abs@plt>
add    %r12d,%eax
movslq %eax,%r12
imul   $0x14f8b589,%r12,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x2d,%rax
add    %ecx,%eax
imul   $0x186a0,%eax,%eax
add    (%rsp),%ebx
sub    %eax,%r12d
add    $0x1,%ebp
cmp    0x4(%rsp),%ebp
jl     11e0 <main+0xa0>
lea    0xdcc(%rip),%rdi
mov    %r12d,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x61a90,%rsp
pop    %rbx
pop    %r12
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 = [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 i32
%7 = alloca [100000 x i32]
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %5
%10 = bitcast [100000 x i32]* %7 to i8*
store i32 0, i32* %8
%11 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %2, i32* %3)
store i32 0, i32* %9
br label %12
12: ; preds = %29, %0
%13 = load i32, i32* %9
%14 = load i32, i32* %2
%15 = sub nsw i32 %14, 1
%16 = icmp slt i32 %13, %15
br i1 %16, label %17, label %32
17: ; preds = %12
%18 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%19 = load i32, i32* %9
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [100000 x i32], [100000 x i32]* %7, i64 0, i64 %20
%22 = load i32, i32* %21
%23 = load i32, i32* %6
%24 = add nsw i32 %22, %23
%25 = load i32, i32* %9
%26 = add nsw i32 %25, 1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [100000 x i32], [100000 x i32]* %7, i64 0, i64 %27
store i32 %24, i32* %28
br label %29
29: ; preds = %17
%30 = load i32, i32* %9
%31 = add nsw i32 %30, 1
store i32 %31, i32* %9
br label %12
32: ; preds = %12
store i32 0, i32* %9
br label %33
33: ; preds = %60, %32
%34 = load i32, i32* %9
%35 = load i32, i32* %3
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %63
37: ; preds = %33
%38 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%39 = load i32, i32* %5
%40 = load i32, i32* %4
%41 = add nsw i32 %39, %40
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [100000 x i32], [100000 x i32]* %7, i64 0, i64 %42
%44 = load i32, i32* %43
%45 = load i32, i32* %5
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [100000 x i32], [100000 x i32]* %7, i64 0, i64 %46
%48 = load i32, i32* %47
%49 = sub nsw i32 %44, %48
%50 = call i64 @abs(i32 %49)
%51 = load i32, i32* %8
%52 = sext i32 %51 to i64
%53 = add nsw i64 %52, %50
%54 = trunc i64 %53 to i32
store i32 %54, i32* %8
%55 = load i32, i32* %8
%56 = srem i32 %55, 100000
store i32 %56, i32* %8
%57 = load i32, i32* %4
%58 = load i32, i32* %5
%59 = add nsw i32 %58, %57
store i32 %59, i32* %5
br label %60
60: ; preds = %37
%61 = load i32, i32* %9
%62 = add nsw i32 %61, 1
store i32 %62, i32* %9
br label %33
63: ; preds = %33
%64 = load i32, i32* %8
%65 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %64)
ret i32 0
}

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