1.Numbers Group
You are given N integers ai where 1≤i≤N. Let the number of repetitions of each integer in the array be ri.
Print M distinct numbers such that the number with maximum ri among the other
numbers comes first, then the number with the next maximum ri and so on. If there
are two numbers with the same repetition count then print the number of larger value first. Note: Please read the sample explanation carefully.
Input format
• First line contains an integer N.
• In the second line: N numbers ai follow.
Output format
Print M numbers in the order illustrated in the question.
Constraints
1≤N≤1000
1≤ai≤1000
Sample Input
5
12216
Sample Output
216
Explanation
In the given sample there are 3 distinct numbers 1 , 2 and 6 with ri values as 2 , 2 and 1. So as per the order asked 2 comes before 1 as it has same ri value but its larger than 1. 1 comes before 6 as its ri value is greater than 6.
2.Denominations
You are given an integer N. You have infinite number of 3, 5 and 10 denomination coins. You have to find the number of ways you can form a sum of N by using the coin denominations.
Input:
The first line contains an Integer T, the number of test cases. Next T lines contain a single integer N.
Output:
For each test case, print the number of ways you can form a sum of N by using the coin denominations.
Constraints:
1≤T≤10^3
0≤N≤10^6
Sample Input
2
20
13
Sample Output
4
2
Explanation
Case 1:
N=20. There are 4 ways to make a sum of 20 using 3, 5 and 10 denomination coins. They are (10, 10), (5, 5, 10), (5, 5, 5, 5), (3, 3, 3, 3, 3, 5)
Case 2:
N=13. There are 2 ways to make a sum of 20 using 3, 5 and 10 denomination coins. They are (3, 5, 5), (3, 10)
3.Special Nodes Tree
You are given a tree of N nodes rooted at 1. Each node of the tree has a color associated with it. Now you are given Q queries. In each query, you are given a node number X and for each query you have to mark the node X as special and all the other nodes in its subtree with the same color also as special. If a node is marked as special in a query then for all the other subsequent queries, it remains marked as special.
For each query, you need to print the total number of special nodes in the tree after you perform the marking operation in the query.
Input
The first line contains an integer N as input denoting the total number of nodes in the tree. Next, N−1 lines contain two integers U and V which denotes there is an edge between the nodes U and V in the tree.
Next line contains N space separated integers that denotes the color of each node of the tree.
Next line contains an integer Q as input that denotes the count of queries.
Next Q lines contain an integer X that denotes the node whose subtree needs to be marked as special for that query.
Output
For each query, you need to print the count of nodes that are special after this query is performed.
Constraints
1≤N,Q≤10^5
1≤X≤10^5
Sample Input
5
3 1
3 2
2 4
2 5
1 1 2 2 1
4
2
4
5
1
Sample Output
2
3
3
4
Explanation
In the first query node 2 is marked as special.Now node 5 has same color and it is inside the subtree rooted at 2 so it also gets marked as special. The answer for this query is 2.
In second query node 4 is marked as special. There is no other node that can be marked as special in this query.So we have 3 nodes as special till now in our tree, thus the output is 3.
In third query node 5 is chosen.It is already special so answer is not increased.
In last query node numbered 1 is chosen. Now we have total 4 nodes that are special.