QOJ.ac

QOJ

时间限制: 1 s 内存限制: 1024 MB 总分: 100 可 Hack ✓

#18113. The Reason Why Hobanwoo Was Late for School 3

统计

After many twists and turns, Hobanwoo has finally arrived in front of the starting village. However, the stairs leading to the village on the cliff have been destroyed by monsters, so he has decided to build stairs using logs.

He builds the stairs by placing logs vertically side by side. Occasionally, monsters use magic with power $m$, which targets the current longest log of length $k$ among all logs placed so far. Any log with a length of at least $\max(k-m, 0)$ has its length reduced to $\max(k-m, 0)$.

You are given $N$ queries:

1 a : Hobanwoo places a log of length $a$ next to the stairs. 2 m : Monsters use magic of power $m$ on the stairs.

The logs Hobanwoo adds are always longer than any log previously added by a type 1 query.

Calculate the sum of the lengths of all logs in the completed stairs after $N$ queries.

Input

The first line contains the number of queries $N$. Starting from the second line, $N$ lines follow, each containing two positive integers $x$ and $y$ separated by a space. If $x$ is 1, Hobanwoo has placed a log of length $y$ next to the stairs; the new log is always longer than any log previously added by a type 1 query. If $x$ is 2, the monsters have used magic of power $y$ on the stairs; this query can occur even if there are no logs on the stairs. ($1 \le N \le 500\,000$) ($1 \le x \le 2$) ($1 \le y \le 10^9$)

Output

Output the sum of the lengths of all logs in the completed stairs after $N$ queries.

Examples

Input 1

1
1 1000000000

Output 1

1000000000

Input 2

1
2 1000000000

Output 2

0

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.