Problem: You are given a rooted tree. Each vertex contains tons of gold, which costs per one ton. Initially, the tree consists only a root numbered with tons of gold and price per ton.
There are queries. Each query has one of two types:
- Add vertex (where is an index of query) as a son to some vertex ; vertex will have tons of gold with per ton. It's guaranteed that .
- For a given vertex consider the simple path from to the root. We need to purchase tons of gold from vertices on this path, spending the minimum amount of money. If there isn't enough gold on the path, we buy all we can.
If we buy tons of gold in some vertex the remaining amount of gold in it decreases by (of course, we can't buy more gold that vertex has at the moment). For each query of the second type, calculate the resulting amount of gold we bought and the amount of money we should spend.
Note that you should solve the problem in online mode. It means that you can't read the whole input at once. You can read each query only after writing the answer for the last query, so don't forget to flush output after printing answers. You can use functions like fflush(stdout) in C++ and BufferedWriter.flush in Java or similar after each writing in your program. In standard (if you don't tweak I/O), endl flushes cout in C++ and System.out.println in Java (or println in Kotlin) makes automatic flush as well.
Input Format: The first line contains three integers , and (; ) — the number of queries, the amount of gold in the root and its price.
Next lines contain descriptions of queries; The -th query has one of two types:
- " " (; ): add vertex as a son to vertex . The vertex will have tons of gold with price per one ton. It's guaranteed that exists and .
- " " (; ): buy tons of gold from vertices on path from to spending the minimum amount of money. If there isn't enough gold, we buy as much as we can. It's guaranteed that vertex exist.
It's guaranteed that there is at least one query of the second type.
Output Format: For each query of the second type, print the resulting amount of gold we bought and the minimum amount of money we should spend.
Note: Explanation of the sample:
At the first query, the tree consist of root, so we purchase tons of gold and pay . tons remain in the root.
At the second query, we add vertex as a son of vertex . Vertex now has tons of gold with price per one ton.
At the third query, a path from to consists of only vertices and and since we buy remaining tons of gold in vertex and ton in vertex . So we bought tons and paid . Now, in vertex no gold left and tons of gold remain in vertex .
At the fourth query, we add vertex as a son of vertex . Vertex now has ton of gold with price .
At the fifth query, a path from to consists of only vertices and . But since no gold left in vertex and only ton is in vertex , we buy ton of gold in vertex and spend . Now, in vertex no gold left.