#P2352. Maximize Total Remuneration

    ID: 15625 Type: Default 1000ms 256MiB

Maximize Total Remuneration

Maximize Total Remuneration

Duye is about to publish a new book chronicling his illustrious career in problem abuse. There are \(n\) publishers interested in releasing the book, and each publisher \(i\) is willing to pay a remuneration value \(p\) as long as \(p\) lies in the interval \([L_i, R_i]\) (i.e. \(L_i \le p \le R_i\)). For each publisher that accepts the chosen value \(p\), Duye receives \(p\) as payment. Find a value \(p\) (which must satisfy at least one publisher's interval) that maximizes the total remuneration received, which is calculated as \(p \times (\text{number of publishers such that } L_i \le p \le R_i)\).

inputFormat

The first line contains a single integer \(n\) \((1 \le n \le 10^5)\), the number of publishers. Each of the next \(n\) lines contains two integers \(L_i\) and \(R_i\) \((1 \le L_i \le R_i \le 10^9)\) representing the minimum and maximum payment that the \(i\)th publisher is willing to pay.

outputFormat

Output a single integer representing the maximum total remuneration Duye can receive.

sample

3
2 5
1 4
3 6
12