This problem is about Binary Search Trees (BST), a basic data structure. The structure is a rooted binary tree which stores values in its nodes. If node x contains value a, all values in the left subtree of x are less than a, and all values in the right subtree of x are greater than a.
In order to unify the details, we provide an implementation of finding a value a in a BST rooted at node x:

Here, l\[x] is the left child of x, r\[x] is the right child of x, and w\[x] is the value of x. Specifically, if x does not have a left child (right child), l\[x] (r\[x]) is 0.
We define A(root,a) as the array of all nodes visited by find(root,a). We also define the cost of find(root,a) as ∑_v∈A(root,a)w\[v].
Now there are n empty BSTs and m operations. Your task is to process these operations quickly. There are two different kinds of operations:
1 l r w". For each i∈\[l,r], insert an integer w into the i-th BST. It is guaranteed that w is not present in these BSTs. Insertion starts at the root, goes the same as find, but instead of making the last find(0,w) call, creates a new node with value w there and returns.2 x a". Calculate the cost of finding a in the x-th BST.The first line contains two integers, n and m (1≤n,m≤2⋅105), indicating the number of BSTs and the number of operations.
Then m lines follow. Each line contains description of an operation and is formatted as either "1 l r w" (1≤l≤r≤n; 1≤w≤109) or "2 x a" (1≤x≤n; 1≤a≤109).
It is guaranteed that all inserted numbers (w in operations of the first kind) are different from each other.
For each operation of the second kind, output a single line with a single integer: the cost.