#include <bits/stdc++.h>

int main() {
    freopen("jumps.in", "r", stdin);
    freopen("jumps.out", "w", stdout);
    int n, k;
    std::cin >> n >> k;
    long long answer = 0;
    for (int i = 0; i < n; i++) {
        int a, b, c;
        std::cin >> a >> b >> c;
        if (k < a)
            continue;
        answer += c * ((k - a) % b == 0);
    }
    std::cout << answer << '\n';
    return 0;
}