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

#BS0000371. Lịch hạ cánh an toàn (A Careful Approach)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Lịch hạ cánh an toàn (A Careful Approach)

A Careful Approach

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

At an airport, nn airplanes are awaiting landing. Airplane ii may land only within the closed interval from aia_i to bib_i minutes. The controller may choose the order and landing time of every airplane.

Let t1≤t2≤⋯≤tnt_1\le t_2\le\cdots\le t_n be the landing times in chronological order. The safety of a schedule is measured by the smallest time difference between consecutive landings:

min⁡1≤j<n(tj+1−tj).\min_{1\le j<n}(t_{j+1}-t_j).

Schedule all airplanes within their respective windows to maximize this value. Landing times may be real numbers.

Input

  • The first line contains an integer nn, the number of airplanes.
  • Line ii of the following nn lines contains integers ai,bia_i,b_i, the beginning and end of airplane ii's landing window in minutes.

Output

Print the optimal gap rounded to the nearest second (round exact half seconds up), in the format m:ss. Here m is the integer number of minutes without leading zeroes and ss is the remaining seconds, always written with two digits.

Subtasks

  • Subtask 1 (20 points): 2≤n≤22\le n\le2; 0≤ai≤bi≤14400\le a_i\le b_i\le1440 for every 1≤i≤n1\le i\le n.
  • Subtask 2 (30 points): 2≤n≤62\le n\le6; 0≤ai≤bi≤14400\le a_i\le b_i\le1440 for every 1≤i≤n1\le i\le n.
  • Subtask 3 (50 points): 2≤n≤82\le n\le8; 0≤ai≤bi≤14400\le a_i\le b_i\le1440 for every 1≤i≤n1\le i\le n.

Examples

Input

3
0 10
5 15
10 15

Output

7:30

Explanation

Land the airplanes at 0, 7.5 and 15 minutes respectively. Both gaps are 7.5 minutes. All times lie in [0,15], so the two gaps sum to at most 15 minutes. Neither schedule can have both gaps greater than 7.5 minutes.

Input

2
0 10
10 20

Output

20:00

Explanation

Land the first airplane at minute 0 and the second at minute 20. The gap equals the entire available span of 20 minutes.

Input

8
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1

Output

0:09

Explanation

Eight airplanes create seven gaps over at most 60 seconds, so the smallest gap is at most 60/760/7 seconds. Equal spacing from 0 to 60 seconds achieves the bound. Rounding approximately 8.5714 seconds gives 9 seconds.