#SGM0000012. Truy vấn tổng đoạn con lớn nhất III (Can you answer these queries III)

Truy vấn tổng đoạn con lớn nhất III (Can you answer these queries III)

Can you answer these queries III

Source: SPOJ

Version: Phuoc Hung OJ Extended

Given an array A1,A2,…,ANA_1,A_2,\ldots,A_N, process two operations:

  • 0 x y: assign Ax=yA_x=y.
  • 1 x y: print the maximum sum of a non-empty contiguous subarray inside [x,y][x,y].

Input

The first line contains NN.

The second line contains the array.

The third line contains QQ.

The next QQ lines describe the operations.

Output

For every operation of type 1, print the answer on its own line.

Subtasks

  • Subtask 1 — 20%: 1≤N,Q≤501\le N,Q\le 50, ∣Ai∣,∣y∣≤1000|A_i|,|y|\le 1000.
  • Subtask 2 — 30%: 1≤N,Q≤50001\le N,Q\le 5000, ∣Ai∣,∣y∣≤104|A_i|,|y|\le 10^4.
  • Subtask 3 — 50%: 1≤N,Q≤500001\le N,Q\le 50000, ∣Ai∣,∣y∣≤104|A_i|,|y|\le 10^4.

Examples

Input

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

Output

6
4
-3

Explanation

The sample follows the operations exactly; each printed line corresponds to a query that requires output.