This page is still under construction.

Parts of this page are still being built. What you see may change.

Insects

Time limit1sMemory limit128 MB

Summary
Each insect dies to one attractor, feed, and poison triple; choose ingredients to maximize p times insects killed minus the ingredient costs.
Level

Medium6 of 10

Topics
Graph, Bit manipulation
Solved
No attempts yet

Problem

Sophie works at a company that produces insect baits. Each bait has three ingredients: an attractor, a feed, and a poison. For each of the nn insect types, there is exactly one triplet of ingredients that eliminates it. The ingredients are numbered.

Sophie is designing a new insect bait. The bait does not need to kill all the insects. Its goal is to maximize the company's profit.

The production cost is the sum of the unit costs of the distinct attractors, feeds, and poisons the bait contains. All attractors share one unit cost, and the same holds for feeds and poisons.

The price is the number of insect types the bait can kill, multiplied by pp, the bang-per-bug factor. The profit per unit of bait is its price minus its production cost.

Help Sophie design the most profitable bait. Write a program that reads the insect count, the bang-per-bug factor, and the unit costs, then determines the maximum possible profit per unit of bait.

Input

The first line contains the integers nn, pp, cac_a, ckc_k, and ctc_t (1≤n,p,ca,ck,ct≤10001 \le n, p, c_a, c_k, c_t \le 1000), separated by single spaces. They are the number of insect types, the bang-per-bug factor, and the unit costs of attractors, feeds, and poisons, respectively.

Each of the next nn lines contains three integers aia_i, kik_i, and tit_i (0≤ai,ki,ti<2560 \le a_i, k_i, t_i < 256), separated by single spaces. The ii-th insect can be eliminated by combining attractor aia_i, feed kik_i, and poison tit_i. All triplets (ai,ki,ti)(a_i, k_i, t_i) are pairwise different.

Output

Print a single integer: the maximum possible profit per unit of bait.

Hint

The bait uses attractors 127 and 255 (cost 2⋅3=62 \cdot 3 = 6), feed 127 (cost 1⋅10=101 \cdot 10 = 10), and poisons 0 and 127 (cost 2⋅1=22 \cdot 1 = 2), for a total production cost of 18. It kills insect types 1, 3, and 4, so its price is 30. The profit per unit is therefore 12.

Examples1

  1. Example 1

    Input
    5 10 3 10 1
    127 127 127
    0 0 127
    255 127 0
    127 127 0
    64 64 64
    
    Expected output
    12