Monkey and Apple-trees
Everyone knows that the yummiest fruit in the world is an apple. Even the monkey Chris knows that. There are many apple-trees in the a forest located along the river and numerated consecutively starting from 1. Sometimes Chris comes to the forest, chooses a group of apple-trees growing consecutively (selected interval) and counts the amount of apple-trees with red-ripen apples among them. Sometimes apples on a few consecutive apple-trees have red-ripen before his next arrival.
You have to answer how many apple-trees in the selected interval have red-ripen apples at each Chris's arrival. At the beginning all the apples are unripen.
Input
In the first line an integer m (1 ≤ m ≤ 100000) - number of events. The following m lines contain description of events - each contains three integers d[i]
, x[i]
, y[i]
(1 ≤ d[i]
≤ 2, x[i]
≤ y[i]
). If the d[i]
= 1, then the event is Chris's arrival, if the d[i]
= 2 - red-ripening of all apples in the selected interval of the apple-trees. Other two numbers x[i]
and y[i]
, describe the interval for the event.
For calculating the limits of the interval there is an additional number c. At the beginning c = 0. An interval for the event is interval from x[i]
+ c to y[i]
+ c inclusively. It's guaranteed that 1 ≤ x[i]
+ c, y[i]
+ c ≤ 10^9
. If the event is apples red-ripening then c doesn't change. If the event is Chris's arrival, then as the result c becomes equal to the amount of red-ripen apple-trees he has counted.
Output
For each of Chris's arrival output one line with one number in it - the task answer.