{"trustable":true,"prependHtml":"\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv class\u003d\"panel_content\"\u003eThere\u0027s a queue obeying the first in first out rule. Each time you can either push a number into the queue (+i), or pop a number out from the queue (-i). After a series of operation, you get a sequence (e.g. +1 -1 +2 +4 -2 -4). We call this sequence a queue sequence.\u003cbr\u003e\u003cbr\u003eNow you are given a queue sequence and asked to perform several operations:\u003cbr\u003e\u003cbr\u003e1. insert p\u003cbr\u003eFirst you should find the smallest positive number (e.g. i) that does not appear in the current queue sequence, then you are asked to insert the +i at position p (position starts from 0). For -i, insert it into the right most position that result in a valid queue sequence (i.e. when encountered with element -x, the front of the queue should be exactly x).\u003cbr\u003eFor example, (+1 -1 +3 +4 -3 -4) would become (+1 +2 -1 +3 +4 -2 -3 -4) after operation \u0027insert 1\u0027.\u003cbr\u003e2. remove i\u003cbr\u003eRemove +i and -i from the sequence.\u003cbr\u003eFor example, (+1 +2 -1 +3 +4 -2 -3 -4) would become (+1 +2 -1 +4 -2 -4) after operation \u0027remove 3\u0027.\u003cbr\u003e3. query i\u003cbr\u003eOutput the sum of elements between +i and -i. For example, the result of query 1, query 2, query 4 in sequence (+1 +2 -1 +4 -2 -4) is 2, 3(obtained by -1 + 4), -2 correspond.\u003cbr\u003e\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"There are less than 25 test cases. Each case begins with a number indicating the number of operations n (1 ≤ n ≤ 100000). The following n lines with be \u0027insert p\u0027, \u0027remove i\u0027 or \u0027query i\u0027(0 ≤ p ≤ length (current sequence), 1 ≤ i, i is granted to be in the sequence).\u003cbr\u003eIn each case, the sequence is empty initially.\u003cbr\u003eThe input is terminated by EOF.\u003cbr\u003e"}},{"title":"Output","value":{"format":"HTML","content":"Before each case, print a line \"Case #d:\" indicating the id of the test case.\u003cbr\u003eAfter each operation, output the sum of elements between +i and -i.\u003cbr\u003e"}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e10\r\ninsert 0\r\ninsert 1\r\nquery 1\r\nquery 2\r\ninsert 2\r\nquery 2\r\nremove 1\r\nremove 2\r\ninsert 2\r\nquery 3\r\n6\r\ninsert 0\r\ninsert 0\r\nremove 2\r\nquery 1\r\ninsert 1\r\nquery 2\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eCase #1:\r\n2\r\n-1\r\n2\r\n0\r\nCase #2:\r\n0\r\n-1\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}