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

#SRD0000042. Vua Kẹo

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Vua Kẹo

Vua Kẹo

Source: VNOJ

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn people arranged in positions 11 through nn. Person ii has ai≥0a_i\ge0 candies. Position ii is a candy king if its count equals the sum of all counts to its left:

ai=∑j=1i−1aj.a_i=\sum_{j=1}^{i-1}a_j.

The sum before position 11 is 00. Each of qq updates p x assigns ap=xa_p=x and then asks for any valid candy-king position. Output -1 if no such position exists. Multiple correct indices may exist.

Input

The first line contains n,qn,q, the next line contains the initial candy counts, and the next qq lines each contain p x.

Output

After each assignment, output any valid king index or -1 if no king exists.

Subtasks

  • Subtask 1 (15 points): 1≤n≤401\le n\le40; 1≤q≤601\le q\le60; 0≤ai,x≤1090\le a_i,x\le10^9; a query may have multiple valid answers.
  • Subtask 2 (25 points): 1≤n≤15001\le n\le1500; 1≤q≤20001\le q\le2000; 0≤ai,x≤1090\le a_i,x\le10^9; a query may have multiple valid answers.
  • Subtask 3 (25 points): 1≤n≤150001\le n\le15000; 1≤q≤150001\le q\le15000; 0≤ai,x≤1090\le a_i,x\le10^9; a query may have multiple valid answers.
  • Subtask 4 (35 points): 1≤n≤2000001\le n\le200000; 1≤q≤2000001\le q\le200000; 0≤ai,x≤1090\le a_i,x\le10^9; a query may have multiple valid answers.

Examples

Input

3 4
2 2 3
1 1
1 2
2 4
3 6

Output

3
2
-1
3

Explanation

Initially [2,2,3][2,2,3]. Set a1=1a_1=1 to get [1,2,3][1,2,3], in which index 33 is valid. Restore a1=2a_1=2, and index 22 becomes valid. Setting a2=4a_2=4 removes all kings; finally setting a3=6a_3=6 makes index 33 valid.