PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#PS0000279. Tổng của các tổng tiền tố (Prefix of Prefix)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Tổng của các tổng tiền tố (Prefix of Prefix)

Prefix of Prefix

Source: Phước Hưng OJ

Version: Phuoc Hung OJ Extended

Problem Statement

Given an integer array a1,…,ana_1,\ldots,a_n, define Pi=∑j=1iajP_i=\sum_{j=1}^i a_j. For each query (l,r)(l,r), compute ∑i=lrPi\sum_{i=l}^r P_i. Every prefix starts at index 1, not at ll.

Input

First line: n,qn,q. Second line: nn integers aia_i. Each of the next qq lines contains two integers l,rl,r.

Output

Print one answer per line, in query order.

Subtasks

  • Subtask 1 (20 points): 1≤n≤301\le n\le30; 1≤q≤401\le q\le40; ∣ai∣≤1000000|a_i|\le1000000; 1≤l≤r≤n1\le l\le r\le n.
  • Subtask 2 (30 points): 1≤n≤2000001\le n\le200000; 1≤q≤2000001\le q\le200000; ∣ai∣≤1000000|a_i|\le1000000; 1≤l≤r≤n1\le l\le r\le n; l=rl=r for every query.
  • Subtask 3 (50 points): 1≤n≤2000001\le n\le200000; 1≤q≤2000001\le q\le200000; ∣ai∣≤1000000|a_i|\le1000000; 1≤l≤r≤n1\le l\le r\le n.

Example 1

Input

4 3
2 -3 4 1
1 4
2 4
3 3

Output

8
6
3

Explanation

P=(2,-1,3,4). The sums are 2-1+3+4=8; -1+3+4=6; 3.

Example 2

Input

1 1
-5
1 1

Output

-5

Explanation

P1=-5.