tests
dict
problem
stringlengths
29
13k
{ "inputs": [ "2\n101\n010\n1111\n1010", "2\n101\n011\n1111\n1010", "2\n001\n111\n1111\n1010", "2\n111\n110\n1111\n1010", "2\n110\n110\n1111\n1010", "2\n110\n110\n1011\n1010", "2\n010\n110\n0011\n1010", "2\n000\n110\n0011\n1010", "2\n001\n110\n0011\n1010", "2\n111\n010\n0011\n1...
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A β‰  B) is available in the market. She purchases the string A and tries to convert it to string B by...
{ "inputs": [ "4\n1 1 1 1\n", "3\n5 1 -5\n", "2\n900 1000\n", "5\n10 5 0 -5 -10\n", "51\n-9 10 30 50 70 90 110 130 150 170 190 210 230 250 270 290 310 330 350 370 390 410 430 450 470 490 510 530 550 570 590 610 630 650 670 690 710 730 750 770 790 810 830 850 870 890 910 930 950 970 990\n", "4\...
Vasya came up with his own weather forecasting method. He knows the information about the average air temperature for each of the last n days. Assume that the average air temperature for each day is integral. Vasya believes that if the average temperatures over the last n days form an arithmetic progression, where the...
{ "inputs": [ "1000 800 1200", "1000 900 850", "1000 800 1040", "1000 900 239", "1000 1135 850", "1000 800 838", "1000 279 239", "1000 316 838", "1100 279 239", "1001 316 838", "1100 279 393", "1001 316 1343", "0100 279 393", "1000 316 1343", "0100 369 393",...
Problem One day, Kawabayashi is about to have lunch at the school cafeteria. There are three types of daily lunch menus for school cafeterias: A lunch, B lunch, and C lunch. Kawabayashi is a glutton, so I would like to eat all three types of daily lunch menus one by one. However, Kawabayashi decided to put up with one...
{ "inputs": [ "3 3\n9 5 1\n7 7 2\n2 1\n3 1\n3 2\n2\n", "6 9\n1 3 1 1 3 1 2 2 2\n4 1 4 2 2 5 3 1 6\n1 2\n1 3\n2 3\n2 4\n2 5\n3 5\n3 6\n4 5\n5 6\n7\n", "7 6\n8 10 4 8 4 4\n45 51 13 13 37 26\n2 7\n7 1\n6 3\n3 1\n5 4\n1 4\n4\n", "2 1\n1\n1\n1 2\n1000000000\n", "9 8\n2 8 2 10 2 2 5 8\n31 29 17 16 31 22...
In one kingdom there are n cities and m two-way roads. Each road connects a pair of cities, and for each road we know the level of drivers dissatisfaction β€” the value wi. For each road we know the value ci β€” how many lamziks we should spend to reduce the level of dissatisfaction with this road by one. Thus, to reduce ...
{ "inputs": [ "10 4 100 5 5 1\n", "30 5 20 20 3 5\n", "16 73 92 72 1 1\n", "50 10 30 20 1 2\n", "375 6 133 267 19 36\n", "5 3 135 12 21 6\n", "49 2 50 20 2 1\n", "0 11 67 82 6 4\n", "46 7 18 6 3 1\n", "10 2 27 4 11 1\n", "35 8 20 20 1 2\n", "3 18 272 17 6 1\n", "30 ...
A boy Valera registered on site Codeforces as Valera, and wrote his first Codeforces Round #300. He boasted to a friend Arkady about winning as much as x points for his first contest. But Arkady did not believe his friend's words and decided to check whether Valera could have shown such a result. He knows that the con...
{ "inputs": [ "5\nabaaaaaaaa\noneplustwo\naaaaaaaaba\ntwoplusone\naaaabaaaaa", "2\noneplustwo\nninemodsix", "3\nacornistnt\npeanutbomb\nconstraint", "5\nabaaaaaaaa\noweplustno\naaaaaaaaba\ntwoplusone\naaaabaaaaa", "2\noneplustwo\nnioemodsix", "3\nacornistnt\npeaoutbnmb\nconstraint", "5\nab...
We will call a string obtained by arranging the characters contained in a string a in some order, an anagram of a. For example, `greenbin` is an anagram of `beginner`. As seen here, when the same character occurs multiple times, that character must be used that number of times. Given are N strings s_1, s_2, \ldots, s...
{ "inputs": [ "5\noolol\n", "16\ngagadbcgghhchbdf\n", "2\naz\n", "10\nmsunonames\n", "4\nmems\n", "7\nlolikek\n", "15\nabacabadabacaba\n", "9\nabcabcabc\n", "21\narozaupalanalapuazora\n", "1\nz\n", "6\nmsucmc\n", "2\naa\n", "10\nmsunenamos\n", "4\nmemt\n", "...
A non-empty string is called palindrome, if it reads the same from the left to the right and from the right to the left. For example, "abcba", "a", and "abba" are palindromes, while "abab" and "xy" are not. A string is called a substring of another string, if it can be obtained from that string by dropping some (possi...
{ "inputs": [ "10 3\n1 8 5 7 100 4 52 33 13 5\n3 10\n4 30\n1 4", "3 2\n5 1 4\n2 3\n1 5", "3 2\n100 100 100\n3 99\n3 99", "11 3\n1 1 1 1 1 1 1 1 1 1 1\n3 1000000000\n4 1000000000\n3 1000000000", "10 3\n1 8 5 7 100 4 7 33 13 5\n3 10\n4 30\n1 4", "3 2\n5 1 1\n2 3\n1 5", "3 2\n100 100 100\n0 9...
You have N cards. On the i-th card, an integer A_i is written. For each j = 1, 2, ..., M in this order, you will perform the following operation once: Operation: Choose at most B_j cards (possibly zero). Replace the integer written on each chosen card with C_j. Find the maximum possible sum of the integers written o...
{ "inputs": [ "4 3\nmeiji 10 1877\ntaisho 6 1917\nshowa 62 1987\nheisei 22 2010\n1868\n1917\n1988\n1 1\nuniversalcentury 123 2168\n2010\n0 0", "4 3\nmeiji 10 1877\ntaisho 6 1917\nshowa 62 1987\nheisei 22 2010\n2046\n1917\n1988\n1 1\nuniversalcentury 123 2168\n2010\n0 0", "4 3\nmeiji 10 1877\ntaisho 6 1917...
As many of you know, we have two major calendar systems used in Japan today. One of them is Gregorian calendar which is widely used across the world. It is also known as β€œWestern calendar” in Japan. The other calendar system is era-based calendar, or so-called β€œJapanese calendar.” This system comes from ancient Chines...
{ "inputs": [ "3\n7\n1 2 3 4 5 6 7\n2 3 4 5 6 7 1\n3 4 5 6 7 1 2\n4 5 6 7 1 2 3\n5 6 7 1 2 3 4\n6 7 1 2 3 4 5\n7 1 2 3 4 5 6\n1 2 3 4 5 7 6\n1 3 4 5 6 7 2\n1 4 5 6 7 3 2\n1 5 6 7 4 2 3\n1 6 7 5 2 3 4\n1 7 6 2 3 4 5\n1 7 2 3 4 5 6\n5\n4 5 1 2 3\n3 5 2 4 1\n1 2 3 4 5\n5 2 4 1 3\n3 4 5 1 2\n2 3 4 5 1\n1 3 5 2 4\n4 1...
Cirno has prepared n arrays of length n each. Each array is a permutation of n integers from 1 to n. These arrays are special: for all 1 ≀ i ≀ n, if we take the i-th element of each array and form another array of length n with these elements, the resultant array is also a permutation of n integers from 1 to n. In the ...
{ "inputs": [ "3 3 1\n3 2", "100000 100000 0", "10 10 14\n4 3\n2 2\n7 3\n9 10\n7 7\n8 1\n10 10\n5 4\n3 4\n2 8\n6 4\n4 4\n5 8\n9 2", "3 6 1\n3 2", "100001 100000 0", "10 10 14\n4 3\n2 2\n7 3\n9 10\n7 9\n8 1\n10 10\n5 4\n3 4\n2 8\n6 4\n4 4\n5 8\n9 2", "100101 100000 0", "10 10 14\n4 3\n2...
Takahashi and Aoki will play a game using a grid with H rows and W columns of square cells. There are N obstacles on this grid; the i-th obstacle is at (X_i,Y_i). Here, we represent the cell at the i-th row and j-th column (1 \leq i \leq H, 1 \leq j \leq W) by (i,j). There is no obstacle at (1,1), and there is a piece ...
{ "inputs": [ "2\n4 1 3 2 5 6\n4 6 5\n1 2 3\n4\n", "3\n5 4 1 2 6 3 7 8 9\n5 6 2\n9 3 4\n1 7 8\n4\n", "3\n5 4 1 2 6 3 7 8 9\n5 6 2\n9 3 4\n1 7 8\n8\n", "1\n2 3 1\n2 3 1\n2\n", "3\n1 2 3 4 5 6 7 8 9\n1 2 3\n4 5 9\n6 7 8\n5\n", "2\n6 4 5 1 3 2\n6 1 3\n4 5 2\n6\n", "5\n5 3 2 7 12 9 4 14 1 10 8...
Recently personal training sessions have finished in the Berland State University Olympiad Programmer Training Centre. By the results of these training sessions teams are composed for the oncoming team contest season. Each team consists of three people. All the students of the Centre possess numbers from 1 to 3n, and a...
{ "inputs": [ "4 6 1\n0 1 1\n0 2 4\n2 0 1\n1 2 2\n3 1 1\n3 2 5", "4 5 0\n0 1 1\n0 2 4\n1 2 2\n2 3 1\n1 3 5", "4 5 0\n0 1 1\n0 2 4\n1 2 2\n2 3 1\n1 3 2", "4 5 0\n0 1 1\n0 2 4\n1 2 0\n2 3 1\n1 3 5", "4 5 0\n0 1 1\n1 2 4\n1 1 0\n2 3 1\n1 3 2", "4 6 1\n0 1 1\n0 2 4\n2 0 1\n1 2 2\n3 0 1\n3 2 5", ...
For a given weighted graph G(V, E) and a source r, find the source shortest path to each vertex from the source (SSSP: Single Source Shortest Path). Constraints * 1 ≀ |V| ≀ 100000 * 0 ≀ di ≀ 10000 * 0 ≀ |E| ≀ 500000 * There are no parallel edges * There are no self-loops Input An edge-weighted graph G (V, E) and th...
{ "inputs": [ "7\n5 6 0 1 -2 3 4\n", "5\n0 1 2 3 4\n", "9\n2 1 0 3 0 0 3 2 4\n", "5\n0 0 0 0 -1000000000\n", "8\n0 -1000000000 1000000000 1000000000 1000000000 -1000000000 1000000000 1000000000\n", "5\n1000000000 0 -1000000000 0 -1000000000\n", "5\n-1000000000 -1000000000 0 1000000000 1000...
You are given the array of integer numbers a0, a1, ..., an - 1. For each element find the distance to the nearest zero (to the element which equals to zero). There is at least one zero element in the given array. Input The first line contains integer n (1 ≀ n ≀ 2Β·105) β€” length of the array a. The second line contains...
{ "inputs": [ "2\n1 1e\n1 f\n", "2\n1 abc\nd0e fe23\n", "1\n1014 1014\n", "7\n1bbc 220c\n25a5 25d0\n1d11 1d4a\n15e2 17c8\n1b0b 23c4\n179b 2120\n1686 1c55\n", "4\n58 5c\n2b 62\n4b 5b\n38 5c\n", "7\nb3 3df\n114 25a\nfd 307\n182 3b0\n17a 324\n3ba 3c4\n3ad 3af\n", "48\n1f6 2ff\n385 3e4\n2fc 3a...
Sherlock found a piece of encrypted data which he thinks will be useful to catch Moriarty. The encrypted data consists of two integer l and r. He noticed that these integers were in hexadecimal form. He takes each of the integers from l to r, and performs the following operations: 1. He lists the distinct digits pr...
{ "inputs": [ "4 9\n1 2\n1 3\n1 4\n0\n1 1 4\n2 4 2\n1 3 4\n3 1\n3 2\n2 3 2\n1 1 2\n3 1\n3 2\n", "2 2\n1 2\n0\n1 2 1\n3 1\n", "3 8\n1 2\n1 3\n0\n1 1 2\n1 1 3\n3 1\n3 2\n2 3 2\n3 1\n1 1 3\n1 1 2\n", "5 12\n1 2\n1 3\n1 4\n1 5\n0\n2 3 2\n1 1 2\n1 3 1\n1 1 5\n1 4 5\n3 3\n2 4 2\n3 2\n1 2 3\n1 5 4\n2 5 2\n3 ...
After a lot of trying, Mashmokh designed a problem and it's your job to solve it. You have a tree T with n vertices. Each vertex has a unique index from 1 to n. The root of T has index 1. For each vertex of this tree v, you are given a list of its children in a specific order. You must perform three types of query on ...
{ "inputs": [ "2 1 1\n1\n50\n2 1 2\n1\n50\n1\n60\n2 1 2\n2\n60 61\n1\n70\n4 2 3\n3\n60 61 62\n1\n70\n2\n80 81\n3 1 2\n3\n60 61 62\n2\n70 60\n1 2 5\n2\n87 95\n3\n96 71 35\n2\n68 2\n3\n3 18 93\n2\n57 2\n2 2 1\n5\n1 2 1 3 1\n0 0 0", "2 1 1\n1\n50\n2 2 2\n1\n50\n1\n60\n2 1 2\n2\n60 61\n1\n70\n4 2 3\n3\n60 61 62\n...
The deadline of Prof. Hachioji’s assignment is tomorrow. To complete the task, students have to copy pages of many reference books in the library. All the reference books are in a storeroom and only the librarian is allowed to enter it. To obtain a copy of a reference book’s page, a student should ask the librarian to...
{ "inputs": [ "4 4\n1 2 3 4\n9 1 10 6\n", "5 5\n1 2 1 2 1\n3 10 1 1 1\n", "10 3\n1 1 1 1 1 1 1 1 1 1\n10 10 5\n", "1 1\n56563128\n897699770\n", "100 55\n1 2 4 4 3 5 5 2 3 4 2 1 1 2 3 5 1 5 4 2 5 4 4 3 3 5 3 4 4 5 5 2 3 3 4 4 3 4 5 5 5 5 3 5 1 2 4 3 4 5 3 3 2 1 4 5 3 4 4 1 5 1 5 2 2 1 4 5 3 3 1 4 2...
Ivar the Boneless is a great leader. He is trying to capture Kattegat from Lagertha. The war has begun and wave after wave Ivar's warriors are falling in battle. Ivar has n warriors, he places them on a straight line in front of the main gate, in a way that the i-th warrior stands right after (i-1)-th warrior. The fir...
{ "inputs": [ "4 2 20\n", "3 2 6\n", "963276084 698548036 1000000000\n", "18036 47899 1000000000\n", "200 10 979220166595737684\n", "740 251 930540301905511549\n", "1000 1000 1000000000000000000\n", "9999999999 33333 1000000000\n", "121 395 621154158314692955\n", "20958318104 4...
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The s...
{ "inputs": [ "725", "1600", "1359", "543", "1855", "609", "982", "1485", "1125", "1764", "554", "417", "979", "424", "470", "826", "1596", "885", "1543", "969", "412", "654", "646", "915", "512", "456", "1815"...
M-kun is a competitor in AtCoder, whose highest rating is X. In this site, a competitor is given a kyu (class) according to his/her highest rating. For ratings from 400 through 1999, the following kyus are given: * From 400 through 599: 8-kyu * From 600 through 799: 7-kyu * From 800 through 999: 6-kyu * From 1000 thro...
{ "inputs": [ "3 3\n1 2\n2 3\n1 3\n4 3\n1 2\n1 3\n1 4\n4 6\n1 2\n1 3\n1 4\n2 3\n3 4\n2 4\n0 0", "3 3\n1 2\n2 3\n1 3\n4 3\n1 2\n1 3\n1 4\n4 6\n1 2\n1 3\n1 2\n2 3\n3 4\n2 4\n0 0", "3 3\n2 2\n2 3\n2 3\n4 3\n1 2\n1 3\n1 4\n4 6\n1 4\n1 3\n1 4\n2 3\n3 4\n2 4\n0 0", "3 3\n2 2\n2 3\n2 3\n4 3\n1 2\n1 3\n1 4\n6...
Gift Exchange Party A gift exchange party will be held at a school in TKB City. For every pair of students who are close friends, one gift must be given from one to the other at this party, but not the other way around. It is decided in advance the gift directions, that is, which student of each pair receives a gift....
{ "inputs": [ "class YabbaDabbaDoo\n def foo\n if foo == 42\n puts 'world hello'\n elsif foo == 24\n puts 'bk201'\n else\n puts 'congrats!'\n end\n end\nend\n\nSAMPLE", "class ZabbaDabbaDoo\n def foo\n if foo == 42\n puts 'wor...
Write your program in Ruby which takes an un-indented Ruby code as string and outputs the indented Ruby code as string. Input Format A string which is un-indented Ruby code Output Format A string which is indented Ruby code SAMPLE INPUT class YabbaDabbaDoo def foo if foo == 42 puts 'world hel...
{ "inputs": [ "3 2 2\n1 2\n", "3 3 2\n1 2\n", "250 300 2\n157 204\n", "99 4754 98\n42 72 26 62 58 59 33 83 63 74 15 44 66 16 90 49 31 71 1 77 18 99 78 48 53 80 36 87 68 9 20 51 5 81 60 7 3 37 17 28 27 73 40 98 88 14 24 55 32 70 96 92 67 50 46 25 84 94 29 12 52 89 11 2 13 91 61 45 23 65 43 35 97 34 6 5...
Valera conducts experiments with algorithms that search for shortest paths. He has recently studied the Floyd's algorithm, so it's time to work with it. Valera's already written the code that counts the shortest distance between any pair of vertexes in a non-directed connected graph from n vertexes and m edges, contai...
{ "inputs": [ "5\n0 0\n100 100\n200 200\n100 0\n0 100", "3\n0 0\n2 2\n3 3" ], "outputs": [ "0", "2" ] }
Chef loves squares! You are given N points with integers coordinates, Chef asks you to find out how many points he should add to these set of N points, so that one could create at least one square having its vertices from the points of the resulting set. Note that the square created need not to be parallel to the axis....
{ "inputs": [ "1\n5 1", "1\n5 0", "1\n5 2", "1\n20 1", "1\n10 2", "1\n29 1", "1\n10 3", "1\n29 2", "1\n10 5", "1\n4 1", "1\n14 2", "1\n10 1", "1\n4 2", "1\n1 2", "1\n1 3", "1\n1 6", "1\n1 12", "1\n1 9", "1\n1 8", "1\n2 8", "1\n4 8", ...
Example Input 1 5 1 Output 11111
{ "inputs": [ "5\n1 2 c\n2 3 a\n3 4 t\n2 5 t\n", "16\n1 2 o\n2 3 f\n1 4 p\n4 5 i\n5 6 e\n6 7 c\n7 8 e\n4 9 r\n9 10 e\n10 11 t\n11 12 t\n12 13 y\n10 14 f\n14 15 i\n15 16 x\n", "3\n2 3 w\n1 2 o\n", "5\n1 2 s\n1 5 p\n5 4 w\n2 3 a\n", "2\n1 2 o\n", "3\n1 3 g\n1 2 o\n", "5\n1 2 m\n1 4 v\n4 5 x\...
Peterson loves to learn new languages, but his favorite hobby is making new ones. Language is a set of words, and word is a sequence of lowercase Latin letters. Peterson makes new language every morning. It is difficult task to store the whole language, so Peterson have invented new data structure for storing his lang...
{ "inputs": [ "XO\n", "Z\n", "AHA\n", "WYYW\n", "Q\n", "R\n", "A\n", "Y\n", "OVWIHIWVYXMVAAAATOXWOIUUHYXHIHHVUIOOXWHOXTUUMUUVHVWWYUTIAUAITAOMHXWMTTOIVMIVOTHOVOIOHYHAOXWAUVWAVIVM\n", "C\n", "QDPINBMCRFWXPDBFGOZVVOCEMJRUCTOADEWEGTVBVBFWWRPGYEEYGPRWWFBVBVTGEWEDAOTCURJMECOVVZOG...
Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it? The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out...
{ "inputs": [ "10\n10 2 8 1 2 4 1 20 4 5\n", "4\n1 2 53 1\n", "6\n1 58 29 1 2 2\n", "6\n29 29 1 1 58 2\n", "9\n7 49 1 1 98 14 49 7 2\n", "3\n1 2 1\n", "3\n5 1 1\n", "6\n1 2 4 8 1 16\n", "18\n10 1 4 5 20 10 40 16 20 8 2 5 8 40 2 80 1 4\n", "5\n7 49 2 1 1\n", "6\n6 1 3 3 2 1\...
Recently you have received two positive integer numbers x and y. You forgot them, but you remembered a shuffled list containing all divisors of x (including 1 and x) and all divisors of y (including 1 and y). If d is a divisor of both numbers x and y at the same time, there are two occurrences of d in the list. For ex...
{ "inputs": [ "2\n3\n1 10 15\n1 10 3\n3\n10 20 30\n15 5 20", "2\n3\n1 10 15\n1 10 3\n3\n19 20 30\n15 5 20", "2\n3\n1 10 29\n1 10 3\n2\n17 39 30\n15 5 20", "2\n3\n1 10 29\n1 8 3\n3\n17 20 30\n15 5 20", "2\n3\n1 10 29\n1 8 3\n3\n17 32 30\n15 5 20", "2\n3\n1 4 15\n1 2 3\n3\n10 7 30\n13 13 35", ...
There are N students living in the dormitory of Berland State University. Each of them sometimes wants to use the kitchen, so the head of the dormitory came up with a timetable for kitchen's usage in order to avoid the conflicts: The first student starts to use the kitchen at the time 0 and should finish the cooking n...
{ "inputs": [ "2\n10 15\n4 6", "2\n10 15\n4 1", "2\n10 28\n4 1", "2\n15 28\n4 1", "2\n8 28\n4 1", "2\n8 12\n8 1", "2\n8 12\n3 1", "2\n8 12\n2 1", "2\n9 12\n2 1", "2\n9 12\n2 2", "2\n9 4\n2 2", "2\n9 4\n2 3", "2\n5 4\n2 3", "2\n8 4\n2 3", "2\n4 1\n2 3", "...
Santosh has a farm at Byteland. He has a very big family to look after. His life takes a sudden turn and he runs into a financial crisis. After giving all the money he has in his hand, he decides to sell some parts of his plots. The specialty of his plot is that it is rectangular in nature. Santosh comes to know that ...
{ "inputs": [ "3\n1 2\n2 3\n1 3\n3 2\n", "4\n1 2\n2 3\n3 4\n2 4\n4 1\n1 3\n", "2\n1 2\n1 2\n", "6\n2 1\n3 2\n4 3\n5 3\n6 4\n2 1\n3 1\n4 1\n5 4\n6 4\n", "2\n2 1\n2 1\n", "5\n2 1\n3 2\n4 3\n5 4\n2 1\n3 1\n4 1\n5 1\n", "5\n1 2\n2 3\n3 4\n4 5\n2 5\n5 3\n3 1\n1 4\n", "10\n1 2\n1 3\n1 4\n1 5...
My name is James diGriz, I'm the most clever robber and treasure hunter in the whole galaxy. There are books written about my adventures and songs about my operations, though you were able to catch me up in a pretty awkward moment. I was able to hide from cameras, outsmart all the guards and pass numerous traps, but w...
{ "inputs": [ "7 5 1", "2 2 1", "77 42 36", "40 98 58", "1 100 97", "7 5 0", "77 42 5", "2 2 0", "80 98 58", "1 110 97", "11 5 0", "2 4 0", "77 42 2", "103 98 58", "0 110 97", "14 5 0", "2 4 -1", "77 42 0", "103 98 87", "1 111 97", "1...
We ask you to select some number of positive integers, and calculate the sum of them. It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer. Your objecti...
{ "inputs": [ "8\n0 0\n1 0\n1 1\n0 1\n3 3\n-3 -3\n-1 2\n0 -3" ], "outputs": [ "1\n1\n0\n0\n1\n1\n2\n2" ] }
There is a very large field, colored white and divided into squares. There is a coordinate system attached to the field: y-axis goes from south to north and x-axis goes from west to east. Sides of the squares are parallel to the axes. There is a robot in the (0, 0) square. Robot starts to move in spiral as depicted. Fi...
{ "inputs": [ "3\n4 15\n1 3 10 11\n1 2 7\n4 100\n1 5 10 50\n3 14 12\n2 1000000000\n1 1\n1\n", "3\n4 15\n1 3 10 11\n1 2 7\n4 100\n1 5 10 42\n3 14 12\n2 1000000000\n1 1\n1\n", "3\n4 15\n1 3 10 11\n1 2 7\n4 111\n2 5 10 39\n3 14 12\n2 1000000000\n1 1\n1\n", "3\n4 15\n1 3 10 11\n1 2 7\n4 111\n2 5 10 39\n3 ...
Polycarp is wondering about buying a new computer, which costs c tugriks. To do this, he wants to get a job as a programmer in a big company. There are n positions in Polycarp's company, numbered starting from one. An employee in position i earns a[i] tugriks every day. The higher the position number, the more tugriks...
{ "inputs": [ "2 2 1\n100 1 1\n2\n100 2 1\n1\n", "1 2 1\n1 1 1\n1\n", "3 2 5\n100 1 1\n1\n100 1 1\n2\n200 1 2\n1 2\n", "1 1 100000000\n1 100000000 1\n1\n", "4 4 1000000000\n1000000000 1000000000 1\n1\n1000000000 1000000000 1\n2\n1000000000 1000000000 1\n3\n1000000000 1000000000 1\n4\n", "1 20 ...
A boy named Gena really wants to get to the "Russian Code Cup" finals, or at least get a t-shirt. But the offered problems are too complex, so he made an arrangement with his n friends that they will solve the problems for him. The participants are offered m problems on the contest. For each friend, Gena knows what pr...
{ "inputs": [ "3 3\n2\nb\nb\nbbac\n0\na\naca\nacba\n1\nab\nc\nccb\n", "5 5\n2\na\nabcbb\nabcaacac\naab\naaa\n0\nb\nb\nbb\nbbaaaabca\nbbcbbc\n4\ncbcb\ncbcbac\ncabbcbbca\ncaca\ncc\n1\nba\nbacbbabcc\nbaccac\nbccababc\na\n3\naaccacabac\nacbb\nacaaaac\nc\ncb\n", "5 5\n4\nacxxay\nasuuswzxyzwvxvwcbuvtxw\nasxyabc...
While exploring the old caves, researchers found a book, or more precisely, a stash of mixed pages from a book. Luckily, all of the original pages are present and each page contains its number. Therefore, the researchers can reconstruct the book. After taking a deeper look into the contents of these pages, linguists t...
{ "inputs": [ "5 6 1\n4 2 1 3 2 6\n2 3 2 4 7 2\n5 2 2 1 1 3\n1 4 3 3 6 4\n5 1 4 2 3 2\n", "3 3 1\n1 2 3\n4 5 6\n7 8 9\n", "2 2 0\n1 2\n2 4\n", "8 7 0\n6 4 7 4 2 3 5\n3 5 6 3 10 9 1\n1 9 3 5 2 1 2\n9 1 5 10 5 8 8\n1 7 1 7 9 8 8\n1 3 9 1 10 3 9\n8 4 3 3 5 6 5\n6 10 7 6 3 8 2\n", "100 2 0\n2 3\n3 2\n...
Let's assume that we are given an n Γ— m table filled by integers. We'll mark a cell in the i-th row and j-th column as (i, j). Thus, (1, 1) is the upper left cell of the table and (n, m) is the lower right cell. We'll assume that a circle of radius r with the center in cell (i0, j0) is a set of such cells (i, j) that <...
{ "inputs": [ "3\nSVO\nSVO-&gt;HKT\nHKT-&gt;SVO\nSVO-&gt;RAP\n", "4\nSVO\nSVO-&gt;CDG\nLHR-&gt;SVO\nSVO-&gt;LHR\nCDG-&gt;SVO\n", "1\nESJ\nESJ->TSJ\n", "1\nAAK\nAAK->ABA\n", "3\nZIZ\nDWJ->ZIZ\nZIZ->DWJ\nZIZ->DWJ\n", "3\nSVO\nSVO->HKT\nHKT->SVO\nSVO->RAP\n", "11\nFGH\nFGH->BRZ\nUBK->FGH\nQRE...
There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from their hometown, Ivan, Artsem and Konstantin take a flight to the contest and back. Jinotega's best friends, team ...
{ "inputs": [ "4 3\n", "5 2\n", "2 1\n", "97821761637600 97821761637497\n", "97821761637600 97\n", "99999999999030 139\n", "99999640000243 99999640000143\n", "1117 1\n", "1260 1157\n", "7420738134810 103\n", "99999999999030 127\n", "97821761637600 71\n", "1117 9\n",...
The campus has m rooms numbered from 0 to m - 1. Also the x-mouse lives in the campus. The x-mouse is not just a mouse: each second x-mouse moves from room i to the room i β‹… x mod{m} (in fact, it teleports from one room to another since it doesn't visit any intermediate room). Starting position of the x-mouse is unknow...
{ "inputs": [ "25\n", "3\n", "2\n", "13\n", "864691128455135232\n", "999971062750901550\n", "943414054006932870\n", "994374468178120050\n", "38927073\n", "136\n", "6\n", "210\n", "55\n", "499999999500000000\n", "138485688541650132\n", "605000000550000000...
Daniel is organizing a football tournament. He has come up with the following tournament format: 1. In the first several (possibly zero) stages, while the number of teams is even, they split in pairs and play one game for each pair. At each stage the loser of each pair is eliminated (there are no draws). Such stage...
{ "inputs": [ "2\n10 30", "1\n1000", "3\n200 200 200", "2\n14 30", "1\n1001", "3\n283 200 200", "2\n14 38", "1\n1100", "3\n99 200 200", "2\n17 38", "1\n1110", "3\n77 200 200", "2\n17 24", "1\n0110", "3\n77 251 200", "2\n10 24", "1\n0100", "3\n77 ...
Given is a sequence of N integers A_1, \ldots, A_N. Find the (multiplicative) inverse of the sum of the inverses of these numbers, \frac{1}{\frac{1}{A_1} + \ldots + \frac{1}{A_N}}. Constraints * 1 \leq N \leq 100 * 1 \leq A_i \leq 1000 Input Input is given from Standard Input in the following format: N A_1 A_2 \...
{ "inputs": [ "2\n0 1", "5\n0 1\n0 2\n0 3\n3 4", "10\n2 8\n6 0\n4 1\n7 6\n2 3\n8 6\n6 9\n2 4\n5 8", "2\n0 2", "2\n0 4", "2\n0 5", "2\n0 9", "2\n0 18", "2\n0 12", "2\n0 17", "2\n1 17", "2\n1 21", "2\n2 21", "2\n2 27", "2\n2 8", "2\n0 8", "2\n0 3", ...
We have a tree with N vertices. The vertices are numbered 0 through N - 1, and the i-th edge (0 ≀ i < N - 1) comnnects Vertex a_i and b_i. For each pair of vertices u and v (0 ≀ u, v < N), we define the distance d(u, v) as the number of edges in the path u-v. It is expected that one of the vertices will be invaded by ...
{ "inputs": [ "7 3\nabacaba\n1 1 1\n1 0 0\n1 0 0\n", "7 3\nabacaba\n0 1 1\n1 0 0\n1 0 0\n", "7 4\nbacadab\n0 1 1 1\n1 0 0 0\n1 0 0 0\n1 0 0 0\n", "3 3\ncbc\n0 0 0\n0 0 1\n0 1 0\n", "10 4\nbcaaddaacc\n1 0 1 1\n0 0 1 0\n1 1 1 0\n1 0 0 1\n", "100 10\nigffabeaiaajhjaghjgfjcchheeigjhibadbbhdhcjiibh...
You are given a string of length n. Each character is one of the first p lowercase Latin letters. You are also given a matrix A with binary values of size p Γ— p. This matrix is symmetric (A_{ij} = A_{ji}). A_{ij} = 1 means that the string can have the i-th and j-th letters of Latin alphabet adjacent. Let's call the s...
{ "inputs": [ "3\n", "2\n", "20\n", "9\n", "181\n", "261\n", "8\n", "121\n", "351\n", "71\n", "141\n", "361\n", "1\n", "61\n", "301\n", "392\n", "10\n", "321\n", "161\n", "151\n", "41\n", "251\n", "241\n", "395\n", "27...
It is known that passages in Singer house are complex and intertwined. Let's define a Singer k-house as a graph built by the following process: take complete binary tree of height k and add edges from each vertex to all its successors, if they are not yet present. <image> Singer 4-house Count the number of non-empty ...
{ "inputs": [ "3\n0 0 0\n7\n2 1\n2 2\n2 3\n1 2 1\n2 1\n2 2\n2 3\n", "5\n0 1 2 3 4\n15\n2 1\n2 2\n1 2 1\n2 2\n2 3\n2 5\n1 3 0\n1 4 0\n2 3\n2 4\n2 5\n1 4 1\n2 3\n2 4\n2 5\n", "5\n0 0 2 3 0\n10\n2 1\n2 5\n2 2\n1 1 0\n2 5\n1 2 0\n1 3 1\n2 3\n2 3\n2 4\n", "10\n0 1 2 2 1 0 0 4 7 9\n10\n2 1\n2 5\n1 6 2\n1 7 ...
You were playing with permutation p of length n, but you lost it in Blair, Alabama! Luckily, you remember some information about the permutation. More specifically, you remember an array b of length n, where b_i is the number of indices j such that j < i and p_j > p_i. You have the array b, and you want to find the p...
{ "inputs": [ "5\n2 4 1 5 3\n", "6\n1 2 4 5 6 3\n", "2\n1 2\n", "10\n8 10 9 3 7 5 4 6 2 1\n", "1\n1\n", "15\n1 7 12 14 15 9 8 10 11 2 5 4 3 13 6\n", "2\n2 1\n", "10\n8 10 9 3 7 5 4 6 1 2\n", "5\n3 4 1 5 2\n" ], "outputs": [ "1\n3\n6\n8\n11\n", "1\n3\n6\n8\n12\n17\n", ...
Ildar is the algorithm teacher of William and Harris. Today, Ildar is teaching Cartesian Tree. However, Harris is sick, so Ildar is only teaching William. A cartesian tree is a rooted tree, that can be constructed from a sequence of distinct integers. We build the cartesian tree as follows: 1. If the sequence is em...
{ "inputs": [ "10 10\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n", "2 5\n3 1 2 3\n3 3 4 5\n", "4 4\n2 1 2\n2 2 3\n2 3 4\n2 4 1\n", "3 10\n4 6 10 1 9\n9 6 1 8 10 4 9 5 7 2\n8 3 10 6 8 2 4 5 1\n", "10 100\n4 51 22 73 78\n1 52\n5 49 74 100 14 80\n1 6\n2 98 65\n5 79 13 47 24 77\n6 47 57 35 24...
Dora the explorer has decided to use her money after several years of juicy royalties to go shopping. What better place to shop than Nlogonia? There are n stores numbered from 1 to n in Nlogonia. The i-th of these stores offers a positive integer a_i. Each day among the last m days Dora bought a single integer from s...
{ "inputs": [ "6 4\n100 20 40 20 50 50\n", "3 2\n40 20 30\n", "2 2\n200 300\n", "100 1\n199 348 489 76 638 579 982 125 28 401 228 117 195 337 80 914 752 98 679 417 47 225 357 413 849 622 477 620 487 223 321 240 439 393 733 660 652 500 877 40 788 246 376 723 952 601 912 316 598 809 476 932 384 147 982 ...
The R1 company wants to hold a web search championship. There were n computers given for the competition, each of them is connected to the Internet. The organizers believe that the data transfer speed directly affects the result. The higher the speed of the Internet is, the faster the participant will find the necessar...
{ "inputs": [ "9\n4 8 10 12 15 18 33 44 81\n", "6\n3 6 9 18 36 108\n", "2\n7 17\n", "4\n3 5 7 105\n", "13\n2 12 60 300 900 6300 44100 176400 352800 705600 3528000 21168000 148176000\n", "11\n2 6 15 35 77 143 221 323 437 667 899\n", "4\n2 3 5 30\n", "27\n5 10 29 58 116 174 2297 4594 918...
Dima the hamster enjoys nibbling different things: cages, sticks, bad problemsetters and even trees! Recently he found a binary search tree and instinctively nibbled all of its edges, hence messing up the vertices. Dima knows that if Andrew, who has been thoroughly assembling the tree for a long time, comes home and s...
{ "inputs": [ "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n", "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n", "2 1\n1 2 1\n", "3 1\n1 2 1\n", "10 10\n1 4 201\n2 3 238\n3 4 40\n3 6 231\n3 8 45\n4 5 227\n4 6 58\n4 9 55\n5 7 14\n6 10 242\n", "10 10\n1 5 178\n1 8 221\n2 7 92\n2 8 159\n3 5 55...
You are given a weighted undirected graph. The vertices are enumerated from 1 to n. Your task is to find the shortest path between the vertex 1 and the vertex n. Input The first line contains two integers n and m (2 ≀ n ≀ 105, 0 ≀ m ≀ 105), where n is the number of vertices and m is the number of edges. Following m l...
{ "inputs": [ "100\n64\n50\n20\n151200\n0", "100\n84\n50\n20\n151200\n0", "100\n84\n50\n20\n150323\n0", "100\n160\n50\n20\n150323\n0", "100\n64\n50\n17\n151200\n0", "100\n50\n50\n20\n151200\n0", "100\n63\n50\n20\n150323\n0", "100\n5\n50\n17\n151200\n0", "100\n50\n74\n20\n151200\n0"...
The surveyor starship Hakodate-maru is famous for her two fuel containers with unbounded capacities. They hold the same type of atomic fuel balls. There, however, is an inconvenience. The shapes of the fuel containers #1 and #2 are always cubic and regular tetrahedral respectively. Both of the fuel containers should b...
{ "inputs": [ "RRULDL\n\nSAMPLE", "RDUUDLRLDLDLDLRUUDLRLDDURUUUUUDUDUDDDDRLLLLLLRRRRLLL", "DDURLDRRUURDRLRDUDUDDUURULLUDRLUDUURDURRURDDRLDLRDURURDLDDDRRRLLURDUURRDLDDDDUDLDLULRRLLUDRLDRRRLDLRULULLLRRLDUDRRUDLUULLDRURULLRULRDLUDDDLDDLRLLUDLRLUULRDDULRRDRRLLRDLRDLRLDLRRDRUUDUUDRRDULUDUDLLRLUDLRRLRDULLRLLULU...
View Russian Translation Little pig Benny has just taken a shower. Now she is going to buy some gifts for her relatives. But the problem is that Benny doesn't know how to reach to the gift shop. Her friend Mike has created a special set of instructions for her. A set of instructions is a string which consists of lett...
{ "inputs": [ "2\nababca\naaabb\n\nSAMPLE", "100\nglnnnxnnmkqnagymndnkbzntnnonuoooannctnunwarxnwnntnrnnnnsronbhnnnxvvnnkkneibhamhbhurnvnnvvnottnlyvwnnyamnnuzghnnlpsnceunslpnyakubnpfihyhzybmuurhymlmrxrgskanvwnkrnnwuotnnmipnnnlacjnpnkojgnnizdrpscnqnynbnjnvyrpmnnzjafuuynuiznqnnrtunpzrdsknyrnnnnnhyynvsenukyikxnyq...
Kevin has a string S consisting of N lowercase English letters. Kevin wants to split it into 4 pairwise different non-empty parts. For example, string "happynewyear" can be splitted into "happy", "new", "ye" and "ar". He can't delete any characters or change the order of the characters. Help Kevin and find if ther...
{ "inputs": [ "3\n2 3\n3 1\n3\n1 2\n1 3\n", "7\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n4\n4 1\n4 2\n4 3\n", "5\n1 2\n2 3\n3 4\n4 5\n4\n4 1\n4 2\n4 3\n", "5\n1 2\n2 3\n3 4\n4 5\n3\n1 2\n2 3\n", "1\n1\n", "20\n14 17\n20 7\n13 15\n20 4\n18 9\n6 3\n16 13\n5 20\n6 14\n13 11\n6 20\n2 20\n4 19\n20 13\n12 13\n...
You are given two trees (connected undirected acyclic graphs) S and T. Count the number of subtrees (connected subgraphs) of S that are isomorphic to tree T. Since this number can get quite large, output it modulo 109 + 7. Two subtrees of tree S are considered different, if there exists a vertex in S that belongs to ...
{ "inputs": [ "10 30\n10 35\n05:20\n", "60 120\n24 100\n13:00\n", "15 14\n32 65\n05:45\n", "1 1\n3 2\n08:44\n", "1 3\n1 2\n21:43\n", "30 19\n21 4\n10:30\n", "65 49\n24 90\n07:10\n", "1 1\n1 1\n23:59\n", "40 74\n100 42\n05:40\n", "1 120\n1 100\n23:59\n", "20 4\n1 20\n06:20\n...
Buses run between the cities A and B, the first one is at 05:00 AM and the last one departs not later than at 11:59 PM. A bus from the city A departs every a minutes and arrives to the city B in a ta minutes, and a bus from the city B departs every b minutes and arrives to the city A in a tb minutes. The driver Simion...
{ "inputs": [ "2\nghjk\nab", "2\nghjk\nba", "2\nhgjk\nba", "2\nhgjk\nca", "2\nhgik\nca", "2\nhgik\nac", "2\nhhik\nac", "2\nhhik\nbc", "2\nhhik\nca", "2\nhiik\nca", "2\nhiik\nac", "2\nhiki\nac", "2\nikih\nac", "2\nikih\nca", "2\nikig\nca", "2\nilig\nca", ...
While evaluating a expression of N distinct factors i.e (A1 * A2 * ..... * An) , Chef wanted to know in how may ways this expression can be evaluated by parenthesizing two factors at a time. Input The first line of the input contains an integer T denoting the number of test cases, for each test case enter the string ...
{ "inputs": [ "5\n3 10\n48 17\n31 199\n231 23\n3 2", "4\n1 1\n1 1\n1 5\n1 100", "3\n2 3\n1 1\n3 2", "5\n3 1\n48 17\n31 199\n231 23\n3 2", "4\n1 1\n1 1\n1 9\n1 100", "3\n3 3\n1 1\n3 2", "3\n4 3\n1 1\n3 1", "3\n4 3\n1 2\n3 1", "3\n2 3\n1 1\n1 2", "4\n1 2\n1 1\n1 9\n1 100", "5...
AtCoDeer the deer is seeing a quick report of election results on TV. Two candidates are standing for the election: Takahashi and Aoki. The report shows the ratio of the current numbers of votes the two candidates have obtained, but not the actual numbers of votes. AtCoDeer has checked the report N times, and when he c...
{ "inputs": [ "7\n5 2 4\n3 1 1 2 5\n5 3 4\n1 1 2 1 2\n4 0 4\n5 5 3 3\n4 1 4\n2 3 2 3\n6 1 2\n3 2 1 1 1 1\n6 2 4\n3 3 2 1 1 1\n6 2 6\n1 1 3 2 1 1\n", "6\n1 0 0\n1\n1 0 0\n2\n1 0 1\n1\n1 0 1\n2\n1 1 1\n1\n1 1 1\n2\n", "7\n5 2 4\n3 1 1 2 5\n5 3 4\n1 1 2 1 2\n4 0 4\n5 5 3 3\n4 1 4\n2 3 2 3\n6 1 2\n3 2 1 1 1 1...
In the game of Mastermind, there are two players β€” Alice and Bob. Alice has a secret code, which Bob tries to guess. Here, a code is defined as a sequence of n colors. There are exactly n+1 colors in the entire universe, numbered from 1 to n+1 inclusive. When Bob guesses a code, Alice tells him some information about ...
{ "inputs": [ "1\n\n7\n\n1\n\n1\n\n0\n\n0\n\n1\n", "46\n63 1\n63 63\n123 1\n123 123\n63 2\n63 62\n123 2\n123 122\n63 3\n63 61\n123 3\n123 121\n63 4\n63 60\n123 4\n123 120\n63 5\n63 59\n123 5\n123 119\n66 65\n80 30\n114 107\n95 66\n87 83\n103 40\n71 65\n72 48\n104 93\n93 14\n65 61\n118 4\n75 68\n108 26\n97 94\...
Linda likes to change her hair color from time to time, and would be pleased if her boyfriend Archie would notice the difference between the previous and the new color. Archie always comments on Linda's hair color if and only if he notices a difference β€” so Linda always knows whether Archie has spotted the difference o...
{ "inputs": [ "2 2\n2 3\n3 5\n", "3 2\n1 2 3\n3 4\n", "3 2\n4 5 6\n1 2\n", "1 1\n2\n1\n", "2 1\n2 2\n3\n", "1 1\n100\n183299\n", "1 1\n1\n1\n", "1 2\n1\n2 2\n", "10 10\n23 100 38 38 73 54 59 69 44 86\n100 100 100 100 100 100 100 100 100 100\n", "1 1\n100\n4\n", "1 1\n999999...
Devu and his brother love each other a lot. As they are super geeks, they only like to play with arrays. They are given two arrays a and b by their father. The array a is given to Devu and b to his brother. As Devu is really a naughty kid, he wants the minimum value of his array a should be at least as much as the ma...
{ "inputs": [ "3\n1 2 3\n2 1 3\n", "6\n6 5 4 3 2 1\n6 5 3 4 2 1\n", "5\n3 1 4 2 5\n4 5 1 3 2\n", "1\n1\n1\n", "10\n4 7 10 2 1 8 3 5 9 6\n4 2 7 1 8 10 5 3 9 6\n", "7\n7 6 3 1 5 4 2\n2 3 1 6 4 7 5\n", "5\n3 1 4 2 5\n4 5 1 3 3\n", "7\n7 6 3 1 5 4 2\n2 3 1 6 4 7 7\n", "5\n3 1 4 2 5\n2 ...
Vasya has got n books, numbered from 1 to n, arranged in a stack. The topmost book has number a_1, the next one β€” a_2, and so on. The book at the bottom of the stack has number a_n. All numbers are distinct. Vasya wants to move all the books to his backpack in n steps. During i-th step he wants to move the book number...
{ "inputs": [ "4\n4 3 2 4\n", "6\n4 5 3 8 3 7\n", "100\n1354 1797 588 3046 1290 745 217 907 113 381 523 935 791 415 92 1597 1739 1774 240 27 1262 2498 52 1339 1031 1355 2036 230 489 7 69 877 530 2664 1230 940 2712 2651 3410 480 332 699 957 2257 1877 1940 452 1652 1216 3144 236 165 1109 888 1649 346 24 183...
One day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as n measurements, and recorded the results in the notebook. After that he was about to show the results to the teacher, but he remembered that at the last lesson, the teacher had...
{ "inputs": [ "1\n2\n", "2\n3 5\n", "1\n1\n", "49\n1 4 4 3 5 2 2 1 5 1 2 1 2 5 1 4 1 4 5 2 4 5 3 5 2 4 2 1 3 4 2 1 4 2 1 1 3 3 2 3 5 4 3 4 2 4 1 4 1\n", "1\n5\n", "25\n4 5 5 5 3 1 1 4 4 4 3 5 4 4 1 4 4 1 2 4 2 5 4 5 3\n", "100\n4 4 2 5 4 2 2 3 4 4 3 2 3 3 1 3 4 3 3 4 1 3 1 4 5 3 4 3 1 1 1 ...
Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place. To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and t...
{ "inputs": [ "3776.0\n1819.0\n645.2\n2004.1\n1208.6", "3776.5765005393655\n1819.0\n645.2\n2004.1\n1208.6", "3777.502968017379\n1819.0\n645.2\n2004.1\n1208.6", "3778.4165917426626\n1819.0\n645.2\n2004.2183724359945\n1208.6", "3779.3515835085277\n1819.169376096264\n645.2\n2004.5930566110492\n1208.6...
There is data that records the altitude of mountains that have been climbed so far. Create a program that reads this data and outputs the elevation difference between the highest and lowest mountains. Input The input is given in the following format: Mountain height ... ... The height of the mountain is given o...
{ "inputs": [ "5\n5 3\n1 5 2 6 1\n1 6\n6\n3 2\n1 2 3\n4 3\n3 1 2 3\n10 3\n1 2 3 4 5 6 7 8 9 10\n", "1\n7 2\n5 5 1 1 2 1 1\n", "1\n26 2\n2 1 1 1 3 1 4 1 1 5 1 1 6 1 1 7 1 1 8 1 1 9 1 1 10 1\n", "1\n17 15\n3 5 4 6 10 2 16 10 18 8 5 1 2 7 15 14 8\n", "1\n10 10\n10 1 1 1 1 1 1 11 1 11\n", "1\n7 3\...
Slime has a sequence of positive integers a_1, a_2, …, a_n. In one operation Orac can choose an arbitrary subsegment [l … r] of this sequence and replace all values a_l, a_{l + 1}, …, a_r to the value of median of \\{a_l, a_{l + 1}, …, a_r\}. In this problem, for the integer multiset s, the median of s is equal to th...
{ "inputs": [ "3\n3\n15\n5\n\nSAMPLE", "3\n3\n15\n5\n\nASMPLE", "3\n3\n30\n2\n\nASLPLE", "3\n1\n19\n1\n\nASLPLE", "3\n2\n19\n1\n\nASLPLE", "3\n2\n16\n2\n\nASLPLE", "3\n6\n15\n2\n\nASMPKE", "3\n2\n1\n1\n\nBSLPEL", "3\n3\n7\n3\n\nBSLPLE", "3\n3\n15\n2\n\nASMPLE", "3\n3\n15\n2...
Today grasshopper Jimmy Jumper is very hungry and his friend is notorious. Jimmy's friend puts an insect infront of him at a distance d. Jimmy can jump only a finite no of steps in each turn. Jimmy is initially at position 0. He can now jump 1 step to reach position 1 then jump 2 steps to reach position 3 then jump 4 s...
{ "inputs": [ "3 1\n1 100 1", "12 5\n43 94 27 3 69 99 56 25 8 15 46 8", "3 1000\n1 100 1", "6 14\n25 171 7 1 17 162", "3 1\n2 100 1", "12 5\n43 94 27 3 69 99 56 25 15 15 46 8", "3 1000\n1 101 1", "6 24\n25 171 7 1 17 162", "3 1\n0 100 1", "12 5\n43 94 27 3 69 99 56 25 27 15 46 ...
There are N cities in Republic of AtCoder. The size of the i-th city is A_{i}. Takahashi would like to build N-1 bidirectional roads connecting two cities so that any city can be reached from any other city by using these roads. Assume that the cost of building a road connecting the i-th city and the j-th city is |i-j...
{ "inputs": [ "5 6\n/home/ACM/index.html\n/ICPC/index.html\n/ICPC/general.html\n/ICPC/japanese/index.html\n/ICPC/secret/confidential/2005/index.html\n/home/ACM/\n/home/ICPC/../ACM/\n/ICPC/secret/\n/ICPC/secret/index.html\n/ICPC\n/ICPC/../ICPC/index.html\n/ICPC\n/ICPC/general.html\n/ICPC/japanese/.././\n/ICPC/japa...
Professor Pathfinder is a distinguished authority on the structure of hyperlinks in the World Wide Web. For establishing his hypotheses, he has been developing software agents, which automatically traverse hyperlinks and analyze the structure of the Web. Today, he has gotten an intriguing idea to improve his software a...
{ "inputs": [ "2\n2 9\n", "3\n3 12 6\n", "7\n2 1000000000 4 6 8 4 2\n", "6\n13 52 0 13 26 52\n", "10\n100000000 200000000 300000000 20 500000000 600000000 700000000 800000000 900000000 1000000000\n", "10\n1 1000000000 1 1 1 1 1 1 1 1\n", "5\n0 0 1 0 0\n", "10\n1000000000 1 2 3 4 5 6 7 ...
There were n types of swords in the theater basement which had been used during the plays. Moreover there were exactly x swords of each type. y people have broken into the theater basement and each of them has taken exactly z swords of some single type. Note that different people might have taken different types of swo...
{ "inputs": [ "3 2" ], "outputs": [ "6" ] }
Consider a sequence of non- negative integers b(1), b(2) … , b(n) of length n. The given sequence is called a winning sequence if and only if there exists integers p and q between 1 and n (both inclusive) such that a(p) xor a(p+1) xor a(p+2) …. xor a(q) = 0. The xor operation is the bitwise xor operation between two in...
{ "inputs": [ "4\n", "2\n", "7\n", "536870913\n", "1048576\n", "1024\n", "999999999999\n", "123456789\n", "3\n", "10\n", "12000\n", "1000\n", "549755813889\n", "549755813888\n", "100000\n", "536870911\n", "1000000000000\n", "65536\n", "536870...
Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him a problem that combines both. He has a complete graph consisting of n vertices numbered from 0 to n - 1. For all 0 ≀ u < v < n, vertex u and vertex v are connected with an undirected edge that has weight <image> (where <image> is t...
{ "inputs": [ "7 3\n1 2 3\n1 4 5\n4 6 7\n", "9 3\n3 6 9\n2 5 8\n1 4 7\n", "5 2\n4 1 5\n3 1 2\n", "13 6\n8 7 6\n11 7 3\n13 9 3\n12 1 13\n8 10 4\n2 7 5\n", "98 38\n70 23 73\n73 29 86\n93 82 30\n6 29 10\n7 22 78\n55 61 87\n98 2 12\n11 5 54\n44 56 60\n89 76 50\n37 72 43\n47 41 61\n85 40 38\n48 93 20\n...
In Berland, there is the national holiday coming β€” the Flag Day. In the honor of this event the president of the country decided to make a big dance party and asked your agency to organize it. He has several conditions: * overall, there must be m dances; * exactly three people must take part in each dance; * eac...
{ "inputs": [ "5 0\n3 14 15 92 6\n", "3 1\n1 2 3\n", "10 1000000\n1 2 3 4 84 5 6 7 8 9\n", "1 1\n3\n", "13 666\n84 89 29 103 128 233 190 122 117 208 119 97 200\n", "1 0\n0\n", "42 42\n42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 4...
You've got an array a, consisting of n integers. The array elements are indexed from 1 to n. Let's determine a two step operation like that: 1. First we build by the array a an array s of partial sums, consisting of n elements. Element number i (1 ≀ i ≀ n) of array s equals <image>. The operation x mod y means that ...
{ "inputs": [ "3\n0\n0\n2", "5\n0\n1\n2\n3\n4", "5\n0\n1\n0\n3\n4", "3\n0\n1\n2", "5\n0\n1\n1\n3\n4", "3\n0\n1\n1", "5\n0\n0\n0\n0\n4", "5\n0\n0\n1\n3\n0", "5\n0\n1\n1\n1\n1", "5\n0\n1\n1\n0\n2", "5\n0\n0\n1\n3\n4", "5\n0\n0\n2\n3\n4", "3\n0\n0\n1", "5\n0\n0\n0\...
Problem Today, the high-class restaurant "Maizu Restaurant", which is completely invited, has finally opened. Only members of this restaurant have the right to invite new members, initially only the owner of the restaurant with membership number 0. Due to its luxury, the Maze Restaurant is only open for $ N $ days fr...
{ "inputs": [ "2\n0 3 D\n3 0 L", "20\n6 -10 R\n-4 -9 U\n9 6 D\n-3 -2 R\n0 7 D\n4 5 D\n10 -10 U\n-1 -8 U\n10 -6 D\n8 -5 U\n6 4 D\n0 3 D\n7 9 R\n9 -4 R\n3 10 D\n1 9 U\n1 -6 U\n9 -8 R\n6 7 D\n7 -3 D", "5\n-7 -10 U\n7 -6 U\n-8 7 D\n-3 3 D\n0 -6 R", "20\n6 -10 R\n-4 -9 U\n9 6 D\n-3 -2 R\n0 7 D\n4 5 D\n10 -...
There are N points in a two-dimensional plane. The initial coordinates of the i-th point are (x_i, y_i). Now, each point starts moving at a speed of 1 per second, in a direction parallel to the x- or y- axis. You are given a character d_i that represents the specific direction in which the i-th point moves, as follows:...
{ "inputs": [ "869 120 1001", "2 2 1", "869 80 1001", "328 80 1001", "328 102 1011", "328 102 1111", "279 102 1111", "25 102 1111", "25 122 1111", "25 63 1111", "25 89 1111", "1486 120 1001", "869 80 1101", "328 117 1011", "40 102 1111", "328 60 1111", ...
In 2937, DISCO creates a new universe called DISCOSMOS to celebrate its 1000-th anniversary. DISCOSMOS can be described as an H \times W grid. Let (i, j) (1 \leq i \leq H, 1 \leq j \leq W) denote the square at the i-th row from the top and the j-th column from the left. At time 0, one robot will be placed onto each s...
{ "inputs": [ "2 1 3 4", "2 1 3 6", "3 1 3 6", "3 0 3 6", "3 0 3 12", "4 0 1 0", "6 0 1 0", "6 1 1 0", "0 11 -2 -1", "0 11 -2 -2", "0 11 -2 0", "0 11 -2 1", "0 11 -3 1", "0 17 -3 1", "0 17 -3 0", "0 17 -2 0", "-1 16 -1 0", "-14 0 -1 1", "0 1 ...
Problem statement When you heard that this year's KUPC can be joined as a team, you decided to talk to your friends and join as a team. Eventually, $ 4 $ people, including you, got together. Individual strength is expressed in ratings, and $ 4 $ person ratings are $ a $, $ b $, $ c $, and $ d $, respectively. You d...
{ "inputs": [ "3\n\nSAMPLE", "3\n\nSAMPKE", "3\n\nSAMPKD", "3\n\nSAMOKD", "3\n\nSAMDKO", "3\n\nSADMKO", "3\n\nTADMKO", "3\n\nTADMJO", "3\n\nTADNJO", "3\n\nT@DNJO", "3\n\nT@DNJN", "3\n\nJ@DNTN", "3\n\nJ@DMTN", "3\n\nI@DMTN", "3\n\nI@DTMN", "3\n\nI@ETMN", ...
Rani has challenged Nandu to generate Splendid Matrices. Splendid matrices are square matrices with dimensions 2^n X 2^n filled in a particular manner. To explain this manner, Rani gives Nandu the matrices for n=1, n=2 and n=3 : n=1 1 2 3 4 n=2 (spacing for clarity) 1 2 5 6 3 4 7 8 9 10 13 14 11 12 15 16 n=3...
{ "inputs": [ "3\n1 1 1\n", "4\n1 1 2 1\n", "2\n2 2\n", "7\n2 2 2 1 1 1 1\n", "10\n1 2 2 1 2 2 1 2 1 1\n", "3\n1 2 2\n", "10\n2 2 1 1 1 1 1 1 1 1\n", "4\n1 1 1 1\n", "3\n2 2 2\n", "247\n2 2 1 2 1 2 2 2 2 2 2 1 1 2 2 1 2 1 1 1 2 1 1 1 1 2 1 1 2 2 1 2 1 1 1 2 2 2 1 1 2 1 1 2 1 1 ...
There were n groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team. The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams...
{ "inputs": [ "2\n2\n1 2\n5\n4 5 3 1 2\n\nSAMPLE", "10\n41\n18467 6334 26500 19169 15724 11478 29358 26962 24464 5705 28145 23281 16827 9961 491 2995 11942 4827 5436 32391 14604 3902 153 292 12382 17421 18716 19718 19895 5447 21726 14771 11538 1869 19912 25667 26299 17035 9894 28703 23811 \n322\n30333 17673 4...
Andrew is very fond of Maths.He has N boxes with him,in each box there is some value which represents the Strength of the Box.The ith box has strength A[i]. He wants to calculate the Overall Power of the all N Boxes. Overall Power here means Sum of Absolute Difference of the strengths of the boxes(between each pair of...
{ "inputs": [ "3\n2 3 1\n", "4\n2 1 1 1\n", "5\n2 4 2 5 3\n", "84\n2 50 67 79 71 45 43 40 57 20 25 8 60 47 52 10 37 23 1 28 22 26 3 42 11 63 61 68 49 32 55 18 5 24 31 70 66 27 38 41 54 12 65 51 15 34 30 35 77 74 21 62 33 16 81 14 19 48 80 73 69 78 39 6 76 46 75 72 84 29 58 59 13 17 82 9 83 4 36 56 53 ...
ZS the Coder and Chris the Baboon has explored Udayland for quite some time. They realize that it consists of n towns numbered from 1 to n. There are n directed roads in the Udayland. i-th of them goes from town i to some other town ai (ai β‰  i). ZS the Coder can flip the direction of any road in Udayland, i.e. if it ...
{ "inputs": [ "2\n", "4\n", "1000000\n", "100\n", "300000\n", "300\n", "9\n", "1\n", "3\n", "3000\n", "6\n", "8\n", "1500\n", "10000\n", "15\n", "900\n", "30\n", "31\n", "99999\n", "100000\n", "4000000\n", "10000000\n", "10\n"...
You are given a tetrahedron. Let's mark its vertices with letters A, B, C and D correspondingly. <image> An ant is standing in the vertex D of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each moment of time he makes a step from one vertex to another one along some edge of the tetrahedron. T...
{ "inputs": [ "19 5 1821\naupontrougevkoffice\n", "4 2 1\nabac\n", "5 2 2\nasgnj\n", "154 81 10000\nyocpcoifeqijjlxfpirerbdvhodniwreecnidrubisoewivmwynhvnwzywnntlerhvluvgtiijivurdznkmijgpvetolnheoxwgdgltcekbxtafredhjhlhfaurwivdatyrzwavvqdlyvjhajkugoiqyfe\n", "401 150 1000000000000000000\nabacabafa...
VK just opened its second HQ in St. Petersburg! Side of its office building has a huge string s written on its side. This part of the office is supposed to be split into m meeting rooms in such way that meeting room walls are strictly between letters on the building. Obviously, meeting rooms should not be of size 0, bu...
{ "inputs": [ "8\n", "1\n", "987\n", "422\n", "100\n", "3\n", "5\n", "4\n", "6\n", "12\n", "116\n", "2\n", "580\n", "9782\n", "7\n", "1000\n", "447\n", "1049\n", "602\n", "101\n", "0\n", "10\n", "9\n", "19\n", "254\n",...
Little X used to play a card game called "24 Game", but recently he has found it too easy. So he invented a new game. Initially you have a sequence of n integers: 1, 2, ..., n. In a single step, you can pick two of them, let's denote them a and b, erase them from the sequence, and append to the sequence either a + b, ...
{ "inputs": [ "2\n3\n1 2 3\n4\n1 2 3 3\n\nSAMPLE", "10\n500\n75 426 445 272 81 447 129 497 202 275 325 482 284 417 156 432 402 228 37 357 239 418 211 179 6 340 68 368 16 440 263 93 449 491 310 355 68 431 80 257 218 434 328 176 355 221 80 422 45 11 67 467 174 191 4 335 34 465 480 221 395 1 152 325 231 302 153 ...
Akhil gives Ramesh an array A of length N. Then he asks him to determine if there exists an element in the array such that the sum of the elements on its left is equal to the sum of the elements on its right. If there are no elements to the left/right, then the sum is considered to be zero. Formally, find an i, such th...
{ "inputs": [ "23\n496\n\nSAMPLE" ], "outputs": [ "496" ] }
Problem Description Apparently, the key that would take Alice home from her Wonderland adventure is a magic pass code hidden in numbers. Help her find it! It's the one with the highest sum of its digits! Input Format Input consists of several integer n, each separated by a newline character. Output Format Output ...
{ "inputs": [ "4\n1 2 10\n2 3 10\n3 3 10\n1 3 10\n6\n1 20 1000\n3 25 10000\n5 15 5000\n22 300 5500\n10 295 9000\n7 7 6000\n8\n32 251 2261\n123 281 1339\n211 235 5641\n162 217 7273\n22 139 7851\n194 198 9190\n119 274 878\n122 173 8640\n0", "4\n1 2 10\n2 3 10\n3 3 10\n1 3 10\n6\n1 20 1000\n3 25 10000\n5 15 5000...
You are appointed director of a famous concert hall, to save it from bankruptcy. The hall is very popular, and receives many requests to use its two fine rooms, but unfortunately the previous director was not very efficient, and it has been losing money for many years. The two rooms are of the same size and arrangement...
{ "inputs": [ "18\n3 4 2 1 5 7 9 7 10 5 12 3 1 1 2 1 3 2\n1\n4 10", "1\n5\n1\n0 0", "2\n3 5\n1\n0 1", "18\n3 4 2 1 5 7 9 7 10 5 12 3 1 1 2 1 0 2\n1\n4 10", "18\n3 4 2 1 5 7 9 14 10 5 12 3 1 1 2 1 3 2\n1\n4 10", "2\n3 3\n1\n0 1", "18\n5 4 2 1 5 7 9 14 10 5 12 3 1 1 2 1 3 2\n1\n4 10", "1...
Chef Ceil has some matchsticks in his kitchen. Detail of matchsticks: There are N matchsticks in total. They are numbered from to 0 to N-1 inclusive. All matchsticks have same length. But they may have different rates of burning. For i^th matchstick, we denote bi as the time required for that matchstick to completely b...
{ "inputs": [ "3\n1\n2\n4\n", "100\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59\n60\n61\n62\n63\n64\n65\n66\n67\n68\n69\n70\n71\...
Andre has very specific tastes. Recently he started falling in love with arrays. Andre calls an nonempty array b good, if sum of its elements is divisible by the length of this array. For example, array [2, 3, 1] is good, as sum of its elements β€” 6 β€” is divisible by 3, but array [1, 1, 2, 3] isn't good, as 7 isn't div...
{ "inputs": [ "5 4\n2 1\n4 2\n3 3\n3 4\n", "4 5\n1 1\n4 4\n4 3\n3 2\n2 4\n", "1 1\n1 1\n", "2 4\n1 1\n2 1\n1 2\n2 2\n", "2 4\n1 1\n2 2\n1 2\n2 2\n", "5 4\n2 1\n4 4\n3 3\n3 4\n", "4 5\n2 1\n4 4\n4 3\n3 2\n2 4\n", "2 4\n1 1\n2 2\n2 2\n2 2\n", "5 4\n2 1\n4 4\n3 3\n5 4\n", "4 5\n2 ...
You are given a chessboard of size n Γ— n. It is filled with numbers from 1 to n^2 in the following way: the first ⌈ (n^2)/(2) βŒ‰ numbers from 1 to ⌈ (n^2)/(2) βŒ‰ are written in the cells with even sum of coordinates from left to right from top to bottom. The rest n^2 - ⌈ (n^2)/(2) βŒ‰ numbers from ⌈ (n^2)/(2) βŒ‰ + 1 to n^2 ...
{ "inputs": [ "5 4 3 1 1\n", "2 1 3 4 5\n", "1000 999 1000 1000 1\n", "1000 999 1 1000 1000\n", "1000 999 1000 1 1000\n", "2 1 1 1 1000\n", "1000 1 1 1000 1\n", "29 12 569 939 259\n", "1000 999 1 1 1000\n", "1000 1 1000 1 1000\n", "1000 1 1000 1000 1\n", "2 1 1000 1 1\n...
A car moves from point A to point B at speed v meters per second. The action takes place on the X-axis. At the distance d meters from A there are traffic lights. Starting from time 0, for the first g seconds the green light is on, then for the following r seconds the red light is on, then again the green light is on fo...
{ "inputs": [ "5 4\n5 2 1 3 7\n1 3 4 10\n", "8 9\n3 1 4 1 5 9 2 6\n1 2 3 4 5 6 7 8 9\n", "1 1\n1000000000\n1000000000\n", "1 1\n1\n1000000000\n", "1 1\n1\n1\n", "1 1\n1000000000\n1\n", "5 4\n5 2 1 3 7\n1 3 4 15\n", "8 9\n3 1 4 0 5 9 2 6\n1 2 3 4 5 6 7 8 9\n", "8 9\n6 1 4 0 5 9 2 6\...
Monocarp would like to open a bakery in his local area. But, at first, he should figure out whether he can compete with other shops. Monocarp plans that the bakery will work for n days. On the i-th day, a_i loaves of bread will be baked in the morning before the opening. At the end of the n-th day, Monocarp will sell ...
{ "inputs": [ "2 2 1\n", "2 2 3\n", "2 2 6\n", "2 2 2\n", "87 20 3\n", "15 6729 6902\n", "4364 1548 8026\n", "6 831 878\n", "16 43 56\n", "57 39 82\n", "2 1 5\n", "54 46 81\n", "8751 81 9336\n", "9296 71 9842\n", "85 5326 5840\n", "2436 4734 9962\n", ...
A very unusual citizen lives in a far away kingdom β€” Dwarf Gracula. However, his unusual name is not the weirdest thing (besides, everyone long ago got used to calling him simply Dwarf Greg). What is special about Dwarf Greg β€” he's been living for over 200 years; besides, he lives in a crypt on an abandoned cemetery an...
{ "inputs": [ "4\n1 2 2 1\n2 3 4\n", "4\n1 1 1 1\n1 3\n", "2\n1 1\n0\n", "3\n1 1 1\n0\n", "8\n1 1 2 1 1 2 1 1\n2 7 8\n", "8\n3 3 1 1 1 1 3 3\n1 6\n", "4\n1 1 1 1\n2 3 4\n", "6\n2 1 1 2 1 1\n1 5\n", "20\n3 3 3 2 2 3 1 1 3 2 1 3 3 1 2 3 1 1 3 3\n1 16\n", "14\n1 2 2 4 4 1 1 1 2 3 ...
As you know, Vova has recently become a new shaman in the city of Ultima Thule. So, he has received the shaman knowledge about the correct bracket sequences. The shamans of Ultima Thule have been using lots of different types of brackets since prehistoric times. A bracket type is a positive integer. The shamans define ...
{ "inputs": [ "3\n1\n5\n10", "3\n1\n9\n10", "3\n1\n9\n13", "3\n1\n9\n19", "3\n1\n10\n19", "3\n1\n10\n15", "3\n1\n14\n15", "3\n1\n14\n1", "3\n1\n14\n2", "3\n1\n19\n2", "3\n1\n4\n10", "3\n1\n9\n5", "3\n1\n9\n11", "3\n1\n10\n11", "3\n1\n24\n2", "3\n1\n7\n1"...
Jerry is not good in studies, but he likes to solve puzzles and always challenges his friend Tom. Today Jerry challenged Tom to solve a new riddle. He says "You are given a Pascal's triangle of infinite height, and you are supposed to find the sum of all the integers present at the given height." As usual Tom is conf...
{ "inputs": [ "6 2\n", "200 50\n", "5892 5197\n", "8064 2765\n", "1000000 999998\n", "963254 219217\n", "94 17\n", "54 47\n", "4 1\n", "8664 7467\n", "52 35\n", "873734 740943\n", "8434 1533\n", "69 16\n", "773361 408936\n", "821587 272623\n", "89 66...
You are given two integers n and k. You need to construct k regular polygons having same [circumcircle](https://en.wikipedia.org/wiki/Circumscribed_circle), with distinct number of sides l between 3 and n. <image> Illustration for the first example. You can rotate them to minimize the total number of distinct point...
{ "inputs": [ "3 9", "3 0", "3 -1", "3 4", "3 1", "6 4", "2 4", "2 3", "2 5", "1 2", "1 5", "5 9", "2 8", "1 3", "2 2", "9 9", "4 8", "1 6", "1 7", "2 7", "2 13", "2 10", "1 10", "3 14", "3 5", "2 6", "5 16", ...
B: Ebi-chan and Integer Sequences- problem Ebi-chan likes sequences. I especially like arithmetic progressions. This time, I decided to create a sequence that meets the following conditions. * Arithmetic progression of length n * When the i-th element of the sequence is defined as s_i, all s_i (1 \ leq i \ leq n) ar...
{ "inputs": [ "2\n13\n11\n\nSAMPLE", "2\n13\n4\n\nSAMPLE", "2\n13\n7\n\nSLPMAE", "2\n2\n7\n\nECMPLS", "2\n2\n8\n\nSLPMAE", "2\n13\n4\n\nEAMPLS", "2\n13\n8\n\nEAMPLS", "2\n13\n8\n\nSLPMAE", "2\n4\n7\n\nSLPMAE", "2\n13\n11\n\nELPMAS", "2\n13\n4\n\nSAMPEL", "2\n13\n4\n\nEA...
a number can be said dual prime. if the number is prime and the sum of digits of the number is also a prime number. If a number is dual prime then print YES else print NO SAMPLE INPUT 2 13 11 SAMPLE OUTPUT NO YES
{ "inputs": [ "5\n\nSAMPLE", "5", "5\n\nMASPLE", "5\n\nELPSAM", "5\n\nELPSBM", "5\n\nELPSBL", "5\n\nLEPSBL", "5\n\nMEPSBL", "5\n\nLBSPEM", "5\n\nLBTPEM", "5\n\nLCTPEM", "5\n\nLMTPEC", "5\n\nLMTPFC", "5\n\nCFPTML", "5\n\nCFPLMT", "5\n\nCFPLNT", "5\n\n...
The penultimate task involved the calculation of the typical Fibonacci sequence up to the nth term. Input – single integer n Output – Fibonacci sequence up to the nth term, all terms on a new line SAMPLE INPUT 5 SAMPLE OUTPUT 1 1 2 3 5
{ "inputs": [ "2\n5 10\n3 4 6 1 9\n3 2\n1 3 4" ], "outputs": [ "1\n0" ] }
An established group of scientists are working on finding solution to NP hard problems. They claim Subset Sum as an NP-hard problem. The problem is to determine whether there exists a subset of a given set S whose sum is a given number K. You are a computer engineer and you claim to solve this problem given that all...