task
stringlengths
0
154k
__index_level_0__
int64
0
39.2k
Weak Bridge Ahead (WBAHD) You are on a highway of two lanes. There is a bridge on the highway which is almost broken. It is so weak that at most one car can stay over the bridge at any moment. Few cars are waiting on both ends of the bridge forming a queue and they want to cross the bridge. Cars on the same side of the bridge are in the same lane and cars on different sides of the bridge are in different lanes. No car can overtake any other car or change its lane; otherwise, they will be fined. So only the cars which are at the front of their queue have the chance to cross the bridge. Given the time needed for each car to cross the bridge, find the optimal order of cars passing the bridge such that the maximum waiting time of a car is minimized [See sample input/output and the explanation section for better understanding]. Waiting time for a car is equal to the time it has to wait before stepping onto the bridge. You can assume that the time needed for a car to get to the bridge or to get down from the bridge is negligible. Input The first line of input contains two integers, T , denoting the number of test cases. Then for each test case you will first be given two integers, N and M . Here N denotes the number of cars waiting in the left side of the bridge and M denotes the number of cars waiting in the right side of the bridge. It follows a single line having N integers. The i -th integer of this line denotes the time needed for the i -th car to pass the road in seconds [ the car at the front of the queue is considered to be the first car ] . Then a line follows having M integers describing the second queue in exactly the same way. Output For each test case print an integer in the form " Case x: k " where x is equal to the number of test case starting from 1 and k is equal to the minimum possible waiting time of the car which has the maximum waiting time. Constraints 1 ≤ T ≤ 10 1 ≤ N ≤ 10000 1 ≤ M ≤ 10000 1 ≤ Time needed for a car to cross the bridge ≤ 1000000000 Example Input: 2 1 1 5 3 3 2 9 11 4 10 12 Output: Case 1: 3 Case 2: 34 Explanation: In the first test case, it’s better to first let the car which takes 3 seconds to pass the bridge first. So the other car has to wait for 3 seconds. In the second case, initially, the highway looks like this: [“-” sign indicates road and “#” sign indicates bridge] 4 11 9 ### ------ ------ ### 10 12 Now let one car from the left side pass the bridge: 4 11 ### ------ ------ ### 10 12 This car had to wait for 0 seconds. Then let one car from the right side pass the bridge: 4 11 ### ------ ------ ### 12 This car had to wait for 9 seconds. Then let another car from the left side pass the bridge: 4 ### ------ ------ ### 12 This car had to wait for 19 seconds. After that, let the last car from the left side pass the bridge. ### ------ ------ ### 12 This car had to wait for 30 seconds. Finally, let the last car from the right side pass the bridge and you are done. ### ------ ------ ### This car had to wait for 34 seconds. So 34 is the maximum waiting time which we tried to minimize. It’s not possible to get a smaller answer by any other ordering of the cars crossing the bridge.
35,000
Straight Line Spiral Pattern (Act 4) (SPTTRN4) For this problem we consider spirals drawn as ASCII Art pictures using only the * and . character in an s by s grid. We call s the size of the spiral. Here are example of such spirals for some values of s. The spiral of size s=3 *.* *.* *** The spiral of size s=4 *.** *..* *..* **** The spiral of size s=5 *.*** *.*.* *.*.* *...* ***** The spiral of size s=6 *.**** *.*..* *.*..* *.**.* *....* ****** The spiral of size s=7 *.***** *.*...* *.*.*.* *.*.*.* *.***.* *.....* ******* The spiral of size s=8 *.****** *.*....* *.*.**.* *.*..*.* *.*..*.* *.****.* *......* ******** The spiral of size s=9 *.******* *.*.....* *.*.***.* *.*.*.*.* *.*.*.*.* *.*...*.* *.*****.* *.......* ********* Input The first line contains an integer T=1000, which is the number of test cases. Then the next T lines contain 3 integers separated by a single space, namely 3≤s≤10000, 1≤i≤s and 1≤j≤s. Output For each test case output in a single line the character of the spiral of size s at row i and at column j. Example Input: 3 3 1 1 4 3 2 5 2 3 Output: * . *
35,001
Pertre (RETOCALENTAMIENT) Every summer Pertre comes to visit her grandmother in the field. This summer, she has a huge wart. Her grandmother knows that one should treat warts when the moon is waning. Therefore, Pertre have to know the time when the moon is there. The lunar cycle lasts 30 days. The size of the visible part of the moon (in units Pertre) for each day is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 and then repeats the cycle, so that after the second one goes back 0, 1, 2... Since there is no internet in the field, Pertre has been watching the moon during several days (n) consecutive and for each of these days wrote the size of the visible part of the moon. Help her to find out if the moon is waxing or waning in the next day or if this can not be determined by the data you have. Spanish version . Input The first line of the input contains a single integer n (1 ≤ n ≤ 92) - the number of consecutive days Pertre was seeing the size of the visible part of the moon. The second line contains n integers ai (0 ≤ ai ≤ 15) - Records Pertre. It is guaranteed that the input data is consistent. Output If Pertre can be sure that the size of the visible part of the moon in the day n + 1 is smaller than the size of the visible part in the day n, then print "MENGUANTE" in the only line of output. If she can be sure that the size of the visible part will increase, then print "CRECIENTE". If it is impossible to determine what exactly will happen to the moon, print -1. Example Input: 5 3 4 5 6 7 Output: CRECIENTE Input: 7 12 13 14 15 14 13 12 Output: MENGUANTE Input: 1 8 Output: -1 Explanation In the first example, the size of the moon in the next day will be 8, therefore the answer is "CRECIENTE". In the second example, the size of the moon in the next day will be 11, so the answer is "MENGUANTE". In the third example, you can not determine what the size of the moon as it can be 7 or 9, therefore the answer is -1.
35,002
COMPUTADOR LOCO . . . (RETO1) ZS Coder performs encoding in a crazy team. If a word is entered into the system in an amount c of consecutive seconds, everything written disappears. More formally, if you have written a word in the second A and then the next word in the second B, then if (B-A) ≤ c, the new word is added to the other words on the screen. If (B-A) > c, then everything on the screen is cleared (after the last word you typed appears on the screen). For example, if c = 5 and written in the second words 1, 3, 8, 14, 19, 20, after the 8th second, three words will be displayed. After that, everything disappears in the 13th second because nothing has been written before the 5 seconds. In the second 14 and 19 two words are written, and finally, in the second 20, you write a word, and a total of three words remain on the screen. Yes give the times when the ZS Coder typed words. Determine how many words remain in after having finished writing all the screen. Spanish version Input The first line contains two integers N and C (1 ≤ n ≤ 100000, 1 ≤ c ≤ 10 9 ) - the number of words typed ZS Coder and delayed crazy, respectively equipment. The next line contains n integers t1, t2 ... tn (1 ≤ t1 < t2 < ... < tn ≤ 10 9 ), where ti denotes the second when ZS Coder writes the watchword i. Output Print a single positive integer, the number of words that remain on the screen after all N words are written, in other words, in the second tn. Example Input: 6 5 1 3 8 14 19 20 Output: 3 Input: 6 1 1 3 5 7 9 10 Output: 2 Explanation The first example is explained in the problem. For the second example after writing the first word in the second one, it disappears because the next word is written in the second 3 and (3-1) > 1 Similarly to 5, 7 and 9, only one word remains in the second 9. Then, a word is written in the second 10, it remains on the screen because (10-9) ≤ 1
35,003
TIEMPO JUNTOS grado 10 (RETO2) Today, an exceptional event will happen in the forest - the hedgehog Filya visit his old friend Sonya! Sonya is an owl and sleeps during the day and awake from minute to minute L1 R1, inclusive. In addition, during the minute she preens k and is not available for Filya. Filya works hard and plans to visit Sonya minute to minute R2 L2, inclusive. Calculate the number of minutes they can spend together. Spanish version Input The only line of input contains integers L1, R1, L2, R2 and k (1 ≤ L1, R1, L2, R2, k ≤ 10 18 , L1 ≤ R1, L2 ≤ R2), providing time slots for Sonya and Filya and the moment of time when Sonya preens. Output Print an integer - the total number of minutes that Sonya and Filya can spend together. Example Input: 1 10 9 20 1 Output: 2 Input: 1 100 50 200 75 Output: 50 Explanation In the first example, they can be together during the 9 to 10 minutes. In the second example, they can be together from 50 to 74 minutes and 76 to 100.
35,004
REJILLA MAGICA (RETO3) ZS Coder and Chris baboon reached the entrance of Udayland. There, at the entrance, there is a magic grid full of integers (n × n). Chris realized that exactly one of the cells of the grid is empty, and to enter Udayland have to put a positive integer in the empty cell. Chris tried to fill in random numbers, but it did not work. ZS Coder realizes they have to put a positive integer such that the numbers in the matrix form a magic square. This means you have to place a positive integer such that the sum of the numbers in each row of the matrix (), each column of the matrix (), and the two diagonals (the main diagonal and the diagonal high) are equal. Chris does not know what number should be placed. Can you help Chris to find the correct positive integer to place or determine that it is impossible? Spanish version Input The first line of the input contains a single integer n (1 ≤ n ≤ 500) - the number of rows and columns of the matrix magic. In the n lines following are the n integer row. The number jth in the ith line is denoted a[i, j] (1 ≤ a[i, j] ≤ 10 9 or a[i, j] = 0), the row number ith and jth column magic matrix. If the corresponding cell is empty, a[i, j] is equal to 0. Otherwise, a[i, j] is positive. It ensures that there is exactly one pair of integers i, j (1 ≤ i, j ≤ n) such that a[i, j] = 0. Output A single integer, positive integer x (1 ≤ x ≤ 1.018) to be placed in the empty cell so that the whole matrix becomes a magical array. If there is no positive integer x, output -1. If there are multiple solutions, you can print any of them. Example Input: 3 4 0 2 3 5 7 8 1 6 Output: 9 Input: 4 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 Output: 1 Input: 4 1 1 1 1 1 1 0 1 1 1 2 1 1 1 1 1 Output: -1 Explanation In the first example, we can put 9 in the empty cell: The sum of each row would be: 4 + 9 + 2 = 3 + 5 + 7 = 8 + 1 + 6 = 15. The sum of each column would be: 4 + 3 + 8 = 9 + 5 + 1 = 2 + 7 + 6 = 15. The sum of the two diagonals is: 4 + 5 + 6 = 2 + 5 + 8 = 15. In the third case, it is not possible to find a number that converts the magic matrix.
35,005
Punto de Control (RETO4) Vasya takes part in the competition guidance. There are n control points located along the line at coordinates x1, x2 ... xn. Vasya starts at the point with given coordinate. His goal is to visit at least n - 1 control points in order to finish the race. Participants are allowed to visit checkpoints in any order. Vasya wants to collect these checkpoints, he asks for help to calculate the total distance travelled is minimised. Input The first line of the input contains two integers n and a (1 ≤ n ≤ 100000, -1000000 ≤ a ≤ 1000000) - the number of checkpoints and the starting position of Vasya, respectively. The second line contains n integers x1, x2 ... xn (-1000000 ≤ xi ≤ 1000000) - coordinates of the control points. Output Print one integer - the minimum distance that Vasya has to travel in order to visit at least n - 1 checkpoint Example Input: 3 10 1 7 12 Output: 7 Input: 2 0 11 -10 Output: 10 Input: 5 0 0 0 1000 0 0 Output: 0 Explanation In the first example Vasya should visit two points. The best way to accomplish this is to go first to the third control point (the distance is 12-10 = 2) and then proceed to the second (the distance is 12-7 = 5). The total distance is 2 + 5 = 7. The second is enough to visit a single point of control mode Vasya should simply go to the extent -10. Distance 10.
35,006
EXPRIMIDOR Grado 11 (RETO5) Kolya is going to make orange juice. He has n oranges sizes a1, a2 ... an. Kolya lay them in the blender in a fixed order, from orange size a1 then a2 size orange and so on. To be put in the blender the orange should have a size not greater than B, so if Kolya sees an orange that is strictly greater than B strip away and continues to the next. The juicer has a special section to collect waste. This section overflows if the sum of squeezed oranges size is greater than d. When this happens, Kolya empties the waste section (even if there are no more oranges to be squeezed) and continues to squeeze the juice. How many times does Kolya have to empty the waste section? Spanish version Input The first line of the input contains three integers n, B and d (1 ≤ n ≤ 100000, 1 ≤ B ≤ d ≤ 1000000) - the number of oranges, the maximum size of the orange that fits in the blender and the d value, which determines the condition when the section waste must be emptied. The second line contains n integers a1, a2 ... n (1 ≤ ai ≤ 1000000) - oranges sizes listed in the order and Kolya will try to put in blender. Output Print one integer - the number of times Kolya will have to empty the waste section. Example Input: 2 7 10 5 6 Output: 1 Input: 1 5 10 7 Output: 0 Explanation In the first example, Kolya squeeze the juice of two oranges and empty the waste section later. In the second example, the orange will not fit into the juicer so that Kolya will not have any juice at all. In the third example, Kolya squeeze the juice of two oranges and empty the waste section later, then squeezes the other orange.
35,007
HULK Grado 10 (RETO6) Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings. Hulk likes the Inception so much, and like that his feelings are complicated. They have  n  layers. The first layer is hate, second one is love, third one is hate and so on... For example if  n = 1, then his feeling is "I hate it" or if  n = 2 it's "I hate that I love it", and if  n = 3 it's "I hate that I love that I hate it" and so on. Please help Dr. Banner. Input The only line of the input contains a single integer  n  (1 ≤ n ≤ 100) — the number of layers of love and hate.   Output Print Dr. Banner's feeling in one line. Example Input: 1 Output: I hate it
35,008
El Hotel con Habitaciones Infinitas (RETO7) HaluaRuti city has a strange hotel with infinite rooms. The groups that come to the hotel follow the following rules: At the same time, only members of a group can rent the hotel. Each group arrives in the morning one day and out the evening of another day. Another group arrives in the morning after a group left the hotel. A very important feature of a group that arrives is to have a member more than the previous group unless it is the first group. You will have the number of members of the original group. A group with n members stay for n days in the hotel. For example, if a group of four members arrive on August 1 in the morning, this will leave the hotel on August 4 night and the next group of five members arrive on Aug. 5 in the morning and go on 5 days and so on. Given an initial group size you should find the size of the group is in the hotel on a specific day. Spanish version Input The input contains integers S (1 <= S <= 10000) and D (1 <= D <= 1015) in each line. S denotes the initial size of the group and D denotes the day for which you must find the size of the group at the hotel, D-th day (starting from 1). All integers input and output are lower than 1015. A group size S means that on the first day a group of S members came to the hotel and stay for S days, then come a group of S + 1 members according to the rules described above. Output For each line of input, print in a line the size of the group at the hotel in the D-th day. Example Input: 1 6 3 10 3 14 Output: 3 5 6
35,009
Maths is Magic (NJEG1) Nikita is facinated by card tricks. She knows that many of the tricks are nothing but mathematical calculations, so she decides to create her own trick. She calls her three friends Medha, Muskan and Anita to show her trick. The trick goes like this. Nikita has a deck of cards (52 cards), 4 plates (plate1, plate2, plate3, plate4) . She asks her friend to shuffle them. Now she wants her friends to assume some things: Jack card has value = 1. Queen has value = 2. King has value = 3. Ace has value = 4. Rest of the cards have the value that are on them. Suits don't matter. Now from the shuffled deck, Nikita takes out one by one 26 cards and puts them on plate1 (these 26 cards are shown to everyone) upside down and hands over the remaining deck to Medha. She asks Medha to take any card say card A from the deck and put it on the plate2 and make its value to 10 by adding the other cards to the plate. For instance , suppose the card taken by Medha is 4, now its value can only be made to 10 by adding any 6 cards (irrespective of the value of the cards) from the deck. Medha passes the remaining cards to Muskan . Now she asks Muskan to take any card from the remaining deck of cards say card B and put it on the plate 3 and make its value to 10 like Medha did. For instance , Suppose Muskan choose Jack (value = 1), now its value can only be made to 10 by adding any 9 cards from the deck. Muskan passes remaining cards to Anita . Now she asks Anita to take any card from the remaining deck of cards say card C and put it on the plate 4 and make its value to 10 like Medha did, If Anita doesn't have sufficient cards she can borrow from the plate1 ( from top of the deck ). For instance , suppose Anita choose 7, now its value can only be made to 10 by adding any 3 cards from the deck. Anita passes remaining cards to Nikita . Now she put the remaining cards on the deck that is already on plate1 (upside down), and asks her friend to tell her the sum of card A + card B + card C. Say this sum is index . From the deck of cards on plate1 , she predicts the value of a card at the index (index = card A + card B + card C). Her friends take out the cards from plate1 and find the same card at that index. Voila they are surprised. Input First line will contain ' T ', the number of test cases. Each line will have values of 26 cards , followed by the values of Card A, Card B and Card C . ( It is guaranteed that the cards A, B and C are not Q, K, A .) Output Each test case must predict the value of the card in plate1 at the index. Where index = values of card A + card B + card C. (Remember plate1 has 26 cards plus remaining cards given by Anita .) Example Input: 1 A 4 2 3 6 5 7 8 9 10 J K Q 2 3 4 5 6 7 8 J Q 8 9 5 4 7 2 4 Output: 7 Explanation Plate1 initially has 26 cards. Now from remaning 26 cards 7 (Card A) was chosen by Medha and to make its value 10, three more cards were added to plate2. From remaining 22 cards, Muskan choose 2 (Card B) and added 8 more cards to make its value 10. Now from remaining 13 cards, Anita choose 4 Card C) and added 6 more cards. Remaining 6 cards were put on 26 cards already in plate1 i.e. plate1 now has (26 + 6) = 32 cards. Index = 13 (7 + 2 + 4), So Nikita predicted card at index number = 13 from the 32 cards.)
35,010
La tarea (CALENTAMIENTO) Today Pispirito was a kind of logic for the first time, the teacher left a task he can not complete without your help. Pispirito has a vector of non-negative integers a1, a2 ... an. What you should do is, first, choose an integer x, then add x to some elements of the vector (not more than once), subtract x from some other elements (also, no more than once) and leave other elements unchanged, so that all vector elements are equal. Pispirito wonders if such an integer x exists? Todo los algoritmos en Español www.dropbox.com/s/u0hc8ukm3iy4sk6/RETOS_MARATON_final_V1_2_2016.doc?dl=0 . Input The first line of input contains an integer n (1 ≤ n ≤ 100 000) - the number of integers in the vector Pispirito. The second line contains n integers a1, a2 ... n (0 ≤ ai ≤ 10 9 ) - vector elements. Output If it is impossible for all elements of the vector are equal by the procedure specified in the problem statement, then print "NO" (without quotation marks) in the only line of output. Otherwise print "YES" (without quotation marks). Example Input: 5 1 3 3 2 1 Output: Si Input: 5 1 3 3 2 1 Output: Si Note: In the first example Pispirito must select x = 1, and then add it to the first and last element of the vector and subtracting the second and third elements.
35,011
Reto Nro 1 Desfile (FINAL1) Very soon there will be a parade of victory over the alien invaders in Mogotes. Unfortunately, all the soldiers were killed in the war and now the army is fully composed of new recruits, many of whom do not even know which leg should begin a march. The civilian population does not understand which of the legs start to go, so it is only important how many soldiers marching in the parade. There will be n columns participating in the parade, the i-th column is li soldiers, who begin to march with the left leg, and ri soldiers, who begin to march with the right leg. The beauty of the parade is calculated by the following formula: if L is the total number of soldiers in the parade starting to march with the left leg, and R is the total number of soldiers in the parade to begin to march with the right leg, beauty is equal to |L - R|. In order to have the greatest beauty, not more than once, you can choose a column and tell all the soldiers in this column change their starting leg, i.e. everyone in this column that starts up with left leg now begin with the right leg and vice versa. Formally, it can be exchanged, not more than one index i, li values ​​and ri. Find the index of the column, so that changing the starting leg for soldiers in this column will maximise the beauty, or determine that it is not necessary to change to increase the current beauty. Input The first line contains a single integer n (1 ≤ n ≤ 105) - which is the number of columns. The following n lines contain pairs of integers li and ri (1 ≤ li, ri ≤ 500) - the number of soldiers in the ith column begin to march with the left leg or right leg respectively. Output Print a single whole number k - the number of the column in which the soldiers need to change leg that begin to march, or 0 if the maximum beauty is already reached. Note that the columns are numbered from 1 to n, in the order in which the input data are given. If there are multiple answers, print any of them. Example Input: 3 5 6 8 9 10 3 Output: 3 Input: 2 6 5 5 6 Output: 1 Input: 6 5 9 1 3 4 8 4 5 23 54 12 32 Output: 0 Explanation In the first example, if you do not give the order to change the starting leg, the number of soldiers, who start marching with the left leg, would be equal to 5 + 8 + 10 = 23, and with the right leg: 6 + 9 + 3 = 18. In this case, the parade beauty will be equal to |23 - 18| = 5. If the order is given to change the leg with which they start the parade to the third (3) column, the number of soldiers who march with the left leg will be equal to 5 + 8 + 3 = 16, and with the right leg: 6 + 9 + 10 = 25. In this case beauty is equal to |16 - 25| = 9 . It is impossible to reach a greater beauty by giving other orders. Therefore, the maximum beauty that can be achieved is 9.
35,012
Reto Nro 6 Cupid (FINAL6) Cupid is standing in a bar and starring at a pretty girl. He wants to shoot her with his heart arrow but he needs to know the distance between him and the girl to make his shot accurate. Cupid asked the bar tender Carl about this distance value, but Carl was so busy talking to the customers so he wrote the distance value (it's a real number) on a napkin. The problem is that he wrote it in scientific notation. The scientific notation of some real number x is the notation of form AeB , where A is a real number and B is an integer and x = A × 10 B is true. In our case A is between 0 and 9 and B is non-negative. Cupid doesn't know anything about scientific notation (as well as anything scientific at all). So he asked you to tell him the distance value in usual decimal representation with minimal number of digits after the decimal point (and no decimal point if it is an integer). See the output format for better understanding. Input The first and only line of input contains a single string of form a . deb where a , d and b are integers and e is usual character 'e' (0 ≤ a ≤ 9, 0 ≤ d < 10 100 , 0 ≤ b ≤ 100) — the scientific notation of the desired distance value. a and b contain no leading zeros and d contains no trailing zeros (but may be equal to 0). Also, b can not be non-zero if a is zero. Output Print the only real number x (the desired distance value) in the only line in its decimal notation. Thus if x is an integer, print it's integer value without decimal part and decimal point and without leading zeroes. Otherwise print x in a form of p . q such that p is an integer that have no leading zeroes (but may be equal to zero), and q is an integer that have no trailing zeroes (and may not be equal to zero). Example Input: 8.549e2 Output: 854.9 Input: 8.549e3 Output: 8549 Input: 0.33e0 Output: 0.33
35,013
Reto Nro 7 Spider Man (FINAL7) Peter Parker wants to play a game with Dr. Octopus. The game is about cycles. Cycle is a sequence of vertices, such that first one is connected with the second, second is connected with third and so on, while the last one is connected with the first one again. Cycle may consist of a single isolated vertex. Initially there are k cycles, i -th of them consisting of exactly v i vertices. Players play alternatively. Peter goes first. On each turn a player must choose a cycle with at least 2 vertices (for example, x vertices) among all available cycles and replace it by two cycles with p and x - p vertices where 1 ≤ p < x is chosen by the player. The player who cannot make a move loses the game (and his life!). Peter wants to test some configurations of initial cycle sets before he actually plays with Dr. Octopus. Initially he has an empty set. In the i -th test he adds a cycle with a i vertices to the set (this is actually a multiset because it can contain two or more identical cycles). After each test, Peter wants to know that if the players begin the game with the current set of cycles, who wins? Peter is pretty good at math, but now he asks you to help. Input The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of tests Peter is about to make. The second line contains n space separated integers a 1 , a 2 ... a n (1 ≤ a i ≤ 10 9 ), i -th of them stands for the number of vertices in the cycle added before the i -th test. Output Print the result of all tests in order they are performed. Print 1 if the player who moves first wins or 2 otherwise. Example Input: 3 1 2 3 Output: 2 1 1 Input: 5 1 1 5 1 1 Output: 2 2 2 2 2 Explanation In the first sample test: In Peter's first test, there's only one cycle with 1 vertex. First player cannot make a move and loses. In his second test, there's one cycle with 1 vertex and one with 2. No one can make a move on the cycle with 1 vertex. First player can replace the second cycle with two cycles of 1 vertex and second player can't make any move and loses. In his third test, cycles have 1, 2 and 3 vertices. Like last test, no one can make a move on the first cycle. First player can replace the third cycle with one cycle with size 1 and one with size 2. Now cycles have 1, 1, 2, 2 vertices. Second player's only move is to replace a cycle of size 2 with 2 cycles of size 1. And cycles are 1, 1, 1, 1, 2. First player replaces the last cycle with 2 cycles with size 1 and wins. In the second sample test: Having cycles of size 1 is like not having them (because no one can make a move on them). In Peter's third test: There a cycle of size 5 (others don't matter). First player has two options: replace it with cycles of sizes 1 and 4 or 2and 3. If he replaces it with cycles of sizes 1 and 4: Only second cycle matters. Second player will replace it with 2 cycles of sizes 2. First player's only option to replace one of them with two cycles of size 1. Second player does the same thing with the other cycle. First player can't make any move and loses. If he replaces it with cycles of sizes 2 and 3: Second player will replace the cycle of size 3 with two of sizes 1 and 2. Now only cycles with more than one vertex are two cycles of size 2. As shown in previous case, with 2 cycles of size 2 second player wins. So, either way first player loses.
35,014
SUM OF DIGITS (ALCATRAZ1) You are being given a number N. (1<=N<=10^50) . You have to print the sum of digits of that particular number.  Input The first line will contain T, the number of testcases (T<10) . The next T lines will contain the numbers whose sum of digits you have to calculate .   Output Output T lines  containing the Sum of Digits of the numbers . Example Input: 3 123123123 3434 1234567890 Output: 18 14 45
35,015
Lazy tourist guide (GIRTH) Marie-Chantal works as a tourist guide. As such she proposes tours to tourists in her city that pass by some of the available points of interest. In the city one can reach of course any point of interest from any other point of interest, but some for some pair of points it is unreasonable to walk directly from the first to the second point without stopping on the way at some other intermediate points of interest. The city provided Marie-Chantal a list of pairs of points of interest that is reasonable to reach directly. These pairs are called reasonable. If A, B is a reasonable pair then so is B, A. A reasonable tour is a list of points of interest that are all different except the first and the last one which are equal, and such that any two successive points of interest on the list form a reasonable pair. She is quite a lazy tourist guide so she wants to find a reasonable tour that visits as little points of interest as possible. Can you help her? Input The first line contains a single integer, the number of test cases. Each test case starts with a line containing two space separated integers N and M, (1≤N≤1000, 1≤M≤40000) where N is the number of points of interest, numbered from 1 to N and M is the number of reasonable pairs. The remaining M lines contain each two space separated integers A, B, (1≤A Output For each test case, numbered k start at 1, output a single line as follows. If there is no tour output "Case #k: -1".  Otherwise output "Case #k: t u1 u2 … ut", where t is the length of an arbitrary shortest tour and u1, u2 … ut, the identifiers of the points of interest along the tour with u1 being equal to ut. The sequence u1, u2 ... ut should be lexicographically smallest among all reasonable tours of length t. Example Input: 2 4 3 1 2 1 3 1 4 4 5 1 2 2 3 3 4 1 4 2 4   Output: Case #1: -1 Case #2: 3 1 2 4 1
35,016
Password01 (TESTPASS) Create a program that verifies passwords. Requirements: 6-20 characters. at least one capital letter, one small, one special character, one digit. the password can not contain consecutive strings of 2 and 3 characters. Input Number of passwords. Passwords. Output Check result "YES" if correct "NO" if not. Example Input: 8 PASS P@ss P@ss123123 Alabama@#1 nonoP@ssw0rd My2P@SSword abcddcba123# MyP@sswordIsReallyLong@RosesAreBlue Output: NO NO NO YES NO YES NO NO
35,017
Ada and Behives (ADABEHIVE) Ada the Ladybug is currently doing her thesis. It is almost complete with one tiny exception - there are some graphs and statistics missing. The topic of thesis is " Behavior of Bee Hives ". She examines population of bees and their growth in given areas. Ada has all data she needs - but parsing it manually might take many long months. She decided to ask you for help. Basically - given population of individual bee hives you will have to answer the number of bees in given area. There are two kinds of queries: Query of kind 1 gives you coordinates of hive and number of new-born bees. Query of kind 2 gives you description of rectangle. You will be asked to find the number of bees living in it. Input The first line contains three integer numbers 1 ≤ N, M ≤ 2000, 1 ≤ Q ≤ 10 5 , the size of examined area (number of rows and number of columns), and number of queries. The next N lines contains M integer numbers 1 ≤ A i,j ≤ 10 4 , the sizes of hives. Afterward, Q lines (of two types) follow First kind 1 I J P , 1 ≤ I ≤ N , 1 ≤ J ≤ M , 1 ≤ P ≤ 10 4 , the position of hive and the number of new-born bees. Second kind 2 I 1 J 1 I 2 J 2 , 1 ≤ I 1 ≤ I 2 ≤ N , 1 ≤ J 1 ≤ J 2 ≤ M , the boundaries of rectangular area for which you want to know the number of bees (more specifically the lower-left and upper right corners). Output For each query of second kind, output the number of bees. Example Input 6 5 8 1 2 3 4 5 1 2 3 4 5 6 6 6 6 6 5 4 3 2 1 5 4 3 2 1 6 6 6 6 6 2 1 1 6 5 2 1 1 2 4 2 4 2 5 4 1 5 4 4 1 1 1 665 2 1 1 6 5 2 1 1 2 4 2 4 2 5 4 Example Output 120 20 18 789 685 22
35,018
Awesome Childhood (AWESOMECHILDHOOD) Childhood is the best time of anyone. We all time miss those awesome moments. Do you remember the winter morning of school day? I can remember! My mom woke me to go to school but I acted like "I don't hear anything!" Can you remember the feelings when your mom is beating your siblings and you are the next!!! Ahh... those days!!! Let’s play a childhood game. You must be feel nostalgic. Think of a number (N) in your head. Borrow that number from your friend. Add them and you have now 2N. I give you 10236 (let G). Add G with 2N. Then equally divide the whole number [(2N+G)/2]. One part keep on your mind and another part through away. Now it’s time to back the borrowed part to your loving friend [{(2N+G)/2}-N]. Finally you have 5118! Think what a genius I am! I know the remaining number! Can you do so? Input First of all input an integer T (0 < T < 10000). T denotes the number of test cases to follow. For each case you’ll given an integer G (1 < G <= 2^32). Where G is multiple of 2. Output For each test case print one line of the form “Case T: R”. Where T is the case number and R is the result according to above description. See sample I/O for more clear. Example Input: 2 10236 172 Output: Case 1: 5118 Case 2: 86
35,019
Will it blend? (URJC2_C) That is the question. Tom Dickson is in charge of the channel Blendtec which is in charge of blending, well, basically anything that can be find, or blend. Mr. Tom don’t want to fail his public on the next show in Madrid, so he is asking the URJC if, given the blender power he is bringing in and some items, whether these items will or will not blend. Input The first line contains an integer T, which specifies the number of test cases. Then, will follow the descriptions of T test cases. For each test case you will receive two integers N and K denoting the number of items to follow and the power of the blender, then, N lines will follow with a single integer Ni denoting the power needed to blend the item. Output For each test case you must print N lines with a string ”Yes, it blends!” if the blender power exceeds the power needed to blend the item, if this is not true, you should print ”Well, it mostly blended” (quotes only for clarification) Example Input: 2 3 5 1 200 4 2 5000 4999 5000 Output: Yes, it blends! Well, it mostly blended Yes, it blends! Yes, it blends! Well, it mostly blended Constraints 1 ≤ N ≤ 1,000 1 ≤ K ≤ 1,000,000,000 1 ≤ Ni ≤ 1,000,000,000
35,020
Keyboard Writing (URJC2_D) Writing at the keyboard can be as easy as riding a bike or as difficult as making a pie (bet you can’t make a pie, can you?). We want to estimate the time that a person will take to write a line, for simplicity, the line will contain only lowercase letters. The person who will take the test will know for sure where some keys are, if they are reading the text and they know beforehand where the key is, they will take on average 50ms to type the letter, else, they will take 150ms to identify the key and then type it. After that, the key will be learnt and if the same letter appears they will no longer need to identify the key, hence, they will just press it and take 50ms. Input The first line contains an integer T, which specifies the number of test cases. Then, will follow the descriptions of T test cases. Each test case will contain two lines, the first line A will contain up to 26 lowercase letters denoting the letters the person knows. The second line B will contain a string of lower case characters that the person needs to transcribe. Output For each input case you must print the number of milliseconds the person needs to write down the second line of each test case. Example Input: 2 urjc urjccontesttwo abcdefghijklmnopqrstuvwxyz thequickbrownfoxjumpsoverthelazydog Output: 1300 1750 Constraints 1 ≤ |A| ≤ 26 1 ≤ |B| ≤ 100,000
35,021
The String Problem (AGPC01D) Mina and Tina love to play with strings. Mina's favorite string name is A and Tina's favorite string name is B . One day Tina stole Mina's string. Now she is wondering the maximum number of string B she can make using characters from string A . After trying for a long period of time she failed to figure out the number. Now she is asking for your help to find the number. Input Input starts with T (1 <= T <= 100) , denoting the number of test case. Each of the test case contains 3 line. First line contains n and m (1 <= n, m <= 100000) . n and m are the size of string A and B respectively. Second line contains string A and third line contains B . Input contains only lower case English letter. Output For each testcase, find the maximum number of string B can be created using characters from string A. Example Input: 2 4 2 abcd ca 4 1 abcd e Output: 1 0
35,022
Can you search? (AGPC01F) Shimlin loves to play with array. One day she was playing a game of finding the smallest number in an array but soon she got bored as the game was too easy for her. She asked her ghost friend to make the game more interesting. After thinking for a while the ghost came up with an idea. The ghost will give her some queries. In each query the ghost will tell her a number b i (less than the given array size) and Shimlin will have to answer the smallest number among first b i elements of the given array. The ghost gave you the responsibility to find the correct answer of each query so that he can match the answer with Shimlin's answer. Input Input starts with T (1 ≤ T ≤ 100) , denoting the number of test cases. Each of the test cases contains 3 lines. In the first line there are two positive integer numbers n and q (1 ≤ n ≤ 10^5, 1 ≤ q ≤ 10^5) — size of the array and number of queries. The second line contains n integers a 1 , a 2 ... a n (1 ≤ a i ≤ 10^5) — elements of the array. The third line contains q integers b 1 , b 2 ... b q (1 ≤ b i ≤ n) — range of query. Output For each query print one integer in a line— the minimum number in that range. Example Input: 1 4 2 2 2 3 1 3 4 Output: 2 1
35,023
A complex yet very simple problem (STROOQ) Pattern Matchers have been designed for various sorts of patterns. Mr. HKP likes to observe patterns in numbers. After completing his extensive research on the squares of numbers, he has moved on to cubes. Now he wants to know all numbers whose cube ends in 888. Given a number k , help Mr. HKP find the k th number (indexed from 1) whose cube ends in 888. Input The first line of the input contains an integer t , the number of test cases. t test cases follow. (1 <= t <= 100000) Each test case consists of a single line containing a single integer k (1 <= k <= 2000000000000). Output For each test case, output a single integer which denotes the k th number whose cube ends in 888. The result will be less than 2 63 . Example Input: 1 1 Output: 192
35,024
Loan for bike (LFBKE) Noyon wants to buy a Motor Bike, but he needs a loan as he is hard up. So, he went to two banks for loan. The first bank lends imposing simple interest while the second one imposes compound interest. Noyon collects the rate of interest of the banks. But he is weak in math. Given the rates of interest, loan amount and years due, help him finding the bank with lowest interest amount. Input The first line contains a number t (t <= 1000) the number of test cases. The next t lines contains numbers p, y, r1, r2 (1 <= p <= 1000000000, 1 <= y <= 50, 3% <= r1, r2 <= 50%) where p denotes the loan amount and y denotes the years due, r1 denotes the rate of interest of first bank and r2 denotes the second. Output Print n lines. Each line containing “Bank 1” if interest amount is lowest for bank 1, “Bank 2” for bank 2. Print “Confused huh!” if the interest amount is the same. (Without quotes) for each test case. Example Input: 4 10000 5 10 15 2000 4 3 5 100 3 5 4 12345 3 9 7 Output: Bank 1 Bank 1 Bank 2 Bank 2
35,025
Vải Lục Ngạn (VLN) Nhân dịp đến quê hương Bắc Giang tham gia thi chọn học sinh giỏi Trại hè Hùng Vương, Hà đến thăm trang trại trồng vải thiều của bác Thuấn. Trang trại gồm n cây thẳng hàng và cách đều nhau (khoảng cách từ gốc cây i đến gốc cây i+1 là 3 mét với mọi i = 1, 2, 3, ..., n-1). Năm nay là năm được mùa nên cây nào cũng sai quả, cây thứ i có số lượng quả vải là a i  quả. Bác Thuấn rất lo lắng vì tuổi già rồi làm sao có thể hái được hết số vải thiều này, Hà đang nghĩ cách giúp bác Thuấn thì đột nhiên có một ông tiên hiện ra trước mắt Hà và nói: “Ta cho cháu một chiếc túi thần, cháu hãy chọn một chỗ đứng ở một gốc cây trong n cây rồi hô to câu thần chú [ Vải ơi chui vào đây ], khi đó tất cả quả ở các cây có khoảng cách tính từ gốc đến chỗ cháu đứng không vượt quá H sẽ từ từ rời khỏi cành và bay vào túi thần này.” Yêu cầu Hãy cho biết Hà có thể thu hoạch giúp bác Thuấn được tối đa bao nhiêu quả vải nếu lời nói của ông tiên là hiện thực. Input Đầu vào có dạng Dòng đầu chứa hai số nguyên dương n, H (n ≤ 100; H ≤ 10 9 ) Dòng thứ hai chứa n số nguyên a 1  , a 2  , . . ., a n trong đó a i  (a i  ≤ 10 9  ; i = 1, 2, 3, . . ., n) là số lượng quả của cây vải thứ i. Hai số liên tiếp trên cùng dòng được ghi cách nhau bởi dấu cách. Output Gồm một số nguyên duy nhất là tổng số lượng quả vải nhiều nhất mà Hà có thể thu hoạch giúp bác Thuấn. Ví dụ Input: 5 3 1 2 2 2 1 Output: 6
35,026
Tavas and Nafas (G10_2) Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas. His phone operating system is Tavdroid, and its keyboard doesn't have any digits! He wants to share his score with Nafas via text, so he has no choice but to send this number using words. He ate coffee mix without water again, so right now he's really messed up and can't think. Your task is to help him by telling him what to type. Input The first and only line of input contains an integer s (0 ≤ s ≤ 99), Tavas's score. Output In the first and only line of output, print a single string consisting only from English lowercase letters and hyphens ('-'). Do not use spaces. Example Input: 6 Output: six Input: 99 Output: ninety-nine Input: 20 Output: twenty Cardinal Numbers Cardinal numbers refer to the size of a group. In English, these words are numerals . 0   zero (nought) 10   ten 1   one 11   eleven 2   two 12   twelve (a dozen ) 20   twenty (a score) 3   three 13   thirteen 30   thirty 4   four 14   fourteen 40   forty (no "u") 5   five 15   fifteen (note "f", not "v") 50   fifty (note "f", not "v") 6   six 16   sixteen 60   sixty 7   seven 17   seventeen 70   seventy 8   eight 18   eighteen (only one "t") 80   eighty (only one "t") 9   nine 19   nineteen 90   ninety (note the "e") If a number is in the range 21 to 99, and the second digit is not zero, one typically writes the number as two words separated by a hyphen . 21   twenty-one 25   twenty-five 32   thirty-two 58   fifty-eight 64   sixty-four 79   seventy-nine 83   eighty-three 99   ninety-nine
35,027
KNIGHT MOVES (G11_2) A friend of you is doing research on the Traveling Knight Problem (TKP) where you are to find the shortest closed tour of knight moves that visits each square of a given set of n squares on a chessboard exactly once. He thinks that the most difficult part of the problem is determining the smallest number of knight moves between two given squares and that, once you have accomplished this, finding the tour would be easy. Of course you know that it is vice versa. So you offer him to write a program that solves the "difficult" part. Your job is to write a program that takes two squares A and B as input and then determines the number of knight moves on a shortest route from a to b. Input The input will contain one or more test cases. Each test case consists of one line containing two squares separated by one space. A square is a string consisting of a letter (a-h) representing the column and a digit (1-8) representing the row on the chessboard. Output For each test case, print one line saying "To get from xx to yy takes n knight moves.". Example Input: e2 e4 a1 b2 b2 c3 a1 h8 a1 h7 h8 a1 b1 c3 f6 f6 Output: To get from e2 to e4 takes 2 knight moves. To get from a1 to b2 takes 4 knight moves. To get from b2 to c3 takes 2 knight moves. To get from a1 to h8 takes 6 knight moves. To get from a1 to h7 takes 5 knight moves. To get from h8 to a1 takes 6 knight moves. To get from b1 to c3 takes 1 knight moves. To get from f6 to f6 takes 0 knight moves.
35,028
DIGITS COUNT (G11_4) Diana is going to write a list of all positive integers between A and B, inclusive, in base 10 and without any leading zeros. She wants to know how many times each digit is going to be used. Input Each test case is given in a single line that contains two integers A and B (1 ≤ A ≤ B ≤ 10 8 ). The last test case is followed by a line containing two zeros. Output For each test case output a single line with 10 integers representing the number of times each digit is used when writing all integers between A and B, inclusive, in base 10 and without leading zeros. Write the counter for each digit in increasing order from 0 to 9. Example Input: 1 9 12 321 5987 6123 12345678 12345679 0 0 Output 0 1 1 1 1 1 1 1 1 1 61 169 163 83 61 61 61 61 61 61 134 58 28 24 23 36 147 24 27 47 0 2 2 2 2 2 2 2 1 1
35,029
First N Positive Number (FUCT_FOR_FNPN) Writing a program that output first n positive number. For example: n = 9 => Print out: 1 2 3 4 5 6 7 8 9 Input The first line of the input consist of a single integer number t which determines the number of tests. In each of next t lines there is a single integer number n . Constraints 0 < t ≤ 1 000 0 < n ≤ 1 000 000 Output For each number n print out the result list. Separate your answers with a new line character. Example Input: 4 5 8 1 0 Output: 1 2 3 4 5 1 2 3 4 5 6 7 8 1 invalid
35,030
CONGHAISOLON (SLSL) Calculate the sum of two integers A and B (1 <= A, B <= 10 1000000 ) Input A and B are separated by space. Output Sum of two numbers A and B. Example Input: 5 08 Output: 13 Nhập vào hai số nguyên A và B (1 <= A, B <= 10 1000000 ) Input a và b cách nhau bởi dấu cách Output Tổng của hai số a và b Ví dụ Input: 5 08 Output: 13
35,031
Connected country (CONGRAPH) After a strong earthquake many roads of the ancient country GRAPH were destroyed. The country is divided into disconnected areas so that from one area city it is impossible to reach another area city. Pharaoh wants to restore the road infrastructure and connect all the cities. He asks the great Thoth to find the minimum number of roads needed for this. Input The first line of input will contain two space separated integer numbers: 0 < N ≤ 800000 , number of cities and 0 < M < 4000000 , number of roads. Follow M lines. Each line represents cities (numbering is zero based) connected by road. All roads are bidirectional. Output One integer number. Answer of the Thoth Example Input: 6 6 0 1 0 2 1 2 3 4 3 5 4 5 Output: 1 Explanation One road from the city number 1 to the city number 4 makes GRAPH connected.
35,032
My Head (MYHEAD) Atik is now a Class - I student. You can trust all other person stated below except Atik . One day he is blabbering " The meaning of 'My Head' is 'Sir er Matha'. " When his Father heard this he said " No. This is wrong. You have to say "The meaning of 'My Head' is 'Amar Matha'. Ok? ". Then Atik started blabbering " The meaning of 'My Head' is 'Babar Matha' " again and again. When his Mother heard this she said " No. This is wrong. You have to say 'The meaning of 'My Head' is 'Amar Matha'. Ok? " Then Atik started blabbering "The meaning of 'My Head' is "Ma er Matha" again and again. When his Sister heard this she said No. This is wrong. You have to say "The meaning of 'My Head' is 'Amar Matha'. Ok? " Then he started blabbering " The meaning of 'My Head' is 'Apur Matha' again and again. When his Grandfather heard this he said " No. This is wrong. You have to say "The meaning of 'My Head' is 'Amar Matha'. Ok? " Atik is getting too much confused and started to say " The meaning of 'My Head' is 'Amar Chouddo Purusher Matha' . Your task is so simple. You just have to print out what is the correct answer for " My Head? " Input No Input Output Just print the correct answer of the string " My Head ". Example Input: There is no sample input. Output: Babar Matha Hint 1 : Read the problem statement carefully. The result will be in the problem. . [ Sample output is incorrect. If you copy, paste and submit this answer then you will get a result of "WRONG ANSWER" ]
35,033
Violet and Her Dream Land (TSMIVIOLET) Violet is a little girl who has a dream world where everything works as per as she wants them to be. She always tries to live in her dream world. Her dream world is very unique where she resembles everything in a different way such as she would call the sun as egg yoke (as she is a food lover), park as pasta, and so on.. One day she decided to give some unique names to all the days in a week such as she would call Saturday as Sandwich, Sunday as Soup, Monday as Macaroon, Tuesday as Toffee, Wednesday as Waffles, Thursday as Taco and Friday as French Fries. She is facing trouble as she decided to give unique name for everything. She wants your help so that you can remind her the names of the days in a week. Whenever she says a day you have to tell her the unique name she has chosen for it. Input input contains string S, a day name. Output Print the corresponding unique name for the day as Violet decided. Example Input: Wednesday Output: Waffles
35,034
Simplify IT (SIMPLFYIT) Nowadays computer can do a lot of things, can't it? But how? Yes, you are the answer. The biggest secret behind capability of the computer is some programmer like you. They wrote some programs and computer only follow these. That's it. Anyway, your task is to write some program that will be followed by the computer to simplify an algebraic expression. The initial expression is 0. There will be 3 types of command. These are: 1 <expression> 2 <expression> 3 For command-type 1, you have to add <expression> to the existing expression. For command-type 2, you have to subtract <expression> from the existing expression. For command-type 3, you have to print the existing expression. For simplicity the <expression> will contain 2 variables, such as 'a' and 'b'. and the <expression> will be in the following format: CaPbQ where 'C' is a constant, 'a' and 'b' are variable and 'P' and 'Q' are the power of 'a' and 'b' respectively. Input The first line will contain an integer T which denotes the number of test cases. For T cases, there will be a number N which denotes the number of command for this case. Then the following N lines contain commands for the case mentioned above. The absolute value of 'C', 'P' and 'Q' is less than or equal to 10. T and N will be a positive integer less than or equal to 101. Output For each command type 3, print the current expression. Print the part first which has the lower power of 'a'. If the power of 'a' is equal then print the part first which has the lower power of 'b'. Example Input: 1 11 3 1 2a1b1 3 1 1a2b0 3 2 1a0b2 3 2 1a5b1 3 1 1a2b0 3 Output: 0 2ab 2ab+a2 -b2+2ab+a2 -b2+2ab+a2-a5b -b2+2ab+2a2-a5b Note: In "-b2+2ab+2a2-a5b", 1st part has 'a' with power 0, 2nd part has 'a' with power 1, 3rd part has 'a' with power 2, 4th part has 'a' with power 5.
35,035
A Simple Problem (SIMPLPRBLM) Given an array of integers A[] and a number S, find the number of pairs of integers in the array whose sum is equal to S. Input Input starts with an integer T (1 ≤ T ≤ 50), denoting the number of test cases. Each case starts with a line containing two integers n (1 ≤ n ≤ 10 5 ) and S (1 ≤ S ≤ 10 10 ). The next line contains n integers, denoting A1, A2 ... An (1 ≤ Ai ≤ 10 9 ). Output For each case, print the case number and the number of ways S can be made. Be careful as the result can be a large number. Example Input: 3 4 8 1 2 4 9 3 7 3 4 4 3 8 4 4 4 Output: Case 1: 0 Case 2: 2 Case 3: 3
35,036
Cheating!! (CHTCHTCHEAT) Let's read a popular Story. Once upon a time there lived, a lazy boy whose name was Som. In olden days in a test paper of any language there used to be one question, which was "write an essay on topic 'xyz'". Now this 'xyz' could be any thing.That was to test the vocabulary and general knowledge of the students. Since our Som was a lazy boy, he decided to write only one essay. The essay of a cow.That would read as follows: "Cow is a domesticated animal. She helps mankind in many ways. Her milk is very healthy for babies. Cows usually eat green grass but they can survive on other things too. Blah blah blah." So he would read the test paper. If the essay is about 'train' he would write as follows: "A train is a form of rail transport consisting of many compartments. When we sit beside a window in a train, we can see many cows grazing in the fields. Cow is a domesticated animal. She helps mankind in many ways..." If the essay is about 'Gandhi' he would write "Gandhi was an Indian leader. He loved cows. Cow is a domesticated animal. She helps mankind in many ways..." If the essay is about a cat, he would write. "Cat drinks milk. The milk comes from a cow. Cow is a domesticated animal. She helps mankind in many ways..." So he has this knack of converting any essay into 'essay of a cow'. After reading this popular story, nowadays many students are following this great technique and it becomes a problem for a teacher to detect the cheating. So, your task is just write a program to detect this cheating. Input The first line will contain an integer T (0 < T < 50) which denotes the number of test cases. For T cases, there will be a string S (lowercase string with fewer than 25 characters) which denotes the name of the essay. Then in the next line there will be an integer N (N < 100) which denotes the number of lines of the essay. Then there will be N number of lines. In each line, A sentence will be given (each sentence length is less than 100). Output For each input, if you find any sentence comes from the given cow's essay then print "Cheating" else "Not cheating". But if the essay is about cow then it is okay to use sentences from the cow's essay, in that case print "Not cheating".  Example Input: 3 cow 3 Cow is a domesticated animal. She helps mankind in many ways. Her milk is very healthy for babies. gandhi 3 Gandhi was an Indian leader. He loved cows. Cow is a domesticated animal. cat 4 Cat drinks milk. The milk comes from a cow. Cats are familiar and easily kept animals Cats can hear sounds too faint or too high. Output: Not cheating Cheating Not cheating
35,037
Prime Names (TRCSTRPR) Mina and Raju are playing a game. They will provide a list which contains a name and a number to each other. They have to add the number to the ASCII values of the names character. Then they have to check that if any of the new added number is prime or not. If for any character of the name the added number is prime then the name will be considered as prime name. Can you help Mina and Raju to find the prime name? Example: Suppose the list contains two names Mina and Raju. The list will be as following: Mina 20 Raju 34 For the first name ASCII values are: 77 105 110 97. After addition the values will be: 97 125 130 117. As 97 is prime number so Mina is a Prime Name. Input First line of input will be the size of the list L (L < 100). Next L line contains S (name) and N (number) pairs separated by space. Name is a string with less than 20 characters. The number will be less than 10000. Output For every name print “YES” if it is prime name, else print “NO”. Example Input: 2 Mina 20 Shimul 60 Output: YES NO
35,038
(HSTRYGV)
35,039
(HSTRYIST)
35,040
(SAWAE)
35,041
Infinity Problem (COUINF) Being in a society it’s my duty to contribute a problem dedicated to Avengers. So this problem is about “The Avengers” . Avengers are MCU heroes who are the owners of some great power. It’s been said that “With great power comes great responsibility”. You are the new member of MCU and the rightful owner of “Respect Stone”. Now it’s your duty to show respect to the MCU heroes. To show respect you just have to write a program that will print the line “ Thank You, Avengers” as its output. Input There will be no input. Output Just one line containing the sentence Thank You, Avengers. Example Input: No Input Output: Thank You, Avengers [ Original Setter of this Problem: Avik Sarkar, CoU ]
35,042
Total Odd V1 (DHRODD) There are two integers L and R , you'll have to count how many odd numbers are there within the range from L to R inclusive. All of you know what is an odd number. A number that is not divisible by 2 is called an odd number. Input The only line contain two integers L, R . Constraints 0 <= L <= R <= 100000000 Output Print the count of odd numbers from L to R inclusive. Example Input: 2 3 Output: 1 [ Original Setter of this Problem Dhruba Mitra, RUET ]
35,043
Total Odd V2 (DHRODDMX) There are two integers L and R, you'll have to count how many odd numbers are there within the range from L to R inclusive. All of you know what is an odd number. An integer that is not divisible by 2 is called an odd number. Input The first line will be a single integer T which denotes the test cases. Next T lines will contain L and R . Constraints 1 <= T <= 10 1 <= L <= R <= 1000000000000000000 Output For each case, print the count of odd numbers from L to R inclusive. Example Input: 3 1 1 1 3 2 3 Output: 1 2 1 [ Original Setter of this problem is Dhruba Mitra, RUET ]
35,044
PKP Knows Nothing 2 (TAMADOM) "You know nothing, PKP Snow" PKP Snow is tired of hearing this. Now he wants to prove that he does know something! He has N distinct dragonglass knives in front of him. He needs to choose R knives out of these. Everyone thinks PKP doesn't know how many ways he can choose R knives out of N . Help PKP finding the answer and thus prove them wrong. But the answer can be very big, so PKP will tell the answer modulo M . Given N , R , M , your job is to find the answer for PKP. Input Input starts with an integer T , denoting the number of test cases. Then each of next T lines contains three integers N , R and M . Constraints 1 <= T <= 100 1 <= N <= 100000 0 <= R <= 100000 1 <= M <= 1000000000000 Output For each test case, print the answer PKP has to find, number of ways to choose R knives out of N modulo M. Print each answer in separate lines like in sample output. Example Input: 5 5 3 100 5 3 2 5 3 7 1 1 20 100 50 1000000009 Output: 10 0 3 1 933591892 Explanation PKP can choose 3 knives out of 5 knives in 10 ways. 10 modulo 100 is 10, while 10 modulo 7 is 3. A modulo B means the remainder found after dividing A by B. [Original Setter of this problem is Tahsin Masrur, RUET ]
35,045
Check number (FUCT_IF_CHECKNUM) Enter a integer then check whether it is positive or negative. Input The first line of the input consist of a single integer number  t  which determines the number of tests. In each of next  t  lines there is a single integer  n . Constraints 0 < t ≤ 1 000 - 1 000 000 ≤ n ≤ 1 000 000 Output For each number n print out the result in format " is positive integer" or " is negative integer" or "n is zero". Separate your answers with a new line character. Example Input: 5 -7 9 0 4 -3 Output: -7 is negative number 9 is positive number n is zero 4 is positive number -3 is negative number
35,046
Square root (FUCT_IF_SQRT) Calculate the square root of a number, or determine that the square root doesn't exist. Input The first line of the input consist of a single integer number  t  which determines the number of tests. In each of next  t  lines there is a single number   n . Constraints 0 < t ≤ 1 000 0 ≤ n ≤ 1 000 000 Output For each number n print out the square root of n . Do not print trailing zeros, or the decimal point if there are no decimal places printed. See examples for clarification. Separate your answers with a new line character. Example Input: 7 4 7 0 2 -9 1 -3 Output: 2 2.645751 0 1.414214 invalid 1 invalid
35,047
Divide (FUCT_IF_DIVIDE) Enter two numbers m and n then calculate the value m  / n , where m is the numerator and n is the denominator. Input The first line of the input consist of a single integer number t which determines the number of tests. In each of next t lines there are two number m and n that are separated by a space character. Constraints 0 < t ≤ 1 000 Output For each test case print out the result of division. Do not print trailing zeros, or the decimal point if there are no decimal places printed. See examples for clarification. Separate your answers with a new line character. Example Input: 7 5 2 -15 -5 8 4 50 0 7 3 -6 2 18 -3 Output: 2.5 3 2 denominator cannot be zero 2.333333 -3 -6
35,048
Compare two numbers (FUCT_IF_COMPARE) Enter two integers then compare their values. Input The first line of the input consist of a single integer number t which determines the number of tests. In each of next t lines there are two number m and n that are separated by a space character. Constraints 0 < t ≤ 1 000 - 1 000 000 ≤ n, m ≤ 1 000 000 Output For each test case print out the result in format "<m> is greater than <n>" or "<m> is smaller than <n>" or "n is equal m: <n>". Separate your answers with a new line character. Example Input: 5 9 2 -3 -5 5 28 0 0 19 13 Output: 9 is greater than 2 -3 is greater than -5 5 is smaller than 28 n is equal m: 0 19 is greater than 13
35,049
Geometric square (FUCT_IF_SQUARE) Enter the edge of the square. Calculate the perimeter and area of the square. Input The first line of the input consist of a single integer number t which determines the number of tests. In each of next t lines will contain the value of square's edge. Constraints 0 < t ≤ 1 000 Output For each test case print out perimeter and area that separated by a space. Separate your answers with a new line character. Example Input: 7 0 1 -2 3 12 -3 20 Output: the length of square's edge must be greater than 0 4 1 the length of square's edge must be greater than 0 12 9 48 144 the length of square's edge must be greater than 0 80 400
35,050
Geometric rectangular (FUCT_IF_RECT) Enter the two edges of the rectangular that named a and b. Calculate the  perimeter  and  area  of the rectangular. Input The first line of the input consist of a single integer number  t  which determines the number of tests. In each of next  t  lines will contain two edges  a and b  that separated by a space. Constraints 0 < t ≤ 1 000 Output For each test case print out  perimeter  and  area  that separated by a space. Separate your answers with a new line character. Example Input: 7 0 9 2 5 1 -5 10 7 9 4 -9 4 12 20 Output: the length of rectangular's edges must be greater than 0 14 10 the length of rectangular's edges must be greater than 0 34 70 26 36 the length of rectangular's edges must be greater than 0 64 240
35,051
Geometric triangular (FUCT_IF_TRI) Enter the three edges of the triangular that named a and b and c. Calculate the  perimeter  and  area  of the triangular. Input The first line of the input consist of a single integer number  t  which determines the number of tests. In each of next  t  lines will contain three edges  a and b  and c that separated by a space. Constraints 0 < t ≤ 1 000 Output For each test case print out  perimeter  and  area  that separated by a space. Separate your answers with a new line character. Example Input: 7 0 5 -2 2 3 4 9 1 10 3 6 5 -9 2 4 8 4 1 15 27 20 Output: the length of triangular's edge must be greater than 0 9 2.905 three numbers a and b and c cannot make a triangular 14 7.483 the length of triangular's edge must be greater than 0 three numbers a and b and c cannot make a triangular 62 147.729
35,052
Geometric circle (FUCT_IF_CIRCLE) Enter the radius of the circle. Calculate the perimeter and area of the circle. Input The first line of the input consist of a single integer number t which determines the number of tests. In each of next t lines will contain the value of radius. Constraints 0 < t ≤ 1 000 Output For each test case print out perimeter and area that separated by a space. Separate your answers with a new line character. Example Input: 5 5 -2 1 0 4 Output: 31.415927 78.539816 the radius must be greater than 0 6.283185 3.141593 the radius must be greater than 0 25.132741 50.265482
35,053
Geometric cylinder (FUCT_IF_CYLINDER) Enter the radius and the height of the cylinder that named r and h . Calculate the  volume  and  total surface area  of the cylinder. Input The first line of the input consist of a single integer number  t  which determines the number of tests. In each of next  t  lines will contain the radius r and the height h  that separated by a space. Constraints 0 < t ≤ 1 000 Output For each test case print out  volume  and  total surface area  that separated by a space. Separate your answers with a new line character. Example Input: 5 1 1 8 -2 4 10 0 7 12 18 Output: 3.14 12.56 the height of cylinder must be greater than 0 502.40 351.68 the radius of cylinder must be greater than 0 8138.88 2260.80
35,054
Sharmeen Loves Mozahid Loves Sharmeen [ EASY ] (MOZSLM) Mozahid and Sharmeen loves each other and spend a lots of time together. One day they found a string which contains only lowercase English letters. As Mozahid loves Sharmeen very much he likes all ‘s’ in the string. On the other hand as Sharmeen loves Mozahid very much she likes all the ‘m’ in the string. Sharmeen always want to stay on both sides (left and right) of Mozahid so that no other girl can take him away from her :P. So, this time Mozahid gives her a task. Mozahid told her, if she can tell him how many different subsequence of ‘ sms ’ exist in that string, he will ensure her that no girl will take him away from her. As Sharmeen is not a programmer, she needs your help to perform this task. Can you do this for her? Input In the first line given an integer T (1 <= T <= 10), the number of test cases. In each test case given a string S of size N (1 <= N <= 100) of lowercase English letters. Output For each test case print the number of different subsequence of ‘sms’ exist on that string in one line. For clearance ‘skmjssm’ has 2 different subsequence of ‘sms’.  {1, 3, 5} and {1, 3, 6} ( 1 based position ). For better understanding see the sample input output. Example Input: 2 asdfmnsmdsms ssmssmjm Output: 10 4 [ This problem originally written by MD. Mozahidul Islam Bhuiyan(kissu_pari_na) ]
35,055
Sharmeen Loves Mozahid Loves Sharmeen [ Medium ] (MOZMSLM) Mozahid and Sharmeen loves each other and spend a lots of time together. One day they found a string which contains only lowercase English letters. As Mozahid loves Sharmeen very much he likes all ‘s’ in the string. On the other hand as Sharmeen loves Mozahid very much she likes all the ‘m’ in the string. Sharmeen always want to stay on both sides (left and right) of Mozahid so that no other girl can take him away from her :P. So, this time Mozahid gives her a task. Mozahid told her, if she can tell him how many different subsequence of ‘ sms ’ exist in that string, he will ensure her that no girl will take him away from her. As Sharmeen is not a programmer, she needs your help to perform this task. Can you do this for her? Input In the first line given an integer T (1 <= T <= 2), the number of test cases. In each test case given a string S of size N (1 <= N <= 7000) of lowercase English letters. Output For each test case print the number of different subsequence of ‘sms’ exist on that string in one line. For clearance ‘skmjssm’ has 2 different subsequence of ‘sms’. {1, 3, 5} and {1, 3, 6} (1 based position). For better understanding see the sample input output. Example Input: 2 asdfmnsmdsms ssmssmjm Output: 10 4 [ This problem originally written by MD. Mozahidul Islam Bhuiyan (kissu_pari_na) ]
35,056
Can Sharmeen Solve it? [ Medium ] (MOZMCAN) Somehow Sharmeen solved the last problem “ Sharmeen loves substring ” and Mozahid became impressed on her performance. Now Mozahid wants to test her programming skill and gives her the hardest problem of today’s problem set. He will give her a string of lowercase English letters of size N and an integer X. Sharmeen has to find the largest substring of that string, which has exactly X subsequences of ‘ sms ’. If multiple solution exists, she has to select the left-most one. If no solution exist she has to print “-1” (without quotes); otherwise, she has to print the starting and ending position of the substring separated by a space in one line. For exact output format, see the example. N.B. Substring is a consecutive sequence of characters of a string, whereas subsequence does not necessarily need to be consecutive. But for both, you have to maintain the order. For clearance, ‘skmjssm’ has 2 different subsequence of ‘sms’, {1, 3, 5} and {1, 3, 6} (1 based position). Input In first line given test case T (1 <= T <= 10). For each test case, a string of lowercase English letters of size N (1 <= N <= 1000) and an integer X (0 <= X <= 10^8) are given, separated by a space. Output For each test case, if solution exists print the starting and ending position of the substring ( 1 based position ) separated by a space, otherwise, print “-1” (without quote) in one line. Example Input: 2 smsmmsms 1 mmsm 1 Output: 1 5 -1 [ This problem originally written by MD. Mozahidul Islam Bhuiyan (kissu_pari_na) ]
35,057
Sharmeen Loves Substring [ EASY ] (MOZESLS) After solving the problem “ MOZHSLM ” Sharmeen become familiar with subsequence and somehow become interested in substring. Instead of learning more about substring she started asking some ludicrous questions to Mozahid about substring. Become tired of answering Sharmeen’s ludicrous questions Mozahid gives Sharmeen another problem which is slightly harder than the previous one. Mozahid will give Sharmeen a string of lowercase English letters and some queries. In each query he will give her a substring of that string. Sharmeen has to answer how many different subsequence of ‘ sms ’ exists in that substring. Can you help Sharmeen solving this problem? Input Given a string of lowercase English letters of length N (1 <= N <= 100) in first line. In the second line given an integer Q (1 <= Q <= 50), which is the number of queries. In each query you will be given two integer L, R (1 <= L <= R <= N). L is the starting position of the substring and R is the ending position of the substring (1 based position). Output For each query you have to output an integer in one line which is the number of different subsequence of ‘sms’ in that substring. N.B. Substring is a consecutive sequence of characters of a string. Where subsequence not necessarily need to be consecutive. But for both you have to maintain the order. For clearance ‘skmjssm’ has 2 different subsequence of ‘sms’. {1, 3, 5} and {1, 3, 6} (1 based position). For better understanding see the sample input output. Example Input: sasmasamsas 3 1 6 3 9 8 11 Output: 2 4 0 [ This problem originally written by MD. Mozahidul Islam Bhuiyan (kissu_pari_na) ]
35,058
Sharmeen Loves Substring [ Medium ] (MOZMSLS) After solving the problem “ MOZHSLM ” Sharmeen become familiar with subsequence and somehow become interested in substring. Instead of learning more about substring she started asking some ludicrous questions to Mozahid about substring. Become tired of answering Sharmeen’s ludicrous questions Mozahid gives Sharmeen another problem which is slightly harder than the previous one. Mozahid will give Sharmeen a string of lowercase English letters and some queries. In each query he will give her a substring of that string. Sharmeen has to answer how many different subsequence of ‘ sms ’ exists in that substring. Can you help Sharmeen solving this problem? Input Given a string of lowercase English letters of length N (1 <= N <= 10^5) in first line. In the second line given an integer Q (1 <= Q <= 500), which is the number of queries. In each query you will be given two integer L, R (1 <= L <= R <= N). L is the starting position of the substring and R is the ending position of the substring (1 based position). Output For each query you have to output an integer in one line which is the number of different subsequence of ‘sms’ in that substring. N.B. Substring is a consecutive sequence of characters of a string. Where subsequence not necessarily need to be consecutive. But for both you have to maintain the order. For clearance ‘skmjssm’ has 2 different subsequence of ‘sms’. {1, 3, 5} and {1, 3, 6} (1 based position). For better understanding see the sample input output. Example Input: sasmasamsas 3 1 6 3 9 8 11 Output: 2 4 0 [ This problem originally written by MD. Mozahidul Islam Bhuiyan (kissu_pari_na) ]
35,059
Team formation (MMFTEAM) Coach has n players. A team is a subset of players and has at least two players - a captain and a keeper. How many ways can a coach form a team from n players? Input Each line of input contains one random integer number 2 ≤ n ≤ 10 6  (1 000 000) . Input terminates with 0 (zero). Output For each n print your answer modulo 1 000 000 007 on new line. Example Input: 2 3 0 Output: 2 12 22/06/2019 - Time limit increased.
35,060
Big team formation (MMFBTEAM) Coach has n players. A team is a subset of players and has at least two players - a captain and a keeper. How many ways can a coach form a team from n players? Input Each line of input contains one random integer number 2 ≤ n ≤ 10 30 . Input terminates with 0 (zero). Output For each n print your answer modulo 1 000 000 007 on new line. Example Input: 2 3 0 Output: 2 12
35,061
Second to time hh_mm_ss (FUCT_IF_SEC2TIME) Enter any positive integer that describes total second. You must convert the total second into time in format "hh:mm:ss" . Input Contain total second. Output Print out time in format "hh:mm:ss" . Example Input 1: 1986 Output 1: 00:33:06 Input 2: -5 Output 2: total second must be a positive integer
35,062
Palindrome number (FUCT_FOR_PALIN) Enter a positive number n . Is it a palindrome number? Input The first line of the input consist of a single integer number  t  which determines the number of tests. In each of next  t  lines there is a single number n . Constraints 0 < t ≤ 1 000 0 ≤ n < 1 000 000 000 Output For each number n print out "YES" if n is palindrome number. Otherwise print out "NO". Separate your answers with a new line character. Note: ignore trailing zeros when determining whether n is a palindrome. Example Input: 8 19523 233332 859 11 819918000 10100 5252 23432 Output: NO YES NO YES YES YES NO YES
35,063
Right arrow (FUCT_FOR_ARROW) Enter any positive integer that describes the height of arrow. Print out the right arrow. Example The right arrow that has 5 rows is: * * * * * * * * * * * * * * * * Input Contain the height of right arrow. Constraints 2 < n ≤ 100 Output Print out the right arrow. Example Input 1: 5 Output 1: * * * * * * * * * * * * * * * * Input 2: 2 Output 2: accept positive integer greater than 2 only!
35,064
Reduced fraction (FUCT_FOR_REFRAC) Enter the numerator and denominator of a fraction. Reduce that fraction. Input The first line of the input consist of a single integer number  t  which determines the number of tests. In each of next  t  lines will contain numerator and denominator of the fraction that separated by a space. Constraints 0 < t ≤ 1 000 Output For each test case print out the numerator and denominator of the reduced fraction that separated by a space. Separate your answers with a new line character. Example Input: 8 -8 16 1 9 8 10 -3 0 150 200 -9 -12 27 9 45 -50 Output: -1 2 1 9 4 5 the denominator can not be zero 3 4 3 4 3 -9 10
35,065
Inverted pyramid (FUCT_FOR_INVPYRA) Enter any positive integer that describes the height of inverted pyramid. Print out the inverted pyramid. Example The inverted pyramid that has 5 rows is: * * * * * * * * * * * * * * * * * * * * * * * * * Input Contain the height of inverted pyramid. Constraints 0 < n ≤ 1 00 Output Print out the inverted pyramid. Example Input 1: 5 Output 1: * * * * * * * * * * * * * * * * * * * * * * * * * Input 2: 2 Output 2: * * * *
35,066
Rhombus (FUCT_FOR_RHOMBUS) Enter the length of rhombus's side. Print out the rhombus. Example Even if the side of the rhombus is 3, the form of rhombus is as below: * * * * * * * * Input Contain the side of rhombus. Constraints 0 < n ≤ 1 00 Output Print out the rhombus. Example Input: 3 Output: * * * * * * * *
35,067
Date validation (FUCT_IF_CHKDATE) Enter an unchecked date then check whether it is valid date. Input The first line of the input consist of a single integer number  t  which determines the number of tests. In each of next  t  lines there is three numbers are month and day and year that separated by a space. Constraints 0 < t ≤ 1 000 Output For each number n print out the checking status is "VALID" for valid date or INVALID for invalid date. Separate your answers with a new line character. Example Input: 7 9 8 2018 3 39 2000 2 29 2018 20 -4 1998 2 29 2000 7 31 1986 11 31 2002 Output: VALID INVALID INVALID INVALID VALID VALID INVALID
35,068
Fat number (FUCT_FOR_FATNUM) A fat number is a number that the sum of its digits is equal with the multiple of its digits. Example: 321 and 123 and 213 are fat number because 3 + 2 + 1 = 3 * 2 * 1. Your mission is finding all fat number between a and b inclusive. Input The first line of the input consist of a single integer number  t  which determines the number of tests. In each of next  t  lines there is two number a and b separated by a space. Constraints 0 < t ≤ 1 000 0 ≤ a, b ≤ 10 000 000 Output For each test case print out all fat number found inside the range which separated by a space. Separate your answers with a new line character. Example Input: 2 8 15 2000 1 Output: 8 9 1 2 3 4 5 6 7 8 9 22 123 132 213 231 312 321 1124 1142 1214 1241 1412 1421
35,069
Number triangular (FUCT_FOR_TRINUM) Enter any positive integer that describes the height of number triangular. Print out the number triangular. Example The number triangular that has 5 rows is: 1 2 1 3 2 1 4 3 2 1 5 4 3 2 1 Input Contain the height of number triangular. Constraints 0 < n ≤ 1 00 Output Print out the number triangular. Example Input 1: 5 Output 1: 1 2 1 3 2 1 4 3 2 1 5 4 3 2 1 Input 2: 2 Output 2: 1 2 1
35,070
Star pyramid (FUCT_FOR_PYRAMID) Enter any positive integer that describes the height of star pyramid. Print out the star pyramid. Example The star pyramid that has 5 rows is: * * * * * * * * * * * * * * * * * * * * * * * * * Input Contain the height of star pyramid. Constraints 0 < n ≤ 1 00 Output Print out the star pyramid. Example Input 1: 5 Output 1: * * * * * * * * * * * * * * * * * * * * * * * * * Input 2: 2 Output 2: * * * *
35,071
Factorial formula (FUCT_FOR_FACFOR) Enter the positive integer n . Calculate and print out n ! step by step. Input The first line of the input consist of a single integer number t which determines the number of tests. In each of next t lines will contain only one positive integer n . Constraints 0 < t ≤ 1 000 Output For each test case print out n ! step by step. Example Input: 5 0 5 9 -3 1 Output: 0!=1 5!=1*2*3*4*5=120 9!=1*2*3*4*5*6*7*8*9=362880 accept positive integer only! 1!=1
35,072
Sum 2 digits (FUCT_FOR_SUM2DIG) Enter a positive number n . Find out all 2-digit number whose sum of 2 digits is equal to n. Input Contain a single number n . Constraints 1 ≤ n ≤ 18 Output Print out all 2-digit numbers whose sum of 2 digits is equal to n. Each solution in one line. If it doesn't have any solution, print out "NO". Example 1 Input: 8 Output: 17 = 1 + 7 = 8 26 = 2 + 6 = 8 35 = 3 + 5 = 8 44 = 4 + 4 = 8 53 = 5 + 3 = 8 62 = 6 + 2 = 8 71 = 7 + 1 = 8 80 = 8 + 0 = 8
35,073
Exponentiation (FUCT_FOR_EXPONEN) Enter the base x and the exponent n . Calculate and print out x n . Input The first line of the input consist of a single integer number  t  which determines the number of tests. In each of next  t  lines will contain x and n  separated by a space. Constraints 0 < t ≤ 1 000 Output For each test case print out x n . Separate your answers with a new line character. Example Input: 5 1 7 2 4 0 9 -3 3 5 -2 Output: 1 16 0 -27 0.040000
35,074
List prime number (FUCT_FOR_PRIME) Find all prime number between a and b inclusive. Input The first line of the input consist of a single integer number  t  which determines the number of tests. In each of next  t  lines there are two numbers a and b separated by a space. Constraints 0 < t ≤ 1 000 1 ≤ a, b ≤ 500 Output For each test case print out all prime number found inside the range separated by a comma. Separate your answers with a new line character. Example Input: 2 10 50 500 400 Output: 11,13,17,19,23,29,31,37,41,43,47 401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499
35,075
Monkyes (G10_11) Peter has a rectangular table consisting of  N  rows and  M  columns. Rows are numbered by integers from 1 to  N  from top to bottom and columns are numbered from 1 to  M  from left to right. Let  (x, y)  denote the cell corresponding to  x th  row and  y th  column. Peter has two monkeys, both initially at the cell (1, 1). He wants them to get to the cell ( N ,  M ). Each of the monkey can move from some cell ( x ,  y ) to cell ( x +1,  y ) or cell ( x ,  y +1). As monkeys do not really like each other, they do not want to meet along their ways, except at the start  (1,1)  and end ( N ,  M ) cells. Also, there are exactly  C  cells in the table containing a banana. When a monkey goes through such a cell, he eats this banana. As Peter also wants to eat bananas, he wants that both the monkeys cumulatively don't eat more than  D  bananas. Find out number of ways in which monkeys can get from cell (1, 1) to cell ( N ,  M ) satisfying the above conditions. As answer could be large, please output your answer modulo  MOD . Input The first line of the input contains an integer  T  denoting the number of test cases. The description of  T  test cases follows. The first line of each test case contains five space-separated integers  N ,  M ,  C ,  D  and  MOD  denoting the sizes of table, the number of cells with a banana, the maximum number of bananas that can be eaten by monkeys and the modulo. Each of next  C  lines contains two space-separated integers  x i  and  y i  denoting the coordinates of the cell with a banana. Output For each test case, output a single line containing the numbers of ways monkeys can get from cell (1, 1) to cell ( N ,  M ) modulo  MOD . Constraints 2 ≤ N, M ≤ 10 5 0 ≤ D ≤ C ≤ min{200, N * M - 2} 1 ≤ x i  ≤ N 1 ≤ y i  ≤ M 1 ≤ MOD ≤ 10 9 It's guaranteed that there is no banana in cells (1, 1) and (N, M) Example Input: 4 2 3 0 0 10 2 3 1 0 16 2 1 3 3 1 0 7 2 2 2 2 2 1 11 1 2 2 1 Output: 1 0 1 0
35,076
Binario (G11) Capture a string containing the input data. Build an AVL (height balanced) binary search tree. That is, the one in which the difference between the heights of the left branch and the right branch of each of its records does not differ by more than one unit. Record the (unordered) text in the binary tree in ordered form and show its inorder, preorder, and postorder traversals. Input Letters that will form a node in the binary (sorted) tree. Output Inorder traversal of the binary tree. Preorder traversal of the binary tree. Postorder traversal of the binary tree. Example Input: GKILQMT Output: GIKLMQT LIGKQMT GKIMTQL Capturar un string que contiene los datos de entrada. Construir un árbol binario de búsqueda AVL( balanceado por la altura). Es decir aquel en que la diferencia entre las alturas de la rama izquierda y la rama derecha de cada uno de sus registros no difiere en más de una unidad. Registrar en el árbol binario el texto (desordenado) en forma ordenada y mostrar sus recorridos inorden, preorden y posorden. Input Letras que formarán un nodo en el árbol binario (ordenado). Output Recorrido inorden del árbol binario. Recorrido preorden del árbol binario. Recorrido posorden del árbol binario. Example Input: GKILQMT Output: GIKLMQT LIGKQMT GKIMTQL
35,077
FACTORES PRIMOS GRADO 10 (RG10) Factores Primos de un Número Compuesto Un número es primo si es divisible por 1 y por sí mismo. Por ejemplo, 7 es primo porque sus únicos factores son 1 y 7. Por definición el 1 no es primo. Un número es compuesto si no es primo. Todo número compuesto puede expresarse como un producto de factores primos. Por ejemplo, el 51 es número compuesto porque 51 = 3 x 17 Elabore un programa que lea un número compuesto y encuentre sus factores primos. Muestras ejecución Elabore un programa que lea un número compuesto y encuentre sus factores primos. Entrada : Un número natural compuesto. Salida : Sus factores primos, en orden ascendente, separados por “ x “. Example Input: 100 Output: 2 x 2 x 5 x 5 Imput: 49 Output: 7 x 7   Nótese que la salida imprime los factores primos en orden ascendente separados por una equis que tiene un espacio a su izquierda y derecha, “ x ”.
35,078
SORT FREQUENCY OF INTEGER GRADO 11 (RG11) Sort Frequency of Integers Code a program that reads a unidimensional array of integers and prints in descending order the frequency of the integers in the array. Input : A sequence of integer numbers where the first one is a positive integer that represents the amount of numbers in the rest of the line. Output : The frequencies of the input numbers sorted in descending order. Input 9 4 80 80 30 4 4 80 4 4 Output 5 3 1   Example Input: 4 5 5 5 5 Output: 4   Note that the first number in the input, 9, indicates the size of the array. Also, note that 80 appears 3 times; 30, once; and 4, five times.
35,079
CLAVES SEGURAS GRADO 11 (RG11_2) Un password seguro es algo delicado. Los usuarios prefieren passwords que sean fáciles de recordar (como “amigo”), pero este password puede ser inseguro. Algunos lugares usan un generador randómico de passwords (como “xvtpzyo”), pero los usuarios toman demasiado tiempo recordándolos y algunas veces lo escriben en una nota pegada en su computador.   Una solución potencial es generar password “pronunciables” que sean relativamente seguros pero fáciles de recordar.   FnordCom está desarrollando un generador de passwords. Su trabajo en el departamento de control de calidad es probar el generador y asegurarse de que los passwords sean aceptables.   Para ser aceptable, el password debe satisfacer estas tres reglas: 1. Debe contener al menos una vocal. 2. No debe tener tres vocales consecutivas o tres consonantes consecutivas. 3. No debe tener dos ocurrencias consecutivas de la misma letra, excepto por ‘ee’ o ‘oo’.   (Para el propósito de este problema, las vocales son 'a', 'e', 'i', 'o', y 'u'; todas las demás letras son consonantes.)   Note que Estas reglas no son perfectas; habrán muchas palabras comunes/pronunciables que no son aceptables.   La entrada consiste en una o más potenciales passwords, uno por línea, seguidas por una línea conteniendo una palabra 'end' que señala el fin de la entrada. Cada password tiene como mínimo una y como máximo veinte letras de largo y está formado por solo letras en minúscula. Por cada password, despliegue si es o no aceptable, usando el formato mostrado en el ejemplo de salida. Example Input a tv ptoui bontres zoggax wiinq eep houctuh end Output <a> is acceptable. <tv> is not acceptable. <ptoui> is not acceptable. <bontres> is not acceptable. <zoggax> is not acceptable. <wiinq> is not acceptable. <eep> is acceptable. <houctuh> is acceptable.
35,080
(RG10_2)
35,081
NEW YEAR GRADO 10 (RG102) Lukas spends the day of New Year's Eve counting the minutes that are missing so that they give the grapes. Can help him? Input The entry consists of a series of hours, each in a line. Each hour is formed by the hours and minutes separated by two dots ( : ) and always using two digits. A representation is used in 24 hours format (that is, from 00:00 to 23:59).   Entry ends when the time is midnight (00:00), which should not be processed. Output For each test case a line will be shown with the number of minutes remaining by midnight. Example Input: 23:45 21:30 00:01 00:00 Output: 15 150 1439
35,082
Sum Until 0 (SUMUNZ) Given a list, calculates the sum of all the elements in the list that precede the first 0. If the 0 is not present the result will be the sum of all the elements. If the list is empty, return 0. NOTE: To read the input list you can, for example, use the lis = eval(input()) command which stores the input list in the lis variable. Input A list of number Output the sum of all the elements in the list that precede the first 0. If the 0 is not present the result will be the sum of all the elements. If the list is empty, return 0 Example Input: [3,6,7,2,0,4,0,45,32,0] Output: 18
35,083
Prime Number (ENPRIME) Read an integer X from the input and calculate the factorial of X. The factorial is a function that multiplies a number for each positive number that precedes it X! = X * (X-1) * (X- 2) * ... * 1 Input An integer number X. Output The factorial of X. Example Input: 4 Output: 24
35,084
Diccionario Graro 10 (G10181) EL DICCIONARIO   Andrea,  de 12 años, tiene un sueño, quiere producir su muy propio diccionario, Esta no es una tarea fácil para ella, con el número de palabras que ella conoce, pues son pocas. En lugar de pensar todas las palabras ella misma, se le ocurrió una idea brillante Elegiría uno de sus favoritos libros de cuentos, de los cuales copiará todas las palabras distintas. Organizando las palabras en orden alfabético, está listo. Por su puesto que es un trabajo realmente lento y aquí es donde el programa de computadora es útil. Se le pide que escriba un programa que liste las diferentes palabras en el texto de entrada En este problema una palabra se define como una secuencia consecutiva de letras en mayúscula y/o minúscula. Las palabras con una sola letra también deben ser consideradas. Además su programa no debe causar insatisfacción. Por ejemplo: palabras como “casa” o “CASA” deben considerarse iguales. Input   El archivo de entrada es un texto con no más de 5000 líneas. Una línea de entrada tiene como máximo 200 caracteres Output Su salida debe dar una lista de palabras diferentes que aparecen en el texto de entrada, una en una línea Cada una de las palabras deben estar todos en minúscula, ordenados en orden alfabético. Puedes estar seguro de que el número de las palabras distintas en el texto no excedan 5000 Example Input: los pollitos dicen pio, PIO,pIo, cuando tienen hambre. cuando tiEnen frio, La gallina busca, el maiz y el trigo, les da la comida, y les presta abrigo Output: abrigo busca comida cuando da dicen el frio gallina hambre la les los maiz pio pollitos presat tienen trigo y
35,085
Criptoanálisis (G10182) El criptoanálisis es el proceso de romper la escritura criptográfica de otra persona. Esto a veces implica algún tipo de análisis estadístico de un pasaje de texto encriptado. Su tarea es escribir un programa que realice un análisis simple de un texto que usted debe ingresar. Input El texto que debe analizarse consiste en: La primera línea de entrada contiene un  único entero decimal positivo (n), este número  indica  el número de líneas que siguen en la entrada. Estas  líneas  contendrán cero o más caracteres (posiblemente incluyendo espacios en blanco).  Output Cada línea de salida contiene una sola letra mayúscula, seguida de un espacio simple, seguido de un entero decimal positivo. El número entero indica cuántas veces aparece (coinsidencia) la letra correspondiente en el texto de entrada. Las letras mayúsculas y minúsculas en la entrada deben considerarse iguales. Sólo se analizan las letras. La salida debe ordenarse descendente por la cantidad de coincidencias en el texto; es decir, la letra más frecuente está en la primera línea de salida y la última línea de salida indica la letra menos frecuente. Si dos letras tienen la misma frecuencia, entocnces la letra que aparece primero en el alfabeto debe aparecer primero en la salida. Si una letra no aparece en el texto, entonces no debe aparecer en la salida. Example Input: 3 Esta es una prueba, Cuentame 1 2 3 4 5, ¡ ¡oohh!! ¿Esta es pregunta facil? Output: E             8 A             7 U            4 T             4 S             4 N            3 R             2 P             2 O            2 H             2 C             2 M           1 L              1 I              1 G            1 F             1 B             1
35,086
Divide Grado 10 (G10183) Este juego de números consiste en identificar si un número es divisible o no por 11.  Para ello se debe usar el siguiente algoritmo:   Borrar el dígito de las unidades Restar el dígito de las unidades que acaba de borrar del número resultante del paso anterior   El proceso se repite siempre y cuando se tengan más de dos dígitos en el resultado.   El número original es divisible por 11 sí y solo si, el número final es divisible por 11. Input La entrada consiste de una serie de números enteros, uno en cada línea.  Esta lista termina con 0, cada entero positivo tiene un máximo de 50 dígitos. Se puede asumir que no hay 0 a la izquierda en los enteros positivos. Output Por cada entero positivo en la entrada, la salida consiste de una serie de números resultantes del proceso de borrar el último digito y de restar el número truncado.  Al final aparece un mensaje que indica si el número original es o no divisible por 11. Las salidas para diferentes enteros positivos deben ser separadas por una línea. Example Input: 12345678901234567900 896245630004 0 Output: 12345678901234567900 1234567890123456790 123456789012345679 12345678901234558 1234567890123447 123456789012337 12345678901226 1234567890116 123456789005 12345678895 1234567884 123456784 12345674 1234563 123453 12342 1232 121 11 El numero 12345678901234567900 es divisible por 11. 896245630004 89624562996 8962456293 896245626 89624556 8962449 896235 89618 8953 892 87 El numero 896245630004 no es divisible por 11.
35,087
Arroz con Pollo Grado 10 (G10184) Suponiendo que una Arroz con pollo se puede cocinar exclusivamente con arroz y pollo, y que para cada cuatro personas se utiliza medio kilo de arroz y un cuarto de kilo de pollo, escribir un programa que se le ingrese el número de comensales para la comida, el precio por kilo de los ingredientes y muestre las cantidades de los ingredientes necesarios y el costo de la misma. Input La entrada consistirá en una serie de líneas, cada línea contiene 3 enteros Comensales, valor del arroz, valor del pollo mayores que cero, separados por un espacio. La entrada terminará cuando la línea tenga los tres 0. Output Por cada entrada, imprima la cantidad de arroz, la cantidad de pollo y el costo de la comida, separados cada uno por un espacio. Si el resultado no es número entero, trabaje con dos cifras decimales. Example Input: 12 1200 6000 200 1000 4000 60 1500 5000 0 0 0 Output: 1.50 0.75 6300 25 12.50 75000 7.50 3.75 30000
35,088
TrianguloRectangulo Grado 10 (G10185) Hacer  un programa que solicite la cantidad de filas para dibujar un triángulo rectángulo con números primos. El triángulo dibujado contiene la serie descendente de números primos, desde el 1000. Input Número entero que indica la cantidad de fílas para dibujar el triángulo   Output Serie descendente de números primos, desde el 1000.   Example Input: 6 Output: 97 991 983 977 971 967 953 947 941 937
35,089
El Diccionario Grado 11 (G11181) EL DICCIONARIO   Andrea,  de 12 años, tiene un sueño, quiere producir su propio diccionario, Esta no es una tarea fácil para ella, con el número de palabras que conoce, pues son pocas. En lugar de pensar todas las palabras ella misma, se le ocurrió una idea brillante Elegiría su libro de cuentos favorito, del cuale copiará todas las palabras distintas. Organizando las palabras en orden alfabético, está listo. Por su puesto que es un trabajo realmente lento entonces, requiere de tu ayuda. Se le pide que escriba un programa que liste las diferentes palabras en el texto de entrada En este problema una palabra se define como una secuencia consecutiva de letras en mayúscula y/o minúscula. Las palabras con una sola letra también deben ser consideradas. Además su programa no debe causar insatisfacción. Por ejemplo: palabras como “casa” o “CASA” deben considerarse iguales. Input   El archivo de entrada es un texto con no más de 5000 líneas. Una línea de entrada tiene como máximo 200 caracteres Output Su salida debe dar una lista de palabras diferentes que aparecen en el texto de entrada, una en una línea Cada una de las palabras deben estar todos en minúscula, ordenados en orden alfabético. Puedes estar seguro de que el número de las palabras distintas en el texto no excedan 5000 Example Input: los pollitos dicen, pio, PIO,pIo, cuando tienen hambre. cuando tiEnen frio, La gallina busca, el maiz y el trigo, les da la comida, y les presta abrigo Output: abrigo busca comida cuando da dicen el frio gallina hambre la les los maiz pio pollitos presat tienen trigo y
35,090
CRUZ Grado 11 (G11182) A word cross is formed by printing a pair of words, the first horizontally and the second vertically, so that they share a common letter. A leading word cross is one where the common letter is as near as possible to the beginning of the horizontal word, and, for this letter, as close as possible to the beginning of the vertical word. Thus DEFER and PREFECT would cross on the first ‘E’ in each word, PREFECT and DEFER would cross on the ‘R’. Double leading word crosses use two pairs of words arranged so that the two horizontal words are on the same line and each pair forms a leading word cross. Write a program that will read in sets of four words and form them (if possible) into double leading word crosses Input Input will consist of a series of lines, each line containing four words (two pairs). A word consists of 1 to 10 upper case letters, and will be separated from its neighbours by at least one space. The file will be terminated by a line consisting of a single ‘#’. Output Output will consist of a series of double leading word crosses as defined above. Leave exactly three spaces between the horizontal words. If it is not possible to form both crosses, write the message ‘Unable to make two crosses’. Leave 1 blank line between output sets. Example Input: MATCHES CHEESECAKE PICNIC EXCUSES PEANUT BANANA VACUUM GREEDY # Output:
35,091
FOLLOWING Grado 11 (G11183) Order is an important concept in mathematics and in computer science. For example, Zorn’s Lemma states: “a partially ordered set in which every chain has an upper bound contains a maximal element.” Order is also important in reasoning about the fix-point semantics of programs. This problem involves neither Zorn’s Lemma nor fix-point semantics, but does involve order. Given a list of variable constraints of the form x < y, you are to write a program that prints all orderings of the variables that are consistent with the constraints. For example, given the constraints x < y and x < z there are two orderings of the variables x, y, and z that are consistent with these constraints: xyz and xzy. Input   The input consists of a sequence of constraint specifications. A specification consists of two lines: a list of variables on one line followed by a list of constraints on the next line. A constraint is given by a pair of variables, where ‘x y’ indicates that x < y. All variables are single character, lower-case letters. There will be at least two variables, and no more than 20 variables in a specification. There will be at least one constraint, and no more than 50 constraints in a specification. There will be at least one, and no more than 300 orderings consistent with the constraints in a specification. Input is terminated by end-of-file. The input consists of a sequence of constraint specifications. A specification consists of two lines: a list of variables on one line, followed by a list of constraints on the next line. A constraint is given by a pair of variables, where ‘x y’ indicates that x < y. All variables are single character, lower-case letters. There will be at least two variables, and no more than 20 variables in a specification. There will be at least one constraint, and no more than 50 constraints in a specification. There will be at least one, and no more than 300 orderings consistent with the constraints in a specification. Input is terminated by end-of-file.   Output The output should consist of the final state of the blocks world. Each original block position numbered i (0 ≤ i < n where n is the number of blocks) should appear followed immediately by a colon. If there is at least a block on it, the colon must be followed by one space, followed by a list of blocks that appear stacked in that position with each block number separated from other block numbers by a space. Don’t put any trailing spaces on a line. There should be one line of output for each block position (i.e., n lines of output where n is the integer on the first line of input). Example Input: 10 move 9 onto 1 move 8 over 1 move 7 over 1 move 6 over 1 pile 8 over 6 pile 8 over 5 move 2 over 1 move 4 over 9 quit Output: 0: 0 1: 1 9 2 4 2: 3: 3 4: 5: 5 8 7 6 6: 7: 8: 9:
35,092
Jolly Grado 11 (G11184) A sequence of n > 0 integers is called a jolly jumper if the absolute values of the differences between successive elements take on all possible values 1 through n−1. For instance, 1 4 2 3 is a jolly jumper, because the absolute differences are 3, 2, and 1, respectively. The definition implies that any sequence of a single integer is a jolly jumper. Write a program to determine whether each of a number of sequences is a jolly jumper. Input: Each line of input contains an integer n < 3000, followed by n integers   representing the sequence. The end of the input will be n=0 that represents the end of the program. Output For each line of input generate a line of output saying “Jolly” or “Not jolly”. Example Input: 5 1 4 2 3 5 1 4 2 -1 6 0 Output: Jolly Not jolly
35,093
Ordenación Grado 11 (G11185) Construir un programa que cree un vector de N posiciones. Si la posición es par, la celda del vector se debe llenar con la siguiente formula Celda[i] = i * i + 1.  Si la celda es impar, la celda del vector se debe llenar con la siguiente formula Celda[i] = 3 * (i + 1).  Luego los elementos que contengan un número par del vector se deben ordenar descendentemente en las primeras posiciones del vector y los elementos impares del vector se deben ordenar ascendentemente en las últimas posiciones del vector. Se debe mostrar el vector sin ordenar y luego el vector ordenado. Ejemplo : al ejecutar el programa se queda esperando la entrada de un número, si el usuario presiona 10 <Enter> debe mostrar lo siguiente: Input Número entero Output Imprime mensaje SIN ORDENAR, seguido del evtor sin ordenar luego el mensaje ORDENADO  seguido del vector ordenado Example Input: 10 Output:
35,094
Occurrences of a Character (ENCAROC) Given a string and a character, calculate the number of occurrences of that character in the string. Input The input consists of two lines. The first contains a string S, while the second contains a character C to be counted  Output The number of occurrences of the character C in the string S Example Input: hello world o Output: 2
35,095
Greatest Common Divisor (ENGCD) Given two integers x, y calculates the greatest common divisor (gcd). In mathematics, the greatest common divisor (gcd) of two or more integers, which are not all zero, is the largest positive integer that divides each of the integers. For example, the gcd of 8 and 12 is 4 Input Two integers x and y other than 0. Output The greatest common divisor (gcd) of x and y. Example Input: 8 12  Output: 4
35,096
Lowest Common Denominator (ENLCD) Given two integers x, y calculates the lowest common denominator (lcd). In mathematics, the lowest common denominator is the smallest number that can be divided into. Input Two integers x and y other than 0. Output The lowest common denominator (lcd) of x and y. Example Input: 6 10 Output: 30
35,097
Menu Tour (MENUTOUR) Rachid is in Barcelona for the first time, and wants to have a really good dinner. He heard that the ultimate dinner consists of C courses, which are numbered from 1 to C and have to be consumed in that order. The streets of Barcelona form a regular grid: west-east oriented streets crossing south-north oriented streets. There are R restaurants in the city and they are located at the crossings. Walking from crossing (i 1 , j 1 ) to crossing (i 2 , j 2 ) takes exactly |i 1 - i 2 | + |j 1 - j 2 | minutes, where |x| denotes the absolute value of x. Here, (i, j) means i-th street from west to east, and j-th street from south to north. Unfortunately, restaurants do not offer all of the C courses. If a restaurant k offers course c then it costs P[k, c] euros. Otherwise the value P[k, c]=0 indicates that the course is not offered. Rachid has B euros that he can spend on his dinner. He would like to choose a sequence of restaurants so that he can have his ultimate dinner without exceeding the available budget, while minimizing the total travel time between restaurants. The tour can start and end at an arbitrary crossing, and can visit the same restaurant several times. Example On this example, there are three courses, whose prices are displayed in order, for every restaurant (a dash corresponds to a dish that is not offered, i.e., when P[k, c]=0). If Rachid has a budget of 9 euros, the optimal tour consists of the restaurants 1--4--3 for a cost of 6 euros and a total travel time of 12 minutes. There is a shorter tour of 2 minutes consisting of the restaurant sequence 1--2--2, but its cost is 17 euros, exceeding the available budget of 9 euros. Input The input begins with a line consisting of the integers C, R, B, separated by a single space. Then R lines follow. The k-th line describes the k-th restaurant and consists of 2+C integers separated by a single space, namely i[k], j[k], P[k, 1] ... P[k, C], where (i[k], j[k]) defines the location of the restaurant. Limits 1 ≤ C ≤ 20 1 ≤ R ≤ 100 0 ≤ B ≤ 100 for every 1 ≤ k ≤ R: 1 ≤ i[k] ≤ 1000 1 ≤ j[k] ≤ 1000 for every 1 ≤ c ≤ C, 0 ≤ P[k, c] ≤ 40. Output The output should consist of a single integer y: the minimum total travel time of an optimal restaurant tour for Rachid. If there is no feasible tour, the value -1 should be printed. Example Input: 3 5 9 1 1 1 0 0 3 1 0 9 7 6 2 0 0 3 3 5 0 2 0 6 5 8 0 9 Output: 12
35,098
Beca Grado 10 (PG10181) Becas para Estudiantes Un país está otorgando becas para estudios en el exterior a los estudiantes que pasen un examen de conocimientos y otro de inglés. Elabore un programa que ayude a esté país a seleccionar los estudiantes que se les otorgará la beca. Input La entrada tiene dos filas. La primera contiene los códigos, un entero entre 1 y 10.000, de los estudiantes, separados por espacios, de los que pasaron el examen de conocimientos; y la segunda, contiene los códigos de los estudiantes, también separadas por espacios en blanco, que pasaron el de inglés. El primer entero en cada línea es el número de códigos en la fila. No hay códigos repetidos en las filas. Output Los códigos de los estudiantes que aprobaron ambos exámenes ordenados ascendentemente. Example Input: 4 101 309 499 333 3 499 66 101   Output: 101 499 Example2 Input: 3 6 999 12 3 12 123 9   Output: 12
35,099