/* 
 * File:   main.c
 * Author: onlyi
 *
 * Created on January 24, 2019, 1:17 PM
 */

#include <stdio.h>
#include <stdlib.h>

typedef int bool;
#define true 1
#define false 0

/*
 * 
 */
int main(int argc, char** argv) {

    // TODO code application logic here              

    int ret = 0;
    int n,t,k;
    
    scanf("%d %d %d", &n, &t , &k);

    int a[n];
    int b[n];
    int c[n];
    
    for (int i = 0; i < n; i++)
    {       
        scanf("%d %d %d", &a[i], &b[i] , &c[i]);
    }

    int ck = k, p1, calcTrain = 0; // ck is number of train that used each hour, p1 is # number of passenger in train
    // calcTrain is variable to calculate that Train is needed
    bool needTrain = true; // Check whether next hour need train
    int numberOfTrain = 0; // The number of trains used 

    int i = 0;
    while (i <= t)
    {
        p1 = 0;
        calcTrain = 0;
        int p2[n]; //P2 is # passanger that will take the train            

        for (int j = 0; j < n; j++)
        {

            p2[j] = 0;

            if (needTrain)
            {
                if (p1 + a[j] <= ck)
                    p2[j] = a[j];
                else
                    p2[j] = ck - p1;

                p1 = p1 + p2[j];
            }

            a[j] = a[j] + b[j] - p2[j];
            if (a[j] + b[j] > c[j])
            {
                calcTrain++;
            }

            if (a[j] > c[j])
            {
                ret = -1;
                break;
            }
        }

        if (ret == -1)
        {
            for (int j = 0; j < n; j++)
            {
                a[j] = a[j] - b[j] + p2[j];
            }

            ck += k;
            ret = 0;

            continue;
        }

        i++;

        if (i <= t)
        {
            numberOfTrain = numberOfTrain + ck/k;
        }

        ck = k;
        if (calcTrain > 0)
            needTrain = true;
        else
        {
            needTrain = false;
            ck = 0;
        }


    }

    printf("%d", numberOfTrain);

    return (EXIT_SUCCESS);
}