22
BEGINNER CHEF AND LUCKY NUMBER Mr. Chef has been given a number N. He has a tendency to double whatever he get. So now he has got the number N with him and he has multiplied the number N by 2. Now Chef is superstitious. He believes in something known as Lucky Number. His lucky number is defined as any number, which when multiplied by 2 has no other factors other than 1, 2, and N. If the number is lucky all you have to do is print “LUCKY NUMBER”. If the number is not a lucky number, print “Sorry”.. Input The first line consists of T, which is the number of test cases. Every line of the next T lines consists of N. Output Print LUCKY NUMBER if the number is lucky and “Sorry” if the number is not lucky followed by a new line. Constraints 1<=T<=1000 1<=N<=1000000 Input 3 26 12 11 Output: Sorry Sorry LUCKY NUMBER CHEF AND WAY After visiting a childhood friend, Chef wants to get back to his home. Friend lives at the first street, and Chef himself lives at the N-th (and the last) street. Their city is a bit special: you can move from the X- th street to the Y-th street if and only if 1 <= Y - X <= K, where K is the integer value that is given to you. Chef wants to get to home in such a way that the product of all the visited streets' special numbers is minimal (including the first and the N-th street). Please, help him to find such a product. Input The first line of input consists of two integer numbers - N and K - the number of streets and the value ofK respectively. The second line consist of N numbers - A 1 , A 2 , ..., A N respectively, where A i equals to the special number of the i-th street. Output Please output the value of the minimal possible product, modulo 1000000007. Constraints 1 N 10^5 1 A i 10^5 1 K N Example Input: 4 2 1 2 3 4. Output:

C# problems

Embed Size (px)

Citation preview

Page 1: C# problems

BEGINNER CHEF AND LUCKY NUMBERMr. Chef has been given a number N. He has a tendency to double whatever he get. So now he has got the number N with him and he has multiplied the number N by 2. Now Chef is superstitious. He believes in something known as Lucky Number. His lucky number is defined as any number, whichwhen multiplied by 2 has no other factors other than 1, 2, and N. If the number is lucky all you have to do is print “LUCKY NUMBER”. If the number is not a lucky number, print “Sorry”..InputThe first line consists of T, which is the number of test cases. Every line of the next T lines consists of N.OutputPrint LUCKY NUMBER if the number is lucky and “Sorry” if the number is not lucky followed by a new line.Constraints1<=T<=1000 1<=N<=1000000Input32612 11

Output:SorrySorryLUCKY NUMBER

CHEF AND WAY 

After visiting a childhood friend, Chef wants to get back to his home. Friend lives at the first street, and Chef himself lives at the N-th (and the last) street. Their city is a bit special: you can move from the X-th street to the Y-th street if and only if 1 <= Y - X <= K, where K is the integer value that is given to you. Chef wants to get to home in such a way that the product of all the visited streets' special numbers is minimal (including the first and the N-th street). Please, help him to find such a product.Input

The first line of input consists of two integer numbers - N and K - the number of streets and the value ofK respectively. The second line consist of N numbers - A1, A2, ..., AN respectively, where Ai equals to the special number of the i-th street.OutputPlease output the value of the minimal possible product, modulo 1000000007.Constraints1 ≤ N ≤ 10^51 ≤ Ai ≤ 10^51 ≤ K ≤ NExampleInput:4 21 2 3 4.

Output:8

GREGOIAN CALENDARAccording to Gregorian Calendar, it was Monday on the date 01/01/2001. If any year is input, Write a program to display what is the day on the 1st January of this year.InputThe first line contains an integer T, total number of testcases. Then follow T lines, each line contains an integer year.OutputDisplay the day on the 1st January of that year in lowercase letter.Constraints1 ≤ T ≤ 10001900≤ A,B,C ≤2500ExampleInput

3 199419912014

Output

saturdaytuesdaywednesday

Page 2: C# problems

 CHEF AND HIS SEQUENCE 

Chef has a sequence of N numbers. He like a sequence better if the sequence contains his favorite sequence as a substring.Given the sequence and his favorite sequence(F) check whether the favorite sequence is contained in the sequenceInputThe first line will contain the number of test cases and are followed by the cases. Each test case consists of four lines: The length of the sequence, the sequence N,the length of F and the sequence FOutputPrint "Yes" if the sequence contains the favourite sequence int it otherwise print "No"Constraints1<=T<=10 1 1Input:261 2 3 4 5 632 3 4622 5 6 33 1 424 15

Output:YesNoCHEF AND DOLLS Chef is fan of pairs and he likes all things that come in pairs. He even has a doll collection in which all dolls have paired.One day while going through his collection he found that there are odd number of dolls. Someone had stolen a doll!!!Help chef find which type of doll is missing..InputThe first line contains the number of test cases. Second line of the input contains the number of elements in the array. The next n lines are the types of each doll that is left.OutputFind the type of doll that doesn't have a pair

Constraints1<=T<=10 1<=N<=100000 (10^5) 1<=ti<=100000Input:131 21Output:2Input:1511223Output:3FARMER AND HIS PLOT Santosh has a farm at Byteland. He has a very big family to look after. His life takes a sudden turn and he runs into a financial crisis. After giving all the money he has in his hand, he decides to sell some parts of his plots. The specialty of his plot is that it is rectangular in nature. Santosh comes to know that he will get more money if he sells square shaped plots. So keeping this in mind, he decides to divide his plot into minimum possible square plots so that he can get maximum profit out of this.So your task is to find the minimum number of square plots that can be formed out of the rectangular plot.InputThe input consists of T number of test cases. T lines follow. Each line consists of two integers N and M which denotes the length and breadth of the rectangle.OutputOutput is a single line which denotes the minimum number of square plots that can be formedConstraints1<=T<=20 1<=M<=10000 1<=N<=10000

Page 3: C# problems

Input:210 154 6

Output:66GRADE THE STEEL A certain grade of steel is graded according to the following conditions. Hardness must be greater than 50. Carbon content must be less than 0.7. Tensile strength must be greater than 5600.

The grades are as follows: Grade is 10 if all three conditions are met. Grade is 9 if conditions (i) and (ii) are met. Grade is 8 if conditions (ii) and (iii) are met. Grade is 7 if conditions (i) and (iii) are met. Garde is 6 if only one condition is met. Grade is 5 if none of three conditions are met.

Write a program, if the user gives values of hardness, carbon content and tensile strength of the steel under consideration and display the grade of the steel.Input The first line contains an integer T, total number of testcases. Then follow T lines, each line contains three numbers hardness, carbon content and tensile strength of the steel.Output Print Grade of the steel depending on Conditions.Constraints 1 ≤ T ≤ 1000 1≤ hardness, carbon content, tensile strength ≤ 10000ExampleInput

3 53 0.6 560245 0 45000 0 0 Output

1066SMALLEST NUMBERS OF NOTES Consider a currency system in which there are notes of seven denominations, namely, Rs. 1, Rs.

2, Rs. 5, Rs. 10, Rs. 50, Rs. 100.If the sum of Rs. N is input, write a program to computer smallest number of notes that will combine to give Rs. N.InputThe first line contains an integer T, total number of testcases. Then follow T lines, each line contains an integer N.OutputDisplay the smallest number of notes that will combine to give N.Constraints1 ≤ T ≤ 10001 ≤ N ≤ 1000000

Example

Input3 1200500242

Output1257int notes[] = {100, 50, 10, 5, 2, 1};for (i = 0; i < 6 && n; ++i) {

if (notes[i] <= n) { s += n / notes[i]; n = n % notes[i];

CHEF AND TWO STRINGS Chef has found two very old sheets of paper, each of which originally contained a string of lowercase Latin letters. The strings on both the sheets have equal lengths. However, since the sheets are very old, some letters have become unreadable.Chef would like to estimate the difference between these strings. Let's assume that the first string is named S1, and the second S2. The unreadable symbols are specified with the question mark symbol '?'. The difference between the strings equals to the number of positions i, such that S1i is not equal toS2i, where S1i and S2i denote the symbol at the i the position in S1 and S2, respectively.

Page 4: C# problems

Chef would like to know the minimal and the maximal difference between the two strings, if he changes all unreadable symbols to lowercase Latin letters. Now that you're fully aware of Chef's programming expertise, you might have guessed that he needs you help solving this problem as well. Go on, help him!InputThe first line of the input contains an integer T denoting the number of test cases. The description of Ttest cases follows.The first line of a test case contains a string S1.The second line of a test case contains a string S2.Both strings consist of lowercase Latin letters and question marks in places where the symbols are unreadable.OutputFor each test case, output the minimal and the maximal difference between two given strings separated with a single space.Constraints1 ≤ T ≤ 1001 ≤ |S1|, |S2| ≤ 100Subtask 1 (25 points): |S1| = 1Subtask 2 (10 points): neither S1 nor S2 contains unreadable symbolsSubtask 3 (65 points): 1 ≤ |S1|, |S2| ≤ 100ExampleInput:3a?c??b???a???a?abacaba?w

Output:1 30 33 5ExplanationExample case 1. You can change the question marks in the strings so that you obtain S1 = abc andS2 = abb. Then S1 and S2 will differ in one position. On the other hand, you can change the letters so that S1 = abc and S2 = bab. Then, the strings will differ in all three positions.Example case 2. Change the question marks this way: S1 = dcba, S2 = dcba, then the strings will

differ in 0 positions. You can also change the question marks so that S1 = aaaa, S2 = dcba, then the strings will differ in 3 positions.Example case 3. Change the question marks this way: S1 = aabac, S2 = abaaw, then the strings will differ in 3 positions. Then, change the question marks this way: S1 = xabac, S2 = abayw, then they will differ in 5 positions.DEVU AND GRAPES Grapes of Coderpur are very famous. Devu went to the market and saw that there were N people selling grapes. He didn’t like it because things were not very structured. So, he gave a task to Dhinwa to make things better. If Dhinwa successfully completes the task, Devu will be happy.Devu wants to change the number of grapes in a bucket of zero or more sellers in such a way that theGCD of all the number of grapes is divisible by K. Dhinwa can add or remove any number of grapes from each of the buckets. Adding or removing a grape will be counted as an operation. Also after the operation, none of the seller’s bucket should be empty.Help Dhinwa in finding the minimum number of operations needed to make Devu happy.InputFirst line of input contains an integer T denoting the number of test cases.For each test case, first line will contain an integer N denoting the number of buckets and integerK.Next line contains N space separated integers denoting the number of grapes in each of the bucket.OutputFor each test case, print a single integer representing the answer of that test case.ConstraintsSubtask #1: 10 points1 ≤ T ≤ 10, 1 ≤ N ,K ≤ 10, 1 ≤ number of grapes in a bucket ≤ 10Subtask #2: 10 points1 ≤ T ≤ 10, 1 ≤ N,K ≤ 100, 1 ≤ number of grapes in a bucket ≤ 100Subtask #3: 80 points1 ≤ T ≤ 10, 1 ≤ N ≤ 105, 1 ≤ K ≤ 109, 1 number of grapes in a bucket ≤ 109

ExampleInput:

Page 5: C# problems

22 23 53 710 16 18

Output:28ExplanationFor the first test case, add or remove 1 grape in each of the bucket.For the second test case, remove three grapes in the first bucket, remove two grapes from the second bucket and add three grapes in the third bucket.COPS AND THE THIEF DEVU There are 100 houses located on a straight line. The first house is numbered 1 and the last one is numbered 100. Some M houses out of these 100 are occupied by cops.Thief Devu has just stolen PeePee's bag and is looking for a house to hide in.PeePee uses fast 4G Internet and sends the message to all the cops that a thief named Devu has just stolen her bag and ran into some house.Devu knows that the cops run at a maximum speed of x houses per minute in a straight line and they will search for a maximum of y minutes. Devu wants to know how many houses are safe for him to escape from the cops. Help him in getting this information.InputFirst line contains T, the number of test cases to follow.First line of each test case contains 3 space separated integers: M, x and y.For each test case, the second line contains M space separated integers which represent the house numbers where the cops are residing.OutputFor each test case, output a single line containing the number of houses which are safe to hide from cops.Constraints1 ≤ T ≤ 104

1 ≤ x, y, M ≤ 10ExampleInput:

34 7 812 52 56 82 10 221 752 5 810 51

Output:0189ExplanationExample 1 : Cops in house 12 can cover houses 1 to 68, and cops in house 52 can cover the rest of the houses. So, there is no safe house.Example 2 : Cops in house 21 can cover houses 1 to 41, and cops in house 75 can cover houses 55 to 95, leaving houses numbered 42 to 54, and 96 to 100 safe. So, in total 18 houses are safe.

CHEF AND STRING Chef likes playing with strings. The most interesting game are named "CHEF in string". The move of the game consists of the following: Chef takes a subsequence of string's letters that form the word "CHEF" and then he removes that symbols. The goal of the game is to make the maximal number of moves. Please, help Chef and tell him the maximal possible number of moves that he is able to make for the given string S.InputThe first line of each test case contains a given string. This string consists of uppercase letters from the set {"C", "H", "E", "F"}.OutputOutput a single line containing the maximal possible number of moves.Constraints1 ≤ |S| ≤ 100000ExampleInput:CHEFCHEFFFF

Output:2

Input:CHHHEEEFFCC

Page 6: C# problems

Output:1BRACKETS A valid parentheses sequence is a non-empty string where each character is either '(' or ')', which satisfies the following constraint:You can find a way to repeat erasing adjacent pairs of parentheses '()' until it becomes empty.For example, '(())' and '()((()()))' are valid parentheses sequences, but ')()(' and '(()' are not.Mike has a valid parentheses sequence. He really likes everything about his sequence, except the fact that it is quite long. So Mike has recently decided that he will replace his parentheses sequence with a new one in the near future. But not every valid parentheses sequence will satisfy him. To help you understand his requirements we'll introduce the pseudocode of function F(S):

FUNCTION F( S - a valid parentheses sequence )

BEGINbalance = 0max_balance = 0FOR index FROM 1 TO

LENGTH(S)BEGIN

if S[index] == '(' then balance = balance + 1

if S[index] == ')' then balance = balance - 1

max_balance = max( max_balance, balance )

ENDRETURN max_balance

ENDIn other words, F(S) is equal to the maximal balance over all prefixes of S.Let's denote A as Mike's current parentheses sequence, and B as a candidate for a new one. Mike is willing to replace A with B if F(A) is equal to F(B). He would also like to choose B with the minimal possible length amongst ones satisfying the previous condition. If there are several such strings with the minimal possible length, then Mike will choose the least one lexicographically, considering '(' to be less than ')'.Help Mike!Input

The first line of the input contains one integer T denoting the number of testcases to process.The only line of each testcase contains one string A denoting Mike's parentheses sequence. It is guaranteed that A only consists of the characters '(' and ')'. It is also guaranteed that A is a valid parentheses sequence.OutputThe output should contain exactly T lines, one line per each testcase in the order of their appearance. The only line of each testcase should contain one string B denoting the valid parentheses sequence that should be chosen by Mike to replace A.Constraints1 ≤ T ≤ 5;1 ≤ |A| ≤ 100000(105).ExampleInput:1()((()()))

Output: ((()))PIECE OF CAKE 

This is a very easy warm-up problem.You are given a string. Your task is to determine whether number of occurrences of some character in the string is equal to the sum of the numbers of occurrences of other characters in the string. InputThe first line of the input contains an integer T denoting the number of test cases. Each of the next Tlines contains one string S consisting of lowercase latin letters.OutputFor each test case, output a single line containing "YES" if the string satisfies the condition given above or "NO" otherwise.Constraints 1 ≤ T ≤ 1000 1 ≤ length of S ≤ 50ExampleInput:4acabzzqzqqabckklkwwww

Page 7: C# problems

Output:YESYESNOYESVERSION CONTROL SYSTEM A version control system(VCS) is a repository of files, often the files for the source code of computer programs, with monitored access. Every change made to the source is tracked, along with who made the change, why they made it, and references to problems fixed, or enhancements introduced, by the change.Version control systems are essential for any form of distributed, collaborative development. Whether it is the history of a wiki page or large software development project, the ability to track each change as it was made, and to reverse changes when necessary can make all the difference between a well managed and controlled process and an uncontrolled ‘first come, first served’ system. It can also serve as a mechanism for due diligence for software projects.In this problem we'll consider a simplified model of a development project. Let's suppose, that there are N source files in the project. All the source files are distinct and numbered from 1 to N.A VCS, that is used for maintaining the project, contains two sequences of source files. The first sequence contains the source files, that are ignored by the VCS. If a source file is not in the first sequence, then it's considered to be unignored. The second sequence contains the source files, that are tracked by the VCS. If a source file is not in the second sequence, then it's considered to be untracked. A source file can either be or not be in any of these two sequences.Your task is to calculate two values: the number of source files of the project, that are both tracked and ignored, and the number of source files of the project, that are both untracked and unignored.InputThe first line of the input contains an integer T denoting the number of test cases. The description of Ttest cases follows.The first line of the test case description contains three integers N, M and K denoting the number of source files in the project, the number of ignored source files and the number of tracked source files.

The second line contains M distinct integers denoting the sequence A of ignored source files. The sequence is strictly increasing.The third line contains K distinct integers denoting the sequence B of tracked source files. The sequence is strictly increasing.OutputFor each test case, output a single line containing two integers: the number of the source files, that are both tracked and ignored, and the number of the source files, that are both untracked and unignored.Constraints1 ≤ T ≤ 1001 ≤ M, K ≤ N ≤ 1001 ≤ A1 < A2 < ... < AM ≤ N1 ≤ B1 < B2 < ... < BK ≤ NExampleInput:27 4 61 4 6 71 2 3 4 6 74 2 21 43 4

Output:4 11 1

ExplanationIn the first test case, the source files {1, 4, 6, 7} are both tracked and ignored, the source file {5} is both untracked and unignored.In the second test case, the source file {4} is both tracked and ignored, the source file {2} is both untracked and unignored.GOOD JOKE! Vadim and Roman like discussing challenging problems with each other. One day Vadim told his friend following problem:Given N points on a plane. Each point p is defined by it's two integer coordinates — px and py. The distance between points a and b is min(|ax - bx|, |ay - by|). You should choose a starting point and make a route visiting every point exactly once, i.e. if we write down numbers of points in order you visit them we should obtain a permutation. Of course, overall distance walked should be as small

Page 8: C# problems

as possible. The number of points may be up to 40."40? Maybe 20? Are you kidding?" – asked Roman. "No, it's not a joke" – replied Vadim. So Roman had nothing to do, but try to solve this problem. Since Roman is really weak in problem solving and you are the only friend, except Vadim, with whom Roman can discuss challenging tasks, he has nobody else to ask for help, but you!InputInput description.The first line of the input contains an integer T denoting the number of test cases. The description of Ttest cases follows.The first line of each test case contains a single integer N denoting the number of points on a plane. The following N lines contain two space-separated integers each — coordinates of points.OutputOutput description.Output the answer for every test case in a separate line. The answer for every test case is a permutation of length N. In case there are several solutions that lead to minimal distance walked, you should choose the lexicographically smallest one. Let P denote such permutation. To make output smaller, you should output H(P). H(P) = P1 xor P2 xor ... xor PN. Have a look at the example and it's explanation for better understanding.Constraints1 ≤ T ≤ 101 ≤ N ≤ 400 ≤ absolute value of each coordinate ≤ 10001 ≤ sum over all N in a single test file ≤ 120ExampleInput:221 20 033 30 00 3Output:30Explanation

For the first test case permutation [1, 2] is optimal. 1 xor 2 = 3.For the second one both [2, 3, 1] and [1, 3, 2] lead us to the shortest walk, but the second one is lexicographically smaller. So the answer is H([1, 3, 2]) = 1 xor 3 xor 2 = 0 .FIT SQUARES IN TRIANGLE What is the maximum number of squares of size 2x2 that can be fit in a right angled isosceles triangle of base B.

One side of the square must be parallel to the base of the isosceles triangle.

Base is the shortest side of the triangleInputFirst line contains T, the number of test cases.

Each of the following T lines contains 1 integer B.OutputOutput exactly T lines, each line containing the required answer.Constraints1 ≤ T ≤ 103

1 ≤ B ≤ 104

Sample Input

111 2 3 4 5 6 7 8 9 10 11(READ ONE BY ONE)Sample Output

0 0 0 1 1 3 3 6 6 10 10Three Way Communications The Chef likes to stay in touch with his staff. So, the Chef, the head server, and the sous-chef all carry two-way transceivers so they can stay in constant contact. Of course, these transceivers have a limited range so if two are too far apart, they cannot communicate directly.The Chef invested in top-of-the-line transceivers which have a few advanced features. One is that even if two people cannot talk directly because they are out of range, if there is another transceiver that is close enough to both, then the two transceivers can still communicate with each other using the third transceiver as an intermediate device.

Page 9: C# problems

There has been a minor emergency in the Chef's restaurantand he needs to communicate with both the head server and the sous-chef right away. Help the Chef determine if it is possible for all three people to communicate with each other, even if two must communicate through the third because they are too far apart.InputThe first line contains a single positive integer T ≤ 100 indicating the number of test cases to follow. The first line of each test case contains a positive integer R ≤ 1,000 indicating that two transceivers can communicate directly without an intermediate transceiver if they are at most R meters away from each other. The remaining three lines of the test case describe the current locations of the Chef, the head server, and the sous-chef, respectively. Each such line contains two integers X,Y (at most 10,000 in absolute value) indicating that the respective person is located at position X,Y.OutputFor each test case you are to output a single line containing a single string. If it is possible for all three to communicate then you should output "yes". Otherwise, you should output "no".To be clear, we say that two transceivers are close enough to communicate directly if the length of the straight line connecting their X,Y coordinates is at most R.ExampleInput:310 10 01 020 10 01 020 00 22 1

Output:yesyes

noCHEF AND REMISSNESS Chef is now a corporate person. He has to attend office regularly. But chef does not want to go to office, rather he wants to stay home and discover different recipes and cook them.In the office where chef works, has two guards who count how many times a person enters into the office building. Though the duty of a guard is 24 hour in a day, but sometimes they fall asleep during their duty and could not track the entry of a person in the office building. But one better thing is that they never fall asleep at the same time. At least one of them remains awake and counts who enters into the office.Now boss of Chef wants to calculate how many times Chef has entered into the building. He asked to the guard and they give him two integers A and B, count of first guard and second guard respectively.Help the boss to count the minimum and maximum number of times Chef could have entered into the office building.InputThe first line of the input contains an integer T denoting the number of test cases. The description of the T test cases follows.Each test case consists of a line containing two space separated integers A and B.OutputFor each test case, output a single line containing two space separated integers, the minimum and maximum number of times Chef could have entered into the office building.Constraints1 ≤ T ≤ 1000 ≤ A, B ≤ 1000000ExampleInput:119 17

Output:19 36SNAPE AND LADDER 

Professor Snape has lots of potions. Bottles containing all types of potions are stacked on shelves which cover the entire wall from floor to ceiling. Professor Snape has broken his bones

Page 10: C# problems

several times while climbing the top shelf for retrieving a potion. He decided to get a ladder for him. But he has no time to visit Diagon Alley. So he instructed Ron Weasley to make a ladder for him. Professor Snape specifically wants a step ladder which looks like an inverted 'V' from side view.Professor just mentioned two things before vanishing-B - separation between left side (LS) and right side (RS) on the groundLS - the length of left sideWhat should be the length of RS? At one extreme LS can be vertical and at other RS can be vertical. Ron is angry and confused. Since Harry is busy battling Voldemort, its your duty to help him find the minimum and maximum length of RS.InputFirst line contains single integer T, the number of test cases. Then T lines follow each containing 2 integers - B and LS.OutputOutput T lines, each containing minimum value of RS and maximum value of RS, separated by space. The answer (RS) will be considered correct if it has relative and absolute error less than 10-2.Constraints1 ≤ T ≤ 10001 ≤ B < LS ≤ 1000Example MIN= IF(B<L)->SQRT(L2-B2) IF(B>L)->SQRT(B2-L2)->ELSE->BInput: MAX=SQRT(B2+L2)34 510 1210 20

Output:3.0 6.403126.63325 15.620517.3205 22.3607CUTTING RECIPES The chef has a recipe he wishes to use for his guests,but the recipe will make far more food than he can serve to the guests.The chef therefore would like to make a reduced version of the recipe which has the same ratios of

ingredients, but makes less food.The chef, however, does not like fractions.The original recipe contains only whole numbers of ingredients,and the chef wants the reduced recipe to only contain whole numbers of ingredients as well.Help the chef determine how much of each ingredient to use in order to make as little food as possible.InputInput will begin with an integer T, the number of test cases.Each test case consists of a single line.The line begins with a positive integer N, the number of ingredients.N integers follow, each indicating the quantity of a particular ingredient that is used.OutputFor each test case, output exactly N space-separated integers on a line,giving the quantity of each ingredient that the chef should use in order to make as little food as possible.Sample Input32 4 43 2 3 44 3 15 9 6Sample Output1 12 3 41 5 3 2ConstraintsT≤1002≤N≤50All ingredient quantities are between 1 and 1000, inclusive.Ciel and Receipt Tomya is a girl. She loves Chef Ciel very much.Tomya like a positive integer p, and now she wants to get a receipt of Ciel's restaurant whose total price is exactly p.The current menus of Ciel's restaurant are shown the following table.

Name of Menu price

eel flavored water 1

deep-fried eel bones 2

Page 11: C# problems

clear soup made with eel livers 4

grilled eel livers served with grated radish 8

savory egg custard with eel 16

eel fried rice (S) 32

eel fried rice (L) 64

grilled eel wrapped in cooked egg 128

eel curry rice 256

grilled eel over rice 512

deluxe grilled eel over rice 1024

eel full-course 2048Note that the i-th menu has the price 2i-1 (1 ≤ i ≤ 12).Since Tomya is a pretty girl, she cannot eat a lot.So please find the minimum number of menus whose total price is exactly p.Note that if she orders the same menu twice, then it is considered as two menus are ordered. (SeeExplanations for details)InputThe first line contains an integer T, the number of test cases.Then T test cases follow.Each test case contains an integer p.OutputFor each test case, print the minimum number of menus whose total price is exactly p.Constraints1 ≤ T ≤ 51 ≤ p ≤ 100000 (105)There exists combinations of menus whose total price is exactly p.Sample Input4102562554096Sample Output2182

ExplanationsIn the first sample, examples of the menus whose total price is 10 are the following:1+1+1+1+1+1+1+1+1+1 = 10 (10 menus)1+1+1+1+1+1+1+1+2 = 10 (9 menus)2+2+2+2+2 = 10 (5 menus)2+4+4 = 10 (3 menus)2+8 = 10 (2 menus)Here the minimum number of menus is 2.In the last sample, the optimal way is 2048+2048=4096 (2 menus).Note that there is no menu whose price is 4096.TRANSFORM THE EXPRESSIONReverse Polish Notation (RPN) is a mathematical notation where every operator follows all of its operands. For instance, to add three and four, one would write "3 4 +" rather than "3 + 4". If there are multiple operations, the operator is given immediately after its second operand; so the expression written "3 − 4 + 5" would be written "3 4 − 5 +" first subtract 4 from 3, then add 5 to that.Transform the algebraic expression with brackets into RPN form.You can assume that for the test cases below only single letters will be used, brackets [] will not be used and each expression has only one RPN form (no expressions like a*b*c)InputThe first line contains t, the number of test cases (less then 100).Followed by t lines, containing an expression to be translated to RPN form, where the length of the expression is less then 400.OutputThe expressions in RPN form, one per line.ExampleInput:3(a+(b*c))((a+b)*(z+x))((a+t)*((b+(a+c))^(c+d)))

Output:abc*+ab+zx+*at+bac++cd+^*Packaging Cupcakes Now that Chef has finished baking and frosting his cupcakes, it's time to package them. Chef has Ncupcakes, and needs to decide how many

Page 12: C# problems

cupcakes to place in each package. Each package must contain the same number of cupcakes. Chef will choose an integer A between 1 and N, inclusive, and place exactly A cupcakes into each package. Chef makes as many packages as possible. Chef then gets to eat the remaining cupcakes. Chef enjoys eating cupcakes very much. Help Chef choose the package size A that will let him eat as many cupcakes as possible.InputInput begins with an integer T, the number of test cases. Each test case consists of a single integer N, the number of cupcakes.OutputFor each test case, output the package size that will maximize the number of leftover cupcakes. If multiple package sizes will result in the same number of leftover cupcakes, print the largest such size.Constraints1 ≤ T ≤ 10002 ≤ N ≤ 100000000 (108)Sample Input225Sample Output23ExplanationIn the first test case, there will be no leftover cupcakes regardless of the size Chef chooses, so he chooses the largest possible size. In the second test case, there will be 2 leftover cupcakes.AMBIGUOUS PERMUTATIONS Some programming contest problems are really tricky: not only do theyrequire a different output format from what you might have expected, butalso the sample output does not show the difference. For an example,let us look at permutations.A permutation of the integers 1 to n is anordering ofthese integers. So the natural way to represent a permutation isto list the integers in this order. With n = 5, apermutation might look like 2, 3, 4, 5, 1. However, there is another possibility of representing a permutation:

You create a list of numbers where the i-th number is theposition of the integer i in the permutation.Let us call this secondpossibility an inverse permutation. The inverse permutationfor the sequence above is 5, 1, 2, 3, 4.

An ambiguous permutation is a permutation which cannot bedistinguished from its inverse permutation. The permutation 1, 4, 3, 2for example is ambiguous, because its inverse permutation is the same.To get rid of such annoying sample test cases, you have to write aprogram which detects if a given permutation is ambiguous or not.Input SpecificationThe input contains several test cases.The first line of each test case contains an integer n(1 ≤ n ≤ 100000).Then a permutation of the integers 1 to n followsin the next line. There is exactly one space characterbetween consecutive integers.You can assume that every integer between 1 and nappears exactly once in the permutation.

The last test case is followed by a zero.Output SpecificationFor each test case output whether the permutation is ambiguous or not.Adhere to the format shown in the sample output.Sample Input41 4 3 252 3 4 5 1110Sample Outputambiguousnot ambiguousambiguousSUMS IN A TRIANGLE 

Page 13: C# problems

Let's consider a triangle of numbers in which a number appears in the first line, two numbers appear in the second line, three in the third line, etc. Develop a program which will compute the largest of the sums of numbers that appear on the paths starting from the top towards the base, so that:on each path the next number is located on the row below, more precisely either directly below or below and one place to the right;the number of rows is strictly positive, but less than 100all numbers are positive integers between O and 99.InputIn the first line integer n - the number of test cases (equal to about 1000).Then n test cases follow. Each test case starts with the number of lines which is followed by their content.OutputFor each test case write the determined value in a separate line.ExampleInput:2312 11 2 34 1 1 2 4 1 22 3 1 1

Output:59THE LEAD GAME The game of billiards involves two players knocking 3 balls aroundon a green baize table. Well, there is more to it, but for ourpurposes this is sufficient.The game consists of several rounds and in each round both playersobtain a score, based on how well they played. Once all the roundshave been played, the total score of each player is

determined byadding up the scores in all the rounds and the player with the highertotal score is declared the winner.The Siruseri Sports Club organises an annual billiards game wherethe top two players of Siruseri play against each other. The Managerof Siruseri Sports Club decided to add his own twist to the game bychanging the rules for determining the winner. In his version, at theend of each round the leader and her current lead are calculated. Onceall the rounds are over the player who had the maximum lead at theend of any round in the game is declared the winner.Consider the following score sheet for a game with 5 rounds: Round Player 1 Player 2

1 140 82 2 89 134 3 90 110 4 112 106 5 88 90 The total scores of both players, the leader and the lead aftereach round for this game is given below: Round Player 1 Player 2 Leader Lead

1 140 82 Player 1 58 2 229 216 Player 1 13 3 319 326 Player 2 7 4 431 432 Player 2 1 5 519 522 Player 2 3The winner of this game is Player 1 as he had the maximum lead (58at the end of round 1) during the game.Your task is to help the Manager find the winner and the winninglead. You may assume that the scores will be such that there will

Page 14: C# problems

always be a single winner. That is, there are no ties.InputThe first line of the input will contain a single integer N (N≤ 10000) indicating the number of rounds in the game. Lines2,3,...,N+1 describe the scores of the two players in the N rounds.Line i+1 contains two integer Si and Ti, the scores of the Player 1and 2 respectively, in round i. You may assume that 1 ≤ Si ≤1000 and 1 ≤ Ti ≤ 1000.OutputYour output must consist of a single line containing two integersW and L, where W is 1 or 2 and indicates the winner and L is themaximum lead attained by the winner.ExampleInput:5140 8289 13490 110112 10688 90Output:1 58FACTORIAL The most important part of a GSM network is so called Base Transceiver Station (BTS). These transceivers form the areas called cells (this term gave the name to the cellular phone) and every phone connects to the BTS with the strongest signal (in a little simplified view). Of course, BTSes need some attention and technicians need to check their function periodically.The technicians faced a very interesting problem recently. Given a set of BTSes to visit, they needed to find the shortest path to visit all of the given points and return back to the central company building. Programmers have spent several months studying this problem but with no results. They were unable to find the solution fast enough. After a long time, one of the programmers found this problem in a conference article. Unfortunately, he found that the problem is so called "Traveling Salesman Problem" and it

is very hard to solve. If we have N BTSes to be visited, we can visit them in any order, giving us N! possibilities to examine. The function expressing that number is called factorial and can be computed as a product1.2.3.4....N. The number is very high even for a relatively small N.The programmers understood they had no chance to solve the problem. But because they have already received the research grant from the government, they needed to continue with their studies and produce at least some results. So they started to study behavior of the factorial function.For example, they defined the function Z. For any positive integer N, Z(N) is the number of zeros at the end of the decimal form of number N!. They noticed that this function never decreases. If we have two numbers N1<N2, then Z(N1) <= Z(N2). It is because we can never "lose" anytrailing zero by multiplying by any positive number. We can only get new and new zeros. The function Z is very interesting, so we need a computer program that can determine its value efficiently.InputThere is a single positive integer T on the first line of input (equal to about 100000). It stands for the number of numbers to follow. Then there are T lines, each containing exactly one positive integer number N, 1 <= N <= 1000000000.OutputFor every number N, output a single line containing the single non-negative integer Z(N).ExampleSample Input:63601001024234568735373Sample Output:0142425358612183837ENORMOUS INPUT TEST 

Page 15: C# problems

The purpose of this problem is to verify whether the method you are using to read input data is sufficiently fast to handle problems branded with the enormous Input/Output warning. You are expected to be able to process at least 2.5MB of input data per second at runtime.InputThe input begins with two positive integers n k (n, k<=107). The next n lines of input contain one positive integer ti, not greater than 109, each.OutputWrite a single integer to output, denoting how many integers ti are divisible by k.ExampleInput:7 31519663697999999611

Output:4