atcoder#ABC247D. [ABC247D] Cylinder
[ABC247D] Cylinder
Score : points
Problem Statement
We have a horizontal cylinder. Given queries, process them in the given order. Each query is of one of the following two types.
1 x c
: Insert balls, with a number written on each of them, to the right end of the cylinder.2 c
: Take out the leftmost balls contained in the cylinder and print the sum of the numbers written on the balls that have been taken out.
We assume that the balls do never change their order in the cylinder.
Constraints
- Whenever a query of type
2 c
is given, there are or more balls in the cylinder. - All values in input are integers.
Input
Input is given from Standard Input in the following format:
The -th query is in one of the following two formats.
Output
Print the response to the queries of type 2 c
in the given order, with newlines in between.
4
1 2 3
2 2
1 3 4
2 3
4
8
- For the -st query, insert balls, with a number written on each of them, to the right end of the cylinder. The cylinder has now balls with numbers written on them, from left to right.
- For the -nd query, take out the leftmost balls contained in the cylinder. The numbers written on the balls taken out are , for a sum of , which should be printed. The cylinder has now a ball with a number written on it, from left to right.
- For the -rd query, insert balls, with a number written on each of them, to the right end of the cylinder. The cylinder has now balls with numbers written on them, from left to right.
- For the -th query, take out the leftmost balls contained in the cylinder. The numbers written on the balls taken out are , for a sum of , which should be printed. The cylinder has now balls with numbers written on them, from left to right.
2
1 1000000000 1000000000
2 1000000000
1000000000000000000
5
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
There may be nothing you should print.