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

#CC0000075. Gói thuê dịch vụ theo ngày (Snuke Prime)

HỌC THEO LỘ TRÌNH

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

2 lộ trình

Gói thuê dịch vụ theo ngày (Snuke Prime)

Snuke Prime

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

There are NN services. Service ii is used from the beginning of day aia_i through the end of day bib_i, inclusive, and costs cic_i per day without a subscription. A subscription costing CC per day covers all services. Find the minimum total cost.

Input

The first line contains N,CN,C. Each of the next NN lines contains ai,bi,cia_i,b_i,c_i.

Output

Print the minimum total cost.

Subtasks

  • Subtask 1 (20 points): 1≤N≤201\le N\le 20; 1≤C≤1091\le C\le10^9; 1≤ai≤bi≤1091\le a_i\le b_i\le10^9; 1≤ci≤1091\le c_i\le10^9.
  • Subtask 2 (30 points): 1≤N≤20001\le N\le 2000; 1≤C≤1091\le C\le10^9; 1≤ai≤bi≤1091\le a_i\le b_i\le10^9; 1≤ci≤1091\le c_i\le10^9.
  • Subtask 3 (50 points): 1≤N≤2000001\le N\le 200000; 1≤C≤1091\le C\le10^9; 1≤ai≤bi≤1091\le a_i\le b_i\le10^9; 1≤ci≤1091\le c_i\le10^9.

Examples

Input

2 6
1 2 4
2 2 4

Output

10

Explanation

On day 11 only one service is active, costing 44. On day 22, the ordinary fees total 88, so the subscription for 66 is cheaper. The answer is 4+6=104+6=10.