Lately Teodoro has been working a lot, solving tons of problems. Now he thinks that he needs some well deserved rest and decided to go to a bath house to take a nice relaxing bath.
Teodoro is very demanding and wants the temperature of the water to be exactly X degrees celsius. The bath house has N taps of water, each with a specific water temperature of ai degrees celsius. He can open multiple taps to get the exact temperature that he wants by controlling the proportion of water coming out of each tap.
For example, imagine Teodoro opened two taps: the first tap has water at 50 degrees celsius and the second tap has water at 75 degrees celsius. He opened the taps so that there is four times more water coming out of the first tap than the second tap. The resulting temperature r can be calculated as:

Notice that the resulting temperature will always be a weighted mean of the water temperatures of the open taps.
The amount of money that Teodoro will pay at the bath house depends on how many different taps he opens and Teodoro doesn't have much money to spend, so he wants to know what is the minimum number of taps that he has to open to get the desired temperature.
The first line of the input contains two integers N (1 ≤ N ≤ 105) and X (0 ≤ X ≤ 100), indicating respectively the number of taps and the desired temperature.
The following line contains N integers ai (0 ≤ ai ≤ 100). The i-th integer indicates the temperature of the water that comes out of the i-th tap.
Output the minimum number of taps that Teodoro needs to open to get his desired temperature. Output - 1 if it is not possible to get the desired temperature in any way.
4 50
25 50 75 100
1
2 50
0 100
2
Nicoleta is a very rich and lazy man. He lives in a huge mansion with his sister Marge. Their mansion is perfectly rectangular and has no inner walls. They made it that way so Nicoleta wouldn't need to open doors and avoid walls.
Last night, he invited some friends to play games at his mansion and they made a big mess. Marge is furious about it and demanded that he cleans everything up today.
There are N dirty spots on the mansion's floor and Nicoleta tried to cover them with M expensive rectangular rugs. Each dirty spot on the floor is represented by a point and each rug is represented by a rectangle.
Marge is used to having all rugs parallel to the walls. Nicoleta made sure that no rug is rotated so that she doesn't notice. However, he might have left some rugs overlapping because he is lazy.
He asked you to double check his "cleaning" by counting how many rugs are covering each spot. A rug is covering a spot if the spot is strictly inside the rug's rectangle.
The first line of the input contains two integers N and M (1 ≤ N, M ≤ 105), indicating respectively the number of dirty spots and the number of rectangular rugs.
Each of the following N lines contains two integers: the i-th line contains xis and yis ( - 109 ≤ xi, yi ≤ 109), indicating the coordinates of the i-th dirty spot.
Each of the following M lines contains four integers: the i-th line contains xibl, yibl, xitr and yitr ( - 109 ≤ xibl < xitr ≤ 109 and - 109 ≤ yibl < yitr ≤ 109), indicating respectively the coordinates of the i-th rug bottom left corner and the coordinates of the i-th rug top right corner.
Output N lines each with a single integer: the i-th integer indicating the number of rugs covering the i-th dirty spot.
2 3
0 0
10 10
-10 -10 10 15
5 5 20 20
9 9 11 11
1
2
2 2
0 0
10 10
-1 -100 1 100
-100 -1 100 1
2
0
Marge is the newest member of GEMA, a programming competition study group at her university. One of the first things she did as a new member was to look at the last year's regionals scoreboard to see how well the team representing her university performed. Looking at it, she noticed that she had no idea how the teams were ranked in the scoreboard. After searching on the internet she found the following text in the rules section of the ACM-ICPC website, describing how teams are ranked in the scoreboard:
"Teams are ranked according to the most problems solved, ... teams who solve the same number of problems are ranked by least total time. The total time is the sum of the time consumed for each problem solved. The time consumed for a solved problem is the time elapsed from the beginning of the contest to the submittal of the accepted run plus 20 penalty minutes for every rejected run for that problem regardless of submittal time. There is no time consumed for a problem that is not solved."
Marge already knows that ACM-ICPC contests have a duration of 300 minutes and, if at any moment there are multiple teams tied for the first position (same number of problems solved and same total time), she considers that all those teams are leading the scoreboard at the same time.
She found the list of submissions of the contest and now she is interested in finding out the total amount of time in minutes that her university's team was leading the scoreboard.
The first line of the input contains three integers N (2 ≤ N ≤ 200), M (1 ≤ M ≤ 104) and P (8 ≤ P ≤ 14), indicating respectively the number of teams in the competition, the total number of submissions and the total number of problems in the contest.
The next N lines contain each a single word, consisting of 1 to 10 uppercase Latin letters, indicating the name of each team. The first team listed corresponds to Marge's university's team.
The next M lines contain each the information about a submission: the name of the team that made the submission, an uppercase letter indicating the problem associated with the submission (one of the first P letters of the alphabet), an integer t (1 ≤ t ≤ 300) indicating the time in minutes at which the submission was made, and a string containing either "OK" (accepted run) or "NO" (rejected run) indicating the result of the submission. The submissions are in nondecreasing order by submitted time (t).
In your calculations, consider that a submission sent at minute t was sent and judged exactly t minutes and 0 seconds after the beginning of the contest.
No team made more than one submission in a given minute and no team submitted an answer for a problem they have already solved.
Output a single integer, the total amount of time in minutes during which Marge's university's team was leading the scoreboard.
3 7 8
BOB
BOBAGI
MARGARIDA
BOBAGI A 1 OK
BOB A 16 NO
MARGARIDA A 22 OK
BOB A 30 OK
BOB H 180 OK
BOBAGI C 185 OK
MARGARIDA G 300 OK
6
2 3 10
BOB
CAFE
BOB A 1 OK
CAFE A 2 OK
CAFE J 300 OK
300
In the first example, BOB was leading the scoreboard between minutes 0 and 1 and between minutes 180 and 185.
In the second example, BOB was leading the scoreboard between minutes 0 and 300, but lost the leadership at the last moment.
Joaozao is a famous digit maker in the city of Sao Carlos. He owns a shop downtown where he receives orders to create numbers. Nicoleta, his friend and a very recent hire, is trying to learn this fancy art of digit making.
Joaozao is specialized in making numbers in base B. A number in base B is a sequence of digits written in the following way:
where 0 ≤ di < B for i = 1, 2, ... m.
Joaozao received an order to build an n-digit number in base B. It is a lot of work for one day, so he decided to ask Nicoleta, who is still learning, to help him.
The process of building the number is the following: First Joaozao creates 2n digits in base B. After that, Joaozao gives pairs of digits to Nicoleta, one after the other. As Nicoleta receives them, he adds these two digits together and takes the remainder of the division by B, creating a new digit z. Finally, Nicoleta attaches z to the beginning of the number they are building, making z its most significant digit. After n steps, they will have an n-digit number written in base B.
Joaozao has already created 2n digits in base B and they will soon start the next step of the process. They are wondering what is the largest number they can build (the larger the number, the more valuable it is). Nicoleta really wants to impress Joaozao, so he asked you to help him with this task.
The first line of the input contains two integers n (1 ≤ n ≤ 105) and B (1 ≤ B ≤ 109), indicating respectively the number of digits of the number Nicoleta will build and its base.
The second line contains 2n integers di representing the digits Joaozao has already created. (0 ≤ di ≤ B - 1).
Output n space separated integers: the digits of the largest number in base B that Joaozao and Nicoleta can build, from most significant to least significant.
If this number has leading zeros, output them anyway.
3 10
1 2 3 4 5 6
9 9 3
2 19
1 2 16 17
18 18
A number xb = d1d2...dm is larger than yb = r1r2...rp. If, and only if,

Danfsk bought some sheep and wants to protect them from wolves. He had the brilliant idea of building two convex fences, one strictly inside the other, and keeping all sheep inside the inner fence. This way, the sheep would have a second layer of protection from the wolves.
He hired Tomask, a famous fence architect, to design two fences for him. After finishing his project, Tomask gave Danfsk two pieces of paper, each containing the coordinates of the poles of a convex fence.
Tomask is also famous for miscalculations on his projects, so, before paying Tomask and starting building the fences, Danfsk wants to check if one convex fence is really strictly inside the other in Tomask's project. He asked you to help him with this task.
The first line of the input contains two integers N and M (3 ≤ N, M ≤ 105) indicating respectively the number of poles of the first convex fence and the number of poles of the second convex fence.
Each of the following N lines contains two integers: the i-th line contains xi1 and yi1 ( - 109 ≤ xi1, yi1 ≤ 109), indicating the coordinates of the i-th pole of the first fence.
Each of the following M lines contains two integers: the i-th line contains xi2 and yi2 ( - 109 ≤ xi2, yi2 ≤ 109), indicating the coordinates of the i-th pole of the second fence.
Each fence has the shape of a convex polygon. Pole coordinates of each fence are given in clockwise order. No two points in the project are the same.
Note that there may be colinear poles in the project.
Output YES if one fence is strictly inside the other (the first fence is strictly inside the second or vice versa). Output NO otherwise.
4 4
1 1
1 -1
-1 -1
-1 1
2 2
2 -2
-2 -2
-2 2
YES
4 3
0 0
0 3
3 3
3 0
1 1
2 3
2 1
NO
3 3
2 1
5 1
2 -1
-3 1
0 1
0 -1
NO
Marge is already preparing for Christmas and bought a beautiful tree, decorated with shiny ornaments. Her Christmas tree can be represented as a complete binary tree composed of N nodes, numbered from 1 to N and rooted on node 1. Each node has an integer value associated to it, representing its shininess.
The shininess of the h - th level of the tree is the sum of the shininess of all the nodes with depth h and the shininess of the tree is the largest value of shininess of its levels.
Nicoleta has a crush on a girl and wants to give her a part of Marge's beautiful tree. To do so, he will choose a node u and give his crush the subtree rooted at node u, including u. However, he doesn't want to get in (too much) trouble with Marge, so he will consider some candidates before making the cut.
Nicoleta has M candidate nodes to be the root of the cut subtree. For each candidate, Nicoleta wants to know what is the value of shininess of the remaining tree.
The first line of the input contains a three integers N (2 ≤ N ≤ 105) and M (1 ≤ M ≤ 105) and w (0 ≤ w ≤ 104), indicating, respectively, the number of nodes of the tree, the number of candidate nodes and the shininess of node 1.
Each of the next N - 1 lines contains three integers u (2 ≤ u ≤ N) , v (1 ≤ v ≤ N) and w (0 ≤ w ≤ 104), indicating that node u is a child of node v and has shininess w.
M lines follow, each with a single integer u (2 ≤ u ≤ N), indicating the number of a candidate node.
For each candidate node, in the order that they appear in the input, output a single line containing a single integer: the shininess of the remaining tree.
6 2 3
4 1 1
5 1 4
2 4 7
3 4 6
6 5 5
4
5
5
13
More about complete binary trees: https://en.wikipedia.org/wiki/Binary_tree#Types_of_binary_trees
Teodoro just moved to Canada. He is having a hard time there as the cost of living is higher than he expected. He is short on money so he decided to eat a string, as they are cheaper than food. He knows exactly how hungry he is, so he will buy a string with exactly K letters.
Teodoro went to a string store and saw that the price of a string depends on which letters are adjacent. For example, the price of the string "bca" is equal to the cost of putting "c" after "b" and "a" after "c". The costs of adjacent letters are given in a 26 × 26 matrix P, in which pi, j corresponds to the cost of putting the j-th letter of the alphabet after the i-th letter of the alphabet, e.g., p3, 7 is the cost of putting "g" after "c". Notice that the cost of putting i after j may not be the same as putting j after i, that is, pi, j may be different from pj, i.
Teodoro wants to order a string of size K with the minimum possible price. He is so hungry that he can barely think. Please help him find the cheapest string of size K.
The first line of the input contains an integer K (2 ≤ K ≤ 104), indicating the size of the string Teodoro will order.
The next 26 lines contain matrix P. The j-th integer of the i-th line corresponds to pi, j (0 ≤ pi, j ≤ 103), indicating the cost of putting the j-th letter of the alphabet right after the i-th letter of the alphabet.
Output a single integer: the minimum cost to create a string of size K.
4
9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
9 9 9 2 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
9 9 9 9 1 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 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9 9 9 9 9 9 9 9 9 9 9
9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
6
Joaozao and Nicoleta are planning to buy some pies at the local market. There are K different types of pies and Joaozao only buys pies of the types that are on his list of preferred pie types. The same goes for Nicoleta, who only buys pies of the types that are on his list of preferred pie types. It's guaranteed that every type of pie appears on at least one list of preferences.
The local market is doing a special pie sale. Because of this, all N pies are lined up in a row. The first pie in the row is of type p1, the second pie is of type p2 and so on until the N-th pie that is of type pN. It is guaranteed that the market sells all types of pies (i.e. each one of the K types of pies will appear at least once in this row). The special promotion of this sale was: if the same person buys pie i and pie i + 1, where i is the position of the pie in the row, this person gets gi candies.
Pies of the same type cannot be bought by different people (i.e. if Joaozao buys one pie of type t, then he has to buy all other pies of the same type t).
Joaozao and Nicoleta decided they will buy all N pies in the row and they want to maximize the total amount of candies they will earn. Given the lists of preferences for each one of them, the type of the pies in the row and the amount of candies that is earned for each pair of consecutive pies, can you tell what is the maximum total amount of candies they can get?
The total amount of candies is the sum of the candies earned by each of them.
The first line of the input contains four integers K (2 ≤ K ≤ 500), N (K ≤ N ≤ 103), A and B (1 ≤ A, B ≤ K) indicating, respectively, the number of types of pies, the number of pies in the row of pies, the size of Joaozao's preference list and the size of Nicoleta's preference list. Pie types are numbered from 1 to K.
The second line contains A integers, the types of pies that Joaozao prefers.
The third line contains B integers, the types of pies that Nicoleta prefers.
It's guaranteed that all the different types of pies will appear in at least one list of preferences.
The fourth line contains N integers. The i-th integer of this line indicates the type of the i-th pie of the row, as described in the statement. Each of the K types of pie will appear at least once.
The fifth and last line contains N - 1 integers. The i-th integer of this line gi (1 ≤ gi ≤ 103) corresponds to the amount of candies earned when buying the i-th and the (i + 1)-th pie.
Output a single integer indicating the maximum total amount of candies that Joaozao and Nicoleta can earn.
4 6 1 3
1
2 3 4
1 3 2 2 4 1
1 2 4 8 16
14
4 10 3 3
1 2 3
2 3 4
1 2 3 4 3 1 2 4 3 1
1 1 5 5 2 2 1 5 1
18
In the first case, to maximize the total amount of candies earned, Joaozao should buy the pies in positions 1 and 6 (1-indexed). Nicoleta should buy the rest.
In the second case, the pies that Joaozao should buy are in positions 1, 2, 6, 7 and 10. Nicoleta should buy the pies in positions 3, 4, 5, 8, 9.
Sancho is a matrix lover. Today he decided to play with a square matrix M with N rows and N columns. Every cell i, j of this matrix contains either 0 or 1.
From this matrix M he created another matrix A. Every cell i, j in this new matrix A contains the sum of the values of the cells in M that are in row i or column j. The element in the cell i, j of the matrix M should be added only once. Formally:

Unfortunately, Sancho lost the original matrix M and now, having only matrix A, he wonders what is the number of matrices M, such that matrix A can be created from M.
The first line of the input contains a single integer N (1 ≤ N ≤ 103), indicating the number of rows and columns of matrices M and A.
Each of the next N lines contains N integers. The j-th element of the i-th line Aij (0 ≤ Aij ≤ 104) is the value of the cell i, j of matrix A.
Output a single integer: the number of matrices M that could have been used to create the matrix A when the process described above is followed.
2
1 1
1 0
1
2
1 1
0 0
0
Sancho loves geometry. And he loves triangles even more, to the point of developing his own metric of beauty for triangles. In his metric, the beauty of a triangle is calculated by subtracting the length of the largest side from the sum of the lengths of the other two sides.
During weekends, Sancho likes to walk by the beach looking for straight sticks to build his triangles. He has already found 2 sticks and he's very optimistic about the triangle he's going to build.
He wants to know what should be the length of the third stick so that the beauty of his triangle is maximized. Help him with this task!
The input consists of a single line, containing two integers l1 and l2 (1 ≤ l1, l2 ≤ 2 × 109) indicating the length of the sticks that Sancho has already found.
Output a single integer: the length of the third stick that maximizes the beauty of the triangle that Sancho is going to build.
5 5
5
When building teams for programming competitions, it is a good idea to team up people that are good at different topics. For instance, it would be a good idea to team up someone who is good at graph problems and bad at geometry problems with someone who is good at geometry problems but bad at graph problems.
GEMA is a programming competition study group with N members. GEMA coaches are interested in counting the number of different good teams that can be created. A good team is composed of 2 members and each member is good at at least one topic that his teammate isn't good at. Two teams are considered different if at least one member is present in one team but not in the other.
GEMA coaches are only considering the M most important topics, and they know, for each member, which topics they are good at, and which topics they are bad at.
The first line of the input contains two integers N (2 ≤ N ≤ 105) and M (2 ≤ M ≤ 21), indicating respectively the number of members in the study group and the number of topics that are being considered.
The second line contains N integers. The i-th integer corresponds to xi (0 ≤ xi < 2M). The j-th least significant digit of the binary representation of xi is 1 if the i-th member is good at the j-th topic and 0 otherwise. For instance, if M = 5 and the i-th member has xi = 11 = (01011)2, it means that he is good at the first, second and fourth topic and bad at the third and fifth topic.
Output a single integer: the number of different good teams that can be created.
2 3
1 4
1
5 4
1 6 13 3 11
6
3 3
1 3 7
0