atcoder#ABC247D. [ABC247D] Cylinder

[ABC247D] Cylinder

Score : 400400 points

Problem Statement

We have a horizontal cylinder. Given QQ queries, process them in the given order. Each query is of one of the following two types.

  • 1 x c: Insert cc balls, with a number xx written on each of them, to the right end of the cylinder.
  • 2 c: Take out the cc 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

  • 1Q2×1051 \leq Q \leq 2\times 10^5
  • 0x1090 \leq x \leq 10^9
  • 1c1091 \leq c \leq 10^9
  • Whenever a query of type 2 c is given, there are cc or more balls in the cylinder.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

QQ

query1{\rm query}_1

\vdots

queryQ{\rm query}_Q

The ii-th query queryi{\rm query}_i is in one of the following two formats.

11 xx cc

22 cc

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 11-st query, insert 33 balls, with a number 22 written on each of them, to the right end of the cylinder. The cylinder has now balls with numbers (2,2,2)(2,2,2) written on them, from left to right.
  • For the 22-nd query, take out the 22 leftmost balls contained in the cylinder. The numbers written on the balls taken out are 2,22,2, for a sum of 44, which should be printed. The cylinder has now a ball with a number (2)(2) written on it, from left to right.
  • For the 33-rd query, insert 44 balls, with a number 33 written on each of them, to the right end of the cylinder. The cylinder has now balls with numbers (2,3,3,3,3)(2,3,3,3,3) written on them, from left to right.
  • For the 44-th query, take out the 33 leftmost balls contained in the cylinder. The numbers written on the balls taken out are 2,3,32,3,3, for a sum of 88, which should be printed. The cylinder has now balls with numbers (3,3)(3,3) 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.