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 | Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode:
for i = 1 to A.length-1
key = A[i]
/* insert A[i] into the sorted sequence A[0,...,j-1] */
j = i - 1
while j >= 0 and A[j] > key
A[j+1] = A[j]
j--
A[j+1] = key
Note... | stdin | null | 3,896 | 1 | [
"3\n1 2 3\n",
"6\n5 2 4 6 1 3\n"
] | [
"1 2 3\n1 2 3\n1 2 3\n",
"5 2 4 6 1 3\n2 5 4 6 1 3\n2 4 5 6 1 3\n2 4 5 6 1 3\n1 2 4 5 6 3\n1 2 3 4 5 6\n"
] | [
"3\n2 2 3\n",
"6\n5 2 5 6 1 3\n",
"3\n2 4 3\n",
"6\n5 2 5 8 1 3\n",
"3\n2 4 5\n",
"6\n5 4 5 8 1 3\n",
"3\n2 4 8\n",
"6\n5 4 5 7 1 3\n",
"3\n2 6 8\n",
"6\n5 4 5 7 1 0\n"
] | [
"2 2 3\n2 2 3\n2 2 3\n",
"5 2 5 6 1 3\n2 5 5 6 1 3\n2 5 5 6 1 3\n2 5 5 6 1 3\n1 2 5 5 6 3\n1 2 3 5 5 6\n",
"2 4 3\n2 4 3\n2 3 4\n",
"5 2 5 8 1 3\n2 5 5 8 1 3\n2 5 5 8 1 3\n2 5 5 8 1 3\n1 2 5 5 8 3\n1 2 3 5 5 8\n",
"2 4 5\n2 4 5\n2 4 5\n",
"5 4 5 8 1 3\n4 5 5 8 1 3\n4 5 5 8 1 3\n4 5 5 8 1 3\n1 4 5 5 8 3\n1... |
CodeContests | Some chefs go for a tour lasting N days. They take packages of bread for food. Each package has K pieces of breads. On the i^th day, they eat Ai pieces of bread.
Unfortunately, chefs are very lazy people, and they always forget to close the package of breads, so each day the last piece of bread becomes exposed to mold ... | stdin | null | 3,899 | 1 | [
"3\n3 4\n3 1 2\n1 1\n1\n2 4\n8 8\n"
] | [
"2\n1\n4\n"
] | [
"3\n3 4\n3 1 2\n1 1\n1\n2 4\n8 1\n",
"3\n3 4\n3 1 2\n1 1\n1\n2 2\n8 1\n",
"3\n3 4\n6 1 2\n1 1\n1\n2 2\n8 1\n",
"3\n3 4\n6 1 2\n1 1\n1\n2 2\n10 1\n",
"3\n3 4\n3 1 0\n1 1\n1\n2 4\n8 8\n",
"3\n3 4\n3 1 4\n1 1\n1\n2 4\n8 1\n",
"3\n3 5\n3 1 2\n1 1\n2\n2 2\n8 1\n",
"3\n3 4\n3 1 2\n1 1\n1\n2 4\n3 1\n",
"3\... | [
"2\n1\n3\n",
"2\n1\n5\n",
"3\n1\n5\n",
"3\n1\n6\n",
"2\n1\n4\n",
"3\n1\n3\n",
"2\n2\n5\n",
"2\n1\n2\n",
"1\n1\n4\n",
"3\n1\n2\n"
] |
CodeContests | In 2937, DISCO creates a new universe called DISCOSMOS to celebrate its 1000-th anniversary.
DISCOSMOS can be described as an H \times W grid. Let (i, j) (1 \leq i \leq H, 1 \leq j \leq W) denote the square at the i-th row from the top and the j-th column from the left.
At time 0, one robot will be placed onto each s... | stdin | null | 1,283 | 1 | [
"869 120 1001\n",
"2 2 1\n"
] | [
"672919729\n",
"9\n"
] | [
"869 80 1001\n",
"328 80 1001\n",
"328 102 1011\n",
"328 102 1111\n",
"279 102 1111\n",
"25 102 1111\n",
"25 122 1111\n",
"25 63 1111\n",
"25 89 1111\n",
"1486 120 1001\n"
] | [
"540377089\n",
"238803603\n",
"261361566\n",
"647647330\n",
"58769\n",
"939039550\n",
"991048692\n",
"324726435\n",
"313816333\n",
"960152848\n"
] |
CodeContests | G: Travel Support-Travel Support-
story
I, Honoka Kosaka, 16 years old! I'm a student idol! !!
In order to give a live performance to convey the goodness of student idols to everyone, we invite many student idols to perform live at Akiba Stadium.
However, some live participants come from afar and it costs a lot of ... | stdin | null | 2,938 | 1 | [
"5 6\n100 80 70 60 50\n1 2 500\n2 5 100\n1 3 400\n1 4 200\n3 5 700\n4 5 800\n1\n5 3 600\n"
] | [
"0\n"
] | [
"5 6\n100 80 70 60 50\n1 2 500\n2 5 100\n1 3 400\n1 4 200\n3 5 700\n2 5 800\n1\n5 3 600\n",
"5 6\n100 80 70 60 50\n1 2 500\n2 5 101\n1 3 400\n1 4 200\n3 5 700\n4 5 800\n1\n5 3 600\n",
"5 6\n100 80 70 60 50\n2 2 500\n2 5 100\n1 3 400\n1 4 200\n3 5 1047\n2 5 800\n1\n5 3 600\n",
"5 6\n100 80 70 60 50\n3 2 500\n2... | [
"0\n",
"1\n",
"847\n",
"400\n",
"598\n599\n0\n",
"300\n",
"498\n",
"608\n609\n0\n",
"587\n588\n0\n",
"508\n509\n0\n"
] |
CodeContests | Write a program to check whether a triangle is valid or not, when the three angles of the triangle are the inputs. A triangle is valid if the sum of all the three angles is equal to 180 degress.
Input
The first line contains an integer T, total number of testcases. Then follow T lines, each line contains three angl... | stdin | null | 2,033 | 1 | [
"3 \n30 40 110\n45 45 90\n180 0 0\n"
] | [
"YES\nYES\nNO\n"
] | [
"3 \n30 40 110\n12 45 90\n180 0 0\n",
"3 \n30 40 111\n12 45 90\n180 0 0\n",
"3 \n30 77 110\n45 45 90\n180 0 0\n",
"3 \n30 40 111\n9 45 90\n180 0 0\n",
"3 \n16 40 111\n9 45 90\n180 0 0\n",
"3 \n16 77 111\n9 45 90\n180 0 0\n",
"3 \n16 77 111\n9 45 22\n180 0 0\n",
"3 \n25 77 111\n9 45 22\n180 0 0\n",
"... | [
"YES\nNO\nNO\n",
"NO\nNO\nNO\n",
"NO\nYES\nNO\n",
"NO\nNO\nNO\n",
"NO\nNO\nNO\n",
"NO\nNO\nNO\n",
"NO\nNO\nNO\n",
"NO\nNO\nNO\n",
"NO\nNO\nNO\n",
"NO\nNO\nNO\n"
] |
CodeContests | Nandu is stuck in a maze consisting of N rooms. Each room with room number x has a door leading into room number 2x (if 2x ≤ N) and another door leading into room number 2x+1 (if 2x+1 ≤ N). All these doors are 2-way doors ie. they can be opened from both the sides.
Some of these N rooms have monsters living in them.
... | stdin | null | 3,385 | 1 | [
"3 9\n001\n1 2\n1 3\n3 2\n2 1\n2 3\n3 1\n1 1\n2 2\n3 3\n\nSAMPLE\n"
] | [
"Yes\nNo\nNo\nYes\nNo\nNo\nYes\nYes\nNo\n"
] | [
"55 4\n0001100110100100011011001111011111100010010110100100001\n37 46\n48 24\n43 45\n41 33\n2 34\n11 5\n",
"3 9\n001\n1 2\n1 3\n3 2\n2 1\n2 3\n3 1\n1 1\n2 2\n3 2\n\nSAMPLE\n",
"55 4\n0001100110100100111011001111011111100010010110100100001\n37 46\n30 24\n43 35\n41 33\n2 34\n11 5\n",
"55 6\n00011001101001000110... | [
"No\nYes\nNo\nNo\n",
"Yes\nNo\nNo\nYes\nNo\nNo\nYes\nYes\nNo\n",
"No\nNo\nNo\nNo\n",
"No\nYes\nNo\nNo\nNo\nNo\n",
"Yes\nYes\nNo\nNo\n",
"No\nNo\n",
"No\nYes\n",
"Yes\nYes\nNo\nYes\nNo\nNo\nYes\nYes\nNo\n",
"Yes\nNo\nNo\nNo\n",
"No\nYes\nYes\nNo\n"
] |
CodeContests | Write a program which manipulates a sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$ by the following operations:
* min($b, e$): report the minimum element in $a_b, a_{b+1}, ..., a_{e-1}$
* max($b, e$): report the maximum element in $a_b, a_{b+1}, ..., a_{e-1}$
Constraints
* $1 \leq n \leq 1,000$
* $-1,000,000,000 \leq a... | stdin | null | 4,211 | 1 | [
"7\n8 3 7 1 9 1 4\n3\n0 0 3\n0 1 5\n1 0 7\n"
] | [
"3\n1\n9\n"
] | [
"7\n8 3 0 1 9 1 4\n3\n0 0 3\n0 1 5\n1 0 7\n",
"7\n8 3 0 0 9 1 4\n3\n0 0 3\n1 1 5\n1 0 7\n",
"7\n8 3 0 0 9 1 4\n6\n0 0 3\n1 1 5\n1 0 7\n",
"7\n8 3 0 1 14 1 4\n3\n0 1 3\n0 1 5\n1 0 7\n",
"7\n2 2 -1 2 9 1 0\n3\n0 0 3\n0 1 5\n1 0 7\n",
"7\n8 3 7 1 9 1 4\n3\n1 0 3\n0 1 5\n1 0 7\n",
"7\n8 3 0 -1 9 1 4\n3\n0 0... | [
"0\n0\n9\n",
"0\n9\n9\n",
"0\n9\n9\n9\n9\n9\n",
"0\n0\n14\n",
"-1\n-1\n9\n",
"8\n1\n9\n",
"0\n-1\n9\n",
"0\n6\n8\n",
"0\n9\n9\n9\n9\n",
"2\n0\n9\n"
] |
CodeContests | We understand that reading English is a great pain to many of you. So we’ll keep this problem statememt simple. Write a program that reports the point equally distant from a set of lines given as the input. In case of no solutions or multiple solutions, your program should report as such.
Input
The input consists o... | stdin | null | 3,528 | 1 | [
"2\n-35 -35 100 100\n-49 49 2000 -2000\n4\n0 0 0 3\n0 0 3 0\n0 3 3 3\n3 0 3 3\n4\n0 3 -4 6\n3 0 6 -4\n2 3 6 6\n-1 2 -4 6\n0\n"
] | [
"Many\n1.5000 1.5000\n1.000 1.000\n"
] | [
"2\n-35 -35 100 100\n-49 49 2000 -2000\n4\n0 0 0 3\n0 0 3 0\n0 3 3 3\n6 0 3 3\n4\n0 3 -4 6\n3 0 6 -4\n2 3 6 6\n-1 2 -4 6\n0\n",
"2\n-35 -35 100 100\n-49 49 1588 -2000\n4\n0 0 0 3\n0 0 3 0\n0 3 3 3\n3 0 3 3\n4\n0 3 -4 6\n3 0 6 -4\n2 3 6 6\n-1 2 -4 6\n0\n",
"2\n-35 -35 100 100\n-49 49 2000 -2000\n4\n0 0 0 3\n0 0 ... | [
"Many\nNone\n1.000000 1.000000\n",
"Many\n1.500000 1.500000\n1.000000 1.000000\n",
"Many\nNone\nNone\n",
"Many\n1.500000 1.500000\nNone\n",
"Many\nMany\n",
"Many\n",
"Many\nNone\nMany\n",
"Many\nNone\n1.000000 1.000000\n",
"Many\nNone\n1.000000 1.000000\n",
"Many\nNone\nNone\n"
] |
CodeContests | For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $L$, find the minimum of each possible sub-arrays with size $L$ and print them from the beginning. For example, for an array $\\{1, 7, 7, 4, 8, 1, 6\\}$ and $L = 3$, the possible sub-arrays with size $L = 3$ includes $\\{1, 7, 7\\}$, $\\{7, 7, ... | stdin | null | 2,980 | 1 | [
"7 3\n1 7 7 4 8 1 6\n"
] | [
"1 4 4 1 1\n"
] | [
"7 3\n1 7 7 4 6 1 6\n",
"7 3\n1 7 3 4 6 1 6\n",
"7 3\n1 7 0 4 6 1 6\n",
"7 3\n0 7 7 4 8 1 6\n",
"7 3\n1 7 7 4 6 1 0\n",
"7 3\n0 7 7 4 8 2 6\n",
"7 3\n1 7 7 5 6 1 0\n",
"7 2\n1 7 0 4 5 1 6\n",
"7 3\n1 7 7 3 6 1 0\n",
"7 3\n1 2 3 3 6 1 8\n"
] | [
"1 4 4 1 1\n",
"1 3 3 1 1\n",
"0 0 0 1 1\n",
"0 4 4 1 1\n",
"1 4 4 1 0\n",
"0 4 4 2 2\n",
"1 5 5 1 0\n",
"1 0 0 4 1 1\n",
"1 3 3 1 0\n",
"1 2 3 1 1\n"
] |
CodeContests | There are 'n' coins kept on the table, numbered from 0 to 'n-1'. Initially, each coin is kept tails up. You have to perform two types of operations :
1) Flip all coins numbered between A and B inclusive. This is represented by the command:
0
A
B
2) Answer how many coins numbered between A and B inclusive are heads up. ... | stdin | null | 1,437 | 1 | [
"7\n3\n0\n3\n5\n1\n0\n6\n1\n3\n4\n\nSAMPLE\n"
] | [
"3\n2\n"
] | [
"7\n3\n0\n3\n1\n1\n0\n6\n1\n3\n4\n",
"7\n3\n0\n3\n5\n1\n0\n6\n1\n6\n4\n\nSAMPLE\n",
"7\n3\n0\n3\n5\n0\n0\n6\n1\n6\n4\n\nSAMPLE\n",
"7\n3\n0\n4\n5\n1\n0\n6\n1\n10\n4\n\nSAMPLE\n",
"7\n2\n0\n3\n5\n1\n0\n6\n1\n3\n4\n",
"7\n3\n0\n3\n3\n1\n0\n6\n1\n10\n4\n\nSAMPLE\n",
"7\n3\n0\n1\n5\n1\n0\n5\n1\n6\n4\n\nMASP... | [
"0\n0\n",
"3\n0\n",
"0\n",
"2\n0\n",
"3\n",
"1\n0\n",
"5\n0\n",
"1\n",
"5\n",
"4\n0\n"
] |
CodeContests | Aarav has just graduated from the university. Now he is going to travel along his country. More precisely: there are N cities with integer coordinates. His plan is to travel between each pair of the cities.
The distance between city A with coordinates (x1, y1) and city B with coordinates (x2, y2) is equal to |x1 - x2... | stdin | null | 3,066 | 1 | [
"4\n-1 5\n1 6\n3 5\n2 3\n\nSAMPLE\n"
] | [
"22\n"
] | [
"21\n10 18\n5 9\n4 -6\n13 1\n17 -10\n-8 19\n-13 19\n17 -20\n-12 5\n10 0\n14 -14\n12 -4\n15 -13\n0 -18\n-17 -11\n-3 19\n-3 12\n0 -17\n-6 -13\n-6 -2\n20 2\n",
"37\n7 -14\n18 -6\n-20 -20\n-15 12\n5 18\n6 7\n-10 -2\n-17 -17\n9 -8\n-14 -16\n12 -4\n17 -2\n-7 -2\n-13 19\n20 -9\n18 5\n19 -4\n3 -4\n-20 1\n9 19\n-14 5\n18 ... | [
"5970\n",
"20056\n",
"23\n",
"6144\n",
"19966\n",
"20\n",
"6284\n",
"19800\n",
"6296\n",
"19830\n"
] |
CodeContests | You had an array of integer numbers. You also had a beautiful operations called "Copy-Paste" which allowed you to copy any contiguous subsequence of your array and paste it in any position of your array. For example, if you have array [1, 2, 3, 4, 5] and copy it's subsequence from the second to the fourth element and p... | stdin | null | 2,464 | 1 | [
"2\n5\n1 1 1 1 1\n5\n1 2 3 1 2\n"
] | [
"1\n3\n"
] | [
"2\n5\n1 1 1 1 1\n5\n1 2 6 1 2\n",
"2\n5\n1 0 1 1 1\n5\n1 3 3 1 2\n",
"2\n5\n1 0 1 2 1\n5\n1 3 3 1 2\n",
"2\n5\n1 1 1 1 1\n5\n1 2 6 0 2\n",
"2\n5\n1 0 1 1 1\n5\n0 3 3 1 2\n",
"2\n5\n1 0 1 2 1\n5\n1 3 3 1 3\n",
"2\n5\n1 1 1 1 1\n5\n1 2 1 1 2\n",
"2\n5\n1 0 1 1 1\n5\n0 6 3 1 2\n",
"2\n5\n0 1 1 1 1\n5\... | [
"1\n3\n",
"2\n3\n",
"3\n3\n",
"1\n4\n",
"2\n4\n",
"3\n2\n",
"1\n2\n",
"2\n5\n",
"2\n2\n",
"3\n4\n"
] |
CodeContests | A substring is a string of characters that is contained in another string. For example, the substrings of "abcdef" could be "abc", "bc", "cdef", "e" and so on. But, "bca", "ace", and "g" are not substrings of "abcdef".
Your task is to count the number of non-empty substrings possible of a given string such that all c... | stdin | null | 605 | 1 | [
"xxxyx\n\nSAMPLE\n"
] | [
"8\n"
] | [
"vxxqwrmmkwwxvuuttolhhhmnvgeeyklltwwrssscwaajttuoqowwwwwooodbjjjjuiuwsssghhzzkjjjbxlmrmbduuuiizyhiiog\n",
"abcdefghhjklmnopqrstuvwxyz\n",
"xyxyx\n\nSAMPLE\n",
"vxxqwrmmkwwxveuttolhhhmnvgueyklltwwrssscwaajttuoqowwwwwooodbjjjjuiuwsssghhzzkjjjbxlmrmbduuuiizyhiiog\n",
"abcdeeghhjklmnopqrstuvwxyz\n",
"xyxxy\n\... | [
"148\n",
"27\n",
"5\n",
"146\n",
"28\n",
"6\n",
"29\n",
"7\n",
"143\n",
"140\n"
] |
CodeContests | “Can you answer this million dollar question ?” said the presenter to Little Achraf.
“Yes”, he responded.
“Ok … here is the question”.
We define a sequence A of strings of order L as follows:
A[n] = \sum\limits_{i = 0}^{L-1} A[n-L+i]; n ≥ L+1; where addition refers to string concatenation
A[n] ∈ [a-z A-Z 0-9]; ... | stdin | null | 5,002 | 1 | [
"2 2\n1 3 A\n3 5 B\n\nSAMPLE\n"
] | [
"1\n"
] | [
"4 11\n72 11 L\n1 3 Y\n2 5 d\n1 4 v\n70 12 B\n5 6 C\n72 10 f\n141 12 s\n1 3 n\n9580 19 L\n1 5 x\n",
"7 3\n1752 17 R\n1 3 U\n1 5 5\n2 8 Y\n",
"7 0\n1 7 X\n405 15 d\n",
"3 1\n100 11 N\n",
"2 2\n1 3 A\n3 5 A\n\nSAMPLE\n",
"11 0\n1 7 X\n405 15 d\n",
"7 4\n1752 17 R\n1 3 U\n1 5 5\n1 8 Y\n",
"10 1\n1 1 R\n5... | [
"0\n",
"14776336\n",
"614581561\n",
"3844\n",
"1\n",
"581171655\n",
"238328\n",
"451503950\n",
"993244711\n",
"62\n"
] |
CodeContests | You are given a string S consisting of lowercase English letters. We will write down this string, starting a new line after every w letters. Print the string obtained by concatenating the letters at the beginnings of these lines from top to bottom.
Constraints
* 1 \leq w \leq |S| \leq 1000
* S consists of lowercase E... | stdin | null | 4,743 | 1 | [
"lllll\n1\n",
"abcdefgh\n3\n",
"souuundhound\n2\n"
] | [
"lllll\n",
"adg\n",
"suudon\n"
] | [
"lllll\n2\n",
"abcdefgh\n4\n",
"dnuohdnuuuos\n2\n",
"llmll\n2\n",
"dnuoodnuuuhs\n2\n",
"llmll\n4\n",
"accdefgh\n5\n",
"dnuoodnuuuhs\n4\n",
"llmll\n6\n",
"hgfedcca\n5\n"
] | [
"lll\n",
"ae\n",
"duhnuo\n",
"lml\n",
"duonuh\n",
"ll\n",
"af\n",
"dou\n",
"l\n",
"hc\n"
] |
CodeContests | Imagine a game played on a line. Initially, the player is located at position 0 with N candies in his possession, and the exit is at position E. There are also N bears in the game. The i-th bear is located at x_i. The maximum moving speed of the player is 1 while the bears do not move at all.
When the player gives a c... | stdin | null | 104 | 1 | [
"3 9 1\n1 3 8\n",
"2 1000000000 1000000000\n1 999999999\n",
"3 9 3\n1 3 8\n"
] | [
"12\n",
"2999999996\n",
"16\n"
] | [
"3 9 1\n2 3 8\n",
"2 1000000000 1000000000\n1 199586132\n",
"3 9 3\n1 3 7\n",
"3 9 3\n1 0 7\n",
"2 1000001000 1000000000\n2 199586132\n",
"3 9 5\n1 0 7\n",
"2 1010001000 1000000000\n2 199586132\n",
"2 1010001000 1000001000\n4 125587868\n",
"3 9 1\n1 3 0\n",
"2 1010000000 1000000000\n1 999999999\n"... | [
"12\n",
"2000000000\n",
"16\n",
"15\n",
"2000001000\n",
"19\n",
"2010001000\n",
"2010002000\n",
"7\n",
"3009999996\n"
] |
CodeContests | Requirements
* All inputs are of non-negative integer value.
* T_{\text{max}} = 10000
* 200 \leq |V| \leq 400
* 1.5 |V| \leq |E| \leq 2 |V|
* 1 \leq u_{i}, v_{i} \leq |V| (1 \leq i \leq |E|)
* 1 \leq d_{u_i, v_i} \leq \lceil 4\sqrt{2|V|} \rceil (1 \leq i \leq |E|)
* The given graph has no self-loops / multiple edges a... | stdin | null | 2,801 | 1 | [
"5 7\n1 2 5\n5 3 4\n2 4 8\n1 5 1\n2 3 3\n4 5 3\n4 3 9\n4\n1\n1 2\n1\n2 5\n1\n3 4\n0\n"
] | [
"2\n-1\n1\n5\n"
] | [
"5 7\n1 2 5\n5 3 4\n2 4 12\n1 5 1\n2 3 3\n4 5 3\n4 3 9\n4\n1\n1 2\n1\n2 5\n1\n3 4\n0\n",
"5 7\n1 2 5\n5 3 4\n2 4 12\n1 5 1\n2 1 3\n4 5 3\n4 3 5\n7\n1\n1 1\n1\n2 5\n1\n3 4\n0\n",
"5 7\n1 2 5\n5 3 4\n2 4 12\n1 5 1\n2 1 3\n4 5 3\n4 3 9\n6\n1\n1 1\n1\n2 6\n1\n3 4\n0\n",
"5 7\n1 2 5\n5 3 4\n2 4 12\n1 5 1\n2 1 3\n4... | [
"-1\n-1\n-1\n-1\n",
"-1\n-1\n-1\n-1\n-1\n-1\n-1\n",
"-1\n-1\n-1\n-1\n-1\n-1\n",
"-1\n-1\n-1\n",
"-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n",
"-1\n",
"-1\n-1\n-1\n-1\n-1\n",
"-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n",
"-1\n-1\n",
"-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n"
] |
CodeContests | Takahashi has an empty string S and a variable x whose initial value is 0.
Also, we have a string T consisting of `0` and `1`.
Now, Takahashi will do the operation with the following two steps |T| times.
* Insert a `0` or a `1` at any position of S of his choice.
* Then, increment x by the sum of the digits in the o... | stdin | null | 2,995 | 1 | [
"1101\n",
"0111101101\n"
] | [
"5\n",
"26\n"
] | [
"1001\n",
"0111101111\n",
"1000\n",
"0111001111\n",
"1010\n",
"1010011111\n",
"0010001111\n",
"0010\n",
"0010001011\n",
"0001\n"
] | [
"5\n",
"28\n",
"4\n",
"27\n",
"6\n",
"29\n",
"23\n",
"3\n",
"21\n",
"2\n"
] |
CodeContests | problem
The IOI country consists of N towns from town 1 to town N, and the towns are connected by roads. The IOI country has K roads, all of which connect two different towns. Cars can move freely in both directions on the road, but they cannot go from one town to another through anything other than the road.
JOI, wh... | stdin | null | 3,362 | 1 | [
"6 6\n400 2\n200 1\n600 3\n1000 1\n300 5\n700 4\n1 2\n2 3\n3 6\n4 6\n1 5\n2 4\n",
"None\n"
] | [
"700\n",
"None\n"
] | [
"enoN\n",
"eooN\n",
"Nooe\n",
"Nood\n",
"Nopd\n",
"Ndpo\n",
"Mdpo\n",
"Mdpn\n",
"npdM\n",
"npdL\n"
] | [
"0\n",
"0\n",
"0\n",
"0\n",
"0\n",
"0\n",
"0\n",
"0\n",
"0\n",
"0\n"
] |
CodeContests | B: 階層的計算機 (Hierarchical Calculator)
Problem
Ebi-chan has N formulae: y = a_i x for i =1, ..., N (inclusive). Now she considers a subsequence of indices with length k: s_1, s_2, ..., s_k. At first, let x_0 be 1 and evaluate s_1-th formulae with x = x_0. Next, let x_1 be the output of s_1 and evaluate s_2-th formulae w... | stdin | null | 3,894 | 1 | [
"4\n2 0 -2 1\n"
] | [
"1\n1\n"
] | [
"4\n2 -1 -2 1\n",
"4\n2 0 -1 1\n",
"4\n1 -1 -2 0\n",
"4\n0 -1 -1 1\n",
"4\n-1 -1 0 2\n",
"4\n-1 -2 0 2\n",
"4\n2 -1 1 2\n",
"4\n-1 1 -2 0\n",
"4\n2 -1 2 2\n",
"4\n1 2 -1 1\n"
] | [
"3\n1\n2\n3\n",
"1\n1\n",
"2\n2\n3\n",
"0\n",
"1\n4\n",
"3\n1\n2\n4\n",
"2\n1\n4\n",
"2\n1\n3\n",
"3\n1\n3\n4\n",
"1\n2\n"
] |
CodeContests | Today is Sid’s birthday and he is very excited about this as he is giving a special birthday party to all his friends. In this party they are going to play a game for which Sid have to arrange all his friends in a row such that no two boys should be present which are adjacent to each other. There are total M girls and ... | stdin | null | 2,272 | 1 | [
"1\n3 2\n\nSAMPLE\n"
] | [
"72\n"
] | [
"1\n2 2\n\nSAMPLE\n",
"1\n2 4\n\nSAMPLE\n",
"1\n3 1\n\nSAMPLE\n",
"1\n2 1\n\nSAMPLE\n",
"1\n4 5\n\nUAMPLE\n",
"1\n4 1\n\nSAMPLE\n",
"1\n1 1\n\nSAMPLE\n",
"1\n6 1\n\nSAMQLE\n",
"1\n3 2\n\nUAMPLF\n",
"1\n10 1\n\nSAMQLE\n"
] | [
"12\n",
"-1\n",
"24\n",
"6\n",
"2880\n",
"120\n",
"2\n",
"5040\n",
"72\n",
"39916800\n"
] |
CodeContests | Ashima's mid term exams are just over. Since, its raining heavily outside, she can't go shopping.
So, she and her best friend Aishwarya have now decided to chill out by eating pizza, chocolates, biscuits, etc.. and playing some indoor games.
The pizza guy has just delivered the pizza, but they forgot to order any soft-... | stdin | null | 3,901 | 1 | [
"3\n1 3 1\n2 2 0\n2 1 1\n\nSAMPLE\n"
] | [
"Ashima\nAishwarya\nAshima\n"
] | [
"1272\n4 65 35\n5 47 2\n0 59 20\n2 41 14\n2 30 17\n2 26 22\n3 44 6\n4 65 10\n5 27 1\n6 0 31\n3 47 1\n6 16 26\n3 30 2\n7 49 12\n1 6 34\n7 48 9\n4 23 4\n7 7 7\n6 38 22\n3 34 32\n6 66 28\n3 61 2\n1 33 6\n3 11 33\n2 62 17\n7 52 29\n5 48 30\n2 30 18\n3 60 15\n7 38 5\n2 26 24\n7 51 29\n4 25 21\n5 54 9\n2 29 4\n0 51 3\n1 ... | [
"Ashima\nAshima\nAshima\nAshima\nAshima\nAishwarya\nAshima\nAshima\nAshima\nAshima\nAshima\nAishwarya\nAshima\nAshima\nAshima\nAshima\nAshima\nAshima\nAishwarya\nAshima\nAishwarya\nAshima\nAshima\nAshima\nAshima\nAshima\nAshima\nAishwarya\nAshima\nAshima\nAishwarya\nAshima\nAshima\nAshima\nAshima\nAshima\nAshima\nA... |
CodeContests | There is a square-shaped grid with N vertical rows and N horizontal columns. We will denote the square at the i-th row from the top and the j-th column from the left as (i,\ j).
Initially, each square is either white or black. The initial color of the grid is given to you as characters a_{ij}, arranged in a square sha... | stdin | null | 459 | 1 | [
"2\n..\n..\n",
"2\n#.\n.#\n",
"2\n",
"3\n.#.\n\n.#.\n",
"3\n...\n.#.\n...\n"
] | [
"-1\n",
"3\n",
"0\n",
"2\n",
"5\n"
] | [
"2\n/.\n..\n",
"2\n#.\n#.\n",
"3\n.#.\n\n.$.\n",
"3\n...\n.#.\n/..\n",
"2\n.\n#.\n",
"2\n#.\n-#\n",
"0\n",
"2\n./\n..\n",
"2\n#.\n#-\n",
"3\n.\".\n\n.$.\n"
] | [
"-1\n",
"2\n",
"6\n",
"5\n",
"4\n",
"3\n",
"-1\n",
"-1\n",
"2\n",
"-1\n"
] |
CodeContests | The huge maze The Squares has been newly completed in the famous theme park. Evacuation drills must be conducted under the guidance of the fire department, but the time required for the drills cannot be predicted due to the huge maze. Therefore, you decided to develop an evacuation drill simulator based on the followin... | stdin | null | 3,441 | 1 | [
"10 3\n##########\n#E.......X\n##########\n4 4\n####\n#N.#\n#..X\n####\n5 5\n#####\n#N..#\n###.X\n#S..#\n#####\n6 6\n######\n#..#X#\n#.EE.#\n####N#\n#....#\n######\n8 8\n##X#####\n#....E.#\n#####.##\n#.#...##\n#.W.#..#\n#.#.N#.X\n#X##.#.#\n########\n0 0\n",
"10 3\n\nE.......X\n\n4 4\n\nN.#\n..X\n\n5 5\n\nN..#\n.X... | [
"8\nNA\n9\n16\n10\n",
"8\nNA\n9\n16\n10\n"
] | [
"10 3\n##########\n#E.......X\n##########\n4 4\n####\n#N.#\n#..X\n####\n5 5\n#####\n#N..#\n###.X\n#S..#\n#####\n6 6\n######\n#..#X#\n#.EE.#\n####N#\n#....#\n######\n8 8\n##X#####\n#....E.#\n#####.##\n#.#...##\n#.W.#..#\n#-#.N#.X\n#X##.#.#\n########\n0 0\n",
"10 3\n\nE.......X\n\n4 4\n\nN.#\n..X\n\n5 5\n\nN..#\n.X... | [
"8\nNA\n9\n16\n23\n",
"8\n",
"8\nNA\n9\n",
"8\nNA\nNA\n",
"8\nNA\n",
"8\nNA\n0\n",
"8\nNA\n9\n16\n10\n",
"2\n",
"8\nNA\n8\n16\n10\n",
"8\nNA\n9\n16\n8\n"
] |
CodeContests | In AtCoder city, there are five antennas standing in a straight line. They are called Antenna A, B, C, D and E from west to east, and their coordinates are a, b, c, d and e, respectively.
Two antennas can communicate directly if the distance between them is k or less, and they cannot if the distance is greater than k.
... | stdin | null | 4,228 | 1 | [
"1\n2\n4\n8\n9\n15\n",
"15\n18\n26\n35\n36\n18\n"
] | [
"Yay!\n",
":(\n"
] | [
"1\n0\n4\n8\n9\n15\n",
"15\n18\n26\n35\n36\n2\n",
"1\n0\n8\n8\n9\n15\n",
"15\n18\n26\n35\n34\n2\n",
"1\n0\n5\n8\n9\n15\n",
"15\n18\n13\n35\n34\n2\n",
"1\n0\n5\n8\n4\n15\n",
"15\n5\n13\n35\n34\n2\n",
"1\n0\n5\n8\n8\n15\n",
"15\n5\n13\n35\n34\n3\n"
] | [
"Yay!\n",
":(\n",
"Yay!\n",
":(\n",
"Yay!\n",
":(\n",
"Yay!\n",
":(\n",
"Yay!\n",
":(\n"
] |
CodeContests | For given two sides of a triangle a and b and the angle C between them, calculate the following properties:
* S: Area of the triangle
* L: The length of the circumference of the triangle
* h: The height of the triangle with side a as a bottom edge
Input
The length of a, the length of b and the angle C are given in... | stdin | null | 1,150 | 1 | [
"4 3 90\n"
] | [
"6.00000000\n12.00000000\n3.00000000\n"
] | [
"4 3 130\n",
"4 3 11\n",
"2 3 90\n",
"3 3 130\n",
"4 5 11\n",
"2 4 90\n",
"2 3 130\n",
"1 5 11\n",
"2 5 90\n",
"2 3 190\n"
] | [
"4.59626665871\n13.3582153654\n2.29813332936\n",
"1.14485397226\n8.20039476726\n0.57242698613\n",
"3.0\n8.60555127546\n3.0\n",
"3.44719999404\n11.4378467222\n2.29813332936\n",
"1.90808995377\n10.3171608338\n0.954044976883\n",
"4.0\n10.472135955\n4.0\n",
"2.29813332936\n9.55120328224\n2.29813332936\n",
... |
CodeContests | Example
Input
5
5 8 1 3 5
1 2 4
2 3 3
2 4 3
1 5 7
Output
4 | stdin | null | 2,900 | 1 | [
"5\n5 8 1 3 5\n1 2 4\n2 3 3\n2 4 3\n1 5 7\n"
] | [
"4\n"
] | [
"5\n5 8 1 3 5\n1 2 4\n2 3 3\n2 4 3\n1 7 7\n",
"5\n5 8 1 4 5\n1 3 5\n2 3 3\n2 4 3\n1 7 6\n",
"5\n5 11 1 3 5\n1 2 4\n3 3 3\n1 4 3\n1 7 7\n",
"5\n5 8 1 3 5\n1 3 4\n2 5 3\n2 4 3\n2 12 7\n",
"5\n3 8 0 4 9\n2 2 2\n2 5 3\n2 4 3\n1 7 6\n",
"5\n5 8 1 3 5\n1 2 4\n2 3 3\n2 4 3\n1 7 6\n",
"5\n5 8 1 4 5\n1 2 4\n2 3 ... | [
"4\n",
"5\n",
"3\n",
"2\n",
"1\n",
"4\n",
"4\n",
"4\n",
"4\n",
"4\n"
] |
CodeContests | Problem
Select 3 grid points from the closed rectangular section surrounded by points (0,0), (n-1,0), (0, m-1), (n-1, m-1) and make a triangle. make.
At this time, the absolute difference between the number of triangles containing the point (x1, y1) but not the point (x2, y2) and the number of triangles containing the... | stdin | null | 1,981 | 1 | [
"2 2 0 0 0 1\n",
"3 2 1 0 0 0\n"
] | [
"0\n",
"3\n"
] | [
"2 2 1 0 0 1\n",
"3 2 1 0 2 1\n",
"3 3 1 0 2 0\n",
"3 6 1 0 2 0\n",
"4 2 1 0 0 1\n",
"3 3 1 1 2 1\n",
"3 9 1 0 2 0\n",
"3 3 1 1 2 2\n",
"2 11 2 0 2 -1\n",
"1 9 0 -1 6 0\n"
] | [
"0\n",
"3\n",
"7\n",
"17\n",
"8\n",
"24\n",
"28\n",
"31\n",
"1\n",
"36\n"
] |
CodeContests | Problem
Aizu decided to play a game using a prime number $ P $, a set of natural numbers $ G $, and a natural number $ A $.
First, Aizu writes $ 1 $ on the paper at hand. After that, perform the following series of operations any number of times.
* Select one element from $ G $. Let this be $ g $.
* Write a new prod... | stdin | null | 3,176 | 1 | [
"1000000007 8\n3 2 9 7 5\n3 2 9 5 1000001\n3 39 1002 65537 12\n2 1000000006 518012930 793649232\n10 459268180 313723762 835892239 612038995 90424474 366392946 38051435 854115735 5132833 320534710 421820264\n1 1 1\n1 1 1000000006\n1 1000000006 1\n",
"7 3\n1 1 2\n1 2 1\n3 1 2 4 5\n"
] | [
"0\n1\n1\n1\n0\n1\n0\n1\n",
"0\n1\n0\n"
] | [
"1000000007 8\n3 2 9 7 5\n3 2 9 5 1000001\n3 39 1002 65537 12\n2 1000000006 518012930 793649232\n10 459268180 313723762 835892239 612038995 90424474 366392946 38051435 514969678 5132833 320534710 421820264\n1 1 1\n1 1 1000000006\n1 1000000006 1\n",
"7 3\n1 1 2\n1 0 1\n3 1 2 4 5\n",
"7 3\n1 2 4\n1 0 1\n3 1 2 4 5... | [
"0\n1\n1\n1\n0\n1\n0\n1\n",
"0\n1\n0\n",
"1\n1\n0\n",
"0\n1\n1\n",
"0\n0\n1\n",
"1\n0\n1\n",
"0\n1\n1\n1\n0\n1\n0\n0\n",
"0\n1\n1\n1\n0\n1\n1\n1\n",
"1\n0\n0\n",
"1\n0\n1\n1\n"
] |
CodeContests | The University of Aizu started a new system for taking classes in 2009. Under the new system, compulsory subjects have been abolished, and subjects can be freely selected in consideration of each course.
However, not all courses can be taken unconditionally, and in order to take a specific course, it is necessary to m... | stdin | null | 3,089 | 1 | [
"4 4\n1 0\n3 2 0 2\n2 0\n2 0\n3 6\n1 0\n3 2 0 2\n2 0\n0 0\n"
] | [
"2\n3\n"
] | [
"4 4\n1 0\n3 2 0 2\n2 0\n2 0\n3 1\n1 0\n3 2 0 2\n2 0\n0 0\n",
"4 4\n1 0\n3 2 0 2\n2 0\n0 0\n3 1\n1 0\n3 2 0 2\n2 0\n0 0\n",
"4 4\n1 0\n3 2 0 2\n2 0\n2 0\n3 6\n1 0\n3 2 0 2\n4 0\n0 0\n",
"4 4\n1 0\n3 2 0 2\n4 0\n0 0\n3 1\n1 0\n3 2 0 2\n2 0\n0 0\n",
"4 4\n2 0\n3 0 -1 2\n2 1\n0 0\n3 2\n1 0\n3 2 0 2\n1 0\n0 0\n... | [
"2\n1\n",
"3\n1\n",
"2\n3\n",
"1\n1\n",
"2\n2\n",
"2\n",
"2\n1\n",
"2\n1\n",
"2\n1\n",
"2\n1\n"
] |
CodeContests | You are visiting a large electronics store to buy a refrigerator and a microwave.
The store sells A kinds of refrigerators and B kinds of microwaves. The i-th refrigerator ( 1 \le i \le A ) is sold at a_i yen (the currency of Japan), and the j-th microwave ( 1 \le j \le B ) is sold at b_j yen.
You have M discount tic... | stdin | null | 1,722 | 1 | [
"1 1 2\n10\n10\n1 1 5\n1 1 10\n",
"2 2 1\n3 5\n3 5\n2 2 2\n",
"2 3 1\n3 3\n3 3 3\n1 2 1\n"
] | [
"10\n",
"6\n",
"5\n"
] | [
"1 1 2\n10\n10\n1 0 5\n1 1 10\n",
"2 2 1\n3 1\n3 5\n2 2 2\n",
"2 3 1\n3 3\n3 6 3\n1 2 1\n",
"2 2 1\n3 2\n3 8\n2 2 2\n",
"1 1 2\n17\n10\n1 0 0\n1 1 10\n",
"1 1 0\n10\n6\n1 0 0\n1 1 10\n",
"1 1 2\n17\n10\n1 0 0\n1 1 14\n",
"2 4 0\n3 5\n3 6 0\n0 2 1\n",
"2 4 0\n2 1\n1 5\n1 2 2\n",
"2 4 0\n2 1\n0 5\n1... | [
"10\n",
"4\n",
"6\n",
"5\n",
"17\n",
"16\n",
"13\n",
"3\n",
"2\n",
"1\n"
] |
CodeContests | E: Taiyaki-Master and Eater
story
Tsuta is very good at making Taiyaki. Ebi-chan loves Taiyaki made by Tsuta-san. The two are happy to make and eat Taiyaki every week, but Tsuta-san's recent worries are that Ebi-chan, who is in the middle of eating, eats the food while making Taiyaki.
Mr. Tsuta, who decided to make ... | stdin | null | 4,169 | 1 | [
"3 3 3 6\n1 0 1 1\n2 2 1 1 2 2\n3 1 1 1\n4 0 2 1\n5 2 1 1 2 2\n6 2 2 1 3 3\n"
] | [
"0 1\n1 1\n0 1\n"
] | [
"3 3 3 6\n1 0 1 1\n2 2 1 1 2 2\n3 1 1 1\n4 0 2 1\n5 2 2 1 2 2\n6 2 2 1 3 3\n",
"3 3 3 6\n1 0 1 1\n2 2 1 1 2 2\n3 1 1 1\n4 0 2 1\n5 2 2 1 2 2\n6 2 3 1 3 3\n",
"3 3 3 6\n1 0 1 1\n2 2 1 0 2 2\n3 1 1 1\n4 0 2 1\n5 2 1 1 2 2\n6 2 2 1 3 3\n",
"3 3 3 6\n1 0 1 1\n2 2 1 1 0 2\n3 1 1 1\n4 0 2 1\n5 2 2 1 2 2\n6 2 3 1 3 ... | [
"0 1\n0 1\n0 1\n",
"0 1\n0 1\n0 0\n",
"0 1\n1 1\n0 1\n",
"0 0\n0 1\n0 0\n",
"0 1\n0 1\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n",
"0 0\n0 1\n0 1\n",
"0 1\n0 1\n",
"0 1\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n",
"0 1\n0 0\n0 1\n",
"0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n"
] |
CodeContests | As we know , Professor Dalton is teaching Compiler Design.
During his first class, he found that the students are very talkative.
so,he decided to divide the class into two sections, A & B
such that the difference between the strength of two sections
is minimum.
Print the strength of two sections in non decreasing
o... | stdin | null | 4,651 | 1 | [
"2\n6\n8\n\nSAMPLE\n"
] | [
"3 3\n4 4\n"
] | [
"2\n1\n8\n\nSAMPLE\n",
"2\n2\n8\n\nSAMPLE\n",
"2\n2\n6\n\nSAPMLE\n",
"2\n2\n12\n\nSAPMLE\n",
"2\n2\n24\n\nSAPMLE\n",
"2\n2\n13\n\nSAPMLE\n",
"2\n2\n4\n\nSAPMLE\n",
"2\n0\n4\n\nSAPMLE\n",
"2\n0\n1\n\nSAPMLE\n",
"2\n-1\n1\n\nSAPMLE\n"
] | [
"0 1\n4 4\n",
"1 1\n4 4\n",
"1 1\n3 3\n",
"1 1\n6 6\n",
"1 1\n12 12\n",
"1 1\n6 7\n",
"1 1\n2 2\n",
"0 0\n2 2\n",
"0 0\n0 1\n",
"-1 0\n0 1\n"
] |
CodeContests | The king of a country loves prime numbers and gambling. The unit of currency in this country is called prime. As of November 1, 2007, Prime's cross-yen rate was just prime at 9973, so the King is overjoyed. Subsidiary coins with 1/101 prime as one subprime are used in this country.
The government of this country has d... | stdin | null | 1,855 | 1 | [
"4\n5 0\n9 1\n3 10\n11 3\n1\n999983 20\n0\n"
] | [
"5\n1\n"
] | [
"4\n5 -1\n9 1\n3 10\n11 3\n1\n999983 20\n0\n",
"4\n5 -1\n9 1\n3 10\n8 3\n1\n999983 20\n0\n",
"4\n3 -1\n14 1\n3 10\n8 3\n1\n999983 20\n0\n",
"4\n3 -1\n14 1\n3 24\n8 3\n1\n999983 20\n0\n",
"4\n5 0\n9 1\n3 10\n8 3\n1\n999983 20\n0\n",
"4\n5 -1\n9 1\n2 10\n11 3\n1\n999983 20\n0\n",
"4\n3 -1\n14 1\n3 24\n8 3... | [
"3\n1\n",
"4\n1\n",
"5\n1\n",
"8\n1\n",
"6\n1\n",
"2\n1\n",
"8\n4\n",
"3\n",
"5\n-1\n",
"5\n"
] |
CodeContests | N tiles are arranged in a row from left to right. The initial color of each tile is represented by a string S of length N.
The i-th tile from the left is painted black if the i-th character of S is `0`, and painted white if that character is `1`.
You want to repaint some of the tiles black or white, so that any two a... | stdin | null | 1,088 | 1 | [
"10010010\n",
"0\n",
"000\n"
] | [
"3\n",
"0\n",
"1\n"
] | [
"10110010\n",
"010\n",
"10110110\n",
"00110110\n",
"100\n",
"10100110\n",
"01110110\n",
"01110111\n",
"10011010\n",
"1\n"
] | [
"2\n",
"0\n",
"3\n",
"4\n",
"1\n",
"2\n",
"3\n",
"2\n",
"2\n",
"0\n"
] |
CodeContests | Maze & Items is a puzzle game in which the player tries to reach the goal while collecting items. The maze consists of $W \times H$ grids, and some of them are inaccessible to the player depending on the items he/she has now. The score the player earns is defined according to the order of collecting items. The objectiv... | stdin | null | 185 | 1 | [
"12 5\n.....S......\n.abcdefghij.\n.0123456789.\n.ABCDEFGHIJ.\n.....T......\n0 1 0 0 0 0 0 0 0 0\n2 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n",
"5 6\n..S..\n\n01234\n56... | [
"26 2\n",
"-1\n",
"53 19\n",
"31 0\n"
] | [
"12 5\n.....S......\n.abcdefghij.\n.0123456789.\n.ABCDEFGHIJ.\n.....T......\n0 1 0 0 0 0 0 0 0 0\n2 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 -1 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n",
"5 6\n..S..\n\n01234\n5... | [
"26 2\n",
"17 0\n",
"44 19\n",
"17 1\n",
"26 1\n",
"44 20\n",
"-1\n",
"26 0\n",
"26 -1\n",
"17 0\n"
] |
CodeContests | Consider all integers between 1 and 2N, inclusive. Snuke wants to divide these integers into N pairs such that:
* Each integer between 1 and 2N is contained in exactly one of the pairs.
* In exactly A pairs, the difference between the two integers is 1.
* In exactly B pairs, the difference between the two integers is ... | stdin | null | 2,963 | 1 | [
"3 1 2 0\n",
"600 100 200 300\n"
] | [
"2\n",
"522158867\n"
] | [
"2 1 2 0\n",
"986 100 200 300\n",
"986 110 200 300\n",
"986 111 200 300\n",
"720 111 200 591\n",
"3 0 2 0\n",
"986 010 200 300\n",
"399 011 200 300\n",
"720 111 27 300\n",
"1394 111 200 109\n"
] | [
"2\n",
"522158867\n",
"844618160\n",
"757624117\n",
"412651792\n",
"1\n",
"970071460\n",
"518979365\n",
"0\n",
"918797286\n"
] |
CodeContests | K Average Ranges
Given the sequence a_1, a_2, .., a_N.
How many intervals in this sequence have an average value of K or more and a length of 1 or more?
input
N K
a_1 a_2 ... a_N
output
Output the answer.
Constraint
* 1 \ leq N \ leq 10 ^ 5
* 1 \ leq K \ leq 10 ^ 9
* 1 \ leq a_i \ leq 10 ^ 9
Input example
... | stdin | null | 2,863 | 1 | [
"6 6\n8 6 9 1 2 1\n"
] | [
"7\n"
] | [
"6 5\n8 6 9 1 2 1\n",
"6 5\n8 6 9 1 4 1\n",
"6 5\n8 6 9 1 4 2\n",
"6 5\n8 6 9 1 7 2\n",
"6 5\n8 6 3 1 7 2\n",
"6 5\n5 6 3 1 7 2\n",
"6 5\n5 2 3 2 7 2\n",
"6 5\n3 2 8 -1 5 2\n",
"6 5\n3 2 15 -2 5 0\n",
"6 5\n3 2 37 -3 7 0\n"
] | [
"10\n",
"11\n",
"12\n",
"15\n",
"6\n",
"4\n",
"2\n",
"3\n",
"8\n",
"13\n"
] |
CodeContests | AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
Constraints
* 1 ≤ a,b ≤ 10000
* a and b are integers.
Input
Input is given from Standard Input in the following format:
a b
Output
If the product is odd, print `Odd`; if it is even, print `Even`.
E... | stdin | null | 20 | 1 | [
"3 4\n",
"1 21\n"
] | [
"Even\n",
"Odd\n"
] | [
"4 4\n",
"1 15\n",
"2 4\n",
"2 15\n",
"3 0\n",
"2 26\n",
"3 -1\n",
"2 32\n",
"0 -1\n",
"1 32\n"
] | [
"Even\n",
"Odd\n",
"Even\n",
"Even\n",
"Even\n",
"Even\n",
"Odd\n",
"Even\n",
"Even\n",
"Even\n"
] |
CodeContests | D: Rescue a Postal Worker
story
You got a job at the post office, which you have long dreamed of this spring. I decided on the delivery area I was in charge of, and it was my first job with a feeling of excitement, but I didn't notice that there was a hole in the bag containing the mail because it was so floating tha... | stdin | null | 3,613 | 1 | [
"5 6 1 1\n1 3 5\n1 2 2\n2 3 1\n3 5 4\n3 4 2\n4 5 3\n3 5\n"
] | [
"7\n"
] | [
"5 6 1 1\n1 3 5\n1 1 2\n2 3 1\n3 5 4\n3 4 2\n4 5 3\n3 5\n",
"5 6 1 1\n1 3 5\n2 1 2\n2 3 1\n3 5 4\n3 4 2\n4 5 3\n3 5\n",
"5 6 1 2\n1 3 5\n2 1 2\n2 3 1\n3 5 4\n3 4 2\n4 5 3\n3 5\n",
"5 6 1 1\n1 3 5\n2 1 2\n2 3 1\n3 1 4\n3 4 2\n4 5 3\n3 5\n",
"5 6 1 1\n1 3 4\n1 2 1\n2 3 1\n3 5 4\n3 4 2\n4 5 3\n3 5\n",
"8 6 1... | [
"9\n",
"7\n",
"5\n",
"8\n",
"6\n",
"Cannot deliver\n",
"10\n",
"0\n",
"4\n",
"3\n"
] |
CodeContests | You might have heard about our new goodie distribution program aka the "Laddu Accrual System". This problem is designed to give you a glimpse of its rules. You can read the page once before attempting the problem if you wish, nonetheless we will be providing all the information needed here itself.
Laddu Accrual Syste... | stdin | null | 123 | 1 | [
"2\n4 INDIAN\nCONTEST_WON 1\nTOP_CONTRIBUTOR\nBUG_FOUND 100\nCONTEST_HOSTED\n4 NON_INDIAN\nCONTEST_WON 1\nTOP_CONTRIBUTOR\nBUG_FOUND 100\nCONTEST_HOSTED\n"
] | [
"3\n1\n"
] | [
"2\n4 INDIAN\nCONTEST_WON 1\nTOP_CONTRIBUTOR\nBUG_FOUND 100\nCONTEST_HOSTED\n1 NON_INDIAN\nCONTEST_WON 1\nTOP_CONTRIBUTOR\nBUG_FOUND 100\nCONTEST_HOSTED\n",
"2\n4 INDIAN\nCONTEST_WON 1\nTOP_CONTRIBUTOR\nBUG_FOUND 100\nCONTEST_HOSTED\n2 NON_INDIAN\nCONTEST_WON 1\nTOP_CONTRIBUTOR\nBUG_FOUND 100\nCONTEST_HOSTED\n",
... | [
"3\n0\n",
"3\n1\n",
"3\n0\n",
"3\n0\n",
"3\n0\n",
"3\n0\n",
"3\n0\n",
"3\n0\n",
"3\n0\n",
"3\n0\n"
] |
CodeContests | Recently Ram got to know about a secret place where he can play many games to win lot of prize. Games are very easy, so he can easily win high prize, but he can play a limited number of games.
He want to win the maximum amount of prize.So he wants to choose games, such that the prize money is maximum.
Assume that he w... | stdin | null | 3,586 | 1 | [
"5\n5 5\n1 1 1 1 1\n4 0\n1 1 1 1\n3 1\n8 9 8\n6 5\n100 200 300 400 500 1000\n2 1\n1 2\n\nSAMPLE\n"
] | [
"5\n0\n9\n2400\n2\n"
] | [
"1\n5 6\n1 0 3 4 5\n",
"1\n5 100\n1 2 6 4 5\n",
"5\n5 5\n1 1 1 1 1\n4 0\n1 1 1 1\n3 1\n8 9 8\n6 5\n100 200 300 400 500 1000\n2 1\n2 2\n\nSAMPLE\n",
"1\n5 6\n1 0 3 4 2\n",
"5\n5 5\n1 1 1 1 1\n4 0\n1 1 1 1\n3 1\n8 9 8\n6 5\n100 200 300 341 500 1000\n2 1\n2 2\n\nSAMPLE\n",
"1\n5 101\n0 2 6 4 5\n",
"1\n5 10... | [
"13\n",
"18\n",
"5\n0\n9\n2400\n2\n",
"10\n",
"5\n0\n9\n2341\n2\n",
"17\n",
"16\n",
"8\n",
"11\n",
"22\n"
] |
CodeContests | There are two rooted trees, each with N vertices. The vertices of each tree are numbered 1 through N. In the first tree, the parent of Vertex i is Vertex A_i. Here, A_i=-1 if Vertex i is the root of the first tree. In the second tree, the parent of Vertex i is Vertex B_i. Here, B_i=-1 if Vertex i is the root of the sec... | stdin | null | 4,192 | 1 | [
"6\n-1 5 1 5 1 3\n6 5 5 3 -1 3\n",
"5\n3 3 4 -1 4\n4 4 1 -1 1\n",
"8\n2 7 1 2 2 1 -1 4\n4 -1 4 7 4 4 2 4\n"
] | [
"IMPOSSIBLE\n",
"POSSIBLE\n1 -1 -1 3 -1\n",
"POSSIBLE\n1 2 -1 0 -1 1 0 -1\n"
] | [
"6\n-1 5 1 5 1 3\n6 3 5 3 -1 3\n",
"8\n2 7 1 2 2 1 -1 4\n8 -1 8 7 4 4 2 4\n",
"5\n-1 0 1 0 0\n1 2 2 -1 6\n",
"5\n3 0 4 -1 4\n4 4 1 -1 1\n",
"8\n2 7 1 2 2 1 -1 4\n4 -1 8 7 4 4 2 4\n",
"5\n3 0 4 -1 4\n4 4 1 0 1\n",
"8\n2 7 1 2 2 1 -1 4\n2 -1 8 7 4 4 2 4\n",
"5\n3 0 4 -1 4\n4 4 0 0 1\n",
"8\n2 7 1 2 2 ... | [
"IMPOSSIBLE\n",
"POSSIBLE\n-1 0 1 0 -1 -1 0 1\n",
"POSSIBLE\n0 -1 1 1 -1\n",
"IMPOSSIBLE\n",
"IMPOSSIBLE\n",
"IMPOSSIBLE\n",
"IMPOSSIBLE\n",
"IMPOSSIBLE\n",
"IMPOSSIBLE\n",
"IMPOSSIBLE\n"
] |
CodeContests | Bhallaladeva was an evil king who ruled the kingdom of Maahishmati. He wanted to erect a 100ft golden statue of himself and he looted gold from several places for this. He even looted his own people, by using the following unfair strategy:
There are N houses in Maahishmati, and the i^th house has Ai gold plates. Each g... | stdin | null | 2,269 | 1 | [
"4\n3 2 1 4\n2\n0\n2\n"
] | [
"10\n3\n"
] | [
"4\n3 2 1 0\n2\n0\n2\n",
"4\n3 2 1 0\n2\n1\n2\n",
"4\n3 2 1 0\n1\n1\n2\n",
"4\n5 2 1 0\n2\n1\n3\n",
"4\n5 0 1 0\n2\n1\n3\n",
"4\n3 0 1 -1\n2\n1\n3\n",
"4\n3 -1 1 -1\n2\n1\n3\n",
"4\n1 2 1 4\n2\n0\n2\n",
"4\n3 2 0 0\n2\n0\n2\n",
"4\n5 2 2 0\n2\n1\n3\n"
] | [
"6\n1\n",
"1\n1\n",
"1\n",
"1\n0\n",
"0\n0\n",
"-1\n-1\n",
"-2\n-1\n",
"8\n2\n",
"5\n0\n",
"2\n0\n"
] |
CodeContests | Don't Cross the Circles!
There are one or more circles on a plane. Any two circles have different center positions and/or different radiuses. A circle may intersect with another circle, but no three or more circles have areas nor points shared by all of them. A circle may completely contain another circle or two circl... | stdin | null | 820 | 1 | [
"5 3\n0 0 1000\n1399 1331 931\n0 1331 500\n1398 0 400\n2000 360 340\n450 950 1600 380\n450 950 1399 1331\n450 950 450 2000\n1 2\n50 50 50\n0 10 100 90\n0 10 50 50\n2 2\n50 50 50\n100 50 50\n40 50 110 50\n40 50 0 0\n4 1\n25 100 26\n75 100 26\n50 40 40\n50 160 40\n50 81 50 119\n6 1\n100 50 40\n0 50 40\n50 0 48\n50 50... | [
"YES NO NO\nYES NO\nNO NO\nNO\nYES\nYES NO NO YES NO NO\nNO NO\n"
] | [
"5 3\n0 0 1000\n1399 1331 931\n0 1331 500\n1398 0 400\n2000 360 340\n450 950 1600 380\n450 950 1399 1331\n450 950 450 2000\n1 2\n50 50 50\n0 10 100 90\n0 10 50 50\n2 2\n50 50 50\n100 50 50\n40 50 110 50\n40 50 0 0\n4 1\n25 100 26\n75 100 26\n50 40 40\n50 160 40\n50 81 50 119\n6 1\n100 50 40\n0 50 40\n17 0 48\n50 50... | [
"YES NO NO\nYES NO\nNO NO\nNO\nYES\nYES NO NO YES NO NO\nNO NO\n",
"YES NO NO\nYES NO\nNO NO\nNO\nYES\nYES NO NO NO NO NO\nNO NO\n",
"YES NO NO\nYES NO\nNO NO\nNO\nYES\nYES NO NO NO NO YES\nNO NO\n",
"NO NO NO\nYES NO\nNO NO\nNO\nYES\nYES NO NO YES NO NO\nNO NO\n",
"YES NO NO\nYES NO\nNO NO\nNO\nYES\nYES NO... |
CodeContests | Ben believes a lot in tarot cards. He believes that they are lucky for him. He even decides to wear clothes according to the color predicted by a draw of a card. This irritates his wife, because sometimes he wears the same color t-shirt continuously if his cards so predict.
Now, his wife wants to go on a vacation wit... | stdin | null | 881 | 1 | [
"2\n5\n1 2 3 4 5\n6\n1 2 1 3 1 5\n\n\nSAMPLE\n"
] | [
"1 5\n2 4\n"
] | [
"2\n5\n1 2 3 4 5\n6\n1 2 1 3 1 8\n\n\nSAMPLE\n",
"2\n5\n0 2 6 4 5\n6\n1 2 2 3 1 8\n\n\nSAMPLE\n",
"2\n5\n0 2 6 8 5\n6\n1 2 2 3 2 8\n\n\nSAMPLE\n",
"2\n5\n1 2 3 4 5\n6\n1 2 0 3 1 5\n\n\nSAMPLE\n",
"2\n5\n1 1 3 4 5\n6\n1 2 0 3 1 10\n\n\nSAMPLE\n",
"2\n5\n2 2 3 4 5\n5\n1 2 1 3 1 15\n\n\nSAMPLE\n",
"2\n5\n1... | [
"1 5\n2 4\n",
"1 5\n3 6\n",
"1 5\n4 6\n",
"1 5\n2 6\n",
"2 5\n2 6\n",
"2 5\n2 4\n",
"1 5\n1 2\n",
"2 5\n1 4\n",
"1 5\n1 4\n",
"1 3\n2 4\n"
] |
CodeContests | All the students in NIT are very lazy. They want to have maximum time for rest. But due to college rules, they must maintain 75% attendance at the end of every week.
Given the schedule of a week, tell them what is the maximum amount of time they might have for resting.
NOTE:
Each day has 24 hrs. i.e. 24x60x60 second... | stdin | null | 207 | 1 | [
"1\n3 60 70 80 90 100 200\n3 50 70 100 120 150 200\n3 50 80 90 100 200 220\n3 80 100 110 115 200 210\n3 10 20 40 50 60 100\n3 10 50 60 80 90 100\n3 50 80 90 100 200 300\n\nSAMPLE\n"
] | [
"604555\n"
] | [
"1\n3 60 70 80 90 100 200\n3 50 70 100 120 150 200\n3 50 80 90 100 200 279\n3 80 100 110 115 200 210\n3 10 20 40 50 60 100\n3 10 50 60 80 90 100\n3 50 80 90 100 200 300\n\nSAMPLE\n",
"1\n3 60 70 80 90 100 200\n3 50 70 100 120 150 200\n3 50 80 90 100 200 279\n3 80 100 110 115 200 210\n3 10 20 40 50 60 100\n3 10 50... | [
"604535\n",
"604505\n",
"604503\n",
"604474\n",
"604555\n",
"604529\n",
"604525\n",
"604495\n",
"604469\n",
"604541\n"
] |
CodeContests | You are supposed to play the rock-paper-scissors game. There are $N$ players including you.
This game consists of multiple rounds. While the rounds go, the number of remaining players decreases. In each round, each remaining player will select an arbitrary shape independently. People who show rocks win if all of the o... | stdin | null | 2,265 | 1 | [
"2\n2\n1 40 40 20\n",
"4\n4\n1 34 33 33\n2 33 34 33\n3 33 33 34\n",
"2\n1\n2 50 50 0\n",
"3\n2\n1 50 0 50\n3 0 0 100\n",
"3\n2\n3 40 40 20\n1 30 10 60\n"
] | [
"0.8\n",
"0.6591870816\n",
"0.5\n",
"1\n",
"0.27\n"
] | [
"2\n2\n0 40 40 20\n",
"2\n1\n2 50 50 1\n",
"3\n2\n3 40 40 8\n1 30 10 60\n",
"2\n1\n2 94 50 1\n",
"3\n2\n1 50 0 50\n3 0 0 000\n",
"3\n4\n3 40 40 20\n1 30 10 60\n",
"2\n1\n2 82 50 1\n",
"3\n2\n3 40 64 8\n1 30 10 60\n",
"2\n1\n2 115 38 1\n",
"3\n2\n3 40 40 20\n0 30 10 60\n"
] | [
"0.800000000\n",
"0.500000000\n",
"0.259200000\n",
"0.940000000\n",
"0.000000000\n",
"0.746000000\n",
"0.820000000\n",
"0.414720000\n",
"1.150000000\n",
"0.270000000\n"
] |
CodeContests | There are N bags of biscuits. The i-th bag contains A_i biscuits.
Takaki will select some of these bags and eat all of the biscuits inside. Here, it is also possible to select all or none of the bags.
He would like to select bags so that the total number of biscuits inside is congruent to P modulo 2. How many such wa... | stdin | null | 2,483 | 1 | [
"3 0\n1 1 1\n",
"1 1\n50\n",
"2 0\n1 3\n",
"45 1\n17 55 85 55 74 20 90 67 40 70 39 89 91 50 16 24 14 43 24 66 25 9 89 71 41 16 53 13 61 15 85 72 62 67 42 26 36 66 4 87 59 91 4 25 26\n"
] | [
"4\n",
"0\n",
"2\n",
"17592186044416\n"
] | [
"1 1\n67\n",
"45 1\n17 55 85 55 74 20 90 67 40 70 39 89 91 50 16 24 14 43 24 68 25 9 89 71 41 16 53 13 61 15 85 72 62 67 42 26 36 66 4 87 59 91 4 25 26\n",
"3 1\n1 1 1\n",
"2 0\n1 1\n",
"1 1\n42\n",
"45 1\n17 55 85 55 74 20 90 67 40 70 39 89 91 50 16 24 14 43 24 68 25 9 89 71 41 16 53 11 61 15 85 72 62 67... | [
"1\n",
"17592186044416\n",
"4\n",
"2\n",
"0\n",
"17592186044416\n",
"17592186044416\n",
"17592186044416\n",
"17592186044416\n",
"17592186044416\n"
] |
CodeContests | Doraemon gave Nobita a gadget that swaps words inside a string in the following manner :
If there are W words, word 1 is swapped with word W, word 2 is swapped with word W-1 and so on.
The problem is that Nobita himself cannot verify the answer for large strings. Help him write a program to do so.
INPUT :
the first ... | stdin | null | 3,787 | 1 | [
"1\nhello world\n\nSAMPLE\n"
] | [
"world hello\n"
] | [
"50\nukjjsjlpYFHnFoTacnXvxenZoAfrZy riPn ObkK ENY ciGCgwlTAIyq Qik AFwRqd cVsieV eQKUAmoFabieStNNTwEWHfb a w sg w fIKFGBz FXjxP yuqQGYT AbCmCkutuUz dR EhwCj fovaistLH ikSfIwYEsy f vasBuknimzMiISBhVhkImfzJ qK vx gfzFXeTDaspOARoAeRe FbKOXiNCPAQQArTFpVqtagicMEkThMnsNZJwZcmPRaGZF BMVOrZMamsgAAKyrPDxRGpmIaxhNdIIQ pLmsj ... | [
"X sn zOxGEtrobbtsVUgqAozGoqzHrPqMFYUYzI tvnbVspMwliWASSW nJsJzy WqZcHirynhWvOoYYkjyeWlMaB PwH pDCwczAZKgznmndR GGyrAfRsOmteiysvcfho nZKrUAd ZkMuzupFaTDaB h iAhQCxu KZOQcIHJxzKGJHo sfX oykXI o NuMxnFIACkoNglkHKgEf dwRX JI VFLfidAVrvpRdnxKi k KZHwSfy eYIEdF gcp wJWrHOgkpt LC oTkZNSqEGMbuCNEv GHhI qsfLTdfRXyJMDGhddoe... |
CodeContests | Rng is going to a festival.
The name of the festival is given to you as a string S, which ends with `FESTIVAL`, from input. Answer the question: "Rng is going to a festival of what?" Output the answer.
Here, assume that the name of "a festival of s" is a string obtained by appending `FESTIVAL` to the end of s. For ex... | stdin | null | 4,585 | 1 | [
"YAKINIKUFESTIVAL\n",
"CODEFESTIVALFESTIVAL\n",
"CODEFESTIVAL\n"
] | [
"YAKINIKU\n",
"CODEFESTIVAL\n",
"CODE\n"
] | [
"YAKINIJUFESTIVAL\n",
"CODEFESTIVALFERTIVAL\n",
"CODEFESTIVAM\n",
"LAVITSEFUJINIKAY\n",
"CPDEFESTIVAM\n",
"LAVITSEEUJINIKAY\n",
"CODEFESTIWALFESTIWAL\n",
"LAWITSEFLAWITSEFEDOC\n",
"BPDEFDSTIVBM\n",
"CODEFWSTIWALFESTIEAL\n"
] | [
"YAKINIJU\n",
"CODEFESTIVAL\n",
"CODE\n",
"LAVITSEF\n",
"CPDE\n",
"LAVITSEE\n",
"CODEFESTIWAL\n",
"LAWITSEFLAWI\n",
"BPDE\n",
"CODEFWSTIWAL\n"
] |
CodeContests | Yuki made a sugoroku so that everyone can play at the children's association event. In this sugoroku, squares are lined up in a ring, and each square has an integer of 1 or more written on it.
The player chooses a square as a starting point and places his piece. Advance the pieces clockwise by the number written on th... | stdin | null | 3,765 | 1 | [
"3\n1 1 1\n",
"8\n2 3 7 3 3 3 4 4\n",
"3\n1 1 2\n"
] | [
"3\n",
"6\n",
"2\n"
] | [
"3\n2 1 1\n",
"8\n2 3 7 3 3 1 4 4\n",
"3\n1 1 3\n",
"3\n1 2 3\n",
"8\n2 4 4 0 3 4 4 4\n",
"8\n0 3 6 0 5 4 4 4\n",
"8\n0 3 5 1 6 0 0 4\n",
"8\n1 1 1 2 11 1 -2 1\n",
"3\n2 1 0\n",
"8\n2 3 4 3 3 1 4 4\n"
] | [
"2\n",
"6\n",
"1\n",
"3\n",
"5\n",
"4\n",
"7\n",
"8\n",
"1\n",
"2\n"
] |
CodeContests | You are given a positive integer N. Find the number of the pairs of integers u and v (0≦u,v≦N) such that there exist two non-negative integers a and b satisfying a xor b=u and a+b=v. Here, xor denotes the bitwise exclusive OR. Since it can be extremely large, compute the answer modulo 10^9+7.
Constraints
* 1≦N≦10^{18... | stdin | null | 181 | 1 | [
"3\n",
"1422\n",
"1000000000000000000\n"
] | [
"5\n",
"52277\n",
"787014179\n"
] | [
"4\n",
"1026\n",
"1000000001000000000\n",
"0\n",
"530\n",
"1100000001000000000\n",
"1\n",
"706\n",
"1100000001000010000\n",
"2\n"
] | [
"8\n",
"29565\n",
"999867657\n",
"1\n",
"10220\n",
"355035671\n",
"2\n",
"17242\n",
"391646023\n",
"4\n"
] |
CodeContests | Chef is fan of pairs and he likes all things that come in pairs. He even has a doll collection in which all dolls have paired.One day while going through his collection he found that there are odd number of dolls. Someone had stolen a doll!!!
Help chef find which type of doll is missing..
Input
The first line conta... | stdin | null | 4,017 | 1 | [
"1\n3\n1 \n2\n1\n",
"1\n5\n1\n1\n2\n2\n3\n"
] | [
"2\n",
"3\n"
] | [
"1\n3\n2 \n2\n1\n",
"1\n3\n0 \n2\n0\n",
"1\n5\n1\n1\n3\n3\n3\n",
"1\n3\n1 \n4\n1\n",
"1\n5\n1\n1\n3\n6\n3\n",
"1\n3\n1 \n8\n1\n",
"1\n5\n1\n1\n2\n2\n5\n",
"1\n5\n1\n1\n3\n3\n9\n",
"1\n3\n1 \n10\n1\n",
"1\n1\n11 \n4\n0\n"
] | [
"1\n",
"2\n",
"3\n",
"4\n",
"6\n",
"8\n",
"5\n",
"9\n",
"10\n",
"11\n"
] |
CodeContests | problem
The JOI country has one long enough road running east to west. The royal palace of JOI country is along the road, and the position along the road in JOI country is represented by the integer A. When A = 0, it represents the position of the royal palace. When A> 0, it indicates the position A meters east of the... | stdin | null | 1,817 | 1 | [
"5 5 3\n-8 1\n-4 2\n-2 2\n4 2\n10 1\n1\n3\n5\n"
] | [
"-6\n-6\n15\n"
] | [
"5 5 3\n-8 1\n-4 2\n-2 2\n4 0\n10 1\n1\n3\n5\n",
"5 8 3\n-8 1\n-4 2\n-2 2\n4 1\n10 1\n1\n3\n5\n",
"5 5 1\n-8 1\n-4 2\n-2 2\n4 2\n10 1\n1\n3\n5\n",
"5 5 3\n-8 1\n-4 2\n-2 2\n4 0\n10 1\n1\n5\n5\n",
"5 8 3\n-8 1\n-4 2\n-2 2\n4 1\n4 1\n2\n3\n5\n",
"5 7 3\n-8 1\n-4 2\n-2 2\n4 1\n4 1\n2\n3\n5\n",
"5 7 3\n-8 2... | [
"-6\n-6\n15\n",
"-6\n-6\n18\n",
"-6\n",
"-6\n15\n15\n",
"-6\n-6\n12\n",
"-6\n-6\n11\n",
"-11\n-9\n11\n",
"11\n-9\n11\n",
"-7\n-7\n15\n",
"-6\n-4\n12\n"
] |
CodeContests | There is a one-dimensional cellular automaton consisting of N cells. Cells are numbered from 0 to N − 1.
Each cell has a state represented as a non-negative integer less than M. The states of cells evolve through discrete time steps. We denote the state of the i-th cell at time t as S(i, t). The state at time t + 1 is... | stdin | null | 1,497 | 1 | [
"5 4 1 3 2 0\n0 1 2 0 1\n5 7 1 3 2 1\n0 1 2 0 1\n5 13 1 3 2 11\n0 1 2 0 1\n5 5 2 0 1 100\n0 1 2 0 1\n6 6 0 2 3 1000\n0 1 2 0 1 4\n20 1000 0 2 3 1000000000\n0 1 2 0 1 0 1 2 0 1 0 1 2 0 1 0 1 2 0 1\n30 2 1 0 1 1000000000\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0\n30 2 1 1 1 1000000000\n1 0 0 0 0 0 ... | [
"0 1 2 0 1\n2 0 0 4 3\n2 12 10 9 11\n3 0 4 2 1\n0 4 2 0 4 4\n0 376 752 0 376 0 376 752 0 376 0 376 752 0 376 0 376 752 0 376\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0\n1 1 3 2 2 2 3 3 1 4 3 1 2 3 0 4 3 3 0 4 2 2 2 2 1 1 2 1 3 0\n"
] | [
"5 4 1 3 2 0\n0 1 2 0 1\n5 7 1 3 2 0\n0 1 2 0 1\n5 13 1 3 2 11\n0 1 2 0 1\n5 5 2 0 1 100\n0 1 2 0 1\n6 6 0 2 3 1000\n0 1 2 0 1 4\n20 1000 0 2 3 1000000000\n0 1 2 0 1 0 1 2 0 1 0 1 2 0 1 0 1 2 0 1\n30 2 1 0 1 1000000000\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0\n30 2 1 1 1 1000000000\n1 0 0 0 0 0 ... | [
"0 1 2 0 1\n0 1 2 0 1\n2 12 10 9 11\n3 0 4 2 1\n0 4 2 0 4 4\n0 376 752 0 376 0 376 752 0 376 0 376 752 0 376 0 376 752 0 376\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0\n1 1 3 2 2 2 3 3 1 4 3 1 2 3 0 4 3 3 0 4 2 2 2 2 1 1 2 1 3 0\n",
"0... |
CodeContests | Serval is fighting with a monster.
The health of the monster is H.
In one attack, Serval can decrease the monster's health by A. There is no other way to decrease the monster's health.
Serval wins when the monster's health becomes 0 or below.
Find the number of attacks Serval needs to make before winning.
Constrai... | stdin | null | 646 | 1 | [
"10 4\n",
"1 10000\n",
"10000 1\n"
] | [
"3\n",
"1\n",
"10000\n"
] | [
"14 4\n",
"2 10000\n",
"11000 1\n",
"14 3\n",
"11 2\n",
"4 3\n",
"14 5\n",
"10010 1\n",
"26 4\n",
"10001 1\n"
] | [
"4\n",
"1\n",
"11000\n",
"5\n",
"6\n",
"2\n",
"3\n",
"10010\n",
"7\n",
"10001\n"
] |
CodeContests | You have final scores of an examination for n students. Calculate standard deviation of the scores s1, s2 ... sn.
The variance α2 is defined by
α2 = (∑ni=1(si - m)2)/n
where m is an average of si. The standard deviation of the scores is the square root of their variance.
Constraints
* n ≤ 1000
* 0 ≤ si ≤ 100
Inpu... | stdin | null | 2,268 | 1 | [
"5\n70 80 100 90 20\n3\n80 80 80\n0\n"
] | [
"27.85677655\n0.00000000\n"
] | [
"5\n70 80 100 107 20\n3\n80 80 80\n0\n",
"5\n70 80 100 107 20\n0\n80 80 80\n0\n",
"5\n70 80 101 107 20\n0\n80 80 80\n0\n",
"5\n70 80 101 123 20\n0\n80 80 80\n0\n",
"5\n70 80 111 123 20\n0\n80 80 80\n0\n",
"5\n70 80 100 90 20\n3\n74 80 80\n0\n",
"5\n70 80 100 99 20\n3\n80 80 80\n0\n",
"5\n70 80 100 107... | [
"30.7349963397\n0.0\n",
"30.7349963397\n",
"30.8972490685\n",
"34.5913283931\n",
"36.0743676313\n",
"27.8567765544\n2.82842712475\n",
"29.2191717884\n0.0\n",
"37.7285038134\n",
"36.151901748\n",
"38.1030182532\n"
] |
CodeContests | In Takaha-shi, the capital of Republic of AtCoder, there are N roads extending east and west, and M roads extending north and south. There are no other roads. The i-th east-west road from the north and the j-th north-south road from the west cross at the intersection (i, j). Two east-west roads do not cross, nor do two... | stdin | null | 1,527 | 1 | [
"9 7 10\nEEEEEWEWW\nNSSSNSN\n4 6 9 2\n3 7 6 7\n7 5 3 5\n1 1 8 1\n4 3 5 4\n7 4 6 4\n2 5 8 6\n6 6 2 7\n2 4 7 5\n7 2 9 7\n",
"4 5 4\nEEWW\nNSNNS\n4 1 1 4\n1 3 1 2\n4 2 3 2\n3 3 3 5\n",
"3 3 2\nEEE\nSSS\n1 1 3 3\n3 3 1 1\n"
] | [
"9\n-1\n4\n9\n2\n3\n7\n7\n6\n-1\n",
"6\n11\n5\n4\n",
"4\n-1\n"
] | [
"6 3 2\nEEE\nSSS\n1 1 3 3\n3 3 1 1\n",
"4 5 2\nEEWW\nNSNNS\n4 1 1 4\n1 3 1 2\n4 2 3 2\n3 3 3 5\n",
"4 5 4\nEEWW\nNSNNS\n4 1 1 4\n1 3 1 2\n4 2 3 2\n3 3 4 5\n",
"6 3 1\nEEE\nSSS\n1 1 3 3\n3 4 1 1\n",
"3 3 1\nEEE\nSSS\n1 2 3 3\n3 3 1 2\n",
"6 3 1\nEEE\nSSS\n1 1 3 1\n6 4 1 1\n",
"4 5 4\nEEWW\nNSNNS\n4 1 1 4... | [
"4\n-1\n",
"6\n11\n",
"6\n11\n5\n5\n",
"4\n",
"3\n",
"2\n",
"6\n11\n5\n4\n",
"6\n11\n5\n",
"6\n1\n5\n",
"3\n-1\n"
] |
CodeContests | Codex is about to start and Ram has not done dinner yet. So, he quickly goes to hostel mess and finds a long queue in front of food counter. But somehow he manages to take the food plate and reaches in front of the queue. The plates are divided into sections such that it has 2 rows and N columns.
Due to the crowd Ram... | stdin | null | 525 | 1 | [
"2\n1\n3\n\nSAMPLE\n"
] | [
"4\n25\n"
] | [
"19\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n18\n17\n18\n19\n",
"2\n1\n3\n\nSBMPLE\n",
"19\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n18\n17\n6\n19\n",
"19\n1\n2\n3\n4\n5\n6\n7\n8\n13\n10\n11\n12\n13\n14\n15\n18\n17\n6\n19\n",
"19\n1\n1\n3\n4\n5\n6\n7\n8\n13\n10\n11\n12\n13\n14\n15\n18\n... | [
"4\n9\n25\n64\n169\n441\n1156\n3025\n7921\n20736\n54289\n142129\n372100\n974169\n2550409\n45765225\n17480761\n45765225\n119814916\n",
"4\n25\n",
"4\n9\n25\n64\n169\n441\n1156\n3025\n7921\n20736\n54289\n142129\n372100\n974169\n2550409\n45765225\n17480761\n441\n119814916\n",
"4\n9\n25\n64\n169\n441\n1156\n3025\... |
CodeContests | Kuldeep's girlfriend Christie recently got her PhD in Maths. So to celebrate, they both decided to play games with mathematical sequences for their date nights.
The game they are playing today is "Jackpot Palindrome", the objective of the game is to find out length of the largest palindrome which only contains the dig... | stdin | null | 1,235 | 1 | [
"4\n1\n2\n3\n4\n\nSAMPLE\n"
] | [
"1\n1\n1\n2\n"
] | [
"4\n1\n2\n3\n4\n\nSLMPAE\n",
"4\n1\n2\n1\n2\n\nSLMPAE\n",
"4\n1\n2\n2\n6\n\nSLMPAE\n",
"4\n1\n0\n2\n3\n\nSPMLAE\n",
"4\n1\n0\n2\n6\n\nSPMLAE\n",
"4\n0\n0\n2\n6\n\nSPMLAE\n",
"4\n0\n0\n0\n6\n\nSPMLAE\n",
"4\n0\n0\n-1\n6\n\nSPMLAE\n",
"4\n0\n-1\n0\n6\n\nEALOOS\n",
"4\n0\n0\n0\n4\n\nEALONS\n"
] | [
"1\n1\n1\n2\n",
"1\n1\n1\n1\n",
"1\n1\n1\n3\n",
"1\n0\n1\n1\n",
"1\n0\n1\n3\n",
"0\n0\n1\n3\n",
"0\n0\n0\n3\n",
"0\n0\n-1\n3\n",
"0\n-1\n0\n3\n",
"0\n0\n0\n2\n"
] |
CodeContests | Julia has a sack full of red and yellow balls and wants to arrange them in a particular order as
defined below.
Let us consider two definitions -
Chroma-regularity - maximum number of objects of the same color that appear consecutively.
Min-Arrangement - An arrangement of the objects with minimum Chroma Regularit... | stdin | null | 4,297 | 1 | [
"10\n10\n\nSAMPLE\n"
] | [
"1\n"
] | [
"253\n619\n",
"10\n10\n\nSEMPLA\n",
"10\n0\n\nESNPLA\n",
"253\n6\n",
"253\n2\n",
"253\n0\n",
"253\n4\n",
"253\n5\n",
"253\n7\n",
"253\n3\n"
] | [
"2\n",
"1\n",
"10\n",
"5\n",
"64\n",
"253\n",
"17\n",
"9\n",
"3\n",
"33\n"
] |
CodeContests | We have sticks numbered 1, \cdots, N. The length of Stick i (1 \leq i \leq N) is L_i.
In how many ways can we choose three of the sticks with different lengths that can form a triangle?
That is, find the number of triples of integers (i, j, k) (1 \leq i < j < k \leq N) that satisfy both of the following conditions:
... | stdin | null | 882 | 1 | [
"2\n1 1\n",
"10\n9 4 6 1 9 6 10 6 6 8\n",
"6\n4 5 4 3 3 5\n",
"5\n4 4 9 7 5\n"
] | [
"0\n",
"39\n",
"8\n",
"5\n"
] | [
"2\n1 0\n",
"10\n9 4 8 1 9 6 10 6 6 8\n",
"6\n4 5 8 3 3 5\n",
"5\n4 4 3 7 5\n",
"10\n9 4 16 1 9 6 10 6 6 8\n",
"6\n4 5 6 3 3 5\n",
"5\n4 0 3 7 5\n",
"10\n9 7 16 1 9 6 10 6 6 8\n",
"5\n4 -1 0 7 5\n",
"10\n9 7 13 2 9 6 10 6 6 8\n"
] | [
"0\n",
"48\n",
"6\n",
"5\n",
"36\n",
"12\n",
"3\n",
"40\n",
"1\n",
"63\n"
] |
CodeContests | Utkarsh lives in a strange country. The cities of the country are present on x axis. He is currently at a city at x = 0. He needs to reach another city at x = N.
Utkarsh can move only in the positive x direction. Also due to massive traffic in the one dimensional country, at any time = T seconds, a person can make one ... | stdin | null | 2,044 | 1 | [
"2\n2\n3\n\nSAMPLE\n"
] | [
"2\n2\n"
] | [
"10\n24597858934063494\n52948353213749172\n66008909937323155\n81760348535676591\n59094560939797792\n59120192561706519\n85271166690001846\n19617202064530213\n70660863580979682\n74570975613492440\n",
"10\n3653\n8735\n7442\n6716\n775\n906\n1997\n5247\n7721\n711\n",
"2\n2\n3\n\nSANPLE\n",
"10\n24597858934063494\n... | [
"221801077\n325417741\n363342565\n404376925\n343786448\n343860997\n412967715\n198076763\n375927822\n386189010\n",
"85\n132\n122\n116\n39\n43\n63\n102\n124\n38\n",
"2\n2\n",
"221801077\n325417741\n363342565\n404376925\n343786448\n311997701\n412967715\n198076763\n375927822\n386189010\n",
"85\n132\n122\n116\n3... |
CodeContests | Problem
Uniqlo Uzuki and Rin Meguro are coming to SEARIGHT LIVE FES for sale. As shown in the figure below, the product sales line consists of two lines, with W people in the horizontal direction and H people in the vertical direction, forming a U-shape. The person at the top of the line is removed from the line after... | stdin | null | 3,326 | 1 | [
"11 11\n5\n0 0 0 0 0\n",
"11 11\n5\n0 0 1 1 1\n"
] | [
"0\n",
"1\n"
] | [
"11 11\n5\n0 1 0 0 0\n",
"12 11\n5\n0 0 0 0 0\n",
"11 11\n5\n1 0 0 1 1\n",
"11 8\n5\n0 1 0 0 0\n",
"11 14\n5\n0 1 0 0 0\n",
"0 14\n5\n0 1 0 0 0\n",
"0 25\n5\n0 1 0 0 0\n",
"11 11\n5\n1 0 1 1 1\n",
"11 11\n8\n0 1 0 0 0\n",
"11 19\n5\n0 1 0 0 0\n"
] | [
"1\n",
"0\n",
"2\n",
"1\n",
"1\n",
"1\n",
"1\n",
"1\n",
"1\n",
"1\n"
] |
CodeContests | New AtCoder City has an infinite grid of streets, as follows:
* At the center of the city stands a clock tower. Let (0, 0) be the coordinates of this point.
* A straight street, which we will call East-West Main Street, runs east-west and passes the clock tower. It corresponds to the x-axis in the two-dimensional coor... | stdin | null | 2,161 | 1 | [
"8\n2 2 286017\n3 1 262355\n2 -2 213815\n1 -3 224435\n-2 -2 136860\n-3 -1 239338\n-2 2 217647\n-1 3 141903\n",
"5\n3 5 400\n5 3 700\n5 5 1000\n5 7 700\n7 5 400\n",
"6\n2 5 1000\n5 2 1100\n5 5 1700\n-2 -5 900\n-5 -2 600\n-5 -5 2200\n",
"3\n1 2 300\n3 3 600\n1 4 800\n"
] | [
"2576709\n1569381\n868031\n605676\n366338\n141903\n0\n0\n0\n",
"13800\n1600\n0\n0\n0\n0\n",
"26700\n13900\n3200\n1200\n0\n0\n0\n",
"2900\n900\n0\n0\n"
] | [
"8\n2 2 286017\n3 1 262355\n2 -2 213815\n1 -3 224435\n-2 -2 136860\n-3 -1 239338\n-2 1 217647\n-1 3 141903\n",
"5\n3 5 400\n5 3 700\n5 5 1000\n4 7 700\n7 5 400\n",
"6\n2 4 1000\n5 2 1100\n5 5 1700\n-2 -5 900\n-5 -2 600\n-5 -5 2200\n",
"3\n1 2 300\n3 3 600\n1 4 1273\n",
"8\n2 2 456035\n3 1 262355\n2 -2 21381... | [
"2359062 1359398 868031 503198 278763 136860 0 0 0\n",
"13100 2300 700 0 0 0\n",
"26700 13900 3200 1200 0 0 0\n",
"3373 900 0 0\n",
"2699098 1359398 868031 503198 278763 136860 0 0 0\n",
"12155 2170 385 0 0 0\n",
"24900 12700 2000 0 0 0 0\n",
"4313 900 0 0\n",
"2699098 1359398 737493 361295 136860 0... |
CodeContests | Today professor Ka has given a string task to Oz and RK. He has given a string STR consisting only of characters '(' and ')' and asked them to convert the string STR into a closed one by adding parenthesis to start and/or end of string STR.
This means that they could add characters either only to the start of string ... | stdin | null | 2,081 | 1 | [
"1\n)(\n\nSAMPLE\n"
] | [
"()()\n"
] | [
"20\n((\n)(\n(((())))\n)()(\n()\n)((()\n())(\n)(((()(((()(\n)()()(\n()))())(()())(()()(()((()()(()()()())()\n))))))))()())(()))()))))))())(())(\n))()(((())()))((()())()\n()\n(()()))\n(()((((()(())(((())(()))(()()())))((())(())()()\n)((()())(())\n(((((((((()))))()(()())(((())((())())(((\n)(())(()))()(())(()(()((()))... | [
"(())\n()()\n(((())))\n()()()\n()\n()((()))\n(())()\n()(((()(((()()))))))\n()()()()\n(((()))())(()())(()()(()((()()(()()()())()))))\n((((((((((((((((())))))))()())(()))()))))))())(())()\n(())()(((())()))((()())())\n()\n((()()))\n(()((((()(())(((())(()))(()()())))((())(())()())))))\n()((()())(()))\n(((((((((()))))()... |
CodeContests | You are playing the following game with Joisino.
* Initially, you have a blank sheet of paper.
* Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times.
* Then, you are asked a question: How many numbe... | stdin | null | 3,678 | 1 | [
"3\n6\n2\n6\n",
"4\n2\n5\n5\n2\n",
"6\n12\n22\n16\n22\n18\n12\n"
] | [
"1\n",
"0\n",
"2\n"
] | [
"3\n6\n2\n7\n",
"4\n3\n5\n5\n2\n",
"6\n12\n22\n18\n22\n18\n12\n",
"4\n3\n5\n9\n1\n",
"6\n4\n47\n28\n35\n18\n12\n",
"3\n0\n0\n10\n",
"3\n6\n2\n8\n",
"4\n3\n5\n5\n1\n",
"6\n12\n22\n18\n35\n18\n12\n",
"3\n3\n2\n8\n"
] | [
"3\n",
"2\n",
"0\n",
"4\n",
"6\n",
"1\n",
"3\n",
"2\n",
"2\n",
"3\n"
] |
CodeContests | We have a round pizza. Snuke wants to eat one third of it, or something as close as possible to that.
He decides to cut this pizza as follows.
First, he divides the pizza into N pieces by making N cuts with a knife. The knife can make a cut along the segment connecting the center of the pizza and some point on the ci... | stdin | null | 3,915 | 1 | [
"2\n",
"3\n",
"10\n",
"1000000\n"
] | [
"138888890\n",
"179012347\n",
"954859137\n",
"44679646\n"
] | [
"4\n",
"6\n",
"15\n",
"8\n",
"11\n",
"7\n",
"1\n",
"5\n",
"18\n",
"9\n"
] | [
"315586422\n",
"503006405\n",
"957950613\n",
"840776333\n",
"829296161\n",
"7661693\n",
"333333336\n",
"577489716\n",
"424877745\n",
"771752662\n"
] |
CodeContests | Given a string S consisting of only 1s and 0s, find the number of substrings which start and end both in 1.
In this problem, a substring is defined as a sequence of continuous characters Si, Si+1, ..., Sj where 1 ≤ i ≤ j ≤ N.
Input
First line contains T, the number of testcases. Each testcase consists of N(the length... | stdin | null | 1,790 | 1 | [
"2\n4\n1111\n5\n10001\n"
] | [
"10\n3\n"
] | [
"2\n4\n1111\n5\n10000\n",
"2\n4\n1111\n5\n10100\n",
"2\n4\n1011\n5\n10000\n",
"2\n4\n1110\n5\n10100\n",
"2\n4\n1001\n5\n10000\n",
"2\n4\n1111\n5\n10011\n",
"2\n4\n0001\n2\n10000\n",
"2\n4\n1111\n5\n00000\n",
"2\n4\n1011\n5\n11100\n",
"2\n4\n1001\n5\n10100\n"
] | [
"10\n1\n",
"10\n3\n",
"6\n1\n",
"6\n3\n",
"3\n1\n",
"10\n6\n",
"1\n1\n",
"10\n0\n",
"6\n6\n",
"3\n3\n"
] |
CodeContests | problem
There is a mysterious device $ M $, and if you put Tanuki and Fox in this device, one animal will come out from the device (hereinafter, Tanuki will be $ T $ and Fox will be $ F $).
$ M (x, y) $ represents an animal that came out by putting animals in the device $ M $ in the order of $ x, y $.
As a result of... | stdin | null | 3,533 | 1 | [
"3\nF T T\n"
] | [
"T\n"
] | [
"3\nF S T\n",
"3\nF R T\n",
"3\nG S T\n",
"3\nG R T\n",
"3\nH R T\n",
"3\nF U T\n",
"3\nE S T\n",
"3\nE T T\n",
"3\nD T T\n",
"3\nI R T\n"
] | [
"T\n",
"T\n",
"T\n",
"T\n",
"T\n",
"T\n",
"T\n",
"T\n",
"T\n",
"T\n"
] |
CodeContests | Intersections of Crossing Path City are aligned to a grid. There are $N$ east-west streets which are numbered from 1 to $N$, from north to south. There are also $N$ north-south streets which are numbered from 1 to $N$, from west to east. Every pair of east-west and north-south streets has an intersection; therefore the... | stdin | null | 1,147 | 1 | [
"4\n12 1\n3 8\n10 7\n13 14\n8 2\n9 12\n6 14\n11 3\n3 13\n1 10\n11 15\n4 15\n4 9\n14 10\n5 7\n2 5\n6 1\n14 5\n16 11\n15 6\n15 13\n9 6\n16 4\n13 2\n",
"3\n1 2\n4 7\n8 6\n2 3\n8 9\n5 3\n4 6\n5 6\n7 8\n1 4\n2 6\n5 9\n"
] | [
"8 2 5 7\n3 13 14 10\n11 15 6 1\n16 4 9 12\n",
"7 4 1\n8 6 2\n9 5 3\n"
] | [
"3\n1 2\n4 7\n8 6\n2 3\n8 9\n5 3\n4 9\n5 6\n7 8\n1 4\n2 9\n5 9\n",
"3\n2 1\n4 7\n8 6\n2 3\n8 9\n5 3\n4 6\n5 6\n7 8\n1 4\n2 6\n5 9\n"
] | [
"1 2 3 \n4 9 5 \n7 8 6\n",
"1 2 3 \n4 6 5 \n7 8 9\n"
] |
CodeContests | Andrew has recently moved to Wengaluru. He finds this city amazing as all the buildings of the city are of same shape. There are N buildings in a row with no space in between. Buildings may have different heights while width in other two dimensions is always 1 unit.
Rain occurs very frequently in Wengaluru so Andre... | stdin | null | 1,351 | 1 | [
"2\n5\n3 2 1 4 5\n5\n1 2 3 4 5\n\nSAMPLE\n"
] | [
"3\n0\n"
] | [
"2\n5\n3 4 1 4 5\n5\n1 2 3 4 5\n\nSAMPLE\n",
"2\n5\n3 4 2 4 5\n5\n1 2 3 4 5\n\nSAMPLE\n",
"2\n5\n3 2 1 4 5\n5\n1 4 3 4 5\n\nSAMPLE\n",
"2\n5\n2 7 2 4 5\n5\n1 2 3 4 5\n\nSAMPLE\n",
"2\n5\n5 1 2 5 5\n5\n1 2 3 4 5\n\nSAMPLE\n",
"2\n5\n3 2 1 4 5\n5\n1 4 3 3 4\n\nSAMPLE\n",
"2\n5\n3 4 1 3 5\n5\n1 2 2 1 5\n\n... | [
"3\n0\n",
"2\n0\n",
"3\n1\n",
"4\n0\n",
"7\n0\n",
"3\n2\n",
"4\n1\n",
"2\n1\n",
"6\n0\n",
"1\n1\n"
] |
CodeContests | N hotels are located on a straight line. The coordinate of the i-th hotel (1 \leq i \leq N) is x_i.
Tak the traveler has the following two personal principles:
* He never travels a distance of more than L in a single day.
* He never sleeps in the open. That is, he must stay at a hotel at the end of a day.
You are ... | stdin | null | 419 | 1 | [
"9\n1 3 6 13 15 18 19 29 31\n10\n4\n1 8\n7 3\n6 7\n8 5\n"
] | [
"4\n2\n1\n2\n"
] | [
"9\n1 3 6 13 15 18 19 29 31\n10\n2\n1 8\n7 3\n6 7\n8 5\n",
"9\n1 6 6 13 23 18 19 29 31\n10\n3\n1 8\n7 3\n6 7\n8 10\n",
"9\n1 3 6 13 23 18 19 29 31\n10\n2\n1 8\n7 5\n6 7\n8 5\n",
"9\n1 3 6 13 23 18 19 29 31\n10\n2\n1 9\n7 3\n6 7\n8 10\n",
"9\n1 3 6 13 23 18 19 29 31\n12\n2\n1 8\n1 3\n9 7\n8 7\n",
"9\n1 3 6... | [
"4\n2\n",
"4\n2\n1\n",
"4\n1\n",
"5\n2\n",
"3\n1\n",
"3\n2\n",
"5\n3\n",
"5\n2\n1\n",
"1\n1\n",
"2\n1\n1\n"
] |
CodeContests | Raghu wants to design a converter such that when a user inputs a binary number it gets converted to Octal number & also the correspond alphabet to it.
Example- if a user inputs- 10101101
then the output is 255 BEE
Note : for decimal places there should be a space between the alphabetic signs
Ex- for input 1011011011... | stdin | null | 520 | 1 | [
"10101101\n\nSAMPLE\n"
] | [
"255 BEE\n"
] | [
"10101111\n",
"10101101\n\nSAPMLE\n",
"11101101\n",
"11100101\n",
"10100101\n",
"10101101\n\nTAPMLE\n",
"10101101\n\nMAPTLE\n",
"10101101\n\nMTPALE\n",
"10101101\n\nMSPALE\n",
"10101101\n\nMRPALE\n"
] | [
"257 BEG\n",
"255 BEE\n",
"355 CEE\n",
"345 CDE\n",
"245 BDE\n",
"255 BEE\n",
"255 BEE\n",
"255 BEE\n",
"255 BEE\n",
"255 BEE\n"
] |
CodeContests | HackerMan has a message that he has coded in form of digits, which means that the message contains only numbers and nothing else. He is fearful that the enemy may get their hands on the secret message and may decode it. HackerMan already knows the message by heart and he can simply destroy it.
But he wants to keep it ... | stdin | null | 327 | 1 | [
"3\n353 575\n238746 39857\n890 231\n\nSAMPLE\n"
] | [
"829\n527327\n32\n"
] | [
"994\n4789 1537\n2363 1131\n3948 2406\n4077 621\n4449 387\n406 3977\n2759 878\n1058 3651\n2356 1943\n3039 2573\n3138 2424\n1371 518\n4387 4339\n1646 2566\n387 481\n1633 2163\n3508 1815\n1011 2131\n3314 2819\n2842 3282\n4031 631\n67 4941\n3264 4893\n652 1712\n3117 4992\n2827 552\n4961 2581\n4621 987\n508 3727\n3463 ... | [
"52271\n3494\n53541\n387\n72201\n7938\n5401\n46001\n32001\n55031\n55521\n6452\n86171\n31131\n769\n3796\n43231\n3142\n51331\n5035\n441\n751\n7068\n7242\n70101\n7357\n6453\n3502\n8708\n63711\n9274\n64221\n3945\n9129\n999\n5438\n3604\n72241\n5978\n47151\n2058\n57421\n95\n7453\n1255\n4015\n5905\n56811\n34721\n28901\n81... |
CodeContests | Takahashi is hosting an sports meet. There are N people who will participate. These people are conveniently numbered 1 through N. Also, there are M options of sports for this event. These sports are numbered 1 through M. Among these options, Takahashi will select one or more sports (possibly all) to be played in the ev... | stdin | null | 2,523 | 1 | [
"3 3\n2 1 3\n2 1 3\n2 1 3\n",
"4 5\n5 1 3 4 2\n2 5 3 1 4\n2 3 1 4 5\n2 5 4 3 1\n"
] | [
"3\n",
"2\n"
] | [
"2 5\n5 1 3 4 2\n2 5 3 1 4\n2 3 1 4 5\n2 5 4 3 1\n",
"2 3\n2 1 3\n2 1 3\n2 1 3\n",
"2 5\n5 1 3 4 2\n2 5 3 1 4\n2 3 1 6 5\n2 5 4 3 1\n",
"2 5\n5 1 3 4 2\n2 5 3 1 4\n2 3 1 6 7\n2 5 4 3 1\n",
"2 5\n5 1 3 4 2\n2 5 3 1 4\n2 0 1 4 5\n2 5 4 3 1\n",
"2 5\n5 1 3 4 2\n2 5 3 1 4\n2 3 1 4 5\n2 5 5 3 1\n",
"2 5\n5 1... | [
"1\n",
"2\n",
"1\n",
"1\n",
"1\n",
"1\n",
"1\n",
"1\n",
"1\n",
"1\n"
] |
CodeContests | To become a millionaire, M-kun has decided to make money by trading in the next N days. Currently, he has 1000 yen and no stocks - only one kind of stock is issued in the country where he lives.
He is famous across the country for his ability to foresee the future. He already knows that the price of one stock in the n... | stdin | null | 213 | 1 | [
"2\n157 193\n",
"7\n100 130 130 130 115 115 150\n",
"6\n200 180 160 140 120 100\n"
] | [
"1216\n",
"1685\n",
"1000\n"
] | [
"2\n157 145\n",
"7\n100 130 243 130 115 115 150\n",
"6\n200 237 160 140 120 100\n",
"2\n157 218\n",
"7\n100 130 243 130 115 115 271\n",
"6\n200 237 160 233 120 100\n",
"2\n103 218\n",
"7\n110 130 243 130 115 115 271\n",
"7\n110 130 136 130 115 115 271\n",
"6\n200 237 119 233 121 100\n"
] | [
"1000\n",
"3165\n",
"1185\n",
"1366\n",
"5706\n",
"1696\n",
"2035\n",
"5161\n",
"2794\n",
"2211\n"
] |
CodeContests | There was girl named Julia in their neighbourhood. Both of them liked her and were trying to impress her. Now that Tim and Bob are done with daddy’s game. Julia thought that Tim solved the game on his own and was deeply impressed. After few days, Julia and Tim realised they fell in love with each other. They started ta... | stdin | null | 4,295 | 1 | [
"4\n2\nKOKUUW\n4\nALEXCSYIEX\n9\nFQHJANHXDXOOURWN\n1\nXIPXBTTIF\n\nSAMPLE\n"
] | [
"IMISSU\nWHATYOUEAT\nWHYAREYOUOFFLINE\nWHOWASSHE\n"
] | [
"4\n2\nKOKUUW\n3\nALEXCSYIEX\n9\nFQHJANHXDXOOURWN\n1\nXIPXBTTIF\n",
"8\n4\nRLALFNFDJAIDFHSLFJSAA\n5\nSJFLRAHIALOANFGHSIEHD\n6\nAFLSJFEIVNSARIENBALAED\n5\nADFLAJDFEHELDFSALJ\n25\nASDFJRRZZZZZZZJRJEALR\n3\nALJSLDKFJKLJSRELJDSL\n5\nARJLHAULDJALDFNDFLAJ\n5\nALRALJIEOABLSIAJZJOAS\n",
"4\n3\nKOKUUW\n4\nALEXCSYIEX\n9\... | [
"IMISSU\nXIBUZPVFBU\nWHYAREYOUOFFLINE\nWHOWASSHE\n",
"NHWHBJBZFWEZBDOHBFOWW\nNEAGMVCDVGJVIABCNDZCY\nUZFMDZYCPHMULCYHVUFUYX\nVYAGVEYAZCZGYANVGE\nBTEGKSSAAAAAAAKSKFBMS\nXIGPIAHCGHIGPOBIGAPI\nVMEGCVPGYEVGYAIYAGVE\nVGMVGEDZJVWGNDVEUEJVN\n",
"HLHRRT\nWHATYOUEAT\nWHYAREYOUOFFLINE\nWHOWASSHE\n",
"JNJTTV\nXIBUZPVFBU\... |
CodeContests | This issue is the same configuration issue as G: DAG Trio (Hard), with only the constraints being different.
input
$ N \ M $
$ a_1 \ b_1 $
$ a_2 \ b_2 $
$ \ vdots $
$ a_M \ b_M $
output
Print "YES" or "NO" on the $ 1 $ line.
Example
Input
3 3
1 2
2 3
3 1
Output
YES | stdin | null | 391 | 1 | [
"3 3\n1 2\n2 3\n3 1\n"
] | [
"YES\n"
] | [
"3 3\n1 1\n2 3\n3 1\n",
"6 3\n1 2\n2 2\n1 1\n",
"3 3\n1 1\n2 3\n2 1\n",
"3 3\n2 2\n2 3\n3 1\n",
"3 3\n2 2\n2 3\n2 1\n",
"3 3\n1 2\n2 2\n3 1\n",
"3 3\n1 2\n2 3\n1 1\n",
"3 3\n1 2\n3 2\n3 1\n",
"3 3\n3 2\n2 2\n3 1\n",
"3 3\n2 2\n2 1\n3 1\n"
] | [
"YES\n",
"NO\n",
"YES\n",
"YES\n",
"YES\n",
"YES\n",
"YES\n",
"YES\n",
"YES\n",
"YES\n"
] |
CodeContests | You received a card at a banquet. On the card, a matrix of $N$ rows and $M$ columns and two integers $K$ and $S$ are written. All the elements in the matrix are integers, and an integer at the $i$-th row from the top and the $j$-th column from the left is denoted by $A_{i,j}$.
You can select up to $K$ elements from th... | stdin | null | 2,621 | 1 | [
"2 2 3 100\n0 0\n0 0\n",
"3 3 2 10\n5 3 7\n2 6 1\n3 4 1\n",
"2 3 1 5\n4 8 -2\n-2 -5 -3\n",
"2 3 1 5\n9 8 -2\n-2 -5 -3\n"
] | [
"Yes\n",
"Yes\n",
"Yes\n",
"No\n"
] | [
"2 2 6 100\n0 0\n0 0\n",
"2 3 1 7\n9 8 -2\n-2 -5 -3\n",
"0 3 2 10\n5 3 7\n2 6 1\n3 4 1\n",
"2 3 1 5\n4 8 0\n-2 -5 -3\n",
"2 2 6 100\n0 1\n0 0\n",
"0 3 2 10\n5 3 7\n0 6 1\n3 4 1\n",
"2 1 6 100\n0 1\n0 0\n",
"0 3 2 10\n5 3 6\n0 6 1\n3 4 1\n",
"2 2 6 100\n0 1\n0 -1\n",
"0 3 2 6\n5 3 6\n0 6 1\n3 4 1\n... | [
"Yes\n",
"No\n",
"Yes\n",
"Yes\n",
"Yes\n",
"Yes\n",
"Yes\n",
"Yes\n",
"Yes\n",
"Yes\n"
] |
CodeContests | Example
Input
6 5 1 2 3
5 5 5
1 5 5
2 5 4
3 5 3
4 5 2
5 5 1
Output
0.631579 | stdin | null | 2,614 | 1 | [
"6 5 1 2 3\n5 5 5\n1 5 5\n2 5 4\n3 5 3\n4 5 2\n5 5 1\n"
] | [
"0.631579\n"
] | [
"6 5 1 2 3\n5 5 5\n1 5 5\n2 5 3\n3 5 3\n4 5 2\n5 5 1\n",
"6 5 1 4 3\n5 5 5\n1 5 5\n2 3 3\n3 1 3\n4 3 2\n5 5 0\n",
"6 5 1 4 3\n5 5 5\n1 5 5\n2 3 5\n3 1 3\n4 3 2\n5 5 0\n",
"6 5 1 4 3\n5 5 9\n1 5 5\n2 3 5\n3 1 3\n4 3 2\n5 5 0\n",
"12 5 1 4 3\n5 5 9\n1 5 5\n2 3 5\n3 1 3\n4 3 2\n5 5 0\n",
"12 5 1 4 3\n5 5 16\... | [
"0.666666667\n",
"0.800000000\n",
"0.750000000\n",
"1.500000000\n",
"3.000000000\n",
"3.100000000\n",
"2.857142857\n",
"3.809523810\n",
"1.330065359\n",
"0.961764706\n"
] |
CodeContests | In the speed skating badge test, grades are awarded when the time specified for two distances is exceeded. For example, to reach Class A, 500 M requires less than 40.0 seconds and 1000 M requires less than 1 minute and 23 seconds.
Create a program that takes the time recorded in the speed skating competitions (500 M a... | stdin | null | 4,629 | 1 | [
"40.0 70.0\n72.5 140.51\n"
] | [
"B\nNA\n"
] | [
"40.0 70.15273874709118\n72.5 140.51\n",
"43.236780306897465 72.47791800727414\n76.48007184592961 143.3245253779178\n",
"50.825010742906116 75.69989732783311\n82.26479437960049 146.33206365267094\n",
"55.48794721361476 79.14473639758064\n86.53074549795734 149.70848351203585\n",
"70.02963720383003 94.7231292... | [
"B\nNA\n",
"C\nNA\n",
"D\nNA\n",
"E\nNA\n",
"NA\nNA\n",
"B\nNA\n",
"B\nNA\n",
"B\nNA\n",
"B\nNA\n",
"B\nNA\n"
] |
CodeContests | In some other world, today is the day before Christmas Eve.
Mr. Takaha is buying N items at a department store. The regular price of the i-th item (1 \leq i \leq N) is p_i yen (the currency of Japan).
He has a discount coupon, and can buy one item with the highest price for half the regular price. The remaining N-1 i... | stdin | null | 2,402 | 1 | [
"4\n4320\n4320\n4320\n4320\n",
"3\n4980\n7980\n6980\n"
] | [
"15120\n",
"15950\n"
] | [
"4\n4320\n7204\n4320\n4320\n",
"3\n32\n7980\n6980\n",
"3\n32\n7980\n615\n",
"3\n6\n7980\n615\n",
"3\n6\n7980\n329\n",
"3\n6\n7980\n207\n",
"3\n7\n7980\n207\n",
"3\n7\n7980\n269\n",
"3\n7\n4428\n269\n",
"3\n7\n4428\n505\n"
] | [
"16562\n",
"11002\n",
"4637\n",
"4611\n",
"4325\n",
"4203\n",
"4204\n",
"4266\n",
"2490\n",
"2726\n"
] |
CodeContests | There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs.
Determine if it is possible that there are exactly X cats among these A + B animals.
Constraints
* 1 \leq A \leq 100
* 1 \leq B \leq 100
* 1 \leq X \leq 200
* All values in input... | stdin | null | 1,529 | 1 | [
"2 2 6\n",
"3 5 4\n",
"5 3 2\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | [
"2 0 6\n",
"2 5 4\n",
"5 3 3\n",
"2 -1 6\n",
"4 5 4\n",
"2 3 3\n",
"2 0 0\n",
"5 5 4\n",
"2 3 5\n",
"2 0 1\n"
] | [
"NO\n",
"YES\n",
"NO\n",
"NO\n",
"YES\n",
"YES\n",
"NO\n",
"NO\n",
"YES\n",
"NO\n"
] |
CodeContests | Almost periodic string
Given the string S. Answer Q queries for this string S. In the i-th query, determine if S [l_i, \ r_i] can be a string of period t_i when you can change from S [l_i, \ r_i] to one character. S [l, \ r] represents the substring of the string S from the lth to the rth.
If the character string W i... | stdin | null | 1,785 | 1 | [
"abcabcaxcabc\n4\n1 9 3\n8 12 3\n1 4 2\n2 3 2\n"
] | [
"Yes\nYes\nNo\nYes\n"
] | [
"abcabcaxcabc\n2\n1 9 3\n8 12 3\n1 4 2\n2 3 2\n",
"abcabcaxcabc\n2\n0 9 3\n8 12 3\n0 0 1\n4 5 1\n",
"abcabcaxcabc\n4\n1 15 3\n8 12 3\n1 4 2\n2 3 2\n",
"abcabcaxcabc\n2\n0 9 3\n8 12 2\n0 0 1\n4 5 1\n",
"abcabcaxcabc\n4\n1 15 3\n8 12 3\n1 4 2\n2 6 2\n",
"abcabcaxcabc\n2\n2 9 3\n7 12 1\n1 -1 1\n4 4 1\n",
"... | [
"Yes\nYes\n",
"No\nYes\n",
"No\nYes\nNo\nYes\n",
"No\nNo\n",
"No\nYes\nNo\nNo\n",
"Yes\nNo\n",
"Yes\nYes\nNo\nYes\n",
"No\nYes\nNo\nNo\nNo\n",
"Yes\n",
"Yes\nYes\nNo\n"
] |
CodeContests | A tetromino is a figure formed by joining four squares edge to edge. We will refer to the following seven kinds of tetromino as I-, O-, T-, J-, L-, S- and Z-tetrominos, respectively:
a60bcb8e9e8f22e3af51049eda063392.png
Snuke has many tetrominos. The number of I-, O-, T-, J-, L-, S- and Z-tetrominos in his possession... | stdin | null | 1,093 | 1 | [
"2 1 1 0 0 0 0\n",
"0 0 10 0 0 0 0\n"
] | [
"3\n",
"0\n"
] | [
"0 0 10 0 1 0 0\n",
"1 1 1 0 0 0 0\n",
"0 0 -1 0 2 0 2\n",
"4 0 1 0 0 0 0\n",
"0 3 0 0 1 0 0\n",
"0 3 0 0 2 0 0\n",
"6 0 2 0 0 0 0\n",
"11 0 2 0 0 0 0\n",
"14 0 2 0 0 0 0\n",
"2 5 1 0 1 2 2\n"
] | [
"0\n",
"1\n",
"2\n",
"4\n",
"3\n",
"5\n",
"6\n",
"10\n",
"14\n",
"7\n"
] |
CodeContests | Example
Input
4 3
1 3 4 7
Output
6 | stdin | null | 36 | 1 | [
"4 3\n1 3 4 7\n"
] | [
"6\n"
] | [
"4 3\n1 3 2 7\n",
"4 4\n1 3 2 4\n",
"4 4\n1 0 2 4\n",
"4 3\n1 3 2 8\n",
"2 4\n1 3 2 4\n",
"4 4\n1 -1 2 4\n",
"4 3\n1 3 2 13\n",
"2 4\n1 2 2 4\n",
"4 2\n1 3 2 13\n",
"14 5\n2 4 1 -1\n"
] | [
"6\n",
"3\n",
"4\n",
"7\n",
"2\n",
"5\n",
"12\n",
"1\n",
"22\n",
"8\n"
] |
CodeContests | The number obtained by multiplying 1 by 2, 3, 5 several times (0 or more times) is called the Hamming numbers. For example
* 1
* 1 x 2 x 2 = 4
* 1 x 2 x 2 x 3 x 5 x 5 = 300
Etc. are humming numbers, but 11, 13, 14 etc. are not humming numbers.
All humming numbers are divisible by a power of 60 (for example, 54 is ... | stdin | null | 618 | 1 | [
"3 8\n1 27\n1 86\n0\n"
] | [
"5\n17\n31\n"
] | [
"3 8\n2 27\n1 86\n0\n",
"3 9\n2 27\n1 86\n0\n",
"3 8\n1 35\n1 86\n0\n",
"5 8\n2 27\n1 86\n0\n",
"3 9\n4 27\n1 86\n0\n",
"3 9\n6 27\n1 86\n0\n",
"3 9\n6 31\n1 86\n0\n",
"3 6\n6 31\n1 86\n0\n",
"3 6\n6 9\n1 86\n0\n",
"3 6\n8 9\n1 86\n0\n"
] | [
"5\n16\n31\n",
"6\n16\n31\n",
"5\n19\n31\n",
"3\n16\n31\n",
"6\n14\n31\n",
"6\n12\n31\n",
"6\n13\n31\n",
"4\n13\n31\n",
"4\n3\n31\n",
"4\n2\n31\n"
] |
CodeContests | Takahashi lives in another world. There are slimes (creatures) of 10000 colors in this world. Let us call these colors Color 1, 2, ..., 10000.
Takahashi has N slimes, and they are standing in a row from left to right. The color of the i-th slime from the left is a_i. If two slimes of the same color are adjacent, they ... | stdin | null | 1,168 | 1 | [
"5\n1 1 2 2 2\n",
"3\n1 2 1\n",
"14\n1 2 2 3 3 3 4 4 4 4 1 2 3 4\n",
"5\n1 1 1 1 1\n"
] | [
"2\n",
"0\n",
"4\n",
"2\n"
] | [
"5\n1 1 3 2 2\n",
"3\n0 2 1\n",
"14\n1 1 2 3 3 3 4 4 4 4 1 2 3 4\n",
"3\n1 2 2\n",
"14\n1 1 3 3 3 3 4 4 4 4 1 2 3 4\n",
"14\n1 1 3 3 3 4 3 4 4 4 1 2 3 4\n",
"5\n1 1 1 1 0\n",
"5\n1 1 6 2 2\n",
"5\n1 2 1 1 0\n",
"5\n1 1 9 2 2\n"
] | [
"2\n",
"0\n",
"4\n",
"1\n",
"5\n",
"3\n",
"2\n",
"2\n",
"1\n",
"2\n"
] |
CodeContests | Chef is going to participate in a new quiz show: "Who dares to be a millionaire?"
According to the rules of the game, contestants must answer N questions. The quiz being famous for its difficulty, each question has 26 candidate answers, but only one of which is correct. Answers are denoted by capital Latin letters from... | stdin | null | 2,465 | 1 | [
"3\n5\nABCDE\nEBCDA\n0 10 20 30 40 50\n4\nCHEF\nQUIZ\n4 3 2 1 0\n8\nABBABAAB\nABABABAB\n100 100 100 100 100 100 100 100 100\n"
] | [
"30\n4\n100\n"
] | [
"3\n5\nABCDE\nEBCDA\n0 8 20 30 40 50\n4\nCHEF\nQUIZ\n4 3 2 1 0\n8\nABBABAAB\nABABABAB\n100 100 100 100 100 100 100 100 100\n",
"3\n5\nABCDE\nEBBDA\n0 8 20 30 40 50\n1\nCHEF\nQUIZ\n4 3 2 1 0\n8\nABBABAAB\nBABABABA\n100 100 100 100 000 100 100 100 100\n",
"3\n5\nABCDE\nEBCDA\n0 8 20 30 40 50\n4\nCHEF\nQUIZ\n2 3 2... | [
"30\n4\n100\n",
"20\n4\n100\n",
"30\n2\n100\n",
"15\n4\n100\n",
"30\n4\n110\n",
"30\n8\n100\n",
"30\n8\n101\n",
"15\n6\n100\n",
"40\n6\n100\n",
"13\n2\n100\n"
] |
CodeContests | Let's play a game using a robot on a rectangular board covered with a square mesh (Figure D-1). The robot is initially set at the start square in the northwest corner facing the east direction. The goal of this game is to lead the robot to the goal square in the southeast corner.
<image>
Figure D-1: Example of a boar... | stdin | null | 2,138 | 1 | [
"8 3\n0 0 0 0 0 0 0 1\n2 3 0 1 4 0 0 1\n3 3 0 0 0 0 0 4\n9 9 1 9\n4 4\n3 3 4 0\n1 2 4 4\n1 1 1 0\n0 2 4 4\n8 7 2 1\n2 8\n2 2\n4 1\n0 4\n1 3\n1 0\n2 1\n0 3\n1 4\n1 9 3 1\n0 0\n"
] | [
"1\n11\n6\n"
] | [
"8 3\n0 0 0 0 0 0 0 1\n2 3 0 1 4 0 0 1\n3 3 0 0 0 0 0 4\n9 9 1 9\n4 4\n3 3 4 0\n1 2 4 4\n1 1 1 0\n0 2 2 4\n8 7 2 1\n2 8\n2 2\n4 1\n0 4\n1 3\n1 0\n2 1\n0 3\n1 4\n1 9 3 1\n0 0\n",
"8 3\n0 0 0 0 0 0 0 1\n2 3 0 1 4 0 0 1\n3 3 0 0 0 0 0 4\n9 9 1 9\n4 4\n3 3 4 0\n1 2 4 4\n1 1 1 0\n0 2 2 4\n8 7 2 1\n2 8\n0 2\n4 1\n0 4\n... | [
"1\n11\n6\n",
"1\n11\n5\n",
"9\n11\n6\n",
"2\n11\n5\n",
"9\n10\n6\n",
"10\n10\n6\n",
"1\n10\n6\n",
"1\n11\n9\n",
"9\n14\n6\n",
"2\n10\n5\n"
] |
CodeContests | Anti-aircraft shield
In 3xxx, human beings who advanced to planets outside the solar system were troubled by the damage to the base caused by the arrival of a large number of meteorites. The International Cosmic Protection Company has developed a new anti-aircraft shield to solve this problem.
The base to be protecte... | stdin | null | 2,702 | 1 | [
"3 3\n2 1\n2 2\n10\n10 4\n1 1\n1 5\n1 9\n1\n5 7\n1000000000 1\n1000000000 1\n1000000000 3\n1000000000 3\n1000000000 5\n1000000000 5\n1\n10000 11\n10934235 560\n3155907 1508\n10901182 2457\n3471816 3590\n10087848 4417\n16876957 5583\n23145027 6540\n15162205 7454\n1749653 8481\n6216466 9554\n7198514\n701 14\n8181 636... | [
"10\n0\n5999999960\n23574372\n985\n"
] | [
"3 3\n2 1\n2 2\n10\n10 4\n1 1\n1 5\n1 9\n1\n5 7\n1000000000 1\n1000000000 1\n1000000000 3\n1000000000 3\n1000000000 5\n1000000000 5\n1\n10000 11\n10934235 560\n3155907 1508\n10901182 2457\n3471816 3590\n10087848 4417\n16876957 5583\n12555319 6540\n15162205 7454\n1749653 8481\n6216466 9554\n7198514\n701 14\n8181 636... | [
"10\n0\n5999999960\n16375858\n985\n",
"10\n0\n5999999960\n16375858\n2626\n",
"10\n0\n5999999960\n16375858\n2002\n",
"10\n0\n5999999960\n16375858\n264\n",
"10\n0\n5999999960\n23574372\n985\n",
"10\n0\n5999999960\n18246381\n2002\n",
"10\n0\n5999999960\n23574372\n0\n",
"11\n0\n5999999960\n16375858\n2002\... |
CodeContests | Step up and down
Kazuki, commonly known as Kerr, who attends JAG University, was invited by your friend this summer to participate in the ICPC (International Collegiate Potchari Contest). ICPC is a sports contest and requires a high degree of athletic ability. However, Mr. Kerr was always in front of the computer, and... | stdin | null | 35 | 1 | [
"4\nlu ru ld rd\n4\nlu ld lu ru\n1\nlu\n10\nru lu ld rd ru rd ru lu rd ld\n0\n"
] | [
"2\n1\n0\n4\n"
] | [
"4\nlu ru ld rd\n4\nlu ld lu ru\n0\nlu\n10\nru lu ld rd ru rd ru lu rd ld\n0\n",
"4\nlu ru ld rd\n0\nlu ld lu ru\n0\nul\n10\nvr lu ld rd rv rd ru lu rc kd\n0\n",
"4\nlu ru ld rd\n4\nlu ld lu ru\n0\nul\n10\nru lu ld rd ru rd ru lu rd ld\n0\n",
"4\nlu ru ld rd\n4\nlu ld lu ru\n0\nlu\n10\nru lu ld rd su rd ru lu... | [
"2\n1\n",
"2\n",
"2\n1\n",
"2\n1\n",
"2\n1\n",
"2\n1\n",
"2\n1\n",
"2\n1\n",
"2\n1\n",
"2\n1\n"
] |
CodeContests | Sorting algorithms for sorting data are basic algorithms indispensable in computer science. For example, as shown in the figure below, the operation of "sorting the elements of an array of integer values in ascending order" is alignment.
<image>
Many alignment algorithms have been devised, but one of the basic alg... | stdin | null | 25 | 1 | [
"5\n5\n3\n2\n1\n4\n6\n1\n2\n3\n4\n5\n6\n3\n3\n2\n1\n0\n"
] | [
"7\n0\n3\n"
] | [
"5\n5\n3\n2\n1\n7\n6\n1\n2\n3\n4\n5\n6\n3\n3\n2\n1\n0\n",
"5\n5\n3\n2\n1\n7\n6\n1\n2\n3\n4\n0\n6\n3\n3\n2\n1\n0\n",
"5\n5\n3\n2\n1\n4\n6\n1\n2\n2\n4\n5\n6\n3\n3\n2\n1\n0\n",
"5\n5\n3\n2\n1\n7\n6\n1\n2\n3\n4\n5\n6\n3\n3\n3\n1\n0\n",
"5\n5\n3\n2\n1\n7\n6\n1\n2\n3\n8\n5\n6\n3\n3\n3\n1\n0\n",
"5\n5\n3\n2\n1\n... | [
"6\n0\n3\n",
"6\n4\n3\n",
"7\n0\n3\n",
"6\n0\n2\n",
"6\n2\n2\n",
"6\n13\n",
"9\n0\n3\n",
"6\n3\n2\n",
"5\n13\n",
"5\n11\n"
] |
CodeContests | As we have seen that Vaishnav was a smart kid and today he has grown up(but he is still childish)
and he is in High school.
Today he was back from school and found that 4 pieces of Pizza was
ordered- one for his father, one for this mother, and one for Vaishnavi and one for him. But
Vaishnav was little late from schoo... | stdin | null | 4,697 | 1 | [
"3\n4\n5\n6\n\nSAMPLE\n"
] | [
"5\n9\n11\n"
] | [
"6668\n1\n2\n4\n5\n7\n8\n10\n11\n13\n14\n16\n17\n19\n20\n22\n23\n25\n26\n28\n29\n31\n32\n34\n35\n37\n38\n40\n41\n43\n44\n46\n47\n49\n50\n52\n53\n55\n56\n58\n59\n61\n62\n64\n65\n67\n68\n70\n71\n73\n74\n76\n77\n79\n80\n82\n83\n85\n86\n88\n89\n91\n92\n94\n95\n97\n98\n100\n101\n103\n104\n106\n107\n109\n110\n112\n113\n1... | [
"0\n1\n5\n9\n17\n21\n31\n41\n57\n63\n79\n95\n119\n127\n149\n171\n199\n211\n241\n269\n307\n323\n359\n383\n431\n449\n489\n529\n583\n603\n649\n695\n753\n773\n829\n881\n939\n963\n1027\n1085\n1161\n1191\n1259\n1307\n1393\n1425\n1493\n1563\n1659\n1695\n1771\n1831\n1933\n1965\n2059\n2141\n2229\n2271\n2367\n2455\n2551\n259... |
CodeContests | <!--
Problem D
-->
Tally Counters
A number of tally counters are placed in a row. Pushing the button on a counter will increment the displayed value by one, or, when the value is already the maximum, it goes down to one. All the counters are of the same model with the same maximum value.
<image> Fig. D-1 Tally Cou... | stdin | null | 4,794 | 1 | [
"4 5\n2 3 1 4\n2 5 5 2\n3 100\n1 10 100\n1 10 100\n5 10000\n4971 7482 1238 8523 1823\n3287 9013 9812 297 1809\n0 0\n"
] | [
"4\n0\n14731\n"
] | [
"4 5\n2 3 1 4\n2 5 5 2\n3 100\n1 10 100\n1 10 100\n5 10000\n4971 7482 1238 8523 1823\n3287 9013 9928 297 1809\n0 0\n",
"4 5\n2 3 1 4\n2 5 5 2\n3 100\n1 10 100\n1 14 100\n5 10000\n4971 7482 1238 8523 1823\n3287 9013 9928 297 1809\n0 0\n",
"4 5\n2 3 1 4\n2 5 5 2\n3 100\n1 10 100\n1 10 100\n5 10000\n4971 7482 1238... | [
"4\n0\n14615\n",
"4\n4\n14615\n",
"4\n0\n13149\n",
"4\n99\n14615\n",
"3\n4\n14615\n",
"5\n4\n14615\n",
"4\n0\n11939\n",
"5\n10\n14615\n",
"5\n10\n15385\n",
"4\n91\n11939\n"
] |
CodeContests | Definition:
Roy's boolean function (RBF) is True, if number of the positive integers less than or equal to N that are relatively prime to N, is prime; else False.
In other words, let Z be the number of integers K in the range 1 ≤ K ≤ N for which the greatest common divisor gcd(N, K) = 1. If Z is prime then RBF is True ... | stdin | null | 1,160 | 1 | [] | [] | [
"10\n10\n7\n9\n5\n6\n8\n1\n6\n2\n4\n",
"10\n3\n846\n2\n305\n186\n6\n473\n512\n567\n4\n",
"10\n916\n1\n975\n1\n964\n986\n6\n904\n906\n906\n",
"10\n93937\n91678\n97274\n3\n90836\n94116\n91419\n91453\n96110\n95153\n",
"10\n93937\n91678\n97274\n5\n90836\n94116\n91419\n91453\n96110\n95153\n",
"10\n10\n11\n9\n5... | [
"FALSE\nFALSE\nFALSE\nFALSE\nTRUE\nFALSE\nFALSE\nTRUE\nFALSE\nTRUE\n",
"TRUE\nFALSE\nFALSE\nFALSE\nFALSE\nTRUE\nFALSE\nFALSE\nFALSE\nTRUE\n",
"FALSE\nFALSE\nFALSE\nFALSE\nFALSE\nFALSE\nTRUE\nFALSE\nFALSE\nFALSE\n",
"FALSE\nFALSE\nFALSE\nTRUE\nFALSE\nFALSE\nFALSE\nFALSE\nFALSE\nFALSE\n",
"FALSE\nFALSE\nFALSE... |
CodeContests | After counting so many stars in the sky in his childhood, Isaac, now an astronomer and a mathematician, uses a big astronomical telescope and lets his image processing program count stars. The hardest part of the program is to judge if a shining object in the sky is really a star. As a mathematician, the only way he kn... | stdin | null | 4,316 | 1 | [
"6\n66 13\n96 61\n76 98\n13 94\n4 0\n45 68\n8\n27 21\n55 14\n93 12\n56 95\n15 48\n38 46\n51 65\n64 31\n0\n"
] | [
"1\n0\n"
] | [
"6\n66 13\n96 61\n76 98\n13 94\n4 0\n45 68\n8\n27 21\n55 14\n93 12\n56 95\n15 48\n38 46\n51 65\n35 31\n0\n",
"6\n66 13\n96 61\n76 98\n13 133\n4 0\n45 44\n8\n27 21\n55 14\n60 12\n18 95\n15 48\n38 10\n51 65\n15 31\n0\n",
"6\n38 10\n96 61\n76 98\n13 94\n4 0\n45 110\n8\n27 14\n55 12\n174 12\n2 95\n15 40\n38 46\n51 ... | [
"1\n0\n",
"1\n1\n",
"0\n0\n",
"0\n1\n",
"1\n0\n",
"1\n0\n",
"1\n0\n",
"1\n0\n",
"1\n0\n",
"1\n0\n"
] |
CodeContests | I have n tickets for a train with a rabbit. Each ticket is numbered from 0 to n − 1, and you can use the k ticket to go to p⋅ak + q⋅bk station.
Rabbit wants to go to the all-you-can-eat carrot shop at the station m station ahead of the current station, but wants to walk as short as possible. The stations are lined up ... | stdin | null | 33 | 1 | [
"6 1 2 3 4 5\n",
"6 200 2 3 4 5\n"
] | [
"1\n",
"1\n"
] | [
"6 1 2 3 4 7\n",
"6 106 2 3 4 5\n",
"6 2 2 3 4 7\n",
"6 159 2 3 4 5\n",
"6 200 2 3 8 8\n",
"6 159 2 3 3 5\n",
"6 3 1 3 4 8\n",
"22 144 2 3 3 5\n",
"17 144 2 3 6 5\n",
"9 5 1 3 15 9\n"
] | [
"1\n",
"13\n",
"2\n",
"8\n",
"40\n",
"0\n",
"3\n",
"15\n",
"37\n",
"5\n"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.