Company Culture 3

Employees sit in a rooted tree. A praise of w given to employee i from a subordinate adds w to i and every ancestor up to the president; type 2 queries ask an employee's running total.

Medium5TreeDFSPrefix sumImplementationNo attempts yetTime limit2sMemory limit512 MB

Problem

Yeongseon's company praises from the top down. When a manager praises a direct subordinate, the praise cascades to every employee below that subordinate. Yeongseon, the president, decided to reverse the direction for exactly one day. When a subordinate praises a manager, that manager and every employee above, all the way up to the president, receive the same amount of praise.

Praise arrives in real time as queries of two kinds.

  • 1 i w: employee i receives praise of amount ww from one direct subordinate. That ww is added to employee i and to every manager above employee i. (1in1 \le i \le n, 1w10001 \le w \le 1000) An employee with no direct subordinate never appears in this query.
  • 2 i: print the total praise employee i has received so far. (1in1 \le i \le n)

Input

The first line has the number of employees nn and the number of queries mm. Employees are numbered 1 through nn. (2n,m1000002 \le n, m \le 100\,000)

The second line has the direct manager of employee 1 through employee nn, in order. A manager's number is always smaller than the employee's own number. Employee 1 is the president and has no manager, so -1 is given in that position.

Each of the next mm lines has one query.

Output

For every query of type 2, print the total praise that employee has received, one per line.