MIPT: Connecting People

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

문제

Moscow IPT campus is under renovation. New student accomodations are located in the freshly built skyscraper housing estate. There are nn skyscrapers in a row, the ii-th from the start of the row having h_ih\_i floors. Skyscraper foundations are perfectly level with each other, and all floors have exact same height, thus same floors (counting from the bottom) in any pair of skyscrapers are on the same vertical level.

Each floor of each skyscraper is occupied by exactly one resident (how fancy is that!). Residents can move up and down inside each skyscraper via elevators. Moving one floor in any direction within the skyscraper ii takes tv_itv\_i seconds.

Really, the only downside of the project is the lack of budget for guarding the entrances to the skyscrapers, thus, for the safety purposes, at the moment entering or leaving the complex is not possible at all. To make up for this, it was decided to build extra corridors connecting skyscrapers in the complex. Each corridor must be perfectly horizontal, thus it must connect floors with same numbers in respective skyscrapers. Further, the corridor can not overlap with any skyscraper standing in between its endpoints. Formally, if floors xx are connected with a corridor in skyscrapers ii and jj, then h_k<xh\_k < x must be satisfied for all kk such that i<k<ji < k < j (and also, naturally, h_i,h_jxh\_i, h\_j \geq x must hold).

Corridors are state-of-the-art, thus travelling through any corridor takes thth seconds, regardless of the distance travelled. However, they are also expensive, thus only n1n-1 of them can be built.

To make residents happier (and also complain less about being imprisoned), the following conditions must be satisfied:

  • It has to be possible to get from any floor of any skyscraper to any other floor of any other skyscraper via elevators and corridors.
  • If we arbtrarily number all residents from 11 to R=_i=1nh_iR = \sum\_{i = 1}^n h\_i, and define d(x,y)d(x, y) as the smallest time (in seconds) the resident xx needs to get to the accomodation of the resident yy via elevators and corridors, then _1x<yRd(x,y)\sum\_{1 \leq x < y \leq R} d(x, y) must the as small as possible. 

Help the MIPT planning board to complete this astounding project.

입력

The first line contains two integers nn and thth --- the number of skyscrapers and the time (in seconds) needed to travel any horizontal corridor respectively (1n601 \leq n \leq 60, 1th1061 \leq th \leq 10^6).

The following nn lines describe the skyscrapers. The ii-th of these lines contains two integers h_i,tv_ih\_i, tv\_i --- the number of floors (as well as residents), and the time (in seconds) needed to travel one floor vertically within the skyscraper ii respectively (1h_i30001 \leq h\_i \leq 3000, 1tv_i1061 \leq tv\_i \leq 10^6).

It is guaranteed that R=_i=1nh_i3000R = \sum\_{i = 1}^n h\_i \leq 3000.

출력

Print a single integer --- the smallest value of _1x<yRd(x,y)\sum\_{1 \leq x < y \leq R} d(x, y) over all valid ways to construct n1n-1 corridors, as defined above.

힌트

In the first sample, there are no corridors, thus the answer is simply the sum of vertical distances.

Optimal configurations for the other sample tests are pictured below:

      #           #        
      #           #        
      #-------#   #       #
      #   #   #   #   #   #
      #   #   #   #   #   #
      #   #---#   #   #   #
      #   #   #   #---#---#
# #   #   # #-#   #   #-# #
#-#   #   # # #   #   # # #
# #   #-# # # #   # #-# # #