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

#DSU0000097. Các bình chứa nước (Vessels)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Các bình chứa nước (Vessels)

Vessels

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn vessels ordered from top to bottom, with capacities aia_i liters. Initially all vessels are empty. Water poured into vessel pp fills it first, then any overflow passes to vessel p+1p+1, and so on. Water overflowing from vessel nn is lost. Process two operations in order: 1 p x pours xx liters into vessel pp; 2 k asks for the amount of water currently held in vessel kk. Overflow is fully settled before each query.

Input

The first line contains nn; the second contains a1,…,ana_1,\ldots,a_n; the next line contains mm; then follow mm operations in the formats described above.

Output

For each query of type 2, print the amount of water in the requested vessel on one line.

Subtasks

  • Subtask 1 (20 points): 1≤n≤301\le n\le 30, 1≤m≤401\le m\le 40, 1≤ai≤201\le a_i\le 20, 1≤pi,ki≤n1\le p_i,k_i\le n, 1≤xi≤1031\le x_i\le 10^3.
  • Subtask 2 (30 points): 1≤n≤1801\le n\le 180, 1≤m≤2501\le m\le 250, 1≤ai≤1051\le a_i\le 10^5, 1≤pi,ki≤n1\le p_i,k_i\le n, 1≤xi≤1091\le x_i\le 10^9.
  • Subtask 3 (50 points): 1≤n,m≤2⋅1051\le n,m\le 2\cdot10^5, 1≤ai,xi≤1091\le a_i,x_i\le 10^9, 1≤pi,ki≤n1\le p_i,k_i\le n.

Examples

Input

2
5 10
6
1 1 4
2 1
1 2 5
1 1 4
2 1
2 2

Output

4
5
8

Explanation

The first pour leaves 44 liters in vessel 11. After subsequent operations, vessel 11 contains 55 liters and vessel 22 contains 88 liters.