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
More Unsullied army are joining Daenerys Stormborn of the House Targaryen, the First of Her Name, the Unburnt, Queen of Meereen, Queen of the Andals and the Rhoynar and the First Men, Khaleesi of the Great Grass Sea, Breaker of Chains, and Mother of Dragons. We know Grey Worm is the Commander of Unsullied and needs h...
stdin
null
3,342
1
[ "1\n3\n4\n1 4 7 10\n5\n3 8 12 16 19\n6\n2 6 9 14 18 25\n\nSAMPLE\n" ]
[ "1 2 3 4 6 7 8 9 10 12 14 16 18 19 25\n" ]
[ "5\n3\n746\n101 102 103 106 109 109 109 111 111 111 112 112 113 114 115 117 117 117 119 120 120 120 122 125 126 131 131 131 133 136 136 137 138 139 139 139 140 142 142 144 145 148 148 150 150 150 152 154 156 159 161 165 165 170 172 172 173 174 174 175 176 177 177 178 179 183 183 183 185 186 187 187 188 188 192 193 ...
[ "101 102 103 103 104 106 106 107 108 109 109 109 111 111 111 112 112 112 112 112 113 114 114 115 115 115 115 117 117 117 119 120 120 120 120 121 122 122 124 125 125 126 128 130 131 131 131 133 133 135 135 135 135 136 136 137 137 137 138 139 139 139 139 139 140 141 141 142 142 144 145 148 148 148 149 150 150 150 152...
CodeContests
Jack is the most intelligent student in the class.To boost his intelligence,his class teacher gave him a problem named "Substring Count". Problem : His Class teacher gave him n strings numbered from 1 to n which consists of only lowercase letters (each having length not more than 10) and then ask Q questions related t...
stdin
null
93
1
[ "3\ncode\ncoder\ncoding\n2\n1 3 code\n1 3 co\n\nSAMPLE\n" ]
[ "2 \n3\n" ]
[ "1000\nspnogbxcrp\nbaukbqnmyu\nogxdxhtcwz\nbsjufplykz\nkhicdrdixl\nzookiqggel\nfczygjfhfa\nkobjmuswpw\ndypvhmsjlh\nvbcnnpwmgm\nvzvkarnyqs\ntfssjnurqh\ntbxcluekyt\necnegofqxs\nhbhdeftboc\nqvmotsnevm\nwxzidquite\noqowdpeszj\npnypgzooxk\nuytjntdfmn\nhfltadjbhv\nprzgdcxowz\ncirhknzsrk\ncyfjwvjgmw\nzzkqhtpjwm\nfaklucwdv...
[ "0\n1\n3\n0\n0\n2\n3\n1\n0\n2\n2\n1\n1\n1\n3\n1\n0\n2\n0\n0\n4\n0\n3\n3\n0\n2\n2\n2\n5\n2\n3\n1\n2\n1\n1\n1\n4\n1\n1\n4\n1\n1\n2\n2\n0\n3\n2\n2\n0\n3\n2\n1\n0\n0\n2\n2\n0\n0\n0\n2\n3\n0\n2\n2\n1\n2\n1\n1\n2\n3\n1\n3\n1\n1\n1\n2\n0\n2\n0\n0\n3\n1\n1\n0\n0\n0\n1\n3\n0\n1\n1\n1\n1\n2\n1\n1\n2\n1\n0\n0\n2\n0\n0\n0\n2\n...
CodeContests
AtCoder Inc. has decided to lock the door of its office with a 3-digit PIN code. The company has an N-digit lucky number, S. Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set the PIN code. How many different PIN codes can he set this way? ...
stdin
null
4,148
1
[ "4\n0224\n", "6\n123123\n", "19\n3141592653589793238\n" ]
[ "3\n", "17\n", "329\n" ]
[ "19\n5546189040285140044\n", "19\n4753841743850076999\n", "19\n9039528710159876563\n", "19\n3616863455241776042\n", "19\n2785343766571511696\n", "19\n2922045480066417189\n", "19\n7230040539071200180\n", "19\n1036710694297327965\n", "19\n1455506616048969060\n", "19\n3356521006821128568\n" ]
[ "273\n", "311\n", "412\n", "322\n", "239\n", "281\n", "292\n", "364\n", "172\n", "210\n" ]
CodeContests
Welcome to PC Koshien, players. This year marks the 10th anniversary of Computer Koshien, but the number of questions and the total score will vary from year to year. Scores are set for each question according to the difficulty level. When the number of questions is 10 and the score of each question is given, create a ...
stdin
null
4,943
1
[ "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" ]
[ "55\n" ]
[ "1\n2\n4\n4\n5\n6\n7\n8\n9\n10\n", "1\n2\n8\n4\n5\n6\n7\n8\n9\n10\n", "1\n2\n8\n4\n3\n6\n7\n8\n9\n10\n", "1\n2\n8\n3\n3\n6\n7\n8\n9\n10\n", "1\n2\n8\n3\n3\n6\n7\n5\n9\n10\n", "1\n2\n8\n4\n3\n6\n7\n5\n9\n10\n", "1\n2\n2\n4\n3\n6\n7\n5\n9\n10\n", "1\n2\n2\n4\n3\n6\n7\n5\n12\n10\n", "1\n3\n2\n4\n3\n6\n...
[ "56\n", "60\n", "58\n", "57\n", "54\n", "55\n", "49\n", "52\n", "53\n", "50\n" ]
CodeContests
A robot is put at the origin in a two-dimensional plane. Initially, the robot is facing in the positive x-axis direction. This robot will be given an instruction sequence s. s consists of the following two kinds of letters, and will be executed in order from front to back. * `F` : Move in the current direction by dis...
stdin
null
2,522
1
[ "TF\n1 0\n", "FF\n1 0\n", "FFTTFF\n0 0\n", "FTFFTFFF\n-2 -2\n", "TTTT\n1 0\n" ]
[ "No\n", "No\n", "Yes\n", "Yes\n", "No\n" ]
[ "UF\n1 0\n", "FT\n1 0\n", "FF\n1 -1\n", "FFTTFF\n1 0\n", "FTFFTFFF\n-2 -3\n", "TTTT\n1 -1\n", "FTFFTFFF\n4 0\n", "UF\n1 -1\n", "FF\n0 -1\n", "FFTTFF\n2 0\n" ]
[ "No\n", "Yes\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n" ]
CodeContests
There are N flowers arranged in a row. For each i (1 \leq i \leq N), the height and the beauty of the i-th flower from the left is h_i and a_i, respectively. Here, h_1, h_2, \ldots, h_N are all distinct. Taro is pulling out some flowers so that the following condition is met: * The heights of the remaining flowers ar...
stdin
null
3,757
1
[ "5\n1 2 3 4 5\n1000000000 1000000000 1000000000 1000000000 1000000000\n", "4\n3 1 4 2\n10 20 30 40\n", "1\n1\n10\n", "9\n4 2 5 8 3 6 1 7 9\n6 8 8 4 6 3 5 7 5\n" ]
[ "5000000000\n", "60\n", "10\n", "31\n" ]
[ "5\n1 2 3 4 5\n1000000000 1000000010 1000000000 1000000000 1000000000\n", "4\n3 1 4 2\n10 20 2 40\n", "9\n4 2 5 8 3 6 1 7 9\n6 8 8 4 6 5 5 7 5\n", "5\n1 2 3 4 5\n1000000000 1000000010 1000000000 1010000000 1000000000\n", "9\n4 2 5 8 3 6 1 7 9\n6 8 8 4 6 4 5 7 5\n", "5\n1 2 3 4 5\n1000000000 1000000010 100...
[ "5000000010\n", "60\n", "33\n", "5010000010\n", "32\n", "5010100010\n", "46\n", "65\n", "5020100010\n", "4020100010\n" ]
CodeContests
You have successfully completed your studies and are preparing to move from near Komaba to near Hongo. As I was organizing my house, I found a lot of lottery tickets I bought last year. After confirming the exchange deadline, I have to cash in by tomorrow, but it is troublesome to go to the lottery counter for a small ...
stdin
null
3,649
1
[ "3 3\n*******1 100\n******22 1000\n11111112 1000000\n01203291\n02382022\n11111111\n10 10\n****3228 149416\n****3992 198635\n****4286 77783\n****4843 225244\n***49835 231046\n***59393 379996\n*5763748 437345\n*6726222 58054\n*8117882 16375\n*9244339 537727\n77885716\n96726222\n26971031\n66652868\n89599648\n37772338\...
[ "1200\n438050\n", "1200\n", "438050\n" ]
[ "3 3\n*******1 100\n******22 1000\n11111112 1000100\n01203291\n02382022\n11111111\n", "10 10\n****3228 149416\n****3992 198635\n****4286 77783\n****4843 225244\n***49835 231046\n***59393 379996\n*5763748 437345\n*6726222 58054\n*8117882 16375\n*9244339 537727\n30548855\n96726222\n26971031\n66652868\n89599648\n377...
[ "1200\n", "438050\n", "58054\n", "0\n", "1200\n438050\n", "1000\n", "1002\n", "379996\n", "39119\n", "1020\n" ]
CodeContests
Agon Packers and Movers specialize in moving large number luggages from one place to another. The luggages are packed by the Packers, and after they're done with the job, the Movers take over. First, the Packers put the packages they have packed in a single line, one behind the other, and then the Movers come one by ...
stdin
null
2,950
1
[ "2\n5\n200 25 974 564 429\n\nSAMPLE\n", "2\n4\n5 10 21 20\n" ]
[ "1199\n", "36\n" ]
[ "11\n250\n344 269 950 341 830 539 640 337 759 64 737 250 936 104 886 781 977 124 670 737 802 360 381 953 58 988 199 134 38 520 656 970 514 666 595 871 654 173 292 756 712 503 390 724 656 704 750 11 845 713 7 48 50 819 576 711 935 121 325 873 24 406 724 165 619 440 204 768 990 434 456 568 317 209 588 856 868 889 310...
[ "12278\n", "1199\n", "34\n", "12332\n", "12317\n", "1036\n", "25\n", "1003\n", "1015\n", "1016\n" ]
CodeContests
Once N boys and M girls attended a party. You are given a matrix A of N rows and M columns where Aij is 1 if the i-th boy likes the j-th girl, otherwise it will be 0. Note that it is not necessary that if a boy x likes girl y, then girl y should like boy x. You know that if there are two different boys x and y, who bot...
stdin
null
4,646
1
[ "2\n4 3\n111\n100\n110\n000\n2 2\n10\n01\n" ]
[ "4\n0\n" ]
[ "2\n4 3\n111\n100\n110\n000\n2 1\n10\n01\n", "2\n4 3\n101\n100\n110\n000\n2 1\n10\n01\n", "2\n4 3\n101\n100\n010\n000\n2 1\n10\n01\n", "2\n4 3\n111\n100\n110\n010\n2 2\n10\n01\n", "2\n4 3\n111\n000\n110\n000\n2 1\n10\n01\n", "2\n4 3\n101\n101\n111\n001\n2 1\n10\n01\n", "2\n4 3\n111\n100\n011\n100\n0 1\n...
[ "4\n0\n", "3\n0\n", "1\n0\n", "6\n0\n", "2\n0\n", "9\n0\n", "5\n0\n", "7\n0\n", "8\n0\n", "10\n0\n" ]
CodeContests
** Problem Statement is Updated ** Xenny had N colors with him, all arranged in a straight line. He was interested in picking up a particular subarray of colors. A pre-set is a set that contains all subarrays of colors that start from the first color and do not contain the last color. An end-set is a set that contai...
stdin
null
400
1
[ "1\n4\n1 2 1 2\n\nSAMPLE\n" ]
[ "2\n" ]
[ "1\n4\n1 2 1 2\n\nTAMPLE\n", "1\n0\n1 3 1 2\n\nTAMPLE\n", "1\n0\n1 3 0 3\n\nTAMPLE\n", "1\n-3\n-1 -1 -1 -1\n\nANMDPL\n", "1\n0\n1 2 1 2\n\nTAMPLE\n", "1\n0\n1 3 1 3\n\nTAMPLE\n", "1\n0\n1 3 -1 3\n\nTAMPLE\n", "1\n0\n1 6 -1 3\n\nTAMPLE\n", "1\n0\n1 6 -1 3\n\nTEMPLA\n", "1\n-1\n1 6 -1 3\n\nTEMPLA\n"...
[ "2\n", "1\n", "0\n", "3\n", "2\n", "2\n", "0\n", "0\n", "0\n", "0\n" ]
CodeContests
A rabbit is playing a role-playing game. Just before entering the castle, he was ambushed by an enemy! It was a battle between one hero operated by a rabbit and n enemies. Each character has four stats, health hi, attack power ai, defense power di, and agility si. I = 0 is the information of the main character, 1 ≤ i ...
stdin
null
114
1
[ "1\n1 1 1 1\n10000 10000 10000 10000\n", "2\n10 3 1 2\n2 4 1 3\n2 2 1 1\n" ]
[ "-1\n", "4\n" ]
[ "1\n1 0 1 1\n10000 10000 10000 10000\n", "2\n10 3 1 2\n2 4 1 3\n1 2 1 1\n", "2\n10 3 1 2\n2 4 1 3\n1 3 1 1\n", "2\n10 3 1 2\n3 4 1 3\n1 3 1 1\n", "2\n10 3 2 2\n3 4 1 3\n1 3 1 1\n", "1\n1 0 1 1\n10000 10010 10000 10000\n", "1\n1 0 1 1\n10000 10010 10000 10100\n", "1\n1 0 1 1\n10000 10010 10000 10101\n"...
[ "-1\n", "4\n", "5\n", "9\n", "6\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n" ]
CodeContests
Snuke has two boards, each divided into a grid with N rows and N columns. For both of these boards, the square at the i-th row from the top and the j-th column from the left is called Square (i,j). There is a lowercase English letter written in each square on the first board. The letter written in Square (i,j) is S_{i...
stdin
null
1,090
1
[ "2\nab\nca\n", "5\nabcde\nfghij\nklmno\npqrst\nuvwxy\n", "4\naaaa\naaaa\naaaa\naaaa\n" ]
[ "2\n", "0\n", "16\n" ]
[ "2\nab\nda\n", "5\nabcde\nfghij\nklmno\npqrst\nuvvxy\n", "4\naaaa\naaaa\naaaa\nbaaa\n", "2\nab\nad\n", "5\nabcde\nfghij\nonmlk\npqrst\nuvwxy\n", "4\nbaaa\naaaa\naaaa\nbaaa\n", "2\nab\nac\n", "5\nedcba\nfghij\nonmlk\npqrst\nuvwxy\n", "4\nbaaa\naaa`\naaaa\nbaaa\n", "2\nba\nca\n" ]
[ "2\n", "0\n", "4\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n" ]
CodeContests
AtCoDeer the deer has found two positive integers, a and b. Determine whether the concatenation of a and b in this order is a square number. Constraints * 1 ≤ a,b ≤ 100 * a and b are integers. Input Input is given from Standard Input in the following format: a b Output If the concatenation of a and b in this o...
stdin
null
2,645
1
[ "1 21\n", "12 10\n", "100 100\n" ]
[ "Yes\n", "No\n", "No\n" ]
[ "2 21\n", "000 001\n", "5 10\n", "110 100\n", "2 22\n", "7 10\n", "101 100\n", "4 22\n", "7 16\n", "101 101\n" ]
[ "No\n", "Yes\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n" ]
CodeContests
Let w be a string consisting of lowercase letters. We will call w beautiful if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful. Constraints * 1 \leq |w| \leq 100 * w consists of lowercas...
stdin
null
1,410
1
[ "abaccaba\n", "hthth\n" ]
[ "Yes\n", "No\n" ]
[ "ab`ccaba\n", "ab`cc`ba\n", "hthtg\n", "hghtt\n", "`b`cc`ba\n", "hgtth\n", "ab`cc`b`\n", "hgtuh\n", "`b`cc`ca\n", "hgsth\n" ]
[ "No\n", "Yes\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n" ]
CodeContests
Edward Leven loves multiples of eleven very much. When he sees a number, he always tries to find consecutive subsequences (or substrings) forming multiples of eleven. He calls such subsequences as 11-sequences. For example, he can find an 11-sequence 781 in a number 17819. He thinks a number which has many 11-sequence...
stdin
null
3,210
1
[ "17819\n1111\n11011\n1234567891011121314151617181920\n0\n" ]
[ "1\n4\n4\n38\n" ]
[ "17819\n1011\n11011\n1234567891011121314151617181920\n0\n", "17819\n1010\n11011\n1234567891011121314151617181920\n0\n", "17819\n1011\n11011\n1300831114838731654212402340246\n0\n", "17819\n1010\n01011\n1234567891011121314151617181920\n0\n", "17819\n1010\n11011\n1300831114838731654212402340246\n0\n", "17819...
[ "1\n1\n4\n38\n", "1\n0\n4\n38\n", "1\n1\n4\n32\n", "1\n0\n1\n38\n", "1\n0\n4\n32\n", "1\n0\n1\n32\n", "1\n0\n2\n32\n", "1\n4\n4\n38\n", "1\n0\n4\n39\n", "1\n1\n1\n32\n" ]
CodeContests
Dr. Tsuruga of the University of Aizu is famous for his enthusiastic research. There are several students in his lab, but he works late into the night every day, so he always comes home last. His lab has multiple rooms connected by doors, and the last person to leave the lab is supposed to turn off the lights in all th...
stdin
null
1,895
1
[ "4 3\n1 2\n2 3\n2 4\n1 0 0 0\n2 2 3\n0\n3 1 2 4\n2 2 3\n4 3\n1 2\n2 3\n2 4\n1 0 0 0\n2 2 3\n0\n3 1 2 4\n1 3\n4 3\n1 2\n2 3\n2 4\n1 0 0 0\n2 2 3\n0\n2 1 2\n2 2 3\n0 0\n" ]
[ "You can go home in 10 steps.\nSwitch on room 2.\nSwitch on room 3.\nMove to room 2.\nMove to room 3.\nSwitch off room 1.\nSwitch on room 4.\nMove to room 2.\nMove to room 4.\nSwitch off room 2.\nSwitch off room 3.\nYou can not switch off all lights.\nHelp me!\n" ]
[ "4 3\n1 2\n1 3\n2 4\n1 0 0 0\n2 2 3\n0\n3 1 2 4\n2 2 3\n4 3\n1 2\n2 3\n2 4\n1 0 0 0\n2 2 3\n0\n3 1 2 4\n1 3\n4 3\n1 2\n2 3\n2 4\n1 0 0 0\n2 2 3\n0\n2 1 2\n2 2 3\n0 0\n", "4 3\n1 2\n1 3\n2 4\n1 0 0 0\n2 2 3\n0\n3 1 2 4\n2 2 3\n4 3\n1 2\n2 3\n2 2\n1 0 0 0\n2 2 3\n0\n3 1 2 4\n1 3\n4 3\n1 2\n2 3\n2 4\n1 0 0 0\n2 2 3\...
[ "You can not switch off all lights.\nYou can not switch off all lights.\nHelp me!\n", "You can not switch off all lights.\nHelp me!\nHelp me!\n", "You can go home in 10 steps.\nSwitch on room 2.\nSwitch on room 3.\nMove to room 2.\nMove to room 3.\nSwitch off room 1.\nSwitch on room 4.\nMove to room 2.\nMove to...
CodeContests
An autumn sports festival is held. There are four events: foot race, ball-carrying, obstacle race, and relay. There are n teams participating, and we would like to commend the team with the shortest total time in this 4th event as the "winner", the next smallest team as the "runner-up", and the second team from the bot...
stdin
null
3,882
1
[ "8\n34001 3 20 3 8 6 27 2 25\n20941 3 5 2 41 7 19 2 42\n90585 4 8 3 12 6 46 2 34\n92201 3 28 2 47 6 37 2 58\n10001 3 50 2 42 7 12 2 54\n63812 4 11 3 11 6 53 2 22\n54092 3 33 2 54 6 18 2 19\n25012 3 44 2 58 6 45 2 46\n4\n1 3 23 1 23 1 34 4 44\n2 5 12 2 12 3 41 2 29\n3 5 24 1 24 2 0 3 35\n4 4 49 2 22 4 41 4 23\n0\n" ...
[ "54092\n34001\n10001\n1\n3\n2\n" ]
[ "8\n34001 3 20 3 8 6 27 2 25\n20941 3 5 2 41 7 19 2 42\n90585 4 8 3 12 6 46 2 34\n92201 3 28 2 47 6 37 2 58\n10001 3 50 2 42 7 12 2 54\n63812 4 11 3 11 6 98 2 22\n54092 3 33 2 54 6 18 2 19\n25012 3 44 2 58 6 45 2 46\n4\n1 3 23 1 23 1 34 4 44\n2 5 12 2 12 3 41 2 29\n3 5 24 1 24 2 0 3 35\n4 4 49 2 22 4 41 4 23\n0\n",...
[ "54092\n34001\n90585\n1\n3\n2\n", "54092\n34001\n63812\n1\n3\n2\n", "20941\n54092\n63812\n1\n3\n2\n", "20941\n54092\n25012\n1\n3\n2\n", "54092\n65541\n63812\n1\n3\n2\n", "54092\n34001\n10001\n1\n3\n2\n", "54092\n65541\n10001\n1\n3\n2\n", "54092\n34001\n20941\n1\n3\n2\n", "65541\n54092\n10001\n1\n3\n...
CodeContests
Snuke has a string S consisting of three kinds of letters: `a`, `b` and `c`. He has a phobia for palindromes, and wants to permute the characters in S so that S will not contain a palindrome of length 2 or more as a substring. Determine whether this is possible. Constraints * 1 \leq |S| \leq 10^5 * S consists of `a`...
stdin
null
179
1
[ "aba\n", "abac\n", "babacccabab\n" ]
[ "NO\n", "YES\n", "YES\n" ]
[ "acac\n", "bacaccbabab\n", "ccaa\n", "bacaacbcbab\n", "babcbcaacab\n", "bababccacab\n", "bacaccbabac\n", "bacaccbaaac\n", "caaabccacab\n", "caaaaccacab\n" ]
[ "NO\n", "YES\n", "NO\n", "YES\n", "YES\n", "YES\n", "YES\n", "NO\n", "NO\n", "NO\n" ]
CodeContests
H --Bit Operation Game Given a rooted tree with N vertices. The vertices are numbered from 0 to N − 1, and the 0th vertex represents the root. `T = 0` for the root, but for the other vertices * `T = T & X;` * `T = T & Y;` * `T = T | X` * `T = T | Y` * `T = T ^ X` * `T = T ^ Y` One of the operations is written. Her...
stdin
null
2,620
1
[ "6 3\nT=T|X\nT=T|Y\nT=T|Y\nT=T^Y\nT=T&X\n0 1\n0 2\n1 3\n1 4\n2 5\n5 6\n3 5\n0 0\n" ]
[ "4\n6\n0\n" ]
[ "6 6\nT=T|X\nT=T|Y\nT=T|Y\nT=T^Y\nT=T&X\n0 1\n0 2\n1 3\n1 4\n2 5\n5 6\n3 5\n0 0\n", "6 6\nT=T|X\nT=T|Y\nT=T|Y\nT=T^Y\nT=T&X\n0 1\n0 2\n1 3\n1 4\n2 5\n9 6\n3 5\n0 0\n", "6 6\nT=T|X\nT=T|Y\nT=T|Y\nT=T^Y\nT=T&X\n0 1\n0 2\n1 3\n1 4\n2 5\n5 6\n3 5\n1 0\n", "6 6\nT=T|X\nT=T|Y\nT=T|Y\nT=T^Y\nT=T&X\n0 1\n0 2\n1 3\n1 ...
[ "4\n6\n0\n0\n0\n0\n", "15\n6\n0\n0\n0\n0\n", "4\n6\n1\n1\n1\n1\n", "6\n5\n1\n1\n1\n1\n", "5\n5\n1\n1\n1\n1\n", "5\n5\n1\n1\n1\n", "4\n11\n0\n", "4\n5\n0\n0\n0\n0\n", "15\n10\n0\n0\n0\n0\n", "3\n3\n1\n1\n1\n1\n" ]
CodeContests
An bydrocarbon is an organic compound which contains only carbons and hydrogens. An isomer is a compound that has the same number of carbons but different structures. Heptane, for example, is a hydrocarbon with 7 carbons. It has nine isomers. The structural formula of three are shown in Figure 1. Carbons are represente...
stdin
null
4,471
1
[ "1\n4\n" ]
[ "1\n8\n" ]
[ "1\n6\n", "1\n8\n", "1\n12\n", "1\n16\n", "1\n1\n", "1\n13\n", "1\n25\n", "1\n5\n", "1\n2\n", "1\n3\n" ]
[ "1\n26\n", "1\n80\n", "1\n728\n", "1\n6560\n", "1\n1\n", "1\n1457\n", "1\n1062881\n", "1\n17\n", "1\n2\n", "1\n5\n" ]
CodeContests
Puchi hates to carry luggage, but unfortunately he got a job to carry the luggage of his N friends in office. Each day, one of his N friends, gives him the luggage of a particular weight to carry. You will be given the weight of luggage of each friend in the array Weight, where Weighti is the weight of luggage of i^th...
stdin
null
1,919
1
[ "1\n4\n2\n1\n4\n3\n\nSAMPLE\n" ]
[ "1 0 1 0\n" ]
[ "30\n384\n887\n2778\n6916\n7794\n8336\n5387\n493\n6650\n1422\n2363\n28\n8691\n60\n7764\n3927\n541\n3427\n9173\n5737\n5212\n5369\n2568\n6430\n5783\n1531\n2863\n5124\n4068\n3136\n3930\n9803\n4023\n3059\n3070\n8168\n1394\n8457\n5012\n8043\n6230\n7374\n4422\n4920\n3785\n8538\n5199\n4325\n8316\n4371\n6414\n3527\n6092\n8...
[ "29 90 248 287 310 181 15 236 44 75 2 321 2 278 132 14 110 331 189 167 170 78 217 189 46 84 159 131 95 126 346 127 93 93 276 39 286 149 266 199 237 131 146 114 282 150 126 272 127 197 106 184 294 330 51 208 294 211 220 65 25 210 188 9 193 23 44 33 167 177 111 299 13 269 91 145 9 111 101 23 188 199 194 156 96 137 69...
CodeContests
There are 2N balls in the xy-plane. The coordinates of the i-th of them is (x_i, y_i). Here, x_i and y_i are integers between 1 and N (inclusive) for all i, and no two balls occupy the same coordinates. In order to collect these balls, Snuke prepared 2N robots, N of type A and N of type B. Then, he placed the type-A r...
stdin
null
2,168
1
[ "4\n1 1\n2 2\n3 3\n4 4\n1 2\n2 1\n3 4\n4 3\n", "8\n6 2\n5 1\n6 8\n7 8\n6 5\n5 7\n4 3\n1 4\n7 6\n8 3\n2 8\n3 6\n3 2\n8 5\n1 5\n5 8\n", "2\n1 1\n1 2\n2 1\n2 2\n", "3\n1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n", "4\n3 2\n1 2\n4 1\n4 2\n2 2\n4 4\n2 1\n1 3\n" ]
[ "4480\n", "82060779\n", "8\n", "0\n", "7392\n" ]
[ "8\n6 2\n5 1\n6 8\n7 8\n6 5\n5 7\n2 3\n1 4\n7 6\n8 3\n2 8\n3 6\n3 2\n8 5\n1 5\n5 8\n", "4\n1 1\n4 2\n3 3\n4 4\n1 2\n2 1\n3 4\n4 3\n", "8\n6 2\n5 1\n6 8\n7 8\n6 5\n5 7\n4 3\n1 4\n7 6\n8 3\n2 8\n3 6\n3 2\n4 5\n1 5\n5 8\n", "3\n1 1\n1 2\n1 0\n2 1\n2 2\n2 3\n", "3\n1 1\n1 2\n2 1\n2 0\n1 3\n4 3\n", "2\n1 1\n1 ...
[ "0\n", "840\n", "582448612\n", "90\n", "120\n", "0\n", "0\n", "0\n", "0\n", "0\n" ]
CodeContests
Lira is now very keen on compiler development. :) She knows that one of the most important components of a compiler, is its parser. A parser is, in simple terms, a software component that processes text, and checks it's semantic correctness, or, if you prefer, if the text is properly built. As an example, in declaring...
stdin
null
4,996
1
[ "3\n<<>>\n><\n<>>>\n" ]
[ "4\n0\n2\n" ]
[ "3\n<<>>\n<>\n<>>>\n", "3\n><<>\n<>\n<>>>\n", "3\n><<>\n><\n<>>>\n", "3\n<<>>\n><\n<>>?\n", "3\n><<>\n<>\n><>?\n", "3\n><<>\n><\n>><>\n", "3\n<<>>\n<>\n>>><\n", "3\n<<>>\n><\n>>><\n", "3\n<>><\n<>\n>>><\n", "3\n<>><\n<>\n<>>?\n" ]
[ "4\n2\n2\n", "0\n2\n2\n", "0\n0\n2\n", "4\n0\n2\n", "0\n2\n0\n", "0\n0\n0\n", "4\n2\n0\n", "4\n0\n0\n", "2\n2\n0\n", "2\n2\n2\n" ]
CodeContests
Today Oz wants to play with Lucky strings. A string S is called Lucky string if there exists a non-negative integer m such that S is composed of m consecutive 'R' characters followed by m consecutive 'K' characters. Empty string is also a Lucky string i.e for m=0 Now Oz has a string STR. Each character of STR is either...
stdin
null
2,197
1
[ "2\nKRKRKKR\nKKKRRR\n\nSAMPLE\n" ]
[ "4\n0\n" ]
[ "2\nKRKRKKR\nKKKRRR\n\nSAMPLD\n", "2\nRRKRKKK\nKKKRRR\n\nSAMPLD\n", "2\nKRKRKKR\nRRRKKK\n\nSAMPLD\n", "2\nRRKRKKK\nRRRKKK\n\nSAMPLD\n", "2\nKKKRRKR\nKKKRRR\n\nSMAPLD\n", "2\nRKRRKKK\nKKRKRR\n\nDLPAMS\n", "2\nKKKRRKR\nRRRKKK\n\nDLPMAR\n", "2\nKKKRRKR\nRKKRKR\n\nDLPMAS\n", "2\nKKRRKRK\nKKRKRR\n\nCLPAM...
[ "4\n0\n", "6\n0\n", "4\n6\n", "6\n6\n", "2\n0\n", "6\n2\n", "2\n6\n", "2\n2\n", "4\n2\n", "6\n4\n" ]
CodeContests
G: 検閲により置換 (Censored String) Problem Statement You are given the string S, and the set of strings \mathcal P whose size is N. Now we consider applying the following operation to S: * Choose exactly one character in S, and replace it with '*'. Let s_i be a i-th character of S, S_{ij} be a consecutive substring in ...
stdin
null
1,186
1
[ "brainfuck\n1\nfuck\n" ]
[ "1\n" ]
[ "brainfuck\n0\nfuck\n", "brainfudk\n0\nfuck\n", "brainfudk\n0\nfucl\n", "kdufniarb\n0\nfucl\n", "kdufniarb\n0\nfvcl\n", "kdufniarb\n1\nfvcl\n", "kdufniarb\n1\nlcvf\n", "kdufniarb\n1\nclvf\n", "brainfudk\n1\nclvf\n", "brainfudk\n1\nfvlc\n" ]
[ "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n" ]
CodeContests
Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either ...
stdin
null
4,111
1
[ "1 100 2 10\n", "100 10 1 2\n", "10 10 10 1\n", "4 7 9 3\n" ]
[ "Yes\n", "No\n", "Yes\n", "Yes\n" ]
[ "1 000 2 10\n", "100 10 0 2\n", "4 7 2 3\n", "1 000 1 10\n", "100 10 0 4\n", "4 5 2 3\n", "0 000 1 10\n", "000 10 0 4\n", "0 000 1 15\n", "0 000 0 15\n" ]
[ "Yes\n", "No\n", "Yes\n", "Yes\n", "No\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n" ]
CodeContests
There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roa...
stdin
null
1,767
1
[ "4 2\n1 3\n2 3\n", "2 1\n3 2\n4 3\n", "3 2\n2 4\n1 2\n" ]
[ "YES\n", "YES\n", "NO\n" ]
[ "4 3\n1 3\n2 3\n", "1 1\n3 2\n4 3\n", "1 2\n3 2\n4 3\n", "1 2\n2 2\n4 3\n", "3 2\n2 4\n1 4\n", "1 1\n3 2\n4 1\n", "1 4\n2 2\n4 3\n", "3 2\n3 4\n1 4\n", "2 1\n3 2\n4 1\n", "4 2\n1 3\n3 3\n" ]
[ "NO\n", "YES\n", "YES\n", "NO\n", "YES\n", "NO\n", "YES\n", "YES\n", "YES\n", "NO\n" ]
CodeContests
It is said that a legendary treasure left by Mr. Yao is sleeping somewhere in Hachioji long ago. The treasure map, which is said to show its whereabouts, has been handed down by Yao's n descendants, divided into several pieces. Now, the descendants of Mr. Yao were trying to cooperate to obtain the treasure. However, t...
stdin
null
4,475
1
[ "4\n1 1\n2 2 3\n2 1 2\n3 3 4 5\n0\n" ]
[ "3\n" ]
[ "4\n1 1\n2 2 3\n2 1 2\n3 4 4 5\n0\n", "4\n1 1\n2 2 3\n2 1 2\n3 3 4 10\n0\n", "4\n1 1\n2 2 5\n2 0 2\n3 1 4 5\n0\n", "4\n1 1\n2 2 3\n2 1 2\n3 1 4 5\n0\n", "4\n1 1\n2 1 3\n2 0 1\n3 1 4 5\n0\n", "4\n1 1\n2 2 3\n2 0 4\n3 1 4 2\n0\n", "4\n1 1\n2 2 3\n2 1 2\n3 4 4 0\n0\n", "4\n1 1\n2 2 3\n2 2 2\n3 3 4 5\n0\n...
[ "-1\n", "3\n", "5\n", "2\n", "1\n", "4\n", "-1\n", "-1\n", "-1\n", "-1\n" ]
CodeContests
We have a grid with H rows and W columns of squares. Snuke is painting these squares in colors 1, 2, ..., N. Here, the following conditions should be satisfied: * For each i (1 ≤ i ≤ N), there are exactly a_i squares painted in Color i. Here, a_1 + a_2 + ... + a_N = H W. * For each i (1 ≤ i ≤ N), the squares painted i...
stdin
null
1,327
1
[ "1 1\n1\n1\n", "3 5\n5\n1 2 3 4 5\n", "2 2\n3\n2 1 1\n" ]
[ "1\n", "1 4 4 4 3\n2 5 4 5 3\n2 5 5 5 3\n", "1 1\n2 3\n" ]
[ "2 2\n2\n3 1 1\n", "2 1\n1\n2\n", "1 2\n1\n2\n", "2 2\n3\n1 1 2\n", "3 5\n5\n1 2 5 4 3\n", "1 4\n2\n3 1 0\n", "2 2\n3\n1 2 1\n", "2 2\n2\n2 2 1\n", "1 4\n3\n2 2 0\n", "3 5\n5\n1 2 6 4 2\n" ]
[ "1 1\n2 1\n", "1\n1\n", "1 1\n", "1 2\n3 3\n", "1 2 2 3 3\n4 4 3 3 3\n4 4 5 5 5\n", "1 1 1 2\n", "1 2\n3 2\n", "1 1\n2 2\n", "1 1 2 2\n", "1 2 2 3 3\n4 3 3 3 3\n4 4 4 5 5\n" ]
CodeContests
Problem Taro hides important books in the school locker, so he manages them more strictly than other people, and in addition to the keys provided by the school, he has installed the following button authentication type keys. .. <image> However, Taro, who easily forgets his password, has a habit of making it possible...
stdin
null
3,011
1
[ "ABCFI\nABCABCABC\nAEI\nEFC\n(中略)\nDEHED\nEEEEE\n(以上でちょうど1000個)\n" ]
[ "ABCFI\nEFC\n(中略)\nDEHED\n" ]
[ "ABCFI\nABCABCACC\nAEI\nEFC\n(中略)\nDEHED\nEEEEE\n(以上でちょうど1000個)\n", "ABCFI\nABCACCACC\nAEI\nEFC\n(中略)\nDEHEC\nEEEEE\n(以上でちょうど1000個)\n", "ABCFJ\nABCACCACC\nAEI\nEFC\n(中略)\nDEHEC\nEEEEE\n(以上でちょうど1000個)\n", "ABCFJ\nABBACACCC\nAEI\nCFE\n(中畦)\nDEHEC\nEEEEE\n(以上でちょうど1000個)\n", "IFCBA\nABCACCACC\nAEI\nEFC\n(中略)\nD...
[ "ABCFI\nEFC\nDEHED\n", "ABCFI\nEFC\n", "EFC\n", "CFE\n", "IFCBA\nEFC\n", "ABCFI\n", "ABCFI\nCFE\nDEHED\n", "IFCBA\n", "CFE\nEDEFE\n", "ABCFI\nCFE\n" ]
CodeContests
There are N squares in a row, numbered 1 through N from left to right. Snuke and Rng are playing a board game using these squares, described below: 1. First, Snuke writes an integer into each square. 2. Each of the two players possesses one piece. Snuke places his piece onto square 1, and Rng places his onto square 2....
stdin
null
2,054
1
[ "9\n2 0 1 6 1 1 2 6\n5\n2016\n1\n1\n2\n6\n", "5\n2 7 1 8\n1\n2\n" ]
[ "2001\n6\n6\n7\n7\n", "0\n" ]
[ "9\n2 0 1 6 1 1 2 6\n5\n2016\n2\n1\n2\n6\n", "5\n2 7 1 12\n1\n2\n", "9\n2 0 1 6 1 1 2 2\n5\n2016\n2\n1\n2\n6\n", "5\n2 7 2 12\n1\n2\n", "9\n2 0 1 6 1 1 4 2\n5\n2016\n2\n1\n2\n6\n", "5\n2 7 2 12\n1\n0\n", "9\n2 0 2 6 1 1 4 2\n5\n2016\n2\n1\n2\n6\n", "5\n3 7 2 12\n1\n0\n", "9\n2 0 2 6 1 1 4 2\n2\n2016...
[ "2001\n7\n6\n7\n7\n", "4\n", "2005\n7\n6\n7\n7\n", "3\n", "2003\n5\n6\n5\n7\n", "5\n", "2002\n4\n5\n4\n6\n", "6\n", "2002\n4\n", "9\n" ]
CodeContests
AtCoDeer has three cards, one red, one green and one blue. An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card. We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer. Is this integer...
stdin
null
536
1
[ "4 3 2\n", "2 3 4\n" ]
[ "YES\n", "NO\n" ]
[ "7 3 2\n", "2 3 3\n", "7 3 0\n", "2 6 3\n", "7 6 0\n", "2 6 0\n", "9 6 0\n", "0 6 0\n", "5 6 0\n", "0 1 0\n" ]
[ "YES\n", "NO\n", "NO\n", "NO\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "NO\n" ]
CodeContests
For an integer N, we will choose a permutation \\{P_1, P_2, ..., P_N\\} of \\{1, 2, ..., N\\}. Then, for each i=1,2,...,N, let M_i be the remainder when i is divided by P_i. Find the maximum possible value of M_1 + M_2 + \cdots + M_N. Constraints * N is an integer satisfying 1 \leq N \leq 10^9. Input Input is giv...
stdin
null
1,925
1
[ "13\n", "2\n", "1\n" ]
[ "78\n", "1\n", "0\n" ]
[ "21\n", "3\n", "4\n", "30\n", "6\n", "0\n", "-1\n", "8\n", "-4\n", "9\n" ]
[ "210\n", "3\n", "6\n", "435\n", "15\n", "0\n", "1\n", "28\n", "10\n", "36\n" ]
CodeContests
Ayimok is a wizard. His daily task is to arrange magical tiles in a line, and then cast a magic spell. Magical tiles and their arrangement follow the rules below: * Each magical tile has the shape of a trapezoid with a height of 1. * Some magical tiles may overlap with other magical tiles. * Magical tiles are arrang...
stdin
null
1,262
1
[ "3\n26 29 9 12\n6 10 15 16\n8 17 18 19\n" ]
[ "1\n" ]
[ "3\n26 17 9 12\n6 10 15 16\n8 17 18 19\n", "3\n26 29 9 12\n6 10 15 16\n11 17 18 19\n", "3\n26 29 11 12\n6 10 15 16\n8 17 18 19\n", "3\n26 17 9 12\n6 10 27 16\n8 17 18 19\n", "3\n26 29 1 12\n6 10 15 16\n8 17 18 19\n", "3\n26 24 9 12\n6 10 27 16\n8 17 18 19\n", "3\n26 29 1 12\n6 10 15 16\n8 17 18 28\n", ...
[ "1\n", "2\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n" ]
CodeContests
Taru likes reading. Every month he gets a copy of the magazine "BIT". The magazine contains information about the latest advancements in technology. Taru reads the book at night and writes the page number to which he has read on a piece of paper so that he can continue from there the next day. But sometimes the pa...
stdin
null
4,018
1
[ "2\n10\n2 1 2\n2\n10\n1 8\n0\n" ]
[ "31.2000\n47.0000\n" ]
[ "2\n10\n2 1 2\n2\n10\n1 3\n0\n", "2\n4\n2 1 2\n2\n10\n1 3\n0\n", "2\n4\n2 1 2\n2\n10\n1 3\n1\n", "2\n4\n2 1 2\n2\n10\n1 4\n1\n", "2\n4\n2 1 2\n2\n10\n1 1\n1\n", "2\n10\n2 2 2\n2\n10\n1 8\n0\n", "2\n10\n2 1 2\n2\n3\n1 3\n0\n", "2\n4\n2 1 2\n2\n10\n1 6\n1\n", "2\n10\n2 2 2\n2\n3\n1 3\n0\n", "2\n4\n2...
[ "31.2000\n52.0000\n", "0.0000\n52.0000\n", "0.0000\n41.6000\n", "0.0000\n40.8000\n", "0.0000\n43.2000\n", "30.6000\n47.0000\n", "31.2000\n3.0000\n", "0.0000\n39.2000\n", "30.6000\n3.0000\n", "0.0000\n35.2000\n" ]
CodeContests
A rabbit Taro decided to hold a party and invite some friends as guests. He has n rabbit friends, and m pairs of rabbits are also friends with each other. Friendliness of each pair is expressed with a positive integer. If two rabbits are not friends, their friendliness is assumed to be 0. When a rabbit is invited to t...
stdin
null
2,495
1
[ "3 3\n1 2 3\n2 3 1\n3 1 2\n", "2 1\n1 2 5\n", "4 5\n1 2 4\n1 3 3\n2 3 7\n2 4 5\n3 4 6\n", "1 0\n" ]
[ "6\n", "10\n", "16\n", "0\n" ]
[ "3 3\n1 4 3\n2 3 1\n3 1 2\n", "2 2\n1 2 5\n", "4 5\n1 2 4\n1 3 3\n2 3 7\n2 4 3\n3 4 6\n", "2 0\n", "4 2\n1 2 10\n", "4 5\n2 2 6\n1 3 3\n2 2 7\n2 4 4\n3 4 6\n", "3 4\n1 2 3\n4 5 0\n3 1 2\n", "4 5\n2 2 0\n1 3 6\n2 1 8\n2 4 5\n3 6 5\n", "7 7\n1 1 2\n14 5 0\n6 1 1\n", "4 5\n1 2 4\n1 3 3\n2 3 13\n2 4 5...
[ "4\n", "10\n", "14\n", "0\n", "20\n", "12\n", "6\n", "16\n", "2\n", "26\n" ]
CodeContests
You are given a string S consisting of lowercase English letters. Another string T is initially empty. Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times: * Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`. Constrain...
stdin
null
3,600
1
[ "dreamerer\n", "erasedream\n", "dreameraser\n" ]
[ "NO\n", "YES\n", "YES\n" ]
[ "dre`merer\n", "maerdesare\n", "resaremaerd\n", "dre`meqer\n", "er`sedream\n", "ersaremaerd\n", "reqem`erd\n", "eq`sedream\n", "ersaremadrd\n", "reqem`erc\n" ]
[ "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n" ]
CodeContests
There are N men and N women, both numbered 1, 2, \ldots, N. For each i, j (1 \leq i, j \leq N), the compatibility of Man i and Woman j is given as an integer a_{i, j}. If a_{i, j} = 1, Man i and Woman j are compatible; if a_{i, j} = 0, they are not. Taro is trying to make N pairs, each consisting of a man and a woman...
stdin
null
3,273
1
[ "1\n0\n", "4\n0 1 0 0\n0 0 0 1\n1 0 0 0\n0 0 1 0\n", "21\n0 0 0 0 0 0 0 1 1 0 1 1 1 1 0 0 0 1 0 0 1\n1 1 1 0 0 1 0 0 0 1 0 0 0 0 1 1 1 0 1 1 0\n0 0 1 1 1 1 0 1 1 0 0 1 0 0 1 1 0 0 0 1 1\n0 1 1 0 1 1 0 1 0 1 0 0 1 0 0 0 0 0 1 1 0\n1 1 0 0 1 0 1 0 0 1 1 1 1 0 0 0 0 0 0 0 0\n0 1 1 0 1 1 1 0 1 1 1 0 0 0 1 1 1 1 0 0...
[ "0\n", "1\n", "102515160\n", "3\n" ]
[ "1\n1\n", "21\n0 0 0 0 0 0 0 1 1 0 1 1 1 1 0 0 0 1 0 0 1\n1 1 1 0 1 1 0 0 0 1 0 0 0 0 1 1 1 0 1 1 0\n0 0 1 1 1 1 0 1 1 0 0 1 0 0 1 1 0 0 0 1 1\n0 1 1 0 1 1 0 1 0 1 0 0 1 0 0 0 0 0 1 1 0\n1 1 0 0 1 0 1 0 0 1 1 1 1 0 0 0 0 0 0 0 0\n0 1 1 0 1 1 1 0 1 1 1 0 0 0 1 1 1 1 0 0 1\n0 1 0 0 0 1 0 1 0 0 0 1 1 1 0 0 1 1 0 1 0...
[ "1\n", "781575588\n", "0\n", "416994021\n", "2\n", "252921664\n", "166021817\n", "869947220\n", "670448225\n", "394114653\n" ]
CodeContests
Write a program which computes the area of a shape represented by the following three lines: $y = x^2$ $y = 0$ $x = 600$ It is clear that the area is $72000000$, if you use an integral you learn in high school. On the other hand, we can obtain an approximative area of the shape by adding up areas of many rectangles...
stdin
null
2,608
1
[ "20\n10\n" ]
[ "68440000\n70210000\n" ]
[ "20\n15\n", "20\n4\n", "20\n8\n", "20\n2\n", "20\n6\n", "20\n1\n", "20\n-1\n", "20\n3\n", "20\n5\n", "20\n24\n" ]
[ "68440000\n69322500\n", "68440000\n71281600\n", "68440000\n70566400\n", "68440000\n71640400\n", "68440000\n70923600\n", "68440000\n71820100\n", "68440000\n0\n", "68440000\n71460900\n", "68440000\n71102500\n", "68440000\n67737600\n" ]
CodeContests
After many years of research, Ikta has acquired the ability to predict the future! The time and money he spent on this research was enormous, but it's finally time to be rewarded. To get the money back, Ikta decided to start investing in stocks. Ikta does not currently own any shares, but owns x yen. He has invested i...
stdin
null
1,341
1
[ "1 2 5\n6\n10000\n", "2 3 5\n4 5\n6 3\n8 5\n", "3 3 10\n10 9 6\n8 7 3\n7 5 1\n", "2 2 5\n3 2\n5 4\n" ]
[ "5\n", "11\n", "10\n", "9\n" ]
[ "3 3 10\n10 9 6\n14 7 3\n7 5 1\n", "3 3 10\n10 8 13\n14 3 4\n5 5 1\n", "3 3 10\n10 8 13\n14 3 4\n5 4 1\n", "1 2 5\n4\n10000\n", "2 3 5\n4 5\n6 3\n8 6\n", "2 2 6\n3 2\n5 4\n", "3 3 10\n10 9 6\n11 7 3\n7 5 1\n", "3 3 10\n10 4 6\n14 7 3\n7 5 1\n", "3 3 10\n10 8 11\n1 7 3\n7 5 1\n", "3 3 1\n10 8 13\n1...
[ "14\n", "22\n", "18\n", "10001\n", "13\n", "12\n", "11\n", "16\n", "70\n", "1\n" ]
CodeContests
As of now, you helped agent OO7 to find men with different capability values. Now his task is to group up his men and work as a team. He wants to form the groups with minimum 2 men in it. Help him out to find how many such groups are possible. Input - First line contains 'T' test cases followed by 'T' lines containing ...
stdin
null
3,464
1
[ "2\n4\n6\n\nSAMPLE\n" ]
[ "2\n4\n" ]
[ "20\n32\n174\n29\n64\n32\n15\n25\n72\n61\n21\n69\n79\n194\n8\n37\n197\n4\n25\n174\n78\n", "2\n4\n6\n\nSAMPLD\n", "20\n32\n174\n29\n64\n32\n15\n25\n72\n61\n21\n69\n79\n194\n8\n63\n197\n4\n25\n174\n78\n", "2\n4\n10\n\nSAMPLD\n", "20\n32\n174\n29\n64\n32\n17\n25\n72\n61\n21\n69\n79\n194\n8\n63\n197\n4\n25\n174...
[ "1507\n34798214855\n847\n236131\n1507\n41\n383\n695578\n155038\n165\n466610\n1716486\n197395636376\n7\n3660\n254258890939\n2\n383\n34798214855\n1512301\n", "2\n4\n", "1507\n34798214855\n847\n236131\n1507\n41\n383\n695578\n155038\n165\n466610\n1716486\n197395636376\n7\n205343\n254258890939\n2\n383\n34798214855\n...
CodeContests
Problem : Bajirao is on a date with his girlfriend Avni. It is a romantic night and they are playing a game of words. The rule of this game is that if Bajirao says a word such that no adjacent letters occurring in the word are same then he gets a kiss from her otherwise he gets a slap. Input : The first line consi...
stdin
null
718
1
[ "2\nremember\noccurring\n\nSAMPLE\n" ]
[ "KISS\nSLAP\n" ]
[ "2\nremember\noccurring\n\nELPMAS\n", "2\nrmeenber\noccurrhng\n\nSAMPMD\n", "2\nrfrnfemc\nvohtrcgcn\n\nLDPMAS\n", "2\nqfrefmmc\nnohsrcgdv\n\nSCLPEN\n", "2\nremenber\noccurring\n\nELPMAS\n", "2\nremenber\noccurring\n\nSAMPLE\n", "2\nremenber\noccurrhng\n\nSAMPLE\n", "2\nremenber\noccurrhng\n\nSAMPLD\n"...
[ "KISS\nSLAP\n", "SLAP\nSLAP\n", "KISS\nKISS\n", "SLAP\nKISS\n", "KISS\nSLAP\n", "KISS\nSLAP\n", "KISS\nSLAP\n", "KISS\nSLAP\n", "KISS\nSLAP\n", "SLAP\nSLAP\n" ]
CodeContests
problem In one programming contest, it is customary to play a bingo game at a social gathering after the competition. However, the bingo card used in this bingo game is a little special and is created according to the following conditions. * The Bingo card is divided into squares of N rows and N columns, and one posi...
stdin
null
5,060
1
[ "3 9 45\n3 100 50\n5 50 685\n0 0 0\n" ]
[ "1\n7\n74501\n" ]
[ "3 9 45\n3 100 50\n5 50 308\n0 0 0\n", "3 12 45\n3 100 75\n5 50 308\n0 0 0\n", "3 12 45\n3 100 69\n5 50 308\n0 0 0\n", "3 12 45\n3 100 69\n5 90 548\n0 0 0\n", "3 12 45\n3 100 50\n5 50 331\n0 0 0\n", "3 3 45\n3 100 69\n5 50 308\n0 0 0\n", "3 12 60\n3 100 69\n5 90 308\n0 0 0\n", "3 3 45\n3 100 85\n5 50 ...
[ "1\n7\n0\n", "1\n3060\n0\n", "1\n1076\n0\n", "1\n1076\n3141\n", "1\n7\n11\n", "0\n1076\n0\n", "15\n1076\n0\n", "0\n13338\n0\n", "1\n0\n11\n", "15\n0\n0\n" ]
CodeContests
problem There are $ V $ islands, numbered $ 0, 1, ..., V-1 $, respectively. There are $ E $ bridges, numbered $ 0, 1, ..., E-1 $, respectively. The $ i $ th bridge spans island $ s_i $ and island $ t_i $ and is $ c_i $ wide. The AOR Ika-chan Corps (commonly known as the Squid Corps), which has a base on the island $ ...
stdin
null
313
1
[ "4 4\n0 1 3\n0 2 4\n1 3 1\n2 3 5\n" ]
[ "4\n" ]
[ "4 4\n0 1 3\n0 2 4\n1 3 1\n0 3 5\n", "4 8\n0 1 6\n0 2 4\n1 3 1\n0 3 5\n", "4 4\n0 1 3\n0 2 0\n1 3 1\n2 3 5\n", "2 15\n0 1 0\n0 1 4\n2 3 0\n0 3 9\n", "5 8\n0 1 6\n0 0 4\n2 3 4\n1 4 5\n", "2 15\n0 1 0\n0 1 4\n2 3 0\n0 1 9\n", "2 15\n0 1 0\n0 2 4\n2 1 0\n0 1 9\n", "4 9\n0 2 6\n1 2 4\n1 3 2\n0 3 5\n", "...
[ "5\n", "25\n", "0\n", "4\n", "6\n", "112\n", "108\n", "32\n", "15\n", "11\n" ]
CodeContests
We have a 2 \times N grid. We will denote the square at the i-th row and j-th column (1 \leq i \leq 2, 1 \leq j \leq N) as (i, j). You are initially in the top-left square, (1, 1). You will travel to the bottom-right square, (2, N), by repeatedly moving right or down. The square (i, j) contains A_{i, j} candies. You ...
stdin
null
613
1
[ "7\n3 3 4 5 4 5 3\n5 3 4 4 2 3 2\n", "1\n2\n3\n", "5\n3 2 2 4 1\n1 2 2 2 1\n", "4\n1 1 1 1\n1 1 1 1\n" ]
[ "29\n", "5\n", "14\n", "5\n" ]
[ "7\n3 3 4 5 4 5 3\n5 3 8 4 2 3 2\n", "1\n2\n6\n", "5\n3 2 2 4 1\n0 2 2 2 1\n", "4\n1 1 0 1\n1 1 1 1\n", "7\n3 3 4 5 4 5 3\n5 3 8 4 2 5 2\n", "4\n1 1 0 1\n1 1 0 1\n", "7\n3 3 4 5 4 5 3\n5 3 8 4 0 5 2\n", "1\n2\n7\n", "5\n3 2 0 4 1\n0 2 1 2 1\n", "7\n3 3 4 5 4 5 3\n5 3 15 4 0 5 2\n" ]
[ "30\n", "8\n", "14\n", "5\n", "32\n", "4\n", "31\n", "9\n", "12\n", "37\n" ]
CodeContests
This is a story of a world somewhere far from the earth. In this world, the land is parted into a number of countries ruled by empires. This world is not very peaceful: they have been involved in army race. They are competing in production of missiles in particular. Nevertheless, no countries have started wars for yea...
stdin
null
3,610
1
[ "3 3\n3 4 1 1\n2 1 5\n2 3 3\n3 3\n3 2 3 1\n2 1 5\n2 3 3\n0 0\n" ]
[ "Yes\nNo\n" ]
[ "3 3\n3 8 1 1\n2 1 5\n2 3 3\n3 3\n3 2 3 1\n2 1 5\n2 3 3\n0 0\n", "3 6\n3 8 1 1\n2 1 5\n2 3 3\n3 3\n3 2 5 1\n2 1 8\n2 3 3\n0 0\n", "3 3\n3 4 1 1\n2 1 5\n2 3 3\n3 6\n3 2 5 1\n2 1 5\n2 3 3\n0 0\n", "3 3\n3 8 1 1\n2 1 6\n2 3 3\n3 3\n3 2 3 1\n2 2 5\n2 2 3\n0 0\n", "3 3\n3 8 1 1\n2 1 5\n2 3 3\n3 3\n3 2 5 1\n2 1 5...
[ "No\nNo\n", "Yes\nNo\n", "Yes\nYes\n", "No\nYes\n", "No\nNo\n", "No\nNo\n", "No\nNo\n", "No\nNo\n", "Yes\nNo\n", "Yes\nNo\n" ]
CodeContests
Monk visits Biksy, the largest trading market in the land. Biksy has traders from all over the world. There are a total of N items indexed from 1 to N, that are traded in the market by a total of M dealers. Each trader is characterized by three integers, say i, j, C , meaning that the trader will take i'th item from yo...
stdin
null
1,158
1
[ "2\n5 6\n1 2 2\n2 3 -1\n3 4 -7\n4 5 0\n2 3 -7\n3 5 6\n5 8\n1 5 10\n2 3 -6\n5 2 5\n4 5 9\n1 5 1\n2 4 -10\n2 3 -2\n4 1 1\n\nSAMPLE\n" ]
[ "No\nYes\n" ]
[ "2\n5 6\n1 2 2\n2 3 -1\n3 0 -7\n4 5 0\n2 3 -7\n3 5 6\n5 8\n1 5 10\n2 3 -6\n5 2 5\n4 5 9\n1 5 1\n2 4 -10\n2 3 -2\n4 1 1\n\nSAMPLE\n", "2\n5 6\n1 2 2\n2 3 -1\n3 0 -7\n4 5 0\n2 3 -2\n3 5 6\n5 8\n1 5 10\n2 0 -6\n5 2 5\n4 5 9\n1 5 1\n1 4 -10\n2 3 -2\n4 1 1\n\nSAMPLE\n", "2\n1 1\n1 1 4\n4 6\n1 3 -3\n2 3 1\n4 4 -5\n2 ...
[ "No\nYes\n", "No\nNo\n", "Yes\nNo\n", "Yes\nYes\n", "No\nYes\n", "No\nYes\n", "No\nYes\n", "No\nYes\n", "No\nYes\n", "No\nNo\n" ]
CodeContests
I decided to plant vegetables in the vegetable garden. There were n seeds, so I sown n seeds one by one a day over n days. All seeds sprout and grow quickly. I can't wait for the harvest time. One day, when I was watering the seedlings as usual, I noticed something strange. There should be n vegetable seedlings, but o...
stdin
null
3,962
1
[ "5\n1 2 3 6 4 5\n6\n1 3 6 9 12 15 18\n4\n5 7 9 11 12\n0\n" ]
[ "6\n1\n12\n" ]
[ "5\n1 2 3 6 4 5\n6\n1 3 6 9 12 15 18\n4\n5 7 9 11 6\n0\n", "5\n1 2 3 2 4 5\n6\n1 3 6 9 12 15 18\n4\n5 7 9 11 6\n0\n", "5\n1 2 3 2 4 5\n6\n1 3 6 9 12 15 18\n4\n5 7 9 11 7\n0\n", "5\n1 2 3 6 4 5\n6\n1 3 6 9 12 15 18\n4\n5 7 9 11 8\n0\n", "5\n1 2 3 6 4 5\n6\n1 3 6 9 12 15 18\n4\n5 7 9 11 5\n0\n", "5\n1 2 3 1...
[ "6\n1\n6\n", "2\n1\n6\n", "2\n1\n7\n", "6\n1\n8\n", "6\n1\n5\n", "11\n1\n12\n", "9\n1\n6\n", "14\n1\n12\n", "2\n1\n5\n", "25\n1\n12\n" ]
CodeContests
Watson gives to Sherlock a bag of numbers [1, 2, 3 ... N] and then he removes K numbers A1, A2 ... AK from the bag. He now asks Sherlock to find the P'th smallest number in the bag. Input First line contains T, the number of test cases. Each test case consists of N, K and P followed by K integers in next line denoting...
stdin
null
642
1
[ "2\n4 1 2\n1\n5 2 4\n1 3\n\nSAMPLE\n" ]
[ "3\n-1\n" ]
[ "2\n4 1 2\n1\n5 2 4\n1 3\n\nMASPLE\n", "2\n4 1 1\n1\n5 2 4\n1 4\n\nMASQEL\n", "2\n4 1 2\n1\n5 2 0\n1 4\n\nQELSAM\n", "2\n4 1 2\n1\n8 2 4\n1 3\n\nMASPLE\n", "2\n4 1 0\n1\n5 2 4\n1 3\n\nMASQLE\n", "2\n4 1 0\n1\n8 2 4\n1 3\n\nMASQLE\n", "2\n4 1 -1\n1\n9 2 4\n1 3\n\nELPSAM\n", "2\n4 1 0\n1\n8 2 4\n1 6\n\n...
[ "3\n-1\n", "2\n-1\n", "3\n0\n", "3\n6\n", "0\n-1\n", "0\n6\n", "-1\n6\n", "0\n5\n", "-1\n0\n", "1\n-1\n" ]
CodeContests
Do you remember the game of Snakes and Ladders ? We have removed all the snakes from the board. However to compensate for the loss of trouble, we have enlarged the board from a maximum limit (Target Square) of 100 to a maximum limit (Target Square) of N ≥ 100, N being a perfect square. Rani has a match with Nandu on t...
stdin
null
2,835
1
[]
[]
[ "1\n11025 64\n297 345\n3266 10057\n5366 9583\n1815 5123\n1255 1449\n315 1580\n160 513\n2557 3726\n452 4632\n560 3339\n6643 9342\n2591 5273\n1473 5777\n826 10203\n1572 3833\n101 323\n2311 5011\n2124 5492\n6325 6700\n7925 9037\n5995 6129\n1157 3090\n463 3925\n2823 5693\n7447 10803\n10770 10822\n2843 6756\n5929 10030\...
[ "58\n", "61\n", "54\n", "67\n", "66\n", "42\n", "33\n", "53\n", "48\n", "41\n" ]
CodeContests
PCK Taxi in Aizu city, owned by PCK company, has adopted a unique billing system: the user can decide the taxi fare. Today as usual, many people are waiting in a queue at the taxi stand in front of the station. In front of the station, there are $N$ parking spaces in row for PCK taxis, each with an index running from ...
stdin
null
978
1
[ "3\n3 8 10 1\n4 7 1 2 15\n3 11 8 19\n" ]
[ "45\n" ]
[ "3\n3 8 10 1\n4 7 1 4 15\n3 11 8 19\n", "3\n3 8 10 0\n2 7 1 4 15\n3 11 8 19\n", "3\n3 8 10 0\n4 7 2 4 4\n3 11 8 19\n", "3\n3 2 10 1\n4 7 2 4 15\n3 11 13 19\n", "3\n3 8 9 0\n2 7 1 4 15\n2 11 1 19\n", "3\n3 8 5 1\n2 6 1 4 15\n3 11 8 15\n", "3\n6 8 10 1\n4 7 0 1 15\n3 11 8 38\n", "3\n3 8 10 0\n4 0 1 4 15...
[ "45\n", "36\n", "40\n", "47\n", "35\n", "34\n", "64\n", "32\n", "37\n", "39\n" ]
CodeContests
Given an integer N, Chef wants to find the smallest positive integer M such that the bitwise XOR of M and M+1 is N. If no such M exists output -1. Input The first line of input contain an integer T denoting the number of test cases. Each of the following T lines contains an integer N for that test case. Output For ea...
stdin
null
2,387
1
[ "1\n3\n" ]
[ "1\n" ]
[ "1\n1\n", "1\n2\n", "1\n7\n", "1\n15\n", "1\n31\n", "1\n63\n", "1\n127\n", "1\n6\n", "1\n4\n", "1\n8\n" ]
[ "2\n", "-1\n", "3\n", "7\n", "15\n", "31\n", "63\n", "-1\n", "-1\n", "-1\n" ]
CodeContests
There is a sequence of length N: a = (a_1, a_2, ..., a_N). Here, each a_i is a non-negative integer. Snuke can repeatedly perform the following operation: * Let the XOR of all the elements in a be x. Select an integer i (1 ≤ i ≤ N) and replace a_i with x. Snuke's objective is to match a with another sequence b = (...
stdin
null
497
1
[ "3\n0 1 2\n3 1 0\n", "4\n0 1 2 3\n1 0 3 2\n", "3\n0 1 2\n0 1 2\n", "2\n1 1\n0 0\n" ]
[ "2\n", "5\n", "0\n", "-1\n" ]
[ "3\n0 1 2\n3 1 1\n", "3\n0 0 1\n1 0 0\n", "3\n1 -3 1\n-3 -3 1\n", "4\n0 1 2 3\n1 0 3 4\n", "3\n0 2 2\n0 1 2\n", "2\n1 1\n-1 0\n", "3\n0 1 2\n3 0 0\n", "4\n0 1 2 0\n1 0 3 4\n", "3\n0 2 4\n0 1 2\n", "2\n2 1\n-1 0\n" ]
[ "-1\n", "2\n", "1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n" ]
CodeContests
problem JOI, who came to Australia for a trip, enjoyed sightseeing in various places and finally returned to Japan. Now, JOI is in the town with the international airport where the return flight departs. The town is divided into north, south, east and west, and each section has roads, souvenir shops, houses, and an in...
stdin
null
4,982
1
[ "5 4 2\n...#\n.#.#\n.#73\n8##.\n....\n" ]
[ "11\n" ]
[ "5 4 2\n...#\n.#/#\n.#73\n8##.\n....\n", "5 4 2\n.#-.\n.#.$\n37#.\n8##.\n....\n", "5 4 0\n.#-.\n.#.$\n.#73\n8##.\n....\n", "5 4 1\n.#,.\n.#.$\n.#73\n9##.\n....\n", "5 4 0\n.#-.\n.#.$\n37#.\n.##8\n....\n", "5 4 1\n..,#\n#..$\n38#.\n8##.\n....\n", "5 4 2\n.#..\n.#.$\n.#74\n8##.\n....\n", "5 4 1\n..,#\n#...
[ "11\n", "18\n", "8\n", "9\n", "3\n", "19\n", "12\n", "20\n", "7\n", "0\n" ]
CodeContests
There is a rectangular area containing n × m cells. Two cells are marked with "2", and another two with "3". Some cells are occupied by obstacles. You should connect the two "2"s and also the two "3"s with non-intersecting lines. Lines can run only vertically or horizontally connecting centers of cells without obstacle...
stdin
null
858
1
[ "5 5\n0 0 0 0 0\n0 0 0 3 0\n2 0 2 0 0\n1 0 1 1 1\n0 0 0 0 3\n2 3\n2 2 0\n0 3 3\n6 5\n2 0 0 0 0\n0 3 0 0 0\n0 0 0 0 0\n1 1 1 0 0\n0 0 0 0 0\n0 0 2 3 0\n5 9\n0 0 0 0 0 0 0 0 0\n0 0 0 0 3 0 0 0 0\n0 2 0 0 0 0 0 2 0\n0 0 0 0 3 0 0 0 0\n0 0 0 0 0 0 0 0 0\n9 9\n3 0 0 0 0 0 0 0 2\n0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0\n0 0...
[ "18\n2\n17\n12\n0\n52\n43\n" ]
[ "5 5\n0 0 0 0 0\n0 0 0 3 0\n2 0 2 0 0\n1 0 1 1 1\n0 0 0 0 3\n2 3\n2 2 0\n0 3 3\n6 5\n2 0 0 0 0\n0 3 0 0 0\n0 0 0 0 0\n1 1 1 0 0\n0 0 0 0 0\n0 0 2 3 0\n5 9\n0 0 0 0 0 0 0 0 0\n0 0 0 0 3 0 0 0 0\n0 2 0 0 0 0 0 2 0\n0 0 0 0 3 0 0 0 0\n0 0 0 0 0 0 0 0 0\n9 9\n3 0 0 0 0 0 0 0 2\n0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0\n0 0...
[ "18\n2\n17\n12\n0\n52\n43\n", "18\n0\n17\n12\n0\n52\n43\n", "18\n2\n17\n12\n0\n0\n43\n", "18\n0\n17\n12\n0\n0\n43\n", "18\n0\n17\n12\n0\n54\n43\n", "18\n2\n17\n12\n0\n54\n43\n", "18\n2\n17\n12\n0\n44\n43\n", "18\n2\n0\n12\n0\n54\n43\n", "0\n2\n0\n12\n0\n54\n43\n", "18\n2\n17\n12\n0\n34\n43\n" ]
CodeContests
The beauty of a sequence a of length n is defined as a_1 \oplus \cdots \oplus a_n, where \oplus denotes the bitwise exclusive or (XOR). You are given a sequence A of length N. Snuke will insert zero or more partitions in A to divide it into some number of non-empty contiguous subsequences. There are 2^{N-1} possible ...
stdin
null
4,071
1
[ "32\n0 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 0 0 0 0\n", "3\n1 2 2\n", "3\n1 2 3\n", "24\n1 2 5 3 3 6 1 1 8 8 0 3 3 4 6 6 4 0 7 2 5 4 6 2\n" ]
[ "147483634\n", "1\n", "3\n", "292\n" ]
[ "32\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0\n", "24\n1 2 5 3 3 6 1 1 15 8 0 3 3 4 6 6 4 0 7 2 5 4 6 2\n", "3\n2 2 0\n", "24\n1 2 5 3 3 6 1 2 15 8 0 3 3 4 6 6 4 0 7 2 5 4 6 2\n", "24\n1 4 5 3 3 6 1 2 15 8 0 3 3 4 6 6 4 0 7 2 5 4 6 2\n", "24\n1 4 5 3 3 6 2 2 15 8 0 3 3 4 6 6 1 0 7 2...
[ "1\n", "6\n", "3\n", "31\n", "19\n", "5\n", "2\n", "33554438\n", "9\n", "268435465\n" ]
CodeContests
For a finite set of integers X, let f(X)=\max X - \min X. Given are N integers A_1,...,A_N. We will choose K of them and let S be the set of the integers chosen. If we distinguish elements with different indices even when their values are the same, there are {}_N C_K ways to make this choice. Find the sum of f(S) ove...
stdin
null
3,511
1
[ "3 1\n1 1 1\n", "4 2\n1 1 3 4\n", "10 6\n1000000000 1000000000 1000000000 1000000000 1000000000 0 0 0 0 0\n", "6 3\n10 10 10 -10 -10 -10\n" ]
[ "0\n", "11\n", "999998537\n", "360\n" ]
[ "3 1\n1 1 2\n", "4 2\n1 1 2 4\n", "10 5\n1000000000 1000000000 1000000000 1000000000 1000000000 0 0 0 0 0\n", "6 4\n10 10 10 -10 -10 -10\n", "4 2\n1 1 1 4\n", "6 4\n10 10 10 -10 -10 -13\n", "6 4\n10 10 10 -10 -10 0\n", "6 4\n10 10 10 -10 -10 -1\n", "6 4\n10 4 10 -10 -10 -1\n", "6 4\n10 4 10 -9 -10...
[ "0\n", "10\n", "999998257\n", "300\n", "9\n", "330\n", "290\n", "291\n", "285\n", "281\n" ]
CodeContests
Math teacher Mr. Matsudaira is teaching expansion and factoring of polynomials to his students. Last week he instructed the students to write two polynomials (with a single variable x), and to report GCM (greatest common measure) of them as a homework, but he found it boring to check their answers manually. So you are ...
stdin
null
2,893
1
[ "-(x^3-3x^2+3x-1)\n(x-1)^2\nx^2+10x+25\nx^2+6x+5\nx^3+1\nx-1\n.\n" ]
[ "x^2-2x+1\nx+5\n1\n" ]
[ "-(x^3-3x^2+3x-1)\n(x-1)^2\nx^2+10x+25\nx^2+6x+5\nx^4+1\nx-1\n.\n", "-(x^4-3x^2+3x-1)\n(x-1)^2\nx^2+10x+25\nx^2+6x+5\nx^3+1\nx-1\n.\n", "-(x^3-3x^2+3x-1)\n(x-1)^2\nx^2+10x+15\nx^2+6x+5\nx^4+1\nx-1\n.\n", "-(x^3-2x^2+3x-1)\n(x-1)^2\nx^2+10x+25\nx^2+6x+5\n1^4+x\nx-2\n.\n", "-(x^3-3x^2+3x-1)\n(x-1)^3\nx^2+10x+...
[ "x^2-2x+1\nx+5\n1\n", "x-1\nx+5\n1\n", "x^2-2x+1\n1\n1\n", "1\nx+5\n1\n", "x^3-3x^2+3x-1\n1\n1\n", "1\n1\n1\n", "x^3-3x^2+3x-1\nx+5\n1\n", "x-1\n1\n1\n", "x^2-2x+1\nx+5\n1\n", "x^2-2x+1\nx+5\n1\n" ]
CodeContests
Find bridges of an undirected graph G(V, E). A bridge (also known as a cut-edge) is an edge whose deletion increase the number of connected components. Constraints * 1 ≤ |V| ≤ 100,000 * 0 ≤ |E| ≤ 100,000 * The graph is connected * There are no parallel edges * There are no self-loops Input |V| |E| s0 t0 s1 t1 : s...
stdin
null
2,583
1
[ "5 4\n0 1\n1 2\n2 3\n3 4\n", "4 4\n0 1\n0 2\n1 2\n2 3\n" ]
[ "0 1\n1 2\n2 3\n3 4\n", "2 3\n" ]
[ "5 4\n0 1\n1 2\n1 3\n3 4\n", "4 4\n0 1\n0 2\n1 2\n2 4\n", "4 4\n0 1\n1 2\n1 2\n2 4\n", "4 3\n0 1\n1 2\n1 2\n2 4\n", "4 3\n0 1\n1 4\n1 2\n2 4\n", "5 4\n0 1\n1 3\n2 3\n3 4\n", "4 2\n0 1\n0 2\n1 2\n2 3\n", "2 4\n0 1\n0 2\n1 2\n2 3\n", "2 4\n0 1\n1 2\n1 2\n2 3\n", "3 1\n0 1\n1 2\n1 2\n2 4\n" ]
[ "0 1\n1 2\n1 3\n3 4\n", "2 4\n", "0 1\n1 2\n2 4\n", "0 1\n1 2\n", "0 1\n1 2\n1 4\n", "0 1\n1 3\n2 3\n3 4\n", "0 1\n0 2\n", "2 3\n", "0 1\n1 2\n2 3\n", "0 1\n" ]
CodeContests
A dam construction project was designed around an area called Black Force. The area is surrounded by mountains and its rugged terrain is said to be very suitable for constructing a dam. However, the project is now almost pushed into cancellation by a strong protest campaign started by the local residents. Your task is...
stdin
null
2,737
1
[ "4 4 1 1\n2 2 2 2\n2 1 1 2\n2 1 1 2\n2 1 2 2\n1 1\n4 4 1 1\n2 2 2 2\n2 1 1 2\n2 1 1 2\n2 1 2 2\n2 2\n4 4 1 1\n2 2 2 2\n2 1 1 2\n2 1 1 2\n2 1 1 2\n1 1\n3 6 6 1\n1 6 7 1 7 1\n5 1 2 8 1 6\n1 4 3 1 5 1\n1 4\n5 6 21 1\n1 3 3 3 3 1\n3 1 1 1 1 3\n3 1 1 3 2 2\n3 1 1 1 1 3\n1 3 3 3 3 1\n3 4\n0 0 0 0\n" ]
[ "Yes\nNo\nNo\nNo\nYes\n" ]
[ "4 4 1 1\n2 2 2 2\n2 1 1 2\n2 1 0 2\n2 1 2 2\n1 1\n4 4 1 1\n2 2 2 2\n2 1 1 2\n2 1 1 2\n2 1 2 2\n2 2\n4 4 1 1\n2 2 2 2\n2 1 1 2\n2 1 1 2\n2 1 1 2\n1 1\n3 6 6 1\n1 6 7 1 7 1\n5 1 2 8 1 6\n1 4 3 1 5 1\n1 4\n5 6 21 1\n1 3 3 3 3 1\n3 1 1 1 1 3\n3 1 1 3 2 2\n3 1 1 1 1 3\n1 3 3 3 3 1\n3 4\n0 0 0 0\n", "4 4 1 1\n2 2 2 2\...
[ "Yes\nNo\nNo\nNo\nYes\n", "Yes\nYes\nNo\nNo\nYes\n", "Yes\nYes\nYes\nNo\nYes\n", "Yes\nNo\nNo\nNo\nNo\n", "Yes\nYes\nNo\nNo\nNo\n", "Yes\nYes\nYes\nNo\nNo\n", "Yes\nNo\nNo\nYes\nNo\n", "Yes\nNo\nNo\nYes\nYes\n", "No\nNo\nNo\nNo\nYes\n", "Yes\nNo\nYes\nNo\nYes\n" ]
CodeContests
For given a sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$, print the previous permutation and the next permutation in lexicographic order. Constraints * $1 \leq n \leq 9$ * $a_i$ consist of $1, 2, ..., n$ Input A sequence is given in the following format. $n$ $a_0 \; a_1 \; ... \; a_{n-1}$ Output Print the previ...
stdin
null
3,456
1
[ "3\n3 2 1\n", "3\n2 1 3\n" ]
[ "3 1 2\n3 2 1\n", "1 3 2\n2 1 3\n2 3 1\n" ]
[ "3\n3 3 1\n", "3\n3 1 3\n", "3\n3 3 2\n", "3\n6 1 3\n", "3\n3 5 2\n", "3\n11 1 3\n", "3\n0 5 2\n", "3\n11 1 4\n", "3\n0 10 2\n", "3\n6 1 4\n" ]
[ "3 1 3\n3 3 1\n", "1 3 3\n3 1 3\n3 3 1\n", "3 2 3\n3 3 2\n", "3 6 1\n6 1 3\n6 3 1\n", "3 2 5\n3 5 2\n5 2 3\n", "3 11 1\n11 1 3\n11 3 1\n", "0 2 5\n0 5 2\n2 0 5\n", "4 11 1\n11 1 4\n11 4 1\n", "0 2 10\n0 10 2\n2 0 10\n", "4 6 1\n6 1 4\n6 4 1\n" ]
CodeContests
Sigma and Sugim are playing a game. The game is played on a graph with N vertices numbered 1 through N. The graph has N-1 red edges and N-1 blue edges, and the N-1 edges in each color forms a tree. The red edges are represented by pairs of integers (a_i, b_i), and the blue edges are represented by pairs of integers (c...
stdin
null
3,439
1
[ "4 1 2\n1 2\n3 4\n2 4\n1 2\n3 4\n1 3\n", "5 1 2\n1 2\n1 3\n1 4\n4 5\n2 1\n1 3\n1 5\n5 4\n", "3 3 1\n1 2\n2 3\n1 2\n2 3\n", "4 1 2\n1 2\n1 3\n1 4\n2 1\n2 3\n1 4\n", "4 2 1\n1 2\n3 4\n2 4\n1 2\n3 4\n1 3\n" ]
[ "2\n", "6\n", "4\n", "4\n", "-1\n" ]
[ "4 1 2\n1 4\n3 4\n2 4\n1 2\n3 4\n1 3\n", "4 2 1\n1 4\n3 4\n4 4\n1 2\n3 4\n1 3\n", "4 2 1\n1 2\n3 6\n2 4\n1 2\n2 4\n1 3\n", "4 2 1\n1 4\n3 1\n4 4\n2 2\n3 4\n1 3\n", "5 1 2\n1 2\n1 3\n1 4\n6 5\n2 1\n1 3\n1 5\n5 4\n", "4 2 1\n1 4\n3 4\n2 4\n1 2\n3 4\n1 3\n", "4 2 1\n1 4\n3 4\n2 4\n1 2\n2 4\n1 3\n", "4 2 ...
[ "-1\n", "2\n", "4\n", "0\n", "6\n", "-1\n", "-1\n", "-1\n", "2\n", "2\n" ]
CodeContests
Poornimites are taught to add multi-digit numbers from right-to-left one digit at a time. Many find the "carry" operation - in which 1 is carried from one digit position to be added to the next - to be a significant challenge. Your job is to count the number of carry operations for each of addition problem so that edu...
stdin
null
4,332
1
[ "3\n123 456\n555 555\n123 594\n\nSAMPLE\n" ]
[ "No carry operation\n3 carry operations\n1 carry operation\n" ]
[ "3\n123 355\n555 555\n123 594\n\nSAMPLE\n", "3\n123 355\n555 555\n123 412\n\nSAMPLD\n", "3\n123 355\n550 555\n123 594\n\nSAMPLE\n", "3\n123 484\n555 555\n123 594\n", "3\n233 355\n550 555\n216 594\n\nSAMPLE\n", "3\n233 355\n550 242\n123 594\n\nSAMPLE\n", "3\n225 355\n555 708\n123 594\n\nSAMPLD\n", "3\n...
[ "No carry operation\n3 carry operations\n1 carry operation\n", "No carry operation\n3 carry operations\nNo carry operation\n", "No carry operation\n2 carry operations\n1 carry operation\n", "1 carry operation\n3 carry operations\n1 carry operation\n", "No carry operation\n2 carry operations\n2 carry operati...
CodeContests
We have N locked treasure boxes, numbered 1 to N. A shop sells M keys. The i-th key is sold for a_i yen (the currency of Japan), and it can unlock b_i of the boxes: Box c_{i1}, c_{i2}, ..., c_{i{b_i}}. Each key purchased can be used any number of times. Find the minimum cost required to unlock all the treasure boxes....
stdin
null
4,031
1
[ "4 6\n67786 3\n1 3 4\n3497 1\n2\n44908 3\n2 3 4\n2156 3\n2 3 4\n26230 1\n2\n86918 1\n3\n", "12 1\n100000 1\n2\n", "2 3\n10 1\n1\n15 1\n2\n30 2\n1 2\n" ]
[ "69942\n", "-1\n", "25\n" ]
[ "4 0\n67786 3\n1 3 4\n3497 1\n2\n44908 3\n2 3 4\n2156 3\n2 3 4\n26230 1\n2\n86918 1\n3\n", "2 3\n10 1\n1\n15 1\n2\n29 2\n1 2\n", "2 3\n10 1\n1\n28 1\n2\n30 2\n1 2\n", "0 0\n25124 5\n0 6 9\n6178 0\n0\n10169 0\n1 -1 4\n2156 3\n2 3 7\n26230 1\n2\n14402 1\n3\n", "4 6\n67786 3\n1 3 4\n3497 1\n2\n44908 3\n2 3 4\n...
[ "-1\n", "25\n", "30\n", "0\n", "69942\n", "21\n", "-1\n", "-1\n", "-1\n", "-1\n" ]
CodeContests
Aizu is famous for its buckwheat. There are many people who make buckwheat noodles by themselves. One day, you went shopping to buy buckwheat flour. You can visit three shops, A, B and C. The amount in a bag and its unit price for each shop is determined by the follows table. Note that it is discounted when you buy bu...
stdin
null
1,018
1
[ "500\n2200\n0\n" ]
[ "850\n3390\n" ]
[ "500\n1000\n0\n", "500\n0000\n0\n", "500\n1100\n0\n", "500\n0000\n1\n", "500\n0000\n2\n", "500\n0000\n-1\n", "500\n0000\n4\n", "500\n0000\n8\n", "500\n0000\n-2\n", "500\n0000\n3\n" ]
[ "850\n1520\n", "850\n", "850\n1950\n", "850\n", "850\n", "850\n", "850\n", "850\n", "850\n", "850\n" ]
CodeContests
<image> Arrange integers (0 or more and 99 or less) in a rhombus as illustrated in Fig. 1. Create a program that reads the data representing the rhombus and outputs the maximum value of the sum of the integers that pass when starting from the top and proceeding to the bottom according to the following rules. * At ea...
stdin
null
3,005
1
[ "7\n3,8\n8,1,0\n2,7,4,4\n4,5,2,6,5\n2,7,4,4\n8,1,0\n3,8\n7\n" ]
[ "55\n" ]
[ "7\n3,8\n8,1,0\n2,7,4,4\n4,5,2,6,5\n2,7,4,4\n8,1,0\n8,3\n7\n", "7\n3,8\n8,1,0\n2,7,4,4\n4,5,2,6,5\n2,7,4,4\n8,1,0\n8,3\n3\n", "7\n3,8\n8,1,0\n2,7,4,4\n4,5,2,6,5\n4,4,7,2\n8,1,0\n8,3\n3\n", "7\n3,8\n8,1,0\n2,7,4,4\n4,5,2,6,5\n4,4,7,2\n8,1,0\n8,3\n0\n", "7\n3,8\n8,1,0\n2,7,4,4\n4,5,2,6,5\n2,7,4,4\n8,1,0\n3,8\...
[ "60\n", "56\n", "53\n", "50\n", "52\n", "51\n", "45\n", "54\n", "55\n", "57\n" ]
CodeContests
Example Input 2 2 .. .. Output Second
stdin
null
312
1
[ "2 2\n..\n..\n" ]
[ "Second\n" ]
[ "1 2\n..\n..\n", "1 0\n..\n..\n", "1 1\n..\n..\n", "1 0\n-.\n..\n", "1 0\n-/\n..\n", "1 0\n-/\n./\n", "1 0\n,/\n./\n", "2 0\n,/\n./\n", "2 -1\n,/\n./\n", "2 -1\n/,\n./\n" ]
[ "First\n", "Second\n", "First\n", "Second\n", "Second\n", "Second\n", "Second\n", "Second\n", "Second\n", "Second\n" ]
CodeContests
The Head Chef has been playing with Fibonacci numbers for long . He has learnt several tricks related to Fibonacci numbers . Now he wants to test his chefs in the skills . A fibonacci number is defined by the recurrence : f(n) = f(n-1) + f(n-2) for n > 2 and f(1) = 0 and f(2) = 1 . Given a number A , determine if...
stdin
null
1,991
1
[ "3\n3\n4\n5\n" ]
[ "YES\nNO\nYES\n" ]
[ "3\n3\n4\n3\n", "3\n3\n6\n4\n", "3\n3\n3\n4\n", "3\n3\n3\n3\n", "3\n6\n3\n6\n", "3\n9\n15\n9\n", "3\n6\n9\n3\n", "3\n6\n5\n3\n", "3\n3\n7\n3\n", "3\n2\n7\n3\n" ]
[ "YES\nNO\nYES\n", "YES\nNO\nNO\n", "YES\nYES\nNO\n", "YES\nYES\nYES\n", "NO\nYES\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nYES\n", "NO\nYES\nYES\n", "YES\nNO\nYES\n", "YES\nNO\nYES\n" ]
CodeContests
Snuke loves "paper cutting": he cuts out characters from a newspaper headline and rearranges them to form another string. He will receive a headline which contains one of the strings S_1,...,S_n tomorrow. He is excited and already thinking of what string he will create. Since he does not know the string on the headlin...
stdin
null
4,706
1
[ "3\ncbaa\ndaacc\nacacac\n", "3\na\naa\nb\n" ]
[ "aac\n", "\n" ]
[ "3\ncaaa\ndaacc\nacacac\n", "3\ncaaa\nd`acc\nacacac\n", "3\naaca\nbdb`c\nacacac\n", "3\na\naa\na\n", "3\ncaca\ncca`d\nacacac\n", "3\nacba\nda`cb\nacacbc\n", "3\n_a_b\nc_bcb\nabcada\n", "3\naad_\nbdb_c\nababcd\n", "3\nba`c\nbcb`c\nabdbcb\n", "3\nbcac\ncc`be\nacacbc\n" ]
[ "aac\n", "ac\n", "c\n", "a\n", "acc\n", "abc\n", "b\n", "d\n", "bc\n", "bcc\n" ]
CodeContests
Our smart travel agent, Mr. X's current assignment is to show a group of tourists a distant city. As in all countries, certain pairs of cities are connected by two-way roads. Each pair of neighboring cities has a bus service that runs only between those two cities and uses the road that directly connects them. Each bus...
stdin
null
3,073
1
[ "7 10\n1 2 30\n1 3 15\n1 4 10\n2 4 25\n2 5 60\n3 4 40\n3 6 20\n4 7 35\n5 7 20\n6 7 30\n1 7 99\n\nSAMPLE\n" ]
[ "1 2 4 7\n5\n" ]
[ "7 10\n1 2 30\n1 3 15\n1 4 10\n2 4 25\n2 5 60\n2 4 40\n3 6 20\n4 7 35\n5 7 20\n6 7 30\n1 7 99\n\nSAMPLE\n", "7 10\n1 2 30\n1 3 15\n1 4 10\n2 4 25\n2 5 60\n2 4 40\n3 6 20\n4 7 35\n5 7 20\n6 7 30\n1 7 170\n\nSAMPLE\n", "7 10\n1 2 30\n1 3 15\n1 4 10\n2 4 25\n2 5 60\n2 4 40\n3 6 20\n4 7 35\n5 7 20\n6 7 30\n1 7 322\...
[ "1 2 4 7\n4\n", "1 2 4 7\n6\n", "1 2 4 7\n12\n", "1 7\n4\n", "1 2 5 7\n4\n", "1 2 5\n12\n", "1 2 5 3 4 7\n4\n", "1 2 5\n15\n", "1 2 4 7\n5\n", "1 4 5\n12\n" ]
CodeContests
Heading ##There are two integers A and B. You are required to compute the bitwise AND amongst all natural numbers lying between A and B, both inclusive. Input Format First line of the input contains T, the number of testcases to follow. Each testcase in a newline contains A and B separated by a single space. Constrai...
stdin
null
1,237
1
[ "3 \n12 15 \n2 3 \n8 13\n\nSAMPLE\n" ]
[ "12\n2\n8\n" ]
[ "3 \n8 15 \n2 3 \n8 13\n\nSAMPLE\n", "3 \n12 13 \n2 3 \n8 13\n\nSAMPLE\n", "3 \n12 13 \n2 3 \n0 13\n\nSAMPLE\n", "3 \n0 13 \n2 3 \n8 13\n\nSAMPLE\n", "3 \n0 24 \n0 3 \n8 11\n\nSAMPLE\n", "3 \n12 13 \n0 3 \n8 13\n\nSAMPLE\n", "3 \n12 13 \n0 3 \n0 13\n\nSAMPLE\n", "3 \n0 13 \n0 3 \n0 13\n\nSAMPLE\n", ...
[ "8\n2\n8\n", "12\n2\n8\n", "12\n2\n0\n", "0\n2\n8\n", "0\n0\n8\n", "12\n0\n8\n", "12\n0\n0\n", "0\n0\n0\n", "0\n0\n14\n", "0\n0\n12\n" ]
CodeContests
Professor Random, known for his research on randomized algorithms, is now conducting an experiment on biased dice. His experiment consists of dropping a number of dice onto a plane, one after another from a fixed position above the plane. The dice fall onto the plane or dice already there, without rotating, and may rol...
stdin
null
3,090
1
[ "4\n6 4\n6 4\n6 4\n6 4\n2\n5 3\n5 3\n8\n4 2\n4 2\n4 2\n4 2\n4 2\n4 2\n4 2\n4 2\n6\n4 6\n1 5\n2 3\n5 3\n2 4\n4 2\n0\n" ]
[ "0 1 1 0 0 1\n1 0 0 0 1 0\n1 2 2 1 0 0\n2 3 0 0 0 0\n" ]
[ "4\n6 4\n6 4\n6 4\n6 4\n2\n5 3\n5 3\n8\n4 2\n4 2\n4 2\n4 2\n4 2\n4 2\n4 2\n4 2\n6\n3 6\n1 5\n2 3\n5 3\n2 4\n4 2\n0\n", "4\n6 4\n6 4\n6 4\n6 4\n2\n5 3\n5 3\n8\n4 2\n4 2\n4 2\n4 2\n4 2\n4 2\n4 2\n4 1\n6\n4 6\n1 5\n2 3\n5 3\n2 4\n4 2\n0\n", "4\n6 4\n6 4\n6 4\n6 4\n2\n5 3\n5 3\n8\n4 2\n4 2\n4 2\n4 2\n4 2\n4 2\n4 2\...
[ "0 1 1 0 0 1\n1 0 0 0 1 0\n1 2 2 1 0 0\n2 3 0 0 0 0\n", "0 1 1 0 0 1\n1 0 0 0 1 0\n1 3 1 1 0 0\n2 3 0 0 0 0\n", "0 1 1 0 0 1\n1 0 0 0 1 0\n1 2 2 1 0 0\n2 1 1 1 0 0\n", "0 2 1 0 0 1\n1 0 0 0 1 0\n1 2 2 1 0 0\n2 3 0 0 0 0\n", "0 1 1 0 0 1\n1 0 0 0 1 0\n1 3 1 1 0 0\n3 1 0 1 0 0\n", "1 1 0 0 0 1\n1 0 0 0 1 0\...
CodeContests
Miki is a high school student. She has a part time job, so she cannot take enough sleep on weekdays. She wants to take good sleep on holidays, but she doesn't know the best length of sleeping time for her. She is now trying to figure that out with the following algorithm: 1. Begin with the numbers K, R and L. 2. She t...
stdin
null
1,260
1
[ "3 0 2\n0.10000000000\n0.00000100000\n0.37500000000\n", "3 0 2\n0.10000000000\n0.37499999977\n1.00000000000\n", "3 0 2\n0.10000000000\n0.50000000000\n1.00000000000\n", "3 0 2\n0.20000000000\n0.00000100000\n0.37500000000\n" ]
[ "0.729000\n", "0.810000\n", "0.900000\n", "0.512000\n" ]
[ "3 0 2\n0.4085591484323763\n0.00000100000\n0.37500000000\n", "3 0 2\n0.14744802999270293\n0.37499999977\n1.00000000000\n", "4 0 2\n0.10000000000\n0.50000000000\n1.00000000000\n", "3 0 3\n0.20000000000\n0.00000100000\n0.37500000000\n", "3 0 2\n0.14744802999270293\n1.1414476119385046\n1.00000000000\n", "4 0...
[ "0.2068873589\n", "0.7268448616\n", "0.9000000000\n", "0.0000000000\n", "1.0000000000\n", "0.9720000000\n", "0.9782590785\n", "0.8748000000\n", "0.5120000000\n", "0.8100000000\n" ]
CodeContests
Given are a prime number p and a sequence of p integers a_0, \ldots, a_{p-1} consisting of zeros and ones. Find a polynomial of degree at most p-1, f(x) = b_{p-1} x^{p-1} + b_{p-2} x^{p-2} + \ldots + b_0, satisfying the following conditions: * For each i (0 \leq i \leq p-1), b_i is an integer such that 0 \leq b_i \le...
stdin
null
1,010
1
[ "2\n1 0\n", "3\n0 0 0\n", "5\n0 1 0 1 0\n" ]
[ "1 1\n", "0 0 0\n", "0 2 0 1 3\n" ]
[ "3\n0 0 1\n", "2\n0 0\n", "3\n0 1 0\n", "3\n0 1 1\n", "3\n1 1 0\n", "5\n0 1 0 1 1\n", "2\n0 1\n", "5\n0 0 0 1 1\n", "3\n1 1 1\n", "5\n0 0 1 1 1\n" ]
[ "0 1 2\n", "0 0\n", "0 2 2\n", "0 0 1\n", "1 2 1\n", "0 3 4 2 2\n", "0 1\n", "0 4 0 3 3\n", "1 0 0\n", "0 1 1 1 2\n" ]
CodeContests
Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of Mysterious Light. Three mirrors of length N are set so that they form an equilateral triangle. Let the vertices of the triangle be a, b and c. Inside the triangle, the rifle is placed at the point p on segment ab such that ap ...
stdin
null
144
1
[ "5 2\n" ]
[ "12\n" ]
[ "5 4\n", "7 4\n", "6 1\n", "9 4\n", "6 3\n", "14 4\n", "8 1\n", "28 4\n", "15 2\n", "28 3\n" ]
[ "12\n", "18\n", "15\n", "24\n", "9\n", "36\n", "21\n", "72\n", "42\n", "81\n" ]
CodeContests
Daenerys Targaryen set her eyes on The Kingdom of The North which is ruled by the House Stark. There is a huge market in the Castle of Winterfell that sells products of all prices starting from 1 coin i.e. there are products worth Rs 1, 2, 3 . . . 10^17 . Ned Stark is the Lord of Winterfell. He gives Daenerys some co...
stdin
null
1,272
1
[ "2\n10\n1 2 4 8 16 32 64 128 256 512\n5\n1 3 4 5 7\n\nSAMPLE\n" ]
[ "1024\n2\n" ]
[ "2\n10\n1 2 4 8 16 32 64 128 256 512\n5\n0 3 4 5 7\n\nSAMPLE\n", "2\n10\n1 2 0 8 16 32 64 128 256 512\n5\n1 3 4 5 7\n\nSAMPLE\n", "2\n10\n1 2 4 8 11 32 64 128 256 512\n6\n0 3 4 5 0\n\nSAMPLE\n", "2\n11\n1 2 6 8 11 32 64 128 256 512\n6\n0 3 4 5 0\n\nSAMPLE\n", "2\n10\n1 2 1 8 16 32 64 128 611 512\n5\n1 3 4 5...
[ "1024\n1\n", "4\n2\n", "27\n1\n", "4\n1\n", "5\n2\n", "6\n2\n", "6\n3\n", "12\n3\n", "1\n3\n", "1\n2\n" ]
CodeContests
You are addicted to watching TV, and you watch so many TV programs every day. You have been in trouble recently: the airtimes of your favorite TV programs overlap. Fortunately, you have both a TV and a video recorder at your home. You can therefore watch a program on air while another program (on a different channel) ...
stdin
null
4,596
1
[ "4\nOmoikkiriTV 12:00 13:00 5 1\nWaratteIitomo 12:00 13:00 10 2\nWatarusekennhaOnibakari 20:00 21:00 10 3\nSuzumiyaharuhiNoYuuutsu 23:00 23:30 100 40\n5\na 0:00 1:00 100 100\nb 0:00 1:00 101 101\nc 0:00 1:00 102 102\nd 0:00 1:00 103 103\ne 0:00 1:00 104 104\n0\n" ]
[ "121\n207\n" ]
[ "4\nOmoikkiriTV 12:00 13:00 5 1\nWaratteIitomo 12:00 13:00 10 2\nWatarusekennhaOnibakari 20:00 21:00 10 3\nSuzumiyaharuhiNoYuuutsu 23:00 23:30 100 40\n5\na 0:00 1:00 100 100\nb 0:00 1:00 101 101\nc 0:00 1:00 102 102\nc 0:00 1:00 103 103\ne 0:00 1:00 104 104\n0\n", "4\nOmoikkiriTV 12:00 13:00 5 1\nWaratteIitomo 12...
[ "121\n207\n", "121\n287\n", "121\n241\n", "120\n207\n", "114\n287\n", "120\n287\n", "121\n264\n", "116\n207\n", "122\n241\n", "120\n261\n" ]
CodeContests
We will define the median of a sequence b of length M, as follows: * Let b' be the sequence obtained by sorting b in non-decreasing order. Then, the value of the (M / 2 + 1)-th element of b' is the median of b. Here, / is integer division, rounding down. For example, the median of (10, 30, 20) is 20; the median of ...
stdin
null
2,603
1
[ "3\n10 30 20\n", "10\n5 9 5 9 8 9 3 5 4 3\n", "1\n10\n" ]
[ "30\n", "8\n", "10\n" ]
[ "3\n10 9 20\n", "10\n5 9 5 9 8 4 3 5 4 3\n", "1\n4\n", "10\n5 9 5 9 16 8 3 5 4 3\n", "1\n2\n", "1\n16\n", "1\n7\n", "1\n3\n", "1\n6\n", "1\n1\n" ]
[ "10\n", "5\n", "4\n", "8\n", "2\n", "16\n", "7\n", "3\n", "6\n", "1\n" ]
CodeContests
The Quarkgo Empire Expeditionary Force is an evil organization that plans to invade the Earth. In keeping with the tradition of the invaders, they continued to send monsters at a pace of one every week, targeting the area around Tokyo in Japan. However, each time, five warriors calling themselves the Human Squadron Ear...
stdin
null
3,014
1
[ "30\n", "8\n", "2000000000\n" ]
[ "4\n", "2\n", "20\n" ]
[ "57\n", "13\n", "1204648530\n", "3\n", "5\n", "22801121\n", "11933788\n", "2291365\n", "784277\n", "166022\n" ]
[ "4\n", "3\n", "20\n", "1\n", "2\n", "16\n", "15\n", "14\n", "13\n", "11\n" ]
CodeContests
There are N(N+1)/2 dots arranged to form an equilateral triangle whose sides consist of N dots, as shown below. The j-th dot from the left in the i-th row from the top is denoted by (i, j) (1 \leq i \leq N, 1 \leq j \leq i). Also, we will call (i+1, j) immediately lower-left to (i, j), and (i+1, j+1) immediately lower-...
stdin
null
4,271
1
[ "3 2 1\n1 2 0\n", "3 2 2\n1 1 1\n2 1 0\n", "5 4 2\n1 3 1\n4 2 0\n", "20 20 0\n" ]
[ "6\n", "0\n", "172\n", "881396682\n" ]
[ "3 1 1\n1 2 0\n", "3 2 2\n1 1 1\n2 1 1\n", "3 1 1\n0 2 0\n", "3 0 1\n0 2 0\n", "3 3 1\n1 2 0\n", "4 2 1\n1 2 0\n", "3 3 1\n1 1 0\n", "3 2 2\n0 1 1\n2 1 1\n", "4 2 1\n1 3 0\n", "3 2 1\n0 2 -1\n" ]
[ "2\n", "3\n", "4\n", "1\n", "13\n", "22\n", "16\n", "7\n", "20\n", "10\n" ]
CodeContests
Sherlock has intercepted some encrypted messages, which he suspects are from Professor Moriarty. He found that the number of characters in each message (including spaces) is always a square number. From this he deduces that it must be a Caesar Box Cipher. In a Caesar Box Cipher, suppose the number of characters is L ...
stdin
null
4,774
1
[]
[]
[ "101\ng hJtLZNqYMMjePTIaxEBMyVWqwohAxuXQLPzJH JsJCjQeNmJbKYjU FyEFnTZSwNKEmkZktwcQCPGtgzYjeZbg OXIiEBMzomm\nBDSBHdwXUpfbYonKssmVOlcsQGKAohfsHcdQvUeywFRhOLUDuzRFquPqwHJrEslf\neYLKUFamzcZ CZMHwiTLZBxhXgiFpThKSYhg\nwiUcahEtiTIUZxirNMRPryjZobZHcgknTVJTNLHZcxKOLZxJfJbwbkmlzGNfE LblFMxrxhmzkYtSUzQqLdqGnekBTT J WEWbKAuCeP...
[ "gMBxJbnZgX MMusKTkzIhjyXJYZtYiJeVQCjSwjEtPWLjUwceBLTqPQ NQZMZIwzeFKCbzNaoJNyEPgoqxhHmEmG mYEA JFktOm\nBUsQHwuwDpsGcFzHSfmKdRRJBbVAQhFrHYOovOqEdolhULuswncfeUPlXKssyDqf\neaCTXhYmZLgKLzMZiSKcHBFYUZwxphF ihTg\nwZoNfEzGWyPOixbLJ knboDjUiZHbLYeKSSvcrHZwbtkAvWPaNccblSBuRibhMgxkFUTCBSZERkKmMzTeCWgtPnOlxQ PDx irTLzrqJiBtbT...
CodeContests
Description You are given two strings S and T, such that length of S is greater than the length of T. Then a substring of S is defined as a sequence of characters which appear consecutively in S. Find the total number of distinct substrings of M such that T is a substring of M Input Format One line containing strings...
stdin
null
10
1
[]
[]
[ "aaaa b\n", "dcba cb\n", "aa`a a\n", "dcac dc\n", "a``a a\n", "b abab\n", "aaaa c\n", "dcba bc\n", "b baba\n", "aaa` c\n" ]
[ "0\n", "4\n", "7\n", "3\n", "6\n", "0\n", "0\n", "0\n", "0\n", "0\n" ]
CodeContests
Polo, the Penguin, has a lot of tests tomorrow at the university. He knows that there are N different questions that will be on the tests. For each question i (i = 1..N), he knows C[i] - the number of tests that will contain this question, P[i] - the number of points that he will get for correctly answering this questi...
stdin
null
675
1
[ "1\n3 7\n1 2 3\n2 3 5\n3 3 3\n" ]
[ "11\n" ]
[ "1\n3 7\n1 2 0\n2 3 5\n3 3 3\n", "1\n3 7\n1 2 3\n2 3 5\n3 4 3\n", "1\n3 7\n1 2 3\n2 3 5\n3 0 3\n", "1\n3 7\n1 2 0\n2 3 10\n7 3 3\n", "1\n3 7\n1 2 0\n2 3 8\n3 1 4\n", "1\n3 7\n1 2 0\n2 2 10\n0 3 3\n", "1\n3 12\n1 2 2\n4 3 5\n3 1 3\n", "1\n3 7\n1 1 0\n2 3 5\n3 3 3\n", "1\n3 7\n1 2 0\n2 3 10\n6 3 3\n",...
[ "11\n", "14\n", "6\n", "23\n", "5\n", "2\n", "17\n", "10\n", "20\n", "13\n" ]
CodeContests
We have a connected undirected graph with N vertices and M edges. Edge i in this graph (1 \leq i \leq M) connects Vertex U_i and Vertex V_i bidirectionally. We are additionally given N integers D_1, D_2, ..., D_N. Determine whether the conditions below can be satisfied by assigning a color - white or black - to each v...
stdin
null
330
1
[ "5 5\n3 4 3 5 7\n1 2\n1 3\n3 2\n4 2\n4 5\n", "4 6\n1 1 1 1\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n", "5 7\n1 2 3 4 5\n1 2\n1 3\n1 4\n2 3\n2 5\n3 5\n4 5\n" ]
[ "BWWBB\n4\n3\n1\n5\n2\n", "BBBW\n1\n1\n1\n2\n1\n1\n", "-1\n" ]
[ "5 5\n3 4 3 5 7\n1 2\n0 3\n3 2\n4 2\n4 5\n", "4 6\n1 1 1 1\n1 2\n1 3\n2 4\n2 3\n2 4\n3 4\n", "5 7\n1 1 3 4 5\n1 2\n1 3\n1 4\n2 3\n2 5\n3 5\n4 5\n", "4 6\n1 1 2 1\n1 2\n1 3\n2 4\n2 3\n2 4\n3 4\n", "4 6\n1 1 2 1\n1 2\n2 3\n2 4\n2 3\n2 4\n3 4\n", "5 7\n1 1 3 4 3\n1 2\n1 3\n1 4\n2 3\n2 5\n1 5\n4 5\n", "5 7\...
[ "-1\n", "WBBW\n1\n1\n1\n1000000000\n1000000000\n1000000000\n", "WBBBW\n1\n3\n4\n1000000000\n5\n1000000000\n1000000000\n", "WBBW\n1\n2\n1\n1000000000\n1000000000\n1000000000\n", "WBWW\n1\n2\n1\n1000000000\n1000000000\n1000000000\n", "WBBBW\n1\n3\n4\n1000000000\n3\n1000000000\n1000000000\n", "WBBBB\n1\n3\...
CodeContests
Example Input 1 5 1 Output 11111
stdin
null
2,420
1
[ "1\n5 1\n" ]
[ "11111\n" ]
[ "1\n5 0\n", "1\n5 2\n", "1\n20 1\n", "1\n10 2\n", "1\n29 1\n", "1\n10 3\n", "1\n29 2\n", "1\n10 5\n", "1\n4 1\n", "1\n14 2\n" ]
[ "0\n", "22222\n", "333333880\n", "222222208\n", "777773972\n", "333333312\n", "555547937\n", "555555520\n", "1111\n", "222066668\n" ]
CodeContests
Write a program which prints $n$-th fibonacci number for a given integer $n$. The $n$-th fibonacci number is defined by the following recursive formula: \begin{equation*} fib(n)= \left \\{ \begin{array}{ll} 1 & (n = 0) \\\ 1 & (n = 1) \\\ fib(n - 1) + fib(n - 2) & \\\ \end{array} \right. \end{equation*} Constraints ...
stdin
null
751
1
[ "3\n" ]
[ "3\n" ]
[ "1\n", "2\n", "4\n", "8\n", "6\n", "15\n", "7\n", "24\n", "14\n", "5\n" ]
[ "1\n", "2\n", "5\n", "34\n", "13\n", "987\n", "21\n", "75025\n", "610\n", "8\n" ]
CodeContests
You are given two integers A and B. Find the largest value among A+B, A-B and A \times B. Constraints * -1000 \leq A,B \leq 1000 * All values in input are integers. Input Input is given from Standard Input in the following format: A B Output Print the largest value among A+B, A-B and A \times B. Examples Inp...
stdin
null
4,782
1
[ "0 0\n", "3 1\n", "4 -2\n" ]
[ "0\n", "4\n", "6\n" ]
[ "0 -1\n", "6 1\n", "0 -2\n", "6 0\n", "9 1\n", "3 0\n", "9 0\n", "4 0\n", "-2 2\n", "5 0\n" ]
[ "1\n", "7\n", "2\n", "6\n", "10\n", "3\n", "9\n", "4\n", "0\n", "5\n" ]
CodeContests
AltF4 and CtrlF4 again started playing games. This time they drew a N x N matrix and filled number in each of the cells randomly. The game is played in turns (AltF4 always starts first, as his name comes first alphabetically). In each turn, a player calls out a number in the range [1, N] which has not already been cal...
stdin
null
677
1
[ "1\n2\n4 1\n1 8\n\nSAMPLE\n" ]
[ "8 4\n" ]
[ "1\n2\n4 1\n1 10\n\nSAMPLE\n", "1\n2\n6 1\n0 10\n\nSAMLPE\n", "1\n2\n12 1\n0 10\n\nSAMLPE\n", "1\n2\n0 1\n0 10\n\nSAMLPE\n", "1\n2\n4 1\n1 6\n\nSAMPLE\n", "1\n0\n4 1\n0 10\n\nSAMPLE\n", "1\n2\n4 1\n0 1\n\nSAMLPE\n", "1\n2\n4 2\n1 12\n\nSAMPLE\n", "1\n2\n0 0\n0 14\n\nSAMLPE\n", "1\n2\n4 2\n1 20\n\n...
[ "10 4\n", "10 6\n", "12 10\n", "10 0\n", "6 4\n", "0 0\n", "4 1\n", "12 4\n", "14 0\n", "20 4\n" ]
CodeContests
Find the intersection of two sets $A = \\{a_0, a_1, ..., a_{n-1}\\}$ and $B = \\{b_0, b_1, ..., b_{m-1}\\}$. Constraints * $1 \leq n, m \leq 200,000$ * $0 \leq a_0 < a_1 < ... < a_{n-1} \leq 10^9$ * $0 \leq b_0 < b_1 < ... < b_{m-1} \leq 10^9$ Input The input is given in the following format. $n$ $a_0 \; a_1 \; ....
stdin
null
355
1
[ "4\n1 2 5 8\n5\n2 3 5 9 11\n" ]
[ "2\n5\n" ]
[ "4\n1 2 5 8\n5\n4 3 5 9 11\n", "4\n1 2 5 8\n9\n2 3 5 9 11\n", "4\n1 2 9 8\n5\n4 3 5 9 11\n", "4\n1 2 5 8\n9\n1 3 5 9 11\n", "4\n1 2 9 8\n7\n2 3 5 9 11\n", "4\n1 2 2 8\n9\n1 3 5 9 11\n", "4\n1 3 9 8\n7\n2 3 5 9 11\n", "4\n0 2 5 8\n5\n0 3 5 9 12\n", "4\n1 0 4 10\n9\n2 4 5 9 11\n", "4\n1 2 8 8\n5\n2 ...
[ "5\n", "2\n5\n", "9\n", "1\n5\n", "2\n9\n", "1\n", "3\n9\n", "0\n5\n", "4\n", "2\n" ]
CodeContests
We have had record hot temperatures this summer. To avoid heat stroke, you decided to buy a quantity of drinking water at the nearby supermarket. Two types of bottled water, 1 and 0.5 liter, are on sale at respective prices there. You have a definite quantity in your mind, but are willing to buy a quantity larger than ...
stdin
null
2,890
1
[ "180 100 2400\n", "200 90 2018\n" ]
[ "460\n", "450\n" ]
[ "180 100 3257\n", "12 90 2018\n", "324 100 3257\n", "22 90 2018\n", "324 101 3257\n", "21 90 2018\n", "324 111 3257\n", "324 111 5696\n", "467 101 5696\n", "467 101 10577\n" ]
[ "640\n", "36\n", "700\n", "66\n", "707\n", "63\n", "777\n", "1332\n", "1212\n", "2222\n" ]
CodeContests
problem JOI City will hold a large-scale exposition. There are two themes for this exposition, and each of the N exhibition facilities in JOI City will exhibit on one of the two themes. The location of the facility is represented by plane coordinates (x, y). To move from the facility at position (x, y) to the facili...
stdin
null
4,867
1
[ "5\n0 0\n1 0\n-1 -2\n0 1\n-1 1\n" ]
[ "3\n" ]
[ "5\n-1 0\n1 0\n-1 -2\n0 1\n-1 1\n", "5\n-2 0\n1 0\n0 -2\n0 2\n-1 1\n", "5\n0 0\n2 0\n0 -1\n-2 6\n-4 2\n", "5\n0 1\n2 1\n0 -1\n-2 4\n-4 1\n", "5\n-1 1\n1 1\n0 -1\n-2 8\n-5 1\n", "5\n-2 2\n-1 2\n0 -1\n-2 26\n-9 1\n", "5\n-2 2\n-1 3\n0 -2\n-2 26\n-9 1\n", "5\n-2 2\n-1 2\n0 -2\n-3 26\n-13 1\n", "5\n-2 2...
[ "3\n", "4\n", "6\n", "5\n", "7\n", "11\n", "12\n", "16\n", "15\n", "8\n" ]
CodeContests
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a string s consisting of lowercase letters. Determine if there exists a (...
stdin
null
4,430
1
[ "needed\n", "atcoder\n" ]
[ "2 5\n", "-1 -1\n" ]
[ "deened\n", "aoctder\n", "aocteer\n", "aectepp\n", "defnfd\n", "ndeedd\n", "defned\n", "fedned\n", "aocueer\n", "efdned\n" ]
[ "1 3\n", "-1 -1\n", "4 6\n", "5 7\n", "3 5\n", "2 4\n", "-1 -1\n", "-1 -1\n", "4 6\n", "-1 -1\n" ]
CodeContests
Problem Statement "Everlasting -One-" is an award-winning online game launched this year. This game has rapidly become famous for its large number of characters you can play. In this game, a character is characterized by attributes. There are $N$ attributes in this game, numbered $1$ through $N$. Each attribute takes...
stdin
null
2,740
1
[ "3 2\n1 2\n2 3\n5 0\n100000 0\n0 0\n" ]
[ "3\n32\n607723520\n" ]
[ "3 2\n1 2\n2 3\n2 0\n100000 0\n0 0\n", "3 2\n1 2\n2 3\n3 0\n100000 0\n0 0\n", "5 2\n1 2\n2 3\n5 0\n100000 0\n0 0\n", "3 2\n1 2\n2 3\n4 0\n100000 0\n0 0\n", "5 2\n1 2\n2 3\n2 0\n100000 0\n0 0\n", "5 2\n1 2\n2 1\n2 0\n100000 0\n0 0\n", "5 2\n1 2\n2 1\n3 0\n100000 0\n0 0\n", "5 2\n1 2\n2 1\n6 0\n100000 0...
[ "3\n4\n607723520\n", "3\n8\n607723520\n", "9\n32\n607723520\n", "3\n16\n607723520\n", "9\n4\n607723520\n", "17\n4\n607723520\n", "17\n8\n607723520\n", "17\n64\n607723520\n", "17\n32\n607723520\n", "9\n8\n607723520\n" ]
CodeContests
Example Input 3 NNN NNN NNN Output Taro
stdin
null
902
1
[ "3\nNNN\nNNN\nNNN\n" ]
[ "Taro\n" ]
[ "3\nNNN\nNNO\nNNN\n", "3\nNMN\nNNO\nNNN\n", "3\nNMN\nNNP\nNNN\n", "3\nMMN\nNNO\nNNN\n", "3\nMMN\nONN\nNNN\n", "3\nMMN\nONN\nMNN\n", "3\nMMN\nNNO\nMNN\n", "3\nMMN\nNNO\nMON\n", "3\nNMN\nNNO\nMON\n", "3\nNMN\nNNO\nMNN\n" ]
[ "Taro\n", "Taro\n", "Taro\n", "Taro\n", "Taro\n", "Taro\n", "Taro\n", "Taro\n", "Taro\n", "Taro\n" ]
CodeContests
You are given a string $S$, which is balanced parentheses with a star symbol '*' inserted. Any balanced parentheses can be constructed using the following rules: * An empty string is balanced. * Concatenation of two balanced parentheses is balanced. * If $T$ is balanced parentheses, concatenation of '(', $T$, and ')'...
stdin
null
3,332
1
[ "*\n", "((((((((((*))))))))))\n", "((*)())\n", "(*)\n", "()*()\n" ]
[ "0\n", "10\n", "2\n", "1\n", "0\n" ]
[ "((*)(()\n", "(*)())(\n", "((()(*(\n", "((((((((((*))))))()))\n", "*))()((\n", "(((((((()(*))))))()))\n", "(((((((()()*)))))()()\n", "((((*()\n", "((()(((()(*)))))())))\n", "(((((*)\n" ]
[ "2\n", "1\n", "3\n", "10\n", "0\n", "8\n", "7\n", "4\n", "6\n", "5\n" ]
CodeContests
As we all know, F.C. Barcelona is the best soccer team of our era! Their entangling and mesmerizing game style usually translates into very high ball possession, consecutive counter-attack plays and goals. Lots of goals, thanks to the natural talent of their attacker and best player in history, Lionel Andres Messi. How...
stdin
null
4,133
1
[ "2\n2 4\n4 2\n" ]
[ "4\n6\n" ]
[ "2\n3 4\n4 2\n", "2\n3 4\n4 3\n", "2\n3 1\n4 2\n", "2\n3 1\n4 3\n", "2\n6 1\n4 3\n", "2\n6 2\n4 3\n", "2\n6 2\n4 1\n", "2\n5 2\n4 1\n", "2\n5 2\n4 2\n", "2\n3 2\n4 2\n" ]
[ "12\n6\n", "12\n21\n", "0\n6\n", "0\n21\n", "1\n21\n", "22\n21\n", "22\n1\n", "10\n1\n", "10\n6\n", "2\n6\n" ]
CodeContests
problem AOR Ika and you came to the tournament-style table tennis tournament singles section for reconnaissance. For AOR Ika-chan, who wants to record all the games, you decide to ask for the number of games that will be played in this tournament. There are $ N $ players in the tournament, each with a uniform number ...
stdin
null
432
1
[ "2 0\n" ]
[ "1\n" ]
[ "2 1\n", "2 2\n", "2 4\n", "0 4\n", "-1 4\n", "-1 0\n", "1 -1\n", "-1 2\n", "-1 -4\n", "-2 -7\n" ]
[ "0\n", "-1\n", "-3\n", "-5\n", "-6\n", "-2\n", "1\n", "-4\n", "2\n", "4\n" ]
CodeContests
There are N squares lining up in a row, numbered 1 through N from left to right. Initially, all squares are white. We also have N-1 painting machines, numbered 1 through N-1. When operated, Machine i paints Square i and i+1 black. Snuke will operate these machines one by one. The order in which he operates them is rep...
stdin
null
3,235
1
[ "2\n", "4\n", "5\n", "100000\n" ]
[ "1\n", "16\n", "84\n", "341429644\n" ]
[ "3\n", "100010\n", "6\n", "110010\n", "9\n", "110011\n", "11\n", "110001\n", "13\n", "111001\n" ]
[ "4\n", "795416653\n", "516\n", "993165555\n", "275040\n", "471359203\n", "31000320\n", "428910207\n", "928152292\n", "293611143\n" ]
CodeContests
Takahashi loves walking on a tree. The tree where Takahashi walks has N vertices numbered 1 through N. The i-th of the N-1 edges connects Vertex a_i and Vertex b_i. Takahashi has scheduled M walks. The i-th walk is done as follows: * The walk involves two vertices u_i and v_i that are fixed beforehand. * Takahashi wi...
stdin
null
4,190
1
[ "5 3\n1 2\n1 3\n3 4\n3 5\n2 4\n3 5\n1 5\n", "6 4\n1 2\n2 3\n1 4\n4 5\n4 6\n2 4\n3 6\n5 6\n4 5\n", "4 3\n2 1\n3 1\n4 1\n2 3\n3 4\n4 2\n" ]
[ "6\n2 4\n3 5\n5 1\n", "9\n2 4\n6 3\n5 6\n4 5\n", "6\n2 3\n3 4\n4 2\n" ]
[ "4 1\n2 1\n3 1\n4 1\n2 3\n3 4\n4 2\n", "4 0\n2 1\n3 1\n4 0\n2 3\n3 4\n4 2\n", "4 1\n2 1\n3 1\n5 -1\n3 3\n3 4\n4 2\n", "4 1\n2 1\n3 1\n4 0\n2 3\n3 4\n4 2\n", "4 1\n2 1\n3 1\n6 0\n2 3\n3 4\n4 2\n", "4 1\n2 1\n3 1\n5 0\n2 3\n3 4\n4 2\n", "4 1\n2 1\n3 1\n5 0\n2 3\n3 4\n4 4\n", "4 1\n2 1\n3 1\n4 1\n2 3\n3 ...
[ "2\n2 3\n", "0\n", "0\n3 3\n", "2\n2 3\n", "2\n2 3\n", "2\n2 3\n", "2\n2 3\n", "2\n2 3\n", "2\n2 3\n", "0\n" ]
CodeContests
The fight between Batman and Superman just got dirty. Superman tried to trick Batman and locked him inside an N x N grid. This gird is really special. It has values at each of its cell which is some positive integer. Superman gave Batman a serious headache inside the grid. He gave him an integer K and ordered him to t...
stdin
null
2,672
1
[ "3 2\n5 69 2 \n42 9 9 \n5 8 1 \n\nSAMPLE\n" ]
[ "3\n" ]
[ "3 2\n9 69 2 \n42 9 9 \n5 8 1 \n\nSAMPLE\n", "3 2\n9 69 2 \n42 9 17 \n5 8 1 \n\nSAMPLE\n", "3 2\n11 69 5 \n9 9 17 \n5 8 1 \n\nSAMPLE\n", "3 1\n11 37 3 \n6 9 27 \n7 8 1 \n\nQALPLE\n", "3 2\n11 69 2 \n42 9 17 \n5 8 1 \n\nSAMPLE\n", "3 2\n11 69 3 \n42 9 17 \n5 8 1 \n\nSAMPLE\n", "3 2\n11 69 5 \n42 9 17 \n5...
[ "2\n", "1\n", "0\n", "3\n", "1\n", "1\n", "1\n", "0\n", "0\n", "0\n" ]