Under construction

Still being built. Things may change

Dunes

Interview

Time limit2sMemory limit512 MB

Summary
Each gust adds +x to l and then alternates signs up to r; answer m queries for the final height at given positions.
Level

Medium4 of 10

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

Problem

The geographer Grigory Georgievich studies how sand dunes form. He picked a very long dune and divided it into a huge number of sections, numbered from 1 to 10910^9.

Grigory Georgievich's theory states that initially the sand height at every section, measured from some reference level, was zero. After that, nn strong wind gusts blew, and each could change the terrain.

Gust number ii had strength x_ix\_i and acted on the sections from l_il\_i to r_ir\_i. As a result of this gust, the height of section l_il\_i increased by x_ix\_i, the height of section l_i+1l\_i+1 decreased by x_ix\_i, the next one increased again, and so on up to section r_ir\_i, inclusive.

Knowing all the information about all nn gusts, Grigory Georgievich wants to find the final height of some mm sections that interest him. Help him.

Input

The first line of the input file contains two positive integers nn and mm (1≤n,m≤10001 \le n, m \le 1000): the number of wind gusts and the number of sections whose final height interests Grigory Georgievich.

Each of the next nn lines contains a description of one wind gust: three integers l_i,r_i,x_il\_i, r\_i, x\_i (1≤l_i≤r_i≤1091 \le l\_i \le r\_i \le 10^9; 1≤x_i≤10001 \le x\_i \le 1000).

Each of the next mm lines contains an integer q_iq\_i (1≤q_i≤1091 \le q\_i \le 10^9): the number of the section whose final height must be found. The section numbers are given in increasing order.

Output

For each of the mm queries, output one integer: the height of the corresponding section.

Examples1

  1. Example 1

    Input
    2 6
    1 6 7
    3 7 2
    1
    2
    3
    6
    7
    8
    
    Expected output
    7
    -7
    9
    -9
    2
    0