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

#GD0000124. Điểm số trong giải bóng đá (Football)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Điểm số trong giải bóng đá (Football)

Football

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

A football team played nn games. In game ii it scored gig_i goals and conceded hih_i. A win earns 33 points, a draw 11, and a loss 00. You may add at most GG goals to the team’s scores across all games. Maximize total points.

Input

The first line has n,Gn,G. The following nn lines each contain gi,hig_i,h_i.

Output

Print the maximum total points.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le 20; 0≤G≤1060\le G\le10^6; 0≤gi,hi≤1000\le g_i,h_i\le100.
  • Subtask 2 (30 points): 1≤n≤12001\le n\le 1200; 0≤G≤1060\le G\le10^6; 0≤gi,hi≤1000\le g_i,h_i\le100.
  • Subtask 3 (50 points): 1≤n≤1000001\le n\le 100000; 0≤G≤1060\le G\le10^6; 0≤gi,hi≤1000\le g_i,h_i\le100.

Examples

Input

3 2
1 1
0 1
2 0

Output

7

Explanation

Initial score is 1+0+3=41+0+3=4. Spend one extra goal to turn the draw into a win (+2), and one to turn the loss into a draw (+1), yielding 77.