task
stringlengths
0
154k
__index_level_0__
int64
0
39.2k
Derp (DERP) Usually, producing methamphetamine is somewhat laborous and boring. There are some TV series who assume that there is a new way to produce it, being way cheaper than actually is. Nonsense. The fact is there is a new drug around, called Krokodil. This drug is a variation of morphine, which gives 8 to 10 times more hallucination than “meth”, costing up to 10 times less than it. Your friend Derp works in a “meth lab” and, while he was doing some tests, looking at the microscope, he found an interesting property: if he isolates the most far away pair of atoms in it, he will produce a substance as powerful (perhaps even more) as Krokodil is. This happens because one of the electron moves from one atom to the other. But, most of the times, there are hundreds, maybe thousands of particles in each sample, each of them using several layers, making kinda hard to find out which is the longest distance. There’s an unusual fact about this distance calculus: Each electron from these particles are kinda dumb; they are only able to move in horizontal and vertical axis. Also, since there are nanometrical layers, and distance is also considered for calculation between layers (which is the same), and a electron, in the layer L, with position (x, y), can only move to layers L + 1 and L − 1, if any of those exist, in the same relative position as in layer L. Input Each input contains several test cases. The first line of every test case contains a number N, which is the number of particles of that sample (2 ≤ N ≤ 100,000). Then there are N lines, each of which contains 3 integers, li, xi, yi, which are the actual layer, the position corresponding corresponding to the X-axis, and the position corresponding to Y-axis (1 ≤ li, xi, yi ≤ 1,000,000,000). Output For each output you print one integer, DISTANCE, which corresponds to the value of the farthest distance between particles in the that sample. Example Input: 5 1 1 2 3 4 1 2 5 7 4 1 1 3 3 3 0 Output: 12
32,700
Bunnies (BUNNIES) Pompom bunny has N strange eggs. The i-th egg is broken by tapping it exactly Ai times. Pompom needs to break K eggs as soon as possible for cooking a rice omelette. However she has been put in an uncomfortable situation. Someone has shuffled the eggs! Pompom knows the values Ai, however she doesn't know which egg is which. She'd like to minimize the worst-case number of taps. What is the minimal number? Input The first line contains an integer T, the number of test cases. Then T test cases follow. The first line for each test case has 2 integers N and K. Then next line has N integers A1, A2 ... AN. Output For each test case, print the minimal number of taps for the worst-case. Constraints 1 <= T <= 10 1 <= K <= N <= 3000 1 <= Ai <= 1000000 Example Input: 3 2 1 5 8 2 1 5 58 3 2 1 2 3 Output: 8 10 5 Explanation In the first case, if a egg isn't broken after 5 taps, she should continue to tap the same egg. In the second case, if a egg isn't broken after 5 taps, she should tap another egg 5 times.
32,701
Delivery Route (DELIVER) After several years of record milk production, Farmer John now operates an entire network of N farms (1 ≤ N ≤ 100). Farm i is located at position (x i , y i ) in the 2D plane, distinct from all other farms, with both x i and y i being integers. FJ needs your help planning his daily delivery route to bring supplies to the N farms. Starting from farm 1, he plans to visit the farms sequentially (farm 1, then farm 2, then farm 3, etc.), finally returning to farm 1 after visiting farm N. It takes FJ one minute to make a single step either north, south, east, or west. Furthermore, FJ wants to visit each farm exactly once during his entire journey (except farm 1, which he visits twice of course). Please help FJ determine the minimum amount of time it will take him to complete his entire delivery route. Input Line 1: The number of farms, N. Lines 2..1+N: Line i+1 contains two space-separated integers, x i and y i (1 ≤ x i , y i ≤ 1,000,000). Output Line 1: The minimum number of minutes FJ needs to complete his delivery route, or -1 if it is impossible to find a feasible delivery route that visits every farm exactly once (except farm 1). Example Input: 4 2 2 2 4 2 1 1 3 Output: 12 Explanation FJ can complete his delivery route in 12 minutes: 2 minutes to go from farm 1 to farm 2, 5 minutes to go from farm 2 to farm 3 (circumventing farm 1), 3 minutes to go from farm 3 to farm 4, and then 2 minutes to return to farm 1.
32,702
MINI IN DANGER!!! (MINI) There is a n × n board. Tom is playing a game in which there are n × n blocks which can be filled with numbers from 0 to n-1 in some arbitrary way. The rule of the game is that the board should be filled in such a way that the sum of each row and column should be divisible by n. Tom has set the board in a winning configuration. But now the intelligent and notorious daughter of Tom, Mini comes and changes the configuration of the board. But she is scared now as her dad is about to come home. She realizes that dad will get angry if he sees that the board is not in the winning configuration and he will scold her. Mini wants to know the number of ways in which the board can be restored to a winning configuration. Please help her out. Input First line consists of an integer T and then T test cases follow, each having the value of N. Output For each test case you have to output the number of ways modulo 1000000009 in a separate line. Constraints T <= 10 6 N will be between 1 and 2 64 -1 and not a multiple of 1000000009 Sample Input: 1 1 Output: 1
32,703
Alice Sieve (ALICESIE) Alice has recently learned to use the Sieve of Eratosthenes, an ancient algorithm for finding all prime numbers up to any given limit. As expected, she was really impressed by it's simplicity and elegancy. Now, she has decided to design her own sieve method: The Sieve of Alice, formally defined by the following procedure, which determines the Sieve of Alice up to a given limit N. Create a list of consecutive integers from N to 2 (N, N-1, N-2 ... 3, 2). All of those N-1numbers are initially unmarked. Initially, let P equal N, and leave this number unmarked. Mark all the proper divisors of P (i.e. P remains unmarked). Find the largest unmarked number from 2 to P – 1, and now let P equal this number. If there were no more unmarked numbers in the list, stop. Otherwise, repeat from step 3. Unfortunately, Alice has not found an useful application for it's Sieve. But she still wants to know, for a given limit N, how many integers will remain unmarked. Input The first line contains an integer T, the number of test cases (1 ≤ T ≤ 10 4 ) . Each of the next T lines contains an integer N (2 ≤ N ≤ 10 6 ). Output Output T lines, one for each test case, containing the required answer. Example Input: 3 2 3 5 Output: 1 2 3
32,704
Graph Cut (GRAPHCUT) Given a graph G, and a subset of its vertices X. The associated cut of X is the set of edges associated to X is the subset of all edges in G such that exactly one of the two vertices it joins belongs to X. In thinks, you will be given a graph and a subset of its edges, and you will have to determine whether there exists a subset of the vertices of the graph for which the given subset of the edges is its associated cut. Input The first line contains an integer T, the number of test cases (1 ≤ T ≤ 40). Each test case, consists of a line which contains three integers N (2 ≤ N ≤ 500), E (1 ≤ E ≤ 104), K (1 ≤ K ≤ E), the number of vertices in the graph, and the number of edges in the subset for which we want to know whether it is an associated cut or not. Then, E lines follow, each of them contains two integers u, v (1 ≤ u, v ≤ N) which are the vertices joined by the edge, the first K of these E lines represent the asked subset. Output Output T lines, one for each test case. If the asked subset is an associated cut, then print “YES”, otherwise print “NO”. Example Input: 2 3 3 1 1 2 2 3 1 3 12 17 6 3 4 5 6 10 11 1 5 6 10 4 8 1 2 2 3 6 7 7 8 9 10 11 12 5 9 2 6 3 7 7 11 8 12 Output: NO YES
32,705
Longest Common Substring (LONGCS) Substrings are consecutive parts of a string. A problem usually solved with dynamic programming is to find the longest common substring problem is to find the longest string (or strings) that is a substring (or are substrings) of two strings. Your task is to find the length of the longest common substring of K strings. Input The first line contains an integer T, the number of test cases (1 ≤ T ≤ 20) . Each test case, consists of one line containing an integer K (1 ≤ K ≤ 10), and K lines, each containing a string (length of s <= 10^4), the strings only contain the character ‘a’ – ‘z’. Output Output T lines, one for each test case, containing the required sequence, with a blank space between consecutive terms. It is guaranteed that all terms in the sequence are integers. Example Input: 2 2 aaabbb bbaabb 3 icode coder contest Output: 4 2
32,706
Soccer Challenge (SOCCERCH) A soccer field is divided into squared plots, like a grid of N rows and M columns. The length of a plot side is equal to 1. Fernando likes to practice running only through the boundaries of the plots, he does not like to go inside the plots. Some of the plots are muddy, and some others have been selected by Fernando as target plots. A plot may neither be muddy nor a target one. Starting at the top left corner, he would like to go through the field and return back to the starting point. All plots that lie inside the cycle of his path are considered to be inspected. To make things more interesting he would like his path not to intersect with itself in any point different than the starting point. Luckily, the plots boundaries are so wide that Fernando can go along the same boundary multiple times without intersecting his own path. Fernando would like to inspect all target plots, but not any muddy plots. Martin, who plays in the opposing team, challenged Fernando that he could do a shortest path starting from the lower right corner. Can you help Fernando to get his shortest path, and decide whether it is shorter than the one? Input Input consist of many test cases. First line of input starts with two integers R and C (1 ≤ R, C ≤ 50), which defines the rows and columns the soccer field has been divided into. Next, the soccer field is described in R rows, each containing C characters. Chars I, X, and O, represents target plots (to inspect), muddy plots, and common plots respectively. The quantity of target plots plus the quantity of muddy plots will not exceed 10. There will be no spaces between the C characters of each line describing the soccer field. End of the input is indicated by a line containing two zeros, which should not be processed. Output The output of each test case should be a separate line consisting of the name of the player who has the shortest path to inspect the target plots but not the muddy plots, or the word “Tie” in case of a tie, followed by a number representing the length of the shortest path for that player. The examples may clarify the format. Example Input: 1 1 I 2 2 XX XI 2 2 XI IX 3 3 III IXI III 2 2 IO OO 0 0 Output: Tie 4 Martin 4 Tie 10 Tie 18 Fernando 4
32,707
Cheating on the contest (CHEATCON) For the first time the Skyrim Free School of Mathematics, Philosophy and Linguistics will host the Regular Expressions (regex) Contest (RegExCon). The contest happens this way: participants compete always against 1 opponent. One wins one loses. Only one will remain, the champion. In one dispute both participants receive a list with several regular expressions and for each regex the participants must calculate if several given words are recognized or not by the regex. As a member of the School you are participating, and want to win. So, to guarantee your victory, you have to write a program to solve the problem and let it executing in your Cool Stuff Calculator Machine at home. As a mage, expert in Alteration and Illusion, you can easily control your machine with your mind, so you can use your program while in the contest. It's forbidden to use magic in the contest, but coincidentally the Winterhold School will host some Mage Congress, so you don't need to worry, use your magic. A regular expression is used to describe a language (a set of words). Consider that the alphabet of all languages in this problem is {a, b}. A regex R is valid if: R is “a” or “b”; R is “(P.S)” where P and S are regular expressions; R is “(P|S)” where P and S are regular expressions; R is “(P*)” where P is a regular expression; Regular expressions can be nested. There is no ternary operation with operators “.” and “|”, neither binary operation with operator “*”. Words always start with “(“ and finish with “)”. Set L of words recognized by R is formed following next rules: If R is “(a)”, L = {a}; If R is “(b)”, L = {b}; If R is “(P.S)”, L = all words that can be obtained from a concatenation of words p and s, where p is recognized by P and s by S; If R is “(P|S)”, L = union of the sets of words recognized by P and S; If R is “(P*)”, R recognizes the concatenation of 0 or more words recognized by P. Input Input file contains several test cases. First line of a test case contains a regex (defined before, between 1 and 150). Next line contain an integer P (1 ≤ P ≤ 100). Each one of the next P lines contains a word formed by 'a's and 'b's (<= 50) that represents the following question: “Is this word recognized by the given regex?”. Output For each question described before, answer “Y” (no quotes) if the answer is “yes” or “N” (no quotes) if the answer is “not”. At the end of each test case print a blank line. Example Input: (a) 3 a b aa (a.b) 3 a ab b (a|b) 4 a b ab ba (a*) 3 a aaaaaaaaaaa aaaaabaaaaa ((a*).(b*)) 3 bbbaaa aaabbb bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb Output: Y N N N Y N Y Y N N Y Y N N Y Y
32,708
Problem Offensive Strategy (OFFSTRAT) Foo Football Club is a very offensive soccer team. Its coach is planning a new attack strategy. In order not to change its image of offensive team, the coach wants to be sure that the new attack strategy is going to be strongly offensive. He is a very grumpy coach so he does not allow the players to make a pass that is not in the strategy sheet. In fact he is so mad that he does not allow the player who holds the ball to move. An attack strategy is strongly offensive if each football pass position inside the field goes to another football pass position inside the field which is in the same distance or closer to the enemy line of goal, and also it should be possible to reach the enemy goal from every pass position described in the strategy sheet. Input The first line of input consist of a number T (T ≤ 20) representing the number of test cases, then T test cases follow describing a strategy. Each test case begins with two integers W and H (1 < W, H ≤ 100, also W and H are even integers) representing the width and height of the soccer field. The goal lines is the line x = w and the goal is gotten form a pass point (x, y) if it is possible reach the point (w, h/2) from (x, y). These are followed by an integer number M (1 ≤ M < 1000000) the number of available passes in the strategy. The next M lines consist of four integer numbers x0, y0, x1, y1 (0 ≤ x0, x1 ≤ W and 0 ≤ y0, y1 ≤ H) representing the start position (x0, y0), and the end position (x1, y1) of an available pass in. Output For each test case the output should consist of a single line containing “Yes” (without quotes) if the strategy is strongly offensive or “No” (without quotes) otherwise. Example Input: 2 2 2 1 0 1 2 1 2 2 4 0 1 2 1 0 0 1 1 0 2 1 1 1 1 2 1 Output: Yes Yes
32,709
Soccer Ceremony (SCCCER) There are four popular football teams in the region of Sao Paulo: Corinthians, Palmeiras, Santos and Sao Paulo. Exactly n players among those football teams were pre-selected for an award regarding their performance in the championship. Today is the big day when one of them will be awarded as the ultimate champion. The players have now arrived, and everyone remembered their seats row (which is the same for all the n players) but not their column number. And now, as one of the most basic and known rules about football ceremonies had been violated, you’re in a hurry to satisfy the rule by switching as few players as possible. This rule, which I guess you should be familiar with but we are going to state it for the sake of completeness, states that there cannot be 3 or more players from the same team sitting in consecutive seats. Input You’ll first be given an integer T , which represents the total number of test cases. Each test case consist of a single integer N (1 ≤ N ≤ 20) that represents the number of players invited to the ceremony. This is followed by a string S of length N representing the team at which each player belongs to. Each character S[i] of S will be one of the following C , P , N , S , meaning that the player seated at position i belongs to Corinthians, Palmeiras, Santos or Sao Paulo respectively. Each test case will be separated by a blank line. Output The output should consist of a single number per test case. That number should be the minimum number of players that need to change their seats to satisfy the rule, if there is no way to satisfy the rule output -1 instead. Example Input: 2 8 CCCCCCPN 3 CCC Output: 4 -1
32,710
The Yellow Brick Road (YELBRICK) After Dorothy’s memorable adventure in the Land of Oz, traffic along the Yellow Brick Road got really intense, making some sections of it nearly impossible to cross because of the holes along the road. The Land of Oz engineers are having trouble to pave this road, because the yellow stone is in short supply, forcing them to buy stones from different suppliers. As you already know, every road in the Land of Oz must be built using bricks that are perfect and identical cubes. To maximize the durability of the road, it also must be built using the least number of bricks possible. The problem is that each supplier provides stones of different sizes, that must be cut in order to make the bricks for the road. Can you help the engineers to find which is the best brick size to use to maximize the road durability? Input Each test case is given using several lines. The first line contains an integer N representing the number of different suppliers of yellow stone (2 ≤ N ≤ 1000). For simplicity, we assume that the engineers will buy exactly one stone from each supplier. Each of the next N lines contains three integers Ai, Bi, Ci (0 < Ai, Bi, Ci ≤ 1000, 1 ≤ i ≤ N) that describe, respectively, the width, height and depth of each stone provided by the i-th supplier. The last test case is followed by a line containing one zero. Output For each test case, print one line containing the minimum number of identical cubes that can be cut from the given stones. Example Input: 2 1 2 3 4 5 6 2 4 4 4 2 2 2 0 Output: 126 9
32,711
Exclusive Security (EXCLSEC) Ashton Carl McDonald (known as A.C.M.) works at a company called XOR (XptO Revolution). The company has a simple rule for employee identification: each employee must have an integer id that must be unique (no two employees may have the same id). Recently, the employees were grouped into teams, in the following way: the teams are intervals on the XOR’s employees list. An employee can be part of more than one team. The company wants to hire new employees, and needs to generate id numbers for them. However, due to a security flaw in Human Resources software, the company can’t assign a new number that, if one executes Exclusive-Or operation with all numbers of any team, results in 0. McDonald, as the leader lazy programmer of XOR, needs your help to determine if a given number can or can’t be assigned to a new employee. Input The input contains multiple test cases. The first line of each test case contains three numbers, N, T and Q, the number of employees in the company, the number of teams and the number of new numbers to be queried, respectively. The second line contains N numbers X i , 1 ≤ i ≤ N, distinct, the employees id numbers. Each one of the following E lines contains two numbers, A and B, which represent an interval that forms a team. It means that the employees identified by X A … X B form one team. Each one of the following Q lines contains one number Y j , the queried number. Limits: 1 ≤ N, T, Q ≤ 10 5 , 1 ≤ A ≤ B ≤ N. All X i and Y j will be non-negative and fit into a signed 32 bit integer, and all queries must be treated as independent from others (just the initial employees and teams must be taken into account). Output For each test case, the program must print Q + 1 output lines. For each queried number, the program must print ‘Y’, if the number can be assigned to a new employee, or ‘N’, otherwise. The last line is a simple minus sign ‘-’. Example Input: 3 2 4 1 2 4 1 2 1 3 3 5 6 7 0 0 0 Output: N Y Y N -
32,712
Desrugenstein (DESRUG) The city of Desrugenstein is a complete mess. Looking at the map, it seems organized, since it was created in a square grid form, but there is no directions standard. Each corner says the directions you can go from there (north, south, west, east). The mayor Daniel Snake is headstrong and lazy enough to let everything as it is and forbid any change attempt. Unable to do much, the Master Spiritual Counsellor of Desrugenstein, Giordano Marfyn, asked you, Spiritual Counsellor Level XVII of Desrugenstein, lead programmer of Desrugenstein, to write a program to calculate the cost of going from a corner (x, y) to another corner (z, w), considering the messy streets. Input Input file contains several test cases. First line of each test case contains an integer N (1 ≤ N ≤ 10) that represents height and width of the grid that maps the city (a N x N grid). The input file ends with N = 0, and it should not be processed. Each one of the next N lines represents a street of the city, starting from the further north (N – 1) until the further south. In each one of these lines there are 4*N integers, 4 for each corner: A (north) B (south) C (west) D (east). Each one is 0 if it is not possible to go on the respective direction, or 1 if it is possible. After the city map, your program should read an integer P (1 ≤ P ≤ 100). Next P lines contain 4 integers each, x0 y0 x1 y1 representing the question: “What is the minimum cost to go from corner (x0 , y0) to corner (x1 , y1)?”. The cost to go from a corner to the nearest corner in any direction is 1. Output For each question, answer “Impossible” if there is no valid (respecting corners directions) path between the corners, or the minimum cost, if there is (are) path(s). Print a blank line after each test case. Example Input: 4 0 1 0 1 0 0 1 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 1 0 0 1 0 0 0 1 0 1 0 1 1 0 0 0 1 1 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 5 1 3 0 3 2 3 3 0 2 3 0 0 3 1 3 2 0 3 0 0 0 Output: 1 4 7 3 Impossible
32,713
Ball Stacking Again (BALLSAG) The XYZ TV channel is developing again a new game show, where a contestant has to make a choice in order to get a prize. The game consists of a triangular stack of balls, each of them having an integer value, as the example shows. The contestant must choose exactly one ball and his prize is the sum of the value of that ball and the balls directly on top of it. Notice that the prize can be negative! Your friend is going to participate on the game show, and he wants you to develop a program that can tell the maximum prize possible. Input Each test case is described using several lines. The first line contains an integer N representing the number of rows of the stack (0 < N < 1001). The i-th of the next N lines contains i integers Bij (-1000 ≤ Bij ≤ 1000 for 1 ≤ j ≤ i ≤ N); the number Bij is the value of the j-th ball in the i-th row of the stack (the first row is the topmost one, and within each row the first ball if the leftmost one). After each test case there is a blank line. The last test case is followed by a line containing one zero. Output For each test case output a line with an integer representing the maximum prize a contestant can make from the stack. Example Input: 2 -2 1 -10 3 1 -5 3 6 -4 1 0 Output: -1 5 Note: On the first test case, the optimal solution is to take the ball with value 1, making you remove the ball with value -2, resulting in -1. On the second test case the best option is to take the ball with value 1 on the bottom row, resulting in 1+3+1 = 5.
32,714
subarrays (ARRAYSUB) Given an array and an integer k, find the maximum for each and every contiguous subarray of size k. Input the number n denoting number of elements in the array then after a new line we have the numbers of the array and then k in a new line n < 10 6 k < 10 5 1 ≤ k ≤ n and each element of the array is between 0 and 10 6 ( Edited: In fact, n ≤ 10 5 ) Output print the output array Example Input: 9 1 2 3 1 4 5 2 3 6 3 Output: 3 3 4 5 5 5 6
32,715
Searching God (SEAGOD) Jesse is a biologist and he was studying some aspects of life when he discovered that certain species of sea animals tried to tell him some things about God. Those animals were using a certain language to speak with him. They wrote down in binary code (black and white) in the shell they have. As Jesse was the only one that this message was intended to be delivered, they encrypted the message in such way that there is a rule to decrypt every bit in the spherical-shaped shell looking at 3 other bit: the left, itself and the right in this order. So first they write the cyphered message and the rule to decrypt it in lexicographical order, so the rule space in the shell containing the bit to decrypt “101” will be rule's bit 5. To turn the cryptography more elaborated there is also the number of rounds that this must be done to the entire message. Jesse wants to hire you to write a program for him to decrypt the text and live in harmony forever and ever with the animals he loves and find out who is and what this God wants to do. Input The input has several test cases. The first line of a test case contains the message length L (0 < L ≤ 10000). The next line contains the message M, of length L bits. In the next line, your program should read the 8-bits rule R. In another line, the number of rounds 0 ≤ N ≤ 10000. Your program must read until the end of file. Output For each test case your program must write the message M after applying the rule R for N rounds. Example Input: 5 10111 10101010 1 10 1011010101 11100010 2 Output: 10000 1011010101
32,716
Problems in Moria (PROBMOR) Balin, in his last days, needed to put more workers on the tunnels of Moria to build a lot of shelters to his people and to discovery the depths of that land. However, he didn't know where to put a collection point in order to take all the rocks in the way and bring all of them outside of Moria. The only thing he knew was this collection point needed to be fix in a junction point that connects two independent parts. If there's no point with this feature, any junction point, that's not the source one, can be used. Input The input contains several test cases. Each test is given by a line with two integers X (0 < X ≤ 100) and Y (0 < Y). The first one is the number of points and the second, the number of tunnels. Then, the next Y lines are followed by three integers: A (0 < A ≤ 100), B (0 < B ≤ 100) and C (0 < C), which means, there's a link between A and B with a capacity C of workers that can walk through there. After that, there's a line with only one integer which is the start point, in the other words, the point where the workers are divided. Output For each test case, display its case number followed by a blank line. In the next line display the number Z of points that can be used as a collection point and, in the next Z lines shows in decreasing order the maximum number of workers that can be used. Each test case is separated by a blank line as the sample output. Example Input: 45 125 148 233 2 4 11 346 1 56 125 148 233 2 4 11 346 4 5 12 2 Output: Case 1 Points: 3 13 13 9 Case 2 Points: 1 19
32,717
Enemies (ENEM) Gangs are a big problem for every metropolis. Individuals that are member of some gang usually make enemies. When enemies meet each other they always want to fight, which makes the city a dangerous place to live. These gang members are also known as fighters. The local Police Department received anonymous information about a huge meeting between fighters at the central park, but the police chief, as always, wants to know if it is worth to send some of his men there. He knows that a fighter will fight one of his enemies only if all of them are in front of him. If one of the fighters doesn’t want to fight, then the meeting will be canceled. Moreover, each fighter can fight just one enemy at a time, and during this fight his other enemies wait, because they all want to beat him alone. He also knows that one police officer is enough in order to prevent two fighters from start a fight. Given these conditions and the enemy’s relationships of the fighters that will be at the central park, your job is to tell the chief if the meeting will happen or will be canceled. If it is going to happen, then the chief wants to know the minimum number of policemen he needs to send in order to prevent the fights at any moment of the meeting. Input Each test case is described using several lines. The first line contains two integers F (1 ≤ F ≤ 60) and R (1 ≤ R ≤ 1770) representing the number of fighters at the meeting and the number of enemy relationships, respectively. The fighters are identified by different integers from 0 to F - 1. Each of the next R lines contains two integers A and B representing an enemy relationship between the fighters A and B. You can consider that each enemy relationship will appear once in each test case and that if a fighter A is enemy of a fighter B then B is also enemy of A. The last test case is followed by a line containing F = 0 and R = 0. Output For each test, output in a line the minimum number of policemen necessary in order to prevent the fights or output ‘The meeting will be canceled’ if the meeting is going to be canceled. Example Input: 4 4 0 2 0 3 1 2 1 3 6 7 0 2 0 3 0 4 0 5 1 2 1 3 1 4 3 3 0 1 1 2 2 0 0 0 Output: 2 2 The meeting will be canceled
32,718
Portal (PORTALUN) You, as the newly recruited mad scientist at Aperture Laboratories, has been challenged by GLaDOS to a game that will test a new type of Portal! The invention is a series of portals, to each of which is assigned a priority. One can only move from a portal with higher priority to another with lower priority. The game consists of moving the test subjects through the rooms of Aperture Science Enrichment Center. You and GLaDOS alternate turns: at each turn a player must move one of the subjects to a new room using the new portal prototype. Since her disastrous experiment with Chell, GLaDOS has decided not to hand over handheld portal devices to guinea pigs, so the portals have already been placed in the rooms, and their priority is the same priority associated to their room. This way, one can only move from a room to another if there are portals connecting them and the priority of the destiny room is lower than the current room's. The loser will be the player who has no valid move and thus, is doomed to receive no cake and possibly die in a fire. Input The input consists of several test cases. The first line of each test case will begin with two integers N, M denoting the number of rooms and the number of portal connections, 0 < N ≤ 1000 and 0 ≤ M ≤ N (N − 1)/2. Rooms are numbered from 0 to N − 1, and their priority is the same as their number. Then follows M lines describing the connections between two rooms. Each line contains two integers corresponding to rooms connected by portals. The next line contains an integer K , 1 ≤ K < N , denoting the number of test subjects. Two or more subjects may occupy the same room. Next K lines contain the room numbers where the subjects have been allocated. Output For each test case, assuming both you and GLaDOS play perfectly and you are the first player to make a move, print "I win" if you are victorious and "I lose" otherwise. Example Input: 9 14 0 1 0 2 0 3 1 2 2 3 1 4 2 5 5 3 4 5 4 3 5 6 6 7 7 8 8 6 3 3 5 8 Output: I lose
32,719
King (KING) The Nlogonia Kingdom needs a new king. Differently from other monarchy kingdoms, where the king’s choice is hierarchical, at Nlogonia any citizen can apply for the post and the whole population can vote on those who applied. However, with these conditions, a big problem arises: every citizen would probably apply and vote for itself. In order to solve this problem the Nlogonia council decided to split the voting process in two phases. In the first phase, known as constraint phase, every citizen must write two constraints about another two candidates. A constraint can be of one of the following two types: a reliability constraint, which means that the citizen trusts another citizen and wishes that it takes place in the second phase of the voting process; an unreliability constraint, which means that the citizen doesn’t trust another one and wishes that he doesn’t take place in the second phase of the process. The council decided that at least one of the constraints of every citizen must be satisfied in order to choose the group of candidates that can go forward to the second phase. The citizen cannot give itself a reliability constraint. The second phase of the process is a simple voting process where every citizen chooses between one of the candidates that remained from the first phase. Your job is to determine if it is possible to satisfy at least one of the two constraints of every citizen, even if it means that no candidate remains for the second phase, in this case the council decides who must be the king. Input Each test case is described using several lines. The first line contains one integer N representing the number of citizen in the Nlogonia Kingdom (3 ≤ N ≤ 1000). The candidates are identified by different integer from 0 to N-1. Each of the next N lines describes the two constraints of a citizen, and each one starts with an uppercase letter that is either ‘R’ or ‘U’, where ‘R’ indicates a reliability constraint and ‘U’ indicates a unreliability constraint, followed by a integer C (0 ≤ C < 1000) representing the candidate that the citizen gave the constraint. The two constraints will be separated by single space. The last test case is followed by a line containing one zero. Output For each test, use the output uppercase ‘Y’ if it is possible to satisfy at least one constraint for each citizen and ‘N’ if it is not. Example Input: 3 R1U0 U2R1 R2R0 4 R1U0 R0U1 R0R1 U0U1 0 Output: Y N
32,720
Decoding Number Stations with Dr Whooves (PONY2) Dr. Whooves has been holed up in his laboratory, analyzing radio transmissions. Specifically, he has been listening to a very odd transmission - it is just somepony reading a bunch of numbers! There are several of these stations, and Dr. Whooves wants to know what they are trying to hide. He is going to try to decrypt the messsages, and after a lot of study, he has discovered a special number N for each transmission, which will let him discover the true message. He knows that numbers correspond to letters in exactly the following way: a = 1, b = 2, c = 3, ..., z = 26. So for a message, there are many possible decodings, just based off of that. This is where the special number comes in. If Dr. Whooves sorts all the possible decodings lexicographically, then the secret message is the Nth lexicographic decoding. For a given input, output the Nth lexicographic decoding. However, Dr. Whooves realized that he can't type very quickly, so you'll have to make the program yourself. Input Format An integer T, followed by T lines of the form S N where S is a string of digits, and N is an integer for which you are to report the Nth lexicographic possibility. You are guaranteed that S can be parsed in at least 1 way, and that N is a valid number. That is, if there are only 5 ways to parse S, then N will be between 1 and 5. It is further guaranteed that the total number of ways to parse S will fit into a 64 bit signed integer, and that the length of S will be less than or equal to 100. Output Format On T separate lines, output the N_i'th lexicographic valid string. Example Input: 2 1111 4 1111 5 Output: kaa kk
32,721
Monkey and apples (MON2012) Monkey Chris loves apples. That's why he has planted lots of apple trees. He does two types of operations on this trees. First operation " 1 x y ": means counting ripe apple trees on interval [x+c, y+c]. Second operation " 2 x y ": means that all apples on interval [x+c, y+c] get ripe (edible). C=0 in the beginning and becomes the answer of each query ("1" operation). Input Input begins with M (1 ≤ M ≤ 10 5 ) the number of operations. Afterwards M lines each of them is an operation ("1" or "2"). 1 ≤ X+C; Y+C ≤ 10 9 . Example Input 3 2 5 8 2 7 10 1 1 10 Output 6 Explanation 3 queries. Apples gets ripe on intervals 5-8 and 7-10. There are totally 6 ripe apple-trees on interval 1-10 so answer to query is 6.
32,722
Counting Formations (FORMAT1) With the coming release of Marcohard Balconies 100 operating system, people are more and more interested in its new UI (User Interface), code-named “Subway”. This UI presents your desktop as a grid that is divided into N rows and M columns (so you have N * M cells). In each cell, you can place one icon of an application of a certain type. Your applications can be of one of K types, numbered 1 through K. You’re an expert in this field, so it is assumed that there is an unlimited number of applications of each type. Any placement is called an icon formation. Some of the icon formations are beautiful. An icon formation is called beautiful if and only if no pair of rows are similar. Two rows are similar if and only if for each X that 1 <= X <= K , they contain exactly the same number of applications of type X . Given N , M , and K , you should solve for the number of different icon formations that are beautiful, modulo 10 9 +7. Two formations are different if and only if there is a cell where the type of application in one formation is not the same as the type in another formation. You may assume that 1 <= N , M , K <= 50. Input There are several test cases. For each test case there are 3 integers, named N , M , K , in a single line. Please process until EOF (End Of File). Output For each test case, please print a single line with a integer, the corresponding answer to this case. Example Input: 2 2 2 5 3 2 3 5 7 Output: 10 0 894953467
32,723
Balanced Numbers (BALNUM) Balanced numbers have been used by mathematicians for centuries. A positive integer is considered a balanced number if: Every even digit appears an odd number of times in its decimal representation. Every odd digit appears an even number of times in its decimal representation. For example, 77, 211, 6222 and 112334445555677 are balanced numbers while 351, 21, and 662 are not. Given an interval [A, B], your task is to find the amount of balanced numbers in [A, B] where both A and B are included. Input The first line contains an integer T representing the number of test cases. A test case consists of two numbers A and B separated by a single space representing the interval. You may assume that 1 ≤ A ≤ B ≤ 10 19   Output For each test case, you need to write a number in a single line: the amount of balanced numbers in the corresponding interval Example Input: 2 1 1000 1 9 Output: 147 4
32,724
Delivery (TWODEL) Fast Delivery Corporation built one of its offices right in the middle of the longest straight street in Cuba in order to satisfy every order of those customers who live along that street. The addresses of the houses to which the merchandises are distributed are represented by integer numbers which represent the distance between the office and the corresponding houses. If we consider that the office is located at position 0, then the positive addresses are located to the right of the office, and the negative addresses are located to the left of the office.  The delivery orders are satisfied in the same order in which they were received. Fast Delivery Corporation has assigned two employees to the new office. Those employees are in charge of distributing the merchandises. At the beginning of the day, the orders are shared between both employees.  The corporation wants to share the orders between the two employees in such a way that the total distance required to deliver all the merchandise is minimized . Input Line 1: a single integer N (1 ≤ N ≤ 100,000) representing the number of orders The next N lines contain an integer representing an address where a merchandise will be delivered. The distance between the office and any house is not greater than 10 8 Output A single line: the minimum distance the two employees have to travel to satisfy every order. Example Input: 5 1 -1 2 -2 3 Output: 5 Note : The naive greedy doesn't work. Also remember that the deliveries must be satisfied in the same order they appear in the input.
32,725
Unique Strings (UNICA) Some people who love strings have decided to call a special group of strings as the ” unique strings ”. Let’s define a(S) as the number of characters “a” the string S contains, and b(S) as the number of characters “b” the string S contains. S is a unique string if: S only contains the characters “a” and “b” For every substring S’ of S, | a(S’) – b(S’) | ≤ 3 For example, “abbab” is a unique string. However, “abbbba” is not because it includes the substring “bbbb” for which | a(“bbbb”) – b(“bbbb”) | = 4 > 3. Let’s say we sort the unique strings – first by length and then lexicographically . The N th unique string is the string that appears in the position N in the sorted list. The first unique string is assigned the number 1. The first 12 unique strings in the sorted list are: a, b, aa, ab, ba, bb, aaa, aab, aba, abb, baa, bab Input A single number N (1 ≤ N ≤ 10 14 ). Your task is to find the N th unique string in the sorted list. Output A single line: the N th unique string in the sorted list. Example Input: 10 Output: abb Input: 19 Output: abab
32,726
Ranges (RRANGE) There are N contiguous cells numbered from 1 to N. Initially, each cell contains a 0 in it. A sub-contiguous group of cells can be updated this way: A range [i, j] is defined such that i < j The cell numbered i is added 1; the cell numbered i + 1 is added 2, and so on until the cell numbered j is reached and added j – i + 1 For example, if N = 7 and the updates [3, 6] and [4, 7] were performed, this is what would happen. Initially: {0, 0, 0, 0, 0, 0, 0} Update [3, 6]: {0, 0, 1, 2, 3, 4, 0} Update [4, 7]: {0, 0, 1, 3, 5, 7, 4} After performing some update operations, it would be amazing to answer questions like the following: A range [u, v] is defined such that u < v. The answer is the sum of every cell in the range [u, v] (both u and v are included) modulus 10,000. Given N and U updates ranges. You have to write a program capable of answering Q questions. Input The first line contains three integers: N (1 ≤ N ≤ 1, 000,000,000), U and Q (1 ≤ U, Q ≤ 1, 000), representing the number of cells, the number of update operations, and the number of questions respectively. Each of the following U lines contains two integers i and j (1 ≤ i < j ≤ N) separated by a single space indicating an update operation. Each of the following Q lines contains two integers u and v (1 ≤ u < v ≤ N) separated by a single space indicating a question. Output For each question [u, v] you must print the sum of all contiguous cells starting at u and ending at v modulus 10,000. Example Input: 7 2 2 3 6 4 7 4 6 1 7 Output: 15 20
32,727
Funny Areas (FUNAREA) There is an M x N matrix of integer numbers.  Both the rows and columns of the matrix are numbered starting at 0 and ending at M-1 and N-1 respectively. A funny area is defined by three integers i, j, and r, and it is composed for those cells [x, y] such that |i-x| + |j-y| <= r. As you might have probably guessed  [i, j] is the center and r is the radius of the funny area. In this problem we are interested in finding the sum of every cell inside some given funny areas. Input The first line contains two integers 1 <= M, N <= 1000 representing the rows and columns of the matrix. Each of the following M lines contains N integers separated by single spaces. These numbers are non-negative and not greater than 1,000,000,000 The next line contains a number F (1 <= F <= 100,000) which is the number of funny areas. Each of the following F lines contains three integers i , j , and r representing the center and the radius of a funny area. Output F lines: for each funny area print a single number -- the sum of all the cells inside of it. Example Input 5 5 1 2 3 4 5 5 4 3 2 1 1 1 1 1 1 2 3 4 3 0 7 8 9 6 5 3 1 0 0 2 2 2 3 1 1 Output 5 36 18
32,728
KNJIGE (KNJIGE) Mirko has a home library consisting of N books arranged one on top of the other in a narrow cabinet. Since being well trained in the secrets of alphabet in the previous task, he now wishes to arrange the books alphabetically, so that the book whose title comes first alphabetically ends up on top, and the alphabetically last one at the bottom of the pile. Mirko can easily pull a book out of the cabinet, but it is difficult to push it back into the pile, so the book can only be returned to the top of the pile. Thus, the only available method of sorting the books is repeatedly pulling a book out of the pile and placing it on top of the pile. The books are labelled with integers from 1 to N, in alphabetical order. Therefore, Mirko wants them to be ordered as (1, 2, ..., N), counting from the top. For example, if N = 3 and the starting order is (3, 2, 1), two moves are sufficient. First, he pulls out the book number 2 and places it on top, so the pile becomes (2, 3, 1). After that, he does the same with book number 1, thus the pile becomes (1, 2, 3). Help Mirko by calculating the minimum number of moves needed to sort a given starting order. Input The first line of input contains the integer N (N ≤ 300 000). Each of the next N lines contains a single positive integer. These N integers represent the order of Mirko’s books from top to bottom of the cabinet. Each of the integers 1, 2, ..., N appears exactly once. Output The first and only line of output must contain the required minimum number of moves. Example Input: 3 3 2 1 Output: 2
32,729
MONO (MONO) Mirko soon realised that number sequences are not the best career choice, and went right back to letter table business. Mirko’s table has R rows and C columns and consists of lowercase letters. Each cell of the table is a square of equal size. We assign coordinates to vertices of those squares, so that upper-left corner of the table has coordinates (0, 0), upper-right (C, 0), lower-left (0, R), and lower-right (C, R). We say that polygon within the table is monoliteral if the following holds: its vertices are from the described set of cell-square vertices, its edges are parallel to coordinate axes, all letters inside the polygon are equal. A simple polygon for which first two conditions are true (third one may or may not be true) is given. Mirko would like to know the number of monoliteral polygons that can be obtained by moving the given one up, down, left, or right or any combination thereof, but not rotating. Input The first line of input contains two space separated integers R and C (1 ≤ R, C ≤ 500). Each of the next R lines contains exactly C lowercase letters, this is Mirko’s table. The following line contains integer V (4 ≤ V ≤ 500), number of vertices of given polygon. Each of the next V lines contains two integers X, Y (0 ≤ X ≤ C, 0 ≤ Y ≤ R). These are the coordinates of the vertices of the given polygon. Vertices are given in clockwise order. The given polygon will satisfy conditions 1 and 2 from above. Output In the first and only line of output, print expected number of polygons. Examples Input: 3 3 aaa aaa aaa 4 2 0 2 2 0 2 0 0 Output: 4 Input: 3 3 aaa aba aaa 4 2 0 2 2 0 2 0 0 Output: 0 Input: 5 4 xyyx xyyy xxyy xxxx xxxx 8 1 3 1 2 0 2 0 0 2 0 2 1 3 1 3 3 Output: 2
32,730
DIFERENCIJA (DIFERENC) Mirko discovered what Slavko did in previous task, and decided to deal with something completely opposite to tables of letters: sequences of numbers. Let’s define a value of a sequence as the difference between the largest and the smallest number within that sequence. For example, value of sequence (3, 1, 7, 2) is 6, and value of (42, 42) is 0. Find the sum of values of all subsequences of consecutive elements of a given sequence. Input The first line of input contains a single integer N (2 ≤ N ≤ 300 000), number of elements of the sequence. Next N lines contain elements of the sequence. Each element is a positive integer not greater than 100 000 000. Output The first and only line of output must contain the requested sum. Example Input: 3 1 2 3 output: 4 Input: 4 7 5 7 5 Output: 12 Input: 4 3 1 7 2 Output: 31
32,731
ZNANSTVENIK (ZNANSTVE) In this economy, we all know how hard it is to get a job. Mirko, a recent college graduate, however, got lucky - he is now employed as a runeologist by the Language Institute of Croatia. His friend Slavko believes runeology isn’t a science and is hence angry at Mirko for believing the opposite. One foggy Christmas day, Mirko’s laptop broke. Since he isn’t great with computers, he gave it to Slavko to repair it. Slavko, feeling a little naughty, decided to mess up a particular file Mirko was working on. This file contains a matrix of R rows and C columns. Each element of the matrix is a single letter. No two columns of the matrix are equal. To have some fun with pseudo-scientist Mirko, Slavko decided he will delete as many rows as possible from the top of the table, without breaking the no-equal-column rule. Input The first line of input contains two integers R and C (2 ≤ R, C ≤ 1000), the number of rows and the number of columns, respectively. In each of the next R lines there are C lowercase letters of the English alphabet. These R x C letters represent Mirko’s table (which does not have two columns the same.) Output Output a single integer, the maximum number of rows which can be deleted from the top of the table so that no two columns are equal. Example Input: 2 6 dobarz adatak Output: 0 Input: 3 4 alfa beta zeta Output: 2 Input: 4 6 mrvica mrvica marica mateja Output: 1
32,732
Count on a tree (COT) You are given a tree with N nodes. The tree nodes are numbered from 1 to N . Each node has an integer weight. We will ask you to perform the following operation: u v k : ask for the kth minimum weight on the path from node u to node v Input In the first line there are two integers N and M . ( N, M ≤ 100000) In the second line there are N integers. The ith integer denotes the weight of the ith node. In the next N-1 lines, each line contains two integers u v , which describes an edge ( u , v ). In the next M lines, each line contains three integers u v k , which means an operation asking for the kth minimum weight on the path from node u to node v . Output For each operation, print its result. Example Input: 8 5 105 2 9 3 8 5 7 7 1 2 1 3 1 4 3 5 3 6 3 7 4 8 2 5 1 2 5 2 2 5 3 2 5 4 7 8 2  Output: 2 8 9 105 7
32,733
The Blind Passenger (MYQ1) The seats of an Ultra Deluxe Semi-sleeper bus in Thuvax country are numbered according to the following rules: Seat number 1 is reserved for the bus conductor. Remaining seats are numbered as shown in the figure below. The seating arrangement is as shown below. RowNo Left   Right W  A   A  M  W                         01 1     02 03  04 05 06 2     11 10  09 08 07 3     12 13  14 15 16 4     21 20  19 18 17 5     22 ............   A blind person enters the bus with a reservation ticket mentioning his seat number. He meets you at the start of the passage and shows you his ticket. Based on the seat number, help him find his seat by telling him the row number (1, 2 ...), seat position (window or aisle or middle), and the direction (left or right). Input First line contains a positive integer t (t <= 10 5 ) denoting the number of test cases. Each of the next t lines contain a positive integer n (n <= 10 9 ) denoting the blind person's seat number. Output Output one line for every test case in the following format: If the seat number is same as the conductor's seat, print " poor conductor " else, print row_number: represents the row number from the entrance (a positive integer)   seat_position: can be one of "W" or "A" or "M" for window, aisle and middle respectively. direction: can be either "L" or "R" for left or right respectively. Example Input: 3 1 2 3 Output: poor conductor 1 W L 1 A L
32,734
The Wild Wizard (MYQ2) In the country of Thuvax lived an old wizard named Chanithpra. He practiced a form of magic in which the power of spell came from the letters that were written on a piece of parchment. When a sentence s is written, the intensity of the letters are as follows: Intensity of 'a' is 1, 'b' is 2 and it continues until 'z' whose intensity is 26. Intensity of 'A' is 51, 'B' is 52 and it continues until 'Z' whose intensity is 76. Intensity of ' ' (space) is 32. The power of a spell written as a part of the sentence is equal to the sum of the intensities of the characters present in it modulo m. Chanithpra finds an old parchment in Thuvax with a sentence s written on it. Help him find the longest spell (i, i+1 ... j) in the sentence s whose power matches with k. (0 ≤ i ≤ j < length of s) You need to print the starting index i (0 ≤ i ≤ length-1) of such a spell in the sentence and the length of the spell. If there are multiple such spells, find the minimum index i and if there is no such spell print -1. Input The first line contains a single positive integer t (1 ≤ t ≤ 100) denoting the number of test cases. Each test case consists of 2 lines: the first line consists of the sentence s (1 ≤ length of s ≤ 1000000). The second line consists of two integers m and k (2 ≤ m ≤ 1000007 and 0 ≤ k < m). Output For each test case, output one line containing 2 integers. The first is the minimum index i (0 ≤ i ≤ s.length-1). The second is the length of the spell. If no such spell is present, print -1. Example Input: 1 Hello World 10 7 Output: 0 7
32,735
The Dating Dress Problem (MYQ3) Gauthami has to get dressed for a date. She is going to meet Prasanna in the poshest restaurant in the country of Thuvax. Prasanna arrives early and sees the outfit she has picked.   While waiting outside, Prasanna being a restless nerd calculates the number of ways she can get dressed.   The complete outfit she picks is represented as a string of digits. The digits represent the following details about the apparel: (apparel = clothing or accessories or any other part of the outfit)   1 - a 2 piece apparel where first piece has to be worn before the other. It is followed by the description of the two pieces in order.   2 - a 2 piece apparel which can be worn in any order, and it is not necessary to complete one apparel before starting another one. It is followed by the description of the two pieces in order.   0 - a single piece of apparel which can be put on directly.   Help Prasanna calculate the number of ways in which Gautami can get dressed. Since Prasanna does not want to make Gauthami bored by telling her a huge number, he wants to tell her the number of ways modulo 1000000007.   For example, consider an outfit comprising of a shirt, a skirt into which the shirt has to be tucked in and   a neck cloth worn over the shirt. It will be represented as 10200 and the number of ways she can get dressed is 2(She has to wear the shirt first after which she can wear either the skirt after the neck cloth or neck cloth after the skirt). Input   First line is a positive integer T (T<=100) representing the number of testcases  It is followed by T lines, each containing a string S of digits (each digit will be one of 0,1,2) describing the outfit, 1<=|S|<=100,000 The complete outfit comprises of a single item. First line is a positive integer T (T<=100) representing the number of testcases  It is followed by T lines, each containing a string S of digits (each digit will be one of 0,1,2) describing the outfit, 1<=|S|<=100,000 The complete outfit comprises of a single item.   Output Output for each test case should consist of one line representing the number of ways in which Gauthami can get dressed modulo 1000000007. Example Input: 3 10200 0 1102000 Output: 2 1 2
32,736
The Nerd Factor (MYQ5) Prof.Venky handles Advanced Topics in Algorithms course for a class of 'n' students. He is always known for his unsolvable question papers. Knowing that it is impossible to pass his subject in a fair manner, one of the students of his class, Vishy, finds out from his seniors that Prof.Venky won't be able to find out if at least 'k' students together discuss and write the answers and thereby all of them can pass. Hence they decide to divide the whole class into a number of groups so that everyone passes. But all the students are fighting over forming the groups. So Puppala, one of the nerdy students in the class, decides  that he will compute all possible ways that they can form the groups and number them, and finally choose one of those numbers at random and go ahead with that way. Now it is your duty to help Puppala find the number of  ways that they can form such groups.  Pupalla is incapable of reading big numbers, so please tell him the answer modulo 10^9+7. Input The first line contains the number of test case t(1<=t<=10^6). Followed by t lines for each case. Each test case contains two integers 'n' and 'k' separated by a space(1<=k,n<=1000) Output For each test case, print a single line containing one positive integer representing the number of ways modulo 10^9+7 . Example Input: 3 2 1 4 2 6 2 Output: 2 2 4
32,737
Serve The Street (MYQ6) Shree is a very ambitious person and wants to start a new company "RAM COURIER SERVICE" in the country of Thuvax. He plans to open his first office in the Main Street of Thuvax to serve only the people of this street. The Main Street is an inclined road consisting of N buildings spaced out unevenly (building 1 at lowest level and building N at highest level). The distance between adjacent buildings are known to Shree. The delivery costs incurred by him for various deliveries are calculated as follows: To deliver a package of weight 'w' to a building downhill at a distance 'd' from the office, Shree spends w*d*1 units of money. To deliver a package of weight 'w' to a building uphill at a distance 'd' from the office, Shree spends w*d*2 units of money. To deliver a package of non-zero weight to his own building, Shree spends 10 units of money irrespective of the weight of the package. Shree being an astute businessman wants to choose one of these buildings for his new office so that the total delivery cost incurred by him is minimum. Help Shree choose the building for his new office. Input The first line of the input consists of number of test cases t (1 <= t <= 20). The first line of each test case consists of a single number N (1 <= N <= 10^6) which is the number of buildings in the main street. The next line contains N integers representing the weight to be delivered at i th (1 <= i <= N) building (0 <= w[i] <= 100). The last line contains N-1 integers where the i th (1 <= i <= N-1) integer represents the distance between i and i+1 th building (1 <= d[i] <= 100). Output Output a single line for each test case containing two integers separated by a space. The first integer is the minimum delivery cost and the next integer is the building number where the office should be placed in order to incur that cost. If more than one building has the same minimum cost, print the building labelled with the smallest number. Example Input: 1 5 1 2 3 4 5 1 1 1 1 Output: 30 4
32,738
The Rail Network Renovation (MYQ7) The beautiful country of Thuvax has an ancient rail network connecting its 'n' cities using 'm' tracks. The King of Thuvax orders the Railway Minister, Poopsie to renovate the whole rail network. Due to Poopsie's past laziness, the tracks are in shambles and so he wants to rebuild (the tracks are functional again) some of the tracks and destruct (therefore, wont be available for usage) the rest completely.   The King wants to ensure that all the cities are connected after the whole network is renovated but being a miser, he wants to spend the least amount of money possible.   Help Poopsie find out the least amount of money using which the renovation project can be completed. Input The first line of the input contains the number of test cases 't' (1<=t<=100).   The first line of each test case consists of two numbers: number of cities 'n' (1<=n<=10^3) and number of tracks 'm' (0<=m<=10^6). The next m lines contains description of each of the tracks and their corresponding costs of destruction and rebuilding. Each of these m lines contains four integers 'a', 'b', 'd' and 'r' (1<=d, r<=1000000) representing a track between city 'a' and city 'b' with the cost of destruction and rebuilding being d and r respectively (cities are numbered from 1 to n). Output The output consists of t lines. For each test case, print a single line consisting of a single integer that is the least amount of the money required to renovate the whole rail network. Example Input: 1 4 4 2 1 7 8 3 2 4 6 4 2 2 4 1 4 3 5 Output: 21
32,739
The National Game (MYQ8) Prasanna and Nithin had mastered Thuvax's national game, Tic-Tac-Toe . Tic-Tac-Toe is a board game for two players, x and o, who take turns (alternatively) marking the spaces in a 3×3 grid with their signs 'x' and 'o' respectively. The x player goes first. The player who succeeds in placing three of his signs in a horizontal, vertical, or diagonal row wins the game and the game stops there. While returning from a Tic-Tac-Toe tournament, Prasanna and Nithin find a Tic-Tac-Toe like grid. They decide to continue playing from the state the board was in. Help Nithin find whether the next person to move will win/lose or whether the game will result in a tie (assuming both players play optimally), or if such a state is invalid. Input First line of the input contains a number T (1 ≤ T ≤ 10 6 ), followed by 4×T lines. The first line of each test case is empty and the next 3 lines show the state of the game. Output Print win/lose/tie/invalid for each testcase on a separate line. Example Input: 3 oox .x. ..x xox xoo oxx o.. ... ... Output: lose tie invalid Explanation Case 1: Player x can win by placing x in either last cell of the middle row, or the first cell of the last row. So the next player, o, cannot prevent him from winning from this state. Case 2: It is completed game, as you can see no one has won. So, it has ended in a tie. Case 3: Player x should have started the game. Hence such a state can never be reached.
32,740
Divide And Conquer (MYQ9) The King of Thuvax decided to conquer the neighbouring country of Silicon Valley. In order to conquer  a country, he has to successfully invade every city in the country. But he always doesn't get into action unless he plans it properly. He knows that severing a city's communications with all other cities before invading it is the only way to conquer it. He has the information regarding how the cities communicate with each other through his spy. The spy has lived in Silicon Valley right from the time when it was a single city, much before its development into a country. He gives information about how every new city established communication links with other cities. The spy's information is represented as below. Every city can establish its communications with the help of only one other city. It can do it in one of the three ways. Type 1 - It can establish a single communication link with another city 'c'. Type 2 - It can establish communication links with all cities that communicate with another city 'c', but it can't have a communication link with 'c'. Type 3 - It can establish communication links with all cities that communicate with another city 'c' and with 'c' also. All communication links are two-way. Having this information, he finds out that it is not possible for him to invade Silicon Valley in a fair way. So he hires a terrorist gang to bomb some cities and destroy them so that he can invade the country successfully. But the terrorists demanded a huge amount of money for bombing a city. Help the King to find out the minimum number of cities that should be bombed so that he can conquer the country of Silicon Valley successfully. Input The first line consists of number of test cases t (1 <= t <= 10) The first line of each test case consists of the number of cities n (1 <= n <= 10^4) in Silicon Valley. Each of the next n-1 lines consists of two integers x and c. The ith (1 <= i <= n-1) line represents that city i+1 establishes a type 'x' communication link with the help of the city 'c' (1 <= c <= i). (The country initially contains city 1 alone.) Output Output one line for each test case containing the minimum number of cities that should be bombed so that the King can conquer the country. Sample Input 2 2 1 1 3 1 1 3 1 Output 1 2 Explanation Here city 2 has communication links with city 1. So to conquer the country, The King has to bomb one of these cities and then invade the remaining city. Here city 2 has communication links with city 1 and city 3 establishes communication links with city 1 and city 2. So The King has to bomb any of these two cities and then invade the third city to conquer the country.
32,741
DUGDUG (DUGDUG) Dug Dug is a sweet and cute girl who just loves to eat sweet and chocolates but only those which I used to gift her. One day I just said that "DUG DUG you are sweet and also like sweet". I will give you as many sweets as you want but you have to tell me the number of ways you can exchange the words in the sentence such that the sentence is not changed. Note that you can exchange one or more pair of words in the sentence simultaneously but all those pairs should be of different words. Dug Dug was confused. She got angry and said if you want to give the sweet then give otherwise go from here. I said "I i will, i i i will give". She got the chocolates but you will not get it easily. Your task is to find out the number of ways words in a sentence can be exchanged without changing the sentence. Note - one or more pair of words in the sentence can be exchanged simultaneously but all those pairs should be of different words. Input Input will consists of several lines each containing a sentence consisting of not more than 5000 characters. Output For each line of input out a single integer denoting the number of ways in which words in a sentence can be exchanged without changing the sentence. Example Input: DUG DUG you are sweet and also like sweet I i will, i i i will give Ok done you will get what you want Done !!!!!!!! Output: 3 13 1 0 Explanation: For the first sentence "DUG DUG you are sweet and also like sweet" there are three ways - 1) You can change the first "DUG" with second "DUG" 2) You can change the first "sweet" with second "sweet" 3) You can change the first "DUG" with second "DUG" and first "sweet" with second "sweet".
32,742
Mirror Number (MYQ10) A number is called a mirror number if on lateral inversion, it gives the same number i.e. it looks the same in a mirror. For example 101 is a mirror number while 100 is not.  Given two numbers a and b, find the number of mirror numbers in between them (inclusive of a and b). Input First line contains T, number of test cases ≤ 10 5 . Each test case is described in a single line containing two numbers a and b. 0 ≤ a ≤ b ≤ 10 44 Output For each test case print the number of mirror numbers between a and b in a single line. Example Input: 3 0 10 10 20 1 4 Output: 3 1 1
32,743
PASIJANS (FLLM) Pasijans, patience, or solitaire is the name for a group of single player card games. One new such game, so new it has no name, is played with cards sporting random integers as values. The game starts by shuffling all cards and distributing them in N sequences, not necessarily of equal length. During each turn, the player can remove the first card in any sequence and place it at the end of the “Solution sequence”. The card that was second in the selected sequence now becomes the first and the turn ends. Of course once the card is in the “Solution sequence” it cannot be removed, replaced or altered in any way. So don't even try. The game ends when all cards are in the “Solution sequence”. The object of the game is to construct the best possible “Solution sequence”. One sequence  is better than the other if for the first cards they differ, lets call them X and Y, the value on the card X is smaller than the value on the card Y. Write a program that finds the best possible “Solution sequence”. Input The first line contains one integer N (1 ≤ N ≤ 1000), number of starting sequences. Next N lines contain description of input sequences. Each line starts with an integer L (1 ≤ L ≤ 1000), length of the sequence. It's followed by L integers, smaller than 100.000.000. Output One line containing ΣL numbers, the best possible “Solution sequence” obtainable. Example Input: 3 1 2 1 100 1 1 Output: 1 2 100
32,744
GENIJALAC (IWGBST) Mirko is a genius. But the purpose of his inventions is not always obvious. His latest invention, the Shuffle-o-matic 3175, is one of those. The Shuffle-o-matic is used in a very special way. First Mirko places N paper cards, with numbers 1 to N printed on them, on the Shuffle-o-matic working surface. Then he inputs the shuffle sequence in the special input console and hits the go button. The machine than reads the paper cards and outputs the read sequence of numbers on its output tape. It than shuffles the cards according to the shuffle sequence. After that it reads the newly obtained sequence and writes it onto a new line on its output tape. Then it proceeds to shuffle the cards again according to the same shuffle sequence, scans and writes the output to the tape. The machine does this until it runs out of tape. After experimenting with the machine Mirko decided to rest a bit on the floor. There he noticed a piece of output tape. The piece is neatly cut just before the A-th output row and just after the B-th output row. It is also missing the first C number and the last D numbers in all rows. He now wonders how many rows on that piece of paper have the property that all numbers in the row, that are still on the paper, are in the exact same spot they were before all the shuffling began. Input The first line of input contains integers N, A, B, C and D in that order(1 ≤ N ≤ 500 000, A ≤ B ≤ 10^12, 0 ≤ C, D ≤ N, C + D < N). The second line contains the shuffle sequence. The sequence is given as a permutation of numbers 1 to N. If the k-th number in the shuffle sequence is x, after each shuffle the k-th element in the resulting sequence is the x-th element in the previous sequence. Output In the first and only line of input print the number of rows that have the property Mirko is looking for. Example Input: 4 1 5 0 1 1 3 4 2 Output: 2
32,745
0110SS (IWGBS) Dor is IWGolymp student so he has to count in how many ways he can make N digit numbers that is formed by ones and zeroes. But zeroes can not be next to each other. Help to him in how many different numbers can he make. For example, N = 3: 101, 010, 111, 110, 011 Note: A leading zero is allowed. Input A positive integer N (1 ≤ N ≤ 10000). Output Answer for the problem. Example Input: 2 Output: 3
32,746
Joseph’s Problem (NAGAY) Joseph likes taking part in programming contests. His favorite problem is, of course, Joseph’s problem. It is stated as follows.                            There are n persons numbered from 0 to n − 1 standing in a circle. The person number                            k, counting from the person number 0, is executed. After that the person number k of the                            remaining persons is executed, counting from the person after the last executed one. The                            process continues until only one person is left. This person is a survivor. The problem is,                            given n and k detect the survivor’s number in the original circle. Of course, all of you know the way to solve this problem. The solution is very short, all you need is one cycle:          r := 0;          for i from 1 to n do          r := (r + k) mod i;          return r; Here “x mod y” is the remainder of the division of x by y But Joseph is not very smart. He learned the algorithm, but did not learn the reasoning behind it. Thus he has forgotten the details of the algorithm and remembers the solution just approximately. He told his friend Andrew about the problem, but claimed that the solution can be found using the following algorithm:                            r := 0;                            for i from 1 to n do                            r := r + (k mod i);                            return r; Of course, Andrew pointed out that Joseph was wrong. But calculating the function Joseph described is also very interesting. Given n and k, find sum of (k%i) from i=1 to n; Input The input file contains n and k (1 <= n, k <= 10^18) Output Output the sum requested. Example Input: 5 3 Output: 7
32,747
DRIVE (BYTESB) Black Widow needs to get to the Avengers’ aid and fast. Stark may have lent her his new Audi but she forgot to fuel it up (people make all kinds of stupid mistakes, but if they look like Scarlet Johansson, who cares?). She needs to cross the next hill to get to her team but there’s only a little fuel left. So, obviously she’ll take the most efficient route. However, some parts of this route go uphill, some go downhill – each part with a different slope and different length. The fuel expenditure (per unit distance travelled) increases linearly with the driving speed v but there’s also an offset that depends on the slope s of the hill – let’s say when going downhill on a particular road, she might be able to go at 8 km/h without expending any fuel on the other hand, if she were to travel that same road uphill, she would expend fuel at the same rate as if she were driving 8 km/h faster along a flat road. The car’s fuel consumption c in litres per kilometer is given by c = max(0, a*v + b*s) where a: fuel expenditure rate on a flat road, v: speed in km/h, s: inclination of the road, b: positive constant. Acceleration and deceleration are instantaneous and do not cost any fuel. There is also a safe speed limit that she can’t exceed. How quickly can she get there? Input On the first line a positive integer: the number of test cases, at most 100. After that per test case: One line with four floating point numbers a (0.1 <= a <= 100), b (0.1 <= b <= 100), vmax (10 <= vmax <= 200) and f (0 <= f <= 50): the standard (flat road) fuel consumption rate of your car, the slope factor, the maximum speed of your car in km/h, and the amount of fuel you have left in liters, respectively. One line with an integer r (1 <= r <= 10000): the number of road segments. r lines with two floating point numbers xi and yi (1 <= xi <= 1000, -1000 <= y <= 1000) each: the horizontal distance and height change (both in meters) of the i-th road segment. Each road segment has constant slope. Output One line per test case: the earliest time in hours in which you can make it to the town. It is guaranteed that if it is possible it will always be possible in <= twenty four hours. If impossible then output “IMPOSSIBLE” instead. Your output should have a relative or absolute error of at most 10 -6 . Sample Input 2 1.0 100.0 200.0 10 2 1000 0 1000 -1000 10.0 1.0 150 0.0 1 100.0 -100.0 Output 0.1141421356 1.414213562
32,748
Symmetry (SYM12) After taking a modern art class, Farmer John has become interested in finding geometric patterns in everything around his farm. He carefully plots the locations of his N cows (2 ≤ N ≤ 1000), each one occupying a distinct point in the 2D plane, and he wonders how many different lines of symmetry exist for this set of points. A line of symmetry, of course, is a line across which the points on both sides are mirror images of each-other. Please help FJ answer this most pressing geometric question. Input: Line 1: The single integer N. Lines 2..1+N: Line i+1 contains two space-separated integers representing the x and y coordinates of the ith cow (-10,000 ≤ x, y ≤ 10,000). Output: Line 1: The number of different lines of symmetry of the point set. Sample Input 4 0 0 0 1 1 0 1 1 Output 4 Explanation The four cows form the corners of a square. There are 4 lines of symmetry – one vertical, one horizontal, and two diagonal.
32,749
The Lazy Gamer (MYQ11) In the kingdom of Thuvax, a mobile game called Thuball became very popular. The description of the game is as follows: A mobile phone made in Thuvax has a screen made of X*Y pixels. Thuball is played by throwing a ball (of size 1 pixel) at an angle of 45 degrees from the bottom of the screen. The ball changes its direction if and only if it hits the left/right/top edge of the screen or an obstacle on its way. There are N fixed obstacles (of size 1 pixel each) on the screen. There are no obstacles in the bottom-most row of the screen. If the moving ball's edge comes in contact with an obstacle's edge, it gets reflected by 90 degrees. If the moving ball's corner comes in contact with an obstacle's corner, it is reflected by 180 degrees. In both reflections the obstacle doesn't move. There is a reflector of length L pixels placed below the bottom row, which reflects (akin to mirror reflection, i.e. 90 degrees) the ball incident on it. The game finishes only when the ball reaches the bottom row and the reflector is not present below it. The total distance (in pixels) travelled by the ball is the score attained during a round until the game finishes. If the game does not finish, the score is 0. Gosu, a Thuvaxian was very fond of this game. He had set the highest score in Thuball in his friend Visu's phone. Not happy with the situation where he didn't have the highest score, Visu decided to recruit you to do his dirty work. Visu is lazy and doesn't want to move the reflector after starting the game. But, he wants to ensure that he gets the highest score possible with a reflector of length L when its kept stationary in any position. Help Visu out by telling him the maximum score he can get without moving the reflector for Q different lengths. Input First line contains two integers X and Y, which are the height and width of the screen. (1 ≤ X, Y ≤ 1000) Second line contains the number of obstacles N followed by N lines with two integers xi and yi, position of each obstacle. Consider the bottom-left corner of the screen as origin and the top-right corner to have the coordinates: (X-1, Y-1). The next line contains Q, for the number of cases (for different lengths of the reflector). (1 ≤ Q ≤ 1000) Followed by Q lines with one positive integer L, representing the length of the reflector. Output For each query output the maximum score Visu can achieve without moving the reflector in a single line. Example Input: 3 4 1 2 3 1 3 Output: 6
32,750
The Great Escape (MYQ12) A map consists of N checkpoints (numbered from 1 to N) connected by M one way roads. A thief is at checkpoint S. He wants to move to checkpoint D. The police, guessing that the thief will move through the route that takes him the least time to reach D from S, have called for security alerts to be placed in all the roads of all such routes. The thief wants to reach D without passing through any of those security alerted roads in the least possible time. If there are multiple such routes, he wants to travel so as to cross a minimum number of checkpoints. Find the minimum time required by the thief to reach D from S, the minimum number of checkpoints in such a route and the number of such routes available. Since the number of such routes may be huge, print the number of such routes modulo 1000000007. Input The first line of the input consists of a single integer t representing the number of test cases (1 ≤ t ≤ 300) The first line of each test case consists of two integers N, M where N is the number of checkpoints and M is the number of roads. (1 ≤ N ≤ 500 and 1 ≤ M ≤ 10 4 ) The next M lines consist of three integers x, y, t where x and y represent that the road can be used to travel to checkpoint y from checkpoint x in time t (t ≤ 100) (1 ≤ x, y ≤ N) The last line contains S and D (source and destination). Output For each test Case, output a single line containing 3 integers x, y, z. Where x is the least amount of time needed to travel from S to D without using any of the security alerted roads, y is the minimum number of checkpoints in such a route and z is the number of such routes modulo 1000000007. If there is no such path print -1. Example Input: 1 3 3 1 3 2 1 2 2 3 2 4 1 2 Output: 6 3 1
32,751
Count on a tree II (COT2) You are given a tree with  N  nodes. The tree nodes are numbered from  1  to  N . Each node has an integer weight. We will ask you to perform the following operation: u v  : ask for how many different integers that represent the weight of nodes there are on the path from u to v . Input In the first line there are two integers  N  and  M . ( N ≤ 40000, M ≤ 100000) In the second line there are  N  integers. The i-th integer denotes the weight of the i-th node. In the next  N-1  lines, each line contains two integers  u   v , which describes an edge ( u , v ). In the next  M  lines, each line contains two integers  u   v , which means an operation asking for how many different integers that represent the weight of nodes there are on the path from  u  to  v . Output For each operation, print its result. Example Input: 8 2 105 2 9 3 8 5 7 7 1 2 1 3 1 4 3 5 3 6 3 7 4 8 2 5 7 8 Output: 4 4
32,752
VUK (NAGAY1) Vjekoslav the Wolf is running away from a bunch of blood hungry hunters. The hunters are smart and hide behind trees. Vjekoslav knows this, but doesn't know which trees. He would like to run to his comfortable, civilized cottage (as opposed to the hunters quite uncivilized den, yes I am rooting for the Wolf here) staying as far away as possible from any trees. The forest can be represented as a N by M gird. Let us mark empty meadow patches with '.', patches with a tree in the middle with '+', Vjekoslav's current position with 'V' and the position of his cottage with 'J'. Vjekoslav can run from his current patch to any other patch north, east, south or west from him, even if it contains a tree. If Vjekoslav is standing in R-th row and C-th column on the grid and there is a tree in the A-th row and B-th column then the distance between Vjekoslav and that tree is: |R-A| + |C-B| Help Vjekoslav find the best route to his cottage. The best route is any route that maximizes the minimal distance between Vjekoslav and all trees at any given moment. Note that Vjekoslav's cottage doesn't occupy the entire patch so that patch must also be included in the route. Input The first line of input contains integers N and M (1 ≤ N, M ≤ 500), grid dimensions. The next N lines contain M characters each: '.', '+', 'V', 'J'. Input will contain exactly one character 'V' and 'J' and at least one character '+'. Output Output a single integer, the minimal distance from a tree in the optimal route. Example Input: 4 4 +... .... .... V..J Output: 3
32,753
Easy Calculation (TRIGALGE) Find x such that Ax+Bsin(x)=C. Input The first line denotes T (number of test cases). 3T integers follow denoting A,B and C for every test case. (A >= B > 0). All Integers are less than 100000. Output T real numbers rounded to 6 digits one in each line. Example Input: 1 1 1 20 Output: 19.441787
32,754
String Subsequence (STRSEQ) Given a string of digits, find the smallest nonnegative integer that does not occur in the given string as a subsequence. The length of the string is between 1 and 100000, inclusive. Input The input consists of several lines (at most 200), each with a single string S, with between 1 and 10^5 digits. Output Print a single line for each string containing the smallest nonnegative integer that does not occur in the given string as a subsequence. Example Input 9876543210 21698921085321984125 12345678901 Output 11 7 22
32,755
Michel and the championship (CHAMPS) Michel is participating in a championship where each participant have p i (0<=i<=N-1) points. He knows for some pairs of participants an inequality between the points of each one, in the form p A -p B >= C. Now he wants to know if his data is correct, i.e., if its possible to assign points for each participant and satisfy all the inequalities. Input The input consists of several test cases (at most 150). The first line of each test case consists of two integers N and M (1<=N<=500, 0<=M<=5000). Then follow M lines of three integers A, B and C, indicating that p A -p B >= C (0<=A,B<=N-1, |C|<=20000). Output Print a single line for each test case with 'y' if the data is valid or 'n' if its not. Example Input 2 2 0 1 2 1 0 2 4 4 0 1 1 1 2 1 2 3 -2 3 0 1 4 4 0 1 1 1 2 1 2 3 -3 3 0 1 Output n n y
32,756
Trapezoid (TRAPEZBO) Consider two arbitrarily chosen horizontal lines. A trapezoid Ti between these lines has two vertices situated on the upper line and the other two vertices on the lower line (see figure below). We will denote by ai, bi, ci and di the upper left, upper right, lower left and respectively lower right vertices of the trapezoid Ti. A subset S of trapezoids is called independent if no two trapezoids from S intersect. Task Determine the cardinality of the largest independent set of trapezoids (the largest set means the set with most elements). Also find the count of different independent sets with maximum cardinality. Find this count modulo 30013. Input The first line of input contains one integer N – the number of trapezoids. Each of the next N lines contains four integers ai, bi, ci and di. No two trapezoids have a common vertex (corner). Output The only line of output should contain two numbers separated by space: firstly, the cardinality of the largest independent set; secondly, the count of different independent sets with maximum cardinality modulo 30013. Constraints 1 ≤ N ≤ 100 000 1 ≤ ai, bi, ci, di ≤ 1 000 000 000 Example The picture below is NOT an accurate representation. The trapezoids' top and bottom have been shifted up and down for visibility. Input: 7 1 3 1 9 4 7 2 8 11 15 4 12 10 12 15 19 16 23 16 22 20 22 13 25 30 31 30 31 Output: 3 8
32,757
Ra-One Numbers (RAONE) In the War between good and evil . Ra-One is on the evil side and G-One on the good side. Ra-One is fond of destroying cities and its G-one's duty to protect them..   Ra-One loves to destroy cities whose Zip Code has special properties. He says he loves to destroy cities which have Ra-One numbers as their Zip Code. Any number is Ra-one if the Difference between Sum of digits at even location and Sum of digits at odd location is One (1).. For eg... for 234563 is Ra-One number digits at odd location are 3,5,3 (unit place is location 1 ) digits at even location are 2,4,6 Diff = (2+4+6)-(3+5+3)=12-11 = 1. And 123456 is not Ra-One number diff = (5+3+1) - (2+4+6) = -4   G-One knows this about Ra-one and wants to deploy his Army members in those cities. 1 army member will be deployed in each city. G-one knows the range of ZIP-Codes where Ra-One might attack & needs your help to find out how many army members he needs. Can you help Him ? Input First line will have only one integer 't' number of Zip-Code ranges. it is followed by t lines Each line from 2nd line contains 2 integer 'from'  and 'to'. These indicate the range of Zip codes where Ra-one might attack. ('From' and 'to' are included in the range) NOTE: 't' will be less than 100. 'from' and 'to' will be between 0 and 10^8 inclusive. Output A single number for each test case telling how many army members G-One needs to deploy. each number should be on separate lines Example Input: 2 1 10 10 100 Output: 1 9 explanation: for 1st test case the only number is 10 for 2nd test case numbers are 10, 21, 32, 43, 54, 65, 76, 87, 98
32,758
G-One Numbers (GONE) The War of Evil vs Good continues and Ra-One and G-One continue to be on respective sides. After saving all the cities with Ra-One Numbers G-One realised that some cities whose population is a "G-One Number" can be easy target for Ra-One. A G-One number is a number sum of whose digits is a prime number For example 12 .. sum = 1+2 = 3 ... 3 is a prime number. G-One wants to find out all the populations which can be g-One numbers.... Can You help him.? You will be given the range of population and you have to tell him how many in this range are G-One Numbers. Input first line has number 'c' indicating the number of ranges. 'c' lines follow and contain two numbers ... 'f' and 't' inclusive. Output Print a single line per case giving the number of populations which are G-One numbers. Example Input: 3 10 19 1 9 20 29 Output: 4 4 5 Note : c will be less than 100 t and f will be less than 10^8 inclusive
32,759
Wachovia Bank (WACHOVIA) Danilo Gheyi is a renowned bank robber. He is known worldwide for accomplishing the most profitable bank robbery, in Fortaleza, Ceará. Danilo and his friends dug a tunnel to get into the main chest. There were some bags, with different amounts of money or jewelry and weight. They had to leave about 50% of the total value, since the truck couldn't carry all the bags. Danilo wasn't caught, and to show that he can do itall again, he is planning a robbery to one of the safer banks in USA -the Wachovia Bank. He wants your help to maximize the amount stolen, avoiding a huge loss as it happened in Fortaleza. Write a program that, given the maximum weight the truck is ableto carry and the information about each bag in the bank, determine the maximum value that Danilo can steal. Input The input consists of several instances. There is an integer N (1 ≤ N ≤ 200) in the first line; it stands for the number of instances. The first line of each instance contains two integers, K and M (8 ≤ K ≤ 1000 and 1 ≤ M ≤ 50) representing, respectively, the maximum weight the truck can handle and the amount of bags in the bank. The next M lines describe each bag with two integers A and B (8 ≤ A ≤ 200 and 1 ≤ B ≤ 25): the weight and the value of the bag, respectively. Output For each instance output a sentence “ Hey stupid robber, you can get P. ”, and P represents the maximum value Danilo can steal. Example Input: 3 34 5 178 12 30 1 13 7 34 8 87 6 900 1 900 25 100 10 27 16 131 9 132 17 6 5 6 23 56 21 100 25 1 25 25 25 100 2 Output: Hey stupid robber, you can get 8. Hey stupid robber, you can get 25. Hey stupid robber, you can get 99.
32,760
Happiness at the lowest cost (RS2D) Rafael Phofo was a happy guy living with his best friend, Danilo Gheyi. They were so friends that they made a blood pact during their childhood. But Matheus Pheverso, the owner of the Infelicity Forest, a forest that Rafael and Danilo used to cross every day, didn't like to see them together. He always tried to separate them; a day he finally achieved his goal, making the two guys lost in two different points of his forest. Rafael Phofo knew it wouldn't be hard to find his friend, because he had some RS2D (love notes), the money that Matheus Pheverso charged to let his visitors cross each street connecting two points of the forest. But there was a problem: analyzing the map of the forest, Rafael realized that his amount of RS2D could be insufficient. So he called you, a great programmer and also his friend, to know if it's possible to find Danilo with that amount of RS2D. You need to write a program that determine the minimum amount of RS2D necessary. Consider that Rafael is in the position 1 of the forest and Danilo is in the position N. Input The input consists of several instances; the first line contains an integer K (1 ≤ K ≤ 20), the amount of instances. The first line of each instance contains two integers N and M (1 ≤ N ≤ 10 6 , 1 ≤ M ≤ 10 6 ), the amount of points and the amount of streets in the forest, respectively. The next M lines contain three integers A, B and C (1 ≤ A ≤ N, 1 ≤ B ≤ N, 1 ≤ C ≤ 10 6 ), indicating a one-way street from point A to point B with cost C. Output For each instance output a sentence “Rafael will find his love for P RS2D.”, and P represents the minimum amount of RS2D that Rafael needs to caught Danilo. Example Input: 2 6 9 1 2 7 1 5 14 1 3 9 2 4 15 2 3 10 3 5 2 3 4 11 5 6 9 4 6 6 5 7 1 2 1 1 3 5 2 4 2 3 4 2 3 5 3 2 5 3 4 5 1 Output: Rafael will find his love for 20 RS2D. Rafael will find his love for 4 RS2D.
32,761
GAME (GAMECG) Ashton Carl McDonalds (known as A.C.M.) works at a small school. The school have decided to compete in a new style of game designed by programmers. This game is organized in teams, each team have the size of M competitors, the goal of the game is to each team solve the maximum number of problems, if there is a tie, the team who solved faster win. It is important to you know that the order of the members in a team doesn't matter. Carl was designed by his school to be a kind of coach of this game. He needs to train all the teams of his school, and the most important, he needs to choose theses teams. A.C.M is kind of worried if it will be a lot of teams, and maybe it will be a lot of work to him. Due to this, he decides to count how many different teams can exist in his school. McDonalds is not good on mathematics, due to this he asked you to count the number of different teams. A.C.M knows that the result can be very large, so he asked to you to give the result in modulus 1300031, but he needs to know if the result exceeds 1300030 or not. Input The input consists of several lines. Each line consists of two integers N (1 ≤ N ≤ 10 6 ) and M (1 ≤ M ≤ N), the number of students and the numbers of members in each team. Output The output consists of two lines. The first line contains the result in modulus, and the second line contains “Exceeds” if the result exceeds 1300030 or “Does not exceed” if the result does not exceed 1300031. Example Input: 3 1 140 60 15 8 Output: 3 Does not exceed 207865 Exceeds 6435 Does not exceed
32,762
Sum of Tetranacci numbers (TETRAHRD) The sequence of Tetranacci numbers is defined as follows: a n = a n-1 + a n-2 + a n-3 + a n-4 with a 0 = a 1 = a 2 = 0 and a 3 = 1. Input Input starts with a positive integer t ≤ 4000, then t lines follow. Each of the t lines contains two space separated integers m and n with 0 ≤ m ≤ n ≤ 10 9 . Output Calculate a m + a m+1 + ... + a n and print the result modulo 1000000007. Example Input: 2 1 2 1919 5393 Output: 0 66616 Note : If your solution times out, you may try the tutorial version first.
32,763
Unlock it ! (DCEPC204) Vaibhav loves playing with numbers. To enjoy his summer holidays he decides to join the group "number players" of his school. He decides to visit the group hall. At the gate he finds a lock and a paper. The gate can only be unlocked by solving the puzzle written on the paper. Vaibhav is stuck with his puzzle, help him in solving it. Here is the puzzle description: Given a sequence F(N) F(0) = 1 F(1) = 1 F(2) = 1 F(n) = product of all odd primes less than or equal to n (for n≤ 10) F(n) = (2 (n/4) ) × F(n/5) × F(n/10) (for n > 10) For every fraction, a ceil value is taken for evaluation. For eg. F(11)=2 ceil(11/4) × F(ceil(11/5)) × F(ceil(11/10))  = 2 3 × F(3) × F(2) = 24 Given N. Find the max value of (a b ) % mod such that a and b satisfies the relation gcd(a, b) = F(N). Gcd : Greatest common divisor Input First line gives T, the number of test cases. Next T line gives number N. Output For each test case, print the desired value on a new line. Constraints T ≤ 10 N ≤ 10 6 mod = 10 9 . NOTE: a must be ≤ 5 × F(n) and b must be ≤ 5 × F(n), a can be equal to b and mod = 10 9 . Example Input: 1 2 Output: 1024
32,764
Its a Murder! (DCEPC206) Once detective Saikat was solving a murder case. While going to the crime scene he took the stairs and saw that a number is written on every stair. He found it suspicious and decides to remember all the numbers that he has seen until now. While remembering the numbers he found that he can find some pattern in those numbers. So he decides that for each number on the stairs he will note down the sum of all the numbers previously seen on the stairs which are smaller than the present number. Calculate the sum of all the numbers written on his notes diary. Input First line gives T, number of test cases. 2T lines follow. First line gives you the number of stairs N. Next line gives you N numbers written on the stairs. Output For each test case output one line giving the final sum for each test case. Constraints T ≤ 10 1 ≤ N ≤ 10 5 All numbers will be between 0 and 10 6 . Example Input: 1 5 1 5 3 6 4 Output: 15
32,765
Unique Paths (DCEPC202) Vaibhav sir and Jyoti ma’am are pretty pissed off after taking the doubt clearing session for first batch. People are not taking them seriously and doing their assignments, so they decided only intelligent students should appear in the tutorials. So they put up a condition, only those students who came to the class walking on unique paths can attend the class. By unique path they meant that at least 1 move differs from any other path. You are at the position (0, 0) in the corridor and the class is at the position (n-1, 4). Where n is the length of corridor and width is 5 units. You can move only to the adjacent tile on the floor. As you are not idiots you have to reach at the class using shortest path only. Corridor has some broken tiles which are not to be traversed on, they are : (0, 2), (n/2, 0), (n/2, 2), (n/2, 4) and (n-1, 2). The minimum students required for class is given (k). You have to tell the minimum length of corridor to select k students. Input First line contains T (1 <= T <= 10) number test cases. Each test case consist of 1 integer K (2 <= K <= 10 18 ), the minimum number of student required. Output Minimum length of corridor required to select at least K student. Note : Required length of the corridor will always be between 4 and 10000 (inclusive) Example Input: 2 2 9 Output: 4 6
32,766
Finally a Treat (DCEPC207) Anuja ma’am is getting more and more obsessed by her name (actually she loves it!!!). She has a strong belief that her name has something very special but she could not make it out what is it. As Vaibhav sir is very good in finding pattern he helped her with her problem, that she has a name in which only one character has maximum frequency i.e. ‘a’. She became very happy and decided to give a party to all of the members of DCE Coders who have special names. But wait, she finds out that the list is too big, so she decided to narrow it down. Here's how she narrows it: “Anuja ma’am will give a party to all those whose name is special and the character which makes their name special MUST be the character with maximum frequency in the entire list of names. There is only ONE special character in the string.” As a student you are required to make a list of names ELLIGIBLE for party. Remember, a name is special only if a SINGLE character has the maximum frequency in it. (See example #2 ) Input 1st line contains T(1<=T<=100), number of test cases. Next T lines contain a string(1<=Length of String<=10000) containing list of names separated by SPACES. Output Output k+1 lines for each test case, where k is the number of students ELLIGIBLE. First line contains “Case #x:” where x is the case number starting from 1. Then next k lines contain the names of ELLIGIBLE students. Note: Each input string will have at least 1 word (of at least 1 character). i.e. there is no input string with only spaces Example Input: 2 abcdd abccd cccd aabb aabcc aaa adaa Output: Case #1: abccd cccd Case #2: aaa adaa
32,767
Medium Factorization (FACTCG2) The task in this problem is to write a number in a multiplication of prime numbers separated by “ x ”. You need to put the number 1 in this multiplication. Input The input consists of several lines. Each line consists of one integer N (1 ≤ N ≤ 10 7 ) . Output For each line you need to output the factorization separated by “ x ” and including 1. Sample Input 1 2 4 8 Output 1 1 x 2 1 x 2 x 2 1 x 2 x 2 x 2
32,768
BF Vector (BFTAB) Your task is to put in the output nth character of the read input. You have to use BF. Input First line have x chars (1 ≤ x ≤ 99) and ends with a line feed (10) Second line is one number n (00 ≤ n ≤ 99) Output It's only one character. Example Input: 01234567 02 Output: 2 Input: 0112ok3-12kewpl11,2eo12o3ke12ls12w1io2j34e12md 14 Output: l
32,769
Obsession (DCEPC203) Ankur sir is really obsessed with dce coders. Every other day he announces to the admins the current number of members and boasts about the continuous increase in the member count. Within a week the admins got bored of his habit and started losing interest in this topic. Ankur sir is very clever. He knows that every body loves to solve puzzles. To maintain their interest he decides to ask a puzzle based on the number of current members. This way he can still bug the admins about the increasing member count without making them feel bored. The puzzle says for the given member count N, tell me how how many smaller numbers (k ≥ 2) exist such that F(k) = 2 * k * k - 1 is a prime. Input First line gives T, the number of test cases Each of the next T lines give a number N. Output Print the output for every test case on a new line    Constraints T ≤ 1000 2 ≤ N ≤ 10000000 Example Input: 1 5 Output: 3
32,770
The Prime Minister (DCEPC200) DCE Coders mentors got fed up by making problems, they are deciding upon the toughest problem for contest. Everybody started to tease Ankur sir that he can’t make a single tough problem for juniors. He got very angry, now you only handle Ankur sir’s anger (Beware: All the tough number theory problems given to you as assignments are like 2+2=4 for Ankur sir). Here is the problem given by him (Say thanks to Jyoti ma’am that she softens the problem slightly.. ;)). You are given an integer n. There will be 2 different numbers K1 and K2, such that K1 × K2 = n. Both of which satisfies the equation  (Totient(K!)  mod K) !=0.   You are also given value of a function, F(n) = Sum of squares  of factor of n. (example F(20) = 546) Now you have to calculate the value of x and y which satisfies the equation K1x + K2y = m. Where m is given. Since there are many roots you have to find a single pair (x, y) which satisfies the equation having minimum absolute value of (x + y). If no pair is possible output -1. Else output (abs(x + y) m ) % mod . Input First line contains T (1 ≤ T ≤ 10000) number of test cases. Each test case consist of single line containing 3 integers n, F(n) and m. Output Output  T lines, each line contains a single integer ((x + y) m ) % mod. Constraints T ≤ 10000 N ≤ 10 8 F(n) ≤ 10 18 M ≤ 100 mod = 10000000000283 Example Input: 1 6 50 3 Output: 0
32,771
Supplying the Suppliers (SUPSUP) It's battle time yet again, and now General Frey is worried about the supplies to his units. The capital city of the Empire has two exits, the North Gate and the South Gate, at which several key elements to the army will be stored. Several squads are going to be deployed, and seeing as each one of them has different needs, the General needs to decide on which exit he will deposit each supply type. Storing a supply element on both exits is costly and confusing, so the whole shipment for a resource must be located at a single exit. The orders that specify which soldier should get which supply should not be disrespected, that is, two soldiers from the same squad cannot swap items if it's more convenient to do so. To solve this issue, the General has decided that a simple rule should be followed: No squad should ever have more than one soldier carrying an element from the opposite exit in which he is located. Given the list of squads and their needs, find out if it's possible to place the items on the exits such that the rule's followed. Input The input consists of several test cases. On the first line of each test case will be an integer N (1 ≤ N ≤ 100) , the number of squads. Each of the following N lines begins with an integer t, describing how many needs that specific squad has. t integers and characters follow, each of which specify a supply type that squad needs. You may assume a supply type fits in a signed 32-bit integer. If the character is 'S', then the soldier that is going to fetch that item is at the South Gate, if it is 'N' the soldier is at the North Gate. Equal integers specify equal supply types, and no item appears twice on the same squad list. The number of different supply types in a single testcase is at most 100. The last test case will be followed by a line containing a single zero. Output Print a single line for each test case. The line must contain the words "March onward" if it's possible to assign the deposits and follow the General's rules, "Coordination issue" otherwise. Example Input: 2 2 1S 2S 2 1N 2N 2 3 1S 2S 3S 3 1N 2N 3N 0 Output: March onward Coordination issue
32,772
Decoys and Diversions (DECOY) Apparently, both sides of the battle are now using some sort of cat-and-mouse tactics on the battlefield. The rules are as follows: there are two battles happening simultaneously at different fields. The armies take turns retreating one of their two units to a different location; the retreat of an army automatically causes the opposing army on the same field to follow it. The one that is cornered (that is, has nowhere to retreat on their turn) will be the one that ultimately loses the battle. Given the description of the fields, and supposing that both commanders are perfect strategists, can you decide who is going to win? Input The first line of input contains an integer T , the number of test cases. Each test case consists of two descriptions of the fields of the battle. A description begins with a line containing integers N (1 ≤ N ≤ 100), M (1 ≤ M ≤ 10000), the number of locations in the field and the number of roads connecting the locations, respectively. The following M lines each contain two integers u , v (1 ≤ u,v ≤ N) denoting that there is a one-way road connecting position u to the position v. The initial location of all units is at position 1 in their respective fields. Output For each test case, output a single line containing the result of the battle, assuming your side is the first to play. Print "I lose" if you're going to lose, "I win" if you're guaranteed to win or "Deadlock" if the battle will go on forever. Example Input: 3 2 1 1 2 2 1 1 2 2 2 1 2 2 1 2 1 1 2 3 2 1 2 2 3 2 1 1 2 Output: I lose Deadlock I win
32,773
Customs (CUSTOMSL) Matheus, Bruno and Ricardo are the boasting for the research department at Indústria de Obras Intermináveis (IOI) and they constantly travelled together for another countries to research different methods, equipment and primal materials for amazing works. Furthermore, they operate in the informal import market, bringing equipment and electronics for your friend and coworkers. Before leaving they make a list of N products who they have to buy, each one of them with a price Pi DE$ (Dinheiro Estrangeiro). They have to pay some customs duty if anyone of them exceeds the maximum amount of Q that each one can brings. As them always travel together, they note that it’s more cheap for them, if the products are organized in a way that’s can be possible to reduce the maximum amount of duty who they have to pay. Given the prices of N products, Q and the maximum tax A, you have to say the minimum price of duty that they have to pay. Input The input is only a testcase. The first line include an integer N (1 ≤ N ≤ 100), that represents the number of products bought. The second line include two integers, Q and A (1 ≤ Q ≤ 500, 1 ≤ A ≤ 200), that represents the maximum amount of import, and the tax of importation in percent. The next N lines includes each one, an integer Pi (1 ≤ Pi ≤ Q), that represents the price of the i-th product. Output You have to write in your output a single line contains the minimum possible value of duty that Matheus, Bruno and Ricardo have to pay. Example Input: 4 10 1 10 9 8 7 Output: 0.05 Input: 6 9 20 9 6 3 3 3 3 Output: 0.00
32,774
I Hate Parenthesis (FERT21_1) “I Hate Parenthesis”, it was the phrase that Ana said during the class of arithmetic. She want a simple code made for yourself (of course) to “kick out” the parenthesis from particular expressions without break maths. Input The first line contains the number of test cases T. One expression per line from second to (T+1)-th line. Each expression contains only uppercase letters (each letter can appears once), operators (+, *) and parentheses (()). There are no spaces inside the expressions and no input line contains more than 80 characters. Output A single line per case. The line must contains the expression without parenthesis. If there is more than one addend then you must sort first the one with more factors. Addends with the same amount of factors must be sorted in alphabetic order. See the example for more details. Example Input: 2 C*(A+B) (A+B+D*E)*C Output: A*C+B*C C*D*E+A*C+B*C
32,775
Dixon Dominoes (DIXDOOM) Dixon was in his house, he was a little bored, so he took some dominoes from the case and started thinking: “It is possible to use Qx pieces from the Dominoes so it can make a simulation of a game?” so, Dixon is not a super programmer, but he knows a little bit of constraints in the problems, so he will give it to you, your task, if you choose to accept it, is to find all the possible ways of some N pieces of Domino can be joined together to make a game simulation using exactly Qx dominoes pieces. If you can’t do this, you should print “0” Input The input will consists of an integer T, denoting the number of test cases, next, T cases will follow, every case starts with 2 lines N and Q, being N the number of dominoes David has and Q the number of queries you should do, then, N lines will follow, denoting the two parts of a domino piece, as you may know, the domino piece is split in two, so you can join by any side another piece, after this, Q lines will follow, denoting the number of piece you must use to build the game simulation. Constraints 1<=T<=100 1 <= N <= 16 1 <= Q <= 16 0 <= N 1 … N N <= 6 1 <= Q 1 … Q N <= N Output You should output all the possible ways to form a game using Qx pieces (with any possible permutation too), as this number can grow very huge, we need you to print the output modulo 31337. Example Input: 3 4 3 2 3 3 1 1 4 4 3 1 3 4 2 1 1 2 1 2 2 2 1 1 1 1 1 2 Output: 8 10 4 4 8 Domino idea credits goes to: Daniel Ampuero and Luis Arguello Example of the output with the first case and Q=4 solution 1: joining the pieces 1, 2, 3 and 4. solution 2: joining the pieces 4, 3, 2 and 1. solution 3: joining the pieces 2, 3, 4 and 1. solution 4: joining the pieces 1, 4, 3 and 2. Tip : In the case with one piece only, you can form a game starting with the two faces of every single piece, i.e. if we want to form a game using just the piece "2 1", one possible game is "2 1" and the other "1 2", resulting in two different ways.
32,776
Online Bridge Searching (ONBRIDGE) English Vietnamese Given a graph of N vertices, numbered from 0 to N - 1. Initially, there is no edge in the graph. Sequentially adding M undirected edges (u, v) to the graph (0 <= u, v <= N - 1). After adding an edge, you must print out the current number of bridges in the graph. The data guarantees that there is no request to add an existed edge, or an edge from a vertex to itself. Input The first line contains an integer T (T <= 10) denotes the number of test cases. Each test case begins with 2 integers N (1 <= N <= 50000) and M (1 <= M <= 100000), followed by M lines, each line contains a pair of integers (u, v) represents a request to add an edge (u, v) to the graph. Output After each request, print out the current number of bridges in the graph on a separate line. Example For the input data: 1 5 10 3 0 0 2 1 0 1 3 1 4 2 4 4 0 2 1 2 3 3 4 the correct result is: 1 2 3 1 2 0 0 0 0 0
32,777
Foodie Golu (DCEPC301) Being a big foodie Golu wants to try all the dishes available at a party but because of his increasing weight his mother does not allow him to do so. After a huge fight they both come to an agreement. 1.  The first rule of the agreement says that Golu should only eat at an interval of 10 minutes. 2.  The second rule is regarding the stalls available. There are N stalls in one line and Golu should select only one stall to eat at one time. The selected stall must lie at the n/2th position or (n/2 + 1) position (zero indexed) among all remaining stalls. 3.  Once he has selected a stall he must discard all the stalls to its left (or right) and in future can only eat from the remaining stalls. Also he can eat from a stall only once during the party, so once he has eaten from a stall, it should be discarded too. The initial cooking speed at all the stalls is 1 unit. After doing some calculations Golu realises that the speed of cooking of the cook at every stall becomes double every 10 minutes. Depending upon the type of dish available and his eating capacity, he assigned a value to each stall such that any point of time he can eat a quantity which is equal to (value of that stall) * (current speed of cooking at that stall). Since speed is increasing exponentially he only remembers speed as speed % mod at any time. Since he wants to eat the maximum amount of food, help him in developing a strategy to eat. NOTE: If there are only 2 stalls left, he must choose any one stall and discard the other. Input First line contains T, the number of test cases. (1 ≤ T ≤ 5) First line of each test case contains n, the number of stalls in the party. (1 ≤ n ≤ 3000) Next line of each test case contains n space separated integers, representing the value of each of the stalls. (All values are between 1 and 3000 inclusive) Output Output T lines, one for each test case containing the maximum amount of food Golu can eat mod 10 9 +7 Example Input: 1 5 2 4 1 3 5 Output: 21 Explanation: Golu can select the fourth stall first and discard all stalls to its right (i.e. discard fifth stall). Then he can select the third stall and again discard all stalls to its right (no stall to discard this time). Finally he chooses the 2 nd stall. Therefore total food he can eat = 3×1 + 1×2 + 4×4 = 21.
32,778
Vero Dominoes (VERODOOM) Vero was one day playing some sort of game that consists in drinking a lot of orange juice, the game's idea is in turning up one domino piece and count the black dots in it, then, drink as many deciliters as the total count of the dots in the domino piece, for example, a 6-maximum-dots dominoes contains 168 dots in it.   She wants to know how much deciliters can be drank in one simple game, she doubts about your skills as a programmer, so she can test your program with over 150 thousands of cases.   INPUT:   The input will start with a T integer number, then, T lines will follow, for each T there will be a number N.   CONSTRAINTS: 1<=T<=150.000 0<=N<=50.000.000   OUTPUT:   For each number N you should output the total dots in the domino pieces...   SAMPLE INPUT: 2 6 1   SAMPLE OUTPUT: 168 3   Explanation of the second case: There's only 1 dot maximum in the domino pieces, so you will count the piece 0 0, 0 1 and 1 1 (you should not count the 1 0 piece as it is represented with the 0 1 piece)   Constraints of the problem has been modified so the problem is a little bit challenging now.
32,779
Aritho-geometric Series (AGS) (AGS) Arithmetic and geometric progressions are 2 of the well known progressions in maths. Arithmetic progression (AP) is a set in which the difference between 2 consecutive numbers is constant. For example: 1, 3, 5, 7, 9... In this series the difference between 2 numbers is 2. Geometric progression (GP) is a set in which the ratio of 2 consecutive numbers is the same. For example: 1, 2, 4, 8, 16... In this the ratio of the numbers is 2. What if there is a series in which we multiply a(n) by 'r' to get a(n+1) and then add 'd' to a(n+1) to get a(n+2)? For example: let's say d = 1 and r = 2 and a(1) = 1, the series would be 1, 2, 4, 5, 10, 11, 22, 23, 46, 47, 94, 95, 190... We add d to a(1) and then multiply a(2) with r and so on. Your task is, given 'a', 'd' and 'r' to find the a(n) term. since the numbers can be very large, you are required to print the numbers modulo 'mod' - mod will be supplied in the test case. Input First line of input will have number 't' indicating the number of test cases. Each of the test cases will have 2 lines. The first line will have 3 numbers 'a', 'd' and 'r'. The second line will have 2 numbers 'n' and 'mod'. a = first term of the AGS. d = the difference element. r = the ratio element. n = n th term required to be found. mod = need to print the result modulo mod Output For each test case print "a(n) % mod" in a separate line. Example Input: 2 1 1 2 13 7 2 2 2 10 8 Output: 1 6 Explanation For the first test case the series is 1, 2, 4, 5, 10, 11, 22, 23, 46, 47, 94, 95, 190..., the 13 th term is 190, and 190 % 7 = 1. Notes The value of a, d, r, n and mod will be less than 10 8 and more than 0. For every series, the second term will be a+d and third term will be (a+d)*r, and so on.
32,780
LUCIFER Number (LUCIFER) Lucifer is the only human who has defeated RA-ONE in a computer game ... RA-One is after lucifer for revenge and G-One is there to protect him ... All thi G-One and Ra-one Nonsense has disturbed Lucifer's life ... He wants to get Rid of Ra-One and kill him . He found that Ra-One can be killed only by throwing Lucifer number of weapons at him. Lucifer number shares the some properties of Ra-One Numbers numbers and G-One Numbers Any number is LUCIFER NUMBER if the difference between sum of digits at even location and sum of digits at odd location is prime number. For example, 20314210 is a Lucifer number: digits at odd location 0, 2, 1, 0. digits at even location 1, 4, 3, 2. difference = (1+4+3+2)-(0+2+1+0) = 10-3 = 7 ... a prime number. Lucifer has access to a Warehouse which has lots of weapons. He wants to know in how many ways can he kill him. Can you help him? Input First line will have a number 't' denoting the number of test cases. each of the following t lines will have 2 numbers 'a', 'b' Output Print single number per test case, depicting the count of Lucifer numbers in the range a, b inclusive. Example Input: 5 200 250 150 200 100 150 50 100 0 50 Output: 2 16 3 18 6 NOTE: t will be less than 100. 'a' and 'b' will be between 0 and 10^9 inclusive.
32,781
R Numbers (ITRIX12E) R - Numbers R-numbers are numbers which have the property that they do not have the digit '0' and sum of every two adjacent digits of the number is prime. 123 is a R-number because 1+2 =3 and 2+3 =5 and 3, 5 are primes. How many R-numbers can be formed with at most length N? i.e. R-numbers of length 1 + R-numbers of length 2 + R-numbers of length 3 + ... R-numbers of length N. Length of a number = Number of digits in the number. Only four single digit numbers are R-numbers which are nothing but single digit primes 2, 3, 5, 7. Input Specification The first line of the input file contains T which denotes the number of test cases. The next T lines contain an integer N ≤ 10 9 . Output Specification Print the numbers of R-numbers modulo 1000000007. [10 9 +7]; Example Sample Input: 2 1 2 Sample Output: 4 33
32,782
Discords Dilemma (PONY3) Discord is in trouble for causing discord, so he is trying to escape from Equestria. He's arrived at the port, and he doesn't care what boat he gets on, he just wants to get out. He can see the boat schedule, where he sees that N boats are arriving today, boat 1 arrives any time within a_1 minutes boat 2 arrives any time within a_2 minutes ... boat N arrives any time within a_N minutes (uniform distribution) Tell discord the expected number of minutes he needs to wait for a boat to arrive. For some reason, you should be accurate to 10^-6 of a minute. Input Format: T (number of test cases) N1 (number of boats for test case 1) a1 a2 ... aN N2 ... NT ... Output Format: answer1 answer2 ... answerT Limits: 1 <= T <= 100 1 <= N <= 100 1 <= ai <= 1000 Also, N * max{ai} <= 10000 Sample Input: 4 1 5 3 49 50 51 3 50 50 50 3 2 7 19 Sample Output: 2.500000 12.495000 12.500000 0.874687 Note: Round however Java would round if you used the statement System.out.printf("%.6f\n", answer);
32,783
AP - Complete The Series (Easy) (AP2) Arithmetic and geometric Progressions are 2 of the well known progressions in maths. Arithmetic progression (AP) is a set in which the difference between 2 numbers in constant. for e.g., 1, 3, 5, 7, 9 ... In this series the difference between 2 numbers is 2. The task here is very simple indeed. You will be given the 3rd term, 3rd last term and the sum of the series. You need print length of the series and the series. Input First line will contain a number indicating the number of test cases. Each of the following t lines will have 3 number '3term', '3Lastterm' and 'sum' 3term - is the 3rd term in of the series and 3Lastterm - is the 3rd term in of the series and sum - is the sum of the series. Output For each input of the test case, you need to print 2 lines. First line should have 1 value - the number of terms in the series. 2nd line of the output should print the series numbers separated by single space. Example Input: 1 3 8 55 Output: 10 1 2 3 4 5 6 7 8 9 10 NOTE: In all the test cases, all the series elements are positive integers. The series will have at least 7 elements. number of test cases ≤ 100. All the numbers will fit in 64 bits (long long in C)
32,784
AP - Complete The Series v2 (AP3) After solving "AP - Complete The Series (easy)" very fast, Lucifer decided to make it little more interesting. He said he will give you the 3rd term, 4th last term and the sum of the AP series. You need print length of the series and the series. Input First line will contain a number indicating the number of test cases. Each of the following t lines will have 3 numbers '3term' ,'4Lastterm' and 'sum': 3term - is the 3rd term in the series and 4Lastterm - is the 4th last term in the series and sum - is the sum of the series. Output For each input of the test case, you need to print 2 lines. The first line should have 1 value - number of terms in the series. The second line of the output should print the series numbers separated by single space. Example Input: 1 3 7 55 Output: 10 1 2 3 4 5 6 7 8 9 10 Note In all the test cases all the series elements are positive integers. The series will have at least 7 elements. Number of test cases ≤ 100. All the numbers will fit in 64 bits (long long in C)
32,785
Large banner (BANNER) Bessie is returning from a long trip abroad to the Isle of Guernsey, and Farmer John wants to mount a nice "Welcome Home" banner for her arrival. Farmer John's field has integer dimensions M x N (1 <= M, N <= 100,000), and he has installed a post at every possible point in the field with integer coordinates (if we assign a coordinate system to the field so that (0,0) is in the lower-left corner and (M,N) is in the upper-right corner). Of these (M+1) * (N+1) points, Farmer John must pick two as the endpoints of the banner. Farmer John, being the perfectionist that he is, insists that the banner must be completely straight. This means that, for the two posts he chooses, there cannot be any other post on the line segment that the banner will form between them. Additionally, Farmer John wants the banner to have length at least L and at most H (1 <= L <= H <= 150,000). Farmer John needs your help to figure out how many possible ways he can hang the banner. The banner is reversible, so switching the two endpoints of the banner counts as the same way to hang the banner. As this number may be very large, Farmer John simply wants to know what it is modulo B (1 <= B <= 1,000,000,000). Consider the example below, with M = 2 and N = 2: * * * * * * * * * Farmer John wants the length of the banner to be between 1 and 3 inclusive. Any choice of posts satisfies this length requirement, but note that eight pairs cannot be picked: (0, 0) and (2, 0): (1, 0) is on the line segment between them (0, 1) and (2, 1): (1, 1) is on the line segment between them (0, 2) and (2, 2): (1, 2) is on the line segment between them (0, 0) and (2, 2): (1, 1) is on the line segment between them (0, 0) and (0, 2): (0, 1) is on the line segment between them (1, 0) and (1, 2): (1, 1) is on the line segment between them (2, 0) and (2, 2): (2, 1) is on the line segment between them (0, 2) and (2, 0): (1, 1) is on the line segment between them Therefore, there are a total of (9 choose 2) - 8 = 28 possible locations. Input * Line 1: Five space-separated integers: M, N, L, H and B. Output * Line 1: One integer denoting the number of possible banners (modulo B). Example Input: 2 2 1 3 100 Output: 28
32,786
SelfDescribingSequenceProblem (MAIN12A) Everyone loves Swampy. Swampy the Alligator lives under the city and yearns for a more human like existence. Swampy recently learned a new self describing sequence. The sequence is described in blocks where each block has the same number and two consecutive blocks have consecutive numbers in them. To construct the sequence start with '1'. Now '1' means that the following block is of length 1. As '1' was chosen in previous block, therefore '2' is chosen for the current block making the sequence '12'. Now '2' means that the following block is of length 2. As '2' was chosen in previous block, therefore '3' is chosen for the current block making the sequence '1233'. Now '33' means that the following 2 blocks are of length 3. As '3' was chosen in previous block, therefore '4' is chosen for the current block making the sequence '1233444'. And the second '3' in the sequence appends '555' in the already generated sequence, making the sequence '1233444555'. Input First line of the input contains an integer T, the number of test cases. Then T test cases follow. Each test case consists of a single integer N. Output For each test case, print Case #X: S, where X is the test case number starting from 1, S is the Nth term of the sequence described above. Example Input: 4 1 2 3 4 Output: Case #1: 1 Case #2: 2 Case #3: 3 Case #4: 3 Constraints: T <= 10000 1 <= N <= 1000000
32,787
PrimeFactorofLCM (MAIN12B) Everyone loves Swampy. Swampy the Alligator lives under the city and yearns for a more human like existence. One day Swampy took part in a maths contest to show his supremacy over other his other alligator friends. The task required him to output the prime divisors of the lcm of n numbers a1, a2 ... an. Tired of trying the problem, he turned to you for help. He believes that you can help him solve the problem. Input First line of the input contains an integer T, the number of test cases. Then T test cases follow. Each test case consists of a single integer n. Next line contains n integers (space separated), a1, a2 ... an. Output For each test case, print Case #X: M where M is the number of prime divisors of lcm(a1, a2 ... an) and then M lines with the prime divisors in non-decreasing order. Example Input: 1 8 1 2 3 4 5 6 7 8 Output: Case #1: 4 2 3 5 7 Constraints: T <= 100 1 <= N <= 100 1 <= ai <= 10^12
32,788
Email ID (MAIN12C) Everyone loves Swampy. Swampy the Alligator lives under the city and yearns for a more human like existence. One day Swampy thought to learn the intricacies of the internet. He went to a book store in SwampVille immediately and bought a book on "Basic Internet". After reading the book Swampy decided to try on some exercises. The exercise demanded Swampy to report all valid email-id's in a given free-form text string. Check output section for exact specification. Swampy lacks the intelligence of humans and therefore needs you to help him in this job. The chapter defined email-id's as a string consisting of two parts. From left to right, these are username and site-address. The username is non-empty string of minimum length 5 build from characters {a-z A-Z 0-9 . _} (excluding the brackets). The username cannot start from '.' or '_' The site-address is build of a prefix which is non-empty string build from characters {a-z A-Z 0-9} (excluding the brackets) followed by one of the following suffixes {".com", ".org", "edu", ".co.in"}. There is no space character in the email-id. The entire email-id is "username@site-address". Input First line of the input contains an integer T, the number of test cases. Then T test cases follow. Each test case consists of String S on a single line. S is made up of characters {a-z A-Z 0-9 ~!@#$%^&*()<>?,.} (excluding the brackets) and space character too. Output For each test case, print Case #X: K, where X is the test case number starting from 1, K is the number of email-id's found in S, and then K lines with email-id's found in S. Example Input: 2 svm11@gmail.com svm11@gmail.com svm12@gmail.co.in Output: Case #1: 1 svm11@gmail.com Case #2: 2 svm11@gmail.com svm12@gmail.co.in Constraints: T ≤ 100 |S| ≤ 10000
32,789
Discord is Cornered (PONY4) The ponies have finally cornered Discord. His earlier escape attempts didn't help him much. The unicorn ponies have begun casting magic spells at Discord to turn him back into stone. There are N ponies and pony I has a casting rate A_I. That is, once pony I began casting her magic spell, it would send a bolt of magic at Discord every A_I seconds, precisely. At time t = 0 seconds, all the ponies began casting their magic. It has now been M seconds since they began casting. Discord is wearing down. He only can survive being hit by K-1 more spells before being turned into stone (so the Kth spell will turn him to stone). Determine which pony has the honor of casting the final blow against Discord. Notes: If multiple ponies send a bolt of magic at the same time, then they hit in order of the smaller rate first. All the ponies are casting different spells, so all the casting rates are distinct. If some ponies cast a bolt of magic after exactly M seconds, that bolt has already hit Discord. He can survive an additional K-1 spells. Input The input file will begin with a number T on the first line, indicating the number of test cases in the file. It is followed by 2T lines, which represent the T test cases. Test case i begins with the label "Case #i: " and is followed by space separated N, M, and K for that case. On the next line are N space separated integers representing the rates of pony 0 , pony 1 ... pony N-1 . T //number of test cases Case #1: N M K//number of ponies, number of seconds since they began casting, the spell which will turn him to stone A 0 A 1 ... A N-1 ... (etc.) Output The output contains T lines, one for each test case. For test case i, begin the line with the label "Case #i: ", and then the index of the pony which has dealt the final blow against Discord. Case #1: C 1 // C 1 is the pony which casts the final blow against Discord Case #2: C 2 ... Case #T: C T Constraints Number of test cases varies. Depends on the instance size. 1 ≤ N ≤ 5000 0 ≤ M ≤ 10 18 - 1 1 ≤ K < 2 63 - 1 1 ≤ A i ≤ 10 18 Example Input: 5 Case #1: 2 0 4 2 3 Case #2: 2 0 5 2 3 Case #3: 3 7 4 2 3 5 Case #4: 4 55 88 10000 55 3 16 Case #5: 4 9950 23 10000 55 3 16 Output: Case #1: 0 Case #2: 1 Case #3: 2 Case #4: 2 Case #5: 0 You can be assured that it will not take more than 10 18 seconds to turn Discord into stone from when the ponies began casting.
32,790
Restacking haybales 2012 (RESTACK) Farmer John has just ordered a large number of bales of hay. He would like to organize these into N piles (1 ≤ N ≤ 100,000) arranged in a circle, where pile i contains B i bales of hay. Unfortunately, the truck driver delivering the hay was not listening carefully when Farmer John provided this information, and only remembered to leave the hay in N piles arranged in a circle. After delivery, Farmer John notes that pile i contains A i bales of hay. Of course, the A i 's and the B i 's have the same sum. Farmer John would like to move the bales of hay from their current configuration (described by the A i 's) into his desired target configuration (described by the B i 's). It takes him x units of work to move one hay bale from one pile to a pile that is x steps away around the circle. Please help him compute the minimum amount of work he will need to spend. Input Line 1: The single integer N. Lines 2..1+N: Line i+1 contains the two integers A i and B i (1 ≤ A i , B i ≤ 1000). Output A single line containing one number, answer to the problem. Example Input: 4 7 1 3 4 9 2 1 13 Output: 13
32,791
The Great Escape (GREAT_E) Primo is a famous guitar player in the city of Caracas, he wants to live his life at the fullest, so he went to the nearest food store to buy an arepa, a famous dish of all South America. While eating his arepa, Primo received a call from his friend Maxx, who was piloting his helicopter when he soon noticed that a lot of fans were around the streets, pursuing and looking for Primo. Primo is starting to go crazy, he wants to eat his arepa as many time he can before the fans takes him... He is not interested in the fans because he already has a girlfriend! So, your task is very simple, Maxx (in his helicopter) will give you the connection between the streets, the time you can spend from street to street, and the amount of time the street has left before the fans takes it. If some fans “take” a street, that street will be discarded, Primo won't go there... NOT EVEN DEAD! Primo really likes arepas, so help him find the maximum time he can spend eating the food before the fans can reach him. Input Input will start with a number T of test cases, then, T cases will follow: Each test case will start with 3 numbers N, R, M, corresponding, to number of intersections, number of streets and maximum time he can eat the arepa Then, R lines will follow. Each line will contain 3 numbers and a string Ri, Rj, Wij, Tij, corresponding to, Intersection I is connected to intersection J with a length of Wij minutes and the fans will arrive to the street in Tij minutes (or may not arrive, in this case, Tij will be equal to INF) The final line of each test case will contain two numbers S, E corresponding to the starting intersection Primo is in (the food store) and the E will correspond to his house. Note that: if the fans won't arrive to the street the Tij of the street will be INF. Also note that: if you can go from the i-th intersection to the j-th intersection as you can go from the j-th intersection to the i-th intersection. Output Your output will start with a “Case #i: “ string, where I is the i-th case you are on. If Primo can escape, you should output “Primo can escape in T minute(s)” where T Is the maximum amount of time he can spend eating his arepa, else, you should print “Primo can't escape” Example Input: 4 3 2 100 0 1 30 40 1 2 10 40 0 2 3 2 100 0 1 30 INF 1 2 10 INF 0 2 4 3 100 0 1 20 INF 1 2 40 INF 2 3 50 120 0 3 2 1 100 0 1 1 2 0 1 Output: Case #1: Primo can't escape Case #2: Primo can escape in 100 minute(s) Case #3: Primo can escape in 9 minute(s) Case #4: Primo can't escape Constraints 1 ≤ N ≤ 100,000 1 ≤ R ≤ 100,000 1 ≤ M ≤ 100,000 0 ≤ R1, R2, S, E < N 1 ≤ Tij, Wij ≤ 500 Clarification: It is guaranteed that every intersection will be connected to at least one other intersection, there will be no equal relation on the input data and Primo will always reach his house.
32,792
Magic Strawberries (STRAWB) Andreina the Hobbit was walking in a big yard when he saw a huge path of strawberries, Andreina ran, looking where to found her friend, Teresa (Everybody knows that Teresa LOVES strawberries), Teresa then looked the giant path of strawberries, having some amount of strawberries in a single meter, but she soon noticed that in the end of the path there was a HUGE pot of strawberries, full of this delicious fruit, Teresa, grabbed the first strawberry, but she was sent some amount of spaces ahead! However, she grabbed another strawberry and she was sent out of the range of the pot. She was a little confused, but, the Hobbit noticed that she was sent exactly Ai meters, the same exact amount of strawberries that were on the floor. Now, Teresa likes a lot this fruits and wants to reach the pot, however, she doesn't want to repeat the experience of magically sent out away from the pot! Teresa won't leave any fruits in a single square if she decides to grab it. Andreina the Hobbit called you, and you, the only programmer in Rainbowland must solve the problem... Andreina will give you the amount of meters to reach the pot and the number of strawberry meters that Teresa wants to pick as maximum (she has a little trauma as she was sent out of the pot range). Andreina then explains you: “Teresa can grab all the strawberries in a single square, but, if she does so, she will be transported “Ai” meters ahead, being Ai the number of strawberries she grabbed. Else, Teresa will decide to skip the strawberry meter, she doesn't like this, so, give me the minimum strawberry meters Teresa should skip.” Input The input will consists on T test cases, then, 3 lines will follow, the first line contains two numbers N and K, being N the number of meters and being K the maximum numbers of strawberries Teresa wants to pick, in the next line there will be N integers, giving the number of strawberries in each tile, the last number (Nn) will always be a 0, this represents the pot Teresa wants to go. Finally, the third line is a blank line. Output The output starts with “Scenario #i:” where “i” is the test case of evaluation starting by 1, in the next line, you should output “Teresa will skip N strawberries” where N is the minimum number of strawberries Teresa will skip, if Teresa should skip all the strawberries, you should output “Teresa will skip all the strawberries” Example Input: 3 7 2 1 1 1 1 1 1 0 7 2 3 2 1 3 2 1 0 7 1 7 6 5 4 3 2 0 Output: Scenario #1: Teresa will skip 4 strawberries Scenario #2: Teresa will skip 0 strawberries Scenario #3: Teresa will skip all the strawberries Explanation of the Second Sample Test Teresa takes the first strawberry at the 1st tile, moves 3 tiles to the right (4th tile), then she grabs the strawberry (3) and moves 3 more tiles, arriving then to the tile 7 where is the pot. Constraints 2 ≤ N ≤ 1000 0 ≤ K ≤ N 1 ≤ Ni ≤ N
32,793
The Ball Game (IEEEBGAM) Taru and Hanaku play a ball game. The game is played with N white balls, N black balls and N boxes. Hanaku chooses one box randomly and one ball from it randomly. Taru has to arrange the balls in such a way that the probability of Hanaku choosing a White ball is maximised. None of the boxes after the arrangement should be empty. Your task is to find that maximum probability. Input The first line contains the number of test cases (T) followed by T lines each an integer N. Output For each test case output the maximum probability of getting a white ball which is possible with an arrangement for the above configuration. Print the answer rounded to 8 decimal places. Constraints T ≤ 20 N ≤ 1000 Example Sample Input: 1 1 Sample Output: 0.50000000
32,794
Save money for YTU (MONEYYTU) It is Taru’s dream to study in Yanyang Technological University and Taru must start saving money in order to ensure that he has sufficient funds to take admission. Taru needs to have X amount of dollars at the end of T months. Taru deposits his money in a bank that pays a monthly interest of R% on the balance in his account. But wait, Taru is very superstitious; he deposits money in his account only if the balance in the account is a multiple of 100. If the balance in the account at the beginning of a month is not a multiple of 100 Taru withdraws the minimum offset to make the balance divisible by 100 and donates it to a charitable trust. Example – If in the beginning of the month Taru has $17823 in his account he will donate $23 and make the balance divisible by 100. You are to calculate the minimum monthly installment which Taru should deposit in the bank in order to get the funds required. Input The first line contains the number of test cases (Test) followed by Test lines each containing 3 integers, X, T, R. Output For each test case output the minimum monthly installment Taru deposits in the bank in order to generate the required funds. Print the answer rounded to 4 decimal places. Constraints Test<=20, X<=10^6, T<=60, R<=10. Sample Input 2 50000 3 5 20000 5 6 Sample Output 15142.8571 3386.7925
32,795
Korra in the Spirit World (SPWORLD) Avatar Korra is trapped in the spirit world and she summons Avatar Aang for help. Avatar Aang who wants to help Avatar Korra first wants to know whether she is intelligent enough to win the ancient game of co-prime Polygons. Two polygons are said to be co-prime if the number of their sides is co-prime. Examples - A 3-sided polygon and a 4-sided polygon are co-prime whereas a 4 sided polygon and a 6 sided polygon are not. The game begins with N polygons. The game has the following rules- A player takes any one polygon and cuts it into two co-prime polygons. Cutting is done along a line joining 2 vertices of a polygon (points cannot be adjacent). These 2 new co-prime polygons now become a part of the game. If he/she is not able to perform such a cut on any of polygons he/she loses. Avatar Aang takes the first turn. After each cut it is the turn of the other person. In a turn a person can make only one cut. Though Aang thinks Korra is not intelligent he is forgetting that she has the wisdom of all the Avatars, even him. So she knows the game. Hence both of them play optimally. Input The first line contains the number of test cases (T) followed by T lines each containing a test case. A test case begins with the number N. N integers follow denoting the number of sides in the N polygons. Every polygon will has at least 3 sides. Output For each test case output the winner of the game. Constraints T<=15, N<=7, 3<=sides of polygon<=1000 Sample Input 2 3 5 6 7 2 6 7 Sample Output Aang Korra
32,796
369 Numbers (NUMTSN) A number is said to be a 369 number if: The count of 3s is equal to the count of 6s and the count of 6s is equal to the count of 9s. The count of 3s is at least 1. For Example 12369, 383676989, 396 all are 369 numbers whereas 213, 342143, 111 are not. Given A and B find how many 369 numbers are there in the interval [A, B]. Print the answer modulo 1000000007. Input The first line contains the number of test cases (T) followed by T lines each containing 2 integers A and B. Output For each test case output the number of 369 numbers between A and B inclusive. Constraints T ≤ 100 1 ≤ A ≤ B ≤ 10 50 Example Input: 3 121 4325 432 4356 4234 4325667 Output: 60 58 207159
32,797
Build the Tower (BUILDTOW) 8. Build the Tower The president of Yanyang University has decided to build a new tower in front of the auditorium and has invited the students of SCE to help with the project. The tower is one of a kind and is made up of N cuboids one over the other. Each cuboid has a height of 1 unit and the length and breadth of a cuboid is equal. The top most cuboid’s length is 1 unit. The cuboid below it has a length of 2. All the cuboids below it have their lengths equal to the sum of the lengths of the 2 cuboids above it. Cuboid Length Breadth Height 1 1 1 1 2 2 2 1 3 3 3 1 4 5 5 1 5 8 8 1   As a token of appreciation the president has decided to give SCE a grant of $ ((Volume of Tower) % 1000000007) Your task is to calculate the amount of grant received by SCE for a given value of N. Input The first line contains the number of test cases (T) followed by T lines each containing a single integer N. Output For each test case output the grant that SCE receives for building the tower. Constraints T <= 20, N <= 10^18 Example Sample Input 2 5 10 Sample Output $103 $12815
32,798
Ipad Testing (IPAD) Apple recently released "the new Ipad" with several advance features. But the device was jailbroken within a week of its launch.  After learning the technique to jailbreak "the new Ipad", one of the enthusiast, Donncha O'Cearbhaill successfully installed different programming language compilers available from the cydia store on the device. Now O'Cearbhaill wants his friends to test these compilers. Being a good computer science student, he decided to use instead of traditional 'hello world' program, a new programming puzzle to test the compilers on the jailbroken devices : For any α, β >= 0, how many positive integers are there which can't be expressed as αλ + βμ where gcd(λ,μ) = 1 and λ,μ > 1. Also find the maximum of all such possible integers. ( α, β, λ, μ are all integers ) O'Cearbhaill knew that neither the cydia store nor the app store has a decent text editor suitable for all programming languages, so he only accept programs less than equals to 100 characters in length. Input First line consist of T ( <= 1000 ). Next T lines has two integers λ and μ such that gcd(λ,μ) = 1 and  1 < λ, μ < 10^8. Output For each test case output the two required values separated by a single space in a single line. Example Input: 2 2 3 3 4 Output: 1 1 3 5
32,799