Under construction

Still being built. Things may change

Time to Rest

Interview

Time limit2sMemory limit1024 MB

Summary
Given n penguin groups with start a_i, step b_i, and size c_i, find the total count of penguins whose path passes through point k.
Level

Easy2 of 10

Topics
Math, Implementation
Solved
No attempts yet

Problem

Stopping Doctor Octavius Sprut was not easy. But thanks to the courage, bravery and the doctor's super beam, the penguins finally managed it. Now they sit together with the North Wind and discuss the battle.

The skipper noticed that the monster penguins did not move at random but followed a certain algorithm: all penguins were split into nn groups, and the ii-th group had cic_i penguins. Imagine that all penguins move along a coordinate line. The ii-th group starts its attack at point aia_i and advances bib_i per step. So the path of the ii-th group is the sequence of points ai,ai+bi,ai+2bi,…,ai+jbi,…a_i, a_i+b_i, a_i+2b_i, \ldots, a_i+jb_i, \ldots. Every one of the cic_i penguins in the ii-th group passes through each point of this sequence. The sequence can be considered infinite.

Secret praised the skipper for this observation and proposed that everyone think about this problem: given a number kk, how many penguins passed through the point with coordinate kk during the whole attack?

The penguins and the North Wind have been thinking about it for a long time without success. Help them!

Input

The first line contains two integers nn, kk (1≤n≤100 0001 \le n \le 100\,000, 1≤k≤1091 \le k \le 10^9), the number of penguin groups and the coordinate of the point whose count is needed. Each of the next nn lines contains three integers ai,bi,cia_i, b_i, c_i (1≤ai,bi,ci≤1091 \le a_i, b_i, c_i \le 10^9): the starting position of the ii-th group, the length of one jump, and the number of penguins in the group.

Output

Print one line with the number of penguins that passed through the point with coordinate kk.

Hint

In the first test, the first group passes through the points {1, 2, 3, 4, \ldots} and the second group passes through {1, 3, 5, 7, \ldots}. The first group has 2 penguins and the second has 3, so 5 penguins pass through the point 3 in total. In the second test, both groups pass through the same points, so 2 penguins pass through the point 4 in total.

Examples2

  1. Example 1

    Input
    2 3
    1 1 2
    1 2 3
    
    Expected output
    5
    
  2. Example 2

    Input
    2 4
    1 1 2
    1 2 3
    
    Expected output
    2