task
stringlengths
0
154k
__index_level_0__
int64
0
39.2k
Firing (FIRING) About N birds in a row, each bird i-th has power a[i]. If we shoot bird i-th, bird (i-1)-th, bird i-th and bird (i+1)-th will fight, so we lost a[i-1]+a[i]+a[i+1] energy (that a[0]=0, a[n+1]=0). And then, bird i+1 will stand near bird i-1. John will shoot the bird in descending order of power. If at the time, we have many birds that power is maximum, Jonh'll shoot the bird i-th such that i is smallest possible. Let me know total energy John lost to shoot all bird. Input The first line is a integer: N. (1≤N≤1000000). The next line is N integer: a[1],a[2],...,a[n]. (1≤a[i]≤1000000000). Output Only integer: Result. Example Input: 6 1 4 2 3 6 5 Output: 38
34,900
Sherlock Holmes (SKHOL) Sherlock Holmes is a renowned detective. His Scotland Yard colleagues often provide him with a set of evidence and ask for his help in solving the mysteries. After many years of practice, Holmes has gained an enormous amount of experience and already knows causes for many common events, which, combined with his extraordinary deductive capabilities, enables him to solve cases in a matter of minutes, from the comfort of his chair. Holmes' knowledge base can be modeled as a set of implications of the form (where A and B represent events), which means that, if A occurred, event B must have also occurred (remember that logical implication is false only if A is tru Sherlock Holmes is a renowned detective. His Scotland Yard colleagues often provide him with a set of evidence and ask for his help in solving the mysteries. After many years of practice, Holmes has gained an enormous amount of experience and already knows causes for many common events, which, combined with his extraordinary deductive capabilities, enables him to solve cases in a matter of minutes, from the comfort of his chair. Holmes' knowledge base can be modeled as a set of implications of the form A -> B(where A and B represent events), which means that, if A occurred, event B must have also occurred (remember that logical implication is false only if A is true and B is false). Of course, implications can form chains of reasoning, e.g. A -> B -> C. However, there will never be a circular chain of implications (e.g. A -> B -> ... -> A). Holmes is given a set S = {S1, S2, S3, ..., Sn} of events that are known to have occurred. He can then, using his extensive knowledge and deductive powers, find all events that have certainly occurred. It's important to note that Holmes' knowledge is so mind-bogglingly huge that he knows all possible causes of events. In other words, there is no implication that is true, but not included in Holmes' knowledge base. Many detective agencies would highly appreciate Holmes' one of a kind capabilities, so you were given a task to accomplish with a computer what is out of reach for ordinary mortals. Write a program to find all events that have certainly occurred based on the given implications and evidence collected by your colleague detectives. Input First line of input consists of three integers, D (1 ≤ D ≤ 1000), the number of different types of events, M (1 ≤ M ≤ 100000), the number of implications, and N (1 ≤ N ≤ D), the number of evidence collected by the detectives. Each of the M lines that follow contains two integers A and B (1 ≤ A, B ≤ D), describing an implication A -> B. Finally, each of the last N lines contain an integer X (1 ≤ X ≤ D) describingan event that must have occurred, based on the evidence collected by detectives. Output The first and only line of output should contain integers (in any order) representing events that have certainly occurred. Example Input: 3 2 1 1 2 2 3 2 Output: 1 2 3   Input: 3 2 1 1 3 2 3 3 Output: 3 Input: 4 4 1 1 2 1 3 2 4 3 4 4 Output: 1 2 3 4
34,901
Xor (SKTRIXOR) Mirko and Slavko have built their own LED display. The display is initially white. During each of the N parts of the testing phase, Mirko attached three electrodes to the display in such way that they formed a right isosceles triangle. He noticed that, after attaching the electrodes, all pixels in the enclosing triangle are inverted (white pixels become black, and black pixels become white). Watching Mirko play with the electrodes, Slavko observed interesting shapes emerging on the screen. Mathematically inclined as he is, first thing that crossed his mind was how to calculate total area covered by black pixels. Help him by writing a program to do just that! INPUT First line of input contains an integer N (1 ≤ N ≤ 10), number of triangles formed by Mirko's fiddling with electrodes. Each of the following N lines contains three integers X, Y and R (1 ≤ X, Y, R ≤ 106 ), describing a triangle. (X, Y) are the coordinates of the lower left corner of the triangle, while R represents the length of the two sides of the triangle. Mirko and Slavko have built their own LED display. The display is initially white. During each of the N parts of the testing phase, Mirko attached three electrodes to the display in such way that they formed a right isosceles triangle. He noticed that, after attaching the electrodes, all pixels in the enclosing triangle are inverted (white pixels become black, and black pixels become white). Watching Mirko play with the electrodes, Slavko observed interesting shapes emerging on the screen. Mathematically inclined as he is, first thing that crossed his mind was how to calculate total area covered by black pixels. Help him by writing a program to do just that! INPUT First line of input contains an integer N (1 ≤ N ≤ 10), number of triangles formed by Mirko's fiddling with electrodes. Each of the following N lines contains three integers X, Y and R (1 ≤ X, Y, R ≤ 10^6 ), describing a triangle. (X, Y) are the coordinates of the lower left corner of the triangle, while R represents the length of the two sides of the triangle. OUTPUT The first and only line of output should contain the area covered by black pixels, rounded to one decimal place. SAMPLE TEST CASES Input: 3 1 1 2 7 1 6 5 3 4 Output: 24.0 Input: 5 5 5 99 5 5 99 5 5 99 5 5 99 5 5 99 Output: 4900.5 Input: 4 5 5 99 5 5 99 5 5 99 5 5 99 Output: 0.0
34,902
Dispatching (HDISP) Dispatching   In a sect of ninja, ninjas are dispatched to a client, and they are rewarded according to their work. In this sect, there is one ninja called the Master. Every ninja except the Master has one and only one boss. In order to preserve the confidentiality and to encourage leadership, any instructions concerning their work are always sent by a boss to his/her subordinates. It is forbidden to send instructions by other methods. You are gathering a number of ninjas and dispatch them to a client. You have to pay salaries to dispatched ninjas. For each ninja, the amount of salary for him/her is fixed. The total amount of salaries paid to them should be within a budget. Moreover, in order to send instructions, you have to choose a ninja as a manager who can send instructions to all dispatched ninjas. When instructions are sent, a ninja who is not dispatched may mediate the transmission. The manager may or may not be dispatched. If the manager is not dispatched, he will not be paid. You would like to maximize the satisfaction level of the client as much as possible within a budget. The sat- isfaction level of the client is calculated as the product of the total number of dispatched ninjas and the leadership level of the manager. For each ninja, his/her leadership level is fixed. In a sect of ninja, ninjas are dispatched to a client, and they are rewarded according to their work. In this sect, there is one ninja called the Master. Every ninja except the Master has one and only one boss. In order to preserve the confidentiality and to encourage leadership, any instructions concerning their work are always sent by a boss to his/her subordinates. It is forbidden to send instructions by other methods. You are gathering a number of ninjas and dispatch them to a client. You have to pay salaries to dispatched ninjas. For each ninja, the amount of salary for him/her is fixed. The total amount of salaries paid to them should be within a budget. Moreover, in order to send instructions, you have to choose a ninja as a manager who can send instructions to all dispatched ninjas. When instructions are sent, a ninja who is not dispatched may mediate the transmission. The manager may or may not be dispatched. If the manager is not dispatched, he will not be paid. You would like to maximize the satisfaction level of the client as much as possible within a budget. The sat- isfaction level of the client is calculated as the product of the total number of dispatched ninjas and the leadership level of the manager. For each ninja, his/her leadership level is fixed.   Task Write a program that, given the boss Bi, the amount of salaryCi, the leadership level Li of each ninja i(1 <= i <= N), and the budget for salaries M, outputs the maximum value of the satisfaction level of the client when the manager and dispatched ninjas are chosen so that all the conditions are fulfilled.   Constraints 1 <= N <= 100 000 The number of ninjas 1 <= M <= 1 000 000 000 The budget for salaries 0 <= Bi < i The boss of each ninja 1 <= Ci <= M The amount of salary of each ninja 1 <= Li <= 1 000 000 000 The leadership level of each ninja   Input Read the following data from the standard input. • The first line of input contains two space separated integers N, M, where N is the number of ninjas and M is the budget. • The following N lines describe the boss, salary, leadership level of each ninja. The (i + 1)-th line contains three space separated integers Bi,Ci,Li, describing that the boss of ninja i is ninja Bi, the amount of his/her salary is Ci, and his/her leadership level is Li. The ninja i is the Master if Bi = 0. Since the inequality Bi < i is always satisfied, for each ninja, the number of his/her boss is always smaller than the number of himself/herself.   Output Write the maximum value of the satisfaction level of the client to the standard output.   Grading In test cases worth 30% of the full score, N <= 3 000.   Sample Input and Output Sample Input 1 5 4 0 3 3 1 3 5 2 2 2 1 2 4 2 3 1 Sample Output 1 6 If we choose ninja 1 as a manager and ninja 3, 4 as dispatched ninjas, the total amount of salaries is 4 which does not exceed the budget 4. Since the number of dispatched ninjas is 2 and the leadership level of the manager is 3, the satisfaction level of the client is 6. This is the maximum value.
34,903
Uplan (VNPLAN2) Bài này là bài V11PLAN với giới hạn N lớn hơn. Note: this is V11PLAN with higher limit for N. In 2011, Vietnam set out a national development plan . The plan will consist of two phases: the first year and last year . At each stage , a number of paths between pairs of cities will be built . You are given a graph showing the results of the plan , in which each edge ( i , j ) represents the plan to create a path between city i and city j ( not necessarily the way directly) . You need to count the number of different plans can produce results . Two different plan if there is a road was built in the period of the plan but not built in the corresponding period of the other plan . For example , if we build the first phase ramp ( 1.2 ) , we constructed a later stage seams ( 2.3 ) , the resulting graph will have three edges : ( 1,2 ) , ( 2 , 3 ) , ( 1.3 ) by the existence of paths between all 3 cities. If we build ( 1.2 ) in the first phase and construction ( 1.2 ) , ( 1.3 ) at a later stage , we obtain the same result . Note , to save , we can only build a road between a pair of cities in a period , but later stages we can build a longer route to replace street due to subsidence rate in Vietnam South is pretty fast . In 2011, Vietnam sets out a national development plan. The plan will consist of two phases: the first half of the year and the second half of the year. At each phase, a number of paths between some pairs of cities will be built. You are given a graph describle the result of the plan, in which each edge (i,j) represents the plan to make city i and city j connected (not necessarily directly). You need to count the number of different plans that can produce that graph. Two plans are  different if there is a road being built in a phase of the plan but not built in the corresponding phase of the other plan. For example, if we build in the first phase road (1,2) , and then in the second phase we build (2,3) , the resulting graph will have three edges: (1,2), (2,3), (1,3). Building (1,2) in the first phase and (1,2), (1,3) in the later phase produce the same result. Note, we can only build a road between a pair of cities in a phase, but at the later phase we can rebuild that route again due to subsidence rate in Vietnam is pretty fast.   Input The first line is N (1 <= N <= 80). N lines follow, each has N integers. City i and j should be connected at the end of the year if the j-th number at line i is 1, else it's 0. The input will make sure that is city i and j are connected, j and k are connected, then i and k are connected. Output A single integer which is the number of different plans modulo 1000000007. Example Input: 2 0 1 1 0 Output: 3 Explain: we can build the road between two cities only in the first haft of the year, second half of the year, or both. Input: 3 0 1 1 1 0 1 1 1 0 Output: 54 Input: 16 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 Output: 604876153
34,904
Best Temperature (MILKTEMP) Trong một trang trại có N chú bò. Các chú bò rất nhạy cảm với nhiệt độ. Mỗi chú bò i có một khoảng nhiệt độ nhất định A i .. B i mà chúng có thể thấy thoải mái. Nếu gặp nhiệt độ T < A i , chú bò sẽ thấy quá lạnh và sản xuất X đơn vị sữa. Nếu gặp nhiệt độ T nằm trong khoảng nhiệt độ này A i ≤ T ≤ B i chú bò sẽ sản xuất Y đơn vị sữa. Nếu nhiệt độ T > B i , chú bò sẽ thấy quá nóng và sản xuất Z đơn vị sữa. Giá trị Y sẽ luôn lớn hơn cả X và Z . Cho các giá trị X , Y và Z cũng như vùng nhiệt độ của mỗi chú bò, bạn hãy tính tổng lượng sữa lớn nhất có thể đạt được nếu nhiệt độ được đặt một cách tối ưu. Input   Dòng một chứa 4 số nguyên N X Y Z . N dòng tiếp, dòng thứ i chứa hai số nguyên A i và B i Output Ghi ra lượng sữa lớn nhất có thể đạt được Giới hạn 1 ≤ N ≤ 20,000 1 ≤ A i ≤ B i ≤ 10 9 0 ≤ X , Y , Z ≤ 1000 40% số test có B i ≤ 100 60% số test có N ≤ 1000 Ví dụ Input: 4 7 9 6 5 8 3 4 13 20 7 10 Output: 31 Giải thích Nhiệt độ tối ưu sẽ bằng 7 hoặc 8. Khi đó chú bò thứ 1 và thứ 4 sẽ thoải mái, chú bò thứ 2 cảm thấy nóng và chú bò thứ 3 cảm thấy lạnh. Số lượng sữa đạt được: 9 × 2 + 7 + 6 = 31
34,905
Periodicity (HCHANGE) Periodicity Byteasar, the king of Bitotia, has ordained a reform of his subjects' names. The names of Bitotians often contain repeating phrases, e.g., the name  Abiabuabiab  has two occurrences of the phrase  abiab . Byteasar intends to change the names of his subjects to sequences of bits matching the lengths of their original names. Also, he would very much like to reflect the original repetitions in the new names. In the following, for simplicity, we will identify the upper- and lower-case letters in the names. For any sequence of characters (letters or bits) w=w1 * w2 * ... * wk, p (1 <= p < k) is a period of w if w_i = w_i+p for all i = 1....k-p. We denote the set of all periods of w by Okr(w). For example, Okr(0000) = {1,2,3}. Byteasar has decided that every name is to be changed to a sequence of bits that: has length matching that of the original name, has the same set of periods as the original name, is the smallest (lexicographically 1 ) sequence of bits satisfying the previous conditions. For example, the name  ABIABUABIAB  should be changed to  01001101001 ,  BABBAB  to  010010 , and  BABURBAB  to  01000010 .   Byteasar has asked you to write a program that would facilitate the translation of his subjects' current names into new ones. If you succeed, you may keep your current name as a reward! Input In the first line of the standard input there is a single integer   - the number of names to be translated (1 <= k <= 20). The names are given in the following lines, one in each line. Each name consists of no less than 1 and no more than 200000 upper-case (capital) letters (of the English alphabet). In the test worth 30% of the points each name consists of at most 20 letters. Output Your program should print   lines to the standard output. Each successive line should hold a sequence of zeroes and ones (without spaces in between) corresponding to the names given on the input. If an appropriate sequence of bits does not exists for some names, then " XXX " (without quotation marks) should be printed for that name. Example For the input data: 3 ABIABUABIAB BABBAB BABURBAB the correct result is: 01001101001 010010 01000010
34,906
Lampice (HLAMPS) LAMPICE 2*N light bulbs are arranged in two rows and N columns. Each light bulb can be either off or on, and  all lights are initially off.  We want to turn some of them on so that they form a beautiful pattern. In one step we can change  the state of a sequence of (one or more) consecutive light bulbs in the same row or column.  Given the desired pattern, write a program that finds the minimum number of steps required to form  the pattern.    The following figure illustrates the seven steps needed to obtain the pattern given in the third example:    0 00000000000000000000 00000000000000000000 1 111 00000000000000000 00000000000000000000 2 111000 1 0000000000000 000000 1 0000000000000 3 11100010000000000000 0 11111011 00000000000 4 1110110 1111 000000000 01111101100000000000 5 11101101111000 11111 0 01111101100000000000 6 111011011110001 0 1110 011111011000000 1 0000 7 11101101111000101 0 10 01111101100000010 1 00   input data  The first line of input contains an integer N, 1 ≤ N ≤ 10,000, the number of columns.  Each of the following two lines contains a sequence of N characters representing the desired final  pattern.  Character '1' indicates a light bulb that should be on in the final state, while the character '0' indicates a  light bulb that should be off.  output data  The first and only line of output should contain a single integer – the minimum number of steps  required.  examples  input    3  100  000    output    1  input    5  11011  11011    output    3  input    20  11101101111000101010  01111101100000010100    output    7
34,907
Simplifying the Farm (HKRUSKAL) Farmer John has been taking an evening algorithms course at his local university, and he has just learned about minimum spanning trees. However, Farmer John now realizes that the design of his farm is not as efficient as it could be, and he wants to simplify the layout of his farm.   The farm is currently arranged like a graph, with vertices representing fields and edges representing pathways between these fields, each having an associated length. Farmer John notes that for each distinct length, at most three pathways on his farm share this length. FJ would like to remove some of the pathways on his farm so that it becomes a tree -- that is, so that there is one unique route between any pair of fields. Moreover, Farmer John would like this to be a minimum spanning tree -- a tree having the smallest possible sum of edge lengths.   Help Farmer John compute not only the sum of edge lengths in a minimum spanning tree derived from his farm graph, but also the number of different possible minimum spanning trees he can create.   PROBLEM NAME: simplify   INPUT FORMAT:   * Line 1: Two integers N and M (1 <= N <= 40,000; 1 <= M <= 100,000), representing the number of vertices and edges in the farm graph, respectively. Vertices are numbered as 1..N.   * Lines 2..M+1: Three integers a_i, b_i and n_i (1 <= a_i, b_i <= N; 1 <= n_i <= 1,000,000) representing an edge from vertex a_i to b_i with length n_i. No edge length n_i will occur more than three times.   SAMPLE INPUT (file simplify.in):   4 5 1 2 1 3 4 1 1 3 2 1 4 2 2 3 2   OUTPUT FORMAT:   * Line 1: Two integers representing the length of the minimal spanning tree and the number of minimal spanning trees (mod 1,000,000,007).   SAMPLE OUTPUT (file simplify.out):   4 3   OUTPUT DETAILS:   Picking both edges with length 1 and any edge with length 2 yields a minimum spanning tree of length 4.
34,908
Game of Life (GMLIFE1) Alice and Bob are playing a game of life, Alice is representing the evil character, and Bob is representing the good character; the game requires the evil to make a ritual in order to rule the world; Bob, being the good character, he tries to stop Alice from making this ritual. The ritual consists of m gears, that can rotate in only one direction, that is clockwise, each with a pointer pointing to one of its holes, and the ith gear containts n[i] holes; the configuration of the gears was ready to make the ritual, but unfortunately for Alice, Bob then rotated the gears by some number of pushes, precisely he pushed the i-th gear by a[i] holes, then he changed the system of the gears, and made it with one global control for all the gears, so that the only move Alice can make is to push all the gears at the same time, each by one hole. Since it will take too much time to complete the ritual, Alice thought of bringing some workers to finish the task for her as soon as possible, given that they all do the same amount of work. Alice wants to know in how many ways can she do this. Alice and Bob are playing a game of life, Alice is representing the evil character, and Bob is representing the good character; the game requires the evil to make a ritual in order to rule the world; Bob, being the good character, he tries to stop Alice from making this ritual. The ritual consists of m gears that can rotate in only one direction, that is clockwise direction; each gear has a pointer pointing to one of its holes; the i th  gear containts n i  holes; in order to make the ritual, all the gears must be on their starting position. The configuration of the gears was ready to make the ritual, but unfortunately for Alice, Bob rotated the gears by some number of pushes, precisely he pushed the i th  gear by a i  holes, then he changed the system of the gears, and made it with one global control for all the gears, so that the only move Alice can make is to push all the gears at the same time by one hole for each gear. Since it will take too much time to complete the ritual, Alice thought of bringing some workers to finish the task for her as soon as possible, given that they all do the same amount of work. Alice wants to know in how many ways can she do this. It's guaranteed that the minimum positive number of moves Alice can make, so it can restore the gears from the current configuration to Bob's configuration again, will not exceed 10 14 ; and it is also guaranteed that Bob's configuration isn't the original configuration.   Sample input 1, the first gear rotated clockwise by 2 pushes, and the second gear rotated clockwise by 5 pushes.     Input For each input file, the first line contains a single integer m (1 <= m <= 10 3 ), the number of gears, and each of the next m lines contains two integers, the i th  line contain the two integers a i  and n i  space separated (0 <= a i  < n i  < 10 14 ). Output For each test case, output a line containing a single integer, the number of ways to get an amount of workers, such that each does the same amount of work so they can solve the ritual. Example Input: 2 2 3 5 7 Output: 5 Input: 2 2 6 3 4 Output: 0 In the first case, the ritual can be completed after 16 pushes, so Alice can bring 1, 2, 4, 8, or 16 workers. In the second case, the ritual cannot be completed.
34,909
Discrete Roots (DISCRT1) In this problem, we try to compute discrete k th  root modulo n; given n, k, a; find all the solutions for x such that x k  = a (mod n) and x is coprime with n. Input For each input file, there are 3 space seperated integers n, k, a. n = p e  for some odd prime p, integer e > 0; 0 <= a < n <= 10 9 , 0 <= k < phi(n), where phi is Euler's totient function; the numbers n, a are coprimes. Output The first line of the output contains a single integer m, the number of solutions in the range [0, n - 1] that are coprimes with n, followed by m lines that contain the m solutions in ascending order. It is guranteed that m <= 10 4 . Example Input: 5 1 3 Output: 1 3
34,910
Robot quét vôi (HVT_QV) Một quần thể nhà cao tầng được xây dựng trên một nền hình chữ nhật, trên đó được chia thành M × N ô vuông đơn vị ( M dòng, N cột). Các dòng được đánh số từ 1 đến M , các cột được đánh số từ 1 đến N . Người ta xem khu nhà được tạo bởi các khối có đáy là một ô vuông với những chiều cao nào đó mà người ta gọi là những đơn nguyên. Một đơn nguyên được xác định bởi tọa độ dòng, cột của ô đáy và chiều cao tương ứng. Một khối nhà được định nghĩa là một tập hợp các đơn nguyên có đáy tạo thành một miền gồm các ô kề cạnh. Ví dụ hình vẽ dưới đây mô tả một quần thể gồm 3 khối nhà: Người ta đánh số các khối nhà bằng những số nguyên liên tục bắt đầu từ 1 theo trình tự duyệt các ô đáy theo từng dòng từ 1 đến M và trên mỗi dòng, duyệt các ô đáy theo từng cột từ 1 đến N . Ví dụ, các khối nhà cho trong hình vẽ bên dưới được đánh số theo thứ tự các ô đáy (có màu xám, con số là chiều cao). Người ta muốn quét vôi các bức tường xung quanh tất cả các khối nhà (không quét vôi phía trên nóc nhà) 1 2 3 0 2 1 1 0 1 0 0 1 2 1 1 0 0 1 0 0 0 1 1 0         Yêu cầu: Hãy xác định số lượng các khối nhà, tổng số diện tích quét vôi, khối nhà có diện tích quét vôi lớn nhất và diện tích này. Input - Dòng đầu tiên ghi 2 số nguyên M , N (0 < M , N ≤100) - M dòng tiếp theo, mỗi dòng ghi N số nguyên thể hiện chiều cao của đơn nguyên (0 ≤ H [ i , j ] ≤ 10.000 với i = 1, 2, …, M ; j = 1, 2, …, N ), với quy ước bằng 0 khi đơn nguyên này không có. Giả thiết rằng các giá trị này đều là các số nguyên và tính theo đơn vị một cạnh của ô vuông. Các số trên cùng môt dòng ghi cách nhau ít nhất một dấu cách. Output - Dòng đầu tiên ghi số lượng các khối nhà; - Dòng thứ hai ghi tổng diện tích cần quét vôi; - Dòng thứ ba ghi số hiệu của khối nhà có diện tích quét vôi lớn nhất và giá trị diện tích của khối nhà này. Nếu có nhiều khối nhà có cùng diện tích quét vôi lớn nhất thì đưa ra khối nhà có số hiệu nhỏ nhất. Example Input: 4 6 1 2 3 0 2 1 1 0 1 0 0 1 2 1 1 0 0 1 0 0 0 1 1 0 Output: 3 50 1 30
34,911
HERMAN (CCHERMAN) The 19th century German mathematician Hermann Minkowski investigated a non-Euclidian  geometry, called the taxicab geometry. In taxicab geometry the distance between two points T1(x1,  y1) and T2(x2, y2) is defined as:    D(T1,T2) = |x1 - x2| + |y1 - y2|    All other definitions are the same as in Euclidian geometry, including that of a circle:    A circle is the set of all points in a plane at a fixed distance (the radius) from a fixed point (the  centre of the circle).    We are interested in the difference of the areas of two circles with radius R, one of which is in  normal (Euclidian) geometry, and the other in taxicab geometry. The burden of solving this difficult  problem has fallen onto you. The 19th century German mathematician Hermann Minkowski investigated a non-Euclidian geometry, called the taxicab geometry. In taxicab geometry the distance between two points T1(x1, y1) and T2(x2, y2) is defined as: D(T1,T2) = |x1 - x2| + |y1 - y2|   All other definitions are the same as in Euclidian geometry, including that of a circle:  A circle is the set of all points in a plane at a fixed distance (the radius) from a fixed point (the centre of the circle). We are interested in the difference of the areas of two circles with radius R, one of which is in normal (Euclidian) geometry, and the other in taxicab geometry. The burden of solving this difficult problem has fallen onto you. Input The first and only line of input will contain the radius R, an integer smaller than or equal to 10000. Output On the first line you should output the area of a circle with radius R in normal (Euclidian) geometry. On the second line you should output the area of a circle with radius R in taxicab geometry. Note: Please output the result with 6 digits after the decimal point.   Example Input1: 1 Output1: 3.141593 2.000000 Input2: 21 Output2: 1385.442360 882.000000 Input3: 42 Output3: 5541.769441 3528.000000
34,912
Kill evil instantly (HAJIME) This problem tests your knowledge of the C programming language. Your task is to submit a snippet of C code that consists of two declarations defining a type called "zan", which should be a struct containing two members: first an unsigned int called "aku", then a constant pointer to char called "soku". To make things more interesting, you can't use any whitespace in either declaration, and the two declarations must be sufficiently dissimilar (basically, you have to use two different tricks to get around the lack of whitespace). Input There is no input. Output Your submission should consist of exactly two declarations as described above, separated by whitespace. Update : "Exactly two" means exactly two. Your code isn't allowed to define any other types; anything containing struct foo or typedef unsigned int is rejected. "Whitespace" includes newlines. NUL ('\0') is not whitespace, but it isn't a valid token separator either. Example Output: typedef:struct{unsigned*aku;char*soku;}zan; typedef:struct{unsigned*aku;char*soku;}zan; This example is invalid for the following reasons: typedef: is a syntax error aku and soku have the wrong type the two declarations are too similar
34,913
Problem (PROBLEM) This problem has no statement Input The format of the input data in not known. Constraints The input file is of the reasonable size. Output Output the right answer for each test. Example Input: 4 188 432 100 765 Output: 4 0 2 1
34,914
Guess the task II (GUESS002) Example Input: 2.0 1.6 Output: 3.0
34,915
Guess the task III (GUESS003) Example Input: 1.1 Output: 1
34,916
Guess the task V (GUESS005) .................................................................................................................................................................. ...................................................n vertex.................................................................................................... .................................................................................................................................................................. .................................................................................................................................................................. .....................................................................................3,14....................................................................... .................................................................................................................................................................. .................................................................................................................................................................. .................................................................................................................................................................. .................................................................................................................................................................. .................................................................................................................................................................. ...................................................................................................................r.............................................. ........................................................................................... Example Input: 10 6 Output: 60.0
34,917
LOGIC (LGIC) Given a sequance of natural numbers. Find N'th term of this sequence. a1=2, a2=4, a3=11, a4=36, a5=147, a6=778 ... ... ... ... aN. Input   Only one natural number 7<=N<20. Output One natural number. N'th term of the sequence. Example Input: 10 Output: 3629814
34,918
SEQUENCE (BEANONE) A sequence of natural numbers is given A1=9 A2=96 A3=685 A4=4992 and so on.. Your task is to find the Nth term of the sequence. Input A natural number N such that 5<=N<=1000 Output The Nth number of the sequence which is also a natural number. Example Input: 8 Output: 39916680
34,919
The Easiest Sequence Of the World!! (ARD1) I just found the easiest and funny sequence ever ! Your task is simple. Just write a program to find the Nth term of this sequence!! The sequence is as follows:: 3, 8, 12, 17, 22, 28, 35....   I just found the easiest and funny sequence ever ! Your task is simple. Just write a program to find the Nth term of this sequence!! The sequence is as follows:: 3, 8, 12, 17, 22, 28, 35....     Input   First line contains t = number of test cases and then next t lines follow n.  1<=n<=10^11 Note-- Value of n is modified to encourage better solutions! Output   Just the output the nth term modulo 123456789   Example Input: 3 1 2 3 Output: 3 8 12
34,920
External Sequence (VPL0_E) This problem is nearly impossible to solve! You are given no goals; you can only guess what the corresponding output is for each input. Good luck! Input The first line contains an integer T , which specifies the number of test cases. Then, will follow the descriptions of T test cases. For each case you will receive an integer N , then, you must print the N -th sequence. The input must be read from standard input.   Output For each input case you must print the string "Scenario #i: " where i denotes the case you are analyzing (starting from 1) and the sequence as described above. The output must be written to standard output.   Input Output for sample input 5 0 1 2 3 9 Scenario #1: 1 Scenario #2: 11 Scenario #3: 21 Scenario #4: 1211 Scenario #5: 13211311123113112211   Constraints • 1 ≤ T ≤ 41 • 0 ≤ N ≤ 40  The score will be the quantity of characters the code has.
34,921
LOGIC (CODR) Mr.X  has recently graduated from his university.He was called for an interview by a company Y.In the coding round the company asked from Mr.X to decrypt a set of 3 digit numbers using some algorithm.Mr.X does not have very good programming skills,but he knows you as a friend and a talented programmer.Help Mr.X to get selected for the job. Input Each line of input consists of a 3 digit number. Inputs are terminated when 0 is encounterred. Output Ouput consists of a decrypted number for each input number. Example Input: 999 111 124 987 0   Output: 8181261 010120 0208100 7256821
34,922
Jaddouic Sequence (JADDOU3) Jadou has created another boring sequence, he wrote the 1st 5 numbers on a stone, 300 years later Hasan Jadou Jr. found the stone and wanted to find the nth element of the sequence. The numbers written on the stone were... 1, 10 , 36 , 136 ,528 Help Jadou find the rest of the sequence. print the nth element of the Jadou sequence mod 123456789   Jadou has created another boring sequence, he wrote the 1st 5 numbers on a stone, 300 years later Hasan Jadou Jr. found the stone and wanted to find the nth element of the sequence. The numbers written on the stone were... 3, 10 , 36 , 136 ,528. Jaddou junior descovered that the elements of the sequence are always even except the 1st one. Help Jadou find the rest of the sequence. print the nth element of the Jaddou sequence mod 123456789     Input One integer n.(0<n<10^18) Output The nth element of the Jaddou sequence mod 123456789. Example Input: 5 Output: 528
34,923
Strange Pattern (Easy) (THINK) Mr. X is new to programming and he tries to make a function to print out the x-th fibonacci numbers. For x=1 and x=2, the function prints out 2 and 3 respectively. But for some reason, every number after that also prints out 3. In the end, Mr. X given up on fixing the function and instead challenges you to recreate the function that he created. Since Mr. X is new to programming, he only wants you to do a single statement in the function so he can understand. The statement must also not contain any letter but 'x'. Mr. X doesn't understand bitwise, relational, logical, and conditional/ternary operators, so don't use that. Mr. X has given you his code for you to edit, but you can only edit a certain part of the code. #include <stdio.h> int count(int x){ return edit this part ; } int main(){ for( int i=1 ; i-1001 ; i++ ) printf("%d %d\n",i,count(i)); return 0; } #include <stdio.h> int count(int x){ return (x+1)%x+2 } int main(){ for( int i=1 ; i-1001 ; i++ ) printf("%d %d\n",i,count(i)); return 0; }M Mr. X will first check the correctness of the output. If the output is correct, he then will check the code. If he finds anything that he doesn't understand, the result will be "compilation error". Changing the code other than the allowed part may also result in a compile error. DO NOT USE ANY WHITESPACE ON THE EDITED PART Input No input. Output 1 2 2 3 3 3 4 3 ... and so on ... 998 3 999 3 1000 3    Click here to see all problems in this series!
34,924
Strange Pattern (Medium) (THINKBIT) Mr. X has learned bitwise operators. With this ability, he once again wants to make a fibonacci function. Same as before, for x=1 and x=2 the function prints out 2 and 3 respectively. But the problem still occurs, every number after 2 also prints out 3. Again, Mr. X given up on fixing the function and instead challenges you to recreate the function that he created. Since he wants to study more bitwise operators, he only wants you to do a single   statement using only bitwise operators . You can also use numbers and the letter 'x'. Mr. X has given you his code for you to edit, but you can only edit a certain part of the code. #include <stdio.h> int count(int x){ return edit this part ; } int main(){for(int i=1;i^10001;i++)printf("%d %d\n",i,count(i));return 0;} #include <stdio.h> int count(int x){ return (x+1)%x+2 } int main(){ for( int i=1 ; i-1001 ; i++ ) printf("%d %d\n",i,count(i)); return 0; }M Mr. X will first check the correctness of the output. If the output is correct, he then will check the code. If there is anything that violates the rule above, the result will be "compilation error". Changing the code other than the allowed part may also result in a compile error. DO NOT USE ANY WHITESPACE ON THE EDITED PART Input No input. Output 1 2 2 3 3 3 4 3 ... and so on ... 9998 3 9999 3 10000 3  Click here to see all problems in this series!
34,925
Strange Pattern (Hard) (THINKX) Mr. X has mastered programming. Fibonacci is too easy for him. To make his name heard all over the world, he challenges you to create a function that returns 2 if the input is 1, and returns 3 if the input is greater than 1. Since Mr. X wants to make himself famous, the function must be simple and some advertising must be put in the function. He only wants you to do a single statement in the function so it's easy to read. The statement must also not contain any numbers or letters other than 'x'. To make it more interesting, every operator or symbol other than x can only be used once in the statement. Mr. X has given you his code for you to edit, but you can only edit a certain part of the code. #include <stdio.h> int count(int x){ return edit this part ; } int main(){for(int i=1;i<100001;i++)printf("%d %d\n",i,count(i));return 0;} #include <stdio.h> int count(int x){ return (x+1)%x+2 } int main(){ for( int i=1 ; i-1001 ; i++ ) printf("%d %d\n",i,count(i)); return 0; }M Mr. X will first check the correctness of the output. If the output is correct, he then will check the code. If there is anything that violates the rule above, the result will be "compilation error". Changing the code other than the allowed part may also result in a compile error. DO NOT USE ANY WHITESPACE ON THE EDITED PART Input No input. Output 1 2 2 3 3 3 4 3 ... and so on ... 99998 3 99999 3 100000 3  Click here to see all problems in this series!
34,926
Strange Pattern (Impossible) (THINKLOL) Mr. X is now very popular. But he feels that being popular isn't as good as he thought. He wants to return to his old way. In order to do that, he moved to a less popular language than his usual language(don't worry, it's still a popular language). Mr. X doesn't have the power of STL anymore, but he takes that as a challenge. He wants to do his infamous 2-3-3-3 function in C now. Since Mr. X also wants to make other people forget him, the function must be so simple that it's forgettable. He only wants you to do a single statement in the function. The statement must also not contain the letter 'x'. Mr. X has given you his code for you to edit, but you can only edit a certain part of the code. #include <stdio.h> int count(int x){ return edit this part ; } int main(i){for(i=1;i%1000001;i++)printf("%d %d\n",i,count(i));return 0;} #include <stdio.h> int count(int x){ return (x+1)%x+2 } int main(){ for( int i=1 ; i-1001 ; i++ ) printf("%d %d\n",i,count(i)); return 0; }M Mr. X will first check the correctness of the output. If the output is correct, he then will check the code. If there is anything that violates the rule above, the result will be "compilation error". Changing the code other than the allowed part may also result in a compile error. DO NOT USE ANY WHITESPACE ON THE EDITED PART Input No input. Output 1 2 2 3 3 3 4 3 ... and so on ... 999998 3 999999 3 1000000 3  Click here to see all problems in this series!
34,927
Just Guess The Output ! (GUESSOUT) There is a 96-digit decimal number in the output file ... guess it ! Input no input. Output The 96-digit number ! Example no example . [note: the problem can be solved by less than 10 submittions.]
34,928
Just Guess The Output ! (Very Easy) (GUESS000) There is a 96-digit decimal number in the output file ... guess it ! Input no input. Output The 96-digit number ! Example no example . [white note: you can get AC using at most 10 submittions ]
34,929
N-th Term (TERMN) Find the n-th term of the sequence 1, 4, 16, 36, 100, ... Input First Line : T (No. of test cases < 1000) T Lines each containing a value of n (n < 100000) Output Exactly T lines each containing n-th term of the sequence. Example Input: 4 2 3 4 5 Output: 4 16 36 100
34,930
Coder Express 4!! (CODERE4) Coder Express Le!! Thangabali won the contest and Meenamma was not ready to marry him so she ran away with Rahul to a town where Thangabali was trained. The experts helped Rahul in solving the toughest question and help improve his coding skills. As a final challenges:They ask him solutions to some sequences. The first sequence was : 0 1 1 2 3 5 8 13..... Rahul easily fugured out and answered it is fibonacci F(n)=F(n-1)+F(n-2) n>=2,and F[n]=1 for n=0,1 The second sequence which they gave were: 1 1 3 7 17... After thinking for a while Rahul answered it as F(n)=2*F[n-1]+ F[n-2] n>=2,and F[n]=1 for n=0,1 They were very impressed and they asked him to build the solution for the third sequence and then he is well trained to defeat anybody? The third sequence was 1 1 3 8 20 50 123...and so on Rahul was unable to figure it out .Your task is to tell him the nth term of the third sequence so that he could easily solve the problem.   Input Specification: First line contains an integer T(1 < = T< = 1000) that represents the number of test cases.Then follows the T containg the integer N(1< = N< = 1000000000) specifying the term to be printed. Output Specification: For each test case, print only one line, the nth term Since the output would be very large you have to print your answer modulo 1000000007. Sample input: 3 1 2 3 Sample Output: 1 1 3
34,931
Sum The Amazing Series (SNGSAS) Consider the series (1 / 5) + (5 / 6) + (9 / 11) + (24 / 31) + (50 / 43) + ... Input First line of input is t (t < 5001) . Next t lines contains a positive integer n (n < 6001) . Output Output is sum of the series upto n terms, upto 2 decimal places. Example Input: 6 1 2 3 4 5 6 Output: 0.20 1.03 1.85 2.63 3.79 5.00
34,932
Time to get a job (ABCLOG) ABC Pvt. Ltd., needs to recruit some candidates and they want the test to be somewhat new, rather than the conventional way of asking questions in all areas. They have a logic, which converts one integer to another. Your task is to find the logic behind it and then solve the questions for certain inputs. The question given by them is as follows: The following are the output provided for the inputs given to one of our newly bought machines. You need to find the output that will be generated for the given inputs. Some sample input and output are:    4 -> 1, 23 -> 29, 7 -> 7  16 -> 1   Your task is to find the machine's output for some inputs Input Input contains several integers, each in a single line. Input ends with a -1 All inputs <= 10^16 Output Output one integer for every input, as said above. Example Input: 4 7 23 -1   Output: 1 7 29
34,933
Guess The Setters (GTSBDNY) Guess the setters | GTSBDNY Problem solving is fun. We always try to use our algorithmic knowledge to solve some problems. Sometimes we use our intuition to solve a problem. We don’t know the proof and we don’t know whether the solution idea will really work for all kinds of cases. And sometimes, when we see that limit is low, brute force is possible to solve the problem. Most of the time it is ok, and actually it is always OK! So try brute force for this problem. :P This problem is nothing but an old riddle about guessing the problem setters. Most of the people think that why the hell one should guess the names of the problem setters!! It’s fun actually, but not for some nerdy people I guess. By the way, in this problem you will again try to guess the problem setters. But we will give you some options to answer. You need to guess. The answer sequence is somehow related to the number 11111011110. Easy, huh? Let’s try.   ID Problem Code Problem Name Options 0 BADXOR BAD XOR Mir Wasi Ahmed Aninda Majumdar Nafis Sadique 1 MAXRAD Maximum Radius Momontho Mashak Monmoy Syed Shahriar Manjur Ahmad Faiyaz 2 BUYINT Buying Integers Momontho Mashak Monmoy Syed Shahriar Manjur Ahmad Faiyaz 3 TREEPAL Tree and Palindrome Nafis Ahmed Aninda Majumder Syed Shahriar Manjur 4 SPACEBRG Space Bridges Nafis Sadique Aninda Majumder Momontho Mashak Monmoy 5 XYI XYI Ahmad Faiyaz Mir Wasi Ahmed Nafis Ahmed 6 MNIU My Name is UMM! Nafis Sadique Mir Wasi Ahmed Nafis Ahmed   Input  There is no input for this problem Output  You should output the answer sequence with these digits only ‘0’, ‘1’,’2’. And you should give output a string with exactly 7 digits. Example: 1110211. The Most significant digit (the leftmost one) of the output string will correspond to the problem BADXOR and the least significant digit (the right most one) will correspond to the problem MNIU
34,934
Fight with Abhishek (GUTTSS) Abhishek popularly known as "Gutts" by his friends Anurag garg and Bhavik, is very good at solving logical problems. Recently he was solving some encryption problem and challenges Bhavik to solve the same.Bhavik being lazy asks for your help to encrypt the numbers using some test cases given by "Gutts"; your task is to find the encypted numbers for the input numbers: Input Input contains several numbers each in a different line  first line contains T : number of test cases (T <= 100) For next T lines each line contains a number n (0<=n<2^64) Output For every test case print encrypted number in separate line . Input: 6 2 3 6 7 17 25 Output: 0 1 1 3 8 9 NOTE: for each test case ans will be less than 2^64
34,935
Sasha is a noob (SNOOB) Sasha is a noob. Input I don't read inputs ever since Y2K. Output Output 42 only to pass this problem Example: Output: 19
34,936
Sasha is a noob v2 (BRIKCGM) Description On the borderline of insanity, Sasha, after trying to solve BRICKGM and failing a few hundred times, decided to take things into his own hands. United with his equally nooby friends and family he created his own task. This time he won't have people laugh at him for not knowing programming and being a noob. Putting things into perspective he stared into a giant abyss that is spoj for a moment, then decided to create problem with name BRIKCGM. Up until now, nobody notice poor little Sasha. Then it came your time. Step into the ever shining light of spoj. Annihilate everything Sasha stands for. Step onto the scene and crush his nooby friends. However you are able to. Anywhere he is, whatever he does, he will always be a noob. Input wat dis? Output banana
34,937
Learn to Read (L2R) Most problems on SPOJ are very reliant on the problem description. An unclear problem description can make the problem harder to solve than it should be. That's why the goal of this problem's description is to ensure that you have all the necessary information you need. However, it's not easy to include all information in the description without telling too much about the solution of the problem. Especially in riddles, where most problem descriptions are unclear. Some of them even have no problem description! This problem is probably the easiest problem in SPOJ because I will give you the answer to this problem in the description. Well it's technically not the actual answer, but rather how you handle the test data correctly. If you already know what you're supposed to do with the input , I can ensure that you will solve this problem easily. It will be very simple, so simple that you can probably solve this if you have coded "Hello World!" at some point in your life. But then again, you might have forgotten how to code. But it's none of my concern. Some people don't like long problem statement, and often times just read the input and output straight away. Maybe you just did that and come back here because you don't understand the input and output? That's why I told you that problem description is very important, don't skip it! Without it you will most likely lost on what you have to do. That is the power of a great problem description. You're probably already itching to know what you have to do to get accepted in this problem. So now I will tell you how you solve this problem. Ready? Okay, here we go. You must process the input which consists of a number that will fit in a signed sixteen bit integer. Why sixteen bit you ask? Because I think it's unnecessary to increase the constraint to thirty-two or sixty-four bit since it won't add much difficulty to the problem. Decreasing it to two or three bit is also possible, but I like sixteen bit. But how do you process it? I might or might not have told you, but it's on the problem description. If you still did not know what you are supposed to do with the input, perhaps you should start over reading from the top. Make sure you don't miss a single word that I typed here. You could also choose to continue reading, but I doubt it will benefit you anything. If you already read over but still can't understand what you have to do, maybe the next paragraph will help. I can't guarantee that, though. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Note that this last paragraph doesn't tell you anything, it's just here to make the problem statement longer and to punish those people that only read the last paragraph. You must respect the effort made by the problem setter to create a story fitting for the problem, it's not easy you know. Also, the paragraph before this is useless. You should totally ignore it. Input An integer Output An integer Example Input: 0 Output: 0
34,938
Progressions (PGR01) Charan is good at Mathematics and he loves the concept of progressions. He was assigned a task to calculate the n-th term in the given series. As he is good at mathematics he calculates the answer but as the series was too large he decided to write a program to solve that problem. Help Mr.Charan in solving the problem. Given series is  t1=1,t2=9,t3=45,t4=189,t5=729..... Here, tn=n-th term in the series.  Input First line represents the number of test cases. Next t lines represent the n value.  1<=tn<10^18  Output Output the corresponding value of the n-th term Example Input: 1 10 Output: 373977
34,939
CAT and XAT (CATXAT) In a certain language (consisting of 26 upper case alphabets only),  CAT  is written as ZGXEQX.  XAT  is written as UBXEQX. You are given various strings as input and according to the translation logic potrayed by above examples you need to give its corresponding string in that other language.  Input Specification: First line consists of t, the number of test cases. Next t lines consists of a string s consisting of uppercase alphabets (A-Z) only.  Output Specification: Output consists of t lines each containing the final transformed output string for given input string.  Constraint: t <= 100  1<=length(s) <= 100  Sample Input: 2  CAT  XAT  Sample Output:   ZGXEQX  UBXEQX
34,940
AMUSING SEQUENCE (DB002) Given a sequence of natural numbers . Find it's N'th term. a1=3, a2=9, a3=30, a4=101, a5=358, a6=1443... ...,aN Input Single line containing a natural number  N Output Print N'th term of the sequence modulo 10^9+7. Constraints 1  <=  N  <= 100 Example Input: 5 Output: 358
34,941
Strange Pattern (Impossible) (Hard) (THINKLUL) Mr. S says to Mr. X "Hey, I can do that too!". #include <stdio.h> int count(int s){ return  edit this part ; } int main(i){srand(time(0));for(i=1;i+037775702734;i++)printf("%d %d\n",i,count(i));return 0;} #include <stdio.h> int count(int x){ return (x+1)%x+2 } int main(){ for( int i=1 ; i-1001 ; i++ ) printf("%d %d\n",i,count(i)); return 0; }M The rule is don't use the letter 's' on the edited part. Everything else is the same as the linked problem above. Input No input. Output 1 2 2 3 3 3 4 3 ... and so on ... 555553 3 555554 3 555555 3  Click here to see all problems in this series!
34,942
No Description 1 (NODESC1) Example Input: 6 Output: ????????
34,943
Under the Spreading Chestnut Tree (KURINO) "Under the Spreading Chestnut Tree"(大きな栗の 木の下で) 大きな栗の 木の下で あなたと わたし 仲良く 遊びましょう 大きな栗の 木の下で Hint: Ooki na kuri no ki no shita de ana ta to wa ta shi na ka yo ku a so bi ma shou ooki na kuri no ki no shita de Input A string in Romaaji. Output The desired string in Romaaji. Example Input: na ka yo ku a so bi ma shou Output: ooki na kuri no ki no shita de Input: ku da mo no wa do ko de su ka Output: ooki na kuri no ki no ue de Hint: Watch this link !
34,944
Strange Pattern (bugged) (THINKING) Really makes you think #include <stdio.h> int count(int t){ return  edit this part ; } int main(i){for(i=1;i<<0b10000;i++)printf("%d %d\n",i,count(i));return 0;} #include <stdio.h> int count(int x){ return (x+1)%x+2 } int main(){ for( int i=1 ; i-1001 ; i++ ) printf("%d %d\n",i,count(i)); return 0; }M you must not use any emoji on the edited part, especially not thinking emoji. Space is probably not ok because judge uses scanf %s Input No input. Output 1 2 2 3 3 3 4 3 ... and so on ... 65534 3 65535 3 65536 3  Click here to see all problems in this series!
34,945
Broken Calculator (NASIO) Abdullah has a calculator of NASIO brand. (Why NASIO not CASIO is one of the top 10 questions science cannot answer.) For the last few days his calculator is giving some weird answers while doing any mathematical operations. Some examples are: 1 - 1 = 15 2 + 2 = 65 3 - 3 = 11 4 + 4 = 113 5 + 7 = 163 12 - 4 = 97 23 * 11 = 36196 5 / 2 = 19.115385 Given the operation find what Abdullah's calculator will show. NOTE: For a division operation Abdullah's calculator rounds up his result 6 digits after decimal point, and for others he just prints a integer what his system gives. Input First line contains an integer 0 < t < 10000, number of testcases. Next t lines contains the operations in any of these formats: a + b a - b a * b a / b where a and b are non-negative integers less than 10 6 . See sample test case for better clarifications. Output For each testcase on separate line print what Abdullah's calculator with show. Example Input: 4 1+2 2*3 3/4 4-5 Output: 54 875 17.634615 -4
34,946
Find my favourite (IDONTKNOW) I have 2 favourite numbers! Find them out! The numbers are in the range of 1-20 inclusive. Output 2 of my favourite numbers separated with an end line or a space. The example is only an example, not the actual test case. Example Output: 1 2
34,947
Obfuscated Property (FUSC) Consider the sequence: 0, 1, 1, 2, 1, 3, 2, 3, 1, 4, 3, 5, 2, 5, 3, 4, 1, 5, 4, 7, 3, 8, 5, 7, 2, 7, 5, 8, 3, 7, 4, 5, 1, 6, 5, 9, 4... This sequence is defined recursively by the formula: f(2n) = f(n) f(2n+1) = f(n) + f(n+1) with the initial values f(0) = 0 and f(1) = 1 In 1982, Dijkstra called this sequence fusc because it possesses a curious ob fusc ated property: if the sum of two indices, n and m, is a power of 2, then f(n) and f(m) are coprime . The sequence of the ratios of two consecutive elements u n = f(n) / f(n+1) runs through all non-negative rational numbers (in reduced form) just once! 0, 1, 1/2, 2, 1/3, 3/2, 2/3, 3, 1/4, 4/3, 3/5, 5/2, 2/5, 5/3, 3/4, 4 ... Moreover, if the terms are written as an array: 1 1, 2 1, 3, 2, 3 1, 4, 3, 5, 2, 5, 3, 4 1, 5, 4, 7, 3, 8, 5, 7, 2, 7, 5, 8, 3, 7, 4, 5 1, 6, 5, 9, 4, 11, 7, 10, 3, 11, 8, 13, 5, 12, 7, 9, 2, 9, 7, 12, 5, 13, 8, 11, 3, 10, 7, 11, 4, 9, 5, 6 then the sum of the k-th row is 3 k-1 , each column is an arithmetic progression, and the steps are nothing but the original sequence! In this problem, given n, you have to find max{f(i); 0 <= i <= n)} Input One single line contains n (0 <= n <= 10 15 ). Output One single line contains max{f(i); 0 <= i <= n)}. Example Input: 10 Output: 4
34,948
SPOJ Custom Test (BACTERIA) This problem is to simulate "custom test" function in other Online Judges. The time limit for this problem is 30 seconds. Input No specified input. The judge input file is actually an empty file. Output Any output will be accepted. Click on "accepted" verdict to see the output of your program. The output limit for this problem is 1024KB. If your output exceeds 1024KB, only the first 1024KB will be displayed. Any output will receive 0 points as judge result. Note This is actually not a problem. This is a tool which allows you to run your program at SPOJ machines to see its performance (including output, running time, memory used, etc.) Advertisement The list below contains the problems added to SPOJ classical section by Fudan University Problem Setters. Old Contest Problems Old Chinese National Olympiad in Informatics(CNOI) problems, from year 1997 - 2008, not all problem included: link . This section contains both medium and hard problems. Old Internet Problem Solving Contest(IPSC) problems, from 1999 - 2009, not all problems included: link . Most of the problems in this section are easy and medium level. Collected Old Chinese National Olympiad in Informatics in Province(NOIP) problems, or similar: link . Most of the problems in this section are easy . Real-Time Contest Problems [ Medium - Hard ] ACM/ICPC World Finals 2002 in Hawaii, one problem excluded: link [ Medium - Hard ] ACM/ICPC Central European Regional Contest 2005 in Budapest: link [ Medium - Hard ] ACM/ICPC Regional Contest, Hangzhou 2008: link [ Hard ] ACM/ICPC Regional Contest, Shanghai 2009: link [ Hard ] ACM/ICPC Regional Contest, Shanghai 2011 Preliminary Contest: link [ Hard ] ACM/ICPC Regional Contest, Shanghai 2011, one problem excluded: link [ Medium - Hard ] ACM/ICPC Regional Contest, Chengdu 2012, one problem excluded: link [ Easy - Medium ] Fudan University Local Contest #1: link [ Easy - Medium ] Fudan University Local Contest #2: link [ Medium ] Fudan University Local Contest #3: link [ Easy ] Fudan University Local Contest 2012: link [ Hard ] ACM/ICPC World Finals 2016 in Bangkok, one problem excluded: link Other Problems Online Judge only problems, which means "it requires a lot of time and/or deep thinking to solve, not very suitable to be put in a real-time contest": link Collected problems, which means "it's collected from various ICPC or similar programming contests, once be used as a real-time contest problem": link . However, most of the problems in this section are hard to solve in the contest.
34,949
Life, the Universe, and Everything (Interactive) (EXPECT) Note for Interactive problem setters: if you are stucked on how to write a interactive problem judge, you may send a mail to "blue.mary.me@qq.com". It will send you the custom judge of this problem. Your program is to use the brute-force approach in order to find the Answer to Life, the Universe, and Everything. More precisely... rewrite small numbers from input to output. Stop processing input after reading in the number 42. All numbers at input are integers of one or two digits. Interactive Protocol You should communicate with Judge using standard input and output. Attention: the program should clear the output buffer after printing each line. It can be done using fflush(stdout) command or by setting the proper type of buffering at the beginning of the execution - setlinebuf(stdout). Each time the judge will give you a number. You should rewrite this number to standard output. If this number equals 42, after rewriting your program should terminate immediately. Example The example of communication. Input: 3 15 42 Output: 3 15 42 Attention: the program should clear the output buffer after printing each line. Reference Please pay attention that: your program should NOT output any extra characters like "J","P" or “:". Follow the interactive protocol strictly. A sample program (in C++) that can get Accepted is as the following:
34,950
Test 1 (TESTINT) Given two natural numbers (both not greater than 200), each number in the separate line, please print the sum of them. Example Input: 2 3 Output: 5
34,951
Half of the half (STRHH) Given a sequence of 2* k characters, please print every second character from the first half of the sequence. Start printing with the first character. Input In the first line of input you are given the positive integer t (1<= t <=100) - the number of test cases. In the each of the next t lines, you are given a sequence of 2* k (1<= k <=100) characters. Output For each of the test cases please please print every second character from the first half of a given sequence (the first character should appear). Example Input: 4 your progress is noticeable Output: y po i ntc
34,952
Character Patterns (Act 1) (CPTTRN1) Using two characters: . (dot) and * (asterisk) print a chessboard-like pattern. The first character printed should be * (asterisk). Input You are given t < 100 - the number of test cases and for each of the test cases two positive integers: l - the number of lines and c - the number of columns in the pattern ( l , c < 100). Output For each of the test cases output the requested pattern (please have a look at the example). Use one line break in between successive patterns. Example Input: 3 3 1 4 4 2 5 Output: * . * *.*. .*.* *.*. .*.* *.*.* .*.*.
34,953
Character Patterns (Act 2) (CPTTRN2) Using two characters: . (dot) and * (asterisk) print a frame-like pattern. Input You are given t - the number of test cases and for each of the test cases two positive integers: l - the number of lines and c - the number of columns of a frame. Output For each of the test cases output the requested pattern (please have a look at the example). Use one line break in between successive patterns. Example Input: 3 3 1 4 4 2 5 Output: * * * **** *..* *..* **** ***** *****
34,954
Character Patterns (Act 3) (CPTTRN3) Using two characters: . (dot) and * (asterisk) print a grid-like pattern. Input You are given t - the number of test cases and for each of the test cases two positive integers: l - the number of lines and c - the number of columns in the grid. Each square of the grid is of the same size and filled with 4 dots (see the example below). Output For each of the test cases output the requested pattern (please have a look at the example). Use one line break in between successive patterns. Example Input: 3 3 1 4 4 2 5 Output: **** *..* *..* **** *..* *..* **** *..* *..* **** ************* *..*..*..*..* *..*..*..*..* ************* *..*..*..*..* *..*..*..*..* ************* *..*..*..*..* *..*..*..*..* ************* *..*..*..*..* *..*..*..*..* ************* **************** *..*..*..*..*..* *..*..*..*..*..* **************** *..*..*..*..*..* *..*..*..*..*..* ****************
34,955
Character Patterns (Act 4) (CPTTRN4) Using two characters: . (dot) and * (asterisk) print a grid-like pattern. Input You are given t - the number of test cases and for each of the test cases four positive integers: l - the number of lines, c - the number of columns in the grid; h and w - the high and the width of the single rectangle. Output For each of the test cases output the requested pattern (please have a look at the example). Use one line break in between successive patterns. Example Input: 3 3 1 2 1 4 4 1 2 2 5 2 2 Output: *** *.* *.* *** *.* *.* *** *.* *.* *** ************* *..*..*..*..* ************* *..*..*..*..* ************* *..*..*..*..* ************* *..*..*..*..* ************* **************** *..*..*..*..*..* *..*..*..*..*..* **************** *..*..*..*..*..* *..*..*..*..*..* ****************
34,956
Character Patterns (Act 5) (CPTTRN5) Using two characters: . (dot) and * (asterisk) print a grid-like pattern. The grid will have l lines, c columns, and each square shaped element of the grid will have the height and width equal to s . Moreover, each of the grid elements will have a diagonal. The diagonal of the first square in the first line of the grid is directed towards down and right corner - use the \ (backslash) character to print it; while the next diagonal will be directed towards upper right corner - use the / (slash) character to print it. Print the successive diagonals alternately (please consult the example below). Input You are given t - the number of test cases and for each of the test case three positive integers: l - the number of lines, c - the number of columns in the grid and s - the size of the single square shaped element. Output For each of the test cases output the requested pattern (please have a look at the example). Use one line break in between successive patterns. Example Input: 3 3 1 2 4 4 1 2 5 2 Output: **** *\.* *.\* **** *./* */.* **** *\.* *.\* **** ********* *\*/*\*/* ********* */*\*/*\* ********* *\*/*\*/* ********* */*\*/*\* ********* **************** *\.*./*\.*./*\.* *.\*/.*.\*/.*.\* **************** *./*\.*./*\.*./* */.*.\*/.*.\*/.* ****************
34,957
Character Patterns (Act 6) (CPTTRN6) Given specified dimensions, print a grid-like pattern. Use the | (pipe) sign to print vertical elements, the - (minus) to print horizontal ones and + (plus) for crossings. The rest of the space fill with . (dots) characters. Input You are given t - the number of test cases and for each of the test cases four positive integers: l - the number of horizontal elements, c - the number of vertical elements in the grid; h and w - the high and the width of the single rectangle respectively. Output For each of the test cases output the requested pattern (please have a look at the example). Use one line break in between successive patterns. Example Input: 3 3 1 2 1 4 4 1 2 2 5 3 2 Output: .|. .|. -+- .|. .|. -+- .|. .|. -+- .|. .|. ..|..|..|..|.. --+--+--+--+-- ..|..|..|..|.. --+--+--+--+-- ..|..|..|..|.. --+--+--+--+-- ..|..|..|..|.. --+--+--+--+-- ..|..|..|..|.. ..|..|..|..|..|.. ..|..|..|..|..|.. ..|..|..|..|..|.. --+--+--+--+--+-- ..|..|..|..|..|.. ..|..|..|..|..|.. ..|..|..|..|..|.. --+--+--+--+--+-- ..|..|..|..|..|.. ..|..|..|..|..|.. ..|..|..|..|..|..
34,958
Character Patterns (Act 7) (CPTTRN7) Print a regular grid pattern with diamond-like base elements. Use the \ (backslash) and the / (slash) characters to print diamonds and . (dots) to fill the rest of the space. Input You are given t - the number of test cases and for each of the test cases three positive integers: r - the number of rows, c - the number of columns in the grid and s - the size of each diamond. Output For each of the test cases output the requested pattern (please have a look at the example). Use one line break in between successive patterns. Example Input: 3 3 1 2 4 4 1 2 5 2 Output: ./\. /..\ \../ .\/. ./\. /..\ \../ .\/. ./\. /..\ \../ .\/. /\/\/\/\ \/\/\/\/ /\/\/\/\ \/\/\/\/ /\/\/\/\ \/\/\/\/ /\/\/\/\ \/\/\/\/ ./\../\../\../\../\. /..\/..\/..\/..\/..\ \../\../\../\../\../ .\/..\/..\/..\/..\/. ./\../\../\../\../\. /..\/..\/..\/..\/..\ \../\../\../\../\../ .\/..\/..\/..\/..\/.
34,959
Minimum Bounding Rectangle (HS12MBR) Compute the Minimum Bounding Rectangle (MBR) that surrounds the given set of 2D objects, i.e., the axis-aligned rectangle, which contains all of the specified objects and is the one with minimum area among all rectangles with this property. Input First, you are given t ( t <100) - the number of test cases. Each of the test cases starts with one integer n ( n < 100) - the number of objects in the set. In the successive n lines, the descriptions of the objects follow. Each object is described by one character and some parameters: a point: p x y , where x and y are point coordinates. a circle: c x y r , where x and y are the center coordinates and r is the radius of the circle. a line segment: l x 1 y 1 x 2 y 2 , where x i , y i are the coordinates of the endpoints of the line. Successive test cases are separated by an empty line. Output For each of the test cases output four numbers - the coordinates of the two points that correspond to the lower left and the upper right corner of the MBR, in the following order: first the x -coordinate of the lower left corner, then the y -coordinate of the lower left corner, the x -coordinate of the upper right corner and the y -coordinate of upper right corner. You can assume that all object parameters are integers and that -1000 -1000 1000 1000 is a bounding rectangle for all of them. Example Input: 3 1 p 3 3 2 c 10 10 20 c 20 20 10 1 l 0 0 100 20 Output: 3 3 3 3 -10 -10 30 30 0 0 100 20 Test case description test 1: points only (2 pts) test 2: circles only (2 pts) test 3: lines only (2 pts) test 4: mixed (2 pts) test 5: mixed (2 pts)
34,960
Hidden Password (HS12HDPW) You are given two alphanumeric ASCII strings. An ancient manuscript says those strings contain a hidden password. Decode it! The first string may be grouped into tuples of six characters each. For each such 6-tuple, taking from the i -th character (start counting from 0) the i -th bit of its ASCII code gives you a number (call it a ), and likewise taking the (( i +3) mod 6)-th bits gives you another number (call it b ). These two numbers tell you about the next two characters to be included in the password, namely the a -th and the b -th character from the second string (count starting from 0 as usual). Input First, you are given t ( t < 100) - the number of test cases. Each of the test cases starts with one number n ( n < 100) - the number of 6-tuples in the first string, followed by the two strings in separate lines (please have a look at the example to see the correct format). The second string is 64 characters long. Successive test cases are separated by an empty line. Output For each of the test cases, output its hidden password in a separate line. Example Input: 2 2 qwe345 rf3Arg XSBSRasdew9873465hkldsfsalndfvnfq489uqovkLKJHaeDaae555Sk5asdpASD 3 2S4J5K 111111 lrtb2A isimgsow45ipfgisd56wfgngdfcdkgc7kKKKkuuJJgfstdygQdWORQADFSLKF2K8 Output: keep coding Explanation Let us have a look at the first 6-tuple: qwe345 . char. ASCII code q 113 = 0111 0 00 1 B w 119 = 011 1 01 1 1B e 101 = 01 1 00 1 01B 3 51 = 0011 0 01 1 B 4 52 = 001 1 01 0 0B 5 53 = 00 1 10 1 01B a (blue bits) = 110111B = 55 b (red bits) = 101110B = 46
34,961
Evaluate simple RPN expression (RPNEVAL) Evaluate an expression in Reverse Polish Notation (otherwise known as Postfix notation). Assume there are 4 numerical operators: + - * /, and numbers can be floating point values. Each token in the expression, be it a number of operator, is separated from its neighbours by one or more spaces, to make the expression easy to parse. The program should read a series of input strings from stdin and output either the evaluated number to 4 decimal places (use the %.4f print format), or the single word "ERROR". If the expression is not parseable, does not evaluate correctly, or leaves extra data on the stack, the output should be "ERROR". An example INPUT/OUTPUT sequence is given below for reference. Input A series of RPN expressions, one per line on stdin. Output One line for each output element - either the numerical output, or the string "ERROR" Example Input: 1 2 3 / 2 3 / 3 4 * / 1 2 4 + - 5 * 7 / Output: ERROR 0.6667 ERROR -3.5714
34,962
Divisibility (SMPDIV) Print all integers a i such that a i is divisible by x and not divisible by y , where 1 < a i < n < 100000 . Input First, you are given t ( t < 100) - the number of test cases. In each of the following t lines, 3 integers: n x y . You might assume also that x < n and x is not divisible by y . Output In each of the following t lines, numbers requested in the problem description in the separated by a single space in ascending order. Example Input: 2 7 2 4 35 5 12 Output: 2 6 5 10 15 20 25 30
34,963
Two Circles (SMPCIRC) Given two circles: O1 with the center o1 = ( x 1 , y 1 ) and a radius r 1 and O2 with the center o2 = ( x 2 , y 2 ) and radius r 2 , please compute if O1 is inside O2 or if O2 is inside O1 . Input First t < 1000, the number of test cases. In each of the following t lines, 6 integers: x 1 y 1 r 1 x 2 y 2 r 2 . Where 0 ≤ x 1 , y 1 , x 2 , y 2 ≤ 10000 and 0 < r 1 , r 2 ≤ 10000. Output For each test case print one character: I, if O1 is inside O2 (or if O2 is inside O1 ), E, if O1 is internally tangent to O2 (or if O2 is internally tangent to O1 ), O, in other cases. Example Input: 2 103 104 5 100 100 10 103 104 10 100 100 10 Output: E O
34,964
Iterated sums (SMPSUM) Please compute the sum of squares for the given numbers: a , a +1, ..., b -1, b . Input Two numbers: a and b separated by space, where 1 <= a <= b <=100. Output Computed sum: a * a + ( a +1)*( a +1) + ... + ( b -1)*( b -1) + b * b Example Input: 1 4 Output: 30 Example 2 Input: 5 6 Output: 61
34,965
Wow (SMPWOW) Input Given a positive integer 0 < x < 50. Output Print one word: Wo...ow (letter o must be repeated x times). Example 1 Input: 1 Output: Wow Example 2 Input: 7 Output: Wooooooow
34,966
Character Patterns (Act 8) (CPTTRN8) Print a regular grid pattern with diamond-like base elements. Use the \ (backslash) and the / (slash) characters to print the borders and the * (asterisk) to print the inner part of the diamonds. Use . (dots) to fill the rest of the space. Input You are given t - the number of test cases and for each of the test cases three positive integers: r - the number of rows, c - the number of columns in the grid and s - the size of each diamond. Output For each of the test cases output the requested pattern (please have a look at the example). Use one line break in between successive patterns. Example Input: 3 3 1 2 4 4 1 2 5 2 Output: ./\. /**\ \**/ .\/. ./\. /**\ \**/ .\/. ./\. /**\ \**/ .\/. /\/\/\/\ \/\/\/\/ /\/\/\/\ \/\/\/\/ /\/\/\/\ \/\/\/\/ /\/\/\/\ \/\/\/\/ ./\../\../\../\../\. /**\/**\/**\/**\/**\ \**/\**/\**/\**/\**/ .\/..\/..\/..\/..\/. ./\../\../\../\../\. /**\/**\/**\/**\/**\ \**/\**/\**/\**/\**/ .\/..\/..\/..\/..\/.
34,967
Straight Line Spiral Pattern (Act 1) (SPTTRN1) Print a straight line spiral pattern as shown in the example below. Please use the * (asterisk) and . (dot) characters. Input You are given t - the number of test cases and for each of the test cases one integer: s , 3 < s < 100 - the size of the shape. Output For each of the test cases output the requested pattern. Use one line break in between successive patterns. Example Input: 5 4 5 11 13 78 Output: **** ...* *..* **** ***** ....* ***.* *...* ***** *********** ..........* *********.* *.......*.* *.*****.*.* *.*...*.*.* *.*.***.*.* *.*.....*.* *.*******.* *.........* *********** ************* ............* ***********.* *.........*.* *.*******.*.* *.*.....*.*.* *.*.***.*.*.* *.*.*...*.*.* *.*.*****.*.* *.*.......*.* *.*********.* *...........* ************* ****************************************************************************** .............................................................................* ****************************************************************************.* *..........................................................................*.* *.************************************************************************.*.* *.*......................................................................*.*.* *.*.********************************************************************.*.*.* *.*.*..................................................................*.*.*.* *.*.*.****************************************************************.*.*.*.* *.*.*.*..............................................................*.*.*.*.* *.*.*.*.************************************************************.*.*.*.*.* *.*.*.*.*..........................................................*.*.*.*.*.* *.*.*.*.*.********************************************************.*.*.*.*.*.* *.*.*.*.*.*......................................................*.*.*.*.*.*.* *.*.*.*.*.*.****************************************************.*.*.*.*.*.*.* *.*.*.*.*.*.*..................................................*.*.*.*.*.*.*.* *.*.*.*.*.*.*.************************************************.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*..............................................*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.********************************************.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*..........................................*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.****************************************.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*......................................*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.************************************.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*..................................*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.********************************.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*..............................*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.****************************.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*..........................*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.************************.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*......................*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.********************.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*..................*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.****************.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*..............*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.************.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*..........*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.********.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*......*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.****.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*..*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*....*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.******.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*........*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.**********.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*............*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.**************.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*................*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.******************.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*....................*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.**********************.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*........................*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.**************************.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*............................*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.******************************.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*................................*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.**********************************.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*....................................*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.**************************************.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*........................................*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.******************************************.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*............................................*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.**********************************************.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*................................................*.*.*.*.*.*.*.* *.*.*.*.*.*.*.**************************************************.*.*.*.*.*.*.* *.*.*.*.*.*.*....................................................*.*.*.*.*.*.* *.*.*.*.*.*.******************************************************.*.*.*.*.*.* *.*.*.*.*.*........................................................*.*.*.*.*.* *.*.*.*.*.**********************************************************.*.*.*.*.* *.*.*.*.*............................................................*.*.*.*.* *.*.*.*.**************************************************************.*.*.*.* *.*.*.*................................................................*.*.*.* *.*.*.******************************************************************.*.*.* *.*.*....................................................................*.*.* *.*.**********************************************************************.*.* *.*........................................................................*.* *.**************************************************************************.* *............................................................................* ******************************************************************************
34,968
Straight Line Spiral Pattern (Act 2) (SPTTRN2) Print a straight line spiral pattern as shown in the example below. Please use the * (asterisk) and . (dot) characters. Input You are given t - the number of test cases and for each of the test cases one integer: s , 3 < s < 100 - the size of the shape. Output For each of the test cases output the requested pattern. Use one line break in between successive patterns. Example Input: 5 4 5 11 13 78 Output: *.** *..* *..* **** *.*** *.*.* *.*.* *...* ***** *.********* *.*.......* *.*.*****.* *.*.*...*.* *.*.*.*.*.* *.*.*.*.*.* *.*.***.*.* *.*.....*.* *.*******.* *.........* *********** *.*********** *.*.........* *.*.*******.* *.*.*.....*.* *.*.*.***.*.* *.*.*.*.*.*.* *.*.*.*.*.*.* *.*.*...*.*.* *.*.*****.*.* *.*.......*.* *.*********.* *...........* ************* *.**************************************************************************** *.*..........................................................................* *.*.************************************************************************.* *.*.*......................................................................*.* *.*.*.********************************************************************.*.* *.*.*.*..................................................................*.*.* *.*.*.*.****************************************************************.*.*.* *.*.*.*.*..............................................................*.*.*.* *.*.*.*.*.************************************************************.*.*.*.* *.*.*.*.*.*..........................................................*.*.*.*.* *.*.*.*.*.*.********************************************************.*.*.*.*.* *.*.*.*.*.*.*......................................................*.*.*.*.*.* *.*.*.*.*.*.*.****************************************************.*.*.*.*.*.* *.*.*.*.*.*.*.*..................................................*.*.*.*.*.*.* *.*.*.*.*.*.*.*.************************************************.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*..............................................*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.********************************************.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*..........................................*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.****************************************.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*......................................*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.************************************.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*..................................*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.********************************.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*..............................*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.****************************.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*..........................*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.************************.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*......................*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.********************.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*..................*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.****************.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*..............*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.************.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*..........*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.********.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*......*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.****.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*..*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*..*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.**.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*....*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.******.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*........*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.**********.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*............*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.**************.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*................*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.******************.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*....................*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.**********************.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*........................*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.**************************.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*............................*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.******************************.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*................................*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.**********************************.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*....................................*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.**************************************.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*........................................*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.******************************************.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*............................................*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.**********************************************.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*................................................*.*.*.*.*.*.*.* *.*.*.*.*.*.*.**************************************************.*.*.*.*.*.*.* *.*.*.*.*.*.*....................................................*.*.*.*.*.*.* *.*.*.*.*.*.******************************************************.*.*.*.*.*.* *.*.*.*.*.*........................................................*.*.*.*.*.* *.*.*.*.*.**********************************************************.*.*.*.*.* *.*.*.*.*............................................................*.*.*.*.* *.*.*.*.**************************************************************.*.*.*.* *.*.*.*................................................................*.*.*.* *.*.*.******************************************************************.*.*.* *.*.*....................................................................*.*.* *.*.**********************************************************************.*.* *.*........................................................................*.* *.**************************************************************************.* *............................................................................* ******************************************************************************
34,969
Straight Line Spiral Pattern (Act 3) (SPTTRN3) Print a straight line spiral pattern as shown in the example below. Please use the * (asterisk) and . (dot) characters. Input You are given t - the number of test cases and for each of the test cases one integer: s , 3<s<100 - the size of the shape. Output For each of the test cases output the requested pattern. Use one line break in between successive patterns. Example Input: 5 4 5 11 13 78 Output: **** ...* *..* **** ***** ....* ***.* *...* ***** *********** ..........* ***.*****.* *.*.*...*.* *.*.***.*.* *.*...*.*.* *.*.***.*.* *.*.....*.* *.*******.* *.........* *********** ************* ............* ***.*******.* *.*.*.....*.* *.*.*****.*.* *.*.....*.*.* *.*.***.*.*.* *.*.*...*.*.* *.*.*****.*.* *.*.......*.* *.*********.* *...........* ************* ****************************************************************************** .............................................................................* ***.************************************************************************.* *.*.*......................................................................*.* *.*.**********************************************************************.*.* *.*......................................................................*.*.* *.*.***.****************************************************************.*.*.* *.*.*.*.*..............................................................*.*.*.* *.*.*.*.**************************************************************.*.*.*.* *.*.*.*..............................................................*.*.*.*.* *.*.*.*.***.********************************************************.*.*.*.*.* *.*.*.*.*.*.*......................................................*.*.*.*.*.* *.*.*.*.*.*.******************************************************.*.*.*.*.*.* *.*.*.*.*.*......................................................*.*.*.*.*.*.* *.*.*.*.*.*.***.************************************************.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*..............................................*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.**********************************************.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*..............................................*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.***.****************************************.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*......................................*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.**************************************.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*......................................*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.***.********************************.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*..............................*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.******************************.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*..............................*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.***.************************.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*......................*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.**********************.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*......................*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.***.****************.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*..............*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.**************.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*..............*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.***.********.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*......*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.******.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*......*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.***..*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.**.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*....*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.******.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*........*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.**********.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*............*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.**************.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*................*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.******************.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*....................*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.**********************.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*........................*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.**************************.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*............................*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.******************************.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*................................*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.**********************************.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*....................................*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.**************************************.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*........................................*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.******************************************.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*............................................*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.**********************************************.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*................................................*.*.*.*.*.*.*.* *.*.*.*.*.*.*.**************************************************.*.*.*.*.*.*.* *.*.*.*.*.*.*....................................................*.*.*.*.*.*.* *.*.*.*.*.*.******************************************************.*.*.*.*.*.* *.*.*.*.*.*........................................................*.*.*.*.*.* *.*.*.*.*.**********************************************************.*.*.*.*.* *.*.*.*.*............................................................*.*.*.*.* *.*.*.*.**************************************************************.*.*.*.* *.*.*.*................................................................*.*.*.* *.*.*.******************************************************************.*.*.* *.*.*....................................................................*.*.* *.*.**********************************************************************.*.* *.*........................................................................*.* *.**************************************************************************.* *............................................................................* ******************************************************************************
34,970
Fun with Sequences (SMPSEQ3) You are given a sorted sequence of n integers S = s 1 , s 2 ... s n and a sorted sequence of m integers Q = q 1 , q 2 ... q m . Please print in ascending order all such s i that does not belong to Q . Input data specification In the first line you are given one integer 2 <= n <= 100 , and in the following line n integers: -100 <= s i <= 100, s i <= s i +1 . In the third line you are given one integer 2 <= m <= 100 , and in the following line m integers: -100 <= q i <= 100, q i <= q i +1 . Output data specification The sequence of requested integers separated by spaces. Example Input: 5 -2 -1 0 1 4 6 -3 -2 -1 1 2 3 Output: 0 4
34,971
Fun with Sequences (Act 2) (SMPSEQ4) You are given a sorted sequence of n integers S = s 1 , s 2 ... s n and a sorted sequence of m integers Q = q 1 , q 2 ... q m . Please print in ascending order all such s i that belongs to Q . Input data specification In the first line you are given one integer 2 <= n <= 100 , and in the following line n integers: -100 <= s i <= 100, s i <= s i +1 . In the third line you are given one integer 2 <= m <= 100 , and in the following line m integers: -100 <= q i <= 100, q i <= q i +1 . Output data specification The sequence of requested integers separated by spaces. Example Input: 5 -2 -1 0 1 4 6 -3 -2 -1 1 2 3 Output: -2 -1 1
34,972
Fun with Sequences (Act 3) (SMPSEQ5) You are given a sequence of n integers S = s 1 , s 2 ... s n and a sequence of m integers Q = q 1 , q 2 ... q m . Please print in ascending order all such i , that s i = q i , i <=n , i <=m . Input data specification In the first line you are given one integer 2 <= n <= 100 , and in the following line n integers: -100 <= s i <= 100, s i <= s i +1 . In the third line you are given one integer 2 <= m <= 100 , and in the following line m integers: -100 <= q i <= 100, q i <= q i +1 . Output data specification The sequence of requested indexes separated by spaces. Example 1 Input: 5 -2 -2 -1 1 4 6 -3 -2 -1 1 2 3 Output: 2 3 4 Example 2 Input: 5 -2 -1 -3 1 4 5 -3 -2 -1 1 2 Output: 4
34,973
Fun with Sequences (Act 4) (SMPSEQ6) You are given S - a sequence of n integers S = s 1 , s 2 ... s n , Q - a sequence of n integers Q = q 1 , q 2 ... q n and a nonnegative parameter x . Please print in ascending order all such i , that s i = q i+y , where -x <= y <= x . Input data specification In the first line you are given two integers 2 <= n <= 100 , 0 <= x < n and in the following two lines n integers in each of the line: -100 <= s i , q i <= 100 Output data specification The sequence of requested integers separated by spaces. Example 1 Input: 5 2 -1 2 -1 1 -1 3 -2 -1 1 2 Output: 1 3 4 5 Example 2 Input: 6 4 -1 2 2 2 2 -2 3 -2 3 3 3 -1 Output: 6 Example 3 Input: 6 0 -1 2 10 12 6 -2 2 -2 10 21 6 -1 Output: 3 5
34,974
Fun with Sequences (Act 5) (SMPSEQ7) You are given S - a sequence of n integers S = s 1 , s 2 ... s n . Please, compute if it is possible to split S into two parts: s 1 , s 2 ... s i and s i+1 , s i+2 ... s n (1 <= i < n ) in such a way that the first part is strictly decreasing while the second is strictly increasing one. Input data specification In the first line you are given an integer 2 <= n <= 100 and in the following line n integers -100 <= s i <= 100. Output data specification One word Yes or No . Example 1 Input: 5 -1 2 -1 1 -1 Output: No Example 2 Input: 6 3 1 -2 -2 -1 3 Output: Yes Example 3 Input: 6 2 2 1 0 1 2 Output: No
34,975
XOR (BSCXOR) Given two logic values p and q (0 or 1) please compute p XOR q . Example Input: 1 1 Output: 0
34,976
Cross Pattern (Act 1) (PCROSS1) Print a cross pattern using the * (asterisk) and . (dot) characters. Input The first line contains an integer t , the number of test cases. The next t lines contain four integers separated by spaces: m , n , c i , c j . Output For each test case print a cross on an m -by- n grid centered at row c i and column c j , as shown in the example. Constraints 1 ≤ t ≤ 100 1 ≤ m , n ≤ 100 1 ≤ c i ≤ m 1 ≤ c j ≤ n Example Input: 3 1 1 1 1 5 5 3 3 8 13 3 5 Output: * ..*.. ..*.. ***** ..*.. ..*.. ....*........ ....*........ ************* ....*........ ....*........ ....*........ ....*........ ....*........
34,977
Cross Pattern (Act 2) (PCROSS2) Print a cross pattern using the * (asterisk) and . (dot) characters. Input The first line contains an integer t , the number of test cases. The next t lines contain four integers separated by spaces: m , n , c i , c j . Output For each test case print a cross on an m -by- n grid centered at row c i and column c j , as shown in the example. Constraints 1 ≤ t ≤ 100 1 ≤ m , n ≤ 100 1 ≤ c i ≤ m 1 ≤ c j ≤ n Example Input: 3 1 1 1 1 5 5 3 3 8 13 3 5 Output: * *...* .*.*. ..*.. .*.*. *...* ..*...*...... ...*.*....... ....*........ ...*.*....... ..*...*...... .*.....*..... *.......*.... .........*...
34,978
Fun with Sequences (Act 6) (SMPSEQ8) You are given a sequence of n integers S = s 1 , s 2 ... s n and a sequence of m integers Q = q 1 , q 2 ... q m . If q 1 + q 2 + ... + q m < s 1 + s 2 + ... + s n please print the sequence S and otherwise please print the sequence Q . Input data specification In the first line you are given one integer 2 <= n <= 100 , and in the following line n integers: -100 <= s i <= 100. In the third line you are given one integer 2 <= m <= 100 , and in the following line m integers: -100 <= q i <= 100. Output data specification The sequence of requested integers separated by spaces. Example 1 Input: 5 -2 -1 0 1 4 6 -3 -2 -1 1 2 3 Output: -2 -1 0 1 4 Example 2 Input: 5 -2 -1 0 1 2 6 -3 -2 -1 1 2 3 Output: -3 -2 -1 1 2 3
34,979
Fun with Sequences (Act 7) (SMPSEQ9) You are given a sequence of n integers S = s 1 , s 2 ... s n and a sequence of m integers Q = q 1 , q 2 ... q m . If ( q 1 + q 2 + ... + q m )/m < ( s 1 + s 2 + ... + s n )/n please print the sequence S and otherwise please print the sequence Q . Input data specification In the first line you are given one integer 2 <= n <= 100 , and in the following line n integers: -100 <= s i <= 100. In the third line you are given one integer 2 <= m <= 100 , and in the following line m integers: -100 <= q i <= 100. Output data specification The sequence of requested integers separated by spaces in the same order as in the input. Example 1 Input: 5 -2 -1 0 1 4 6 -3 -2 -1 1 2 3 Output: -2 -1 0 1 4 Example 2 Input: 5 -2 -1 1 2 3 6 -2 -1 0 1 2 3 Output: -2 -1 1 2 3
34,980
Substitution cipher (SMPCPH1) You are given a sequence of n characters S = s 1 , s 2 , ..., s n in such a way that for i ≠ j we have also s i ≠ s j . Your task is to substitute every s i with s i +1 for i in {1, 2, ... n -1} and s n with s 1 in the given plain text. Input In the first line you are given one integer 2<= n <=26 , and in the following line n characters. In the third line you are given one integer 2<= m <=100 , and in the following m lines you are given a plaintext to be encoded. Plaintext contains only white spaces and small letters from the Latin alphabet. The whole plain text is at most 1000 characters long. Output Encoded text, as specified above. Example 1 Input: 6 spojit 3 after this training we will solve even difficult and tricky problems easily Output: afser shtp sratntng we wtll pjlve even dtfftculs and srtcky orjblemp eaptly Example 2 Input: 10 dontgiveup 3 after this training we will solve even difficult and tricky problems easily Output: afgur ghvs gravtvti wu wvll snleu ueut ovffvcplg ato grvcky drnblums uasvly
34,981
Sum of two numbers (CHITEST1) Compute the sum of two numbers. Input The first line of the input will include the number N of test cases, and the each of the following N lines will include two numbers separated by whitespace. Output Starting with the second line of the input, the sum of the two numbers in the line must be printed into a line in the output. The accuracy of the output should be better than 10^-6. Example Input: 3  2 3 3.3 4 -1 4 Output: 5 7.3 3
34,982
Duronto Eagle (DRNTEAGL) During his study in Amazing International University-Bangladesh Kazi Hossain accidentally made a space ship while doing a course assignment. He named the space ship Duronto Eagle. Now he wants to travel to other habitable planets in the galaxy with Duronto Eagle. As Kazi is a very brave guy he wants to start his space journey by travelling to the farthest planet in the galaxy first. The co-ordinate of the planet Kazi is currently in (planet Earth) is always (0, 0). You are given the co-ordinates of the other N habitable planets in the galaxy in a 2D Cartesian plane. You have to find the index of the farthest planet considering the Euclidean distance from planet Earth (0, 0). Indices range from 1 to N. Input Input starts with an integer T (≤ 100), denoting the number of test cases. Each of the test cases starts with an integer N (1 ≤ N ≤ 50), denoting the number of planets. Each of the next N lines contains two integers x i y i (-10000 ≤ x i , y i ≤ 10000) describing the coordinates of the planets in the galaxy. Output For each case print the case number and the index of the farthest planet from Earth that Kazi will be travelling first. If there’s multiple possible answers output the one that comes first in the input. See sample input output for clarification. Example Input: 2 3 4 0 0 5 2 2 4 2 3 1 1 5 5 -4 -1 Output: Case 1: 2 Case 2: 3
34,983
Binary numbers (CHI_BINARY) The goal of this problem is to illustrate that all arithmetic operations on natural numbers in binary format can be implemented by using a few logical operations on the individual bits. The allowed operations are XOR, NOT, AND, OR, and SHIFT, where the latter is the operation of shifting the bits of a number to the right or to the left (with digits disappearing or new zeroes appearing at one or the other end as needed). Note that in principle, NOT, AND, and OR are superfluous because they can be expressed in terms of XOR only. No automatic check will be performed on if the submitted code satisfies the aforementioned restrictions. This means that the problem solver needs to impose the restrictions on their code, keeping in mind the goal that we are trying to mimic how the CPU hardware handles integers. Input The first number is the number of test cases, in binary. Then the next numbers are in groups of 3, all in binary. In each group, the first number encodes the operation to be performed on the next 2 numbers. The encoding convention is as follows: 0 greater than 1 addition 10 subtraction 11 multiplication 100 division All numbers in the input are understood to be non-negative integers. If needed, you can assume that the number of bits in each integer does not exceed 200. Output For each test case, the output must include one or two binary numbers. In case of division only, the output consists of two numbers: Supposing that the pair of numbers in the input are A and B, the output should be A/B (integer division) and A%B (remainder). If B happens to be 0, the output should be 0 0 (two zeroes). For the operation "greater than", output 1 if the first number is greater than the second number, and output 0 otherwise. If the first argument A of a subtraction is smaller than the second argument B, then A should be replaced by A + 2 N , where N is the smallest integer such that 2 N > max{A,B}. For example, in the operation 100 - 101 (decimal 4 - 5), the first argument should be increased by 1000 (decimal 8), making it 1100 (decimal 12), and the output corresponding to the operation 100 - 101 should be 111 (decimal 12 - 5 = 7). Example Input: 111 0 10 10 1 10 11 0 11 10  11 101 11 10 11 10 100 1011 11 10 10 11 Output: 0 101 1  1111 1 11 10 11
34,984
Strange But Easy (SERI07) Hari is very bright student and always solves mathematical problems and series. Lalit (who jealous of him) gives him a series to find the logic and find as many terms as Lalit wants. Hari not getting the logic and wants you to help him. Your task is so simple, you have to find the terms of the series. Few terms of the series are 11 90 346 936 ... It isn't too irritating to do that...? Yeah it is, so look at the hint and do it. Hint: This is actually not the hint... it's the answer... The series is formed by Prime Number Combinations. For example: 1st term (2 * 3) + 5 = 11, 2nd term (7 * 11) + 13 = 90 so on. It's too easy now for you. Just Basic to check your programming skill :P Input First line of input is 't' - number of test cases. In each of the next t lines there is only one Integer n (n < 10000). Output Output is the n term of the series. Warning: be careful with large output data. Example Input: 3 1 2 3 Output: 11 11 90 11 90 346
34,985
Natural numbers (CHI_NATURAL) Implement arithmetic operations for nonnegative integers whose values are allowed to be beyond the range supported by the computer's built-in integer arithmetics. Given two nonnegative integers A and B, the code should be able to decide whether A < B, A = B, or A > B, and to compute A + B,  A - B, with the convention that A - B = 0 for A < B,  A * B,  A / B (integer division) A % B (remainder).  Moeover, we introduce the new operation called truncated multiplication A # B [M], as follows. This operation will depend on the particular base in which the numbers are represented, and within the tests, it is assumed that the base is 100. In other words, we assume that any number A is represented within the code as A = A_0 + A_1 * BASE + A_2 * BASE^2 + ... , where 0 <= A_k < BASE are the digits, and we set BASE = 100 for the purposes of the tests. One can write the product A * B as A * B = A_0*B_0 + (A_0*B_1+A_1*B_0) * BASE + (A_0*B_2+A_1*B_1+A_2*B_0) * BASE^2 + ...  If we remove the first M - 1 terms from this expansion, and divide the result by BASE^M, we get the truncated product A # B [M]. Note that truncated multiplication depends on a parameter M, which may be assumed to be a moderate sized integer (in particular well within the 32 bit range). For example, we have 910 * 820 = (10+9*100)*(20+8*100) = 10*20 + (10*8+9*20)*100 + (9*8)*100^2 = 200 + 260*100 + 72*100^2 = 746200 and hence 910 # 820 [M=1] = 260 + 72*100 = 7460 and 910 # 820 [M=2] = 72 If M is not too large, the digits of A # B [M] approximate the most significant digits of the product A * B well, so this operation can be used in multiplying mantissas of floating point numbers (Multiplying the mantissas exactly would result in too many digits, and a lot of them woud be meaningless anyway). Input All numbers in input and output should be nonnegative integers in decimal notation. The first line of the input is the number N of test cases. Then each of the following N lines has either the format c A B or c A B M where c is one of the characters '<', '+', '-', '*', '#', '/', describing the arithmetic operation to be performed on the numbers A and B (and possibly M). The second format (and hence the number M) is used only when c = '#'. We emphasize again that in the tests we have, it is assumed that BASE = 100. Output The output should consist of N lines, with each line containing the result of the arithmetic operation in the corresponding line of the input. For division, the output is 2 integers A / B and A % B, separated by a space. If B = 0, then return 0 0 (two zeroes). For all other operations, the ouput is one integer. For '<', the output should be 1 if A < B, 0 if A = B, and -1 if A > B. In case of subtraction A - B with A < B, the ouput should be 0. Example Input: 15 < 1000 1999 < 9898 9898 < 1234 123 < 0 0 + 1791593436984766559642626609333245051871 307634751338542477034677711517175 - 1000000000000000000000000000000000000000000000 1 - 9851454318615645743724544440468029862 40153566442954896526103872421591156 * 333333333 0 * 1 3333333335555 * 9999999999999999999999999999999999999999 999999999999999999999999999999999999999 / 1 999999999999999999999999999999999999999999999 / 999999999999999999999999999999999999999999999 2 / 861564574372454444046802986230763475133854247703 6442954896526103872421591156 # 1010 2020 1 # 619665458372652911688999608 5642672187122910629212227277 6 Output: 1 0 -1 0 1791593744619517898185103644010956569046 999999999999999999999999999999999999999999999 9811300752172690847198440568046438706 0 3333333335555 9999999999999999999999999999999999999989000000000000000000000000000000000000001 0 1 499999999999999999999999999999999999999999999 1 133721962703322764598 5829723863328422309867552415 20400 3496569047280138337581751280571264068913704
34,986
n-th root (CHI_ROOT) Compute 101 significant figures of the n-th root of a number. Input The first line of the input contains the number of test cases. In each of the following lines, the numbers n and x are given, where n is a positive (32 bit) integer, and x is a floating point number with arbitrary precision. Output Each line of the output should be the sequence consisting of the first 101 digits of the positive n-th root of x. All trailing and leading zeroes, as well as the decimal point (if any) should be removed. Score For each test case, let K be the first position of the digit where the first difference to the reference solution occured. Then the score awarded to the test case will be K divided by the number of digits M in the reference solution. The numbers K and M are not larger than 101. For example, let us say we are computing the square root of 1.44, and the ouput is 11. Then since the reference solution is 12, this solution would receive the score of 0.5 (50%). The final score of the problem is the sum of the scores over all test cases, normalized so that the maximum possible score is 10. Example Input: 4 3 2 4 16 2 5 2 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679 Output: 12599210498948731647672106072782283505702514647015079800819751121552996765139594837293965624362550941 2 22360679774997896964091736687312762354406183596115257242708972454105209256378048994144144083787822749 17724538509055160272981674833411451827975494561223871282138077898529112845910321813749506567385446653
34,987
The real exponential (CHI_EXP) Compute 101 significant figures of the exponential of a real number. Input The first line of the input contains the number of test cases. In each of the following lines, a single real number –100 ≤ x ≤ 100 is given, in the usual decimal notation. The number of decimal digits of x is not more than 101. Output Each line of the output should be the sequence consisting of the first 101 significant decimal digits of the exponential of x. All trailing and leading zeroes, as well as the decimal point (if any) should be removed. Score For each test case, let K be the first position of the digit where the first difference to the reference solution occurred. Then the score awarded to the test case will be K–1 divided by the number of digits M ≤ 101 in the reference solution. If all digits match, K = M+1 is understood. For example, let us say a particular output has the first 50 digits of exp(1) correct, and the 51-st digit is different from that of the reference solution. Then this particular test case would receive the score of 50/101 ≈ 0.5 (50%). The final score of the problem is the sum of the scores over all test cases, normalized so that the maximum possible score is 10. Example Input: 3 0 1 -3.14159265358979323846264338327950288 Output: 1 27182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664274 43213918263772249774417737171728011457104245174434972327166908869626900798351779694542372009588635587
34,988
The real sine (CHI_SIN) Compute 101 significant figures of the sine of a real number. Input The first line of the input contains the number of test cases. In each of the following lines, a single real number 0 ≤ x < π is given, in the usual decimal notation. The number of decimal digits of x is not more than 101. Output Each line of the output should be the sequence consisting of the first 101 significant decimal digits of the sine of x. All trailing and leading zeroes, as well as the decimal point (if any) should be removed. Score For each test case, let K be the first position of the digit where the first difference to the reference solution occured. Then the score awarded to the test case will be K–1 divided by the number of digits M ≤ 101 in the reference solution. If all digits match, K = M+1 is understood. For example, let us say a particular output has the first 50 digits of sin(1) correct, and the 51-st digit is different from that of the reference solution. Then this particular test case would receive the score of 50/101 ≈ 0.5 (50%). The final score of the problem is the sum of the scores over all test cases, normalized so that the maximum possible score is 10. Example Input: 2 0 1.5707963267948966 Output: 0 99999999999999999999999999999999981507813299633318447401631655066443910339246693874482714867916134939
34,989
The real logarithm (CHI_LOG) Compute 101 significant figures of the logarithm of a positive real number. Input The first line of the input contains the number of test cases. In each of the following lines, a single real number 1 ≤ x ≤ 100 is given, in the usual decimal notation. The number of decimal digits of x is not more than 101. Output Each line of the output should be the sequence consisting of the first 101 significant decimal digits of the logarithm of x. All trailing and leading zeroes, as well as the decimal point (if any) should be removed. Example Input: 2 1 3.1415926535897932384626433832 Output: 0 1144729885849400174143427351327752157627210731401746036785205942589070827177558730931032351538638113
34,990
The real arctangent (CHI_ATAN) Compute 101 significant figures of the arctangent of a real number. Input The first line of the input contains the number of test cases. In each of the following lines, a single real number 0 ≤ x ≤ 10 is given, in the usual decimal notation. The number of decimal digits of x is not more than 101. Output Each line of the output should be the sequence consisting of the first 101 significant decimal digits of the arctangent of x. All trailing and leading zeroes, as well as the decimal point (if any) should be removed. Example Input: 3 0 1 2.718281828459045235360287 Output: 0 78539816339744830961566084581987572104929234984377645524373614807695410157155224965700870633552926699 12182829050172776217604617127291832691014807688333489455796019635447595534415986839011077205055833227
34,991
GORDON AND GALLERY (GDGALKN) Joker has planned a bank robbery again. But this time Gordon has got to know about it! Since batman is tired and is on a vacation, So he himself wants to catch the joker (which is impossible!) For that, he has planned to put camera's with automatic guns inside the bank. The bank is peculiar in shape. It is that of an irregular closed polygon with N sides. The cameras can be fitted ONLY at the corners (INTERSECTION of the walls and are rotatable along vertical axis). That means the camera guns can rotate horizontally from one wall of the corner to another covering the area between the walls. It can detect any movement within that area until infinite distance and will shoot whenever it detects a movement. Assuming that the robbery is going to take place at night when there is no bankers or clients but only robbers, find the minimum number of guns Gordon needs to place to kill the joker and his robbers. Input The first line consists of a single integer T denoting the number of test cases. T lines follow each containing an integer N denoting the number of sides. Output For each test case print the required answer. Constraints 1 <= T <= 1000 3 <= n <= 100000 Example Input: 1 8 Output: 2
34,992
GST Calculator (PCC15D) Maslee is a student at a public university. Since the implementation of Good and Services Tax (GST), the prices for food at cafeterias in the university have become more expensive and Maslee has decided to cook his own meal. GST rates are classified into two types, which are: Standard-Rated (SR) Standard-rated supplies are taxable supplies of goods and services which are subject to a proposed rate of 6%. Zero-Rated (ZR) Zero-rated supplies are taxable supplies of goods and services which are subject to GST at 0% rate. Below is an example of a receipt after GST: Item Quantity Price GST Rates Meksis Prepaid 1 30.00 SR Jati Rice 1 32.00 ZR Rybena Juice 2 18.00 SR Peanut Butter 5 4.50 SR Total Amount Including GST 125.81 Total Amount GST Paid 5.31 And this is how to calculate the new prices for goods and services after GST: Meksis Prepaid 1 x RM30.00 = RM30.00 + 6% = RM31.80 Jati Rice 1 x RM32.00 = RM32.00 + 0% = RM32.00 Rybena Juice 2 x RM18.00 = RM36.00 + 6% = RM38.16 Peanut Butter 5 x RM4.50 = RM22.50 + 6% = RM23.85 ---------------------------------------------------- + Total Including GST = RM125.81 Your task is to make a simple calculator to help Maslee to calculate the total amount that Maslee needs to pay for items and services after GST and the amount of GST paid for the items and services. Input Input consists of integer T denoting number of test cases. Each test case consists of integer N denoting number of items followed by N-lines of item details (name, quantity, price, and GST-rate). Item name will consists of single string, and price are rounded to 2 decimal places. Output For each test case, output consists of case number followed by 2 lines of total paid amount including GST and total amount of GST paid. Example Input: 2 4 MeksisPrepaid 1 30.00 SR JatiRice 1 32.00 ZR RybenaJuice 2 18.00 SR PeanutButter 5 4.50 SR 3 GardenihaBread 3 2.40 ZR WaterSpinach 5 1.10 ZR iPong6 1 2779.00 SR Output: Case #1: Total Amount Include GST: 125.81 Total Amount GST Paid: 5.31 Case #2: Total Amount Include GST: 2958.44 Total Amount GST Paid: 166.74
34,993
Emoticons (EMO) Who doesn't use emoticons while chatting and of course who doesn't make mistakes! For example, we often type :o or :[ instead of :p -_ or -__ instead of -_- :* instead of :( (Beware sometimes these can be fatal :P) Now it's up to computer scientists to do something to avoid such problems. Good news is that Voogle have managed to detect what should be the correct emo for any sentence! All that left is to replace the faulty emoticons with the correct ones. As a computer programmer, you are given the job. Can you do it? Input Input data consists of several lines containing emoticons at places. Each line ends with a full stop. End of input is indicated by “#” without quote, which should not be processed. Emoticons start with some special characters (see below) and is at least 2 characters long. They come in pairs, first one is the expected one and the second one is typed. It is guaranteed that there is a space before and after every emoticon. 2 ≤ length of each emo ≤ 5 Each line contains at least one emoticon. Any emo start with one of these characters: {:, -, >} Number of total characters doesn’t exceed 10 6 Output Corrected text after replacing all the emoticons pairs with the correct ones. There should be exactly one space before and another one after each emo. A single space is used to separate two adjacent words in a sentence. See sample for details. Input might have unnecessary spaces, discard them. Example Input: Always remember: “For every problem there is a fast, easy and wrong solution” :P :[ . Sometimes a line :O :T may contain only emoticons like the next one.  -_- -__ . And can be of different lengths too -_- -_ . Even if both emoticons in a pair are correct, only one remains, Consider this case: :/ :) . # Output: Always remember: "For every problem there is a fast, easy and wrong solution" :P . Sometimes a line :O may contain only emoticons like the next one.  -_- . And can be of different lengths too -_- . Even if both emoticons in a pair are correct, only one remains, Consider this case: :/ . Note: In the third line of both the input and output, there is a space before the emo. Special Thanks to Sakibul Mowla.
34,994
Brocken Data Base (BRKDB) A university course database has broken, one of the column has been completely deleted and that column had the names of the 3 students that belong to that group. It is known that in that course where only 3 students with the same surname and different last names and different id codes. You have the following data: “Monsalve” had the code 200410061010, “Silva” had 200120039010 and “Pineda” 199810024010. Your goal is to get back the data base integrity and print the surnames, last names and codes of the students one per line.  Input As input read the name that had been deleted and now has been recovered by the IT personal of the university. Output It is expected that your problem prints as outputs one line per person replaced with the given data: Name + space + Lastname1 + space + code1 Name + space + Lastname2 + space + code2 Name + space + Lastname3 + space + code3 Example: Input: Antonio Output: Antonio Silva 200120039010 Antonio Pineda 199810024010 Antonio Monsalve 200410061010
34,995
Simple Average (AVRG) There is a customer that always comes to a store and buys 6 different products, but the problem is that he always takes too much time chosing and trying the products because he needs that the average of the products gives an exact number. Input As input you will be given 6 lines, each with the cost of one of the products. Output Your problem should output the average cost of the products. Example Input: 3 7 5 2 1 6 Output: 4
34,996
Team Building (BIPCSMR16) To make competitive programmers of BUBT, authority decide to take regular programming contest. To make this contest more competitive and fruitful there are some rules given to balance a team: Only 1st, 2nd and 3rd year students can participate. A team must have three members. All the members cannot be from the same year. You need to find out the maximum number of teams can build up according to given rules. Input The first line of input contains an integer T (1 <= T <= 10000) the number of test cases. Next T line contains three positive integer X, Y and Z (1 <= X, Y, Z <= 2*10^9) separated by a space which denotes the number of participants from 1st, 2nd, and 3rd year student. Output You need to find out the maximum number of teams can build up according to given rules. Example Input: 2 1 2 3 1 12 3 Output: 2 4
34,997
Depressed Coder (DPRSDCDR) Tinni is passionate about coding. But due to classes, CTs, and lab report, everyday she cannot code for at least three hours as suggested by Sadivai. So, sometimes she becomes depressed. But when she is able to code up to the mark she is jolly. Everyday Tinni eats, sleeps and does other household chores for 10 hours. She spends rest of her day attending classes, writing lab reports and preparing for CTs. And if there's time she smiles and does programming. Tinni's BF knows this fact but as he is illiterate he cannot calculate. So he seeks your help to make a program which can calculate whether Tinni will be jolly or depressed based on the input data. Input The input contains a number (1 ≤ N ≤ 1000) at the first line representing the number of test case. The next N lines contain 5 integers each, representing number of CT (0 ≤ nCT ≤ 3), number of Lab Reports (0 ≤ nLab ≤ 3), time required for each CT preparation (1 ≤ tCT ≤ 5) hours, time required for each Lab Report writing (1 ≤ tLab ≤ 5) hours and time for attending classes (3 ≤ tCls ≤ 8) hours. Output For each test cases print "Khushi" (means jolly in Bengali) or "Hotash" (means depressed in Bengali) in a new line. Example Input: 2 2 2 3 1 6 1 2 1 2 3 Output: Hotash Khushi
34,998
A problem of Backtracking (BTCK) You have to solve the following problem with backtracking. You're given a sequence of 10 positive integers n 1 , n 2 , n 3 ... n 9 , n 10 and a positive value K . To solve this problem you need to print a permutation a 1 , a 2 , a 3 ... a 10 of the numbers {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} such that a 1 * n 1 + a 2 * n 2 + a 3 * n 3 + ... + a 10 * n 10  ≤ K . Input In the first line, a single integer T, the number of test cases. For each test case there will be two lines: In the first line, 10 positive integers (1 ≤ n_i ≤ 10^9) separated by spaces. In the second line, a single positive integer K (1 ≤ K ≤ 10^9). Output For each test case, print a line with the answer for that test case as following: Among all the permutations that solve the problem according to the description above, print the lexicographically smallest. You've to print the permutation in a single line, separating each integer by a simple space. If no such permutation exists, print a single line with "-1". Example Input: 2 1 2 3 4 5 6 7 8 9 10 200 1 2 3 4 5 6 7 8 9 10 100 Output: 2 6 8 9 7 5 4 3 1 0 -1
34,999