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

#CC0000079. Những hình vuông rơi xuống (Falling Squares)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Những hình vuông rơi xuống (Falling Squares)

Falling Squares

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

Squares fall one at a time, with left coordinate lil_i and side length sis_i. Each square lands on the ground or the top of an earlier square. Merely touching at a vertical side does not support another square. After each drop, output the greatest height reached so far.

Input

The first line contains nn, followed by nn lines li,sil_i,s_i. This is the stdin/stdout adaptation of LeetCode.

Output

Print nn lines, each giving the maximum height after that drop.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le 20; 1≤li≤1081\le l_i\le10^8; 1≤si≤1061\le s_i\le10^6.
  • Subtask 2 (30 points): 1≤n≤2001\le n\le 200; 1≤li≤1081\le l_i\le10^8; 1≤si≤1061\le s_i\le10^6.
  • Subtask 3 (50 points): 1≤n≤10001\le n\le 1000; 1≤li≤1081\le l_i\le10^8; 1≤si≤1061\le s_i\le10^6.

Examples

Input

3
1 2
2 3
6 1

Output

2
5
5

Explanation

The first square covers [1,3)[1,3) and reaches height 22. The second covers [2,5)[2,5), overlaps the first and reaches height 55. The third is separate, so the maximum remains 55.