You are given a tree with N nodes and N−1 edges and an integer K. Each node has a label denoted by an integer, Ai. Your task is to find the length of the longest path such that label of all the nodes in the path are divisible by K.
Length of a path is the number of edges in that path.
Input Format:
First line contains two space separated integers, N and K. Next line contains N space separated integers, ith integer denotes the label of ith node, Ai. Next N−1 lines contains two space separated integers each, U and V denoting that there is an edge between node U and node V.
Output Format:
Print a single integer denoting the length of the longest path such that label of all the nodes in the path are divisible by K.
Constraints:
1≤N≤105
1≤K≤105
1≤Ai≤105
1≤U,V≤N
Longest path will be 1->2->4.