The Traveler

Interview

Time limit1sMemory limit128 MB

Summary
Given gaps between n towns and a walk of m east/west jumps, find the total distance covered, reported mod 100000.
Level

Easy3 of 10

Topics
Prefix sum, Array, Implementation, Simulation
Solved
No attempts yet

Problem

You are a traveler journeying along the JOI Road. The JOI Road is a straight road running east to west, and there are nn post towns along it. The post towns are numbered from 11 to nn in order from west to east: post town 11 is the westernmost and post town nn is the easternmost.

Starting from post town 11, you set out on a journey of mm days. Your itinerary follows a sequence a1,a2,…,ama_1, a_2, \ldots, a_m, where each aia_i is a nonzero integer describing your move on day ii. If you begin day ii at post town kk, then on day ii you travel in a straight line from post town kk to post town k+aik + a_i.

Given the number of post towns nn, the number of days mm, the distances between adjacent post towns, and the movement sequence a1,a2,…,ama_1, a_2, \ldots, a_m, write a program that computes the total distance you travel over the mm days, taken modulo 100000=105100000 = 10^5.

Input

The first line contains two integers nn and mm, separated by a space. Here nn (2≤n≤100000=1052 \le n \le 100000 = 10^5) is the number of post towns along the JOI Road, and mm (1≤m≤100000=1051 \le m \le 100000 = 10^5) is the number of days of the journey.

Each of the next n−1n - 1 lines gives a distance between adjacent post towns: line i+1i + 1 (1≤i≤n−11 \le i \le n - 1) contains a positive integer sis_i (1≤si≤1001 \le s_i \le 100), the distance between post town ii and post town i+1i + 1.

Each of the next mm lines gives one element of the movement sequence: line i+ni + n (1≤i≤m1 \le i \le m) contains the nonzero integer aia_i describing your move on day ii.

It is guaranteed that you never move west of post town 11 or east of post town nn.

Output

Output a single line containing the total distance you travel over the mm days, taken modulo 100000=105100000 = 10^5.

Note

For the first sample: on day 11 you move from post town 11 to post town 33; on day 22 from post town 33 to post town 22; on day 33 from post town 22 to post town 55; on day 44 from post town 55 to post town 77; and on day 55 from post town 77 to post town 44. The total distance over the 55 days is 1818.

Examples5

  1. Example 1

    Input
    7 5
    2
    1
    1
    3
    2
    1
    2
    -1
    3
    2
    -3
    
    Expected output
    18
    
  2. Example 2

    Input
    2 1
    5
    1
    
    Expected output
    5
    
  3. Example 3

    Input
    2 4
    100
    1
    -1
    1
    -1
    
    Expected output
    400
    
  4. Example 4

    Input
    5 1
    1
    2
    3
    4
    4
    
    Expected output
    10
    
  5. Example 5

    Input
    4 2
    10
    20
    30
    3
    -3
    
    Expected output
    120