PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#CC0000035. Tổng các phần tử ở vị trí 3, 8, 13, ... (Sum of Medians)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

2 lộ trình

Tổng các phần tử ở vị trí 3, 8, 13, ... (Sum of Medians)

Sum of Medians

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Maintain a set of distinct positive integers. If the current sorted set is a1<a2<⋯<aka_1<a_2<\cdots<a_k, a sum query asks for a3+a8+a13+⋯a_3+a_8+a_{13}+\cdots, summing all positions ii such that i mod 5=3i\bmod5=3. Operation add x inserts a value not currently present. Operation del x removes a value that is present. An empty set has sum 00.

Input

The first line contains QQ. Each subsequent line is add x, del x, or sum.

Output

For each sum operation, print the requested sum.

Subtasks

  • Subtask 1 (20 points): 1≤Q≤201\le Q\le 20; 1≤x≤1091\le x\le10^9; each add inserts an absent value, and each del removes a present value.
  • Subtask 2 (30 points): 1≤Q≤7501\le Q\le 750; 1≤x≤1091\le x\le10^9; each add inserts an absent value, and each del removes a present value.
  • Subtask 3 (50 points): 1≤Q≤1000001\le Q\le 100000; 1≤x≤1091\le x\le10^9; each add inserts an absent value, and each del removes a present value.

Examples

Input

6
add 4
add 5
add 1
add 2
add 3
sum

Output

3

Explanation

The sorted set is [1,2,3,4,5], so only the third element is included.