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

#GD0000036. Hoán đổi dung lượng (Swap Space)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Hoán đổi dung lượng (Swap Space)

Swap Space

Source: Kattis

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn disk conversion jobs. Job ii requires at least aia_i free space before it starts and afterwards changes free space to free−ai+bifree-a_i+b_i. Jobs may be ordered arbitrarily. Find the minimum initial free space needed to execute all jobs.

Input

The first line contains nn. Each of the next nn lines contains ai,bia_i,b_i.

Output

Print the minimum initial free space required.

Constraints

  • 1≤n≤2⋅1051\le n\le 2\cdot10^5.
  • 0≤ai,bi≤1090\le a_i,b_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
10 20
30 10
15 15

Output

20

Explanation

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