Under construction

Still being built. Things may change

Superstition

Time limit2sMemory limit512 MB

Summary
Count walks in a weighted undirected graph whose total travel time is a multiple of D and at most K, modulo 1,000,000,007.
Level

Hard8 of 10

Topics
Graph, Matrix, Dynamic programming
Solved
No attempts yet

Problem

Today is the long-awaited day for all school students: the first holiday of the new school year. Our heroine Deni is now in grade 10. She prepared for today. She found that there are N stores downtown, and she plans to visit some of them with her friends.

Deni and her friends do not like some of the connections between the stores, so they will not use them. They made a list of M pairs of stores. A pair (x, y) is on the list when they like the connection between stores x and y. That connection works in both directions, and each pair has a travel time that is the same in both directions. No pair connects a store to itself, and no pair appears twice.

Input

The first line of standard input contains four integers N, M, D and K. Each of the next M lines contains three integers xix_i, yiy_i and tit_i, describing a bidirectional connection between stores xix_i and yiy_i with travel time tit_i (1≤i≤M1 \le i \le M).

Output

Print the number of valid routes. Because this number can be large, print its remainder when divided by 1,000,000,007.

A route is valid if it uses connections from the list, its total travel time is divisible by D, and its total travel time is at most K. A store may be visited more than once. Two routes are different if their sequences of visited stores differ.

Constraints

  • 2≤N≤802 \le N \le 80
  • 2≤M≤31602 \le M \le 3160
  • 2≤D≤K≤1092 \le D \le K \le 10^9
  • 1≤ti≤101 \le t_i \le 10

Examples4

  1. Example 1

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

    Input
    5 7 5 10
    1 3 8
    2 5 7
    3 4 3
    1 4 2
    2 3 1
    1 5 4
    4 5 4
    
    Expected output
    58
    
  3. Example 3

    Input
    5 9 2 20
    1 2 1
    2 3 2
    3 1 1
    3 4 1
    4 5 2
    5 3 1
    1 5 1
    2 4 1
    2 5 1
    
    Expected output
    989802661
    
  4. Example 4

    Input
    5 7 5000000 5000000
    1 3 8
    2 5 7
    3 4 3
    1 4 2
    2 3 1
    1 5 4
    4 5 4
    
    Expected output
    598634781