The Traveler
InterviewTime limit1sMemory limit128 MB
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 post towns along it. The post towns are numbered from to in order from west to east: post town is the westernmost and post town is the easternmost.
Starting from post town , you set out on a journey of days. Your itinerary follows a sequence , where each is a nonzero integer describing your move on day . If you begin day at post town , then on day you travel in a straight line from post town to post town .
Given the number of post towns , the number of days , the distances between adjacent post towns, and the movement sequence , write a program that computes the total distance you travel over the days, taken modulo .
Input
The first line contains two integers and , separated by a space. Here () is the number of post towns along the JOI Road, and () is the number of days of the journey.
Each of the next lines gives a distance between adjacent post towns: line () contains a positive integer (), the distance between post town and post town .
Each of the next lines gives one element of the movement sequence: line () contains the nonzero integer describing your move on day .
It is guaranteed that you never move west of post town or east of post town .
Output
Output a single line containing the total distance you travel over the days, taken modulo .
Note
For the first sample: on day you move from post town to post town ; on day from post town to post town ; on day from post town to post town ; on day from post town to post town ; and on day from post town to post town . The total distance over the days is .
