Under construction

Still being built. Things may change

Why the Cows Climbed onto the Information Island

Time limit2sMemory limit256 MB

Summary
On a circle of N values, each query flips one value's sign; after every query print the sum of products over all N windows of four consecutive cows.
Level

Medium6 of 10

Topics
Implementation, Math, Array, Brute force
Solved
No attempts yet

Problem

NN cows have climbed onto the Information Island!

The cows are resting in the front yard on the first floor of the Information Island, sitting in a circle in the order A1,A2,A3,…,AN,A1A_1, A_2, A_3, \dots, A_N, A_1. Each cow has a sticker with a quality score AiA_i on it. Next to the herd, Ukje found a formula that Hyobin had worked out, and it looks like this.

S=∑i=1N(Ai×Ai+1×Ai+2×Ai+3)S = \sum_{i=1}^N(A_{i}\times A_{i+1}\times A_{i+2}\times A_{i+3}) (where AN+1=A1,AN+2=A2,AN+3=A3A_{N+1}=A_{1}, A_{N+2}=A_{2}, A_{N+3}=A_{3})

In words, for the cows sitting in a circle, it is the sum of the products of the quality scores of every four consecutive cows.

Ukje plans to be mean so that Hyobin cannot leave school. Over QQ rounds, Ukje will pick some ii-th cow. Then he will peel off the sticker with AiA_i and stick on a sticker with Ai×−1A_i \times -1. Hyobin then has to recompute SS QQ times. A sticker stays swapped until it gets swapped again later.

You, Hyobin's best friend, have decided to help Hyobin, who is being tormented by the troublemaker Ukje. Help Hyobin compute SS!

Input

The first line gives NN, the number of cows, and QQ, the number of times Ukje will play his trick.

The second line gives the quality scores AiA_i of the NN cows in order.

The third line gives the QQ cow indices QiQ_i that Ukje will pick, in order.

Output

Over QQ lines, print the recomputed value of SS.

Constraints

  • 4≤N≤200 0004 ≤ N ≤ 200\,000
  • 1≤Q≤200 0001 ≤ Q ≤ 200\,000
  • 1≤∣Ai∣≤101 ≤ |A_i| ≤ 10
  • 1≤Qi≤N1 ≤ Q_i ≤ N

Examples1

  1. Example 1

    Input
    8 5
    -2 3 5 -6 10 -8 7 6
    3 5 2 7 7
    
    Expected output
    -1080
    1920
    4224
    2376
    4224