/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/* 
 * 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

static int parseint(void) {
    int c, n;

    n = getchar() - '0';
    while ((c = getchar()) >= '0')
        n = 10 * n + c - '0';

    return n;
}

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

    // TODO code application logic here              

    unsigned int i = 0;
    unsigned int n, t, k;

    n = parseint();
    t = parseint();
    k = parseint();

    unsigned int a[n];
    unsigned int b[n];
    unsigned int c[n];

    for (i = 0; i < n; i++)
    {
        a[i] = parseint();
        b[i] = parseint();
        c[i] = parseint();
    }

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

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

        unsigned int j = 0;
        while (j < n)
        {

            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])
            {
                unsigned int x = a[j] - c[j];

                if ((x % k) == 0)
                    x = x / k;
                else
                    x = x / k + 1;

                ck += k*x;
                p1 = 0;
                calcTrain = 0;                

                for (x = 0; x <= j; x++)
                {
                    a[x] = a[x] - b[x] + p2[x];
                }

                j = 0;
                continue;
            }

            j++;
        }

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

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

        i++;
    }

    printf("%u\n", numberOfTrain);
    return (EXIT_SUCCESS);
}
