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

#GD0000135. Giao thư trên trục số (Postal Delivery)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Giao thư trên trục số (Postal Delivery)

Postal Delivery

Source: Kattis

Version: Phuoc Hung OJ Extended

Problem Statement

A post office is at coordinate 00. Address ii lies at nonzero coordinate xix_i and needs tit_i letters. The truck carries at most KK letters per trip, must start each trip at 00 and return to 00, and may visit multiple addresses along a trip. Find the minimum total travel distance.

Input

The first line has n,Kn,K. The next nn lines contain xi,tix_i,t_i in strictly increasing order.

Output

Print the minimum total round-trip travel distance.

Subtasks

  • Subtask 1 (20 points): 3≤n≤203\le n\le 20; 1≤K≤100001\le K\le10000; −1500≤x1<⋯<xn≤1500-1500\le x_1<\cdots<x_n\le1500; xi≠0x_i\ne0; 1≤ti≤8001\le t_i\le800.
  • Subtask 2 (30 points): 3≤n≤2003\le n\le 200; 1≤K≤100001\le K\le10000; −1500≤x1<⋯<xn≤1500-1500\le x_1<\cdots<x_n\le1500; xi≠0x_i\ne0; 1≤ti≤8001\le t_i\le800.
  • Subtask 3 (50 points): 3≤n≤10003\le n\le 1000; 1≤K≤100001\le K\le10000; −1500≤x1<⋯<xn≤1500-1500\le x_1<\cdots<x_n\le1500; xi≠0x_i\ne0; 1≤ti≤8001\le t_i\le800.

Examples

Input

3 100
-10 50
10 175
25 20

Output

90

Explanation

One round trip to −10-10 costs 2020. On the positive side, a trip to 1010 delivers 100100 letters (2020 distance); another goes to 2525, delivers 2020 there and the remaining 7575 at 1010 (5050 distance). Total 9090.