{"trustable":true,"prependHtml":"\u003cstyle type\u003d\u0027text/css\u0027\u003e\n .input, .output {\n border: 1px solid #888888;\n }\n .output {\n margin-bottom: 1em;\n position: relative;\n top: -1px;\n }\n .output pre, .input pre {\n background-color: #EFEFEF;\n line-height: 1.25em;\n margin: 0;\n padding: 0.25em;\n }\n \u003c/style\u003e\n \u003clink rel\u003d\"stylesheet\" href\u003d\"//codeforces.org/s/96598/css/problem-statement.css\" type\u003d\"text/css\" /\u003e\n\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027$$$$$$\u0027, right: \u0027$$$$$$\u0027, display: true},\n {left: \u0027$$$\u0027, right: \u0027$$$\u0027, display: false},\n {left: \u0027$$\u0027, right: \u0027$$\u0027, display: true},\n {left: \u0027$\u0027, right: \u0027$\u0027, display: false}\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003eThe narrow bus is so narrow it doesn\u0027t have any seats and the passengers have to stand in a row. The bus has two doors that can be used for entering or leaving the bus: one in the front and one in the back. People can\u0027t easily swap in the bus because it is too narrow, so the order people are standing in does not change while the bus is running.\u003c/p\u003e\u003cp\u003eAt each bus stop, either a single person enters the bus or a single person leaves the bus. \u003c/p\u003e\u003cul\u003e \u003cli\u003e If a person wants to enter the bus, they will choose one of the doors to do that. Then this person joins the beginning or the end of the row, according to which door they used to enter. \u003c/li\u003e\u003cli\u003e If a person wants to leave at a stop, they will choose the direction with the least amount of people and proceed to that door (in case both directions have the same amount of people, the person chooses the front door). Everyone in that direction will have to get out then as well. No one likes standing outside and waiting so everybody who wants to continue riding the bus will use the other door to get back in. These passengers will enter the bus back in the same order they got out. \u003c/li\u003e\u003c/ul\u003e\u003cp\u003eGiven a description of people entering and leaving the bus, count how many people will have to get out when somebody leaves the bus. \u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003eThe first line of input contains a single integer \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003en\u003c/i\u003e\u003c/span\u003e, the number of actions at bus stops (\u003cspan class\u003d\"tex-span\"\u003e1 ≤ \u003ci\u003en\u003c/i\u003e ≤ 10\u003csup class\u003d\"upper-index\"\u003e5\u003c/sup\u003e\u003c/span\u003e). The next \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003en\u003c/i\u003e\u003c/span\u003e lines will contain one of the three types of actions each. The actions happen consecutively as they are given in the input.\u003c/p\u003e\u003cul\u003e \u003cli\u003e \"\u003cspan class\u003d\"tex-font-style-tt\"\u003eF\u003c/span\u003e\"\u0026nbsp;— a person enters the bus using the front door. \u003c/li\u003e\u003cli\u003e \"\u003cspan class\u003d\"tex-font-style-tt\"\u003eB\u003c/span\u003e\"\u0026nbsp;— a person enters the bus using the back door. \u003c/li\u003e\u003cli\u003e \"\u003cspan class\u003d\"tex-font-style-tt\"\u003eO\u003c/span\u003e \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003ei\u003c/i\u003e\u003c/span\u003e\"\u0026nbsp;— the \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003ei\u003c/i\u003e\u003c/span\u003e-th person that has entered the bus today leaves. \u003c/li\u003e\u003c/ul\u003e\u003cp\u003eEach action happens at a single bus stop. After the action is completed, the bus leaves for the next stop.\u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003ePrint a single integer for each type \"\u003cspan class\u003d\"tex-font-style-tt\"\u003eO\u003c/span\u003e\" query, the number of people who will have to get out and go back in the bus when a person leaves at the stop.\u003c/p\u003e"}},{"title":"Examples","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\u003e9\nF\nB\nB\nB\nB\nO 2\nF\nF\nO 4\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e1\n2\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Note","value":{"format":"HTML","content":"\u003cp\u003eIn the example, after everyone gets in the bus during the first 5 stops, the people are ordered 1, 2, 3, 4, 5.\u003c/p\u003e\u003cp\u003eAt the 6th stop, the 2nd person leaves through the front door and the 1st person is forced to get out of the bus. The 1st person then uses the back door to enter the bus again. The order changes to 3, 4, 5, 1.\u003c/p\u003e\u003cp\u003eDuring the next two stops two people use the front door to enter the bus, and the order becomes 7, 6, 3, 4, 5, 1.\u003c/p\u003e\u003cp\u003eAt the 9th stop, the 4th person leaves through the back door and now the 5th and the 1st person are forced to get out of the bus. They then use the front door to get back in the bus. The order changes to 5, 1, 7, 6, 3.\u003c/p\u003e"}}]}