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 | You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}.
You will now successively do the following Q operations:
* In the i-th operation, you replace every element whose value is B_{i} with C_{i}.
For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th... | stdin | null | 251 | 1 | [
"2\n1 2\n3\n1 100\n2 100\n100 1000\n",
"4\n1 2 3 4\n3\n1 2\n3 4\n2 4\n",
"4\n1 1 1 1\n3\n1 2\n2 1\n3 5\n"
] | [
"102\n200\n2000\n",
"11\n12\n16\n",
"8\n4\n4\n"
] | [
"4\n1 2 3 3\n3\n1 2\n3 4\n2 4\n",
"4\n2 1 1 1\n3\n1 2\n2 1\n3 5\n",
"4\n1 2 3 3\n3\n1 2\n3 4\n0 4\n",
"4\n0 1 1 1\n3\n1 2\n2 1\n3 5\n",
"4\n1 3 3 3\n3\n1 2\n3 4\n0 4\n",
"4\n1 3 4 3\n3\n1 2\n3 4\n0 4\n",
"4\n0 1 1 1\n3\n1 4\n2 1\n5 10\n",
"4\n0 2 4 3\n3\n1 2\n3 4\n0 4\n",
"4\n0 1 1 1\n3\n1 0\n2 1\n5... | [
"10\n12\n16\n",
"8\n4\n4\n",
"10\n12\n12\n",
"6\n3\n3\n",
"11\n14\n14\n",
"12\n14\n14\n",
"12\n12\n12\n",
"9\n10\n14\n",
"0\n0\n0\n",
"2\n1\n1\n"
] |
CodeContests | Example
Input
4
5
8
58
85
Output
2970.000000000 | stdin | null | 3,650 | 1 | [
"4\n5\n8\n58\n85\n"
] | [
"2970.000000000\n"
] | [
"4\n5\n8\n58\n152\n",
"4\n5\n8\n55\n152\n",
"4\n5\n20\n55\n152\n",
"4\n5\n15\n58\n85\n",
"4\n5\n8\n58\n171\n",
"4\n5\n9\n55\n152\n",
"4\n2\n11\n55\n152\n",
"4\n5\n17\n55\n152\n",
"4\n5\n15\n58\n7\n",
"4\n5\n10\n58\n171\n"
] | [
"5181.000000000000000\n",
"4945.500000000000000\n",
"5887.500000000000000\n",
"3285.000000000000000\n",
"5808.000000000000000\n",
"5024.000000000000000\n",
"5082.000000000000000\n",
"5652.000000000000000\n",
"693.000000000000000\n",
"5984.000000000000000\n"
] |
CodeContests | There is a cube which consists of n × n × n small cubes. Small cubes have marks on their surfaces. An example where n = 4 is shown in the following figure.
<image>
Then, as shown in the figure above (right), make a hole that penetrates horizontally or vertically from the marked surface to the opposite surface.
You... | stdin | null | 1,021 | 1 | [
"4 3\nxy 4 4\nxz 1 2\nyz 2 3\n4 5\nxy 1 1\nxy 3 3\nxz 3 3\nyz 2 1\nyz 3 3\n0 0\n"
] | [
"52\n46\n"
] | [
"4 3\nxy 4 4\nxz 1 2\nyz 2 3\n4 5\nxy 1 1\nxy 3 3\nxz 3 2\nyz 2 1\nyz 3 3\n0 0\n",
"4 3\nxy 4 4\nxz 1 2\nyz 2 3\n4 5\nxy 1 1\nxy 3 3\nxz 3 1\nyz 2 1\nyz 3 3\n0 0\n",
"4 3\nxy 4 3\nxz 1 2\nyz 2 3\n4 5\nxy 1 1\nwy 3 3\nxz 3 2\nyz 2 1\nyz 3 3\n0 0\n",
"5 3\nxy 4 3\nxz 1 2\nyz 2 3\n4 5\nxy 1 1\nxy 3 3\nxz 3 2\nyz... | [
"52\n46\n",
"52\n47\n",
"52\n48\n",
"110\n46\n",
"52\n49\n",
"970\n46\n",
"2702\n46\n",
"2702\n47\n",
"53\n46\n",
"488\n46\n"
] |
CodeContests | Prime Caves
An international expedition discovered abandoned Buddhist cave temples in a giant cliff standing on the middle of a desert. There were many small caves dug into halfway down the vertical cliff, which were aligned on square grids. The archaeologists in the expedition were excited by Buddha's statues in thos... | stdin | null | 4,513 | 1 | [
"49 22\n46 37\n42 23\n945 561\n1081 681\n1056 452\n1042 862\n973 677\n1000000 1000000\n0 0\n"
] | [
"0 0\n6 43\n1 23\n20 829\n18 947\n10 947\n13 947\n23 947\n534 993541\n"
] | [
"49 22\n46 37\n42 23\n945 561\n1081 681\n1056 512\n1042 862\n973 677\n1000000 1000000\n0 0\n",
"49 22\n46 27\n42 23\n945 561\n1081 681\n1056 452\n1042 862\n973 677\n1000000 1000000\n0 0\n",
"49 22\n46 27\n42 23\n945 561\n1081 681\n1056 452\n1042 333\n973 677\n1000000 1000000\n0 0\n",
"49 22\n46 37\n42 12\n945... | [
"0 0\n6 43\n1 23\n20 829\n18 947\n4 941\n13 947\n23 947\n534 993541\n",
"0 0\n0 0\n1 23\n20 829\n18 947\n10 947\n13 947\n23 947\n534 993541\n",
"0 0\n0 0\n1 23\n20 829\n18 947\n10 947\n11 947\n23 947\n534 993541\n",
"0 0\n6 43\n2 23\n20 829\n18 947\n10 947\n13 947\n23 947\n534 993541\n",
"0 0\n6 43\n2 23\n2... |
CodeContests | Let f(A, B), where A and B are positive integers, be the string satisfying the following conditions:
* f(A, B) has length A + B;
* f(A, B) contains exactly A letters `A` and exactly B letters `B`;
* The length of the longest substring of f(A, B) consisting of equal letters (ex., `AAAAA` or `BBBB`) is as small as possi... | stdin | null | 4,898 | 1 | [
"5\n2 3 1 5\n6 4 1 10\n2 3 4 4\n6 4 3 7\n8 10 5 8\n"
] | [
"BABAB\nAABAABAABB\nA\nBAABA\nABAB\n"
] | [
"5\n2 3 1 5\n6 4 1 10\n2 3 4 4\n6 4 3 7\n8 10 5 14\n",
"5\n2 3 1 5\n6 4 1 10\n2 3 4 4\n6 4 3 7\n8 2 5 8\n",
"5\n2 3 1 5\n6 4 1 10\n2 3 4 4\n6 7 3 7\n8 10 5 14\n",
"5\n2 3 1 5\n6 4 1 10\n2 3 6 4\n6 4 3 7\n8 2 5 8\n",
"5\n2 3 1 5\n9 4 1 10\n2 3 6 4\n6 4 3 7\n8 2 5 8\n",
"5\n2 3 1 5\n9 4 1 10\n2 3 6 4\n6 4 3... | [
"BABAB\nAABAABAABB\nA\nBAABA\nABABBABBAB\n",
"BABAB\nAABAABAABB\nA\nBAABA\nAAAB\n",
"BABAB\nAABAABAABB\nA\nBABAB\nABABBABBAB\n",
"BABAB\nAABAABAABB\n\nBAABA\nAAAB\n",
"BABAB\nAABAABAABA\n\nBAABA\nAAAB\n",
"BABAB\nAABAABAABA\n\nBAABA\nBAAA\n",
"BBABB\nAABAABAABA\n\nBAABA\nBAAA\n",
"BBABB\nAA\n\nBAABA\n... |
CodeContests | You are given a string and a number k. You are suggested to generate new strings by swapping any adjacent pair of characters in the string up to k times. Write a program to report the lexicographically smallest string among them.
Input
The input is given in the following format.
s
k
The first line provides a st... | stdin | null | 3,125 | 1 | [
"pckoshien\n3\n",
"pckoshien\n10\n"
] | [
"ckopshien\n",
"cekophsin\n"
] | [
"kcposhien\n3\n",
"pckoshien\n9\n",
"kcooshien\n3\n",
"pckoshien\n16\n",
"kcooshien\n6\n",
"pckoshien\n30\n",
"kcooshien\n4\n",
"kdooshien\n4\n",
"kdooshien\n2\n",
"pckosiien\n26\n"
] | [
"ckophsien\n",
"cekopshin\n",
"ckohosien\n",
"cehikposn\n",
"chkooisen\n",
"cehiknops\n",
"ckhoosien\n",
"dkhoosien\n",
"dkoohsien\n",
"ceiiknops\n"
] |
CodeContests | Taro has decided to move. Taro has a lot of luggage, so I decided to ask a moving company to carry the luggage. Since there are various weights of luggage, I asked them to arrange them in order from the lightest one for easy understanding, but the mover left the luggage in a different order. So Taro tried to sort the l... | stdin | null | 1,065 | 1 | [
"8\n6 2 1 3 8 5 4 7\n",
"5\n1 5 3 2 4\n",
"7\n1 2 3 4 5 6 7\n",
"4\n1 4 2 3\n"
] | [
"19\n",
"7\n",
"0\n",
"4\n"
] | [
"7\n1 2 5 4 3 6 7\n",
"4\n2 4 2 2\n",
"4\n1 4 3 2\n",
"7\n1 3 2 4 5 6 7\n",
"4\n3 4 1 2\n",
"8\n7 2 1 3 8 5 4 6\n",
"7\n1 2 8 1 3 6 7\n",
"5\n2 5 3 1 4\n",
"8\n5 2 1 3 8 6 4 7\n",
"7\n2 1 5 4 3 6 7\n"
] | [
"7\n",
"4\n",
"5\n",
"2\n",
"3\n",
"20\n",
"9\n",
"6\n",
"18\n",
"8\n"
] |
CodeContests | Fatland is a town with N cities numbered 1, 2, ..., N, connected with 2-way roads. Vincent is a villian who wants to set the entire town ablaze. For each city, there is a certain risk factor E[i] for setting that city ablaze. But once a city c is set ablaze, all cities that can be reached from c will be set ablaze imme... | stdin | null | 4,768 | 1 | [
"4\n3 3 3 3\n2\n1 2\n4 1\n\nSAMPLE\n"
] | [
"3\n"
] | [
"523\n99 579 761 271 923 129 332 471 667 607 959 414 553 147 885 77 776 670 194 603 22 688 288 317 223 844 193 657 919 827 627 918 502 278 957 646 874 501 760 403 894 995 326 51 307 118 695 777 109 299 38 614 410 551 522 154 300 763 19 389 880 932 988 621 815 207 284 553 398 576 684 522 502 290 566 572 927 998 66 8... | [
"1\n",
"530\n",
"695241507\n",
"66\n",
"2\n",
"847620757\n",
"923810382\n",
"192857783\n",
"596428895\n",
"68\n"
] |
CodeContests | Mary Thomas has a number of sheets of squared paper. Some of squares are painted either in black or some colorful color (such as red and blue) on the front side. Cutting off the unpainted part, she will have eight opened-up unit cubes. A unit cube here refers to a cube of which each face consists of one square.
She is... | stdin | null | 5,067 | 1 | [
"3 40\n.a....a....a....a....f....f....f....f...\nbc#.#cd#.#de#.#eb#.#cb#.#dc#.#ed#.#eb#.\n.#....#....#....#....#....#....#....#...\n",
"3 40\n.a....a....a....a....f....f....f....f...\nbc#.#cd#.#de#.#eb#.#cb#.#dc#.#ed#.#be#.\n.#....#....#....#....#....#....#....#...\n",
"3 40\n.a....a....a....a....f....f....f...... | [
"No\n",
"Yes\n",
"Yes\n",
"Yes\n"
] | [
"3 64\n.a....a....a....a....f....f....f....f...\nbc#.#cd#.#de#.#eb#.#cb#.#dc#.#ed#.#eb#.\n.#....#....#....#....#....#....#....#...\n",
"3 40\n.a....a....a....a....f....f....f....f...\n.#eb#.#de#.#cd#.#bc#.#be#.#ed#.#dc#.#cb#\n.#....#....#....#....#....#....#....#...\n",
"5 40\n.a....a....a....a....f....f....f..... | [
"No\n",
"Yes\n",
"No\n",
"No\n",
"No\n",
"No\n",
"No\n",
"No\n",
"No\n",
"No\n"
] |
CodeContests | Long long ago, there was a thief. Looking for treasures, he was running about all over the world. One day, he heard a rumor that there were islands that had large amount of treasures, so he decided to head for there.
Finally he found n islands that had treasures and one island that had nothing. Most of islands had sea... | stdin | null | 148 | 1 | [
"3\n2 3\n3 6\n1 2\n3\n2 3\n3 5\n1 2\n0\n"
] | [
"Yes\nNo\n"
] | [
"3\n2 3\n3 6\n1 2\n3\n2 3\n3 5\n2 2\n0\n",
"3\n2 3\n3 6\n2 2\n3\n3 3\n3 6\n2 2\n0\n",
"3\n2 1\n3 6\n1 2\n3\n2 3\n3 5\n0 2\n0\n",
"3\n2 5\n0 9\n4 1\n0\n2 0\n3 10\n2 3\n0\n",
"3\n4 5\n3 8\n1 2\n0\n7 3\n3 5\n2 1\n0\n",
"3\n2 3\n3 6\n1 2\n3\n0 3\n3 5\n1 2\n0\n",
"3\n2 3\n3 6\n1 2\n3\n3 3\n3 5\n2 2\n0\n",
... | [
"Yes\nNo\n",
"No\nNo\n",
"No\nYes\n",
"No\n",
"Yes\n",
"Yes\nYes\n",
"Yes\nNo\n",
"Yes\nNo\n",
"No\nNo\n",
"No\nNo\n"
] |
CodeContests | A new school in Byteland is now in the process of renewing some classrooms with new, stronger and better chairs, so that the students can stay still and pay attention to class :)
However, due to budget and logistic reasons, it's only possible to carry a chair at a time to the classroom, which means that for a long time... | stdin | null | 439 | 1 | [
"2\n1\n2\n"
] | [
"1\n3\n"
] | [
"2\n1\n4\n",
"2\n1\n8\n",
"2\n1\n0\n",
"2\n0\n0\n",
"2\n1\n6\n",
"2\n1\n1\n",
"2\n2\n0\n",
"2\n1\n12\n",
"2\n2\n1\n",
"2\n2\n2\n"
] | [
"1\n15\n",
"1\n255\n",
"1\n0\n",
"0\n0\n",
"1\n63\n",
"1\n1\n",
"3\n0\n",
"1\n4095\n",
"3\n1\n",
"3\n3\n"
] |
CodeContests | You are given a string S of length N consisting of `A`, `C`, `G` and `T`. Answer the following Q queries:
* Query i (1 \leq i \leq Q): You will be given integers l_i and r_i (1 \leq l_i < r_i \leq N). Consider the substring of S starting at index l_i and ending at index r_i (both inclusive). In this string, how many t... | stdin | null | 2,842 | 1 | [
"8 3\nACACTACG\n3 7\n2 3\n1 8\n"
] | [
"2\n0\n3\n"
] | [
"8 3\nACACTACG\n3 7\n2 3\n1 6\n",
"8 3\nGCATCACA\n3 7\n2 3\n1 8\n",
"8 3\nACBCTADG\n3 7\n2 3\n1 6\n",
"8 3\nACACTACG\n3 7\n2 3\n1 2\n",
"8 3\nACACTACG\n3 7\n4 3\n1 2\n",
"8 3\nGAATCCCA\n3 7\n3 3\n2 8\n",
"8 3\nACACTADG\n3 7\n2 4\n1 6\n",
"8 2\nACBCTACG\n6 7\n3 3\n1 6\n",
"8 3\nACACTADG\n3 7\n2 4\n2 ... | [
"2\n0\n2\n",
"1\n0\n1\n",
"0\n0\n1\n",
"2\n0\n1\n",
"2\n-1\n1\n",
"0\n0\n0\n",
"1\n1\n2\n",
"1\n0\n",
"1\n1\n1\n",
"2\n0\n"
] |
CodeContests | problem
There are the following games.
N characters are lined up in a vertical row. The color of these characters is red, blue, or yellow, and in the initial state, four or more characters of the same color are not lined up in a row. The player can select a character at a certain position and change it to another col... | stdin | null | 895 | 1 | [
"12\n3\n2\n1\n1\n2\n3\n2\n2\n2\n1\n1\n3\n12\n3\n2\n1\n1\n2\n3\n2\n1\n3\n2\n1\n3\n0\n"
] | [
"3\n12\n"
] | [
"12\n3\n2\n1\n1\n2\n3\n2\n2\n2\n1\n1\n3\n12\n3\n2\n1\n1\n2\n5\n2\n1\n3\n2\n1\n3\n0\n",
"12\n3\n2\n1\n1\n2\n3\n2\n2\n2\n1\n1\n3\n12\n3\n2\n2\n1\n2\n5\n2\n1\n3\n2\n1\n3\n0\n",
"12\n3\n2\n1\n1\n2\n3\n2\n0\n2\n1\n1\n3\n12\n3\n2\n1\n2\n2\n5\n2\n1\n3\n2\n1\n3\n0\n",
"12\n3\n2\n1\n1\n2\n3\n2\n2\n2\n1\n1\n3\n12\n2\n2... | [
"3\n12\n",
"3\n8\n",
"12\n8\n",
"3\n7\n",
"7\n12\n",
"8\n8\n",
"2\n8\n",
"7\n8\n",
"7\n6\n",
"12\n12\n"
] |
CodeContests | Angry Birds is a mobile game of a big craze all over the world. You were convinced that it was a waste of time to play the game, so you decided to create an automatic solver.
<image>
You are describing a routine that optimizes the white bird's strategy to defeat a pig (enemy) by hitting an egg bomb. The white bird fo... | stdin | null | 3,171 | 1 | [
"0 7 3 1\n",
"1 7 2 2\n0 1 1 2\n",
"1 7 3 1\n1 1 2 2\n"
] | [
"Yes\n",
"No\n",
"No\n"
] | [
"1 4 2 2\n0 1 1 2\n",
"0 7 2 1\n",
"1 5 3 1\n1 1 2 2\n",
"2 4 2 2\n0 1 1 2\n",
"1 5 3 1\n1 1 2 4\n",
"2 4 2 2\n0 2 1 2\n",
"1 5 3 1\n1 1 3 4\n",
"2 4 2 2\n0 2 2 2\n",
"2 4 4 2\n0 2 1 2\n",
"2 3 4 2\n0 2 1 2\n"
] | [
"No\n",
"Yes\n",
"No\n",
"No\n",
"No\n",
"No\n",
"No\n",
"No\n",
"No\n",
"No\n"
] |
CodeContests | Takahashi decided to go sightseeing in New York with Apple. Takahashi didn't have any particular hope for sightseeing, but due to Sachika-chan's enthusiastic invitation, he decided to go sightseeing in the "hosonogai place" as shown in the map below.
<image> Google Maps-(C) 2012 Google
This "horizontal place" is very... | stdin | null | 4,009 | 1 | [
"100\n4\n3\n1\n1\n3\n2\n40\n60\n",
"100\n2\n2\n1\n0\n",
"100\n3\n2\n1\n1\n1\n50\n",
"100\n2\n1\n2\n0\n"
] | [
"421\n",
"200\n",
"200\n",
"201\n"
] | [
"100\n4\n6\n1\n1\n3\n2\n40\n60\n",
"100\n3\n2\n1\n1\n1\n59\n",
"100\n2\n0\n2\n0\n",
"100\n2\n0\n4\n0\n",
"100\n4\n6\n2\n1\n3\n2\n63\n60\n",
"100\n4\n7\n2\n1\n3\n2\n63\n60\n",
"100\n4\n7\n2\n1\n5\n2\n63\n68\n",
"100\n4\n7\n0\n1\n5\n4\n63\n93\n",
"100\n4\n6\n1\n1\n2\n2\n40\n60\n",
"100\n1\n1\n2\n0\n... | [
"601\n",
"200\n",
"201\n",
"401\n",
"801\n",
"901\n",
"1101\n",
"1059\n",
"600\n",
"100\n"
] |
CodeContests | Roy has a wooden log (tree trunk) of length L units.
Since the log is too heavy for him to lift, he wants to cut it into pieces.
He can lift pieces of length 1 or 2 units.
He wonders in how many ways can he make such pieces of the wooden log.
Now Roy is too lazy, so he would also like to finish cutting with minim... | stdin | null | 1,841 | 1 | [
"2 \n3 \n4\n\nSAMPLE\n"
] | [
"2 1\n3 1\n"
] | [
"19\n1\n10\n100\n1000\n10000\n100000\n1000000\n10000000\n100000000\n1000000000\n9\n99\n999\n9999\n99999\n999999\n9999999\n99999999\n883957737\n",
"2 \n0 \n4\n\nSAMPLE\n",
"19\n1\n10\n110\n1000\n10000\n100000\n1000000\n10000000\n100000000\n1000000000\n9\n99\n999\n9999\n99999\n999999\n9999999\n99999999\n883957737... | [
"1 0\n6 4\n51 49\n501 499\n5001 4999\n50001 49999\n500001 499999\n5000001 4999999\n50000001 49999999\n500000001 499999999\n5 4\n50 49\n500 499\n5000 4999\n50000 49999\n500000 499999\n5000000 4999999\n50000000 49999999\n441978869 441978868\n",
"1 -1\n3 1\n",
"1 0\n6 4\n56 54\n501 499\n5001 4999\n50001 49999\n500... |
CodeContests | Takahashi is locked within a building.
This building consists of H×W rooms, arranged in H rows and W columns. We will denote the room at the i-th row and j-th column as (i,j). The state of this room is represented by a character A_{i,j}. If A_{i,j}= `#`, the room is locked and cannot be entered; if A_{i,j}= `.`, the r... | stdin | null | 142 | 1 | [
"3 3 3\n#.#\n#S.\n###\n",
"3 3 3\n.#\nS.\n",
"3 3 3\n\nS#\n",
"7 7 2\n\n\n...##\nS###\n.#.##\n.###\n"
] | [
"1\n",
"1\n",
"2\n",
"2\n"
] | [
"2 3 3\n.#\nS.\n",
"7 8 2\n\n\n...##\n###S\n.#.##\n.###\n",
"7 7 2\n\n\n##...\nS###\n.#.##\n.###\n",
"2 3 3\n#.\nS.\n",
"7 7 2\n\n\n##...\nS###\n##.#.\n.###\n",
"2 3 3\n#.\n.S\n",
"7 12 2\n\n\n##...\nS###\n##.#.\n.###\n",
"7 12 2\n\n\n#$...\nS###\n##.#.\n.###\n",
"7 12 2\n\n\n#$...\nS##\"\n##.#.\n.#... | [
"1\n",
"2\n",
"1\n",
"1\n",
"1\n",
"1\n",
"1\n",
"1\n",
"1\n",
"1\n"
] |
CodeContests | Given are a permutation p_1, p_2, \dots, p_N of (1, 2, ..., N) and an integer K. Maroon performs the following operation for i = 1, 2, \dots, N - K + 1 in this order:
* Shuffle p_i, p_{i + 1}, \dots, p_{i + K - 1} uniformly randomly.
Find the expected value of the inversion number of the sequence after all the oper... | stdin | null | 489 | 1 | [
"10 3\n1 8 4 9 2 3 7 10 5 6\n",
"3 2\n1 2 3\n"
] | [
"164091855\n",
"1\n"
] | [
"3 3\n1 2 3\n",
"10 6\n1 8 4 9 2 3 7 10 5 6\n",
"3 2\n2 1 3\n",
"10 5\n1 8 4 9 2 3 7 10 5 6\n",
"10 7\n1 8 4 9 2 3 7 10 5 6\n",
"3 2\n2 3 1\n",
"10 8\n1 8 4 9 2 3 7 10 5 6\n",
"10 4\n1 8 4 9 2 3 7 10 5 6\n",
"3 3\n1 2 2\n",
"3 3\n1 2 1\n"
] | [
"499122178\n",
"3081022\n",
"1\n",
"610446407\n",
"347784862\n",
"2\n",
"561512471\n",
"907096085\n",
"499122178\n",
"499122178\n"
] |
CodeContests | Given an array A. Is there any subset of array A in which if we do AND of all elements of that subset then output should be in power of two (for example : 1,2,4,8,16 and so on ).
Input:
First line contains number of test cases T. Each test first line contains N size of array A and next line contains N space separ... | stdin | null | 3,985 | 1 | [] | [] | [
"23\n3\n7 31 127\n3\n31 127 7\n3\n7 127 31\n84\n5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125 130 135 140 145 150 155 160 165 170 175 180 185 190 195 200 205 210 215 220 225 230 235 240 245 250 255 260 265 270 275 280 285 290 295 300 305 310 315 320 325 330 335 340 345 350 355 360 ... | [
"NO\nNO\nNO\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\n",
"YES\nYES\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nN... |
CodeContests | Takahashi has A cookies, and Aoki has B cookies. Takahashi will do the following action K times:
* If Takahashi has one or more cookies, eat one of his cookies.
* Otherwise, if Aoki has one or more cookies, eat one of Aoki's cookies.
* If they both have no cookies, do nothing.
In the end, how many cookies will Taka... | stdin | null | 1,205 | 1 | [
"500000000000 500000000000 1000000000000\n",
"2 3 3\n"
] | [
"0 0\n",
"0 2\n"
] | [
"500000000000 274588616851 1000000000000\n",
"2 3 1\n",
"2 3 2\n",
"2 3 0\n",
"2 6 0\n",
"4 6 0\n",
"8 6 0\n",
"10 6 0\n",
"498881727339 49011419508 0000000100000\n",
"0 6 0\n"
] | [
"0 0\n",
"1 3\n",
"0 3\n",
"2 3\n",
"2 6\n",
"4 6\n",
"8 6\n",
"10 6\n",
"498881627339 49011419508\n",
"0 6\n"
] |
CodeContests | C: Prayer (Pray)
Some twins are famous for praying before the contest.
There are four integers $ H, W, X, Y $, and it seems unlucky if $ H \ times W $ and $ x + y $ are both odd numbers.
input
Four integers $ H, W, X, Y $ are given, separated by spaces.
output
Output "No" if you are unlucky, or "Yes" if not. But ... | stdin | null | 668 | 1 | [
"3 5 1 4\n"
] | [
"No\n"
] | [
"3 5 2 4\n",
"3 9 1 4\n",
"3 13 1 4\n",
"3 13 1 3\n",
"3 13 1 1\n",
"3 13 2 1\n",
"3 13 3 1\n",
"0 13 3 1\n",
"0 13 4 1\n",
"0 13 2 1\n"
] | [
"Yes\n",
"No\n",
"No\n",
"Yes\n",
"Yes\n",
"No\n",
"Yes\n",
"Yes\n",
"Yes\n",
"Yes\n"
] |
CodeContests | Kenkoooo found a simple connected graph. The vertices are numbered 1 through n. The i-th edge connects Vertex u_i and v_i, and has a fixed integer s_i.
Kenkoooo is trying to write a positive integer in each vertex so that the following condition is satisfied:
* For every edge i, the sum of the positive integers writt... | stdin | null | 4,897 | 1 | [
"4 3\n1 2 6\n2 3 7\n3 4 5\n",
"3 3\n1 2 3\n2 3 5\n1 3 4\n",
"8 7\n1 2 1000000000\n2 3 2\n3 4 1000000000\n4 5 2\n5 6 1000000000\n6 7 2\n7 8 1000000000\n"
] | [
"3\n",
"1\n",
"0\n"
] | [
"4 3\n1 2 6\n2 3 7\n3 4 7\n",
"3 3\n1 2 3\n2 3 0\n1 3 4\n",
"4 3\n1 2 6\n2 3 7\n3 4 3\n",
"4 3\n1 2 4\n2 3 7\n3 4 7\n",
"4 3\n1 2 6\n2 3 7\n3 4 6\n",
"4 3\n1 2 11\n2 3 7\n3 4 3\n",
"8 7\n1 2 1000000000\n2 3 2\n3 4 1000000000\n4 5 2\n5 6 1000000000\n6 7 2\n2 8 1000000000\n",
"8 7\n1 2 1000000000\n2 3 2... | [
"5\n",
"0\n",
"1\n",
"3\n",
"4\n",
"2\n",
"0\n",
"0\n",
"0\n",
"0\n"
] |
CodeContests | Consider the following game. There are k pairs of n cards with numbers from 1 to n written one by one. Shuffle these kn cards well to make piles of k cards and arrange them in a horizontal row. The i-th (k-card) pile from the left of the n piles created in this way is called "mountain i".
<image>
The game starts at ... | stdin | null | 2,019 | 1 | [
"2 1 0 5\n3 1 1 3\n2 2 1 3\n0 0 0 0\n"
] | [
"0.50000\n0.833\n1.000\n"
] | [
"2 1 0 5\n3 1 2 3\n2 2 1 3\n0 0 0 0\n",
"2 1 0 5\n3 1 2 0\n2 2 1 3\n0 0 0 0\n",
"2 1 0 5\n3 1 2 6\n2 2 1 3\n0 0 0 0\n",
"2 1 0 7\n3 1 0 0\n2 2 1 3\n0 0 0 0\n",
"2 1 0 1\n2 1 0 0\n2 2 1 3\n0 0 0 0\n",
"2 1 -1 5\n4 1 2 0\n2 2 1 3\n0 0 0 0\n",
"2 1 0 1\n2 1 0 0\n2 2 1 4\n0 0 0 0\n",
"2 1 0 5\n4 1 -1 1\n2... | [
"0.50000\n0.833\n1.000\n",
"0.50000\n0.\n1.000\n",
"0.50000\n0.833333\n1.000\n",
"0.5000000\n0.\n1.000\n",
"0.5\n0.\n1.000\n",
"1.00000\n0.\n1.000\n",
"0.5\n0.\n1.0000\n",
"0.50000\n0.7\n1.000\n",
"0.5\n1.\n1.0000\n",
"0.5\n0.7\n1.000\n"
] |
CodeContests | At one point, there was a president who traveled around Japan to do business. One day he got a mysterious ticket. If you use the ticket, the train fare will be free regardless of the distance to the destination. However, when moving from the current station to the adjacent station is counted as one step, if the number ... | stdin | null | 4,987 | 1 | [
"2 1 1\n1 2\n2 1 2\n1 2\n3 1 2\n1 2\n8 8 5778\n1 2\n2 3\n2 4\n3 5\n5 6\n6 7\n7 8\n4 8\n8 8 5777\n1 2\n2 3\n2 4\n3 5\n5 6\n6 7\n7 8\n4 8\n0 0 0\n"
] | [
"yes\nno\nno\nyes\nno\n"
] | [
"2 1 1\n1 2\n2 1 2\n1 4\n3 1 2\n1 2\n8 8 5778\n1 2\n2 3\n2 4\n3 5\n5 6\n6 7\n7 8\n4 8\n8 8 5777\n1 2\n2 3\n2 4\n3 5\n5 6\n6 7\n7 8\n4 8\n0 0 0\n",
"2 1 1\n1 2\n2 1 2\n1 4\n3 1 2\n1 2\n11 8 5778\n1 2\n2 3\n2 4\n3 5\n5 6\n6 7\n7 8\n4 8\n8 8 5777\n1 2\n2 3\n2 4\n3 5\n5 6\n6 7\n7 8\n4 8\n0 0 0\n",
"4 1 1\n1 2\n2 1 ... | [
"yes\nno\nno\nyes\nno\n",
"yes\nno\nno\nno\nno\n",
"no\nno\nno\nno\nno\n",
"no\nno\nno\nyes\nno\n",
"no\nno\nno\nno\nyes\n",
"yes\nno\nno\nyes\nno\n",
"yes\nno\nno\nyes\nno\n",
"yes\nno\nno\nno\nno\n",
"yes\nno\nno\nyes\nno\n",
"yes\nno\nno\nno\nno\n"
] |
CodeContests | Statement: Write a code to display all the non-prime numbers upto N.
Input: Only the value of N.
Output: The numbers which are not prime upto N (including N), each in a new line.
Constraints: 1 ≤ N ≤ 10^4
SAMPLE INPUT
25
SAMPLE OUTPUT
4
6
8
9
10
12
14
15
16
18
20
21
22
24
25
Explanation
In the above case, input ... | stdin | null | 1,000 | 1 | [] | [] | [
"1660\n",
"2898\n",
"3167\n",
"4395\n",
"5575\n",
"3957\n",
"4220\n",
"6575\n",
"4206\n",
"4936\n"
] | [
"4\n6\n8\n9\n10\n12\n14\n15\n16\n18\n20\n21\n22\n24\n25\n26\n27\n28\n30\n32\n33\n34\n35\n36\n38\n39\n40\n42\n44\n45\n46\n48\n49\n50\n51\n52\n54\n55\n56\n57\n58\n60\n62\n63\n64\n65\n66\n68\n69\n70\n72\n74\n75\n76\n77\n78\n80\n81\n82\n84\n85\n86\n87\n88\n90\n91\n92\n93\n94\n95\n96\n98\n99\n100\n102\n104\n105\n106\n10... |
CodeContests | Problem statement
There are rectangles with vertical and horizontal lengths of h and w, and square squares with a side length of 1 are spread inside. If the upper left cell is (0,0) and the cell to the right of j below (0,0) is represented as (i, j), (i, j) is i + j. If is even, it is painted red, and if it is odd, it... | stdin | null | 1,662 | 1 | [
"3\n2 3\n3 3\n4 3\n"
] | [
"1 1\n1 0\n1 1\n"
] | [
"3\n1 3\n3 3\n4 3\n",
"3\n2 4\n3 3\n4 3\n",
"3\n2 4\n3 3\n3 3\n",
"3\n1 4\n3 2\n4 3\n",
"3\n2 4\n3 6\n3 3\n",
"3\n2 2\n3 2\n2 3\n",
"3\n4 4\n3 6\n3 3\n",
"3\n2 2\n4 2\n1 3\n",
"3\n1 3\n3 3\n4 4\n",
"3\n1 4\n3 7\n4 3\n"
] | [
"2 1\n1 0\n1 1\n",
"1 1\n1 0\n1 1\n",
"1 1\n1 0\n1 0\n",
"1 1\n1 1\n1 1\n",
"1 1\n1 1\n1 0\n",
"1 0\n1 1\n1 1\n",
"1 0\n1 1\n1 0\n",
"1 0\n1 1\n2 1\n",
"2 1\n1 0\n1 0\n",
"1 1\n11 10\n1 1\n"
] |
CodeContests | You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b.
The i-th operation is as follows:
1. Append a_i to the end of b.
2. Reverse the order of the elements in b.
Find the sequence b obtained after these n operations.
Constraints... | stdin | null | 3,838 | 1 | [
"6\n0 6 7 6 7 0\n",
"4\n1 2 3 4\n",
"1\n1000000000\n",
"3\n1 2 3\n"
] | [
"0 6 6 0 7 7\n",
"4 2 1 3\n",
"1000000000\n",
"3 1 2\n"
] | [
"6\n1 6 7 6 7 0\n",
"4\n1 4 3 4\n",
"1\n1000010000\n",
"3\n2 2 3\n",
"6\n1 10 7 6 7 0\n",
"4\n1 4 0 4\n",
"1\n1100010000\n",
"3\n4 2 3\n",
"6\n1 10 7 6 4 0\n",
"4\n0 4 0 4\n"
] | [
"0 6 6 1 7 7\n",
"4 4 1 3\n",
"1000010000\n",
"3 2 2\n",
"0 6 10 1 7 7\n",
"4 4 1 0\n",
"1100010000\n",
"3 4 2\n",
"0 6 10 1 7 4\n",
"4 4 0 0\n"
] |
CodeContests | B: Dansunau www --Dance Now!-
story
Last lab life! Daigakuin! !! Dosanko Snow has won 9th place in the event "Master Idol World", which can be said to be the outpost of the biggest competition "Lab Life" where master idols compete. The sharp dance is ridiculed as "9th place dance", and the whole body's deciding pose ... | stdin | null | 2,029 | 1 | [
"9\n9 8 7 6 5 4 3 2 1\n1 1 1\n2 2 2\n3 3 3\n4 4 4\n5 5 5\n6 6 6\n7 7 7\n8 8 8\n9 9 9\n"
] | [
"2\n"
] | [
"9\n9 8 7 6 5 4 3 2 1\n1 1 1\n3 2 2\n3 3 3\n4 4 4\n5 5 5\n6 6 6\n7 7 7\n8 8 8\n9 9 9\n",
"9\n9 8 7 6 5 4 3 2 1\n1 1 1\n3 4 2\n3 3 3\n4 4 4\n5 5 5\n6 6 6\n7 7 7\n8 8 8\n9 9 9\n",
"9\n9 8 7 6 5 4 3 2 1\n1 1 1\n2 2 2\n3 3 3\n4 4 4\n5 5 5\n5 6 6\n7 7 7\n8 8 8\n9 9 9\n",
"9\n7 8 7 6 5 4 3 1 1\n1 1 1\n2 1 2\n3 3 2\... | [
"3\n",
"4\n",
"2\n",
"1\n",
"6\n",
"5\n",
"4\n",
"4\n",
"3\n",
"4\n"
] |
CodeContests | Given a tree T with non-negative weight, find the height of each node of the tree. For each node, the height is the distance to the most distant leaf from the node.
Constraints
* 1 ≤ n ≤ 10,000
* 0 ≤ wi ≤ 1,000
Input
n
s1 t1 w1
s2 t2 w2
:
sn-1 tn-1 wn-1
The first line consists of an integer n which represents th... | stdin | null | 4,604 | 1 | [
"4\n0 1 2\n1 2 1\n1 3 3\n"
] | [
"5\n3\n4\n5\n"
] | [
"4\n0 2 2\n1 2 1\n1 3 3\n",
"4\n0 1 2\n1 2 2\n1 3 3\n",
"4\n0 1 2\n1 2 1\n2 3 3\n",
"4\n0 1 2\n1 2 0\n1 3 3\n",
"4\n0 2 2\n1 2 1\n2 3 3\n",
"4\n0 1 2\n1 2 0\n0 3 3\n",
"4\n0 1 0\n1 2 0\n1 3 3\n",
"4\n0 1 2\n0 2 0\n0 3 3\n",
"4\n0 1 2\n1 2 1\n1 3 0\n",
"4\n0 2 2\n1 2 2\n1 3 3\n"
] | [
"6\n3\n4\n6\n",
"5\n3\n5\n5\n",
"6\n4\n3\n6\n",
"5\n3\n3\n5\n",
"5\n4\n3\n5\n",
"3\n5\n5\n5\n",
"3\n3\n3\n3\n",
"3\n5\n3\n5\n",
"3\n2\n3\n2\n",
"7\n4\n5\n7\n"
] |
CodeContests | You are given a permutation p_1,p_2,...,p_N consisting of 1,2,..,N. You can perform the following operation any number of times (possibly zero):
Operation: Swap two adjacent elements in the permutation.
You want to have p_i ≠ i for all 1≤i≤N. Find the minimum required number of operations to achieve this.
Constraint... | stdin | null | 102 | 1 | [
"5\n1 4 3 5 2\n",
"9\n1 2 4 9 5 8 7 3 6\n",
"2\n1 2\n",
"2\n2 1\n"
] | [
"2\n",
"3\n",
"1\n",
"0\n"
] | [
"5\n1 4 4 5 2\n",
"9\n1 2 4 9 5 8 7 6 6\n",
"9\n1 2 4 9 5 8 4 6 6\n",
"5\n0 4 4 5 1\n",
"2\n1 0\n",
"2\n1 1\n",
"5\n1 4 4 5 1\n",
"2\n1 -1\n",
"2\n0 2\n",
"9\n2 2 4 9 5 8 4 6 6\n"
] | [
"1\n",
"3\n",
"2\n",
"0\n",
"1\n",
"1\n",
"1\n",
"1\n",
"1\n",
"2\n"
] |
CodeContests | In this problem, we only consider strings consisting of lowercase English letters.
Strings s and t are said to be isomorphic when the following conditions are satisfied:
* |s| = |t| holds.
* For every pair i, j, one of the following holds:
* s_i = s_j and t_i = t_j.
* s_i \neq s_j and t_i \neq t_j.
For example, `a... | stdin | null | 15 | 1 | [
"1\n",
"2\n"
] | [
"a\n",
"aa\nab\n"
] | [
"4\n",
"6\n",
"3\n",
"7\n",
"5\n",
"8\n",
"4\n",
"3\n",
"5\n",
"6\n"
] | [
"aaaa\naaab\naaba\naabb\naabc\nabaa\nabab\nabac\nabba\nabbb\nabbc\nabca\nabcb\nabcc\nabcd\n",
"aaaaaa\naaaaab\naaaaba\naaaabb\naaaabc\naaabaa\naaabab\naaabac\naaabba\naaabbb\naaabbc\naaabca\naaabcb\naaabcc\naaabcd\naabaaa\naabaab\naabaac\naababa\naababb\naababc\naabaca\naabacb\naabacc\naabacd\naabbaa\naabbab\naab... |
CodeContests | Examples
Input
4 5 2
0 1 2 1
0 2 1 2
1 2 1 1
1 3 1 3
2 3 2 1
Output
6
Input
Output | stdin | null | 5,073 | 1 | [
"4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1\n",
"\n"
] | [
"6\n",
"\n"
] | [
"4 5 2\n0 0 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1\n",
"4 5 2\n0 1 2 0\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1\n",
"4 5 2\n0 1 2 0\n0 2 1 2\n1 2 2 1\n0 3 1 3\n2 3 2 1\n",
"4 5 3\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1\n",
"4 5 2\n0 1 2 0\n0 2 1 4\n1 1 1 1\n1 3 1 3\n2 3 2 1\n",
"10 5 0\n0 1 2 0\n0 1 0 2\... | [
"-1\n",
"5\n",
"4\n",
"10\n",
"8\n",
"0\n",
"6\n",
"2\n",
"-1\n",
"5\n"
] |
CodeContests | International Carpenters Professionals Company (ICPC) is a top construction company with a lot of expert carpenters. What makes ICPC a top company is their original language.
The syntax of the language is simply given in CFG as follows:
S -> SS | (S) | )S( | ε
In other words, a right parenthesis can be closed by a... | stdin | null | 548 | 1 | [
"3\n0 ( 10\n10 ) 20\n0 ( 10\n",
"3\n0 ( 10\n10 ) 5\n10 ) 5\n",
"3\n0 ) 10\n10 ( 5\n10 ( 5\n"
] | [
"No\nNo\nYes\n",
"No\nNo\nYes\n",
"No\nNo\nYes\n"
] | [
"3\n0 ( 10\n10 ) 5\n10 ( 5\n",
"3\n-1 ( 10\n10 ) 5\n10 ) 5\n",
"3\n-1 ( 9\n10 ) 9\n20 ( 4\n",
"3\n-1 ) 0\n8 ( 19\n4 ' 2\n",
"3\n-2 ) 0\n7 ) 0\n4 ( 11\n",
"3\n-1 ( 0\n10 ) 4\n20 ( 4\n",
"3\n0 ) 0\n7 * 0\n1 ( 0\n",
"3\n0 ) 10\n10 ( 5\n10 ( 7\n",
"3\n-1 ( 10\n10 ) 5\n10 ( 5\n",
"3\n0 ) 10\n10 ( 9\n10... | [
"No\nNo\nNo\n",
"No\nNo\nYes\n",
"No\nYes\nNo\n",
"Yes\nNo\nNo\n",
"Yes\nYes\nNo\n",
"Yes\nNo\nYes\n",
"Yes\nYes\nYes\n",
"No\nNo\nNo\n",
"No\nNo\nNo\n",
"No\nNo\nNo\n"
] |
CodeContests | A 3×3 grid with a integer written in each square, is called a magic square if and only if the integers in each row, the integers in each column, and the integers in each diagonal (from the top left corner to the bottom right corner, and from the top right corner to the bottom left corner), all add up to the same sum.
... | stdin | null | 2,566 | 1 | [
"8\n3\n5\n",
"1\n1\n1\n"
] | [
"8 3 4\n1 5 9\n6 7 2\n",
"1 1 1\n1 1 1\n1 1 1\n"
] | [
"8\n0\n5\n",
"1\n0\n1\n",
"8\n-1\n5\n",
"1\n0\n2\n",
"1\n-1\n1\n",
"1\n-1\n2\n",
"1\n-1\n4\n",
"1\n0\n4\n",
"1\n1\n2\n",
"1\n-2\n2\n"
] | [
"8 0 7\n4 5 6\n3 10 2\n",
"1 0 2\n2 1 0\n0 2 1\n",
"8 -1 8\n5 5 5\n2 11 2\n",
"1 0 5\n6 2 -2\n-1 4 3\n",
"1 -1 3\n3 1 -1\n-1 3 1\n",
"1 -1 6\n7 2 -3\n-2 5 3\n",
"1 -1 12\n15 4 -7\n-4 9 7\n",
"1 0 11\n14 4 -6\n-3 8 7\n",
"1 1 4\n5 2 -1\n0 3 3\n",
"1 -2 7\n8 2 -4\n-3 6 3\n"
] |
CodeContests | Gorillas in Kyoto University are good at math. They are currently trying to solve problems to find the value of an expression that contains two functions, `_` , `^`. Each of these functions takes two input values. `_` function returns the smaller of the two input values and `^` function returns the larger. Gorillas kno... | stdin | null | 773 | 1 | [
"4\n_(4,51)?\n^(99,_(3,67))?\n_(0,87)?\n3?\n",
"7\n_(23,^(_(22,40),4))?\n_(0,99)?\n^(99,_(^(19,2),5))?\n_(^(43,20),^(30,29))?\n^(_(20,3),_(50,41))?\n^(_(20,3),_(3,41))?\n^(_(20,3),_(4,41))?\n"
] | [
"4 5\n99 4\n0 3\n3 2\n",
"22 18\n0 3\n99 4\n30 17\n41 17\n3 14\n4 15\n"
] | [
"7\n_(23,^(_(22,40),4))?\n_(0)99,?\n^(99,_(^(19,2),5))?\n_(^(43,20),^(30,29))?\n^(_(20,3),_(50,41))?\n^(_(20,3),_(3,41))?\n^(_(20,3),_(4,41))?\n",
"7\n_(23,^(_(22,40),4))?\n_(0,99)?\n^(99,_(^(19,2),5))?\n_(^(43,20),^(30,29))?\n^(_(20,3),_(50,41))?\n^(_(20,3),_(3,41))?\n^(^(20,3),_(4,41))?\n",
"7\n_(23,^(_(22,40... | [
"22 18\n0 3\n99 4\n30 17\n41 17\n3 14\n4 15\n",
"22 18\n0 3\n99 4\n30 17\n41 17\n3 14\n20 14\n",
"22 18\n0 3\n99 4\n30 17\n40 17\n3 14\n20 14\n",
"23 14\n0 3\n99 4\n30 17\n41 17\n3 14\n4 15\n",
"4 5\n99 4\n0 3\n3 2\n",
"22 18\n0 3\n99 4\n31 17\n41 17\n3 14\n4 15\n",
"22 18\n0 3\n98 13\n30 17\n41 17\n3 1... |
CodeContests | Claire is a man-eater. She's a real man-eater. She's going around with dozens of guys. She's dating all the time. And one day she found some conflicts in her date schedule. D'oh!
So she needs to pick some dates and give the others up. The dates are set by hours like 13:00 to 15:00. She may have more than one date with... | stdin | null | 4,283 | 1 | [
"2\n2 100\n10 12\n14 16\n2 200\n12 13\n18 20\n4\n1 100\n6 22\n1 1000\n6 22\n1 10000\n6 22\n1 100000\n6 22\n16\n1 100000000\n6 7\n1 100000000\n7 8\n1 100000000\n8 9\n1 100000000\n9 10\n1 100000000\n10 11\n1 100000000\n11 12\n1 100000000\n12 13\n1 100000000\n13 14\n1 100000000\n14 15\n1 100000000\n15 16\n1 100000000\... | [
"300\n100000\n1600000000\n"
] | [
"2\n2 100\n10 12\n14 16\n2 200\n12 13\n18 20\n4\n1 100\n6 22\n1 1000\n6 22\n1 10000\n6 22\n1 100000\n6 22\n16\n1 100000000\n6 7\n1 100000000\n7 8\n1 100000000\n8 9\n1 110000000\n9 10\n1 100000000\n10 11\n1 100000000\n11 12\n1 100000000\n12 13\n1 100000000\n13 14\n1 100000000\n14 15\n1 100000000\n15 16\n1 100000000\... | [
"300\n100000\n1610000000\n",
"300\n100000\n1610001000\n",
"300\n100000\n1610001010\n",
"200\n100000\n1610001000\n",
"300\n100000\n1510001010\n",
"300\n100000\n1610001020\n",
"300\n100000\n1511001010\n",
"300\n100000\n1511101010\n",
"300\n100000\n1610101020\n",
"200\n100000\n1611001000\n"
] |
CodeContests | Constraints
* All values in input are integers.
* 1\leq N, M\leq 12
* 1\leq X\leq 10^5
* 1\leq C_i \leq 10^5
* 0\leq A_{i, j} \leq 10^5
Input
Input is given from Standard Input in the following format:
N M X
C_1 A_{1,1} A_{1,2} \cdots A_{1,M}
C_2 A_{2,1} A_{2,2} \cdots A_{2,M}
\vdots
C_N A_{N,1} A_{N,2} \cdots A_{... | stdin | null | 1,524 | 1 | [
"3 3 10\n100 3 1 4\n100 1 5 9\n100 2 6 5\n",
"3 3 10\n60 2 2 4\n70 8 7 9\n50 2 3 9\n",
"8 5 22\n100 3 7 5 3 1\n164 4 5 2 7 8\n334 7 2 7 2 9\n234 4 7 2 8 2\n541 5 4 3 3 6\n235 4 8 6 9 7\n394 3 6 1 6 2\n872 8 4 3 7 2\n"
] | [
"-1\n",
"120\n",
"1067\n"
] | [
"2 3 10\n100 3 1 4\n100 1 5 9\n100 2 6 5\n",
"3 3 10\n60 2 2 4\n70 8 7 2\n50 2 3 9\n",
"8 5 22\n100 3 7 5 3 1\n164 4 5 2 7 8\n334 7 2 7 2 9\n234 4 7 2 8 2\n541 5 4 3 3 6\n235 4 6 6 9 7\n394 3 6 1 6 2\n872 8 4 3 7 2\n",
"8 5 22\n100 3 7 5 3 1\n164 4 5 1 7 8\n334 7 2 7 2 9\n234 4 7 2 8 2\n541 5 4 3 3 6\n235 4 6... | [
"-1\n",
"120\n",
"1067\n",
"1374\n",
"1242\n",
"1740\n",
"1764\n",
"1293\n",
"1297\n",
"1531\n"
] |
CodeContests | There are N empty boxes arranged in a row from left to right. The integer i is written on the i-th box from the left (1 \leq i \leq N).
For each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it.
We say a set of choices to put a ball or not in the boxes is good when the following con... | stdin | null | 571 | 1 | [
"5\n0 0 0 0 0\n",
"3\n1 0 0\n"
] | [
"0\n",
"1\n1\n"
] | [
"3\n1 0 1\n",
"3\n1 1 0\n",
"3\n0 0 0\n",
"5\n1 0 0 0 0\n",
"5\n1 0 0 0 1\n",
"5\n1 1 0 1 0\n",
"5\n1 0 1 0 0\n",
"5\n1 1 0 0 0\n",
"5\n1 0 0 0 0\n",
"3\n0 0 0\n"
] | [
"1\n3\n",
"1\n2\n",
"0\n",
"1\n1\n",
"1\n5\n",
"1\n4\n",
"1\n3\n",
"1\n2\n",
"1\n1\n",
"0\n"
] |
CodeContests | You have an appointment to meet a friend of yours today, but you are so sleepy because you didn’t sleep well last night.
As you will go by trains to the station for the rendezvous, you can have a sleep on a train. You can start to sleep as soon as you get on a train and keep asleep just until you get off. However, bec... | stdin | null | 3,929 | 1 | [
"3 1\n1 09:00 3 10:00\n3\n1 09:10\n2 09:30\n3 09:40\n3 2\n1 09:00 1 10:00\n3\n1 09:10\n2 09:30\n3 09:40\n3\n3 09:20\n2 09:30\n1 10:00\n1 0\n1 09:00 1 10:00\n1 0\n1 10:00 1 09:00\n3 1\n1 09:00 3 09:35\n3\n1 09:10\n2 09:30\n3 09:40\n4 3\n1 09:00 4 11:00\n3\n1 09:10\n2 09:20\n4 09:40\n3\n1 10:30\n3 10:40\n4 10:50\n4\n... | [
"30\n30\n0\nimpossible\nimpossible\n60\n"
] | [
"3 1\n1 09:00 3 10:00\n3\n1 09:10\n2 09:30\n3 09:40\n3 2\n1 09:00 1 10:00\n3\n1 09:10\n2 09:30\n3 09:40\n3\n3 09:20\n2 09:30\n1 10:00\n1 0\n1 09:00 1 10:00\n1 0\n1 10:00 1 09:00\n3 1\n1 09:00 3 09:35\n3\n1 09:10\n2 09:30\n3 09:40\n4 3\n1 09:00 4 11:00\n3\n2 09:10\n2 09:20\n4 09:40\n3\n1 10:30\n3 10:40\n4 10:50\n4\n... | [
"30\n30\n0\nimpossible\nimpossible\n20\n",
"30\n0\n0\nimpossible\nimpossible\n20\n",
"30\n0\n0\nimpossible\nimpossible\n60\n",
"30\n0\n",
"30\n0\n0\n0\nimpossible\n60\n",
"30\n0\n0\nimpossible\nimpossible\n100\n",
"30\n30\n0\nimpossible\nimpossible\n100\n",
"30\n0\nimpossible\nimpossible\nimpossible\n... |
CodeContests | The word `internationalization` is sometimes abbreviated to `i18n`. This comes from the fact that there are 18 letters between the first `i` and the last `n`.
You are given a string s of length at least 3 consisting of lowercase English letters. Abbreviate s in the same way.
Constraints
* 3 ≤ |s| ≤ 100 (|s| denotes ... | stdin | null | 1,647 | 1 | [
"smiles\n",
"internationalization\n",
"xyz\n"
] | [
"s4s\n",
"i18n\n",
"x1z\n"
] | [
"selims\n",
"intfrnationalization\n",
"xxz\n",
"smilet\n",
"noitazilanoitanrftni\n",
"xx{\n",
"stilem\n",
"ooitazilanoitanrftni\n",
"x{x\n",
"melits\n"
] | [
"s4s\n",
"i18n\n",
"x1z\n",
"s4t\n",
"n18i\n",
"x1{\n",
"s4m\n",
"o18i\n",
"x1x\n",
"m4s\n"
] |
CodeContests | There are several colored cubes. All of them are of the same size but they may be colored differently. Each face of these cubes has a single color. Colors of distinct faces of a cube may or may not be the same.
Two cubes are said to be identically colored if some suitable rotations of one of the cubes give identical l... | stdin | null | 1,655 | 1 | [
"3\nscarlet green blue yellow magenta cyan\nblue pink green magenta cyan lemon\npurple red blue yellow cyan green\n2\nred green blue yellow magenta cyan\ncyan green blue yellow magenta red\n2\nred green gray gray magenta cyan\ncyan green gray gray magenta red\n2\nred green blue yellow magenta cyan\nmagenta red blue... | [
"4\n2\n0\n0\n2\n3\n4\n4\n0\n16\n"
] | [
"3\nscarlet green blue yellow magenta cyan\nblue pink green magenta cyan lemon\npurple red blue yellow cyan green\n2\nred green blue yellow magenta cyan\ncyan green blue yellow magenta red\n2\nred green gray gray magenta cyan\ncyan green gray fray magenta red\n2\nred green blue yellow magenta cyan\nmagenta red blue... | [
"4\n2\n1\n0\n2\n3\n4\n4\n0\n16\n",
"4\n2\n1\n0\n2\n4\n4\n4\n0\n16\n",
"4\n2\n1\n0\n2\n5\n4\n4\n0\n16\n",
"5\n2\n1\n0\n2\n5\n4\n4\n0\n16\n",
"5\n2\n1\n1\n2\n5\n4\n4\n0\n16\n",
"5\n2\n1\n1\n3\n5\n4\n4\n0\n16\n",
"5\n2\n1\n1\n3\n6\n4\n4\n0\n16\n",
"6\n2\n1\n1\n3\n6\n4\n4\n0\n16\n",
"7\n2\n1\n1\n3\n6\n4... |
CodeContests | Do you know "sed," a tool provided with Unix? Its most popular use is to substitute every occurrence of a string contained in the input string (actually each input line) with another string β. More precisely, it proceeds as follows.
1. Within the input string, every non-overlapping (but possibly adjacent) occurrences... | stdin | null | 3,010 | 1 | [
"2\na bb\nb aa\na\nbbbbbbbb\n1\na aa\na\naaaaa\n3\nab aab\nabc aadc\nad dee\nabc\ndeeeeeeeec\n10\na abc\nb bai\nc acf\nd bed\ne abh\nf fag\ng abe\nh bag\ni aaj\nj bbb\na\nabacfaabe\n0\n"
] | [
"3\n-1\n7\n4\n"
] | [
"2\na bb\nb aa\na\nbbbbbbbb\n1\na aa\na\naaaaa\n3\nab aab\nabc aadc\nad dee\nabc\ndeeeeeeeec\n10\na abc\nb bai\nc acf\nd bed\ne abh\nf fag\ng abe\nh bag\ni aaj\nj bbb\na\nabaceaabe\n0\n",
"2\na bb\nb aa\nb\nbbbbbbbb\n1\nb aa\na\naaaaa\n3\nab aab\nabc aadc\nad dee\nabc\ndeeeeeeeec\n10\na abc\nb bai\nc acf\nd bed\n... | [
"3\n-1\n7\n-1\n",
"-1\n-1\n7\n-1\n",
"-1\n-1\n-1\n-1\n",
"3\n-1\n-1\n-1\n",
"3\n-1\n",
"-1\n-1\n",
"3\n-1\n-1\n4\n",
"3\n",
"-1\n",
"3\n-1\n7\n-1\n"
] |
CodeContests | Roy frequently needs to use his old Nokia cell phone for texting whose keypad looks exactly as shown below.
You may be already familiar with the working of the keypad, however if you're not we shall see a few examples.
To type "b", we need to press "2" twice. To type "?" we need to press "1" thrice. To type "5" w... | stdin | null | 3,868 | 1 | [
"3\nhack\n5!\ni_?_uSAMPLE\n"
] | [
"11\n10\n15\n"
] | [
"10\no3fmci,o2p\nc8tllmhzg7\n747kdw9lo3\nsj8cz3cvmo\ns3szaonxca\npir_be2g1p\n23?behplex\nd4hiyu65r6\n6rtnnrjj0!\n7u7mlvsf0d\n",
"3\nhabk\n5!\ni_?_uSAMPLE\n",
"10\no3fmci,o2p\nc8tllmhzg7\n747kdw9lo3\nsj8cz3cvmo\ns3szaonxca\npir_be2g1p\n23?behplex\nd4hiyu65r6\n6rtnnrjj0!\n7u7nlvsf0d\n",
"3\nhabk\n5!\nh_?_uSAMPL... | [
"36\n35\n42\n39\n36\n33\n35\n38\n31\n39\n",
"10\n10\n15\n",
"36\n35\n42\n39\n36\n33\n35\n38\n31\n40\n",
"10\n10\n14\n",
"36\n35\n42\n39\n36\n33\n34\n38\n31\n40\n",
"36\n35\n42\n39\n36\n33\n34\n38\n31\n36\n",
"36\n35\n42\n39\n36\n33\n33\n38\n31\n36\n",
"11\n10\n14\n",
"36\n35\n42\n39\n36\n33\n33\n38\... |
CodeContests | Brian built his own car and was confused about what name he should keep for it. He asked Roman for help. Roman being his good friend, suggested a lot of names.
Brian only liked names that:
- Consisted of exactly three distinct characters, say C1, C2 and C3
- Satisfied the criteria that the string was of the form - ... | stdin | null | 4,529 | 1 | [
"2\nbbbrrriii\nbrian\n\nSAMPLE\n"
] | [
"OK\nNot OK\n"
] | [
"2\nbbbrrriii\nbrian\n\nELPMAS\n",
"2\nbbarrriii\nbrian\n\nELPMAS\n",
"2\nbbarrriii\nbrian\n\nSAMPLE\n",
"2\nbbarrriii\nbiran\n\nSAMPLE\n",
"2\nbbarrriji\nbiran\n\nSAMPLE\n",
"2\nbbarrrijj\nbiran\n\nSAMPLE\n",
"2\nbbarrjijr\nbiran\n\nSAMPLE\n",
"2\nbb`rrjijr\nbiran\n\nSAMPLE\n",
"2\nbb`rrjijr\nbiram... | [
"OK\nNot OK\n",
"Not OK\nNot OK\n",
"Not OK\nNot OK\n",
"Not OK\nNot OK\n",
"Not OK\nNot OK\n",
"Not OK\nNot OK\n",
"Not OK\nNot OK\n",
"Not OK\nNot OK\n",
"Not OK\nNot OK\n",
"Not OK\nNot OK\n"
] |
CodeContests | Agent OO7 is engaged in a mission to stop the nuclear missile launch. He needs a surveillance team to monitor the progress of the mission. Several men with different type of capabilities assemble in a hall, help OO7 to find out total men with different capabilities. Capability is represented in form of numbers.
Input -... | stdin | null | 4,611 | 1 | [
"3\n6\n48 11 11 48 36 10\n4\n25 25 25 25\n9\n6 98 12 256 23 245 10 19 3\n\nSAMPLE\n"
] | [
"4\n1\n9\n"
] | [
"3\n6\n48 11 11 48 19 10\n4\n25 25 25 25\n9\n6 98 12 256 23 245 10 19 3\n",
"3\n6\n48 18 11 48 36 10\n4\n25 25 25 25\n9\n6 98 12 256 23 245 10 19 3\n\nSAMPLE\n",
"3\n6\n48 11 11 48 19 10\n4\n25 25 25 25\n9\n3 98 12 256 23 245 10 19 3\n",
"3\n6\n48 11 9 48 19 10\n4\n25 25 25 25\n9\n3 98 12 256 23 245 10 19 3\n... | [
"4\n1\n9\n",
"5\n1\n9\n",
"4\n1\n8\n",
"5\n1\n8\n",
"5\n2\n9\n",
"6\n1\n9\n",
"5\n3\n9\n",
"6\n1\n8\n",
"6\n2\n8\n",
"6\n2\n7\n"
] |
CodeContests | problem
At IOI Confectionery, rice crackers are baked using the traditional method since the company was founded. This traditional method is to bake the front side for a certain period of time with charcoal, turn it over when the front side is baked, and bake the back side for a certain period of time with charcoal. W... | stdin | null | 581 | 1 | [
"2 5\n0 1 0 1 0\n1 0 0 0 1\n3 6\n1 0 0 0 1 0\n1 1 1 0 1 0\n1 0 1 1 0 1\n0 0\n"
] | [
"9\n15\n"
] | [
"2 5\n0 1 0 1 0\n1 0 0 0 1\n3 6\n1 0 1 0 1 0\n1 1 1 0 1 0\n1 0 1 1 0 1\n0 0\n",
"2 5\n0 1 1 1 0\n1 0 0 0 1\n3 6\n1 0 0 0 1 0\n1 1 1 0 1 0\n1 0 1 1 0 1\n0 0\n",
"2 5\n0 1 0 1 0\n1 0 0 0 1\n3 6\n1 0 0 0 1 1\n1 1 1 0 1 0\n1 0 1 1 0 1\n0 0\n",
"2 5\n1 1 1 1 0\n1 0 0 1 1\n3 6\n1 0 0 0 1 0\n0 1 1 0 1 0\n1 0 1 1 0 1... | [
"9\n15\n",
"10\n15\n",
"9\n14\n",
"8\n15\n",
"9\n16\n",
"9\n17\n",
"8\n14\n",
"10\n16\n",
"8\n16\n",
"10\n14\n"
] |
CodeContests | The squirrel Chokudai has N acorns. One day, he decides to do some trades in multiple precious metal exchanges to make more acorns.
His plan is as follows:
1. Get out of the nest with N acorns in his hands.
2. Go to Exchange A and do some trades.
3. Go to Exchange B and do some trades.
4. Go to Exchange A and do some... | stdin | null | 3,874 | 1 | [
"23\n1 1 1\n2 1 1\n"
] | [
"46\n"
] | [
"23\n1 1 1\n2 2 1\n",
"23\n1 2 1\n2 1 1\n",
"23\n1 2 1\n2 0 1\n",
"23\n0 2 1\n2 0 1\n",
"23\n1 1 2\n1 1 0\n",
"23\n1 1 1\n2 0 1\n",
"23\n1 4 1\n2 1 1\n",
"23\n1 1 2\n2 3 0\n",
"23\n0 2 1\n4 0 1\n",
"23\n1 8 1\n2 1 1\n"
] | [
"46\n",
"92\n",
"48\n",
"27\n",
"25\n",
"47\n",
"184\n",
"71\n",
"29\n",
"368\n"
] |
CodeContests | Deadlock Detection
In concurrent processing environments, a deadlock is an undesirable situation where two or more threads are mutually waiting for others to finish using some resources and cannot proceed further. Your task is to detect whether there is any possibility of deadlocks when multiple threads try to execute... | stdin | null | 4,006 | 1 | [
"11\n01u12u0123u\n6\n01u10u\n8\n201u210u\n9\n01u12u20u\n3\n77u\n12\n9u8u845u954u\n0\n"
] | [
"SAFE\nUNSAFE\nSAFE\nUNSAFE\nUNSAFE\nUNSAFE\n"
] | [
"11\n01u12u0123u\n6\n01u10u\n8\n201u210u\n9\n01u12u20u\n3\nu77\n12\n9u8u845u954u\n0\n",
"11\n01u12u0123u\n6\n01u10u\n0\n201u210u\n9\n01u12u20u\n3\n77u\n12\n9u8u845u954u\n0\n",
"11\n01u12u3120u\n6\n01u10u\n0\n20u1210u\n5\n01u12u20u\n3\n77u\n12\n9u8u845u954u\n0\n",
"11\n01u12u0123u\n6\n01u10u\n1\n201u210u\n9\n1... | [
"SAFE\nUNSAFE\nSAFE\nUNSAFE\nUNSAFE\nUNSAFE\n",
"SAFE\nUNSAFE\n",
"UNSAFE\nUNSAFE\n",
"SAFE\nUNSAFE\nSAFE\nSAFE\nUNSAFE\nUNSAFE\n",
"SAFE\n",
"SAFE\nSAFE\n",
"SAFE\nUNSAFE\nSAFE\nUNSAFE\n",
"SAFE\nUNSAFE\nSAFE\nSAFE\n",
"UNSAFE\nUNSAFE\nSAFE\nUNSAFE\nUNSAFE\nUNSAFE\n",
"SAFE\nUNSAFE\nSAFE\nUNSAFE\... |
CodeContests | Gaku decided to observe the ant's nest as a free study during the summer vacation. The transparent observation case that his grandpa prepared for his grandchildren is very unique and looks like Figure 1.
Ant nest
Figure 1
This case consists of two congruent convex polygons s1 and s2 and some rectangles. Place one o... | stdin | null | 4,510 | 1 | [
"4 1 1\n0 0\n1 0\n1 2\n0 2\n0 0 0\n"
] | [
"1.000000\n"
] | [
"4 1 1\n0 0\n1 0\n1 2\n-1 2\n0 0 0\n",
"4 1 1\n0 -1\n1 0\n1 2\n-1 2\n0 0 0\n",
"4 1 1\n0 -1\n1 0\n0 2\n-1 2\n0 0 0\n",
"4 2 1\n0 -1\n1 0\n1 2\n-1 2\n0 0 0\n",
"4 1 1\n0 0\n1 0\n1 2\n0 4\n0 0 0\n",
"4 1 1\n0 0\n1 0\n1 2\n-1 1\n0 0 0\n",
"4 2 1\n0 -1\n1 0\n2 2\n-1 2\n0 0 0\n",
"4 1 1\n-1 -1\n1 0\n0 2\n-... | [
"0.82842712709\n",
"0.63567449160\n",
"0.92820323152\n",
"0.33385053757\n",
"1.00000000020\n",
"0.73205080935\n",
"0.28284271411\n",
"0.66666666862\n",
"0.23106865865\n",
"0.41421356491\n"
] |
CodeContests | Two foxes Jiro and Saburo are playing a game called 1D Reversi. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones b... | stdin | null | 5,017 | 1 | [
"WWWWWW\n",
"WBWBWBWBWB\n",
"BBBWW\n"
] | [
"0\n",
"9\n",
"1\n"
] | [
"WWWXWW\n",
"WBWBWBBBWW\n",
"BWBBW\n",
"WXWXWW\n",
"WWBBCWBWBV\n",
"XWBBCWBWBV\n",
"XWVBCWBWCB\n",
"WWBBB\n",
"XWVWVX\n",
"WWBBBWBWBW\n"
] | [
"2\n",
"6\n",
"3\n",
"4\n",
"7\n",
"8\n",
"9\n",
"1\n",
"5\n",
"6\n"
] |
CodeContests | Problem
N people with IDs from 1 to N are about to sit in N-legged chairs with numbers from 1 to N. The person with ID i wants to sit in the chair pi.
N people are lined up in a row in ascending order of ID, and the first person in the row takes the following actions.
1. If no one is sitting on the chair pi, sit on ... | stdin | null | 2,069 | 1 | [
"5\n3 3 4 4 5\n",
"5\n1 2 3 4 5\n"
] | [
"4\n2\n1\n3\n5\n",
"1\n2\n3\n4\n5\n"
] | [
"5\n2 2 3 4 5\n",
"5\n2 2 1 4 5\n",
"5\n3 2 1 4 5\n",
"5\n3 4 1 4 5\n",
"5\n1 4 3 4 5\n",
"5\n4 2 1 4 5\n",
"5\n3 4 1 5 5\n",
"5\n1 4 4 4 5\n",
"5\n4 2 1 4 2\n",
"5\n1 4 4 5 5\n"
] | [
"2\n1\n3\n4\n5\n",
"3\n1\n2\n4\n5\n",
"3\n2\n1\n4\n5\n",
"3\n4\n1\n2\n5\n",
"1\n4\n3\n2\n5\n",
"3\n2\n4\n1\n5\n",
"3\n5\n1\n2\n4\n",
"1\n3\n4\n2\n5\n",
"3\n2\n5\n1\n4\n",
"1\n5\n3\n2\n4\n"
] |
CodeContests | problem
Given two strings, find the longest of the strings contained in both strings and write a program that answers that length.
Here, the string s included in the string t means that s appears consecutively in t. An empty string, that is, a string of length 0, is included in any string. For example, the string ABR... | stdin | null | 303 | 1 | [
"None\n",
"ABRACADABRA\nECADADABRBCRDARA\nUPWJCIRUCAXIIRGL\nSBQNYBSBZDFNEV\n"
] | [
"None\n",
"5\n0\n"
] | [
"Nnne\n",
"ABRACADAARA\nECADADABRBCRDARA\nUPWJCIRUCAXIIRGL\nSBQNYBSBZDFNEV\n",
"DBRACAAAARA\nECADADBBRBCRDARA\nLCRIIXACURIGJWPU\nSBQNYBSBZDFOEV\n",
"DBRACAAAARA\nECADADBBRBBRDARA\nLCRIIXACURIGJWPU\nSBQNYBSBFDZOEU\n",
"DBRACAAA@RA\nECADADBBRBBRDARA\nLCRIIXACURIGJWPU\nSBQNYBSBFDZOEU\n",
"CARBR@AA?CB\nABRDRB... | [
"0\n",
"4\n0\n",
"3\n0\n",
"3\n1\n",
"2\n1\n",
"2\n2\n",
"4\n1\n",
"1\n1\n",
"0\n",
"4\n0\n"
] |
CodeContests | Exclusive OR (XOR) is an operation on two binary numbers $ x $ and $ y $ (0 or 1) that produces 0 if $ x = y $ and $ 1 $ if $ x \ ne y $. This operation is represented by the symbol $ \ oplus $. From the definition: $ 0 \ oplus 0 = 0 $, $ 0 \ oplus 1 = 1 $, $ 1 \ oplus 0 = 1 $, $ 1 \ oplus 1 = 0 $.
Exclusive OR on two... | stdin | null | 4,353 | 1 | [
"3 3\n1 2 3\n",
"7 1\n1 0 1 0 1 0 1\n",
"5 10\n1 2 4 8 16\n"
] | [
"2\n",
"1\n",
"7\n"
] | [
"5 10\n1 2 5 8 16\n",
"5 10\n1 2 5 8 14\n",
"5 10\n1 2 5 14 14\n",
"8 10\n1 2 5 24 14\n",
"8 10\n1 2 5 24 11\n",
"8 10\n1 2 5 6 11\n",
"8 10\n0 2 5 6 11\n",
"8 10\n0 1 2 5 11\n",
"8 10\n0 1 2 5 9\n",
"8 10\n0 1 2 5 18\n"
] | [
"7\n",
"3\n",
"5\n",
"19\n",
"21\n",
"11\n",
"10\n",
"13\n",
"14\n",
"20\n"
] |
CodeContests | Bozo is shifting his house. He has some balls and boxes which he has to shift. He now wonders how large a ball he can fit in a given box. Given the dimensions of a box, help Bozo determine the radius of the largest ball that he can fit in the box. Assume that an inflated ball will be spherical.
Input:-
The first line... | stdin | null | 281 | 1 | [
"3\n1 2 3\n3 3 7\n987548 4578445 9645875456\n\nSAMPLE\n"
] | [
"0.5\n1.5\n493774.0\n"
] | [
"28\n754474126400970 101 196613378898208859\n380621045618581 267501121282332999 950586\n793855488118611572 865408 211106328880\n373419125 487966671162 240278042032\n366316 973 365\n592904340231516 734 44193919246935149\n76 752 536\n343780751470180549 907 976026998834190\n868 755369598881618 949147865451779631\n6929... | [
"50.5\n475293.0\n432704.0\n186709562.5\n182.5\n367.0\n38.0\n453.5\n434.0\n359440681.5\n121.5\n103446324720.5\n145.0\n358.5\n169136.0\n17331424576.0\n478450.0\n248.0\n301944857579.0\n176772278.5\n238.5\n366.0\n396.5\n118.5\n254726.5\n290.5\n18108035.0\n223199.5\n",
"274.5\n223.5\n270358901.0\n249360.5\n258997.5\n6... |
CodeContests | Write a program which reads two sequences of nodes obtained by the preorder tree walk and the inorder tree walk on a binary tree respectively, and prints a sequence of the nodes obtained by the postorder tree walk on the binary tree.
Constraints
* $1 \leq n \leq 40$
Input
In the first line, an integer $n$, which is... | stdin | null | 3,778 | 1 | [
"5\n1 2 3 4 5\n3 2 4 1 5\n",
"4\n1 2 3 4\n1 2 3 4\n"
] | [
"3 4 2 5 1\n",
"4 3 2 1\n"
] | [
"4\n1 2 3 4\n2 1 3 4\n",
"4\n2 1 3 4\n2 1 3 4\n",
"4\n2 1 3 4\n3 1 2 4\n",
"5\n1 2 3 4 5\n1 2 4 3 5\n",
"4\n2 1 3 4\n1 2 3 4\n",
"5\n1 3 2 4 5\n3 2 4 1 5\n",
"4\n1 4 3 2\n1 2 3 4\n",
"5\n1 2 3 4 5\n3 4 2 1 5\n",
"4\n1 2 3 4\n1 2 4 3\n",
"4\n2 1 3 4\n2 1 4 3\n"
] | [
"2 4 3 1\n",
"4 3 1 2\n",
"3 1 4 2\n",
"4 5 3 2 1\n",
"1 4 3 2\n",
"4 2 3 5 1\n",
"2 3 4 1\n",
"4 3 2 5 1\n",
"4 3 2 1\n",
"4 3 1 2\n"
] |
CodeContests | Snuke found N strange creatures. Each creature has a fixed color and size. The color and size of the i-th creature are represented by i and A_i, respectively.
Every creature can absorb another creature whose size is at most twice the size of itself. When a creature of size A and color B absorbs another creature of siz... | stdin | null | 4,900 | 1 | [
"5\n1 1 1 1 1\n",
"3\n3 1 4\n",
"6\n40 1 30 2 7 20\n"
] | [
"5\n",
"2\n",
"4\n"
] | [
"5\n1 1 1 1 2\n",
"3\n3 1 3\n",
"6\n40 1 26 2 7 20\n",
"3\n1 1 3\n",
"6\n7 2 21 2 9 20\n",
"5\n1 2 1 1 2\n",
"6\n40 1 26 2 9 20\n",
"5\n1 2 1 0 2\n",
"6\n40 1 21 2 9 20\n",
"5\n1 1 1 0 2\n"
] | [
"5\n",
"2\n",
"4\n",
"3\n",
"6\n",
"5\n",
"4\n",
"4\n",
"4\n",
"4\n"
] |
CodeContests | F: Miko Mi String-
story
Mikko Mikkomi ~! Everyone's idol, Miko Miko Tazawa! Today ~, with Mikoto ~, practice the string algorithm, let's do it ☆
Miko's special ~~ character making ~~ The slogan "MikoMikomi" becomes "MikoMikoMi" in Roman letters! In other words, if A = “Mi” and B = “Ko”, you can write in the form of... | stdin | null | 4,323 | 1 | [
"NicoNicoNi\n"
] | [
"Love Nico!\n"
] | [
"iNociNociN\n",
"iNobiNociN\n",
"iNoaiNociN\n",
"iNoaiNochN\n",
"NhcoNiaoNi\n",
"NhcoNiNoai\n",
"NhcoNjNoai\n",
"NhboNjNoai\n",
"NhbNNjooai\n",
"NhbNOjooai\n"
] | [
"Love iNoc!\n",
"mitomerarenaiWA\n",
"mitomerarenaiWA\n",
"mitomerarenaiWA\n",
"mitomerarenaiWA\n",
"mitomerarenaiWA\n",
"mitomerarenaiWA\n",
"mitomerarenaiWA\n",
"mitomerarenaiWA\n",
"mitomerarenaiWA\n"
] |
CodeContests | Ikshu and his prime matrix
Ikshu is in love with prime numbers. He has a matrix of size N X N and wants atleast 5 prime numbers in that matrix arranged like a cross as shown in figure. Let us call this matrix "new year matrix"
X X X X X
If matrix is not a "new year matrix" he can alter it with the operation a... | stdin | null | 322 | 1 | [
"3 1\n2 2 3\n4 5 6\n7 8 9\n\nSAMPLE\n"
] | [
"yes\n2\n2 2\n"
] | [
"142 3\n1639 47 1213 1989 256 4557 1411 765 4454 4006 2184 4267 399 3040 244 457 4028 3120 2447 2609 949 1324 1954 2453 4273 4587 1632 2181 1378 2208 1911 3711 1136 2293 3119 62 4381 3621 2147 406 4974 4268 3514 1047 4315 2058 2339 1740 133 895 279 1040 4524 1291 1133 4166 3447 4112 1324 2564 3685 4367 4651 1511 20... | [
"yes\n1\n68 80\n",
"yes\n1\n12 23\n",
"yes\n2\n2 2\n",
"yes\n1\n2 2\n",
"yes\n1\n12 18\n",
"yes\n1\n14 22\n",
"yes\n1\n13 19\n",
"yes\n1\n4 3\n",
"yes\n3\n2 2\n",
"yes\n5\n2 2\n"
] |
CodeContests | Example
Input
4 2 58 100
10 10 50 80
Output
75
2 3 | stdin | null | 946 | 1 | [
"4 2 58 100\n10 10 50 80\n"
] | [
"75\n2 3\n"
] | [
"6 2 58 100\n10 10 50 80\n",
"6 2 15 100\n10 10 50 80\n",
"6 3 15 100\n10 10 50 80\n",
"6 3 15 100\n10 10 12 80\n",
"6 3 15 100\n10 10 20 80\n",
"6 4 15 100\n10 10 20 80\n",
"9 4 15 100\n10 10 20 80\n",
"13 3 24 100\n10 10 23 80\n",
"13 3 24 100\n20 10 23 80\n",
"13 3 24 100\n20 18 23 80\n"
] | [
"70\n2 3\n",
"35\n1 2\n",
"35\n1 2 5\n",
"56\n1 2 3\n",
"60\n1 2 3\n",
"65\n1 2 3 5\n",
"60\n1 2 3 5\n",
"61\n1 2 3\n",
"66\n1 2 3\n",
"52\n1 3 5\n"
] |
CodeContests | Problem:
Rani and Nandu decide to play a number game. Both play alternately, Rani playing the first move.
In each of their moves, they can subtract a maximum of k and a minimun of 1 from n ( ie.each of them must subtract from n, any natural number less than or equal to k) , and the new value of n will be the result ... | stdin | null | 12 | 1 | [
"2\n2 1\n3 2\n\nSAMPLE\n"
] | [
"Rani\nRani\n"
] | [
"72\n909 34\n420 51\n621 76\n65 48\n82 41\n665 53\n43 33\n309 21\n942 51\n156 13\n997 11\n753 26\n529 41\n187 15\n961 71\n619 7\n425 73\n126 75\n551 77\n121 79\n349 82\n16 12\n711 36\n389 81\n72 2\n747 89\n265 30\n896 13\n14 1\n289 71\n270 17\n470 9\n33 18\n141 33\n904 83\n915 96\n803 38\n673 61\n621 53\n225 14\n58... | [
"Rani\nRani\nRani\nRani\nRani\nRani\nRani\nNandu\nRani\nRani\nNandu\nRani\nRani\nRani\nRani\nRani\nRani\nRani\nRani\nRani\nRani\nRani\nRani\nRani\nRani\nRani\nRani\nRani\nRani\nNandu\nRani\nRani\nRani\nRani\nRani\nRani\nRani\nRani\nRani\nRani\nRani\nRani\nRani\nRani\nRani\nRani\nRani\nRani\nRani\nRani\nRani\nRani\n... |
CodeContests | There are N pieces of source code. The characteristics of the i-th code is represented by M integers A_{i1}, A_{i2}, ..., A_{iM}.
Additionally, you are given integers B_1, B_2, ..., B_M and C.
The i-th code correctly solves this problem if and only if A_{i1} B_1 + A_{i2} B_2 + ... + A_{iM} B_M + C > 0.
Among the N c... | stdin | null | 4,622 | 1 | [
"3 3 0\n100 -100 0\n0 100 100\n100 100 100\n-100 100 100\n",
"5 2 -4\n-2 5\n100 41\n100 40\n-3 0\n-6 -2\n18 -13\n",
"2 3 -10\n1 2 3\n3 2 1\n1 2 2\n"
] | [
"0\n",
"2\n",
"1\n"
] | [
"3 3 0\n100 -100 0\n0 100 101\n100 100 100\n-100 100 100\n",
"5 2 -4\n-2 5\n100 41\n100 40\n-4 0\n-6 -2\n18 -13\n",
"3 3 0\n101 -100 0\n0 100 101\n100 100 100\n-100 100 100\n",
"5 2 -4\n-2 5\n100 41\n001 40\n-3 1\n-6 -2\n18 -13\n",
"2 3 -10\n1 2 3\n3 2 1\n1 1 2\n",
"5 2 -4\n-2 5\n100 41\n100 40\n-4 -1\n-6... | [
"0\n",
"2\n",
"1\n",
"3\n",
"0\n",
"1\n",
"0\n",
"1\n",
"1\n",
"0\n"
] |
CodeContests | Fair Chocolate-Cutting
You are given a flat piece of chocolate of convex polygon shape. You are to cut it into two pieces of precisely the same amount with a straight knife.
Write a program that computes, for a given convex polygon, the maximum and minimum lengths of the line segments that divide the polygon into two... | stdin | null | 3,285 | 1 | [
"4\n0 0\n10 0\n10 10\n0 10\n"
] | [
"10\n14.142135623730950488\n"
] | [
"4\n0 0\n10 0\n10 4\n0 10\n",
"4\n0 0\n10 0\n10 2\n0 10\n",
"4\n0 0\n10 0\n10 2\n0 9\n",
"4\n0 0\n10 1\n10 2\n0 9\n",
"4\n0 0\n10 1\n10 2\n1 9\n",
"4\n0 0\n9 1\n10 2\n1 9\n",
"4\n0 0\n9 1\n10 4\n1 9\n",
"4\n0 0\n10 0\n14 10\n0 10\n",
"4\n0 0\n7 0\n10 4\n0 10\n",
"4\n0 0\n10 0\n10 2\n0 1\n"
] | [
"7.3178024859\n12.2065556157\n",
"6.7528910636\n11.6619037897\n",
"6.1868396755\n11.4127122105\n",
"6.1660587942\n10.7703296143\n",
"6.3319736848\n10.2437469572\n",
"6.3592985397\n9.7717758522\n",
"6.7506203352\n9.8478424033\n",
"10.0000000000\n16.4155227683\n",
"7.5414879701\n11.8726576637\n",
"1... |
CodeContests | Today a plane was hijacked by a maniac. All the passengers of the flight are taken as hostage. Chef is also one of them.
He invited one of the passengers to play a game with him. If he loses the game, he will release all the passengers, otherwise he will kill all of them. A high risk affair it is.
Chef volunteered fo... | stdin | null | 3,819 | 1 | [
"2\n3 3 3\n1\n3 3 3\n2\n"
] | [
"1\n4\n"
] | [
"2\n6 3 3\n1\n3 3 3\n2\n",
"2\n0 0 3\n2\n3 3 3\n2\n",
"2\n6 0 3\n2\n3 3 3\n2\n",
"2\n1 0 3\n1\n3 3 0\n2\n",
"2\n0 0 3\n2\n3 3 4\n0\n",
"2\n6 0 3\n3\n3 3 3\n2\n",
"2\n0 0 3\n2\n3 4 0\n2\n",
"2\n6 0 3\n3\n3 3 3\n4\n",
"2\n1 1 3\n1\n0 3 0\n2\n",
"2\n0 0 5\n2\n3 3 6\n4\n"
] | [
"1\n4\n",
"2\n4\n",
"3\n4\n",
"1\n3\n",
"2\n-2\n",
"5\n4\n",
"2\n3\n",
"5\n10\n",
"1\n2\n",
"2\n10\n"
] |
CodeContests | Problem
There are $ 2 $ teams, Team UKU and Team Ushi. Initially, Team UKU has $ N $ people and Team Uku has $ M $ people. Team UKU and Team Ushi decided to play a game called "U & U". "U & U" has a common score for $ 2 $ teams, and the goal is to work together to minimize the common score. In "U & U", everyone's phys... | stdin | null | 1,344 | 1 | [
"64783 68943\n",
"20 10\n",
"1000000000000000000 1000000000000000000\n",
"10 20\n"
] | [
"4\n",
"0\n",
"2\n",
"1\n"
] | [
"57319 68943\n",
"25 10\n",
"1000000000000000000 1000000000010000000\n",
"10 36\n",
"105904 68943\n",
"25 12\n",
"1000000001000000000 1000000000010000000\n",
"10 48\n",
"109335 68943\n",
"13 12\n"
] | [
"3\n",
"0\n",
"4\n",
"1\n",
"2\n",
"0\n",
"2\n",
"1\n",
"2\n",
"2\n"
] |
CodeContests | Problem statement
There is a rational number sequence $ X_0, X_1, X_2, ..., X_N $. Each term is defined as follows.
1. $ X_0 = 0 $
2. $ X_i = X_ {i-1} $ $ op_i $ $ Y_i $ ($ 1 \ leq i \ leq N $). However, $ op_i $ is $ + $, $ − $, $ × $, $ ÷ $ Either.
Find $ X_N $.
Constraint
* $ 1 \ leq N \ leq 10 ^ 5 $
* $ 1 \... | stdin | null | 2,026 | 1 | [
"4\n1 1\n4 2\n2 4\n3 4\n"
] | [
"-14\n"
] | [
"4\n0 1\n4 2\n2 4\n3 4\n",
"4\n0 1\n4 2\n2 1\n3 4\n",
"4\n-1 1\n4 3\n1 1\n3 4\n",
"4\n-1 1\n4 2\n1 1\n3 8\n",
"4\n-1 1\n4 4\n1 0\n3 8\n",
"4\n1 2\n4 2\n2 4\n3 4\n",
"4\n1 2\n4 2\n2 4\n3 7\n",
"4\n0 1\n4 3\n2 1\n2 4\n",
"4\n-2 1\n4 2\n1 1\n1 4\n",
"4\n2 2\n4 2\n2 4\n3 7\n"
] | [
"-16\n",
"-4\n",
"4\n",
"8\n",
"0\n",
"-12\n",
"-21\n",
"-5\n",
"5\n",
"-35\n"
] |
CodeContests | Let S(n) denote the sum of the digits in the decimal notation of n. For example, S(123) = 1 + 2 + 3 = 6.
We will call an integer n a Snuke number when, for all positive integers m such that m > n, \frac{n}{S(n)} \leq \frac{m}{S(m)} holds.
Given an integer K, list the K smallest Snuke numbers.
Constraints
* 1 \leq K... | stdin | null | 256 | 1 | [
"10\n"
] | [
"1\n2\n3\n4\n5\n6\n7\n8\n9\n19\n"
] | [
"18\n",
"7\n",
"5\n",
"8\n",
"2\n",
"6\n",
"15\n",
"4\n",
"1\n",
"11\n"
] | [
"1\n2\n3\n4\n5\n6\n7\n8\n9\n19\n29\n39\n49\n59\n69\n79\n89\n99\n",
"1\n2\n3\n4\n5\n6\n7\n",
"1\n2\n3\n4\n5\n",
"1\n2\n3\n4\n5\n6\n7\n8\n",
"1\n2\n",
"1\n2\n3\n4\n5\n6\n",
"1\n2\n3\n4\n5\n6\n7\n8\n9\n19\n29\n39\n49\n59\n69\n",
"1\n2\n3\n4\n",
"1\n",
"1\n2\n3\n4\n5\n6\n7\n8\n9\n19\n29\n"
] |
CodeContests | Internet search engines, such as Google, automatically sort and categorize web pages around the world to create a huge database. It also parses the search keywords entered by the user and creates an inquiry statement for database search.
In each case, complicated processing is performed to realize efficient search, bu... | stdin | null | 3,841 | 1 | [
"Win today's preliminary contest and be qualified to visit University of Aizu.\n",
"Rain, rain, go to Spain.\n"
] | [
"Win and visit Aizu\n",
"Rain rain Spain\n"
] | [
"Win today's preliminary contest and be qualified to visit University fo Aizu.\n",
"Rain, rain, go ot Spain.\n",
"Rain, iarn, og ot Spain.\n",
"Win todax's premiminary contest and be qualified to vhsit Uniwersity fo Aizu.\n",
"niW todax's premiminary contest and be qualified to vhsit Uniwersity fo Aizu.\n",... | [
"Win and visit Aizu\n",
"Rain rain Spain\n",
"Rain iarn Spain\n",
"Win and vhsit Aizu\n",
"niW and vhsit Aizu\n",
"niW `nd vhsit Aizu\n",
"niW `nd vhtit Aizu\n",
"Win `nd vhtit Aizu\n",
"iWn `nd vhtit Aizu\n",
"iWn `nd vhsit Aizu\n"
] |
CodeContests | Read the coordinates of four different points on the plane, $ A (x_A, y_A) $, $ B (x_B, y_B) $, $ C (x_C, y_C) $, $ D (x_D, y_D) $, and straight line $ Create a program that outputs YES if AB $ and $ CD $ are orthogonal, and NO if they are not orthogonal. Here, "straight line" does not mean a line segment. Please refer... | stdin | null | 3,763 | 1 | [
"1.0 1.0 2.0 2.0 0.0 0.0 1.0 -1.0\n0.0 0.0 2.0 0.0 -1.0 2.0 2.0 2.0\n10.0 6.0 3.4 5.2 6.8 9.5 4.3 2.1\n2.5 3.5 2.5 4.5 -3.3 -2.3 6.8 -2.3\n"
] | [
"YES\nNO\nNO\nYES\n"
] | [
"1.0 1.0 2.0 2.0 0.0 0.0 1.0 -1.0\n0.0 0.0 2.0 0.0 -1.0 2.0 2.0 2.0\n10.0 6.0 3.4 5.2 6.8 9.5 4.3 2.1\n2.5 3.5 2.5 5.324353001023156 -3.3 -2.3 6.8 -2.3\n",
"1.0 1.0 2.0 2.0 0.0 0.0 1.0 -1.0\n0.0 0.0 2.0 0.0 -1.0 2.0 2.0 2.0\n10.0 6.0 3.4 5.2 6.8 9.5 4.3 2.1\n3.455765838159193 3.5 2.5 5.324353001023156 -3.3 -2.3 6... | [
"YES\nNO\nNO\nYES\n",
"YES\nNO\nNO\nNO\n",
"NO\nNO\nNO\nNO\n",
"YES\nNO\nNO\nNO\n",
"NO\nNO\nNO\nNO\n",
"NO\nNO\nNO\nNO\n",
"NO\nNO\nNO\nNO\n",
"NO\nNO\nNO\nNO\n",
"NO\nNO\nNO\nNO\n",
"NO\nNO\nNO\nNO\n"
] |
CodeContests | Mr. Infinity has a string S consisting of digits from `1` to `9`. Each time the date changes, this string changes as follows:
* Each occurrence of `2` in S is replaced with `22`. Similarly, each `3` becomes `333`, `4` becomes `4444`, `5` becomes `55555`, `6` becomes `666666`, `7` becomes `7777777`, `8` becomes `888888... | stdin | null | 3,041 | 1 | [
"299792458\n9460730472580800\n",
"3\n157\n",
"1214\n4\n"
] | [
"2\n",
"3\n",
"2\n"
] | [
"299792458\n16007747457388278\n",
"3\n162\n",
"1214\n1\n",
"1214\n8\n",
"299792458\n5161700883731392\n",
"3\n102\n",
"1214\n9\n",
"299792458\n6594324861078428\n",
"3\n74\n",
"1214\n17\n"
] | [
"2\n",
"3\n",
"1\n",
"2\n",
"2\n",
"3\n",
"2\n",
"2\n",
"3\n",
"2\n"
] |
CodeContests | Let there be a function f(N) such that f(N) denotes number of zeroes at the end of N! (factorial of N).
For example, f(5) = 1 because 5! = 120.
You have to compute f(N) for given N.
Input format : Input begins with integer t ( 1 ≤ t ≤ 10000) denoting number of test cases. Then there are t lines each containing exac... | stdin | null | 567 | 1 | [
"5\n4\n5\n10\n25\n100\n\nSAMPLE\n"
] | [
"0\n1\n2\n6\n24\n"
] | [
"1000\n65\n85\n45\n23\n85\n63\n52\n79\n24\n5\n6\n74\n64\n64\n99\n45\n66\n76\n65\n21\n57\n88\n100\n94\n17\n82\n100\n46\n88\n29\n70\n7\n50\n46\n92\n95\n96\n94\n97\n85\n84\n12\n27\n51\n59\n54\n91\n44\n89\n69\n72\n63\n82\n92\n98\n39\n15\n36\n92\n13\n43\n6\n99\n84\n37\n53\n51\n18\n79\n86\n99\n64\n50\n46\n21\n65\n37\n60\... | [
"15\n20\n10\n4\n20\n14\n12\n18\n4\n1\n1\n16\n14\n14\n22\n10\n15\n18\n15\n4\n13\n20\n24\n21\n3\n19\n24\n10\n20\n6\n16\n1\n12\n10\n21\n22\n22\n21\n22\n20\n19\n2\n6\n12\n13\n12\n21\n9\n20\n15\n16\n14\n19\n21\n22\n8\n3\n8\n21\n2\n9\n1\n22\n19\n8\n12\n12\n3\n18\n20\n22\n14\n12\n10\n4\n15\n8\n14\n12\n18\n1\n8\n10\n8\n22\... |
CodeContests | You will be given a string S of length 3 representing the weather forecast for three days in the past.
The i-th character (1 \leq i \leq 3) of S represents the forecast for the i-th day. `S`, `C`, and `R` stand for sunny, cloudy, and rainy, respectively.
You will also be given a string T of length 3 representing the ... | stdin | null | 3,432 | 1 | [
"CSS\nCSR\n",
"RRR\nSSS\n",
"SSR\nSSR\n"
] | [
"2\n",
"0\n",
"3\n"
] | [
"CSS\nBSR\n",
"SRR\nSSR\n",
"SSR\nRTS\n",
"STR\nSTR\n",
"RSR\nSSS\n",
"SSC\nBSR\n",
"RSR\nSSR\n",
"SSR\nRSS\n",
"SSC\nRSB\n",
"RTR\nSSR\n"
] | [
"1\n",
"2\n",
"0\n",
"3\n",
"1\n",
"1\n",
"2\n",
"1\n",
"1\n",
"1\n"
] |
CodeContests | Alice has just learnt about primeStrings. A string is a primeString if the number of distinct alphabets used in the string is a prime and also the number of occurrences of each alphabet in the string is also a prime.
Given a String you need to tell if it is a primeString or not.
Input:
First line contains T which is t... | stdin | null | 247 | 1 | [
"3\nababb\nabcab\naabbccdd\n\nSAMPLE\n"
] | [
"YES\nNO\nNO\n"
] | [
"3\nababb\nabcab\naabbccdd\n\nS@MPLE\n",
"3\nababc\nabcab\nddccbbaa\n\nS@MPLE\n",
"3\nababc\nbabba\ndcdcbbaa\n\nS@MPLE\n",
"3\naabbb\nbabba\naabbccdd\n\nEAMOSL\n",
"3\nbbaba\nabcbc\nccbcbbaa\n\nSM>OLD\n",
"3\ncbaac\nbacab\nacaccadd\n\nELPM@S\n",
"3\nababb\nabcab\nddccbbaa\n\nS@MPLE\n",
"3\ncbaba\nabca... | [
"YES\nNO\nNO\n",
"NO\nNO\nNO\n",
"NO\nYES\nNO\n",
"YES\nYES\nNO\n",
"YES\nNO\nYES\n",
"NO\nNO\nYES\n",
"YES\nNO\nNO\n",
"NO\nNO\nNO\n",
"NO\nNO\nNO\n",
"YES\nNO\nNO\n"
] |
CodeContests | Who's interested in football?
Rayne Wooney has been one of the top players for his football club for the last few years. But unfortunately, he got injured during a game a few months back and has been out of play ever since.
He's got proper treatment and is eager to go out and play for his team again. Before doing that,... | stdin | null | 1,952 | 1 | [
"3\n6\n3 7 1 4 2 4\n5\n5 4 3 2 1\n5\n4 3 2 2 3\n"
] | [
"4\nUNFIT\n1\n"
] | [
"3\n6\n3 7 1 4 2 4\n5\n5 4 3 2 1\n5\n4 3 1 2 3\n",
"3\n6\n3 1 1 4 2 4\n5\n5 4 3 2 1\n5\n4 3 1 2 3\n",
"3\n6\n3 1 1 4 2 4\n5\n2 4 3 2 1\n5\n4 3 1 2 3\n",
"3\n6\n1 1 0 4 2 4\n5\n4 4 3 2 1\n5\n4 0 1 2 3\n",
"3\n6\n1 1 0 4 2 4\n5\n4 7 3 2 2\n5\n4 0 1 2 3\n",
"3\n6\n1 1 1 4 2 4\n5\n4 7 3 2 2\n5\n4 0 1 2 3\n",
... | [
"4\nUNFIT\n2\n",
"3\nUNFIT\n2\n",
"3\n2\n2\n",
"4\nUNFIT\n3\n",
"4\n3\n3\n",
"3\n3\n3\n",
"4\nUNFIT\n1\n",
"5\nUNFIT\n2\n",
"3\n7\n3\n",
"4\n1\n3\n"
] |
CodeContests | Snuke, who loves animals, built a zoo.
There are N animals in this zoo. They are conveniently numbered 1 through N, and arranged in a circle. The animal numbered i (2≤i≤N-1) is adjacent to the animals numbered i-1 and i+1. Also, the animal numbered 1 is adjacent to the animals numbered 2 and N, and the animal numbered... | stdin | null | 3,277 | 1 | [
"10\noxooxoxoox\n",
"6\nooxoox\n",
"3\noox\n"
] | [
"SSWWSSSWWS\n",
"SSSWWS\n",
"-1\n"
] | [
"3\nxoo\n",
"6\nxooxoo\n",
"10\nxooxoxooxo\n",
"10\nxxooxoxooo\n",
"10\noxooooxxox\n",
"10\nxoxxooooxo\n",
"10\noooxoxooxx\n",
"10\noxooooxxxo\n",
"10\noxoooxxoox\n",
"10\noxooooxoxx\n"
] | [
"-1\n",
"SSSSWW\n",
"SWWSSSWWSS\n",
"SWSWWWSSSS\n",
"SSWWSWWWWS\n",
"SWWWWSWWSS\n",
"SSSSWWWSWS\n",
"WWWSWWSSWS\n",
"WSSSSSWSWW\n",
"WSSSSSSWWW\n"
] |
CodeContests | Chef loves to play games. Now he plays very interesting game called "Segment". At the beginning Chef has segment [0, X] and no points on it. On each step Chef chooses the subsegment of maximal length possible such as it contains no points on it. If there are more than one such subsegment Chef chooses the one with the m... | stdin | null | 396 | 1 | [
"4\n10 1\n10 2\n10 3\n1000000000 1234567\n"
] | [
"5.0000000000000000\n2.5000000000000000\n7.5000000000000000\n177375316.6198730468750000\n"
] | [
"4\n10 2\n10 2\n10 3\n1000000000 1234567\n",
"4\n10 2\n10 3\n10 3\n1000000000 1234567\n",
"4\n14 2\n10 3\n10 3\n1000000000 1234567\n",
"4\n14 2\n10 3\n13 3\n1000000000 1234567\n",
"4\n10 2\n10 3\n13 3\n1000000000 1234567\n",
"4\n3 2\n10 3\n13 3\n1000000000 1234567\n",
"4\n3 2\n10 6\n13 3\n1000000000 123... | [
"2.5000000000000000\n2.5000000000000000\n7.5000000000000000\n177375316.6198730468750000\n",
"2.5000000000000000\n7.5000000000000000\n7.5000000000000000\n177375316.6198730468750000\n",
"3.5000000000000000\n7.5000000000000000\n7.5000000000000000\n177375316.6198730468750000\n",
"3.5000000000000000\n7.50000000000... |
CodeContests | We ask you to select some number of positive integers, and calculate the sum of them.
It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer.
Your objecti... | stdin | null | 4,390 | 1 | [
"7 5 1\n",
"2 2 1\n",
"77 42 36\n",
"40 98 58\n",
"1 100 97\n"
] | [
"YES\n",
"NO\n",
"NO\n",
"YES\n",
"YES\n"
] | [
"7 5 0\n",
"77 42 5\n",
"2 2 0\n",
"80 98 58\n",
"1 110 97\n",
"11 5 0\n",
"2 4 0\n",
"77 42 2\n",
"103 98 58\n",
"0 110 97\n"
] | [
"YES\n",
"NO\n",
"YES\n",
"YES\n",
"YES\n",
"YES\n",
"YES\n",
"NO\n",
"YES\n",
"NO\n"
] |
CodeContests | Write a program which solve a simultaneous equation:
ax + by = c
dx + ey = f
The program should print x and y for given a, b, c, d, e and f (-1,000 ≤ a, b, c, d, e, f ≤ 1,000). You can suppose that given equation has a unique solution.
Input
The input consists of several data sets, 1 line for each data set. In a ... | stdin | null | 892 | 1 | [
"1 2 3 4 5 6\n2 -1 -2 -1 -1 -5\n",
"2 -1 -3 1 -1 -3\n2 -1 -3 -9 9 27\n"
] | [
"-1.000 2.000\n1.000 4.000\n",
"0.000 3.000\n0.000 3.000\n"
] | [
"1 2 3 4 5 6\n2 -1 -4 -1 -1 -5\n",
"2 -1 -3 1 0 -3\n2 -1 -3 -9 9 27\n",
"1 2 3 4 5 5\n2 -1 -4 -1 -1 -5\n",
"3 -1 -3 1 0 -3\n2 -1 -3 -9 9 27\n",
"1 2 3 4 5 4\n2 -1 -4 -1 -1 -5\n",
"3 -1 -3 1 0 -3\n2 -1 -3 -9 18 27\n",
"1 1 3 4 5 4\n2 -1 -4 -1 -1 -5\n",
"3 -2 -3 1 0 -3\n2 -1 -3 -9 18 27\n",
"1 1 3 4 5... | [
"-1.000 2.000\n0.333 4.667\n",
"-3.000 -3.000\n0.000 3.000\n",
"-1.667 2.333\n0.333 4.667\n",
"-3.000 -6.000\n0.000 3.000\n",
"-2.333 2.667\n0.333 4.667\n",
"-3.000 -6.000\n-1.000 1.000\n",
"11.000 -8.000\n0.333 4.667\n",
"-3.000 -3.000\n-1.000 1.000\n",
"11.000 -8.000\n0.000 4.000\n",
"11.000 -8.... |
CodeContests | Dr. Asimov, a robotics researcher, loves to research, but hates houseworks and his house were really dirty. So, he has developed a cleaning robot.
As shown in the following figure, his house has 9 rooms, where each room is identified by an alphabet:
<image>
The robot he developed operates as follows:
* If the bat... | stdin | null | 503 | 1 | [
"1\nE A C\n1\nE B C\n2\nE A B\n0\n"
] | [
"0.00000000\n0.25000000\n0.06250000\n"
] | [
"1\nD A C\n1\nE B C\n2\nE A B\n0\n",
"1\nD A C\n1\nE B C\n2\nF A B\n0\n",
"1\nD A C\n0\nE B C\n2\nF A B\n0\n",
"1\nC A C\n0\nE B C\n2\nF A B\n0\n",
"1\nE A B\n1\nE B C\n2\nE A B\n0\n",
"1\nD A C\n1\nE A D\n2\nF A B\n0\n",
"1\nC A D\n1\nD B C\n2\nF A B\n0\n",
"1\nD A C\n1\nE A D\n3\nF A B\n0\n",
"1\n... | [
"0.25000000\n0.25000000\n0.06250000\n",
"0.25000000\n0.25000000\n0.00000000\n",
"0.25000000\n",
"0.00000000\n",
"0.00000000\n0.25000000\n0.06250000\n",
"0.25000000\n0.00000000\n0.00000000\n",
"0.00000000\n0.00000000\n0.00000000\n",
"0.25000000\n0.00000000\n0.01562500\n",
"0.25000000\n0.00000000\n0.0... |
CodeContests | Takahashi is going to set a 3-character password.
How many possible passwords are there if each of its characters must be a digit between 1 and N (inclusive)?
Constraints
* 1 \leq N \leq 9
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the number of possibl... | stdin | null | 4,070 | 1 | [
"2\n",
"1\n"
] | [
"8\n",
"1\n"
] | [
"4\n",
"0\n",
"3\n",
"-1\n",
"5\n",
"-2\n",
"-4\n",
"-3\n",
"8\n",
"-5\n"
] | [
"64\n",
"0\n",
"27\n",
"-1\n",
"125\n",
"-8\n",
"-64\n",
"-27\n",
"512\n",
"-125\n"
] |
CodeContests | Deepak like strings which are in flip flop in nature. For example, he likes XYXYX, while he doesn't like XXYX. Now he want to convert every string into a string which he likes. for this, he only delete the character in the string.
Now find the minimum number of delete operation which is required to covert a string tha... | stdin | null | 4,491 | 1 | [
"5\nXXXX\nYYYYY\nXYXYXYXY\nYXYXYX\nXXXYYY\n\nSAMPLE\n"
] | [
"3\n4\n0\n0\n4\n"
] | [
"5\nXXXX\nYYYYY\nXYXYXYXY\nYXYXYX\nXYXYYY\n\nSAMPLE\n",
"5\nXXXX\nYYYYY\nXYXYXYXY\nXYXYXY\nXYYYYY\n\nSAMPLE\n",
"5\nXXXX\nYYYYY\nYXYXYXYX\nYYYXYX\nXYYYYY\n\nKEPMAS\n",
"5\nXXXX\nYYYYY\nYXYXYXYX\nYYYYYX\nYYYYYX\n\nKEPMBS\n",
"5\nXXXX\nYYYYY\nYYYXYXYX\nYYYXYX\nYYYYYX\n\nKPEMBS\n",
"5\nXXXX\nYYYYY\nYYYXYXYX\... | [
"3\n4\n0\n0\n2\n",
"3\n4\n0\n0\n4\n",
"3\n4\n0\n2\n4\n",
"3\n4\n0\n4\n4\n",
"3\n4\n2\n2\n4\n",
"3\n4\n2\n2\n5\n",
"3\n4\n2\n2\n2\n",
"3\n4\n2\n0\n2\n",
"3\n4\n0\n1\n4\n",
"3\n3\n0\n2\n4\n"
] |
CodeContests | Taro loves chocolate and when he returns from school he eats his favorite chocolate bar with a heart symbol on it. A recent pleasure is to eat all the heart symbol blocks to the end. Taro , Try to eat as many heartless blocks as possible, with all heartmark blocks connected.
<image>
However, Taro is still young, and ... | stdin | null | 4,512 | 1 | [
"4 4\n1 0 0 0\n0 0 1 0\n0 1 0 0\n1 0 0 1\n1 1\n1\n2 3\n1 0 0\n0 0 1\n0 0\n"
] | [
"7\n0\n2\n"
] | [
"4 4\n1 0 0 0\n0 0 1 0\n0 0 0 0\n1 0 0 1\n1 1\n1\n2 3\n1 0 0\n0 0 1\n0 0\n",
"4 4\n1 0 -1 1\n0 0 1 0\n0 0 0 0\n1 0 0 1\n1 1\n1\n2 3\n1 0 0\n0 0 1\n0 0\n",
"4 4\n1 -1 0 0\n0 0 1 0\n0 1 0 0\n0 0 0 1\n1 1\n1\n2 3\n1 0 0\n0 0 1\n0 0\n",
"4 4\n1 0 -1 0\n0 0 1 0\n0 0 0 0\n1 0 0 1\n1 1\n1\n1 3\n1 0 1\n0 0 1\n0 0\n",... | [
"7\n0\n2\n",
"6\n0\n2\n",
"8\n0\n2\n",
"7\n0\n0\n",
"9\n0\n2\n",
"4\n",
"8\n0\n1\n",
"12\n0\n2\n",
"10\n0\n2\n",
"3\n"
] |
CodeContests | Given a string consisting of only numbers from 0 to 9, consider the operation of creating a new string from that string according to the following rules. Read the given string one character at a time from the left end. Go, if the same number a continues r, write the number r and the number a in this order without separ... | stdin | null | 3,924 | 1 | [
"5\n11\n5\n11\n0\n"
] | [
"13112221\n13112221\n"
] | [
"5\n11\n5\n21\n0\n",
"5\n18\n5\n21\n0\n",
"5\n18\n5\n1\n0\n",
"5\n18\n6\n1\n0\n",
"5\n28\n6\n1\n0\n",
"5\n28\n11\n1\n0\n",
"5\n28\n3\n1\n0\n",
"5\n43\n3\n1\n0\n",
"5\n43\n3\n0\n0\n",
"5\n11\n5\n15\n0\n"
] | [
"13112221\n1113213211\n",
"311311222118\n1113213211\n",
"311311222118\n312211\n",
"311311222118\n13112221\n",
"11131221121113122118\n13112221\n",
"11131221121113122118\n3113112221232112111312211312113211\n",
"11131221121113122118\n1211\n",
"11131221141113122113\n1211\n",
"11131221141113122113\n3110\... |
CodeContests | We have N lamps numbered 1 to N, and N buttons numbered 1 to N. Initially, Lamp 1, 2, \cdots, A are on, and the other lamps are off.
Snuke and Ringo will play the following game.
* First, Ringo generates a permutation (p_1,p_2,\cdots,p_N) of (1,2,\cdots,N). The permutation is chosen from all N! possible permutations ... | stdin | null | 645 | 1 | [
"3 1\n",
"3 2\n",
"8 4\n",
"9999999 4999\n"
] | [
"2\n",
"3\n",
"16776\n",
"90395416\n"
] | [
"14 4\n",
"5 1\n",
"3 0\n",
"9479599 4999\n",
"23 4\n",
"8 1\n",
"23 6\n",
"4 1\n",
"34 6\n",
"7 6\n"
] | [
"349779046\n",
"24\n",
"0\n",
"395563313\n",
"586770919\n",
"5040\n",
"342122491\n",
"6\n",
"808113344\n",
"3475\n"
] |
CodeContests | One of the main tasks of an operating system is process scheduling, i.e., managing CPU sharing among a community of ready processes. Several algorithms exist for scheduling tasks to the CPU. Here we are considering Round Robin Scheduling(in a single CPU system) which is the most widely used of all the scheduling algori... | stdin | null | 879 | 1 | [] | [] | [
"10 10\n7 87 78 16 94 36 87 93 75 22 \n10\n1 8\n1 10\n2 7\n1 7\n1 9\n2 9\n2 10\n1 1\n1 4\n2 6\n",
"10 10\n7 87 78 16 94 36 87 93 75 22 \n10\n1 8\n1 10\n2 7\n1 7\n1 9\n2 9\n2 10\n1 1\n1 8\n2 6\n",
"10 10\n7 87 78 16 94 36 87 93 63 22 \n10\n1 8\n1 10\n2 7\n1 7\n1 9\n2 9\n2 10\n1 1\n1 8\n0 6\n",
"10 10\n7 87 78 ... | [
"67\n87\n8\n57\n77\n6\n3\n0\n27\n4\n",
"67\n87\n8\n57\n77\n6\n3\n0\n67\n4\n",
"67\n87\n8\n57\n77\n5\n3\n0\n67\n4\n",
"67\n87\n7\n57\n77\n8\n3\n0\n67\n4\n",
"67\n87\n8\n57\n5\n5\n3\n0\n27\n4\n",
"67\n87\n8\n57\n77\n6\n3\n0\n10\n4\n",
"67\n87\n8\n8\n77\n5\n3\n0\n67\n4\n",
"77\n87\n7\n57\n77\n8\n3\n0\n67... |
CodeContests | Given an array A of N elements, find the number of distinct possible sums that can be obtained by taking any number of elements from the array and adding them.
Note that 0 can always be obtained by taking none.
First line of the input contains number of test cases T.
Each test case has two lines. First line has N, t... | stdin | null | 2,635 | 1 | [
"3\n3\n1 2 3\n5\n5 1 3 2 7\n4\n1 2 4 8 \n\nSAMPLE\n"
] | [
"7\n19\n16\n"
] | [
"10\n35\n62 92 40 83 88 39 33 55 33 45 84 90 81 75 99 94 90 33 11 53 21 12 62 73 23 24 20 2 29 30 49 71 80 45 96\n39\n63 17 79 62 5 40 13 83 32 37 70 0 85 73 4 32 41 78 42 43 32 9 81 12 11 96 74 41 7 90 51 1 58 98 54 47 71 41 17\n53\n52 50 16 75 96 45 77 83 81 41 64 81 96 78 96 8 100 8 39 4 44 44 59 33 90 27 65 54 ... | [
"1886\n1787\n2821\n2314\n2482\n5081\n1962\n1703\n5280\n3536\n",
"7\n19\n16\n",
"7\n16\n16\n",
"7\n20\n16\n",
"7\n12\n16\n",
"7\n11\n16\n",
"7\n11\n12\n",
"7\n6\n12\n",
"7\n4\n12\n",
"6\n4\n12\n"
] |
CodeContests | Problem Statement
Let's consider operations on monochrome images that consist of hexagonal pixels, each of which is colored in either black or white. Because of the shape of pixels, each of them has exactly six neighbors (e.g. pixels that share an edge with it.)
"Filtering" is an operation to determine the color of a... | stdin | null | 272 | 1 | [
"00000000111111110000000011111111000000001111111100000000111111110000000011111111000000001111111100000000111111110000000111111111\n10000000111111110000000011111111000000001111111100000000111111110000000011111111000000001111111100000000111111110000000011111111\n0101010101010101010101010101010101010101010101010101010... | [
"yes\nyes\nno\n"
] | [
"00000000111111110000000011111111000000001111111100000000111111110000000011111111000000001111111100000000111111110000000111111111\n10000000111111110000000011111111000000001111111100000000111111110000000011111111000000001111111100000000111111110000000011111111\n0101010101010101010101010101010101010101010101010101010... | [
"yes\nyes\nno\n",
"yes\nno\nno\n",
"yes\nyes\nno\n",
"yes\nyes\nno\n",
"yes\nno\nno\n",
"yes\nno\nno\n",
"yes\nno\nno\n",
"yes\nno\nno\n",
"yes\nno\nno\n",
"yes\nno\nno\n"
] |
CodeContests | Rajat is a guy who always wants to live in a fantasy world. In his world,
a deck consists of X cards, where X is a multiple of 4.
There are four types of cards namely spade , heart , club and diamond with
each type having values in range of [1,X/4] inclusive.
His cousin wants to test him. So,to test Rajat , his
cousin... | stdin | null | 486 | 1 | [
"2\n8 8 2 heart\n52 1 10 spade \n\nSAMPLE\n"
] | [
"0.1250000000\n0.0192307692\n"
] | [
"97\n100026500 23754052 19170 diamond\n100024464 99996319 5706 heart\n100005436 99990832 32392 diamond\n100000292 99982871 12383 spade\n100019912 99993613 25668 club\n100004664 99996953 15142 heart\n100006868 99979224 25548 diamond\n100012316 99990126 3036 diamond\n100000288 99991248 30107 diamond\n100019264 999918... | [
"0.0000000100\n0.0000000100\n0.0000000100\n0.0000000100\n0.0000000100\n0.0000000100\n0.0000000100\n0.0000000100\n0.0000000100\n0.0000000100\n0.0000000100\n0.0000000100\n0.0000000100\n0.0000000100\n0.0000000100\n0.0000000100\n0.0000000100\n0.0000000100\n0.0000000100\n0.0000000100\n0.0000000100\n0.0000000100\n0.00000... |
CodeContests | Fibonacci number f(i) appear in a variety of puzzles in nature and math, including packing problems, family trees or Pythagorean triangles. They obey the rule f(i) = f(i - 1) + f(i - 2), where we set f(0) = 1 = f(-1).
Let V and d be two certain positive integers and be N ≡ 1001 a constant. Consider a set of V nodes, e... | stdin | null | 342 | 1 | [
"5 5\n50 1\n13 13\n"
] | [
"2\n50\n8\n"
] | [
"5 5\n50 2\n13 13\n",
"2 5\n50 1\n13 13\n",
"2 5\n50 1\n15 13\n",
"5 10\n50 1\n13 20\n",
"5 10\n50 1\n22 20\n",
"8 10\n50 1\n22 20\n",
"8 2\n50 1\n22 20\n",
"8 2\n50 2\n22 20\n",
"5 5\n50 1\n13 18\n",
"5 5\n50 2\n13 4\n"
] | [
"2\n47\n8\n",
"1\n50\n8\n",
"1\n50\n10\n",
"1\n50\n7\n",
"1\n50\n13\n",
"3\n50\n13\n",
"7\n50\n13\n",
"7\n47\n13\n",
"2\n50\n7\n",
"2\n47\n10\n"
] |
CodeContests | <!--
Problem F
-->
Flipping Colors
You are given an undirected complete graph. Every pair of the nodes in the graph is connected by an edge, colored either red or black. Each edge is associated with an integer value called penalty.
By repeating certain operations on the given graph, a "spanning tree" should be for... | stdin | null | 4,085 | 1 | [
"4\n3 3 1\n2 6\n-4\n3\n1 -10\n100\n5\n-2 -2 -2 -2\n-1 -1 -1\n-1 -1\n1\n4\n-4 7 6\n2 3\n-1\n0\n"
] | [
"7\n11\n-1\n9\n"
] | [
"4\n3 3 1\n2 6\n-4\n3\n1 -10\n100\n5\n-2 -2 -2 -2\n-1 -1 -1\n-2 -1\n1\n4\n-4 7 6\n2 3\n-1\n0\n",
"4\n3 3 1\n2 6\n-4\n3\n1 -10\n100\n5\n-2 -3 -1 -2\n-1 -1 -1\n-2 -1\n1\n4\n-4 7 6\n1 3\n-1\n0\n",
"4\n3 3 1\n2 6\n-4\n3\n1 -10\n100\n5\n-2 -3 -2 -2\n-1 -1 -1\n-2 -1\n1\n4\n-4 7 2\n1 3\n-1\n0\n",
"4\n3 3 1\n2 8\n-4\... | [
"7\n11\n-1\n9\n",
"7\n11\n-1\n8\n",
"7\n11\n-1\n6\n",
"7\n",
"8\n",
"17\n",
"8\n11\n-1\n9\n",
"7\n11\n-1\n10\n",
"8\n11\n-1\n8\n",
"7\n-1\n-1\n9\n"
] |
CodeContests | Takahashi is standing on a two-dimensional plane, facing north. Find the minimum positive integer K such that Takahashi will be at the starting position again after he does the following action K times:
* Go one meter in the direction he is facing. Then, turn X degrees counter-clockwise.
Constraints
* 1 \leq X \leq ... | stdin | null | 2,319 | 1 | [
"90\n",
"1\n"
] | [
"4\n",
"360\n"
] | [
"155\n",
"2\n",
"297\n",
"408\n",
"643\n",
"810\n",
"928\n",
"1780\n",
"33\n",
"70\n"
] | [
"72\n",
"180\n",
"40\n",
"15\n",
"360\n",
"4\n",
"45\n",
"18\n",
"120\n",
"36\n"
] |
CodeContests | Problem
Ghosts line up in a straight line from left to right with $ N $ people.
At first, the $ i $ th ghost from the left is facing left if $ U_i $ is'L', and facing right if it is'R'.
They are so timid that I don't want to see scary ghosts as much as possible.
You can instruct each ghost to look back.
It's scary t... | stdin | null | 4,092 | 1 | [
"3 1\nRRL\n5 5 1\n3 1 10\n",
"5 5\nRLRLL\n9 5 1 3 10\n1 3 5\n2 4 9\n4 2 16\n1 5 2\n3 5 10\n"
] | [
"1\n",
"8\n"
] | [
"3 1\nRRL\n5 5 1\n3 1 3\n",
"5 5\nRLRLL\n9 5 1 3 10\n1 3 5\n2 4 9\n4 2 7\n1 5 2\n3 5 10\n",
"5 5\nRLRLL\n9 5 1 3 10\n1 4 5\n2 4 9\n2 2 7\n1 5 2\n3 5 10\n",
"5 5\nRLRLL\n9 5 1 3 6\n1 4 5\n2 4 9\n2 2 7\n1 5 0\n3 5 10\n",
"5 5\nRLRLL\n9 5 1 3 6\n1 4 5\n2 4 9\n2 2 7\n1 5 0\n3 5 0\n",
"5 5\nRLRLL\n9 5 1 3 10\n... | [
"1\n",
"8\n",
"6\n",
"4\n",
"3\n",
"10\n",
"5\n",
"0\n",
"9\n",
"7\n"
] |
CodeContests | Let f(x) represent the number of set bits (i.e. bit = 1) in the binary representation of non-negative integer x.
For e.g. f(3) = 2, since 3 is represented as '11' in binary.
Xenny's friend Xynazog gave him the following task:
Given two non-negative integers A and B, find the sum of f(x) for all x in range [A, B] (A a... | stdin | null | 2,515 | 1 | [
"1\n1 3\n\nSAMPLE\n"
] | [
"4\n"
] | [
"1\n1 1\n\nSAMPLE\n",
"1\n2 1\n\nASMPLE\n",
"1\n4 1\n\nELPMSA\n",
"1\n4 0\n\nELPMSA\n",
"1\n1 3\n\nELPMAS\n",
"1\n1 2\n\nASMPLE\n",
"1\n3 1\n\nASMPLE\n",
"1\n1 4\n\nELPAMT\n",
"1\n3 0\n\nASNPLE\n",
"1\n1 6\n\nELPALT\n"
] | [
"1\n",
"0\n",
"-3\n",
"-4\n",
"4\n",
"2\n",
"-1\n",
"5\n",
"-2\n",
"9\n"
] |
CodeContests | Chef loves games! But he likes to invent his own. Now he plays game "Digit Jump". Chef has sequence of digits S1, S2,..., SN,. He is staying in the first digit (S1) and want to reach the last digit (SN) in the minimal number of jumps.
While staying in some digit x with index i (digit Si) Chef can jump into digits with... | stdin | null | 358 | 1 | [
"01234567890\n",
"012134444444443\n"
] | [
"1\n",
"4\n"
] | [
"1352328136\n",
"20776892991725\n",
"6858574858270\n",
"10353326888495\n",
"2595212919780\n",
"1149262658611\n",
"361054554527\n",
"6\n",
"1404985567\n",
"22244193067\n"
] | [
"3\n",
"2\n",
"5\n",
"4\n",
"6\n",
"1\n",
"7\n",
"0\n",
"8\n",
"9\n"
] |
CodeContests | Ikshu's love for binary numbers
Ikshu recently learnt to generate random numbers. He is generating stream binary numbers. Uptil now he has generated N bits of the binary number. Now, he wants to know if there is a streak of contiguous 1's of length K.
Help him to find the probability of existence of such a streak in ... | stdin | null | 1,078 | 1 | [
"5 1\n\nSAMPLE\n"
] | [
"31/32\n"
] | [
"5 1\n\nS@MPLE\n",
"8 1\n\nSPM@LE\n",
"1 1\n\nSPM@LE\n",
"7 1\n\nSAMPLE\n",
"10 1\n\nSPM@LE\n",
"7 2\n\nSAMPLE\n",
"2 1\n\nSPLALE\n",
"4 1\n\nSPALLE\n",
"10 2\n\nSPM@LE\n",
"3 1\n\nSPALLE\n"
] | [
"31/32\n",
"255/256\n",
"1/2\n",
"127/128\n",
"1023/1024\n",
"47/64\n",
"3/4\n",
"15/16\n",
"55/64\n",
"7/8\n"
] |
CodeContests | Prize
Segtree entered a programming contest with a team of $ N $ and won a $ K $ yen prize! I'm trying to distribute this prize now.
Each $ N $ team member, including Segtree, is numbered from $ 1 $ to $ N $ in order of ability. Segtree is $ 1 $.
If the prize amount of $ i $'s teammate $ (i \ geq 2) $ is less than "... | stdin | null | 949 | 1 | [
"1 1\n"
] | [
"1\n"
] | [
"1 2\n",
"2 1\n",
"1 3\n",
"1 4\n",
"1 6\n",
"2 12\n",
"2 8\n",
"1 9\n",
"3 12\n",
"14 32\n"
] | [
"2\n",
"1\n",
"3\n",
"4\n",
"6\n",
"8\n",
"5\n",
"9\n",
"7\n",
"17\n"
] |
CodeContests | You were caught in a magical trap and transferred to a strange field due to its cause. This field is three- dimensional and has many straight paths of infinite length. With your special ability, you found where you can exit the field, but moving there is not so easy. You can move along the paths easily without your ene... | stdin | null | 2,063 | 1 | [
"2\n0 0 0 0 2 0\n0 0 1 0 0 -1\n2 0 0 0 2 0\n3\n0 5 0 3 1 4\n0 1 0 0 -1 0\n1 0 1 -1 0 1\n3 1 -1 3 1 1\n2\n0 0 0 3 0 0\n0 0 0 0 1 0\n3 0 0 3 1 0\n0\n"
] | [
"1.414\n2.000\n3.000\n"
] | [
"2\n0 0 0 0 2 0\n0 0 1 0 0 -1\n2 0 0 0 2 0\n3\n0 5 0 3 1 4\n0 1 0 0 -1 0\n1 0 1 -1 0 1\n3 1 -1 3 1 1\n2\n0 0 0 3 0 0\n0 -1 0 0 1 0\n3 0 0 3 1 0\n0\n",
"2\n0 0 0 0 2 0\n0 0 1 0 0 -1\n2 0 0 0 2 0\n5\n0 5 0 3 1 4\n0 1 0 0 -1 0\n1 0 1 -1 0 1\n3 1 -1 3 1 1\n2\n0 1 0 3 0 0\n0 -1 0 0 1 0\n3 0 0 3 1 0\n0\n",
"2\n0 0 0 ... | [
"1.414213562\n2.000000000\n3.000000000\n",
"1.414213562\n1.000000000\n",
"1.414213562\n1.447213595\n",
"1.414213562\n2.341640786\n3.000000000\n",
"1.109400392\n2.341640786\n3.000000000\n",
"1.414213562\n2.000000000\n0.000000000\n",
"1.414213562\n1.316227766\n",
"1.414213562\n0.707106781\n",
"0.00000... |
CodeContests | Problem Statement
Sereja has a sequence of n integers a[1], a[2], ..., a[n]. Sereja can do following transformation of the array:
create a new sequence of n integers b[1], b[2], ..., b[n]in this way: (1 ≤ i ≤ n)
Replace the sequence a by b, i.e., a[i] = b[i] for all i in [1, n]
Sereja decided to use his trans... | stdin | null | 3,499 | 1 | [
"3\n1 1 1 1\n2 2 1 1\n2 3 1 1\n"
] | [
"0\n2\n4\n"
] | [
"3\n0 1 1 1\n2 2 1 1\n2 3 1 1\n",
"3\n0 1 1 1\n4 2 1 1\n2 3 1 1\n",
"3\n0 1 1 1\n4 1 1 1\n2 3 1 1\n",
"3\n-1 1 1 0\n4 1 1 1\n2 3 0 1\n",
"3\n-1 1 1 0\n4 1 1 1\n2 3 -1 1\n",
"3\n-1 1 1 0\n4 1 1 2\n2 0 -1 2\n",
"3\n-2 1 1 0\n8 1 0 0\n2 0 -3 2\n",
"3\n-2 1 1 0\n8 2 0 0\n2 0 -3 2\n",
"3\n-2 1 1 -1\n8 2 ... | [
"0\n2\n4\n",
"0\n14\n4\n",
"0\n0\n4\n",
"0\n0\n6\n",
"0\n0\n8\n",
"0\n0\n2\n",
"0\n2\n6\n",
"0\n4\n6\n",
"0\n4\n12\n",
"0\n4\n20\n"
] |
CodeContests | You are on a game show "Who Wants to Be a Millionaire".The host presents you "N" number of closed doors.There is huge prize behind one door while there are sumo wrestlers behind rest of the doors.Initially you are asked to choose a door.After that the host opens (N-2) doors,revealing sumo wrestlers.The host is omniscie... | stdin | null | 1,639 | 1 | [
"1\n3\n\nSAMPLE\n"
] | [
"0.666667\n"
] | [
"444\n793\n255\n144\n906\n931\n102\n101\n301\n341\n340\n308\n524\n678\n587\n405\n718\n733\n466\n145\n13\n27\n717\n714\n899\n911\n121\n602\n864\n882\n876\n761\n886\n640\n697\n44\n29\n288\n938\n525\n331\n160\n940\n50\n445\n67\n65\n188\n735\n524\n600\n408\n836\n939\n949\n89\n967\n433\n921\n958\n78\n779\n446\n107\n127\... | [
"0.998739\n0.996078\n0.993056\n0.998896\n0.998926\n0.990196\n0.990099\n0.996678\n0.997067\n0.997059\n0.996753\n0.998092\n0.998525\n0.998296\n0.997531\n0.998607\n0.998636\n0.997854\n0.993103\n0.923077\n0.962963\n0.998605\n0.998599\n0.998888\n0.998902\n0.991736\n0.998339\n0.998843\n0.998866\n0.998858\n0.998686\n0.998... |
CodeContests | This morning Chef wants to jump a little. In a few minutes he will arrive at the point 0. Then he will perform a lot of jumps in such a sequence: 1-jump, 2-jump, 3-jump, 1-jump, 2-jump, 3-jump, 1-jump, and so on.
1-jump means that if Chef is at the point x, he will jump to the point x+1.
2-jump means that if Chef is a... | stdin | null | 1,995 | 1 | [
"2\n",
"0\n",
"3\n",
"1\n",
"10\n"
] | [
"no\n",
"yes\n",
"yes\n",
"yes\n",
"no\n"
] | [
"4\n",
"-3\n",
"-1\n",
"-2\n",
"5\n",
"-4\n",
"8\n",
"12\n",
"-5\n",
"-6\n"
] | [
"no\n",
"yes\n",
"no\n",
"no\n",
"no\n",
"no\n",
"no\n",
"yes\n",
"yes\n",
"yes\n"
] |
CodeContests | Good evening, contestants.
If a and d are relatively prime positive integers, the arithmetic sequence beginning with a and increasing by d, i.e., a, a + d, a + 2d, a + 3d, a + 4d, ..., contains infinitely many prime numbers. This fact is known as Dirichlet's Theorem on Arithmetic Progressions, which had been conjectur... | stdin | null | 659 | 1 | [
"367 186 151\n179 10 203\n271 37 39\n103 230 1\n27 104 185\n253 50 85\n1 1 1\n9075 337 210\n307 24 79\n331 221 177\n259 170 40\n269 58 102\n0 0 0\n"
] | [
"92809\n6709\n12037\n103\n93523\n14503\n2\n899429\n5107\n412717\n22699\n25673\n"
] | [
"367 186 151\n179 10 203\n271 37 39\n103 230 1\n27 104 185\n253 87 85\n1 1 1\n9075 337 210\n307 24 79\n331 221 177\n259 170 40\n269 58 102\n0 0 0\n",
"367 186 151\n179 10 203\n271 37 39\n103 230 1\n27 104 185\n253 87 85\n1 1 1\n9075 337 210\n307 24 79\n331 221 345\n259 170 40\n269 58 102\n0 0 0\n",
"367 186 151... | [
"92809\n6709\n12037\n103\n93523\n43579\n2\n899429\n5107\n412717\n22699\n25673\n",
"92809\n6709\n12037\n103\n93523\n43579\n2\n899429\n5107\n842341\n22699\n25673\n",
"92809\n6709\n12037\n103\n93523\n43579\n2\n899429\n5107\n842341\n22699\n24919\n",
"92809\n6709\n12037\n103\n93523\n14503\n2\n899429\n5107\n412717\... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.