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

#GD0000026. Chiến dịch biệt kích (Commando War)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Chiến dịch biệt kích (Commando War)

Commando War

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn teams. Team ii needs bib_i minutes of briefing, then independently executes its mission for jij_i minutes. Only one team can be briefed at a time, while missions run in parallel. Minimize the time when all teams are finished.

Input

The first line contains nn. Each of the next nn lines contains bi,jib_i,j_i.

Output

Print the minimum time until all teams finish.

Constraints

  • 1≤n≤1051\le n\le 10^5.
  • 1≤bi,ji≤1091\le b_i,j_i\le 10^9 for 1≤i≤n1\le i\le n.

Subtasks

  • Subtask 1 (20 points): n≤8n\le 8.
  • Subtask 2 (30 points): n≤30n\le 30.
  • Subtask 3 (50 points): Full constraints.

Examples

Input

3
2 5
3 2
1 4

Output

8

Explanation

The sample follows the ordering rule described in the Vietnamese explanation and produces the shown optimum.