Relay

아직 제출이 없습니다시간 제한1초메모리 제한1024 MB

문제

There are NN members in the track club of JOI High School, numbered from 11 to NN. For the member ii (1iN1 ≤ i ≤ N), the time of the 100 m sprint is A_iA\_i msec, and the ability of controlling the baton is B_iB\_i.

The track club will participate in a national contest for the 300 m relay. Three members will run in the 300 m relay. Each member will run for 100 m. A runner will pass the baton to the next runner. Precisely, if the first runner is the member ii (1iN1 ≤ i ≤ N), the second runner is the member jj (1jN1 ≤ j ≤ N), and the third runner is the member kk (1kN1 ≤ k ≤ N), then the three members will run the relay in the following steps.

  1. The member ii runs for 100 m with a baton. It takes A_iA\_i msec.
  2. The member ii gives a baton to the member jj. It takes max(B_i,B_j)\max{(B\_i , B\_j)} msec.
  3. The member jj runs for 100 m with a baton. It takes A_jA\_j msec.
  4. The member jj gives a baton to the member kk. It takes max(B_j,B_k)\max{(B\_j , B\_k)} msec.
  5. The member kk runs for 100 m with a baton. It takes A_kA\_k msec.

Therefore, the record for the 300 m relay is A_i+max(B_i,B_j)+A_j+max(B_j,B_k)+A_kA\_i + \max{(B\_i , B\_j)} + A\_j + \max{(B\_j , B\_k)} + A\_k msec. Here max(x,y)\max{(x, y)} is the largest value of xx and yy. Since you are the coach of the track club, you want to choose three distinct members for the relay and decide the order of the runners so that the record becomes minimum.

Write a program which, given information of the NN members of the track club, calculates the minimum possible record of the 300 m relay.

입력

Read the following data from the standard input. Given values are all integers.

NN

A_1A\_1 B_1B\_1

A_2A\_2 B_2B\_2

\vdots

A_NA\_N B_NB\_N

출력

Write one line to the standard output. The output should contain an integer which is the minimum possible record of the 300 m relay counted by msec.

제한

  • 3N200,0003 ≤ N ≤ 200\\,000.
  • 1A_i100,000,000(=108)1 ≤ A\_i ≤ 100\\,000\\,000 (= 10^8) (1iN1 ≤ i ≤ N).
  • 1B_i100,000,000(=108)1 ≤ B\_i ≤ 100\\,000\\,000 (= 10^8) (1iN1 ≤ i ≤ N).