#COT5. Count on a treap

Count on a treap

131229:出好快一年半的题目了..一直忘记解除隐藏= =

In computer science, the treap is a binary search tree according to the keys and meanwhile a heap according to the weights.
You taks is to maintain a treap that support the following operations:
I k w: Insert a new node, which its key and weight are given by k, w.
D k: Delete a new node in the treap which its key is equal to k.
Q u v: Query the distance between u and v.
No two node will share a same key or same weight, and we guarantee the node is indeedly in the treap before we execute a delete operation.

In computer science, a treap is a binary search tree according to the keys and meanwhile a heap according to the weights.

Your task is to maintain a max-treap supporting the following operations:

  • 0 k w: Insert a new node, whose key and weight are k and w.
  • 1 k: Delete a node in the treap with key k.
  • 2 ku kv: Return the distance between node u whose key is ku and node v whose key is kv.

No two nodes share a same key or same weight, and we guarantee the node is indeed in the treap before a delete operation takes place.

 

Input

The first line contains an integer N(1 ≤ N  200000), the number of operations. The next N lines each contains two or there integers "0 k w" "1 k" or "2 ku kv"(0 < kwkukv  maxlongint).

 

Output

For each query operation, print the distance between u and v.

Example

Input:
12
0 4 17535
0 10 38964
0 2 21626
0 1 61321
2 1 10
2 10 4 
1 10
1 1
0 8 42634
2 8 4
2 8 2
2 4 2

Output: 1 2 2 1 1

</p>