#CCBCHBAHAI0000040. Truy vết vòng for duyệt mảng (Trace an Array Traversal For Loop)

Truy vết vòng for duyệt mảng (Trace an Array Traversal For Loop)

Trace an Array Traversal For Loop

Source: Phước Hưng OJ

Version: Phuoc Hung OJ Extended

Problem Statement

You are given a one-dimensional array of nn integers a0,a1,…,an−1a_0,a_1,\ldots,a_{n-1}. Consider a loop that traverses the array in increasing index order. Before the loop, set S=0S=0. At iteration ii, first update S←S+aiS\leftarrow S+a_i, then record the triple (i,ai,S)(i,a_i,S).

Print the complete trace of this loop. The value of SS on each line is the prefix sum from a0a_0 through aia_i.

Input

  • The first line contains the integer nn.
  • The second line contains exactly nn integers a0,a1,…,an−1a_0,a_1,\ldots,a_{n-1}.

Output

Print exactly nn lines. Line i+1i+1 contains ii, aia_i, and SiS_i, where

Si=∑j=0iaj.S_i=\sum_{j=0}^{i}a_j.

Subtasks

Subtask 1 (20 points): n=1n=1, −9≤a0≤9-9\le a_0\le9.

Subtask 2 (30 points): 2≤n≤202\le n\le20, 0≤ai≤1040\le a_i\le10^4.

Subtask 3 (50 points): 1≤n≤10001\le n\le1000, −109≤ai≤109-10^9\le a_i\le10^9.

Examples

Input

5
4 -2 7 0 3

Output

0 4 4
1 -2 2
2 7 9
3 0 9
4 3 12

Explanation

Initially S=0S=0.

  • For i=0i=0, a0=4a_0=4, so S=4S=4.
  • For i=1i=1, a1=−2a_1=-2, so S=2S=2.
  • For i=2i=2, a2=7a_2=7, so S=9S=9.
  • For i=3i=3, a3=0a_3=0, so SS remains 99.
  • For i=4i=4, a4=3a_4=3, so S=12S=12.

Each line reports the current index, the current element, and the updated sum.