5056: Task processing

内存限制:256 MB 时间限制:2 S
题面:传统 评测方式:文本比较 上传者:
提交:0 通过:0

题目描述

time limit per test
4 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

Vasya wants to create a computing system to process arbitrary tasks. As a part of the system he needs an algorithm which will choose an order of task execution.

He came up with the following algorithm:

  • There is a single execution queue. For task to be completed, it needs to be added to the queue.
  • For each task two values are known: li and ti − the number of seconds that it takes to complete the task and the moment of time when this task is added to the execution queue.
  • If at some moment of time T the algorithm has to select a task for execution, it picks the one with the minimum value of li-(T-ti)2. In case of a tie, algorithm picks a task with the lowest index. Then for the following li seconds the algorithm will wait for the task to be completed.

In order to test the algorithm Vasya wants you to simulate it.

You are given n tasks. For each task, you know the number of seconds li that it takes to complete the task and the moment of time ti when this task is added to the execution queue.

For each task find out the moment of time when it will be completed.

Input

The first line contains an integer number n (1≤n≤105)− the number of task to process. The next n lines contain two integers each: li,ti (1≤li≤105,0≤ti≤105).

Output

Print n space-separated integers. The i-th integer is the moment of time when the i-th task was completed.

Examples
Input
1
10 5
Output
15 
Input
3
3 0
4 3
5 2
Output
3 7 12 
Input
3
3 0
4 2
5 1
Output
3 12 8 
Input
6
3 0
5 1
4 2
5 18
4 19
5 14
Output
3 8 12 24 28 19