dataset
stringclasses
1 value
question
stringlengths
29
13k
exe_method
stringclasses
1 value
solutions
null
task_id
int64
0
5.07k
test_time_limit
int64
1
1
example_input
listlengths
0
5
example_output
listlengths
0
5
test_input
listlengths
1
10
test_output
listlengths
1
10
CodeContests
SKIT's Chemistry Department found some liquid containing a precious chemical which can be separated out of the liquid using centrifugation. This liquid need to be centrifuged for 5 minutes continuously after that some another facilitating chemical is mixed in the liquid and it is again centrifuged for 5 minutes. It is...
stdin
null
1,193
1
[ "2\n2 3\n3 4\n\nSAMPLE\n" ]
[ "15\n15\n" ]
[ "40\n2 3\n3 4\n3 2\n100 0\n3 8\n925 945\n303 919\n493 820\n23 420\n750 597\n11 206\n56 808\n367 734\n1 1\n1 0\n1000 1\n1000 0\n1 1000\n619 932\n840 312\n525 620\n1000 1000\n999 1000\n566 962\n73 522\n224 410\n500 1000\n160 874\n113 454\n517 805\n20 652\n6 64\n24 69\n475 652\n442 507\n228 508\n499 1000\n501 1000\n50...
[ "15\n15\n10\n0\n30\n15\n35\n20\n185\n10\n190\n145\n20\n10\n0\n10\n0\n10000\n20\n10\n15\n10\n15\n20\n75\n20\n20\n55\n45\n20\n330\n110\n30\n15\n15\n25\n25\n20\n20\n15\n", "15\n20\n", "15\n15\n10\n0\n30\n15\n35\n20\n185\n10\n190\n145\n20\n10\n0\n10\n0\n10000\n20\n10\n15\n10\n15\n20\n75\n20\n20\n55\n45\n20\n330\n11...
CodeContests
Problem Lahuy had no time off and was free, and somehow wanted to eat donuts, so he decided to go around the store and buy donuts. There is one donut shop in each city, and all donut shops are closed on odd days. Lahuy has a taste for donuts, so the degree of satisfaction you get depends on the store. So Lahuy decided...
stdin
null
4,878
1
[ "2 1\n1 2\n0 1\n", "5 5\n1 1 1 1 1\n0 1\n1 2\n2 3\n3 0\n3 4\n", "4 4\n1 1 1 1\n0 1\n1 2\n2 0\n2 3\n" ]
[ "1\n", "3\n", "4\n" ]
[ "5 5\n1 1 1 1 1\n0 1\n1 2\n2 3\n3 0\n3 3\n", "4 4\n1 1 2 1\n0 1\n1 2\n2 0\n1 3\n", "4 1\n0 1 2 1\n0 1\n1 2\n2 0\n1 3\n", "2 1\n1 0\n0 1\n", "2 1\n2 0\n0 1\n", "4 4\n2 1 1 1\n0 1\n0 2\n2 0\n2 3\n", "4 4\n0 1 4 1\n0 1\n1 2\n2 0\n1 3\n", "4 4\n1 1 1 1\n0 1\n1 2\n2 0\n1 3\n", "4 4\n0 1 2 1\n0 1\n1 2\n2 ...
[ "4\n", "5\n", "0\n", "1\n", "2\n", "3\n", "6\n", "4\n", "4\n", "0\n" ]
CodeContests
It was an era when magic still existed as a matter of course. A clan of magicians lived on a square-shaped island created by magic. At one point, a crisis came to this island. The empire has developed an intercontinental ballistic missile and aimed it at this island. The magic of this world can be classified into eart...
stdin
null
309
1
[ "4 4 1\n1 0\n0 1\n-1 0\n0 -1\n5 6 2\n1 1\n4 4\n2 -4\n-4 2\n1 5\n0 0 0\n" ]
[ "1.000000000\n6.797434948\n" ]
[ "4 4 1\n1 0\n0 1\n-1 0\n0 -1\n5 6 2\n1 1\n4 8\n2 -4\n-4 2\n1 5\n0 0 0\n", "4 4 1\n0 0\n0 1\n-1 -1\n0 -1\n5 6 2\n1 1\n4 8\n2 -4\n-4 2\n1 5\n0 -1 0\n", "4 4 1\n0 0\n0 1\n-1 -1\n-1 -1\n5 6 2\n1 1\n4 8\n2 -4\n-4 0\n1 5\n0 -1 0\n", "4 4 1\n1 0\n0 1\n-1 0\n0 -1\n5 6 2\n1 1\n4 8\n2 -4\n-2 2\n1 5\n0 0 0\n", "4 4 1\...
[ "0.9999996983\n8.1961520337\n", "1.4999997802\n8.1961520337\n", "1.4999997802\n7.7320507674\n", "0.9999996983\n7.7320505443\n", "1.4999997802\n8.1961520487\n", "1.4999997802\n5.8301267417\n", "1.4999997802\n7.7320505599\n", "1.4999997802\n8.2320503490\n", "1.4999997802\n8.1961521965\n", "0.9999996...
CodeContests
During a voyage of the starship Hakodate-maru (see Problem A), researchers found strange synchronized movements of stars. Having heard these observations, Dr. Extreme proposed a theory of "super stars". Do not take this term as a description of actors or singers. It is a revolutionary theory in astronomy. According to...
stdin
null
4,869
1
[ "4\n10.00000 10.00000 10.00000\n20.00000 10.00000 10.00000\n20.00000 20.00000 10.00000\n10.00000 20.00000 10.00000\n4\n10.00000 10.00000 10.00000\n10.00000 50.00000 50.00000\n50.00000 10.00000 50.00000\n50.00000 50.00000 10.00000\n0\n" ]
[ "7.07107\n34.64102\n" ]
[ "4\n10.00000 10.00000 10.00000\n20.00000 10.00000 10.00000\n20.00000 20.00000 10.00000\n10.00000 20.00000 10.00000\n4\n10.00000 10.063097698119668 10.00000\n10.00000 50.00000 50.00000\n50.00000 10.00000 50.00000\n50.00000 50.00000 10.00000\n0\n", "4\n10.00000 10.00000 10.00000\n20.00000 10.00000 10.00000\n20.0000...
[ "7.071068\n34.631926\n", "7.071068\n34.735589\n", "7.071068\n34.847332\n", "7.071068\n34.749027\n", "7.335041\n34.749027\n", "7.335041\n34.635882\n", "7.335041\n34.590402\n", "7.335041\n34.697096\n", "7.335041\n34.761707\n", "7.335041\n34.804294\n" ]
CodeContests
Aka Beko, trying to escape from 40 bandits, got lost in the city of A. Aka Beko wants to go to City B, where the new hideout is, but the map has been stolen by a bandit. Kobborg, one of the thieves, sympathized with Aka Beko and felt sorry for him. So I secretly told Aka Beko, "I want to help you go to City B, but I w...
stdin
null
580
1
[ "0100\n0101\n10100\n01000\n0101011\n0011\n011111\n#\n" ]
[ "Yes\nNo\nYes\nNo\nYes\nNo\nYes\n" ]
[ "0100\n0101\n10100\n01000\n0101011\n0011\n011110\n#\n", "0100\n1101\n10100\n11000\n0001011\n0011\n011110\n#\n", "0100\n1101\n10000\n10000\n0001011\n0011\n011110\n#\n", "0100\n0101\n10100\n10001\n0011011\n1011\n011110\n#\n", "0100\n0100\n10100\n10001\n0011011\n1001\n011110\n#\n", "0100\n1101\n10100\n10000\...
[ "Yes\nNo\nYes\nNo\nYes\nNo\nNo\n", "Yes\nNo\nYes\nNo\nNo\nNo\nNo\n", "Yes\nNo\nNo\nNo\nNo\nNo\nNo\n", "Yes\nNo\nYes\nNo\nNo\nYes\nNo\n", "Yes\nYes\nYes\nNo\nNo\nNo\nNo\n", "Yes\nNo\nYes\nNo\nNo\nNo\nYes\n", "Yes\nNo\nNo\nNo\nNo\nYes\nNo\n", "Yes\nYes\nNo\nNo\nNo\nNo\nNo\n", "Yes\nYes\nYes\nNo\nNo\nN...
CodeContests
In a factory, there are N robots placed on a number line. Robot i is placed at coordinate X_i and can extend its arms of length L_i in both directions, positive and negative. We want to remove zero or more robots so that the movable ranges of arms of no two remaining robots intersect. Here, for each i (1 \leq i \leq N...
stdin
null
2,996
1
[ "5\n10 1\n2 1\n4 1\n6 1\n8 1\n", "2\n8 20\n1 10\n", "4\n2 4\n4 3\n9 3\n100 5\n" ]
[ "5\n", "1\n", "3\n" ]
[ "5\n10 1\n2 2\n4 1\n6 1\n8 1\n", "2\n8 20\n1 13\n", "4\n2 4\n4 3\n14 3\n100 5\n", "4\n4 16\n4 3\n6 2\n101 5\n", "5\n18 1\n2 1\n4 1\n6 1\n8 1\n", "5\n10 1\n2 2\n4 1\n6 1\n8 2\n", "2\n12 20\n1 13\n", "4\n4 4\n4 3\n14 3\n100 5\n", "2\n12 14\n1 13\n", "4\n4 4\n4 3\n28 3\n100 5\n" ]
[ "4\n", "1\n", "3\n", "2\n", "5\n", "3\n", "1\n", "3\n", "1\n", "3\n" ]
CodeContests
We have an H \times W grid, where each square is painted white or black in the initial state. Given are strings A_1, A_2, ..., A_H representing the colors of the squares in the initial state. For each pair (i, j) (1 \leq i \leq H, 1 \leq j \leq W), if the j-th character of A_i is `.`, the square at the i-th row and j-t...
stdin
null
1,086
1
[ "3 3\n...\n...\n...\n", "2 2\n#.\n.#\n", "2 4\n...\n...#\n", "6 7\n.......\n.......\n.#.....\n..#....\n.#.#...\n.......\n", "2 2\n.\n.#\n" ]
[ "230\n", "15\n", "150\n", "203949910\n", "15\n" ]
[ "3 2\n...\n...\n...\n", "2 1\n#.\n.#\n", "1 4\n...\n...#\n", "2 2\n..-\n...\n...\n", "4 3\n...\n...\n...\n", "2 8\n...\n...#\n", "6 2\n.......\n.......\n.#.....\n..#....\n.#.#...\n.......\n", "4 2\n...\n./.#\n", "6 1\n.......\n.......\n.#.....\n..#....\n.#.#/..\n.......\n", "1 1\n/..\n...\n...\n" ...
[ "46\n", "4\n", "16\n", "14\n", "1066\n", "12866\n", "1394\n", "146\n", "64\n", "2\n" ]
CodeContests
You are given 3 points - middles of the sides of some triangle. Find coordinates of the triangle vertices. Input Input has 3 lines with 2 space-separated reals each - coordinates of the middles of the sides. Output Output 3 lines with 2 space-separated reals - coordinates of the triangle vertices. Each number should...
stdin
null
1,313
1
[ "5.00 3.00\n4.0 4.0\n5.0 5.000\n\nSAMPLE\n" ]
[ "4.0000 2.0000\n4.0000 6.0000\n6.0000 4.0000\n" ]
[ "1.0 1.0\n2.0 2.9\n3.0 2.333445033279755\n", "5.00 3.00\n4.0 4.850336703409528\n5.0 5.000\n\nSAMPLE\n", "1.0 1.90992798442994\n2.0 2.9\n3.0 2.333445033279755\n", "5.788441616816264 3.00\n4.0 4.850336703409528\n5.0 5.000\n\nSAMPLE\n", "1.0 1.90992798442994\n2.0 2.9\n3.3148098329018456 2.333445033279755\n", ...
[ "0.0000 1.5666\n2.0000 0.4334\n4.0000 4.2334\n", "4.0000 2.8503\n4.0000 6.8503\n6.0000 3.1497\n", "0.0000 2.4765\n2.0000 1.3434\n4.0000 3.3235\n", "3.2116 6.8503\n4.7884 2.8503\n6.7884 3.1497\n", "-0.3148 2.4765\n2.3148 1.3434\n4.3148 3.3235\n", "3.2116 7.2320\n4.7884 3.2320\n6.7884 2.7680\n", "-0.3148 ...
CodeContests
You are given an array A1,A2...AN. You have to tell how many pairs (i, j) exist such that 1 ≤ i < j ≤ N and Ai XOR Aj is odd. Input and Output First line T, the number of testcases. Each testcase: first line N, followed by N integers in next line. For each testcase, print the required answer in one line. ...
stdin
null
3,149
1
[ "2\n3\n1 2 3\n4\n1 2 3 4\n\nSAMPLE\n" ]
[ "2\n4\n" ]
[ "2\n3\n1 2 3\n4\n1 2 3 2\n\nSAMPLE\n", "2\n3\n1 2 -2\n4\n2 2 3 2\n\nASMPLE\n", "2\n3\n0 2 2\n4\n1 4 3 4\n\nSAMPLE\n", "2\n3\n0 2 2\n4\n2 4 3 4\n\nSAMPLE\n", "2\n3\n1 2 -2\n4\n2 2 2 2\n\nASMPLE\n", "2\n3\n0 0 0\n4\n2 6 0 2\n\nELPMSA\n", "2\n3\n1 2 0\n4\n1 2 3 2\n\nSAMPLE\n", "2\n3\n1 2 0\n4\n1 2 3 2\n\...
[ "2\n4\n", "2\n3\n", "0\n4\n", "0\n3\n", "2\n0\n", "0\n0\n", "2\n4\n", "2\n4\n", "2\n4\n", "2\n4\n" ]
CodeContests
Given is a string S of length N. Find the maximum length of a non-empty string that occurs twice or more in S as contiguous substrings without overlapping. More formally, find the maximum positive integer len such that there exist integers l_1 and l_2 ( 1 \leq l_1, l_2 \leq N - len + 1 ) that satisfy the following: ...
stdin
null
4,779
1
[ "13\nstrangeorange\n", "2\nxy\n", "5\nababa\n" ]
[ "5\n", "0\n", "2\n" ]
[ "13\nstrangeoranfe\n", "2\nwy\n", "5\n`baba\n", "5\nabac`\n", "13\nefnaroegnarts\n", "2\nvy\n", "5\nabab`\n", "13\nefnarotgnares\n", "2\nyx\n", "13\nserangtoranfe\n" ]
[ "3\n", "0\n", "2\n", "1\n", "3\n", "0\n", "2\n", "3\n", "0\n", "3\n" ]
CodeContests
Print a sequence a_1, a_2, ..., a_N whose length is N that satisfies the following conditions: * a_i (1 \leq i \leq N) is a prime number at most 55 555. * The values of a_1, a_2, ..., a_N are all different. * In every choice of five different integers from a_1, a_2, ..., a_N, the sum of those integers is a composite n...
stdin
null
2,129
1
[ "6\n", "8\n", "5\n" ]
[ "2 3 5 7 11 13\n", "2 5 7 13 19 37 67 79\n", "3 5 7 11 31\n" ]
[ "10\n", "14\n", "12\n", "20\n", "27\n", "13\n", "50\n", "17\n", "1\n", "2\n" ]
[ "11 31 41 61 71 101 131 151 181 191\n", "11 31 41 61 71 101 131 151 181 191 211 241 251 271\n", "11 31 41 61 71 101 131 151 181 191 211 241\n", "11 31 41 61 71 101 131 151 181 191 211 241 251 271 281 311 331 401 421 431\n", "11 31 41 61 71 101 131 151 181 191 211 241 251 271 281 311 331 401 421 431 461 491 ...
CodeContests
Your task is to develop a tiny little part of spreadsheet software. Write a program which adds up columns and rows of given table as shown in the following figure: <image> Input The input consists of several datasets. Each dataset consists of: n (the size of row and column of the given table) 1st row of the tab...
stdin
null
4,351
1
[ "4\n52 96 15 20\n86 22 35 45\n45 78 54 36\n16 86 74 55\n4\n52 96 15 20\n86 22 35 45\n45 78 54 36\n16 86 74 55\n0\n" ]
[ "52 96 15 20 183\n 86 22 35 45 188\n 45 78 54 36 213\n 16 86 74 55 231\n 199 282 178 156 815\n 52 96 15 20 183\n 86 22 35 45 188\n 45 78 54 36 213\n 16 86 74 55 231\n 199 282 178 156 815\n" ]
[ "4\n52 96 15 20\n86 22 35 45\n45 78 54 36\n10 86 74 55\n4\n52 96 15 20\n86 22 35 45\n45 78 54 36\n16 86 74 55\n0\n", "4\n52 26 15 20\n86 22 35 45\n45 78 54 36\n10 86 74 55\n4\n52 96 15 20\n86 22 35 45\n45 78 54 36\n16 86 74 55\n0\n", "4\n52 26 15 20\n143 22 35 45\n45 78 54 36\n10 86 74 55\n4\n52 96 15 20\n86 22...
[ "52 96 15 20 183\n 86 22 35 45 188\n 45 78 54 36 213\n 10 86 74 55 225\n 193 282 178 156 809\n 52 96 15 20 183\n 86 22 35 45 188\n 45 78 54 36 213\n 16 86 74 55 231\n 199 282 178 156 815\n", "52 26 15 20 113\n 86 22 35 ...
CodeContests
This is a story in a depopulated area. In this area, houses are sparsely built along a straight road called Country Road. Until now, there was no electricity in this area, but this time the government will give us some generators. You can install the generators wherever you like, but in order for electricity to be supp...
stdin
null
1,902
1
[ "6\n5 2\n10 30 40 70 100\n7 3\n3 6 10 17 21 26 28\n1 1\n100\n2 1\n0 1000000\n3 5\n30 70 150\n6 4\n0 10 20 30 40 50\n" ]
[ "60\n13\n0\n1000000\n0\n20\n" ]
[ "6\n5 2\n10 30 40 70 100\n7 3\n3 4 10 17 21 26 28\n1 1\n100\n2 1\n0 1000000\n3 5\n30 70 150\n6 4\n0 10 20 30 40 50\n", "6\n5 2\n10 30 40 70 100\n7 3\n3 5 10 17 21 26 28\n1 1\n100\n2 1\n0 1000000\n3 5\n30 70 211\n6 4\n0 10 20 30 40 50\n", "6\n5 2\n10 30 40 70 100\n7 3\n3 6 10 17 21 26 28\n1 1\n100\n2 1\n0 100000...
[ "60\n12\n0\n1000000\n0\n20\n", "60\n13\n0\n1000000\n0\n20\n", "60\n13\n0\n1000000\n0\n13\n", "51\n12\n0\n1000000\n0\n20\n", "-5\n12\n0\n1000000\n0\n20\n", "60\n13\n0\n1000000\n0\n10\n", "51\n12\n0\n1000000\n0\n17\n", "-5\n12\n0\n999999\n0\n20\n", "60\n-1\n0\n1000000\n0\n10\n", "-5\n13\n0\n999999\n...
CodeContests
You are given integers N and K. Find the number of triples (a,b,c) of positive integers not greater than N such that a+b,b+c and c+a are all multiples of K. The order of a,b,c does matter, and some of them can be the same. Constraints * 1 \leq N,K \leq 2\times 10^5 * N and K are integers. Input Input is given from ...
stdin
null
3,314
1
[ "31415 9265\n", "3 2\n", "35897 932\n", "5 3\n" ]
[ "27\n", "9\n", "114191\n", "1\n" ]
[ "31415 12506\n", "35897 446\n", "4 3\n", "2970 12506\n", "35897 490\n", "35897 92\n", "62976 92\n", "101525 92\n", "101525 162\n", "50082 162\n" ]
[ "35\n", "1024000\n", "1\n", "0\n", "778034\n", "118638000\n", "641432629\n", "2687492591\n", "491806259\n", "59007258\n" ]
CodeContests
Based on the information of the time when study started and the time when study ended, check whether the total time studied in one day is t or more, and if not, create a program to find the shortage time. Time is one unit per hour, and minutes and seconds are not considered. The time is expressed in 24-hour notation in...
stdin
null
1,535
1
[ "10\n3\n6 11\n12 15\n18 22\n14\n2\n6 11\n13 20\n0\n" ]
[ "OK\n2\n" ]
[ "10\n3\n6 11\n12 15\n18 22\n14\n2\n6 14\n13 20\n0\n", "10\n3\n8 11\n12 19\n18 38\n14\n2\n6 14\n5 6\n0\n", "10\n3\n8 11\n12 19\n18 38\n8\n2\n6 6\n5 6\n0\n", "10\n3\n6 11\n12 15\n18 22\n14\n2\n6 1\n13 20\n0\n", "10\n3\n6 11\n12 15\n34 22\n14\n2\n6 14\n13 20\n0\n", "10\n3\n8 11\n12 19\n18 9\n8\n2\n6 6\n5 6\n...
[ "OK\nOK\n", "OK\n5\n", "OK\n7\n", "OK\n12\n", "14\nOK\n", "9\n7\n", "2\n12\n", "4\nOK\n", "OK\n1\n", "4\n5\n" ]
CodeContests
We have N sticks with negligible thickness. The length of the i-th stick is A_i. Snuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides. Find the maximum possible area of the rectangle. Constraints * 4 \leq N \leq 10^5 * 1 \leq A_i \leq ...
stdin
null
4,976
1
[ "10\n3 3 3 3 4 4 4 5 5 5\n", "6\n3 1 2 4 2 1\n", "4\n1 2 3 4\n" ]
[ "20\n", "2\n", "0\n" ]
[ "10\n3 3 3 3 4 4 2 5 5 5\n", "6\n3 1 2 4 2 2\n", "6\n3 2 2 4 2 2\n", "6\n3 2 2 4 3 2\n", "10\n3 3 6 3 4 4 1 6 5 5\n", "10\n3 3 6 3 4 3 1 6 5 6\n", "6\n3 4 2 3 4 3\n", "10\n3 3 6 6 4 3 1 6 3 6\n", "10\n3 2 8 6 4 0 1 8 3 10\n", "6\n1 -1 1 7 8 7\n" ]
[ "20\n", "0\n", "4\n", "6\n", "30\n", "18\n", "12\n", "36\n", "24\n", "7\n" ]
CodeContests
Andi and Bob were friends since childhood days. But, as they grew up Bob started behaving weird and this used to irritate Andi. Once, while Andi took a break after typing a large program Bob came from nowhere and swapped some alphabet keys on Andi's keyboard. Andi got very angry on seeing this and decided to end their...
stdin
null
2,350
1
[ "1\nW H\nWelloHorld\n\nSAMPLE\n" ]
[ "HelloWorld\n" ]
[ "1\nW H\nWelloHoqld\n\nSAMPLE\n", "1\nW H\nWeHloloqld\n\nELPMAS\n", "1\nW H\nWeHloldqlo\n\nELPMAS\n", "1\nW H\nXeHloldqlo\n\nSLPMAE\n", "1\nW H\nqeHloldXlo\n\nEAMPLS\n", "1\nV H\nqeHloldXlo\n\nE@MPLS\n", "1\nV I\nqeHloldXlo\n\nE@MPLS\n", "1\nV I\nqeHlodlXlo\n\nE@MPLS\n", "1\nV I\nolXldolHeq\n\nE@MPL...
[ "HelloWoqld\n", "HeWloloqld\n", "HeWloldqlo\n", "XeWloldqlo\n", "qeWloldXlo\n", "qeVloldXlo\n", "qeHloldXlo\n", "qeHlodlXlo\n", "olXldolHeq\n", "olXldomHeq\n" ]
CodeContests
After decrypting the code Enigma crew came to know that there are N locations where bombs has been planted. X1, X2 …. Xn are the N locations. Among this locations, one X location is the central hub which control all the other Xn-1 location. 1 or more than 1 signal is send to N locations. The decrypted code simplified ...
stdin
null
521
1
[ "10\n1 3 5 17 21 17 5 11 10 40\n\nSAMPLE\n" ]
[ "17\n2\n" ]
[ "10\n1 3 5 17 21 17 5 11 7 40\n\nSAMPLE\n", "10\n1 3 5 17 19 17 5 11 1 38\n\nSAMPLE\n", "10\n2 3 5 17 21 29 5 16 7 38\n\nSAMPLE\n", "10\n1 3 5 17 19 5 5 19 1 38\n\nSAMPLD\n", "10\n1 0 4 4 19 5 5 9 1 23\n\nSAMPLE\n", "10\n1 3 5 32 21 17 5 22 4 18\n\nSAMPME\n", "10\n1 3 5 17 19 5 2 10 1 41\n\nSAMPLD\n", ...
[ "17\n2\n", "19\n1\n", "29\n1\n", "19\n2\n", "23\n1\n", "17\n1\n", "41\n1\n", "31\n1\n", "11\n1\n", "37\n1\n" ]
CodeContests
There are N towns located in a line, conveniently numbered 1 through N. Takahashi the merchant is going on a travel from town 1 to town N, buying and selling apples. Takahashi will begin the travel at town 1, with no apple in his possession. The actions that can be performed during the travel are as follows: * Move: ...
stdin
null
3,998
1
[ "5 8\n50 30 40 10 20\n", "10 100\n7 10 4 5 9 3 6 8 2 1\n", "3 2\n100 50 200\n" ]
[ "2\n", "2\n", "1\n" ]
[ "5 8\n21 30 40 10 20\n", "10 100\n7 10 4 5 9 3 6 8 1 1\n", "3 2\n100 78 200\n", "5 8\n21 30 40 0 20\n", "3 3\n100 78 200\n", "5 8\n21 30 24 0 20\n", "3 3\n100 38 200\n", "3 5\n100 38 200\n", "3 8\n100 38 200\n", "3 0\n100 50 200\n" ]
[ "1\n", "2\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n" ]
CodeContests
Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order. From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized. If there are multiple pairs that maximize the value, any of them is accepted. Constraints * 2 ...
stdin
null
3,597
1
[ "5\n6 9 4 2 11\n", "2\n100 0\n" ]
[ "11 6\n", "100 0\n" ]
[ "5\n6 9 1 2 11\n", "5\n6 9 1 2 20\n", "5\n3 9 4 2 11\n", "2\n010 0\n", "5\n6 9 1 2 16\n", "5\n10 9 1 4 20\n", "2\n001 0\n", "5\n6 9 1 2 0\n", "5\n3 9 4 0 9\n", "2\n101 0\n" ]
[ "11 6\n", "20 9\n", "11 4\n", "10 0\n", "16 9\n", "20 10\n", "1 0\n", "9 6\n", "9 4\n", "101 0\n" ]
CodeContests
Find the least common multiple (LCM) of given n integers. Constraints * 2 ≤ n ≤ 10 * 1 ≤ ai ≤ 1000 * Product of given integers ai(i = 1, 2, ... n) does not exceed 231-1 Input n a1 a2 ... an n is given in the first line. Then, n integers are given in the second line. Output Print the least common multiple of th...
stdin
null
3,536
1
[ "4\n1 2 3 5\n", "3\n3 4 6\n" ]
[ "30\n", "12\n" ]
[ "4\n1 2 5 5\n", "3\n3 4 3\n", "4\n1 2 5 7\n", "3\n3 7 3\n", "4\n1 2 1 7\n", "3\n3 10 3\n", "3\n3 13 3\n", "4\n1 2 2 11\n", "3\n6 13 3\n", "3\n4 13 3\n" ]
[ "10\n", "12\n", "70\n", "21\n", "14\n", "30\n", "39\n", "22\n", "78\n", "156\n" ]
CodeContests
Roman has no idea, why this problem is called Stone. He also has no idea on how to solve the followong problem: given array of N integers A and a number K. During a turn the maximal value over all Ai is chosen, let's call it MAX. Then Ai = MAX - Ai is done for every 1 <= i <= N. Help Roman to find out how will the arra...
stdin
null
3,781
1
[ "4 1\n5 -1 7 0\n" ]
[ "2 8 0 7\n" ]
[ "4 1\n5 -1 7 1\n", "4 1\n5 -1 7 2\n", "4 0\n5 -1 7 2\n", "4 0\n5 -1 7 4\n", "4 0\n5 -1 7 0\n", "4 0\n5 -1 10 0\n", "4 0\n5 -1 13 0\n", "4 1\n5 0 7 0\n", "4 1\n5 0 7 1\n", "4 1\n5 -1 7 4\n" ]
[ "2 8 0 6\n", "2 8 0 5\n", "5 -1 7 2\n", "5 -1 7 4\n", "5 -1 7 0\n", "5 -1 10 0\n", "5 -1 13 0\n", "2 7 0 7\n", "2 7 0 6\n", "2 8 0 3\n" ]
CodeContests
Takahashi loves the number 7 and multiples of K. Where is the first occurrence of a multiple of K in the sequence 7,77,777,\ldots? (Also see Output and Sample Input/Output below.) If the sequence contains no multiples of K, print `-1` instead. Constraints * 1 \leq K \leq 10^6 * K is an integer. Input Input is giv...
stdin
null
1,281
1
[ "2\n", "999983\n", "101\n" ]
[ "-1\n", "999982\n", "4\n" ]
[ "3\n", "1803846\n", "1\n", "1041437\n", "958033\n", "9\n", "172483\n", "2243343\n", "187013\n", "27\n" ]
[ "3\n", "-1\n", "1\n", "245040\n", "25740\n", "9\n", "5032\n", "747780\n", "21758\n", "27\n" ]
CodeContests
problem In Ikatta, the SNS used by AOR Ika-chan, posts are called tweets. And in squid, there is a concern that visibility will deteriorate if there are many replies to tweets, so when a tweet meets any of the following rules, the tweet will be displayed on the screen. ing. * Rule 1. No reply to any tweet * Rule 2. ...
stdin
null
2,580
1
[ "6 3\n0\n0\n2\n3\n4\n5\n" ]
[ "5\n" ]
[ "6 6\n0\n0\n2\n3\n4\n5\n", "2 9\n0\n0\n2\n3\n4\n5\n", "4 3\n0\n0\n2\n3\n4\n5\n", "4 1\n0\n0\n2\n3\n4\n5\n", "5 25\n0\n1\n0\n3\n1\n17\n", "0 22\n0\n1\n1\n1\n1\n6\n", "1 16\n0\n0\n2\n5\n4\n2\n", "12 3\n0\n0\n0\n3\n4\n5\n", "7 10\n0\n0\n2\n3\n1\n0\n", "11 4\n0\n1\n2\n2\n4\n4\n" ]
[ "6\n", "2\n", "4\n", "3\n", "5\n", "0\n", "1\n", "12\n", "7\n", "11\n" ]
CodeContests
Andrii is good in Math, but not in Programming. He is asking you to solve following problem: Given an integer number N and two sets of integer A and B. Let set A contain all numbers from 1 to N and set B contain all numbers from N + 1 to 2N. Multiset C contains all sums a + b such that a belongs to A and b belongs to B...
stdin
null
3,820
1
[ "3 5\n6\n2\n9\n7\n5\n" ]
[ "2\n0\n1\n3\n1\n" ]
[ "3 5\n6\n2\n9\n10\n5\n", "3 5\n6\n2\n9\n7\n0\n", "3 5\n6\n2\n8\n7\n0\n", "3 5\n6\n1\n8\n10\n9\n", "3 5\n5\n2\n8\n10\n9\n", "3 5\n5\n2\n9\n7\n0\n", "3 5\n6\n1\n9\n6\n5\n", "3 5\n6\n2\n8\n5\n0\n", "3 5\n3\n2\n8\n10\n9\n", "6 5\n5\n2\n9\n7\n0\n" ]
[ "2\n0\n1\n0\n1\n", "2\n0\n1\n3\n0\n", "2\n0\n2\n3\n0\n", "2\n0\n2\n0\n1\n", "1\n0\n2\n0\n1\n", "1\n0\n1\n3\n0\n", "2\n0\n1\n2\n1\n", "2\n0\n2\n1\n0\n", "0\n0\n2\n0\n1\n", "0\n0\n2\n0\n0\n" ]
CodeContests
You are given a set of circles C of a variety of radii (radiuses) placed at a variety of positions, possibly overlapping one another. Given a circle with radius r, that circle may be placed so that it encircles all of the circles in the set C if r is large enough. There may be more than one possible position of the ci...
stdin
null
2,297
1
[ "1 10\n5 5 7\n2 12\n5 5 7\n8 6 3\n3 10\n3 11 2\n2 1 1\n2 16 3\n3 15\n-5 2 5\n9 2 9\n5 8 6\n3 38\n-25 -10 8\n30 5 7\n-3 35 11\n3 39\n-25 -10 8\n30 5 7\n-3 35 11\n3 800\n-400 400 2\n300 300 1\n300 302 1\n3 800\n400 -400 2\n300 300 1\n307 300 3\n8 147\n130 80 12\n130 -40 12\n-110 80 12\n-110 -40 12\n70 140 12\n70 -100...
[ "81.68140899333463\n106.81415022205297\n74.11215318612639\n108.92086846105579\n0.0\n254.85616536128433\n8576.936716409238\n8569.462129048667\n929.1977057481128\n4181.124698202453\n505.09134735536804\n0.0\n46.82023824234038\n65.66979416387915\n50.990642291793506\n4181.124698202453\n158.87951420768937\n" ]
[ "1 10\n5 5 7\n2 12\n5 5 7\n8 6 3\n3 10\n3 11 2\n2 1 1\n2 16 3\n3 15\n-5 2 5\n9 2 9\n5 8 6\n3 38\n-25 -10 8\n30 5 7\n-3 35 11\n3 39\n-25 -10 8\n30 5 7\n-3 35 11\n3 800\n-400 400 2\n300 300 1\n300 302 1\n3 800\n400 -400 2\n300 300 1\n307 300 3\n8 147\n130 80 12\n130 -40 12\n-110 80 12\n-110 -40 12\n70 140 12\n70 -100...
[ "81.681409\n106.814150\n74.112153\n108.920868\n0.000000\n254.856165\n8576.936716\n8569.462129\n929.197706\n4003.160828\n505.091347\n0.000000\n46.820238\n65.669794\n50.990642\n4181.124698\n158.879514\n", "81.681409\n106.814150\n74.112153\n108.920868\n0.000000\n254.856165\n8576.936716\n8569.462129\n929.472048\n4003...
CodeContests
You had long wanted a spaceship, and finally you bought a used one yesterday! You have heard that the most difficult thing on spaceship driving is to stop your ship at the right position in the dock. Of course you are no exception. After a dozen of failures, you gave up doing all the docking process manually. You began...
stdin
null
3,569
1
[ "1\n3\n2 4 6\n4\n10 100\n2 3\n10 6\n7 6\n" ]
[ "crash\ntry again\ngood 1.000\nperfect\n" ]
[ "1\n3\n2 1 6\n4\n10 100\n2 3\n10 6\n7 6\n", "1\n3\n2 0 6\n4\n10 100\n2 3\n10 6\n7 6\n", "1\n3\n2 4 6\n4\n10 100\n2 3\n10 4\n7 6\n", "1\n3\n2 1 6\n4\n10 100\n2 3\n10 12\n7 6\n", "1\n3\n1 4 6\n4\n10 100\n2 3\n10 4\n7 6\n", "1\n3\n2 1 6\n4\n10 100\n2 3\n10 12\n7 7\n", "1\n1\n1 2 6\n4\n10 100\n2 3\n10 6\n7 ...
[ "crash\ntry again\nperfect\ngood 4.000\n", "crash\ntry again\ngood 1.000\ngood 4.000\n", "crash\ntry again\ngood 6.000\nperfect\n", "crash\ntry again\ncrash\ngood 4.000\n", "crash\ntry again\ngood 2.000\ngood 1.000\n", "crash\ntry again\ncrash\ngood 2.500\n", "crash\ncrash\n", "crash\ntry again\ncrash...
CodeContests
Akash is feeling lonely.So he decided to visit his friend's house. His friend's house is located at the distance of K metres from his house.Now,he can take a step of one metre ,two metres or three metres at a time.Can you tell me number of ways of reaching Akash's friend house. As the answer can be large Print answ...
stdin
null
872
1
[ "2\n2\n3\n\nSAMPLE\n" ]
[ "2\n4\n" ]
[ "15\n1\n1\n9\n4\n10\n7\n2\n6\n6\n2\n12\n9\n15\n6\n6\n", "2\n4\n3\n\nSAMPLE\n", "15\n1\n1\n9\n4\n10\n7\n2\n6\n8\n2\n12\n9\n15\n6\n6\n", "15\n1\n1\n9\n4\n10\n7\n4\n6\n8\n2\n12\n9\n15\n6\n6\n", "15\n1\n1\n9\n4\n16\n7\n4\n6\n8\n2\n12\n9\n15\n6\n6\n", "2\n4\n4\n\nTALPLE\n", "15\n1\n1\n9\n4\n16\n7\n4\n6\n8\n2...
[ "1\n1\n149\n7\n274\n44\n2\n24\n24\n2\n927\n149\n5768\n24\n24\n", "7\n4\n", "1\n1\n149\n7\n274\n44\n2\n24\n81\n2\n927\n149\n5768\n24\n24\n", "1\n1\n149\n7\n274\n44\n7\n24\n81\n2\n927\n149\n5768\n24\n24\n", "1\n1\n149\n7\n10609\n44\n7\n24\n81\n2\n927\n149\n5768\n24\n24\n", "7\n7\n", "1\n1\n149\n7\n10609\n...
CodeContests
Halting Problem A unique law is enforced in the Republic of Finite Loop. Under the law, programs that never halt are regarded as viruses. Releasing such a program is a cybercrime. So, you want to make sure that your software products always halt under their normal use. It is widely known that there exists no algorith...
stdin
null
1,457
1
[ "2 0\n5 1 2 1 1\n10 1 3 2 2\n" ]
[ "9\n" ]
[ "2 0\n5 1 2 1 1\n10 1 3 2 0\n", "1 0\n0 0 2 1 2\n10 1 3 2 0\n", "2 0\n5 1 2 1 2\n10 1 3 2 1\n", "0 3\n0 -2 1 1 2\n5 0 5 6 0\n", "2 -1\n0 0 3 1 1\n13 1 3 2 0\n", "2 0\n0 1 2 1 1\n10 1 3 2 0\n", "2 0\n0 0 2 1 1\n10 1 3 2 0\n", "2 0\n0 0 2 1 1\n14 1 3 2 0\n", "2 0\n0 0 2 1 2\n14 1 3 2 0\n", "2 0\n0 0...
[ "-1\n", "1\n", "8\n", "0\n", "2\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n" ]
CodeContests
A wise king declared a new calendar. "Tomorrow shall be the first day of the calendar, that is, the day 1 of the month 1 of the year 1. Each year consists of 10 months, from month 1 through month 10, and starts from a big month. A common year shall start with a big month, followed by small months and big months one aft...
stdin
null
1,022
1
[ "8\n1 1 1\n344 3 1\n696 5 1\n182 9 5\n998 8 7\n344 2 19\n696 4 19\n999 10 20\n" ]
[ "196470\n128976\n59710\n160715\n252\n128977\n59712\n1\n" ]
[ "8\n1 1 1\n344 3 1\n696 5 1\n182 9 5\n998 5 7\n344 2 19\n696 4 19\n999 10 20\n", "8\n1 1 1\n344 3 1\n696 5 1\n182 9 5\n998 5 7\n344 2 26\n696 4 19\n999 10 20\n", "8\n1 1 1\n344 3 1\n696 4 1\n182 9 5\n998 8 7\n344 2 19\n696 4 19\n999 10 20\n", "8\n1 1 1\n344 3 1\n696 5 1\n182 9 5\n998 5 7\n344 3 26\n696 4 19\n...
[ "196470\n128976\n59710\n160715\n311\n128977\n59712\n1\n", "196470\n128976\n59710\n160715\n311\n128970\n59712\n1\n", "196470\n128976\n59730\n160715\n252\n128977\n59712\n1\n", "196470\n128976\n59710\n160715\n311\n128951\n59712\n1\n", "196469\n128976\n59710\n160715\n252\n128977\n59712\n1\n", "196470\n128976\...
CodeContests
The executive chef is trying to bring some competitive spirit into his kitchen. He wants to split the chefs into two teams based on their age - he'll form the young and the old team. To make it fair, he will split them evenly or give the young team one person advantage when there is an odd number of chefs. Ages of all ...
stdin
null
2,503
1
[ "5\n2 3\n1 7\n5 5\n3 1\n8 15\n" ]
[ "3\n4\n5\n4\n9\n" ]
[ "5\n2 3\n1 7\n4 5\n3 1\n8 15\n", "5\n2 3\n1 7\n4 6\n4 1\n8 15\n", "5\n1 3\n1 7\n4 6\n4 1\n8 25\n", "5\n1 3\n1 8\n12 6\n4 1\n5 25\n", "5\n1 3\n1 8\n12 6\n4 0\n5 25\n", "5\n1 3\n1 8\n12 11\n4 0\n5 25\n", "5\n0 3\n0 2\n12 11\n4 0\n5 25\n", "5\n0 2\n0 2\n12 11\n4 0\n5 25\n", "5\n0 2\n0 1\n12 11\n4 0\n5 ...
[ "3\n4\n5\n4\n9\n", "3\n4\n4\n3\n10\n", "3\n4\n4\n3\n20\n", "3\n5\n5\n4\n19\n", "3\n5\n5\n5\n20\n", "3\n5\n0\n0\n25\n", "3\n1\n6\n6\n31\n", "2\n0\n7\n7\n32\n", "2\n1\n8\n8\n33\n", "2\n2\n9\n9\n34\n" ]
CodeContests
Takahashi wants to be a member of some web service. He tried to register himself with the ID S, which turned out to be already used by another user. Thus, he decides to register using a string obtained by appending one character at the end of S as his ID. He is now trying to register with the ID T. Determine whether...
stdin
null
4,341
1
[ "snuke\nsnekee\n", "a\naa\n", "chokudai\nchokudaiz\n" ]
[ "No\n", "Yes\n", "Yes\n" ]
[ "snuke\nsnelee\n", "b\nba\n", "a\nba\n", "choktdai\nchokudaiz\n", "nsuke\nsnelee\n", "choktdai\nbhokudaiz\n", "nuske\nsnelee\n", "b\nab\n", "iadtkohc\nbhokudaiz\n", "nurke\nsnelee\n" ]
[ "No\n", "Yes\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n" ]
CodeContests
There is a tree with N vertices numbered 1 to N. The i-th edge in this tree connects Vertex a_i and Vertex b_i, and the color and length of that edge are c_i and d_i, respectively. Here the color of each edge is represented by an integer between 1 and N-1 (inclusive). The same integer corresponds to the same color, and...
stdin
null
729
1
[ "5 3\n1 2 1 10\n1 3 2 20\n2 4 4 30\n5 2 1 40\n1 100 1 4\n1 100 1 5\n3 1000 3 4\n" ]
[ "130\n200\n60\n" ]
[ "5 3\n1 2 1 10\n1 3 1 20\n2 4 4 30\n5 2 1 40\n1 100 1 4\n1 100 1 5\n3 1000 3 4\n", "5 3\n1 2 1 10\n1 3 1 20\n2 4 4 30\n5 2 1 40\n1 100 1 4\n1 100 1 5\n3 1000 1 4\n", "5 3\n1 2 1 10\n1 3 1 20\n2 4 4 30\n5 2 1 40\n1 100 1 7\n1 100 1 5\n3 1000 1 4\n", "5 3\n1 2 1 6\n1 3 1 20\n2 4 4 30\n5 2 1 40\n1 100 1 7\n1 100...
[ "130\n200\n60\n", "130\n200\n40\n", "0\n200\n40\n", "0\n200\n36\n", "130\n200\n0\n", "130\n0\n0\n", "0\n200\n60\n", "0\n0\n20\n", "130\n200\n40\n40\n40\n", "0\n0\n36\n" ]
CodeContests
Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and always tries to save as much paper as possible. She decided to play a ghost leg with other participants to decide the team for the Aizu training camp. How to make Amidakuji for this training camp is as foll...
stdin
null
1,224
1
[ "5 4\n4\n3\n1\n2\n", "4 3\n1\n2\n3\n" ]
[ "3\n", "3\n" ]
[ "6 4\n4\n3\n1\n2\n", "4 3\n2\n2\n4\n", "13 1\n7\n4\n3\n", "6 4\n1\n2\n1\n2\n", "4 3\n2\n2\n3\n", "5 3\n2\n2\n3\n", "4 3\n2\n3\n4\n", "4 3\n3\n3\n4\n", "6 4\n4\n1\n1\n2\n", "5 3\n4\n2\n3\n" ]
[ "3\n", "2\n", "1\n", "4\n", "3\n", "3\n", "3\n", "3\n", "3\n", "2\n" ]
CodeContests
Takahashi will take part in an eating contest. Teams of N members will compete in this contest, and Takahashi's team consists of N players numbered 1 through N from youngest to oldest. The consumption coefficient of Member i is A_i. In the contest, N foods numbered 1 through N will be presented, and the difficulty of ...
stdin
null
1,723
1
[ "3 8\n4 2 1\n2 3 1\n", "3 5\n4 2 1\n2 3 1\n", "11 14\n3 1 4 1 5 9 2 6 5 3 5\n8 9 7 9 3 2 3 8 4 6 2\n" ]
[ "0\n", "2\n", "12\n" ]
[ "3 1\n4 2 1\n2 3 1\n", "3 6\n4 2 1\n2 3 1\n", "11 14\n3 1 4 1 5 9 2 6 5 3 5\n8 9 7 9 3 1 3 8 4 6 2\n", "3 1\n8 2 1\n2 3 1\n", "11 14\n3 1 4 1 2 9 2 6 5 3 5\n8 9 7 26 3 1 3 8 4 6 2\n", "11 14\n3 1 4 1 2 9 2 11 5 3 10\n8 9 7 26 3 1 3 8 4 6 2\n", "11 14\n3 1 4 1 2 9 2 11 5 3 10\n8 9 7 26 3 2 3 8 4 6 2\n", ...
[ "4\n", "1\n", "12\n", "7\n", "10\n", "15\n", "16\n", "14\n", "0\n", "3\n" ]
CodeContests
Xenny had a list of N strings of equal length. He wanted to sort them by the first M characters only. That means, while sorting the list of strings, he only wanted to consider the first M characters of each string. Help Xenny to find out the K^th string in the list after he sorts them. Note: Xenny wanted to perform st...
stdin
null
3,112
1
[ "1\n3 1 3\nabcdef\nabcaaa\naabaaa\n\nSAMPLE\n" ]
[ "aabaaa\n" ]
[ "3\n96 69 70\nqbhesygzakrsloihfigftfojmuhbnnziovfbgorczlrlelcxcnwbwdbvnnnyitoeigmzpixaycjrymltjbcflu\ngmuajozobpgxxvyzeilbzjjwkssjtfvtxhfdcgxwhktxvzbxuyjfwklcatveycdlyfyydksbmuysczboyeqzuf\niqfoijdbcdijccrhqlwpkdctmbqetmnbfjbvbwjcvkxxxecbsyiiadyqzkgzvdpclqyhfnilsohodnmoulsyqf\nqafeydvcyaenigztylfwxzkoqliogtpbqzxtiq...
[ "qtklpjbpffrndkbutrvagiozoapbtujskotooykpltycbvkgeedsavtvegmwohqqyqxhvwxowmucncjnlupwdg\niwwgtbzbcszyquqkcazfzgonixxapmrcmawzgyhtckwuncyuwebxdwtfenrplkkgkcgaukwd\nsbjrirfbixtyliordwxbxxtaeibjzvsppaekesdipfkoxetijmznmefgonpxzcwimvxzsmoximrakokmjskvjgagzbgiuugorbw\n", "aabaaa\n", "aabbaa\n", "qtklpjbpffrndkbutr...
CodeContests
You are given a string S consisting of digits between `1` and `9`, inclusive. You can insert the letter `+` into some of the positions (possibly none) between two letters in this string. Here, `+` must not occur consecutively after insertion. All strings that can be obtained in this way can be evaluated as formulas. ...
stdin
null
4,467
1
[ "9999999999\n", "125\n" ]
[ "12656242944\n", "176\n" ]
[ "88\n", "131\n", "189\n", "292\n", "348\n", "260\n", "11\n", "16\n", "0\n", "1\n" ]
[ "104\n", "182\n", "324\n", "430\n", "456\n", "356\n", "13\n", "23\n", "0\n", "1\n" ]
CodeContests
The Monk wants to buy some cities. To buy two cities, he needs to buy the road connecting those two cities. Now, you are given a list of roads, bought by the Monk. You need to tell how many cities did the Monk buy. Input: First line contains an integer T, denoting the number of test cases. The first line of each tes...
stdin
null
3,866
1
[ "1\n3\n1 2\n2 3\n1 3\n\nSAMPLE\n" ]
[ "3\n" ]
[ "1\n3\n1 3\n2 3\n1 3\n", "1\n3\n1 3\n1 3\n1 3\n", "1\n3\n1 3\n2 3\n1 4\n", "1\n2\n2 2\n2 2\n1 3\n", "1\n3\n1 3\n1 6\n4 9\n", "1\n3\n3 5\n8 2\n1 4\n", "1\n2\n1 3\n1 3\n1 3\n", "1\n2\n1 3\n1 4\n1 3\n", "1\n2\n1 2\n2 3\n1 3\n", "1\n3\n2 2\n2 3\n1 3\n\nSAMPLE\n" ]
[ "3\n", "2\n", "4\n", "1\n", "5\n", "6\n", "2\n", "3\n", "3\n", "3\n" ]
CodeContests
Sona loves numbers. Sona loves only certain type of numbers especially prime numbers. She devised a new definition for prime numbers. In a given set of positive integer X = {X0,X1,....Xn-1} Xi is prime only if there are no elements in X which are divisors of Xi (except Xi itself). You are given the set X and find the...
stdin
null
2,952
1
[ "5\n10 49 5 3 20\n\nSAMPLE\n" ]
[ "49 5 3\n" ]
[ "10\n84 87 78 16 94 36 70 93 50 22\n", "5\n10 50 5 3 20\n\nSAMPLE\n", "10\n84 87 78 16 94 36 70 113 50 22\n", "5\n10 50 4 3 20\n\nSAMPLE\n", "10\n84 87 78 16 94 36 70 183 50 22\n", "10\n84 87 78 16 94 36 70 183 50 21\n", "5\n10 50 4 4 20\n\nSANPLE\n", "10\n84 87 78 16 94 36 112 183 50 21\n", "5\n10 ...
[ "84 87 78 16 94 36 70 93 50 22\n", "5 3\n", "84 87 78 16 94 36 70 113 50 22\n", "10 4 3\n", "84 87 78 16 94 36 70 183 50 22\n", "87 78 16 94 36 70 183 50 21\n", "10\n", "87 78 16 94 36 183 50 21\n", "1\n", "3 2\n" ]
CodeContests
Early morning in summer camp The morning of JAG summer training camp is early. To be exact, it is not so fast, but many participants feel that it is fast. At the facility that is the venue for the training camp every year, participants must collect and clean the sheets when they move out. If even one room is delayed,...
stdin
null
4,838
1
[ "2\n0.60 1 2\n0.60 0\n2\n0.60 1 2\n0.60 1 1\n5\n0.10 1 2\n0.20 1 3\n0.30 1 4\n0.40 1 5\n0.50 1 1\n5\n0.10 0\n0.20 1 1\n0.30 1 1\n0.40 1 1\n0.50 1 1\n5\n0.10 4 2 3 4 5\n0.20 0\n0.30 0\n0.40 0\n0.50 0\n4\n0.10 1 2\n0.20 0\n0.30 1 4\n0.40 1 3\n5\n0.10 0\n0.20 0\n0.30 0\n0.40 0\n0.50 0\n0\n" ]
[ "0.400000000\n0.640000000\n0.998800000\n0.168000000\n0.900000000\n0.792000000\n0.151200000\n" ]
[ "2\n0.60 1 2\n0.60 0\n2\n0.60 1 2\n0.60 1 1\n5\n0.10 1 2\n0.20 1 3\n0.30 1 4\n0.40 1 5\n0.50 1 1\n5\n0.10 0\n0.20 1 1\n0.8904968944594156 1 1\n0.40 1 1\n0.50 1 1\n5\n0.10 4 2 3 4 5\n0.20 0\n0.30 0\n0.40 0\n0.50 0\n4\n0.10 1 2\n0.20 0\n0.30 1 4\n0.40 1 3\n5\n0.10 0\n0.20 0\n0.30 0\n0.40 0\n0.50 0\n0\n", "2\n0.60 1...
[ "0.39999999999999999998\n0.63999999999999999999\n0.99880000000000000000\n0.02628074532974025600\n0.89999999999999999998\n0.79199999999999999995\n0.15120000000000000000\n", "0.39999999999999999998\n0.63999999999999999999\n0.99880000000000000000\n0.02628074532974025600\n0.89999999999999999998\n0.7919999999999999999...
CodeContests
English text is not available in this practice contest. At one point, a nobleman fell in love with a brave princess in a poor country and applied for marriage. The princess has given certain conditions to the aristocrats. The condition was to bring in a large number of jewels called "immortal jewels". Immortal gems ar...
stdin
null
2,576
1
[ "6\n-2 -2 1 1\n2 2 2 0\n5 7 1 1\n8 0 3 1\n13 4 1 1\n16 1 1 2\n3\n0 0 2 1\n10 0 2 1\n0 10 2 1\n3\n0 0 2 1\n10 0 2 1\n0 6 2 1\n3\n0 0 2 1\n10 0 2 1\n0 4 2 1\n1\n0 0 1 1\n0\n" ]
[ "4\n2\n3\n3\n1\n" ]
[ "6\n-2 -2 1 1\n2 2 2 0\n5 7 1 1\n8 0 3 1\n13 4 1 1\n16 1 1 2\n3\n-1 0 2 1\n10 0 2 1\n0 10 4 1\n3\n0 0 2 1\n10 0 2 1\n0 6 2 1\n3\n0 0 2 1\n10 0 2 1\n0 4 2 1\n1\n0 0 1 1\n0\n", "6\n-2 -2 1 1\n2 2 4 0\n5 7 1 1\n8 0 3 1\n13 4 1 1\n16 1 0 2\n3\n-1 0 2 1\n10 0 2 1\n0 10 4 1\n3\n0 0 2 1\n10 0 2 1\n0 6 2 1\n3\n0 0 2 1\n1...
[ "4\n2\n3\n3\n1\n", "5\n2\n3\n3\n1\n", "4\n2\n4\n1\n", "5\n2\n", "4\n3\n3\n3\n1\n", "4\n2\n2\n3\n1\n", "5\n2\n4\n1\n", "4\n2\n3\n1\n", "4\n2\n3\n3\n", "5\n2\n2\n3\n1\n" ]
CodeContests
There is a grass field that stretches infinitely. In this field, there is a negligibly small cow. Let (x, y) denote the point that is x\ \mathrm{cm} south and y\ \mathrm{cm} east of the point where the cow stands now. The cow itself is standing at (0, 0). There are also N north-south lines and M east-west lines drawn...
stdin
null
410
1
[ "6 1\n-3 -1 -2\n-3 -1 1\n-2 -1 2\n1 4 -2\n1 4 -1\n1 4 1\n3 1 4\n", "5 6\n1 2 0\n0 1 1\n0 2 2\n-3 4 -1\n-2 6 3\n1 0 1\n0 1 2\n2 0 2\n-1 -4 5\n3 -2 4\n1 2 4\n" ]
[ "INF\n", "13\n" ]
[ "6 1\n-3 -1 -4\n-3 -1 1\n-2 -1 2\n1 4 -2\n1 4 -1\n1 4 1\n3 1 4\n", "5 6\n1 2 0\n0 1 1\n0 2 2\n-3 4 -1\n-2 6 3\n1 0 1\n0 1 2\n2 0 2\n-1 -4 5\n3 -2 6\n1 2 4\n", "5 6\n1 1 0\n0 1 1\n0 2 2\n-3 4 -1\n-2 6 3\n1 0 1\n0 1 2\n2 0 2\n-1 -4 5\n3 -2 6\n1 2 4\n", "5 6\n1 0 1\n0 1 1\n0 4 2\n-3 4 -1\n-1 6 3\n1 0 1\n1 1 2\n2...
[ "INF\n", "13\n", "16\n", "14\n", "28\n", "4\n", "INF\n", "INF\n", "16\n", "INF\n" ]
CodeContests
Ibis is fighting with a monster. The health of the monster is H. Ibis can cast N kinds of spells. Casting the i-th spell decreases the monster's health by A_i, at the cost of B_i Magic Points. The same spell can be cast multiple times. There is no way other than spells to decrease the monster's health. Ibis wins wh...
stdin
null
4,265
1
[ "9 3\n8 3\n4 2\n2 1\n", "9999 10\n540 7550\n691 9680\n700 9790\n510 7150\n415 5818\n551 7712\n587 8227\n619 8671\n588 8228\n176 2461\n", "100 6\n1 1\n2 3\n3 9\n4 27\n5 81\n6 243\n" ]
[ "4\n", "139815\n", "100\n" ]
[ "9999 10\n540 7550\n691 13640\n700 9790\n510 7150\n415 5818\n551 7712\n587 8227\n619 8671\n588 8228\n176 2461\n", "100 6\n1 1\n2 3\n3 9\n4 27\n5 81\n5 243\n", "110 6\n1 1\n2 3\n3 9\n4 27\n5 81\n5 243\n", "9999 10\n540 7550\n691 20670\n700 9790\n863 7150\n415 5818\n551 7712\n587 8227\n619 8671\n588 8228\n176 2...
[ "139815\n", "100\n", "110\n", "85800\n", "27850\n", "19225\n", "27125\n", "47740\n", "28974\n", "21950\n" ]
CodeContests
Akash has lots of assignments to submit in his college. In one of the assignment he is given a string S of length N consisting of lowercase letters (a - z) only. Akash has to answer Q queries and for every query, he is given L, R and K. For each query he has to find the lexicographically Kth smallest character in subs...
stdin
null
4,136
1
[ "6 2\nabcdef\n2 6 3\n4 6 1\n\nSAMPLE\n" ]
[ "d\nd\n" ]
[ "10 10\nabcdefghij\n4 10 5\n3 5 3\n1 10 2\n1 2 3\n2 9 7\n2 5 2\n10 10 2\n10 10 1\n1 1 1\n3 5 3\n", "6 2\naccdef\n2 6 3\n4 6 1\n\nSAMPLE\n", "10 10\nabcdefghij\n3 10 5\n3 5 3\n1 10 2\n1 2 3\n2 9 7\n2 5 2\n10 10 2\n10 10 1\n1 1 1\n3 5 3\n", "6 2\naccdef\n2 6 6\n4 6 1\n\nSAMPLE\n", "10 10\nabcdefghij\n3 10 5\n...
[ "h\ne\nb\nOut of range\nh\nc\nOut of range\nj\na\ne\n", "d\nd\n", "g\ne\nb\nOut of range\nh\nc\nOut of range\nj\na\ne\n", "Out of range\nd\n", "g\ne\nb\nOut of range\nh\nc\nOut of range\nj\nOut of range\ne\n", "f\ne\nb\nOut of range\nh\nc\nOut of range\nj\nOut of range\ne\n", "f\ne\nb\nOut of range\nOut...
CodeContests
There was a power value associated with each soldier of Ram’s troop. It was a known belief that if two soldiers could be paired such that their total power can be divided by 3 perfectly, the pairing becomes ultra-powerful. Ram was curious as to see how many such pairings were possible. Help Ram find out the number of p...
stdin
null
3,074
1
[ "3\n5\n3 6 7 2 9\n4\n2 1 3 4\n3\n9 9 9\n\nSAMPLE\n" ]
[ "4\n2\n3\n" ]
[ "5\n3\n1 2 3\n9\n2 3 4 5 11 3 5 6 4\n1\n2\n2 \n7 2\n3 \n9 9 4\n", "3\n5\n3 6 7 2 9\n4\n2 1 3 4\n3\n6 9 9\n\nSAMPLE\n", "5\n3\n1 2 3\n9\n2 3 4 5 11 3 5 6 4\n1\n2\n2 \n3 2\n3 \n9 9 9\n", "3\n5\n3 6 7 2 9\n4\n2 1 1 4\n3\n9 9 9\n\nSAMPLE\n", "5\n3\n1 2 3\n9\n2 3 4 5 11 3 5 6 4\n1\n2\n2 \n3 2\n3 \n9 9 4\n", "5...
[ "1\n11\n0\n1\n1\n", "4\n2\n3\n", "1\n11\n0\n0\n3\n", "4\n3\n3\n", "1\n11\n0\n0\n1\n", "1\n8\n0\n0\n1\n", "1\n6\n0\n0\n1\n", "3\n6\n0\n0\n1\n", "3\n10\n0\n0\n1\n", "1\n10\n0\n0\n1\n" ]
CodeContests
Given n words w[1..n], which originate from the same stem (e.g. grace, graceful, disgraceful, gracefully), we are interested in the original stem. To simplify the problem, we define the stem as the longest consecutive substring that occurs in all the n words. If there are ties, we will choose the smallest one in the al...
stdin
null
2,546
1
[ "1\n4\ngrace graceful disgraceful gracefully\n" ]
[ "grace\n" ]
[ "1\n4\necarg graceful disgraceful gracefully\n", "1\n4\necarg grbceful lufecargsid gracefully\n", "1\n4\ngeacr graceful disgraceful gracefully\n", "1\n4\necarg grbceful lufecargsid gradefulmy\n", "1\n4\nfcgra grbcdful disgraceeul gracefvlmy\n", "1\n4\ngrace gracefuk disgraceful gracefully\n", "1\n4\ngra...
[ "a\n", "c\n", "ac\n", "e\n", "gr\n", "grace\n", "grac\n", "ce\n", "f\n", "gra\n" ]
CodeContests
Go around the Labyrinth Explorer Taro got a floor plan of a labyrinth. The floor of this labyrinth is in the form of a two-dimensional grid. Each of the cells on the floor plan corresponds to a room and is indicated whether it can be entered or not. The labyrinth has only one entrance located at the northwest corner, ...
stdin
null
3,770
1
[ "3 3\n...\n.#.\n...\n5 5\n..#..\n.....\n#....\n.....\n.....\n3 8\n..#.....\n........\n.....#..\n3 5\n..#..\n.....\n..#..\n4 4\n....\n....\n..##\n..#.\n0 0\n" ]
[ "YES\nNO\nYES\nNO\nNO\n" ]
[ "3 3\n...\n.#.\n...\n5 5\n..#..\n.....\n#....\n.....\n.....\n3 8\n..#.....\n........\n.....#..\n3 5\n..#..\n-....\n..#..\n4 4\n....\n....\n..##\n..#.\n0 0\n", "3 3\n...\n.#.\n...\n5 5\n..#..\n.....\n#....\n../..\n.....\n3 8\n..#.....\n........\n..#.....\n3 5\n..#..\n....-\n..#..\n4 4\n....\n....\n..##\n..#.\n0 0\...
[ "YES\nNO\nYES\nNO\nNO\n", "YES\nNO\nNO\nNO\nNO\n", "YES\nYES\nNO\nNO\nNO\n", "YES\nNO\nYES\nNO\nNO\n", "YES\nNO\nYES\nNO\nNO\n", "YES\nNO\nYES\nNO\nNO\n", "YES\nNO\nYES\nNO\nNO\n", "YES\nNO\nYES\nNO\nNO\n", "YES\nNO\nYES\nNO\nNO\n", "YES\nNO\nYES\nNO\nNO\n" ]
CodeContests
Dr. Asimov, a robotics researcher, released cleaning robots he developed (see Problem B). His robots soon became very popular and he got much income. Now he is pretty rich. Wonderful. First, he renovated his house. Once his house had 9 rooms that were arranged in a square, but now his house has N × N rooms arranged in...
stdin
null
186
1
[ "2 1\n2 3\n6 4\n0 0\n" ]
[ "..\n..\n\nNo\n\n..EEEE\n..E..E\nEEE..E\nE..EEE\nE..E..\nEEEE..\n" ]
[ "3 1\n2 3\n6 4\n0 0\n", "4 1\n2 3\n6 4\n0 0\n", "3 1\n4 3\n6 4\n0 0\n", "4 1\n1 3\n6 6\n0 0\n", "5 1\n4 3\n6 6\n0 0\n", "8 1\n1 3\n6 6\n0 0\n", "5 1\n4 3\n12 4\n0 0\n", "8 1\n1 3\n2 6\n0 0\n", "5 1\n4 3\n23 4\n0 0\n", "16 1\n1 3\n2 6\n0 0\n" ]
[ "No\n\nNo\n\n..EEEE\n..E..E\nEEE..E\nE..EEE\nE..E..\nEEEE..\n", "....\n.EE.\n.EE.\n....\n\nNo\n\n..EEEE\n..E..E\nEEE..E\nE..EEE\nE..E..\nEEEE..\n", "No\n\nEE..\nEE..\n..EE\n..EE\n\n..EEEE\n..E..E\nEEE..E\nE..EEE\nE..E..\nEEEE..\n", "....\n.EE.\n.EE.\n....\n\nNo\n\nEE..EE\nEE..EE\n..EE..\n..EE..\nEE..EE\nEE..E...
CodeContests
A lottery is being held in a corner of the venue of the Aizu festival. Several types of balls are inside the lottery box and each type has its unique integer printed on the surfaces of the balls. An integer T is printed on the lottery box. In the lottery, you first declare two integers A and B, and draw up to M balls ...
stdin
null
1,576
1
[ "3 2 7\n8\n3\n6\n5\n2 2\n3 2\n4 1\n6 1\n6 0\n" ]
[ "yes\nno\nyes\nno\nyes\n" ]
[ "3 2 7\n8\n3\n6\n5\n2 2\n3 2\n4 1\n6 1\n6 1\n", "3 2 7\n8\n3\n6\n5\n2 2\n5 2\n4 1\n6 1\n6 0\n", "3 2 7\n8\n3\n6\n5\n2 2\n3 0\n4 1\n6 1\n6 1\n", "3 2 7\n8\n3\n6\n5\n2 2\n2 1\n4 1\n6 0\n6 1\n", "3 2 7\n8\n3\n6\n5\n2 4\n2 1\n4 1\n6 0\n6 1\n", "3 2 7\n8\n3\n6\n5\n2 4\n2 1\n4 1\n6 0\n6 0\n", "3 1 7\n8\n3\n6\...
[ "yes\nno\nyes\nno\nno\n", "yes\nno\nyes\nno\nyes\n", "yes\nyes\nyes\nno\nno\n", "yes\nyes\nyes\nyes\nno\n", "no\nyes\nyes\nyes\nno\n", "no\nyes\nyes\nyes\nyes\n", "no\nno\nno\nyes\nyes\n", "no\nno\n", "no\nno\nyes\nyes\nyes\n", "yes\nno\nyes\nno\nno\nno\nno\nno\nno\nno\n" ]
CodeContests
Given are integer sequences A and B of length 3N. Each of these two sequences contains three copies of each of 1, 2, \dots, N. In other words, A and B are both arrangements of (1, 1, 1, 2, 2, 2, \dots, N, N, N). Tak can perform the following operation to the sequence A arbitrarily many times: * Pick a value from 1, 2...
stdin
null
3,509
1
[ "8\n3 6 7 5 4 8 4 1 1 3 8 7 3 8 2 4 7 5 2 2 6 5 6 1\n7 5 8 1 3 6 7 5 4 8 1 3 3 8 2 4 2 6 5 6 1 4 7 2\n", "3\n1 1 1 2 2 2 3 3 3\n1 1 1 2 2 2 3 3 3\n", "3\n2 3 3 1 1 1 2 2 3\n3 2 2 1 1 1 3 3 2\n", "3\n2 3 1 1 3 2 2 1 3\n1 2 2 3 1 2 3 1 3\n" ]
[ "7\n", "0\n", "-1\n", "4\n" ]
[ "3\n2 3 3 1 2 1 2 1 3\n3 2 2 1 1 1 3 3 2\n", "3\n1 1 1 2 2 2 3 3 3\n2 1 1 1 2 2 3 3 3\n", "3\n1 1 1 2 2 2 3 3 3\n1 1 1 2 3 2 3 3 2\n", "3\n2 3 3 1 2 1 2 1 3\n3 2 1 2 1 1 3 3 2\n", "3\n2 3 1 1 3 2 2 1 3\n1 2 1 3 1 2 3 2 3\n", "3\n3 3 1 1 3 2 2 1 2\n1 1 2 3 2 2 3 1 3\n", "3\n2 3 3 1 1 1 3 2 2\n3 2 2 1 1 1...
[ "-1\n", "1\n", "4\n", "5\n", "7\n", "6\n", "-1\n", "-1\n", "4\n", "-1\n" ]
CodeContests
Write a program which judges wheather given length of three side form a right triangle. Print "YES" if the given sides (integers) form a right triangle, "NO" if not so. Constraints * 1 ≤ length of the side ≤ 1,000 * N ≤ 1,000 Input Input consists of several data sets. In the first line, the number of data set, N is...
stdin
null
4,669
1
[ "3\n4 3 5\n4 3 6\n8 8 8\n" ]
[ "YES\nNO\nNO\n" ]
[ "3\n4 3 5\n0 3 6\n8 8 8\n", "3\n4 5 5\n-2 3 6\n8 8 8\n", "3\n2 2 -2\n-1 1 0\n3 2 0\n", "3\n0 2 -2\n0 1 1\n0 4 15\n", "3\n-1 -2 0\n0 1 -1\n-2 0 2\n", "3\n-1 -2 -1\n0 1 0\n-2 0 2\n", "3\n1 1 0\n29 1 -1\n0 1 -1\n", "3\n4 3 5\n-1 3 6\n8 8 8\n", "3\n4 3 5\n-2 3 6\n8 8 8\n", "3\n4 5 5\n-2 3 6\n16 8 8\n"...
[ "YES\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nYES\nNO\n", "YES\nYES\nNO\n", "NO\nYES\nYES\n", "NO\nNO\nYES\n", "YES\nNO\nYES\n", "YES\nNO\nNO\n", "YES\nNO\nNO\n", "NO\nNO\nNO\n" ]
CodeContests
PowerShell had N natural numbers. He wanted to test Xenny's speed in finding the sum and difference of several numbers. He decided to ask Xenny several questions. In each question, he gave him two positive integers L and R. He asked him to find the sum of all integers from index L to index R (inclusive) and the differ...
stdin
null
53
1
[ "4 1\n1 2 3 4\n1 3\n\nSAMPLE\n" ]
[ "6 0\n" ]
[ "78 78\n-645462 -187679 693035 927066 431506 16023 -173045 698159 -995400 -687770 -747462 789670 862673 385513 579977 -156856 22209 378002 930156 353000 67263 -758921 572468 562437 125912 -422101 -513624 43409 25348 -214377 808094 -88292 293865 910587 -731480 -509056 901506 -374951 -135921 866114 660340 866783 -225...
[ "3208499 -1574373\n4347018 -4880410\n929147 -974113\n385464 -372496\n4813363 -3572051\n6871030 -6453218\n2426908 -1052822\n385513 385513\n4403463 -2850465\n12174837 -12386883\n7006586 -7952744\n3929223 -1935495\n10126021 -8709265\n10355673 -8646827\n1409665 -3400465\n4805387 -3915767\n4371604 -4583650\n3667106 -193...
CodeContests
There are two standard ways to represent a graph $G = (V, E)$, where $V$ is a set of vertices and $E$ is a set of edges; Adjacency list representation and Adjacency matrix representation. An adjacency-list representation consists of an array $Adj[|V|]$ of $|V|$ lists, one for each vertex in $V$. For each $u \in V$, th...
stdin
null
3,576
1
[ "4\n1 2 2 4\n2 1 4\n3 0\n4 1 3\n" ]
[ "0 1 0 1\n0 0 0 1\n0 0 0 0\n0 0 1 0\n" ]
[ "4\n1 2 2 4\n2 1 1\n3 0\n4 1 3\n", "4\n1 2 0 4\n2 1 1\n3 0\n4 1 3\n", "4\n1 2 1 4\n2 1 1\n3 0\n4 1 3\n", "4\n1 2 2 4\n2 1 4\n3 -1\n4 1 3\n", "4\n1 2 1 4\n2 1 2\n3 0\n4 1 3\n", "4\n1 2 1 4\n2 1 4\n1 -1\n4 1 3\n", "4\n1 2 2 4\n2 1 4\n3 -1\n4 1 1\n", "4\n1 2 0 4\n2 1 2\n3 0\n4 1 3\n", "4\n1 2 0 4\n2 1 ...
[ "0 1 0 1\n1 0 0 0\n0 0 0 0\n0 0 1 0\n", "0 0 0 1\n1 0 0 0\n0 0 0 0\n0 0 1 0\n", "1 0 0 1\n1 0 0 0\n0 0 0 0\n0 0 1 0\n", "0 1 0 1\n0 0 0 1\n0 0 0 0\n0 0 1 0\n", "1 0 0 1\n0 1 0 0\n0 0 0 0\n0 0 1 0\n", "1 0 0 1\n0 0 0 1\n0 0 0 0\n0 0 1 0\n", "0 1 0 1\n0 0 0 1\n0 0 0 0\n1 0 0 0\n", "0 0 0 1\n0 1 0 0\n0 0...
CodeContests
Problem Tomorrow is finally the day of the excursion to Maizu Elementary School. Gatcho, who attends Maizu Elementary School, noticed that he had forgotten to buy tomorrow's sweets because he was so excited. Gaccho wants to stick to sweets so that he can enjoy the excursion to the fullest. Gaccho gets a $ X $ yen al...
stdin
null
119
1
[ "3 10 10\n1\n1 1 1\n1\n3 3 3\n1\n5 5 5\n0 1 0\n1 0 0\n0 1 0\n", "4 59 40\n1\n7 6 3\n1\n10 3 9\n2\n9 8 5\n7 6 10\n4\n8 2 9\n1 7 1\n7 7 9\n1 2 3\n0 28 7 26\n14 0 10 24\n9 6 0 21\n9 24 14 0\n", "1 10 10\n3\n1 10 1\n2 20 2\n3 30 3\n0\n", "2 10 10\n3\n1 10 1\n2 20 2\n3 30 3\n1\n5 200 1\n0 2\n3 0\n" ]
[ "10\n", "34\n", "100\n", "200\n" ]
[ "3 10 10\n1\n1 1 1\n1\n3 3 3\n1\n5 5 5\n0 1 1\n1 0 0\n0 1 0\n", "1 10 3\n3\n1 10 1\n2 20 2\n3 30 3\n0\n", "2 10 10\n3\n1 10 1\n2 9 2\n3 30 3\n1\n5 200 1\n0 2\n3 0\n", "4 59 40\n1\n7 6 3\n1\n10 3 9\n2\n14 8 5\n7 6 10\n4\n8 2 9\n1 7 1\n7 7 9\n1 2 3\n0 28 7 26\n14 0 10 24\n9 6 0 21\n9 24 14 0\n", "1 10 10\n3\n...
[ "9\n", "30\n", "200\n", "32\n", "100\n", "33\n", "94\n", "36\n", "40\n", "77\n" ]
CodeContests
Problem Statement In the headquarter building of ICPC (International Company of Plugs & Connectors), there are $M$ light bulbs and they are controlled by $N$ switches. Each light bulb can be turned on or off by exactly one switch. Each switch may control multiple light bulbs. When you operate a switch, all the light b...
stdin
null
4,990
1
[ "3 10 3\n000 0000000000\n110 0000001111\n101 1111111100\n2 2 0\n1 1 0\n2 1 1\n01 1\n11 11 10\n10000000000 10000000000\n11000000000 01000000000\n01100000000 00100000000\n00110000000 00010000000\n00011000000 00001000000\n00001100000 00000100000\n00000110000 00000010000\n00000011000 00000001000\n00000001100 0000000010...
[ "2222221100\n??\n0\n1\n0123456789A\n" ]
[ "3 10 3\n000 0000000000\n110 0000101111\n101 1111111100\n2 2 0\n1 1 0\n2 1 1\n01 1\n11 11 10\n10000000000 10000000000\n11000000000 01000000000\n01100000000 00100000000\n00110000000 00010000000\n00011000000 00001000000\n00001100000 00000100000\n00000110000 00000010000\n00000011000 00000001000\n00000001100 0000000010...
[ "2222121100\n??\n0\n1\n0123456789A\n", "2222221100\n??\n0\n1\n0A23456789A\n", "2222221100\n?\n0\n1\n0123456789A\n", "2222221200\n??\n0\n1\n0A23456789A\n", "2222221200\n???\n0\n1\n0A23456789A\n", "2222221210\n???\n0\n1\n0A23456789A\n", "2222221210\n???\n0\n1\n0923456789A\n", "2222221100\n????\n0\n1\n0A...
CodeContests
The Aizu Wakamatsu city office decided to lay a hot water pipeline covering the whole area of the city to heat houses. The pipeline starts from some hot springs and connects every district in the city. The pipeline can fork at a hot spring or a district, but no cycle is allowed. The city office wants to minimize the le...
stdin
null
382
1
[ "3 5\n12 8 25 19 23\n9 13 16 0 17\n20 14 16 10 22\n17 27 18 16\n9 7 0\n19 5\n21\n0 0\n" ]
[ "38\n" ]
[ "3 5\n12 8 25 19 44\n9 13 16 0 17\n20 14 16 10 22\n17 27 18 16\n9 7 0\n19 5\n21\n0 0\n", "3 5\n12 15 70 19 44\n9 13 16 0 17\n20 14 16 10 22\n17 27 18 16\n9 7 0\n19 5\n21\n0 0\n", "3 5\n12 8 25 19 23\n9 13 16 0 17\n20 9 16 10 22\n17 27 18 16\n1 7 0\n19 5\n21\n0 0\n", "3 5\n12 15 70 19 44\n16 13 16 0 17\n20 14 ...
[ "38\n", "40\n", "30\n", "43\n", "34\n", "37\n", "36\n", "35\n", "33\n", "27\n" ]
CodeContests
The king demon is waiting in his dungeon to defeat a brave man. His dungeon consists of H \times W grids. Each cell is connected to four (i.e. north, south, east and west) neighboring cells and some cells are occupied by obstacles. To attack the brave man, the king demon created and sent a servant that walks around in...
stdin
null
2,065
1
[ "2 2\n..\n..\n3 3\n...\n...\n..#\n0 0\n" ]
[ "Case 1: 4\nCase 2: 56\n" ]
[ "2 2\n..\n..\n3 3\n...\n...\n#..\n0 0\n", "2 1\n..\n..\n3 3\n...\n...\n#..\n0 0\n", "2 2\n..\n..\n3 1\n...\n...\n..#\n0 0\n", "2 1\n..\n..\n3 2\n...\n...\n..#\n0 0\n", "2 1\n..\n..\n3 1\n...\n...\n./#\n0 0\n", "2 1\n..\n.-\n3 2\n...\n...\n.#.\n0 0\n", "2 2\n..\n..\n3 2\n..-\n...\n..$\n0 0\n", "2 2\n.....
[ "Case 1: 4\nCase 2: 56\n", "Case 1: 1\nCase 2: 56\n", "Case 1: 4\nCase 2: 1\n", "Case 1: 1\nCase 2: 15\n", "Case 1: 1\nCase 2: 1\n", "Case 1: 1\nCase 2: 4\n", "Case 1: 4\nCase 2: 15\n", "Case 1: 4\nCase 2: 4\n", "Case 1: 1\nCase 2: 56\n", "Case 1: 1\nCase 2: 56\n" ]
CodeContests
As we have seen our little Vaishanavi playing with the plywood, her brother Vaishnav was playing with numbers. Read about Factorial As we all know this kid always thinks in a different way than others think. He have some numbers with him. He wants to find out that if he finds the factorial of the numbers that he ha...
stdin
null
4,853
1
[ "3\n1\n6\n8\n\nSAMPLE\n" ]
[ "0\n1\n1\n" ]
[ "100\n200\n220\n202\n203\n204\n205\n206\n207\n208\n209\n210\n211\n212\n213\n214\n215\n216\n217\n218\n219\n220\n221\n222\n223\n224\n225\n226\n227\n228\n229\n230\n231\n232\n233\n234\n235\n236\n237\n238\n239\n240\n241\n242\n243\n244\n245\n246\n247\n248\n249\n200\n201\n202\n203\n204\n205\n206\n207\n208\n209\n210\n211\n...
[ "70\n82\n74\n60\n69\n48\n63\n57\n64\n63\n72\n77\n83\n78\n67\n62\n62\n82\n60\n54\n82\n77\n68\n68\n89\n83\n67\n81\n88\n86\n76\n72\n70\n78\n64\n88\n82\n82\n85\n80\n69\n95\n90\n92\n74\n84\n84\n83\n85\n75\n70\n65\n74\n60\n69\n48\n63\n57\n64\n63\n72\n77\n83\n78\n67\n62\n62\n82\n60\n54\n82\n77\n68\n68\n89\n83\n67\n81\n88\...
CodeContests
An art exhibition will be held in JOI. At the art exhibition, various works of art from all over the country will be exhibited. N works of art were collected as candidates for the works of art to be exhibited. These works of art are numbered 1, 2, ..., N. Each work of art has a set value called size and value. The siz...
stdin
null
3,126
1
[ "3\n2 3\n11 2\n4 5\n" ]
[ "6\n" ]
[ "3\n2 3\n11 2\n4 2\n", "3\n2 5\n11 2\n4 2\n", "3\n2 5\n11 2\n4 3\n", "3\n2 9\n11 0\n4 3\n", "3\n2 9\n11 0\n7 3\n", "3\n2 3\n2 2\n4 5\n", "3\n2 2\n11 2\n4 2\n", "3\n2 5\n11 2\n4 4\n", "3\n2 3\n11 0\n4 3\n", "3\n0 16\n54 3\n5 1\n" ]
[ "3\n", "5\n", "6\n", "10\n", "9\n", "8\n", "2\n", "7\n", "4\n", "16\n" ]
CodeContests
Ikta, who hates to lose, has recently been enthusiastic about playing games using the Go board. However, neither Go nor Gomoku can beat my friends at all, so I decided to give a special training to the lesser-known game Phutball. This game is a difficult game, so I decided to give special training so that I could win ...
stdin
null
2,457
1
[ "...............\n...............\n...............\n...............\n...............\n...............\n...............\n...............\n...............\n...............\n...............\n...............\n...............\n...............\n...............\n...............\n.....XX........\n.....XXXO......\n......X.....
[ "4\n", "6\n", "1\n", "-1\n" ]
[ "...............\n...............\n...............\n...............\n...............\n.........../...\n...............\n...............\n...............\n...............\n...............\n...............\n...............\n...............\n...............\n...............\n.....XX........\n.....XXXO......\n......X.....
[ "4\n", "6\n", "1\n", "-1\n", "7\n", "4\n", "6\n", "1\n", "-1\n", "4\n" ]
CodeContests
Food contains three nutrients called "protein", "fat" and "carbohydrate", which are called three major nutrients. It is calculated that protein and carbohydrate are 4 kcal (kilocalories) and fat is 9 kcal per 1 g (gram). For example, according to the table below, the number 1 cake contains 7 g of protein, 14 g of fat a...
stdin
null
3,603
1
[ "4\n1 7 14 47\n2 5 35 55\n3 6 3 59\n4 6 5 15\n10 15 50 400\n2\n1 8 10 78\n2 4 18 33\n10 10 50 300\n0\n" ]
[ "1\n4\nNA\n" ]
[ "4\n1 7 14 47\n2 5 35 55\n3 6 3 59\n4 6 5 15\n10 15 50 110\n2\n1 8 10 78\n2 4 18 33\n10 10 50 300\n0\n", "4\n1 7 14 47\n2 7 35 55\n3 6 3 78\n4 2 7 15\n10 15 50 110\n2\n1 8 10 215\n0 4 8 33\n4 10 50 300\n0\n", "4\n1 7 14 47\n2 5 35 55\n3 6 3 59\n4 6 5 15\n10 15 50 318\n2\n1 8 10 78\n2 4 18 33\n10 10 50 300\n0\n"...
[ "NA\nNA\n", "NA\n0\n", "4\nNA\n", "NA\n1\n", "NA\n", "NA\n2\n", "3\nNA\n", "2\nNA\n", "4\n", "0\nNA\n" ]
CodeContests
We have held a popularity poll for N items on sale. Item i received A_i votes. From these N items, we will select M as popular items. However, we cannot select an item with less than \dfrac{1}{4M} of the total number of votes. If M popular items can be selected, print `Yes`; otherwise, print `No`. Constraints * 1 \...
stdin
null
3,310
1
[ "4 1\n5 4 2 1\n", "12 3\n4 56 78 901 2 345 67 890 123 45 6 789\n", "3 2\n380 19 1\n" ]
[ "Yes\n", "Yes\n", "No\n" ]
[ "4 1\n5 4 0 1\n", "3 2\n519 19 1\n", "12 3\n4 56 78 901 2 345 67 890 123 45 3 789\n", "3 1\n5 4 0 1\n", "3 2\n39 19 1\n", "3 2\n39 14 1\n", "3 2\n39 18 1\n", "3 1\n39 18 1\n", "3 1\n39 16 1\n", "3 1\n53 16 1\n" ]
[ "Yes\n", "No\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n" ]
CodeContests
Snuke can change a string t of length N into a string t' of length N - 1 under the following rule: * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t. There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operati...
stdin
null
1,092
1
[ "serval\n", "whbrjpjyhsrywlqjxdbrbaomnw\n", "jackal\n", "zzz\n" ]
[ "3\n", "8\n", "2\n", "0\n" ]
[ "resval\n", "whbrjpjyhsrywlqjxcbrbaomnw\n", "zzy\n", "lakjac\n", "xmboabrbnxjrlwyrthyjpjrchv\n", "whcrjpbyhtxywkrlxnbrbaojmr\n", "smjoabjdoxmrjwypugydyqrchv\n", "whdrpxdwhuozxkrmxodjaaojkt\n", "xwwwnajdrxmrqwzpugnhlojced\n", "wyeoqidphazibqrnvxibngzwpx\n" ]
[ "3\n", "8\n", "1\n", "2\n", "6\n", "10\n", "11\n", "9\n", "12\n", "7\n" ]
CodeContests
The Little Elephant from the Zoo of Lviv currently is on the military mission. There are N enemy buildings placed in a row and numbered from left to right strating from 0. Each building i (except the first and the last) has exactly two adjacent buildings with indices i-1 and i+1. The first and the last buildings have j...
stdin
null
714
1
[ "3\n3\n010\n5\n10001\n7\n0000000\n" ]
[ "0\n1\n7\n" ]
[ "3\n3\n011\n5\n10001\n7\n0000000\n", "3\n3\n010\n5\n10001\n7\n0010000\n", "3\n3\n010\n5\n10001\n7\n1010000\n", "3\n3\n010\n5\n10000\n7\n1010000\n", "3\n3\n010\n5\n10011\n7\n0000000\n", "3\n3\n001\n5\n10101\n7\n0000000\n", "3\n3\n010\n5\n00011\n7\n1010000\n", "3\n3\n010\n5\n10011\n7\n1010000\n", "3\n...
[ "0\n1\n7\n", "0\n1\n4\n", "0\n1\n3\n", "0\n3\n3\n", "0\n0\n7\n", "1\n0\n7\n", "0\n2\n3\n", "0\n0\n3\n", "0\n1\n2\n", "0\n3\n2\n" ]
CodeContests
The development of algae in a pond is as follows. Let the total weight of the algae at the beginning of the year i be x_i gram. For i≥2000, the following formula holds: * x_{i+1} = rx_i - D You are given r, D and x_{2000}. Calculate x_{2001}, ..., x_{2010} and print them in order. Constraints * 2 ≤ r ≤ 5 * 1 ≤ D...
stdin
null
4,032
1
[ "2 10 20\n", "4 40 60\n" ]
[ "30\n50\n90\n170\n330\n650\n1290\n2570\n5130\n10250\n", "200\n760\n3000\n11960\n47800\n191160\n764600\n3058360\n12233400\n48933560\n" ]
[ "0 10 20\n", "8 40 60\n", "1 10 20\n", "8 40 0\n", "1 10 32\n", "8 10 0\n", "1 1 32\n", "8 10 -1\n", "1 1 57\n", "8 2 -1\n" ]
[ "-10\n-10\n-10\n-10\n-10\n-10\n-10\n-10\n-10\n-10\n", "440\n3480\n27800\n222360\n1778840\n14230680\n113845400\n910763160\n7286105240\n58288841880\n", "10\n0\n-10\n-20\n-30\n-40\n-50\n-60\n-70\n-80\n", "-40\n-360\n-2920\n-23400\n-187240\n-1497960\n-11983720\n-95869800\n-766958440\n-6135667560\n", "22\n12\n2\...
CodeContests
Madhav went to Riya's Birthday Party. He was a geek so he had no idea regarding which gift she'l like. So he took an array of integers with him. The array followed a particular order. First element of array is 1. Second element of array is 6. Other elements of the array are two less than the mean of the number precedin...
stdin
null
3,627
1
[ "2\n1\n3\n\nSAMPLE\n" ]
[ "1\n15\n" ]
[ "2\n2\n3\n\nSAMPLE\n", "2\n2\n2\n\nELPMAS\n", "2\n1\n3\n\nELPMAS\n", "2\n2\n6\n\nELPNAS\n", "2\n2\n1\n\nSAMPLD\n", "2\n2\n12\n\nELPNAS\n", "2\n3\n1\n\nSAMPLD\n", "2\n2\n20\n\nELPNAS\n", "2\n1\n1\n\nEAPMKS\n", "2\n1\n20\n\nELPNAS\n" ]
[ "6\n15\n", "6\n6\n", "1\n15\n", "6\n66\n", "6\n1\n", "6\n276\n", "15\n1\n", "6\n780\n", "1\n1\n", "1\n780\n" ]
CodeContests
There are N observatories in AtCoder Hill, called Obs. 1, Obs. 2, ..., Obs. N. The elevation of Obs. i is H_i. There are also M roads, each connecting two different observatories. Road j connects Obs. A_j and Obs. B_j. Obs. i is said to be good when its elevation is higher than those of all observatories that can be r...
stdin
null
1,204
1
[ "6 5\n8 6 9 1 2 1\n1 3\n4 2\n4 3\n4 6\n4 6\n", "4 3\n1 2 3 4\n1 3\n2 3\n2 4\n" ]
[ "3\n", "2\n" ]
[ "6 5\n8 6 9 1 2 1\n1 3\n4 2\n4 0\n4 6\n4 6\n", "4 3\n1 2 3 4\n1 3\n3 3\n2 4\n", "4 2\n2 4 3 5\n1 3\n3 3\n2 4\n", "4 0\n2 4 3 5\n1 3\n3 3\n4 4\n", "6 0\n9 6 8 1 1 1\n0 3\n3 0\n4 1\n4 2\n1 6\n", "6 5\n8 6 9 1 2 0\n0 3\n4 0\n4 0\n2 6\n4 6\n", "4 3\n1 6 3 3\n1 3\n2 2\n3 4\n", "6 5\n8 6 9 1 2 1\n1 3\n4 1\n...
[ "3\n", "1\n", "2\n", "4\n", "6\n", "5\n", "0\n", "3\n", "1\n", "3\n" ]
CodeContests
For given an integer $n$, print all permutations of $\\{1, 2, ..., n\\}$ in lexicographic order. Constraints * $1 \leq n \leq 9$ Input An integer $n$ is given in a line. Output Print each permutation in a line in order. Separate adjacency elements by a space character. Examples Input 2 Output 1 2 2 1 Inpu...
stdin
null
1,590
1
[ "3\n", "2\n" ]
[ "1 2 3\n1 3 2\n2 1 3\n2 3 1\n3 1 2\n3 2 1\n", "1 2\n2 1\n" ]
[ "1\n", "4\n", "5\n", "4\n", "1\n", "5\n" ]
[ "1\n", "1 2 3 4\n1 2 4 3\n1 3 2 4\n1 3 4 2\n1 4 2 3\n1 4 3 2\n2 1 3 4\n2 1 4 3\n2 3 1 4\n2 3 4 1\n2 4 1 3\n2 4 3 1\n3 1 2 4\n3 1 4 2\n3 2 1 4\n3 2 4 1\n3 4 1 2\n3 4 2 1\n4 1 2 3\n4 1 3 2\n4 2 1 3\n4 2 3 1\n4 3 1 2\n4 3 2 1\n", "1 2 3 4 5\n1 2 3 5 4\n1 2 4 3 5\n1 2 4 5 3\n1 2 5 3 4\n1 2 5 4 3\n1 3 2 4 5\n1 3 2 5...
CodeContests
Chief Judge's log, stardate 48642.5. We have decided to make a problem from elementary number theory. The problem looks like finding all prime factors of a positive integer, but it is not. A positive integer whose remainder divided by 7 is either 1 or 6 is called a 7N+{1,6} number. But as it is hard to pronounce, we s...
stdin
null
3,009
1
[ "205920\n262144\n262200\n279936\n299998\n1\n" ]
[ "205920: 6 8 13 15 20 22 55 99\n262144: 8\n262200: 6 8 15 20 50 57 69 76 92 190 230 475 575 874 2185\n279936: 6 8 27\n299998: 299998\n" ]
[ "205920\n262144\n262200\n279936\n152244\n1\n", "205920\n262144\n299662\n279936\n152244\n1\n", "205920\n262144\n262200\n259214\n152244\n1\n", "205920\n262144\n299662\n279936\n101746\n1\n", "205920\n262144\n299662\n279936\n112663\n1\n", "205920\n52578\n299662\n279936\n112663\n1\n", "205920\n52578\n299662\...
[ "205920: 6 8 13 15 20 22 55 99\n262144: 8\n262200: 6 8 15 20 50 57 69 76 92 190 230 475 575 874 2185\n279936: 6 8 27\n152244: 6 4229\n", "205920: 6 8 13 15 20 22 55 99\n262144: 8\n299662: 22 106 2827 13621\n279936: 6 8 27\n152244: 6 4229\n", "205920: 6 8 13 15 20 22 55 99\n262144: 8\n262200: 6 8 15 20 50 57 69 ...
CodeContests
As AtCoder Beginner Contest 100 is taking place, the office of AtCoder, Inc. is decorated with a sequence of length N, a = {a_1, a_2, a_3, ..., a_N}. Snuke, an employee, would like to play with this sequence. Specifically, he would like to repeat the following operation as many times as possible: For every i satisfy...
stdin
null
4,034
1
[ "10\n2184 2126 1721 1800 1024 2528 3360 1945 1280 1776\n", "4\n631 577 243 199\n", "3\n5 2 4\n" ]
[ "39\n", "0\n", "3\n" ]
[ "10\n2184 2126 1721 1800 1480 2528 3360 1945 1280 1776\n", "4\n631 846 243 199\n", "10\n2184 2126 1721 1800 1480 2850 3360 1945 1280 1776\n", "4\n631 846 218 199\n", "3\n5 2 8\n", "10\n2184 2126 1721 1800 1480 2850 1620 1945 1280 1776\n", "3\n5 3 8\n", "10\n2184 2126 1721 1800 1480 2850 1620 1945 875 ...
[ "32\n", "1\n", "28\n", "2\n", "4\n", "25\n", "3\n", "17\n", "0\n", "13\n" ]
CodeContests
In the 17th century, Fermat wrote that he proved for any integer $n \geq 3$, there exist no positive integers $x$, $y$, $z$ such that $x^n + y^n = z^n$. However he never disclosed the proof. Later, this claim was named Fermat's Last Theorem or Fermat's Conjecture. If Fermat's Last Theorem holds in case of $n$, then it...
stdin
null
4,830
1
[ "6\n4\n2\n0\n" ]
[ "27\n10\n6\n" ]
[ "6\n6\n2\n0\n", "6\n6\n0\n0\n", "6\n4\n4\n0\n", "6\n4\n0\n-1\n", "6\n5\n2\n0\n", "6\n0\n0\n1\n", "6\n3\n2\n0\n", "6\n5\n0\n1\n", "6\n7\n4\n0\n", "6\n2\n2\n0\n" ]
[ "27\n27\n6\n", "27\n27\n", "27\n10\n10\n", "27\n10\n", "27\n34\n6\n", "27\n", "27\n11\n6\n", "27\n34\n", "27\n2\n10\n", "27\n6\n6\n" ]
CodeContests
Problem Beans are popular at Otsu University. N beans are lined up in a straight line. Each is numbered from 0 to N-1, and the hardness of the i-th bean is ai. Cyan considers the ideal bean hardness to be D. However, Cyan doesn't want to go get the beans that are too far away because he is troublesome. Therefore, Cya...
stdin
null
2,298
1
[ "3\n1 2 3\n3\n0 2 2\n0 2 4\n0 0 2\n", "10\n4 5 0 21 9 100 12 9 0 8\n5\n0 3 20\n2 5 100\n8 9 9\n5 5 10\n0 9 20\n" ]
[ "0\n1\n1\n", "1\n0\n1\n90\n1\n" ]
[ "3\n1 2 3\n3\n0 2 3\n0 2 4\n0 0 2\n", "10\n4 5 0 21 9 100 12 9 0 8\n5\n0 3 20\n2 5 101\n8 9 9\n5 5 10\n0 9 20\n", "10\n4 5 0 21 9 100 12 9 0 6\n5\n0 3 20\n2 5 101\n8 9 9\n5 5 10\n0 9 20\n", "10\n4 5 0 21 9 000 12 9 0 6\n5\n0 3 20\n2 5 101\n8 9 9\n5 5 10\n0 9 20\n", "10\n4 5 1 21 9 000 14 9 0 6\n5\n1 3 20\n0...
[ "0\n1\n1\n", "1\n1\n1\n90\n1\n", "1\n1\n3\n90\n1\n", "1\n80\n3\n10\n1\n", "1\n80\n3\n1\n1\n", "1\n1\n1\n1\n1\n", "1\n80\n2\n10\n1\n", "1\n80\n3\n17\n1\n", "1\n80\n3\n12\n1\n", "14\n67\n3\n6\n6\n" ]
CodeContests
Apple adventure square1001 and E869120 got lost in the grid world of $ H $ rows and $ W $ rows! Said the god of this world. "When you collect $ K $ apples and they meet, you'll be back in the original world." Upon hearing this word, square1001 decided to collect more than $ K $ of apples and head to the square wher...
stdin
null
159
1
[ "5 5 2\ns..#a\n.#...\na#e.#\n...#a\n.#...\n" ]
[ "14\n" ]
[ "5 5 2\ns..#a\n.#...\ne#a.#\n...#a\n.#...\n", "5 5 2\ns..#a\n.#../\n#.a#e\n...#a\n.#...\n", "5 5 2\nb#..s\n.#/./\ne#a.#\n...#a\n.#...\n", "5 5 1\ns..#a\n.#...\na#e.#\n...#b\n.#...\n", "5 5 2\ns.#.a\n.#../\ne#a.#\n...#a\n.#...\n", "5 5 1\nc#..s\n.#/./\n#.a#e\n...#a\n.#...\n", "5 5 4\ns..#b\n.#/./\ne#a.#\...
[ "14\n", "10\n", "16\n", "6\n", "18\n", "4\n", "-1\n", "12\n", "9\n", "8\n" ]
CodeContests
Chef and Roma are playing a game. Rules of the game are quite simple. Initially there are N piles of stones on the table. In each turn, a player can choose one pile and remove it from the table. Each player want to maximize the total number of stones removed by him. Chef takes the first turn. Please tell Chef the max...
stdin
null
951
1
[ "2\n3\n1 2 3\n3\n1 2 1\n" ]
[ "4\n3\n" ]
[ "2\n3\n1 2 3\n3\n1 2 2\n", "2\n3\n1 2 3\n3\n0 2 1\n", "2\n3\n1 0 3\n3\n0 2 1\n", "2\n3\n1 0 2\n3\n0 2 1\n", "2\n3\n1 1 2\n3\n0 4 1\n", "2\n3\n1 1 4\n3\n0 4 1\n", "2\n3\n1 1 4\n3\n0 3 1\n", "2\n3\n1 1 5\n3\n0 3 1\n", "2\n3\n1 1 5\n3\n0 2 1\n", "2\n3\n1 1 5\n3\n2 2 2\n" ]
[ "4\n3\n", "4\n2\n", "3\n2\n", "2\n2\n", "3\n4\n", "5\n4\n", "5\n3\n", "6\n3\n", "6\n2\n", "6\n4\n" ]
CodeContests
Alice and Bob were in love with each other, but they hate each other now. One day, Alice found a bag. It looks like a bag that Bob had used when they go on a date. Suddenly Alice heard tick-tack sound. Alice intuitively thought that Bob is to kill her with a bomb. Fortunately, the bomb has not exploded yet, and there ...
stdin
null
1,064
1
[ "1\n1 1\n4 -1 0 -2 -1 -1 -2 0 -1\n1\n0 3\n4 1 1 1 2 -1 2 -1 1\n1\n-6 -6\n6 1 -2 2 -2 2 3 -2 3 -2 1 1 1\n1\n-10 0\n4 0 -5 1 -5 1 5 0 5\n1\n10 1\n4 5 1 6 2 5 3 4 2\n2\n-47 -37\n4 14 3 20 13 9 12 15 9\n4 -38 -3 -34 -19 -34 -14 -24 -10\n0\n" ]
[ "1.00000000\n0.00000000\n3.23606798\n5.00000000\n1.00000000\n11.78517297\n" ]
[ "1\n1 1\n4 -1 0 -2 -1 -1 -2 0 -1\n1\n0 3\n4 1 1 1 2 -1 2 -1 1\n1\n-6 -6\n6 1 -1 2 -2 2 3 -2 3 -2 1 1 1\n1\n-10 0\n4 0 -5 1 -5 1 5 0 5\n1\n10 1\n4 5 1 6 2 5 3 4 2\n2\n-47 -37\n4 14 3 20 13 9 12 15 9\n4 -38 -3 -34 -19 -34 -14 -24 -10\n0\n", "1\n1 1\n4 -1 0 -2 -1 -1 -2 0 -1\n1\n0 3\n4 1 1 1 2 -1 2 -1 1\n1\n-6 -4\n6 ...
[ "1.000000000000\n0.000000000000\n2.828427124746\n5.000000000000\n1.000000000000\n11.785172975683\n", "1.000000000000\n0.000000000000\n3.236067977500\n5.000000000000\n1.000000000000\n11.785172975683\n", "1.000000000000\n0.000000000000\n2.000000000000\n5.000000000000\n1.000000000000\n11.785172975683\n", "1.0000...
CodeContests
Takahashi's office has N rooms. Each room has an ID from 1 to N. There are also N-1 corridors, and the i-th corridor connects Room a_i and Room b_i. It is known that we can travel between any two rooms using only these corridors. Takahashi has got lost in one of the rooms. Let this room be r. He decides to get back to...
stdin
null
4,110
1
[ "6\n1 2\n2 3\n3 4\n4 5\n5 6\n", "6\n1 5\n5 6\n6 2\n6 3\n6 4\n", "10\n1 5\n5 6\n6 10\n6 4\n10 3\n10 8\n8 2\n4 7\n4 9\n" ]
[ "1 2 3 4 5\n", "5 5 5 1 5\n", "7 5 3 1 3 4 7 4 5\n" ]
[ "6\n1 4\n2 3\n3 4\n4 5\n5 6\n", "6\n1 2\n5 6\n6 2\n6 3\n6 4\n", "10\n1 5\n5 6\n6 10\n1 4\n10 3\n10 8\n8 2\n4 7\n4 9\n", "6\n1 5\n5 6\n6 2\n6 3\n5 4\n", "10\n1 5\n5 6\n6 10\n6 4\n5 3\n10 8\n8 2\n4 7\n4 9\n", "6\n1 4\n2 1\n3 4\n4 5\n5 6\n", "6\n1 4\n5 6\n6 2\n6 3\n6 4\n", "6\n1 4\n2 1\n3 4\n4 5\n1 6\n",...
[ "3 3 1 2 3\n", "1 3 3 3 2\n", "6 4 1 1 2 2 6 2 4\n", "4 4 2 1 4\n", "6 2 3 1 3 4 6 4 4\n", "1 2 1 2 3\n", "4 4 1 5 4\n", "1 2 1 2 1\n", "1 2 3 3 2\n", "9 4 9 1 2 9 9 9 4\n" ]
CodeContests
For a positive integer a, let S(a) be the sum of the digits in base l. Also let L(a) be the minimum k such that S^k(a) is less than or equal to l-1. Find the minimum a such that L(a) = N for a given N, and print a modulo m. Input The input contains several test cases, followed by a line containing "0 0 0". Each tes...
stdin
null
1,301
1
[ "0 1000 10\n1 1000 10\n0 0 0\n" ]
[ "Case 1: 1\nCase 2: 10\n" ]
[ "0 1000 4\n1 1000 10\n0 0 0\n", "0 1000 4\n1 1000 17\n0 0 0\n", "0 1000 4\n1 1000 33\n0 0 0\n", "0 1000 4\n0 1000 17\n0 0 0\n", "0 1000 4\n2 1100 10\n0 0 0\n", "1 1000 10\n1 1000 10\n0 0 0\n", "1 1000 4\n1 1000 17\n0 0 0\n", "0 1000 4\n2 1000 33\n0 0 0\n", "1 1000 12\n1 1000 10\n0 0 0\n", "1 1100 ...
[ "Case 1: 1\nCase 2: 10\n", "Case 1: 1\nCase 2: 17\n", "Case 1: 1\nCase 2: 33\n", "Case 1: 1\nCase 2: 1\n", "Case 1: 1\nCase 2: 19\n", "Case 1: 10\nCase 2: 10\n", "Case 1: 4\nCase 2: 17\n", "Case 1: 1\nCase 2: 65\n", "Case 1: 12\nCase 2: 10\n", "Case 1: 4\nCase 2: 10\n" ]
CodeContests
Statement You need to find a string which has exactly K positions in it such that the character at that position comes alphabetically later than the character immediately after it. If there are many such strings, print the one which has the shortest length. If there is still a tie, print the string which comes the le...
stdin
null
4,252
1
[ "2\n1\n2\n" ]
[ "ba\ncba\n" ]
[ "2\n2\n2\n", "2\n2\n3\n", "2\n3\n2\n", "2\n2\n5\n", "2\n4\n5\n", "2\n3\n5\n", "2\n5\n5\n", "2\n5\n8\n", "2\n4\n8\n", "2\n1\n1\n" ]
[ "cba\ncba\n", "cba\ndcba\n", "dcba\ncba\n", "cba\nfedcba\n", "edcba\nfedcba\n", "dcba\nfedcba\n", "fedcba\nfedcba\n", "fedcba\nihgfedcba\n", "edcba\nihgfedcba\n", "ba\nba\n" ]
CodeContests
Problem Gaccho owns a field separated by W horizontal x H vertical squares. The cell in the x-th column and the y-th row is called the cell (x, y). Only one plant with a height of 0 cm is planted on the land of some trout, and nothing is planted on the land of other trout. Gaccho sprinkles fertilizer on the field at ...
stdin
null
2,736
1
[ "2 3 4\n2\n0 0 0\n1 1 3\n1 0\n0 0\n0 0\n", "3 8 6\n6\n0 4 3\n2 5 3\n0 2 3\n2 2 5\n1 1 3\n2 2 1\n1 1 1\n1 1 1\n1 1 1\n1 0 1\n0 1 1\n1 1 0\n1 0 1\n0 1 0\n", "8 3 3\n7\n0 1 1\n5 1 0\n4 0 2\n3 2 0\n3 1 1\n3 0 1\n5 1 1\n1 0 1 1 0 0 1 0\n0 0 1 1 0 1 0 1\n0 1 0 0 0 1 0 1\n", "3 3 3\n5\n2 0 0\n0 1 0\n1 1 1\n1 2 1\n2 ...
[ "1\n", "4\n", "4\n", "1\n" ]
[ "2 3 4\n2\n0 0 1\n1 1 3\n1 0\n0 0\n0 0\n", "3 8 6\n6\n0 4 3\n2 5 3\n0 2 3\n2 2 5\n1 1 3\n2 2 1\n1 1 0\n1 1 1\n1 1 1\n1 0 1\n0 1 1\n1 1 0\n1 0 1\n0 1 0\n", "3 3 3\n5\n2 0 0\n0 1 0\n1 1 1\n1 2 0\n2 2 0\n0 0 1\n0 1 0\n0 0 0\n", "0 3 4\n2\n0 0 1\n1 1 3\n1 1\n1 0\n0 0\n", "8 3 3\n7\n0 1 1\n5 1 0\n4 0 2\n1 2 0\n3...
[ "1\n", "4\n", "2\n", "0\n", "5\n", "3\n", "4\n", "1\n", "1\n", "4\n" ]
CodeContests
Snuke found a record of a tree with N vertices in ancient ruins. The findings are as follows: * The vertices of the tree were numbered 1,2,...,N, and the edges were numbered 1,2,...,N-1. * Edge i connected Vertex a_i and b_i. * The length of each edge was an integer between 1 and 10^{18} (inclusive). * The sum of the ...
stdin
null
2,130
1
[ "4\n1 2\n2 3\n3 4\n8 6 6 8\n", "15\n9 10\n9 15\n15 4\n4 13\n13 2\n13 11\n2 14\n13 6\n11 1\n1 12\n12 3\n12 7\n2 5\n14 8\n1154 890 2240 883 2047 2076 1590 1104 1726 1791 1091 1226 841 1000 901\n", "5\n1 2\n1 3\n1 4\n1 5\n10 13 16 19 22\n" ]
[ "1\n2\n1\n", "5\n75\n2\n6\n7\n50\n10\n95\n9\n8\n78\n28\n89\n8\n", "1\n2\n3\n4\n" ]
[ "15\n9 10\n9 15\n15 4\n4 13\n13 2\n13 11\n2 14\n13 6\n11 1\n1 12\n12 3\n12 7\n2 5\n14 8\n1154 890 2240 883 2930 2076 1590 1104 1726 1791 1091 1226 841 1000 901\n", "5\n1 2\n1 3\n1 4\n1 5\n5 13 16 19 22\n", "15\n9 10\n9 15\n15 4\n4 13\n13 2\n13 11\n2 14\n13 6\n11 1\n1 12\n12 3\n11 7\n2 5\n14 8\n1154 890 2240 883...
[ "5\n75\n2\n6\n7\n50\n10\n95\n9\n8\n78\n28\n156\n8\n", "2\n3\n4\n5\n", "5\n75\n2\n6\n7\n50\n10\n95\n7\n6\n78\n38\n89\n8\n", "5\n75\n2\n39\n40\n97\n10\n113\n9\n8\n78\n28\n156\n8\n", "1\n1\n3\n4\n", "5\n75\n2\n39\n40\n69\n10\n113\n7\n6\n78\n75\n156\n8\n", "5\n75\n2\n6\n10\n50\n7\n95\n9\n8\n78\n28\n155\n8\n...
CodeContests
Snuke has decided to play with N cards and a deque (that is, a double-ended queue). Each card shows an integer from 1 through N, and the deque is initially empty. Snuke will insert the cards at the beginning or the end of the deque one at a time, in order from 1 to N. Then, he will perform the following action N times...
stdin
null
2,484
1
[ "2 1\n", "2000 1000\n", "17 2\n" ]
[ "1\n", "674286644\n", "262144\n" ]
[ "2000 1100\n", "4 2\n", "4 1\n", "1 1\n", "3 1\n", "13 2\n", "5 2\n", "5 1\n", "10 1\n", "9 2\n" ]
[ "270390985\n", "6\n", "4\n", "1\n", "2\n", "12288\n", "16\n", "8\n", "256\n", "512\n" ]
CodeContests
There are N cities numbered 1 through N, and M bidirectional roads numbered 1 through M. Road i connects City A_i and City B_i. Snuke can perform the following operation zero or more times: * Choose two distinct cities that are not directly connected by a road, and build a new road between the two cities. After he...
stdin
null
2,994
1
[ "3 1\n1 2\n" ]
[ "1\n" ]
[ "3 1\n1 1\n", "5 1\n1 1\n", "6 1\n1 1\n", "3 1\n3 2\n", "5 1\n3 2\n", "2 1\n1 2\n", "9 1\n1 2\n", "15 1\n1 2\n", "10 1\n1 2\n", "10 1\n1 1\n" ]
[ "2\n", "4\n", "5\n", "1\n", "3\n", "0\n", "7\n", "13\n", "8\n", "9\n" ]
CodeContests
Lucky numbers are those numbers which contain only "4" and/or "5". For example 4, 5, 44, 54,55,444 are lucky numbers while 457, 987 ,154 are not. Lucky number sequence is one in which all lucky numbers exist in increasing order for example 4,5,44,45,54,55,444,445,454,455... Now we concatenate all the lucky number...
stdin
null
4,179
1
[ "4\n1\n2\n3\n9\n\nSAMPLE\n" ]
[ "Hacker\nEarth\nHacker\nEarth\n" ]
[ "4\n1\n2\n3\n8\n\nSAMPLE\n", "4\n1\n1\n3\n8\n\nSAMPLE\n", "4\n1\n2\n1\n9\n\nSAMPLE\n", "4\n2\n2\n3\n8\n\nSAMPLE\n", "4\n4\n2\n7\n8\n\nSAMPLE\n", "4\n2\n2\n7\n4\n\nSPMBLE\n", "4\n4\n1\n4\n2\n\nSPMBLE\n", "4\n8\n1\n2\n4\n\nELBMPT\n", "4\n7\n1\n4\n2\n\nELBMPT\n", "4\n8\n1\n2\n2\n\nELBMPT\n" ]
[ "Hacker\nEarth\nHacker\nHacker\n", "Hacker\nHacker\nHacker\nHacker\n", "Hacker\nEarth\nHacker\nEarth\n", "Earth\nEarth\nHacker\nHacker\n", "Hacker\nEarth\nEarth\nHacker\n", "Earth\nEarth\nEarth\nHacker\n", "Hacker\nHacker\nHacker\nEarth\n", "Hacker\nHacker\nEarth\nHacker\n", "Earth\nHacker\nHacker\n...
CodeContests
Chef likes playing with strings. The most interesting game are named "CHEF in string". The move of the game consists of the following: Chef takes a subsequence of string's letters that form the word "CHEF" and then he removes that symbols. The goal of the game is to make the maximal number of moves. Please, help Chef a...
stdin
null
792
1
[ "CHEFCHEFFFF\n", "CHHHEEEFFCC\n" ]
[ "2\n", "1\n" ]
[ "CIEFCHEFFFF\n", "BHHHEEFFFCC\n", "CHEFCHEFGFF\n", "CHHHEEFFFCC\n", "FIEFCHECFFF\n", "FJEFCHECFFF\n", "BHIHEEFFFCC\n", "FJEFCHFCFFF\n", "BHIHEEFFFCB\n", "FJEFCHFCGFF\n" ]
[ "1\n", "0\n", "2\n", "1\n", "1\n", "1\n", "0\n", "0\n", "0\n", "0\n" ]
CodeContests
12:17 (UTC): The sample input 1 and 2 were swapped. The error is now fixed. We are very sorry for your inconvenience. There are N children in AtCoder Kindergarten, conveniently numbered 1 through N. Mr. Evi will distribute C indistinguishable candies to the children. If child i is given a candies, the child's happine...
stdin
null
1,213
1
[ "3 100\n7 6 5\n9 9 9\n", "1 2\n1\n3\n", "2 3\n1 1\n1 1\n", "2 3\n1 1\n2 2\n", "4 8\n3 1 4 1\n3 1 4 1\n" ]
[ "139123417\n", "14\n", "4\n", "66\n", "421749\n" ]
[ "3 100\n7 1 5\n9 9 9\n", "1 2\n1\n4\n", "4 8\n3 1 4 1\n3 1 5 1\n", "3 000\n7 1 5\n9 9 9\n", "1 4\n1\n4\n", "4 8\n3 1 3 1\n3 1 5 1\n", "4 8\n3 1 2 1\n3 1 5 1\n", "4 8\n3 1 2 1\n4 1 5 1\n", "4 15\n3 1 2 1\n4 1 5 1\n", "4 30\n3 1 2 1\n4 1 5 1\n" ]
[ "354395703\n", "30\n", "1925486\n", "135\n", "354\n", "2043587\n", "2085832\n", "6296208\n", "689118492\n", "338389541\n" ]
CodeContests
The problem of hiding a part of a formula and searching for the hidden number is called verbal arithmetic. This time, I'm dealing with an expression in which some numbers in the expression are hidden by X. Enter the following formula and create a program that outputs the result. Formula * A simple one-line addition e...
stdin
null
1,214
1
[ "123+4X6=X79\n12X+4X6=X79\nXX22+89=X2XX\n" ]
[ "5\nNA\n1\n" ]
[ "123+4X6=X79\n12X+4X7=X79\nXX22+89=X2XX\n", "123+5X6=X79\n12X+4X7=X79\nXX22+89=X2XX\n", "123+5X6=X89\n12X+4X7=X79\nXX22+89=X2XX\n", "127+5XX=638\n1+X14X7=X59\nXX32+89=X2XX\n", "123+4X6=X79\n12X+4X6=X79\nXX12+89=X2XX\n", "1X3+426=X79\n12X+4X7=X79\nXX22+89=X2XX\n", "127+5X6=X39\n12X+4X7=X79\nXX22+89=X2XX\...
[ "5\nNA\nNA\n", "NA\nNA\nNA\n", "6\nNA\nNA\n", "1\nNA\nNA\n", "5\nNA\nNA\n", "5\nNA\nNA\n", "NA\nNA\nNA\n", "5\nNA\nNA\n", "NA\nNA\nNA\n", "NA\nNA\nNA\n" ]
CodeContests
In Takahashi Kingdom, there is a east-west railroad and N cities along it, numbered 1, 2, 3, ..., N from west to east. A company called AtCoder Express possesses M trains, and the train i runs from City L_i to City R_i (it is possible that L_i = R_i). Takahashi the king is interested in the following Q matters: * The ...
stdin
null
2,724
1
[ "10 3 2\n1 5\n2 8\n7 10\n1 7\n3 10\n", "2 3 1\n1 1\n1 2\n2 2\n1 2\n", "10 10 10\n1 6\n2 9\n4 5\n4 7\n4 7\n5 8\n6 6\n6 7\n7 9\n10 10\n1 8\n1 9\n1 10\n2 8\n2 9\n2 10\n3 8\n3 9\n3 10\n1 10\n" ]
[ "1\n1\n", "3\n", "7\n9\n10\n6\n8\n9\n6\n7\n8\n10\n" ]
[ "10 3 2\n1 5\n2 8\n7 10\n1 7\n3 3\n", "10 3 2\n1 10\n2 8\n7 10\n1 7\n3 10\n", "10 10 10\n1 6\n2 9\n4 5\n4 7\n4 7\n5 8\n6 6\n6 7\n7 9\n10 10\n1 8\n1 9\n1 10\n2 8\n2 7\n2 10\n3 8\n3 9\n3 10\n1 10\n", "10 3 2\n1 5\n2 8\n7 10\n1 2\n3 3\n", "10 3 2\n1 10\n3 8\n7 10\n1 7\n3 10\n", "10 3 2\n1 10\n5 8\n7 10\n1 10...
[ "1\n0\n", "0\n1\n", "7\n9\n10\n6\n5\n9\n6\n7\n8\n10\n", "0\n0\n", "0\n2\n", "3\n2\n", "1\n1\n", "7\n9\n10\n6\n5\n9\n6\n7\n8\n9\n", "7\n9\n10\n5\n4\n8\n5\n6\n7\n8\n", "0\n" ]
CodeContests
Recently Oz has found a magical string consisting of single digit "1". After experimenting on the string, Oz found a weird magical property of the string that is whenever he touches the string then each digit "1" of string changed to digit "0" and each digit "0" of string changed to "01". Oz found this property intere...
stdin
null
2,000
1
[ "2\n1\n2\n\nSAMPLE\n" ]
[ "0 1\n1 1\n" ]
[ "20\n61\n62\n63\n64\n65\n66\n67\n68\n85\n70\n71\n72\n73\n74\n75\n76\n77\n78\n79\n80\n", "20\n41\n42\n43\n44\n45\n46\n47\n48\n49\n60\n51\n52\n53\n54\n55\n56\n57\n58\n59\n60\n", "2\n1\n2\n\nSANPLE\n", "20\n85\n62\n63\n64\n65\n66\n67\n68\n85\n70\n71\n72\n73\n74\n75\n76\n77\n78\n79\n80\n", "20\n41\n42\n43\n44\n...
[ "1548008755920 2504730781961\n2504730781961 4052739537881\n4052739537881 6557470319842\n6557470319842 10610209857723\n10610209857723 17167680177565\n17167680177565 27777890035288\n27777890035288 44945570212853\n44945570212853 72723460248141\n160500643816367088 259695496911122585\n117669030460994 190392490709135\n19...
CodeContests
Takahashi is practicing shiritori alone again today. Shiritori is a game as follows: * In the first turn, a player announces any one word. * In the subsequent turns, a player announces a word that satisfies the following conditions: * That word is not announced before. * The first character of that word is the same a...
stdin
null
4,583
1
[ "4\nhoge\nenglish\nhoge\nenigma\n", "9\nbasic\nc\ncpp\nphp\npython\nnadesico\nocaml\nlua\nassembly\n", "3\nabc\narc\nagc\n", "8\na\naa\naaa\naaaa\naaaaa\naaaaaa\naaa\naaaaaaa\n" ]
[ "No\n", "Yes\n", "No\n", "No\n" ]
[ "4\nhoge\nenglish\nhnge\nenigma\n", "9\nbasic\nc\npcp\nphp\npython\nnadesico\nocaml\nlua\nassembly\n", "3\naac\narc\nagc\n", "8\na\naa\naaa\naaaa\naaaaa\naaa`aa\naaa\naaaaaaa\n", "4\nhoge\nenglish\nhnge\nemigma\n", "9\nb`sic\nc\npcp\nphp\npython\nnadesico\nocaml\nlua\nassembly\n", "3\naac\ncra\nagc\n", ...
[ "Yes\n", "No\n", "No\n", "No\n", "Yes\n", "No\n", "Yes\n", "No\n", "No\n", "No\n" ]
CodeContests
We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing. We have to build the tower abiding by the following ...
stdin
null
4,237
1
[ "5 2\n", "4 2\n" ]
[ "4\n", "3\n" ]
[ "5 4\n", "4 8\n", "6 8\n", "10 8\n", "10 4\n", "15 3\n", "29 3\n", "29 5\n", "3 7\n", "1 14\n" ]
[ "5\n", "4\n", "6\n", "9\n", "7\n", "8\n", "10\n", "13\n", "3\n", "1\n" ]
CodeContests
You have $N$ items that you want to put them into a knapsack of capacity $W$. Item $i$ ($1 \le i \le N$) has weight $w_i$ and value $v_i$ for the weight. When you put some items into the knapsack, the following conditions must be satisfied: * The total value of the items is as large as possible. * The total weight of...
stdin
null
1,386
1
[ "1 100\n100000 100000\n", "3 50\n60 10\n100 20\n120 30\n", "3 50\n60 13\n100 23\n120 33\n" ]
[ "100\n", "240\n", "210.90909091\n" ]
[ "3 50\n60 10\n110 20\n120 30\n", "0 50\n60 10\n110 20\n120 30\n", "3 14\n60 10\n100 20\n120 30\n", "1 50\n60 13\n100 23\n120 33\n", "3 50\n59 10\n110 20\n120 30\n", "1 100\n100001 100000\n", "3 8\n60 10\n100 20\n120 30\n", "3 50\n59 10\n010 20\n120 30\n", "1 38\n118 1\n010 20\n26 20\n", "1 100\n10...
[ "250.0000000000\n", "0.0000000000\n", "80.0000000000\n", "60.0000000000\n", "249.0000000000\n", "100.0010000000\n", "48.0000000000\n", "184.0000000000\n", "118.0000000000\n", "99.0108910891\n" ]
CodeContests
Mr. A came to Aizu for sightseeing. You can overlook the Aizu Basin from the window of the hotel where you stayed. As I was looking at the scenery, I noticed a piece of the photo on the floor. Apparently I took the outside view from the window. "Which area did you take?" A asked, holding the photo so that the view outs...
stdin
null
3,163
1
[ "8 4\n2 1 3 1 1 5 1 3\n2 3 2 4 1 0 2 1\n0 3 1 2 1 1 4 2\n1 2 3 2 1 1 5 4\n0 2 0 1 1 3 2 1\n1 3 1 2 2 4 3 2\n5 1 2 1 4 1 1 5\n4 1 1 0 1 2 2 1\n2 -1 -1 -1\n0 3 -1 -1\n-1 2 2 4\n-1 1 -1 1\n5 3\n1 0 2 3 5\n2 3 7 2 1\n2 5 4 2 2\n8 9 0 3 3\n3 6 0 4 7\n-1 -1 2\n-1 3 5\n0 4 -1\n0 0\n" ]
[ "4 2\nNA\n" ]
[ "8 4\n2 1 3 1 1 5 1 3\n2 3 2 4 1 0 2 1\n0 3 0 2 1 1 4 2\n1 2 3 2 1 1 5 4\n0 2 0 1 1 3 2 1\n1 3 1 2 2 4 3 2\n5 1 2 1 4 1 1 5\n4 1 1 0 1 2 2 1\n2 -1 -1 -1\n0 3 -1 -1\n-1 2 2 4\n-1 1 -1 1\n5 3\n1 0 2 3 5\n2 3 7 2 1\n2 5 4 2 2\n8 9 0 3 3\n3 6 0 4 7\n-1 -1 2\n-1 3 5\n0 4 -1\n0 0\n", "8 4\n2 1 3 1 1 5 1 3\n2 3 2 4 1 0...
[ "4 2\nNA\n", "NA\nNA\n", "NA\n5 3\n", "4 2\nNA\n", "4 2\nNA\n", "4 2\nNA\n", "NA\nNA\n", "NA\nNA\n", "NA\nNA\n", "NA\nNA\n" ]
CodeContests
Usoperanto is an artificial spoken language designed and regulated by Usoperanto Academy. The academy is now in study to establish Strict Usoperanto, a variation of the language intended for formal documents. In Usoperanto, each word can modify at most one other word, and modifiers are always put before modifiees. For...
stdin
null
784
1
[ "3\n3 -1\n4 0\n5 0\n", "3\n10 -1\n10 0\n10 1\n", "4\n1 -1\n1 0\n1 1\n1 0\n" ]
[ "4\n", "0\n", "1\n" ]
[ "3\n3 -1\n4 0\n4 0\n", "3\n19 -1\n10 0\n10 1\n", "4\n1 -1\n2 0\n1 1\n1 0\n", "4\n1 -1\n1 0\n1 1\n2 0\n", "3\n3 -1\n5 0\n8 0\n", "3\n19 -1\n11 0\n11 0\n", "3\n10 -1\n10 0\n10 0\n", "3\n10 -1\n7 0\n10 0\n", "3\n3 -1\n8 0\n8 0\n", "4\n0 -1\n1 0\n1 0\n1 0\n" ]
[ "4\n", "0\n", "1\n", "2\n", "5\n", "11\n", "10\n", "7\n", "8\n", "3\n" ]
CodeContests
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: Move...
stdin
null
3,040
1
[ "3 7\n-10 -3 0 9 -100 2 17\n", "2 5\n10 12 1 2 14\n", "100 1\n-100000\n" ]
[ "19\n", "5\n", "0\n" ]
[ "3 7\n-10 -1 0 9 -100 2 17\n", "100 1\n-151489\n", "3 7\n-8 -1 0 9 -100 2 17\n", "3 7\n-10 -3 0 9 -100 2 18\n", "2 5\n10 12 1 4 14\n", "6 7\n-8 -1 0 9 -100 2 17\n", "2 5\n10 12 1 4 21\n", "2 7\n-8 -1 0 9 -100 2 17\n", "3 7\n-10 -3 0 9 -5 0 17\n", "3 7\n-8 -1 0 9 -100 0 17\n" ]
[ "18\n", "0\n", "17\n", "19\n", "7\n", "1\n", "11\n", "25\n", "10\n", "16\n" ]
CodeContests
Problem statement Mr. K, a student of the magic department of a certain university, lives in a vast mansion. There was a forest behind the mansion, but there were places where no trees were growing. I felt that it would look bad from the mansion as it was, so Mr. K decided to plant a tree in a place where no trees wer...
stdin
null
2,181
1
[ "4 4\n0 0 0 1\n0 1 1 0\n0 1 1 0\n1 0 0 0\n" ]
[ "1 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 1\n" ]
[ "4 4\n0 0 0 1\n0 1 1 0\n1 1 1 0\n1 0 0 0\n", "4 4\n0 0 0 1\n0 0 1 0\n1 1 1 0\n1 0 0 0\n", "2 4\n0 0 0 1\n0 1 1 0\n1 1 1 0\n1 0 0 0\n", "4 4\n0 0 0 0\n0 0 1 0\n1 1 1 0\n1 0 0 0\n", "4 4\n0 0 0 0\n0 0 0 0\n1 1 1 0\n1 0 0 0\n", "2 2\n0 0 0 1\n0 1 1 0\n1 1 1 0\n2 0 0 0\n", "2 2\n0 1 0 1\n0 1 1 0\n1 1 1 0\n4...
[ "0 0 0 0\n1 0 0 0\n1 1 1 1\n1 0 0 1\n", "0 1 0 0\n0 1 1 1\n1 0 1 1\n1 1 0 1\n", "0 1 1 0\n1 1 1 0\n", "1 0 1 1\n0 1 1 0\n1 0 1 0\n1 1 0 0\n", "1 0 0 1\n1 0 0 1\n1 0 0 0\n1 1 1 0\n", "1 0\n0 0\n", "0 1\n0 1\n", "1 0\n1 1\n", "0 0 0 1\n1 0 0 1\n0 0 0 0\n1 0 0 0\n", "1 1 0 1\n0 0 0 0\n" ]
CodeContests
Saxie is a programming enthusiast. He has always been amazed by the beauty of strings. He always dreams of going to Byteland and playing with strings. One day he had a nightmare that Dr. Evil had attacked the strings. When he came forward to protect the strings, Dr. Evil asked him if every substring of S has its revers...
stdin
null
248
1
[ "2\naba\nax\n\nSAMPLE\n" ]
[ "YES\nNO\n" ]
[ "2\naba\nxa\n\nSAMPLE\n", "2\naab\n`x\n\nTAMPLE\n", "2\naba\nx`\n\nSAMPLE\n", "2\naba\n`x\n\nSAMPLE\n", "2\naba\n`x\n\nTAMPLE\n", "2\naab\nx`\n\nTAMPLE\n", "2\nbaa\nx`\n\nTAMPLE\n", "2\naab\nxa\n\nTAMPLE\n", "2\nbaa\nxa\n\nTAMPLE\n", "2\nbaa\nxa\n\nTMAPLE\n" ]
[ "YES\nNO\n", "NO\nNO\n", "YES\nNO\n", "YES\nNO\n", "YES\nNO\n", "NO\nNO\n", "NO\nNO\n", "NO\nNO\n", "NO\nNO\n", "NO\nNO\n" ]
CodeContests
Problem G: Nezumi's Treasure There were a mouse and a cat living in a field. The mouse stole a dried fish the cat had loved. The theft was found soon later. The mouse started running as chased by the cat for the dried fish. There were a number of rectangular obstacles in the field. The mouse always went straight ahea...
stdin
null
389
1
[ "8\n0 0 2 1\n2 2 4 3\n5 3 7 4\n7 5 9 6\n0 2 1 4\n2 4 3 6\n6 0 7 2\n8 2 9 4\n", "4\n0 0 2 1\n3 0 4 2\n0 2 1 4\n2 3 4 4\n" ]
[ "8\n", "4\n" ]
[ "8\n0 0 2 1\n2 2 4 3\n2 3 7 4\n7 5 9 6\n0 2 1 4\n2 4 3 6\n6 0 7 2\n8 2 9 4\n", "4\n0 0 2 1\n0 0 4 2\n0 2 1 4\n1 3 4 4\n", "4\n0 0 2 1\n3 0 4 2\n0 2 1 4\n1 3 4 4\n", "8\n0 0 4 1\n2 2 4 3\n2 3 7 4\n7 5 9 6\n0 2 1 4\n2 4 3 6\n6 0 7 2\n8 2 9 4\n", "8\n0 0 4 1\n2 2 4 3\n2 3 7 4\n7 5 9 6\n0 2 1 4\n2 4 3 6\n6 0 7 ...
[ "4\n", "0\n", "4\n", "4\n", "4\n", "0\n", "4\n", "0\n", "4\n", "0\n" ]
CodeContests
Joisino is planning on touring Takahashi Town. The town is divided into square sections by north-south and east-west lines. We will refer to the section that is the x-th from the west and the y-th from the north as (x,y). Joisino thinks that a touring plan is good if it satisfies the following conditions: * Let (p,q)...
stdin
null
771
1
[ "1 2 3 4 5 6\n1 2 3 4 5 6\n", "1 1 2 2 3 4\n1 1 2 2 3 3\n", "77523 89555 420588 604360 845669 973451\n2743 188053 544330 647651 709337 988194\n" ]
[ "2346\n", "10\n", "137477680\n" ]
[ "2 1 2 2 3 4\n1 1 2 2 3 3\n", "1 1 2 3 3 4\n1 1 2 2 3 3\n", "1 1 2 3 3 4\n0 1 2 2 3 3\n", "1 1 2 3 3 5\n0 1 2 2 3 3\n", "0 2 3 4 5 6\n1 2 3 4 5 6\n", "1 1 2 3 3 4\n0 2 2 2 3 3\n", "0 1 2 2 3 4\n1 1 2 3 3 3\n", "1 2 2 4 5 6\n1 2 3 4 5 6\n", "1 1 2 2 3 8\n1 1 2 2 3 3\n", "77523 89555 420588 604360 8...
[ "0\n", "19\n", "52\n", "99\n", "4840\n", "60\n", "43\n", "3212\n", "54\n", "295890985\n" ]
CodeContests
Ninja Atsushi guards the town from the roof of the Ninja Building from early morning to late night every day. This Ninja Building is two adjacent buildings of the same floor, and Atsushi's daily routine is to jump between buildings and head to the rooftop for security. Because these two buildings are cleaned frequentl...
stdin
null
1,412
1
[ "8\n0 0 0 2 2 2 0 0\n1 1 1 1 0 0 0 0\n4\n1 1 2 2\n0 0 2 2\n0\n" ]
[ "4\nNA\n" ]
[ "8\n0 0 0 2 2 2 0 0\n1 1 1 1 1 0 0 0\n4\n1 1 2 2\n0 0 2 2\n0\n", "8\n0 0 0 2 2 2 0 0\n1 1 1 1 1 0 0 0\n2\n1 1 2 2\n0 0 2 2\n0\n", "8\n0 0 0 2 2 2 0 0\n0 1 1 1 1 0 0 0\n2\n1 1 2 2\n0 0 2 2\n0\n", "8\n0 0 0 2 2 2 0 1\n1 1 1 1 0 0 0 0\n4\n1 1 2 2\n0 0 2 2\n0\n", "8\n0 0 0 2 2 2 0 0\n1 1 2 1 1 0 0 0\n2\n1 1 2 2...
[ "2\nNA\n", "2\n0\n", "3\n0\n", "4\nNA\n", "4\n0\n", "2\n2\n", "3\n2\n", "3\n1\n", "NA\n0\n", "4\n2\n" ]
CodeContests
Median of K numbers is defined as the (K/2)th smallest number, if K is even; and the ((K+1)/2)th smallest number if K is odd. For example, median of the 4 numbers: 2 1 8 7 is the 2nd smallest number i.e. 2, and the median of the 5 numbers: 2 1 8 7 6 is the 3rd smallest number i.e. 6. In this problem, you'll be g...
stdin
null
2,637
1
[ "5\n10\n5\n1\n2\n15\n\nSAMPLE\n" ]
[ "27\n" ]
[ "5\n11\n5\n1\n2\n15\n\nSAMPLE\n", "5\n11\n5\n1\n4\n15\n\nSAMPLE\n", "5\n11\n10\n1\n4\n15\n\nSALPLE\n", "5\n11\n19\n1\n4\n15\n\nSALOLE\n", "5\n11\n19\n1\n4\n1\n\nSALOLE\n", "5\n11\n8\n1\n4\n1\n\nSALOLE\n", "5\n11\n8\n1\n0\n1\n\nSALOLE\n", "5\n11\n13\n0\n0\n1\n\nSAMOLE\n", "5\n11\n13\n0\n-1\n0\n\nSAMO...
[ "28\n", "30\n", "45\n", "48\n", "41\n", "35\n", "29\n", "34\n", "33\n", "39\n" ]