Yeongseon's company praises downward. When a boss praises a direct subordinate, that subordinate's own subordinates receive praise of the same size, and it keeps spreading to the bottom of the hierarchy.
Yeongseon, the president, flips the direction in which praise spreads during the workday. The starting direction is the subordinate direction.
- Subordinate direction: when an employee receives w praise, that employee and every subordinate under them each receive w praise.
- Boss direction: when an employee receives w praise, that employee and every boss above them each receive w praise.
Praise arrives in real time. There are three kinds of queries.
1 i w: if the current direction is the subordinate direction, employee i receives w praise from the direct boss. If it is the boss direction, employee i receives w praise from one of the direct subordinates. Either way the praise spreads in the current direction. (1≤i≤n, 1≤w≤1000)
2 i: print the total praise employee i has received so far.
3: flip the direction of praise. The subordinate direction becomes the boss direction, and the boss direction becomes the subordinate direction.
Given the direct boss of every employee and the list of queries, print the answer for every query of type 2.