A country has been divided into n states and each state has plenty of resources. All these states are connected with each other by using (n−1) pathways. You can travel to any state from another state by using these pathways. Your task is to extract resources from states.
You are given a list of m states and you have to start your journey from any one of these states. After starting your journey, you will start extracting the resources from the states one by one while visiting them using the pathways. You are also provided with an energy level k where k is your initial energy level. This energy level is decreased by one whenever you use a pathway. If your energy level becomes zero, then you cannot extract resources anymore.
You will be provided with all the information of the country, list of the m states and the initial energy level k. Determine the maximum sum of resources that you can extract from the states during your journey.
Note: You can not visit any state more than once during your journey. Besides, you can also select not to extract resources from any of the states. In that case, the total sum of resources will be zero.
Input format
Output format
For each of the test case, print a single integer that represents the maximum number of extracted resources.
Input Constraints
You can start from state 5 and then extract from states 5,4,2 and 3. This way you will collect 15 resources in total.