#K34477. Counting Green Traffic Signals

    ID: 25318 Type: Default 1000ms 256MiB

Counting Green Traffic Signals

Counting Green Traffic Signals

You are given n traffic signals. Each signal is described by its coordinates xi and yi, its initial state si (0 for green, 1 for red), and a time interval t at which the signal toggles its state. The signal changes its state every t time units.

At a given time instant T, the number of times a signal has toggled its state is given by:

$$\text{state\_changes} = \left\lfloor \frac{T}{t} \right\rfloor$$

A signal that starts green (si = 0) will be green at time T if state_changes is even. Similarly, a signal that starts red (si = 1) will be green if state_changes is odd.

Your task is to read the input from standard input and output the number of signals that are green at time T.

inputFormat

The first line contains an integer n representing the number of traffic signals. Each of the next n lines contains four space-separated integers: xi, yi, si, and t, where si is the initial state (0 for green and 1 for red) and t is the time interval for toggling. The final line contains the integer T, the time instant at which you need to determine the number of green signals.

outputFormat

Output a single integer that represents the number of traffic signals that are green at time T.

## sample
5
0 0 0 10
1 1 1 5
2 2 0 6
3 3 1 3
4 4 0 8
15
3

</p>