#P15634. [2019 KAIST RUN Spring] Eat Economically

[2019 KAIST RUN Spring] Eat Economically

Problem Description

Ho has arrived in a secret place for her secret business trip. She knows her trip will take at most NN days or shorter but doesn't know the exact number of days she'll be there. So, the perfectionist\textbf{the perfectionist} Ho wants to make the daily meal lists for every possible trip length, 11 day to NN days.

There is the only food court that offers exactly 2N2N kinds of menus (by accident) in this secret place. The food court opens only lunch time and dinner time, and oddly, the prices of lunch and dinner for the same menu can be different.

She will eat exactly one menu per lunch and dinner respectively and never eat the same menu for the entire of the trip. She never minds about which kind of menu will be her meal, the only important thing is the entire price of meals must be minimized.

Under these conditions, she can make her meal lists but realizes that writing every N(N+1)N(N+1) menu is hard and tiresome. So, instead of making the meal lists, she calculates the minimized entire price for ii lunch menus and ii dinner menus where i=1i=1 to NN.

You, the big fan of Ho, has a supreme task. Print the NN prices she calculated.

Input Format

The first line contains an integer NN. (1N2500001 \leq N \leq 250 000)

In the next 2N2N lines, each line contains two integer l,dl, d denoting the prices of the menus when lunch and dinner respectively. (1l,d1091 \leq l, d \leq 10^9)

Output Format

Print NN lines. The ii-th line should contain an integer denoting the minimized entire price for ii lunch menus and ii dinner menus.

1
4 9
5 3
7
2
1 6
2 4
5 3
3 1
2
7
4
7 5
5 7
7 4
4 2
2 5
6 4
3 2
1 9
3
7
16
26