In a magical forest, there are villages connected by roads, forming a tree. Each road has a positive integer representing its magical power.
A traveler can journey between any two distinct villages along their unique simple path. The power of a journey is defined as the greatest common divisor (GCD) of the powers of all roads along the path.
The forest guardian has chosen a special integer . A journey is considered enchanted if its power is not divisible by .
Your task is to count the number of enchanted journeys.
Journeys between the same two villages are counted only once, regardless of direction.
Input
The first line contains two integers and (, ).
Each of the next lines contains three integers , , and (, , ), describing a road between villages and with magical power .
It is guaranteed that the roads form a tree.
Output
Print a single integer: the number of enchanted journeys.
Example
stdin
5 6
1 2 6
2 3 10
2 4 12
4 5 3
stdout
7
Note
Here . The tree has the roads (power ), (power ), (power ) and (power ).
The enchanted journeys are:
- (path ): ;
- (path ): ;
- (path ): ;
- (path ): ;
- (path ): ;
- (path ): ;
- (path ): .
None of these powers is divisible by .
The remaining journeys are not enchanted, because their power is divisible by :
- : ;
- (path ): ;
- : .