├── .cph ├── .A_ABC.cpp_72c99599edc46660ce3af1f40916b850.prob ├── .A_And_Matching.cpp_ee7b311baf3f94dfe6e2626d73b063aa.prob ├── .A_Casimir_s_String_Solitaire.cpp_e0bb6a0309cf1827320076b67d58700a.prob ├── .A_Cherry.cpp_d551ed50ee7ff0a5c0547c44c15b7025.prob ├── .A_Dislike_of_Threes.cpp_3519528da9d3c559f2bd19c865a67092.prob ├── .A_Do_Not_Be_Distracted_.cpp_4bb71b178e7f8c2f39fed8d37ee7f4bc.prob ├── .A_Domino_Disaster.cpp_8edd849757a25c864d7145616841d5d5.prob ├── .A_Download_More_RAM.cpp_8a09a9b405416175f1343241136c7653.prob ├── .A_Elections.cpp_7d630d5f6ef4fccb5cbd7587ac6d8626.prob ├── .A_Ezzat_and_Two_Subsequences.cpp_4ceba2731c572376db6d59e009f6a8b0.prob ├── .A_Find_The_Array.cpp_3e98e34c7f915ea80779496e6664b24e.prob ├── .A_Gregor_and_Cryptography.cpp_1494ea7f123daf01ed77133993a7edac.prob ├── .A_Min_Max_Swap.cpp_08b21bc2fa65f744aad9a2403a682355.prob ├── .A_Not_Shading.cpp_125c6c11a1c38aa24eab4ba918cc8b20.prob ├── .A_PizzaForces.cpp_8eb5c67cd416d1b220382dda8d222da5.prob ├── .A_Regular_Bracket_Sequences.cpp_8017d2f731016a232f3d942d0ff23795.prob ├── .A_Shortest_Path_with_Obstacle.cpp_e57183cee061ce02a2e815adc24672a7.prob ├── .A_Simply_Strange_Sort.cpp_26bfc1f9a7dd2e1fa3eda3b6fb6e8c81.prob ├── .A_The_Miracle_and_the_Sleeper.cpp_d44bdf2ddb7397570082bf52f67f6865.prob ├── .B_Alphabetical_Strings.cpp_f59369d25fa812f0f1fd2afcc2a41a10.prob ├── .B_Badge.cpp_1355f04b34c3336aef2caa75cf334a9a.prob ├── .B_Charmed_by_the_Game.cpp_c154a45c15a92ff6367dd4c89c353ce6.prob ├── .B_Cobb.cpp_8915789c3a877838ccec634a7340ee49.prob ├── .B_Fence.cpp_287711b50674bc1ca8274caae736dd83.prob ├── .B_Fun_with_Even_Subarrays.cpp_d02d8f0f90122cfa6e9b32496f69ca5d.prob ├── .B_GCD_Arrays.cpp_f2d2ee904b4653b353310243b7188d7d.prob ├── .B_Gregor_and_the_Pawn_Game.cpp_28e07209853ba18a334ac12236b4f5cb.prob ├── .B_MEXor_Mixup.cpp_220130b118c0f383ee7dc41eb4dff27b.prob ├── .B_Make_it_Divisible_by_25.cpp_5ef004974f7579497aef9fdca9e422a8.prob ├── .B_Moamen_and_k_subarrays.cpp_ac0f47e443d4fcd621ff794967a04868.prob ├── .B_Not_Sitting.cpp_56f38859708fa90676416b7505f62556.prob ├── .B_Ordinary_Numbers.cpp_a18cc688bdbca982c309d95c36d7c528.prob ├── .B_Peculiar_Movie_Preferences.cpp_f452f345d7555784bcdfa20cd22b4852.prob ├── .B_Roof_Construction.cpp_fc0e4ed75e03d35a919bdddf57917930.prob ├── .B_Scenes_From_a_Memory.cpp_bac834ada0f9cfe4bcfe7d346cec2d88.prob ├── .B_Two_Tables.cpp_24cf5ba440eaef50b4be49014f846beb.prob ├── .B_Who_s_Opposite_.cpp_904237bc4b8a362cdefd2487e8cc2377.prob ├── .C_And_Matching.cpp_e9f5b6824e39e039cac345e731430003.prob ├── .C_Coin_Rows.cpp_82fc31e8aa7f413c412ae0a0cbec4e52.prob ├── .C_Deep_Down_Below.cpp_39fbdb1c5a236810f0886544148b0412.prob ├── .C_Infinity_Table.cpp_4995de53452762f7d32832f2e5842c66.prob ├── .C_King_s_Path.cpp_104ad475746588e1894d200611806233.prob ├── .C_Meximum_Array.cpp_fd771bccb4c89be004f26d3434d48ca4.prob ├── .C_Not_Adjacent_Matrix.cpp_6778acdf21e53bf5fb59ea328b9b1c4c.prob ├── .C_Not_Assigning.cpp_044d92884cb48735d6c985648d85280f.prob ├── .C_Pair_Programming.cpp_ed45a04c6ae4af53ae4a320bf41baff0.prob ├── .C_Save_More_Mice.cpp_8195337fa971cecb2a9942eccb50adff.prob ├── .C_Slay_the_Dragon.cpp_5009ec2d737fcfc6416c0f8ea6a7ca49.prob ├── .C_Strange_Test.cpp_fed742147678a621ebe86b6f6136fc63.prob ├── .C_Valhalla_Siege.cpp_2e506985c1957fb56f63144be2d31eb1.prob ├── .C_Web_of_Lies.cpp_b2e975fc9b3471d1fb932e78985064e7.prob ├── .Charmed_by_the_Game.cpp_95350db8d49ed5ecba9384a5688416a4.prob ├── .D1_All_are_Same.cpp_dca88526263c67f67594973b2f73ca9f.prob ├── .D1_Two_Hundred_Twenty_One_easy_version_.cpp_88adc8996b6e7e86536ba414aab1f90b.prob ├── .D1_Up_the_Strip_simplified_version_.cpp_8c2d639903b2eb3ab31539316cda6618.prob ├── .D2_Half_of_Same.cpp_aa36b27864627a5a8326675b98721690.prob ├── .D_Co_growing_Sequence.cpp_2f7468975ced6fa819b6051575e79706.prob ├── .D_Lunar_New_Year_and_a_Wander.cpp_5ae855a2a614db3fd52711bee2ffd72c.prob ├── .D_Productive_Meeting.cpp_aba41bf44ded43530c8218f14cda3e46.prob ├── .D_Same_Differences.cpp_e6fc074ea04ecc7f44b9b62624c93372.prob ├── .D_Secret_Passwords.cpp_5d3c4e93d26b4ae92c92ce8f3d832d82.prob ├── .E1_Permutation_Minimization_by_Deque.cpp_23a8ade3caa4c816e674e8f9fe4b0879.prob ├── .E_Air_Conditioners.cpp_5194b95a134ec708eaebd5e87be33de3.prob ├── .E_Arranging_The_Sheep.cpp_7b2ee259410e2d50289eae742d671367.prob ├── .E_Gardener_and_Tree.cpp_104dacd828b8757284155dc431096fb7.prob ├── .F_Red_Black_Number.cpp_d1d40bfcebb8b4243eae6a66de23af44.prob ├── .G_Changing_Brackets.cpp_37e1b9365ce0f3899992b620105a7bd5.prob └── .Prime_Generator.cpp_8da4a72df0dfdc8a25da70ac2c94826f.prob ├── .gitignore ├── .vscode ├── launch.json ├── settings.json └── tasks.json ├── A_ABC.cpp ├── A_And_Matching.cpp ├── A_Casimir_s_String_Solitaire.cpp ├── A_Cherry.cpp ├── A_Dislike_of_Threes.cpp ├── A_Do_Not_Be_Distracted_.cpp ├── A_Domino_Disaster.cpp ├── A_Download_More_RAM.cpp ├── A_Elections.cpp ├── A_Ezzat_and_Two_Subsequences.cpp ├── A_Find_The_Array.cpp ├── A_Gregor_and_Cryptography.cpp ├── A_Min_Max_Swap.cpp ├── A_Not_Shading.cpp ├── A_PizzaForces.cpp ├── A_Regular_Bracket_Sequences.cpp ├── A_Shortest_Path_with_Obstacle.cpp ├── A_Simply_Strange_Sort.cpp ├── A_The_Miracle_and_the_Sleeper.cpp ├── B_Alphabetical_Strings.cpp ├── B_Badge.cpp ├── B_Charmed_by_the_Game.cpp ├── B_Cobb.cpp ├── B_Fence.cpp ├── B_Fun_with_Even_Subarrays.cpp ├── B_GCD_Arrays.cpp ├── B_Gregor_and_the_Pawn_Game.cpp ├── B_Make_it_Divisible_by_25.cpp ├── B_Not_Sitting.cpp ├── B_Ordinary_Numbers.cpp ├── B_Peculiar_Movie_Preferences.cpp ├── B_Roof_Construction.cpp ├── B_Scenes_From_a_Memory.cpp ├── B_Two_Tables.cpp ├── B_Who_s_Opposite_.cpp ├── C_And_Matching.cpp ├── C_Coin_Rows.cpp ├── C_Deep_Down_Below.cpp ├── C_King_s_Path.cpp ├── C_Meximum_Array.cpp ├── C_Not_Adjacent_Matrix.cpp ├── C_Not_Assigning.cpp ├── C_Pair_Programming.cpp ├── C_Save_More_Mice.cpp ├── C_Slay_the_Dragon.cpp ├── C_Valhalla_Siege.cpp ├── C_Web_of_Lies.cpp ├── D_Co_growing_Sequence.cpp ├── D_Lunar_New_Year_and_a_Wander.cpp ├── D_Productive_Meeting.cpp ├── D_Same_Differences.cpp ├── D_Secret_Passwords.cpp ├── E1_Permutation_Minimization_by_Deque.cpp ├── E_Air_Conditioners.cpp └── E_Arranging_The_Sheep.cpp /.cph/.A_ABC.cpp_72c99599edc46660ce3af1f40916b850.prob: -------------------------------------------------------------------------------- 1 | {"name":"A. ABC","group":"Codeforces - Codeforces Round #769 (Div. 2)","url":"https://codeforces.com/contest/1632/problem/0","interactive":false,"memoryLimit":256,"timeLimit":1000,"tests":[{"id":1643553329436,"input":"4\n1\n1\n2\n10\n2\n01\n4\n1010","output":"YES\nYES\nYES\nNO"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"AABC"}},"batch":{"id":"9f68085a-8b6f-4b50-ad52-57ac45d84830","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/A_ABC.cpp"} -------------------------------------------------------------------------------- /.cph/.A_And_Matching.cpp_ee7b311baf3f94dfe6e2626d73b063aa.prob: -------------------------------------------------------------------------------- 1 | {"name":"A. And Matching","group":"Codeforces - Codeforces Round #768 (Div. 1)","url":"https://codeforces.com/contest/1630/problem/A","interactive":false,"memoryLimit":256,"timeLimit":1000,"tests":[{"id":1643609824587,"input":"4\n4 0\n4 1\n4 2\n4 3","output":"0 3\n1 2\n0 2\n1 3\n0 1\n2 3\n-1"},{"id":1643609870396,"input":"1\n16 15","output":"15 14\n13 1\n0 2\n3 12\n4 11\n5 10\n6 9\n7 8"},{"id":1643610194315,"input":"2\n8 7\n4 3","output":""}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"AAndMatching"}},"batch":{"id":"dae5ca90-4a18-43e6-a17d-8bbe9db4d1c3","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/A_And_Matching.cpp"} -------------------------------------------------------------------------------- /.cph/.A_Casimir_s_String_Solitaire.cpp_e0bb6a0309cf1827320076b67d58700a.prob: -------------------------------------------------------------------------------- 1 | {"name":"A. Casimir's String Solitaire","group":"Codeforces - Codeforces Round #744 (Div. 3)","url":"https://codeforces.com/contest/1579/problem/A","interactive":false,"memoryLimit":256,"timeLimit":2000,"tests":[{"id":1632840223146,"input":"6\nABACAB\nABBA\nAC\nABC\nCABCBB\nBCBCBCBCBCBCBCBC","output":"NO\nYES\nNO\nNO\nYES\nYES"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"ACasimirsStringSolitaire"}},"batch":{"id":"3d06e25c-7db4-423e-b06c-9e3a8a6d4284","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/A_Casimir_s_String_Solitaire.cpp"} -------------------------------------------------------------------------------- /.cph/.A_Cherry.cpp_d551ed50ee7ff0a5c0547c44c15b7025.prob: -------------------------------------------------------------------------------- 1 | {"name":"A. Cherry","group":"Codeforces - Codeforces Round #735 (Div. 2)","url":"https://codeforces.com/contest/1554/problem/0","interactive":false,"memoryLimit":256,"timeLimit":1000,"tests":[{"id":1627569368105,"input":"4\n3\n2 4 3\n4\n3 2 3 1\n2\n69 69\n6\n719313 273225 402638 473783 804745 323328","output":"12\n6\n4761\n381274500335"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"ACherry"}},"batch":{"id":"cea19763-32ab-418f-9529-2349433472a9","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/A_Cherry.cpp"} -------------------------------------------------------------------------------- /.cph/.A_Dislike_of_Threes.cpp_3519528da9d3c559f2bd19c865a67092.prob: -------------------------------------------------------------------------------- 1 | {"name":"A. Dislike of Threes","group":"Codeforces - Codeforces Round #739 (Div. 3)","url":"https://codeforces.com/contest/1560/problem/0","interactive":false,"memoryLimit":256,"timeLimit":1000,"tests":[{"id":1629297868121,"input":"10\n1\n2\n3\n4\n5\n6\n7\n8\n9\n1000","output":"1\n2\n4\n5\n7\n8\n10\n11\n14\n1666"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"ADislikeOfThrees"}},"batch":{"id":"3a1bf79a-6442-4cd9-b21a-775c91a610be","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/A_Dislike_of_Threes.cpp"} -------------------------------------------------------------------------------- /.cph/.A_Do_Not_Be_Distracted_.cpp_4bb71b178e7f8c2f39fed8d37ee7f4bc.prob: -------------------------------------------------------------------------------- 1 | {"name":"A. Do Not Be Distracted!","group":"Codeforces - Codeforces Round #719 (Div. 3)","url":"https://codeforces.com/contest/1520/problem/A","interactive":false,"memoryLimit":256,"timeLimit":1000,"tests":[{"id":1626777208648,"input":"6\n3\nABA\n11\nDDBBCCCBBEZ\n7\nFFGZZZY\n1\nZ\n2\nAB\n10\nAAAAAAAAAJ","output":"NO\nNO\nYES\nYES\nYES\nYES"},{"id":1626778316058,"input":"1\n10\nAAAAAAAAAJ","output":"YES"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"ADoNotBeDistracted"}},"batch":{"id":"4ef3cd04-c539-442a-856b-ff774e533067","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/A_Do_Not_Be_Distracted_.cpp"} -------------------------------------------------------------------------------- /.cph/.A_Domino_Disaster.cpp_8edd849757a25c864d7145616841d5d5.prob: -------------------------------------------------------------------------------- 1 | {"name":"A. Domino Disaster","group":"Codeforces - Codeforces Round #742 (Div. 2)","url":"https://codeforces.com/contest/1567/problem/0","interactive":false,"memoryLimit":256,"timeLimit":2000,"tests":[{"id":1630852769414,"input":"4\n1\nU\n2\nLR\n5\nLRDLR\n6\nUUUUUU","output":"D\nLR\nLRULR\nDDDDDD"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"ADominoDisaster"}},"batch":{"id":"3b3905ed-8687-441e-8470-4fc650fc47dc","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/A_Domino_Disaster.cpp"} -------------------------------------------------------------------------------- /.cph/.A_Download_More_RAM.cpp_8a09a9b405416175f1343241136c7653.prob: -------------------------------------------------------------------------------- 1 | {"name":"A. Download More RAM","group":"Codeforces - Codeforces Round #767 (Div. 2)","url":"https://codeforces.com/contest/1629/problem/A","interactive":false,"memoryLimit":256,"timeLimit":1000,"tests":[{"id":1643693715464,"input":"4\n3 10\n20 30 10\n9 100 10\n5 1\n1 1 5 1 1\n1 1 1 1 1\n5 1\n2 2 2 2 2\n100 100 100 100 100\n5 8\n128 64 32 16 8\n128 64 32 16 8","output":"29\n6\n1\n256"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"ADownloadMoreRAM"}},"batch":{"id":"2d25efda-7147-4d6a-a173-de9278a4d452","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/A_Download_More_RAM.cpp"} -------------------------------------------------------------------------------- /.cph/.A_Elections.cpp_7d630d5f6ef4fccb5cbd7587ac6d8626.prob: -------------------------------------------------------------------------------- 1 | {"name":"A. Elections","group":"Codeforces - Codeforces Round #748 (Div. 3)","url":"https://codeforces.com/contest/1593/problem/A","interactive":false,"memoryLimit":256,"timeLimit":1000,"tests":[{"id":1634495784826,"input":"5\n0 0 0\n10 75 15\n13 13 17\n1000 0 0\n0 1000000000 0","output":"1 1 1\n66 0 61\n5 5 0\n0 1001 1001\n1000000001 0 1000000001"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"AElections"}},"batch":{"id":"b5c13d79-aa5d-423b-96f0-baa9f44b582b","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/A_Elections.cpp"} -------------------------------------------------------------------------------- /.cph/.A_Ezzat_and_Two_Subsequences.cpp_4ceba2731c572376db6d59e009f6a8b0.prob: -------------------------------------------------------------------------------- 1 | {"name":"A. Ezzat and Two Subsequences","group":"Codeforces - Codeforces Round #737 (Div. 2)","url":"https://codeforces.com/contest/1557/problem/0","interactive":false,"memoryLimit":256,"timeLimit":1000,"tests":[{"id":1628519837727,"input":"4\n3\n3 1 2\n3\n-7 -6 -6\n3\n2 2 2\n4\n17 3 5 -3","output":"4.500000000\n-12.500000000\n4.000000000\n18.666666667"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"AEzzatAndTwoSubsequences"}},"batch":{"id":"5f5ef91f-2097-4fc0-a948-baeae518fb38","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/A_Ezzat_and_Two_Subsequences.cpp"} -------------------------------------------------------------------------------- /.cph/.A_Find_The_Array.cpp_3e98e34c7f915ea80779496e6664b24e.prob: -------------------------------------------------------------------------------- 1 | {"name":"A. Find The Array","group":"Codeforces - Educational Codeforces Round 111 (Rated for Div. 2)","url":"https://codeforces.com/contest/1550/problem/A","interactive":false,"memoryLimit":256,"timeLimit":1000,"tests":[{"id":1626275402728,"input":"4\n1\n8\n7\n42","output":"1\n3\n3\n7"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"AFindTheArray"}},"batch":{"id":"a3fe0b51-b4d2-4a1a-ac60-48d4d24071a0","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/A_Find_The_Array.cpp"} -------------------------------------------------------------------------------- /.cph/.A_Gregor_and_Cryptography.cpp_1494ea7f123daf01ed77133993a7edac.prob: -------------------------------------------------------------------------------- 1 | {"name":"A. Gregor and Cryptography","group":"Codeforces - Codeforces Round #736 (Div. 2)","url":"https://codeforces.com/contest/1549/problem/A","interactive":false,"memoryLimit":256,"timeLimit":1000,"tests":[{"id":1627830367752,"input":"2\n17\n5","output":"3 5\n2 4"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"AGregorAndCryptography"}},"batch":{"id":"c12760cf-4712-48dc-a5da-f93c5f3bb823","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/A_Gregor_and_Cryptography.cpp"} -------------------------------------------------------------------------------- /.cph/.A_Min_Max_Swap.cpp_08b21bc2fa65f744aad9a2403a682355.prob: -------------------------------------------------------------------------------- 1 | {"name":"A. Min Max Swap","group":"Codeforces - Codeforces Round #768 (Div. 2)","url":"https://codeforces.com/contest/1631/problem/0","interactive":false,"memoryLimit":256,"timeLimit":1000,"tests":[{"id":1643294137419,"input":"3\n6\n1 2 6 5 1 2\n3 4 3 2 2 5\n3\n3 3 3\n3 3 3\n2\n1 2\n2 1","output":"18\n9\n2"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"AMinMaxSwap"}},"batch":{"id":"7204706a-5a56-4faf-b066-a8869ecd29e6","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/A_Min_Max_Swap.cpp"} -------------------------------------------------------------------------------- /.cph/.A_Not_Shading.cpp_125c6c11a1c38aa24eab4ba918cc8b20.prob: -------------------------------------------------------------------------------- 1 | {"name":"A. Not Shading","group":"Codeforces - Codeforces Round #766 (Div. 2)","url":"https://codeforces.com/contest/1627/problem/0","interactive":false,"memoryLimit":256,"timeLimit":1000,"tests":[{"id":1642257323528,"input":"9\n3 5 1 4\nWBWWW\nBBBWB\nWWBBB\n4 3 2 1\nBWW\nBBW\nWBB\nWWB\n2 3 2 2\nWWW\nWWW\n2 2 1 1\nWW\nWB\n5 9 5 9\nWWWWWWWWW\nWBWBWBBBW\nWBBBWWBWW\nWBWBWBBBW\nWWWWWWWWW\n1 1 1 1\nB\n1 1 1 1\nW\n1 2 1 1\nWB\n2 1 1 1\nW\nB","output":"1\n0\n-1\n2\n2\n0\n-1\n1\n1"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"ANotShading"}},"batch":{"id":"34c15705-7ae0-449b-a616-308749909ca9","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/A_Not_Shading.cpp"} -------------------------------------------------------------------------------- /.cph/.A_PizzaForces.cpp_8eb5c67cd416d1b220382dda8d222da5.prob: -------------------------------------------------------------------------------- 1 | {"name":"A. PizzaForces","group":"Codeforces - Educational Codeforces Round 112 (Rated for Div. 2)","url":"https://codeforces.com/contest/1555/problem/0","interactive":false,"memoryLimit":256,"timeLimit":2000,"tests":[{"id":1627655717151,"input":"9\n12\n15\n300\n1\n9999999999999999\n3\n5\n7\n9","output":"30\n40\n750\n15\n25000000000000000\n15\n15\n20\n25"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"APizzaForces"}},"batch":{"id":"d56fd406-0b37-4fbb-8547-a87c21519028","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/A_PizzaForces.cpp"} -------------------------------------------------------------------------------- /.cph/.A_Regular_Bracket_Sequences.cpp_8017d2f731016a232f3d942d0ff23795.prob: -------------------------------------------------------------------------------- 1 | {"name":"A. Regular Bracket Sequences","group":"Codeforces - Educational Codeforces Round 114 (Rated for Div. 2)","url":"https://codeforces.com/contest/1574/problem/A","interactive":false,"memoryLimit":512,"timeLimit":2000,"tests":[{"id":1632148820078,"input":"3\n3\n1\n3","output":"()()()\n((()))\n(()())\n()\n((()))\n(())()\n()(())"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"ARegularBracketSequences"}},"batch":{"id":"021ed3b9-1756-44e4-8640-d73ea99530fb","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/A_Regular_Bracket_Sequences.cpp"} -------------------------------------------------------------------------------- /.cph/.A_Shortest_Path_with_Obstacle.cpp_e57183cee061ce02a2e815adc24672a7.prob: -------------------------------------------------------------------------------- 1 | {"name":"A. Shortest Path with Obstacle","group":"Codeforces - Codeforces Round #731 (Div. 3)","url":"https://codeforces.com/contest/1547/problem/A","interactive":false,"memoryLimit":512,"timeLimit":2000,"tests":[{"id":1626706829150,"input":"7\n\n1 1\n3 3\n2 2\n\n2 5\n2 1\n2 3\n\n1000 42\n1000 1\n1000 1000\n\n1 10\n3 10\n2 10\n\n3 8\n7 8\n3 7\n\n2 1\n4 1\n1 1\n\n1 344\n1 10\n1 1","output":"4\n6\n41\n4\n4\n2\n334"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"AShortestPathWithObstacle"}},"batch":{"id":"6b18eaea-4fab-499b-ab7d-80f9da9e8636","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/A_Shortest_Path_with_Obstacle.cpp"} -------------------------------------------------------------------------------- /.cph/.A_Simply_Strange_Sort.cpp_26bfc1f9a7dd2e1fa3eda3b6fb6e8c81.prob: -------------------------------------------------------------------------------- 1 | {"name":"A. Simply Strange Sort","group":"Codeforces - Codeforces Round #740 (Div. 2, based on VK Cup 2021 - Final (Engine))","url":"https://codeforces.com/contest/1561/problem/A","interactive":false,"memoryLimit":512,"timeLimit":2000,"tests":[{"id":1629816691300,"input":"3\n3\n3 2 1\n7\n4 5 7 1 3 2 6\n5\n1 2 3 4 5","output":"3\n5\n0"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"ASimplyStrangeSort"}},"batch":{"id":"d7feb3c4-d66b-4038-ae03-f12f8a63f6d0","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/A_Simply_Strange_Sort.cpp"} -------------------------------------------------------------------------------- /.cph/.A_The_Miracle_and_the_Sleeper.cpp_d44bdf2ddb7397570082bf52f67f6865.prob: -------------------------------------------------------------------------------- 1 | {"name":"A. The Miracle and the Sleeper","group":"Codeforces - Codeforces Round #741 (Div. 2)","url":"https://codeforces.com/contest/1562/problem/0","interactive":false,"memoryLimit":256,"timeLimit":1000,"tests":[{"id":1629988911290,"input":"4\n1 1\n999999999 1000000000\n8 26\n1 999999999","output":"0\n1\n12\n499999999"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"ATheMiracleAndTheSleeper"}},"batch":{"id":"5d8882bd-229c-4ddc-9aed-a59179f26d3d","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/A_The_Miracle_and_the_Sleeper.cpp"} -------------------------------------------------------------------------------- /.cph/.B_Alphabetical_Strings.cpp_f59369d25fa812f0f1fd2afcc2a41a10.prob: -------------------------------------------------------------------------------- 1 | {"name":"B. Alphabetical Strings","group":"Codeforces - Codeforces Round #731 (Div. 3)","url":"https://codeforces.com/contest/1547/problem/B","interactive":false,"memoryLimit":512,"timeLimit":2000,"tests":[{"id":1626706836763,"input":"11\na\nba\nab\nbac\nihfcbadeg\nz\naa\nca\nacb\nxyz\nddcba","output":"YES\nYES\nYES\nYES\nYES\nNO\nNO\nNO\nNO\nNO\nNO"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"BAlphabeticalStrings"}},"batch":{"id":"5f444782-6642-4080-b4f0-345c597092c0","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/B_Alphabetical_Strings.cpp"} -------------------------------------------------------------------------------- /.cph/.B_Badge.cpp_1355f04b34c3336aef2caa75cf334a9a.prob: -------------------------------------------------------------------------------- 1 | {"name":"B. Badge","group":"Codeforces - Codeforces Round #503 (by SIS, Div. 2)","url":"https://codeforces.com/problemset/problem/1020/B","interactive":false,"memoryLimit":256,"timeLimit":1000,"tests":[{"input":"3\n2 3 2","output":"2 2 3","id":1631871866224},{"id":1631871866268,"input":"3\n1 2 3","output":"1 2 3"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"BBadge"}},"batch":{"id":"845c1f54-b271-4124-875a-b38a0d07de1b","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/B_Badge.cpp"} -------------------------------------------------------------------------------- /.cph/.B_Charmed_by_the_Game.cpp_c154a45c15a92ff6367dd4c89c353ce6.prob: -------------------------------------------------------------------------------- 1 | {"name":"B. Charmed by the Game","group":"Codeforces - Codeforces Round #740 (Div. 2, based on VK Cup 2021 - Final (Engine))","url":"https://codeforces.com/contest/1561/problem/B","interactive":false,"memoryLimit":512,"timeLimit":2000,"tests":[{"id":1629820193153,"input":"3\n2 1\n1 1\n0 5","output":"4\n0 1 2 3\n2\n0 2\n2\n2 3"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"BCharmedByTheGame"}},"batch":{"id":"fbef86f9-0fd8-4f54-b57b-80fcf384649c","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/B_Charmed_by_the_Game.cpp"} -------------------------------------------------------------------------------- /.cph/.B_Cobb.cpp_8915789c3a877838ccec634a7340ee49.prob: -------------------------------------------------------------------------------- 1 | {"name":"B. Cobb","group":"Codeforces - Codeforces Round #735 (Div. 2)","url":"https://codeforces.com/contest/1554/problem/B","interactive":false,"memoryLimit":256,"timeLimit":1000,"tests":[{"id":1627571934858,"input":"4\n3 3\n1 1 3\n2 2\n1 2\n4 3\n0 1 2 3\n6 6\n3 2 0 0 5 6","output":"-1\n-4\n3\n12"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"BCobb"}},"batch":{"id":"4786d8c0-bf59-4825-8a33-42e268503b2d","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/B_Cobb.cpp"} -------------------------------------------------------------------------------- /.cph/.B_Fence.cpp_287711b50674bc1ca8274caae736dd83.prob: -------------------------------------------------------------------------------- 1 | {"name":"B. Fence","group":"Codeforces - Codeforces Round #211 (Div. 2)","url":"https://codeforces.com/problemset/problem/363/B","interactive":false,"memoryLimit":256,"timeLimit":1000,"tests":[{"input":"7 3\n1 2 6 1 1 7 1","output":"3","id":1632672046953}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"BFence"}},"batch":{"id":"f03345b0-de47-4cad-8130-728bf9f2b603","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/B_Fence.cpp"} -------------------------------------------------------------------------------- /.cph/.B_Fun_with_Even_Subarrays.cpp_d02d8f0f90122cfa6e9b32496f69ca5d.prob: -------------------------------------------------------------------------------- 1 | {"name":"B. Fun with Even Subarrays","group":"Codeforces - Codeforces Round #768 (Div. 2)","url":"https://codeforces.com/contest/1631/problem/B","interactive":false,"memoryLimit":256,"timeLimit":1000,"tests":[{"input":"5\n3\n1 1 1\n2\n2 1\n5\n4 4 4 2 4\n4\n4 2 1 3\n1\n1","output":"0\n1\n1\n2\n0","id":1643294500219},{"id":1643296760741,"input":"1\n8\n3 2 5 5 4 4 6 6","output":"2"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"BFunWithEvenSubarrays"}},"batch":{"id":"544ed781-1bc4-4c9e-a881-dfb0f138ed9e","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/B_Fun_with_Even_Subarrays.cpp"} -------------------------------------------------------------------------------- /.cph/.B_GCD_Arrays.cpp_f2d2ee904b4653b353310243b7188d7d.prob: -------------------------------------------------------------------------------- 1 | {"name":"B. GCD Arrays","group":"Codeforces - Codeforces Round #767 (Div. 2)","url":"https://codeforces.com/contest/1629/problem/B","interactive":false,"memoryLimit":256,"timeLimit":2000,"tests":[{"id":1643694927150,"input":"9\n1 1 0\n3 5 1\n13 13 0\n4 4 0\n3 7 4\n4 10 3\n2 4 0\n1 7 3\n1 5 3","output":"NO\nNO\nYES\nYES\nYES\nYES\nNO\nNO\nYES"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"BGCDArrays"}},"batch":{"id":"167e93a7-9349-4029-b0e2-c111fafc42a9","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/B_GCD_Arrays.cpp"} -------------------------------------------------------------------------------- /.cph/.B_Gregor_and_the_Pawn_Game.cpp_28e07209853ba18a334ac12236b4f5cb.prob: -------------------------------------------------------------------------------- 1 | {"name":"B. Gregor and the Pawn Game","group":"Codeforces - Codeforces Round #736 (Div. 2)","url":"https://codeforces.com/contest/1549/problem/B","interactive":false,"memoryLimit":256,"timeLimit":1000,"tests":[{"id":1627831208786,"input":"6\n4\n1111\n1011\n5\n10101\n11010\n3\n000\n111\n4\n1111\n1111\n3\n010\n010\n5\n11001\n00000","output":"3\n2\n3\n4\n0\n0"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"BGregorAndThePawnGame"}},"batch":{"id":"daa745c9-4980-4b43-8e4b-9c3861cc3ff1","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/B_Gregor_and_the_Pawn_Game.cpp"} -------------------------------------------------------------------------------- /.cph/.B_MEXor_Mixup.cpp_220130b118c0f383ee7dc41eb4dff27b.prob: -------------------------------------------------------------------------------- 1 | {"name":"B. MEXor Mixup","group":"Codeforces - Codeforces Round #742 (Div. 2)","url":"https://codeforces.com/contest/1567/problem/B","interactive":false,"memoryLimit":256,"timeLimit":2000,"tests":[{"input":"5\n1 1\n2 1\n2 0\n1 10000\n2 10000","output":"3\n2\n3\n2\n3","id":1630853020151}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"BMEXorMixup"}},"batch":{"id":"717c5f09-9cd1-42ae-88fb-53560c63d789","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/B_MEXor_Mixup.cpp"} -------------------------------------------------------------------------------- /.cph/.B_Make_it_Divisible_by_25.cpp_5ef004974f7579497aef9fdca9e422a8.prob: -------------------------------------------------------------------------------- 1 | {"name":"B. Make it Divisible by 25","group":"Codeforces - Codeforces Round #748 (Div. 3)","url":"https://codeforces.com/contest/1593/problem/B","interactive":false,"memoryLimit":256,"timeLimit":1000,"tests":[{"id":1634495778786,"input":"5\n100\n71345\n3259\n50555\n2050047","output":"0\n3\n1\n3\n2"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"BMakeItDivisibleBy25"}},"batch":{"id":"149e65dc-ef7f-4ba7-b1af-ae192d69cbc1","size":8},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/B_Make_it_Divisible_by_25.cpp"} -------------------------------------------------------------------------------- /.cph/.B_Moamen_and_k_subarrays.cpp_ac0f47e443d4fcd621ff794967a04868.prob: -------------------------------------------------------------------------------- 1 | {"name":"B. Moamen and k-subarrays","group":"Codeforces - Codeforces Round #737 (Div. 2)","url":"https://codeforces.com/contest/1557/problem/B","interactive":false,"memoryLimit":256,"timeLimit":2000,"tests":[{"id":1628520811290,"input":"4\n5 4\n6 3 4 2 1\n4 2\n1 -4 0 -2\n5 1\n1 2 3 4 5\n8 6\n6 5 7 8 9 2 1 3","output":"Yes\nNo\nYes\nYes"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"BMoamenAndKSubarrays"}},"batch":{"id":"b5d0d3de-ca52-46c6-b48c-39e772abff85","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/B_Moamen_and_k_subarrays.cpp"} -------------------------------------------------------------------------------- /.cph/.B_Not_Sitting.cpp_56f38859708fa90676416b7505f62556.prob: -------------------------------------------------------------------------------- 1 | {"name":"B. Not Sitting","group":"Codeforces - Codeforces Round #766 (Div. 2)","url":"https://codeforces.com/contest/1627/problem/B","interactive":false,"memoryLimit":256,"timeLimit":1000,"tests":[{"id":1642257872051,"input":"2\n4 3\n1 2","output":"3 3 4 4 4 4 4 4 5 5 5 5\n1 1"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"BNotSitting"}},"batch":{"id":"f7467736-86f3-4b08-905f-4cb44d222738","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/B_Not_Sitting.cpp"} -------------------------------------------------------------------------------- /.cph/.B_Ordinary_Numbers.cpp_a18cc688bdbca982c309d95c36d7c528.prob: -------------------------------------------------------------------------------- 1 | {"name":"B. Ordinary Numbers","group":"Codeforces - Codeforces Round #719 (Div. 3)","url":"https://codeforces.com/contest/1520/problem/B","interactive":false,"memoryLimit":256,"timeLimit":2000,"tests":[{"id":1626777191283,"input":"6\n1\n2\n3\n4\n5\n100","output":"1\n2\n3\n4\n5\n18"},{"id":1626788627133,"input":"6\n77\n78\n145\n554\n100007\n9898989893","output":"16\n16\n19\n22\n45"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"BOrdinaryNumbers"}},"batch":{"id":"5b1812b6-8289-4ace-be84-3dfeabd57415","size":8},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/B_Ordinary_Numbers.cpp"} -------------------------------------------------------------------------------- /.cph/.B_Peculiar_Movie_Preferences.cpp_f452f345d7555784bcdfa20cd22b4852.prob: -------------------------------------------------------------------------------- 1 | {"name":"B. Peculiar Movie Preferences","group":"Codeforces - Codeforces Round #767 (Div. 1)","url":"https://codeforces.com/problemset/problem/1628/B","interactive":false,"memoryLimit":512,"timeLimit":2000,"tests":[{"id":1643552768351,"input":"6\n5\nzx\nab\ncc\nzx\nba\n2\nab\nbad\n4\nco\ndef\norc\nes\n3\na\nb\nc\n3\nab\ncd\ncba\n2\nab\nab","output":"YES\nNO\nNO\nYES\nYES\nNO"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"BPeculiarMoviePreferences"}},"batch":{"id":"3af6573a-f3de-46cf-82fd-6400a5541f6c","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/B_Peculiar_Movie_Preferences.cpp"} -------------------------------------------------------------------------------- /.cph/.B_Roof_Construction.cpp_fc0e4ed75e03d35a919bdddf57917930.prob: -------------------------------------------------------------------------------- 1 | {"name":"B. Roof Construction","group":"Codeforces - Codeforces Round #769 (Div. 2)","url":"https://codeforces.com/contest/1632/problem/B","interactive":false,"memoryLimit":256,"timeLimit":1000,"tests":[{"id":1643554070780,"input":"5\n2\n3\n5\n10\n16","output":"0 1\n2 0 1\n3 2 1 0 4\n4 6 3 2 0 8 9 1 7 5"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"BRoofConstruction"}},"batch":{"id":"211f6fc2-c6b1-413a-b02a-5df26b990446","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/B_Roof_Construction.cpp"} -------------------------------------------------------------------------------- /.cph/.B_Scenes_From_a_Memory.cpp_bac834ada0f9cfe4bcfe7d346cec2d88.prob: -------------------------------------------------------------------------------- 1 | {"name":"B. Scenes From a Memory","group":"Codeforces - Codeforces Round #741 (Div. 2)","url":"https://codeforces.com/contest/1562/problem/B","interactive":false,"memoryLimit":256,"timeLimit":1000,"tests":[{"id":1629990278816,"input":"7\n3\n237\n5\n44444\n3\n221\n2\n35\n3\n773\n1\n4\n30\n626221626221626221626221626221","output":"2\n27\n1\n4\n1\n1\n2\n35\n2\n77\n1\n4\n1\n6"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"BScenesFromAMemory"}},"batch":{"id":"82f30692-c76c-481e-affa-bc6a0fec1c3a","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/B_Scenes_From_a_Memory.cpp"} -------------------------------------------------------------------------------- /.cph/.B_Two_Tables.cpp_24cf5ba440eaef50b4be49014f846beb.prob: -------------------------------------------------------------------------------- 1 | {"name":"B. Two Tables","group":"Codeforces - Educational Codeforces Round 112 (Rated for Div. 2)","url":"https://codeforces.com/contest/1555/problem/B","interactive":false,"memoryLimit":256,"timeLimit":2000,"tests":[{"id":1627659818633,"input":"5\n8 5\n2 1 7 4\n4 2\n5 4\n2 2 5 4\n3 3\n1 8\n0 3 1 6\n1 5\n8 1\n3 0 6 1\n5 1\n8 10\n4 5 7 8\n8 5","output":"1.000000000\n-1\n2.000000000\n2.000000000\n0.000000000"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"BTwoTables"}},"batch":{"id":"381494e3-a1bc-408b-ae64-6d955038a2d7","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/B_Two_Tables.cpp"} -------------------------------------------------------------------------------- /.cph/.B_Who_s_Opposite_.cpp_904237bc4b8a362cdefd2487e8cc2377.prob: -------------------------------------------------------------------------------- 1 | {"name":"B. Who's Opposite?","group":"Codeforces - Codeforces Round #739 (Div. 3)","url":"https://codeforces.com/contest/1560/problem/B","interactive":false,"memoryLimit":256,"timeLimit":1000,"tests":[{"id":1629298924113,"input":"7\n6 2 4\n2 3 1\n2 4 10\n5 3 4\n1 3 2\n2 5 4\n4 3 2","output":"8\n-1\n-1\n-1\n4\n1\n-1"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"BWhosOpposite"}},"batch":{"id":"985eb5e8-e3f4-4e89-ae72-39ab5256908f","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/B_Who_s_Opposite_.cpp"} -------------------------------------------------------------------------------- /.cph/.C_And_Matching.cpp_e9f5b6824e39e039cac345e731430003.prob: -------------------------------------------------------------------------------- 1 | {"name":"C. And Matching","group":"Codeforces - Codeforces Round #768 (Div. 2)","url":"https://codeforces.com/contest/1631/problem/C","interactive":false,"memoryLimit":256,"timeLimit":1000,"tests":[{"input":"4\n4 0\n4 1\n4 2\n4 3","output":"0 3\n1 2\n0 2\n1 3\n0 1\n2 3\n-1","id":1643300035754},{"id":1643300706578,"input":"1\n16 10","output":"10 15\n0 5\n1 14\n2 13\n3 12\n4 11\n6 9\n7 8"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"CAndMatching"}},"batch":{"id":"f13f1143-efe0-46fd-888b-32cccda844d9","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/C_And_Matching.cpp"} -------------------------------------------------------------------------------- /.cph/.C_Coin_Rows.cpp_82fc31e8aa7f413c412ae0a0cbec4e52.prob: -------------------------------------------------------------------------------- 1 | {"name":"C. Coin Rows","group":"Codeforces - Educational Codeforces Round 112 (Rated for Div. 2)","url":"https://codeforces.com/contest/1555/problem/C","interactive":false,"memoryLimit":256,"timeLimit":2000,"tests":[{"id":1628006210900,"input":"3\n3\n1 3 7\n3 5 1\n3\n1 3 9\n3 5 1\n1\n4\n7","output":"7\n8\n0"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"CCoinRows"}},"batch":{"id":"c631271f-238d-40c0-9642-320e8dffd36e","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/C_Coin_Rows.cpp"} -------------------------------------------------------------------------------- /.cph/.C_Deep_Down_Below.cpp_39fbdb1c5a236810f0886544148b0412.prob: -------------------------------------------------------------------------------- 1 | {"name":"C. Deep Down Below","group":"Codeforces - Codeforces Round #740 (Div. 2, based on VK Cup 2021 - Final (Engine))","url":"https://codeforces.com/contest/1561/problem/C","interactive":false,"memoryLimit":512,"timeLimit":2000,"tests":[{"id":1629821407406,"input":"2\n1\n1 42\n2\n3 10 15 8\n2 12 11","output":"43\n13"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"CDeepDownBelow"}},"batch":{"id":"3036c110-797f-4203-964f-62a34bd47140","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/C_Deep_Down_Below.cpp"} -------------------------------------------------------------------------------- /.cph/.C_Infinity_Table.cpp_4995de53452762f7d32832f2e5842c66.prob: -------------------------------------------------------------------------------- 1 | {"name":"C. Infinity Table","group":"Codeforces - Codeforces Round #739 (Div. 3)","url":"https://codeforces.com/contest/1560/problem/C","interactive":false,"memoryLimit":256,"timeLimit":1000,"tests":[{"input":"7\n11\n14\n5\n4\n1\n2\n1000000000\n","output":"2 4\n4 3\n1 3\n2 1\n1 1\n1 2\n31623 14130\n","id":1629300722071}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"CInfinityTable"}},"batch":{"id":"8dcb5082-c02f-42df-aabe-28db9399836a","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/C_Infinity_Table.cpp"} -------------------------------------------------------------------------------- /.cph/.C_King_s_Path.cpp_104ad475746588e1894d200611806233.prob: -------------------------------------------------------------------------------- 1 | {"name":"C. King's Path","group":"Codeforces - Codeforces Round #149 (Div. 2)","url":"https://codeforces.com/problemset/problem/242/C","interactive":false,"memoryLimit":256,"timeLimit":2000,"tests":[{"input":"5 7 6 11\n3\n5 3 8\n6 7 11\n5 2 5","output":"4","id":1628144631539},{"input":"3 4 3 10\n3\n3 1 4\n4 5 9\n3 10 10","output":"6","id":1628144631508},{"id":1628144631554,"input":"1 1 2 10\n2\n1 1 3\n2 6 10","output":"-1"},{"id":1628157301221,"input":"13 16 20 10\n18\n13 16 16\n20 10 10\n19 10 10\n12 15 15\n20 10 10\n18 11 11\n19 10 10\n19 10 10\n20 10 10\n19 10 10\n20 10 10\n20 10 10\n19 10 10\n18 11 11\n13 16 16\n12 15 15\n19 10 10\n19 10 10","output":"-1"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"CKingsPath"}},"batch":{"id":"4241ed01-7a6a-4498-8d3a-8a612c959a60","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/C_King_s_Path.cpp"} -------------------------------------------------------------------------------- /.cph/.C_Meximum_Array.cpp_fd771bccb4c89be004f26d3434d48ca4.prob: -------------------------------------------------------------------------------- 1 | {"name":"C. Meximum Array","group":"Codeforces - Codeforces Round #767 (Div. 2)","url":"https://codeforces.com/contest/1629/problem/C","interactive":false,"memoryLimit":256,"timeLimit":2000,"tests":[{"id":1643870745936,"input":"6\n5\n1 0 2 0 3\n8\n2 2 3 4 0 1 2 0\n1\n1\n5\n0 1 2 3 4\n4\n0 1 1 0\n10\n0 0 2 1 1 1 0 0 1 1","output":"1\n4\n2\n5 1\n1\n0\n1\n5\n2\n2 2\n4\n3 2 2 0"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"CMeximumArray"}},"batch":{"id":"9a60f7ad-cb0a-4d0c-918a-fdc9ff648cb6","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/C_Meximum_Array.cpp"} -------------------------------------------------------------------------------- /.cph/.C_Not_Adjacent_Matrix.cpp_6778acdf21e53bf5fb59ea328b9b1c4c.prob: -------------------------------------------------------------------------------- 1 | {"name":"C. Not Adjacent Matrix","group":"Codeforces - Codeforces Round #719 (Div. 3)","url":"https://codeforces.com/contest/1520/problem/C","interactive":false,"memoryLimit":256,"timeLimit":4000,"tests":[{"id":1626793816614,"input":"3\n1\n2\n3","output":"1\n-1\n2 9 7\n4 6 3\n1 8 5"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"CNotAdjacentMatrix"}},"batch":{"id":"a244c562-fba7-467c-a025-113480163852","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/C_Not_Adjacent_Matrix.cpp"} -------------------------------------------------------------------------------- /.cph/.C_Not_Assigning.cpp_044d92884cb48735d6c985648d85280f.prob: -------------------------------------------------------------------------------- 1 | {"name":"C. Not Assigning","group":"Codeforces - Codeforces Round #766 (Div. 2)","url":"https://codeforces.com/contest/1627/problem/C","interactive":false,"memoryLimit":256,"timeLimit":1500,"tests":[{"id":1642261701873,"input":"3\n2\n1 2\n4\n1 3\n4 3\n2 1\n7\n1 2\n1 3\n3 4\n3 5\n6 2\n7 2","output":"17\n2 5 11\n-1"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"CNotAssigning"}},"batch":{"id":"7cdb50df-6f67-43d0-b900-f49f89bbb276","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/C_Not_Assigning.cpp"} -------------------------------------------------------------------------------- /.cph/.C_Pair_Programming.cpp_ed45a04c6ae4af53ae4a320bf41baff0.prob: -------------------------------------------------------------------------------- 1 | {"name":"C. Pair Programming","group":"Codeforces - Codeforces Round #731 (Div. 3)","url":"https://codeforces.com/contest/1547/problem/C","interactive":false,"memoryLimit":512,"timeLimit":2000,"tests":[{"id":1626706844788,"input":"5\n\n3 2 2\n2 0\n0 5\n\n4 3 2\n2 0 5\n0 6\n\n0 2 2\n1 0\n2 3\n\n5 4 4\n6 0 8 0\n0 7 0 9\n\n5 4 1\n8 7 8 0\n0","output":"2 0 0 5\n0 2 0 6 5\n-1\n0 6 0 7 0 8 0 9\n-1"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"CPairProgramming"}},"batch":{"id":"b7f945eb-032d-4059-bd2a-a73499135e34","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/C_Pair_Programming.cpp"} -------------------------------------------------------------------------------- /.cph/.C_Save_More_Mice.cpp_8195337fa971cecb2a9942eccb50adff.prob: -------------------------------------------------------------------------------- 1 | {"name":"C. Save More Mice","group":"Codeforces - Codeforces Round #748 (Div. 3)","url":"https://codeforces.com/contest/1593/problem/C","interactive":false,"memoryLimit":256,"timeLimit":4000,"tests":[{"id":1634495782256,"input":"3\n10 6\n8 7 5 4 9 4\n2 8\n1 1 1 1 1 1 1 1\n12 11\n1 2 3 4 5 6 7 8 9 10 11","output":"3\n1\n4"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"CSaveMoreMice"}},"batch":{"id":"149e65dc-ef7f-4ba7-b1af-ae192d69cbc1","size":8},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/C_Save_More_Mice.cpp"} -------------------------------------------------------------------------------- /.cph/.C_Slay_the_Dragon.cpp_5009ec2d737fcfc6416c0f8ea6a7ca49.prob: -------------------------------------------------------------------------------- 1 | {"name":"C. Slay the Dragon","group":"Codeforces - Educational Codeforces Round 114 (Rated for Div. 2)","url":"https://codeforces.com/contest/1574/problem/C","interactive":false,"memoryLimit":256,"timeLimit":2000,"tests":[{"id":1632666105183,"input":"4\n3 6 2 3\n5\n3 12\n7 9\n4 14\n1 10\n8 7","output":"1\n2\n4\n0\n2"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"CSlayTheDragon"}},"batch":{"id":"f3a71cc9-c92a-465c-9ede-6635a4d9e644","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/C_Slay_the_Dragon.cpp"} -------------------------------------------------------------------------------- /.cph/.C_Strange_Test.cpp_fed742147678a621ebe86b6f6136fc63.prob: -------------------------------------------------------------------------------- 1 | {"name":"C. Strange Test","group":"Codeforces - Codeforces Round #769 (Div. 2)","url":"https://codeforces.com/contest/1632/problem/C","interactive":false,"memoryLimit":256,"timeLimit":1000,"tests":[{"input":"5\n1 3\n5 8\n2 5\n3 19\n56678 164422","output":"1\n3\n2\n1\n23329","id":1643557117434}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"CStrangeTest"}},"batch":{"id":"9a47bbf2-bc19-465b-804f-265b2822548c","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/C_Strange_Test.cpp"} -------------------------------------------------------------------------------- /.cph/.C_Valhalla_Siege.cpp_2e506985c1957fb56f63144be2d31eb1.prob: -------------------------------------------------------------------------------- 1 | {"name":"C. Valhalla Siege","group":"Codeforces - Codeforces Round #478 (Div. 2)","url":"https://codeforces.com/contest/975/problem/C","interactive":false,"memoryLimit":256,"timeLimit":2000,"tests":[{"input":"5 5\n1 2 1 2 1\n3 10 1 1 1","output":"3\n5\n4\n4\n3","id":1630650170830},{"id":1630650170826,"input":"4 4\n1 2 3 4\n9 1 10 6","output":"1\n4\n4\n1"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"CValhallaSiege"}},"batch":{"id":"ef9aa958-d029-4423-9e5f-63a74c0256fb","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/C_Valhalla_Siege.cpp"} -------------------------------------------------------------------------------- /.cph/.C_Web_of_Lies.cpp_b2e975fc9b3471d1fb932e78985064e7.prob: -------------------------------------------------------------------------------- 1 | {"name":"C. Web of Lies","group":"Codeforces - Codeforces Round #736 (Div. 2)","url":"https://codeforces.com/contest/1549/problem/C","interactive":false,"memoryLimit":256,"timeLimit":2000,"tests":[{"input":"4 3\n2 1\n1 3\n3 4\n4\n3\n1 2 3\n2 3 1\n3","output":"2\n1","id":1628262446894},{"id":1628262446907,"input":"4 3\n2 3\n3 4\n4 1\n1\n3","output":"1"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"CWebOfLies"}},"batch":{"id":"7a5ec8db-1bf0-49bc-9dc7-1c449ea5a5ad","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/C_Web_of_Lies.cpp"} -------------------------------------------------------------------------------- /.cph/.Charmed_by_the_Game.cpp_95350db8d49ed5ecba9384a5688416a4.prob: -------------------------------------------------------------------------------- 1 | {"name":"Charmed by the Game","group":"Codeforces","url":"https://m1.codeforces.com/contest/1561/problem/B","interactive":false,"memoryLimit":512,"timeLimit":2000,"tests":[{"id":1629817757273,"input":"3\n2 1\n1 1\n0 5","output":"4\n0 1 2 3\n2\n0 2\n2\n2 3"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"CharmedByTheGame"}},"batch":{"id":"cb3303f7-e023-4fea-92c0-6b389b634c94","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/Charmed_by_the_Game.cpp"} -------------------------------------------------------------------------------- /.cph/.D1_All_are_Same.cpp_dca88526263c67f67594973b2f73ca9f.prob: -------------------------------------------------------------------------------- 1 | {"name":"D1. All are Same","group":"Codeforces - Codeforces Round #748 (Div. 3)","url":"https://codeforces.com/contest/1593/problem/D1","interactive":false,"memoryLimit":256,"timeLimit":1000,"tests":[{"input":"3\n6\n1 5 3 1 1 5\n8\n-1 0 1 -1 0 1 -1 0\n4\n100 -1000 -1000 -1000\n","output":"2\n1\n1100\n","id":1634495785848}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"D1AllAreSame"}},"batch":{"id":"149e65dc-ef7f-4ba7-b1af-ae192d69cbc1","size":8},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/D1_All_are_Same.cpp"} -------------------------------------------------------------------------------- /.cph/.D1_Two_Hundred_Twenty_One_easy_version_.cpp_88adc8996b6e7e86536ba414aab1f90b.prob: -------------------------------------------------------------------------------- 1 | {"name":"D1. Two Hundred Twenty One (easy version)","group":"Codeforces - Codeforces Round #741 (Div. 2)","url":"https://codeforces.com/contest/1562/problem/D1","interactive":false,"memoryLimit":512,"timeLimit":2000,"tests":[{"id":1629991745854,"input":"3\n14 1\n+--++---++-++-\n1 14\n14 3\n+--++---+++---\n1 14\n6 12\n3 10\n4 10\n+-+-\n1 1\n1 2\n1 3\n1 4\n2 2\n2 3\n2 4\n3 3\n3 4\n4 4","output":"2\n2\n1\n0\n1\n2\n1\n2\n1\n2\n1\n1\n2\n1"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"D1TwoHundredTwentyOneEasyVersion"}},"batch":{"id":"87dc0df7-7d45-4399-b5cf-df5685ce33f9","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/D1_Two_Hundred_Twenty_One_easy_version_.cpp"} -------------------------------------------------------------------------------- /.cph/.D1_Up_the_Strip_simplified_version_.cpp_8c2d639903b2eb3ab31539316cda6618.prob: -------------------------------------------------------------------------------- 1 | {"name":"D1. Up the Strip (simplified version)","group":"Codeforces - Codeforces Round #740 (Div. 2, based on VK Cup 2021 - Final (Engine))","url":"https://codeforces.com/contest/1561/problem/D1","interactive":false,"memoryLimit":128,"timeLimit":6000,"tests":[{"input":"3 998244353","output":"5","id":1629818185150},{"input":"5 998244353","output":"25","id":1629818185179},{"input":"42 998244353","output":"793019428","id":1629818185149}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"D1UpTheStripSimplifiedVersion"}},"batch":{"id":"4514ded9-3177-4d31-a5ae-4e6da62d0d27","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/D1_Up_the_Strip_simplified_version_.cpp"} -------------------------------------------------------------------------------- /.cph/.D2_Half_of_Same.cpp_aa36b27864627a5a8326675b98721690.prob: -------------------------------------------------------------------------------- 1 | {"name":"D2. Half of Same","group":"Codeforces - Codeforces Round #748 (Div. 3)","url":"https://codeforces.com/contest/1593/problem/D2","interactive":false,"memoryLimit":256,"timeLimit":1000,"tests":[{"input":"4\n6\n48 13 22 -15 16 35\n8\n-1 0 1 -1 0 1 -1 0\n4\n100 -1000 -1000 -1000\n4\n1 1 1 1\n","output":"13\n2\n-1\n-1\n","id":1634495789453}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"D2HalfOfSame"}},"batch":{"id":"149e65dc-ef7f-4ba7-b1af-ae192d69cbc1","size":8},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/D2_Half_of_Same.cpp"} -------------------------------------------------------------------------------- /.cph/.D_Co_growing_Sequence.cpp_2f7468975ced6fa819b6051575e79706.prob: -------------------------------------------------------------------------------- 1 | {"name":"D. Co-growing Sequence","group":"Codeforces - Codeforces Round #731 (Div. 3)","url":"https://codeforces.com/contest/1547/problem/D","interactive":false,"memoryLimit":512,"timeLimit":2000,"tests":[{"id":1626706853492,"input":"5\n4\n1 3 7 15\n4\n1 2 4 8\n5\n1 2 3 4 5\n4\n11 13 15 1\n1\n0","output":"0 0 0 0\n0 1 3 7\n0 1 0 3 2\n0 2 0 14\n0"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"DCoGrowingSequence"}},"batch":{"id":"bc5b0736-0c09-4571-9e02-22c37139af7a","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/D_Co_growing_Sequence.cpp"} -------------------------------------------------------------------------------- /.cph/.D_Lunar_New_Year_and_a_Wander.cpp_5ae855a2a614db3fd52711bee2ffd72c.prob: -------------------------------------------------------------------------------- 1 | {"name":"D. Lunar New Year and a Wander","group":"Codeforces - Codeforces Round #536 (Div. 2)","url":"https://codeforces.com/problemset/problem/1106/D","interactive":false,"memoryLimit":256,"timeLimit":3000,"tests":[{"input":"3 2\n1 2\n1 3","output":"1 2 3","id":1629320866862},{"input":"5 5\n1 4\n3 4\n5 4\n3 2\n1 5","output":"1 4 3 2 5","id":1629320866822},{"id":1629320866837,"input":"10 10\n1 4\n6 8\n2 5\n3 7\n9 4\n5 6\n3 4\n8 10\n8 9\n1 10","output":"1 4 3 7 9 8 6 5 2 10"},{"id":1629351844923,"input":"7 6\n1 2\n2 5\n5 3\n5 4\n3 6\n3 7","output":"1 2 5 3 4 6 7"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"DLunarNewYearAndAWander"}},"batch":{"id":"f93b1f39-0972-4e64-843d-bd3641fef270","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/D_Lunar_New_Year_and_a_Wander.cpp"} -------------------------------------------------------------------------------- /.cph/.D_Productive_Meeting.cpp_aba41bf44ded43530c8218f14cda3e46.prob: -------------------------------------------------------------------------------- 1 | {"name":"D. Productive Meeting","group":"Codeforces - Codeforces Round #744 (Div. 3)","url":"https://codeforces.com/contest/1579/problem/D","interactive":false,"memoryLimit":256,"timeLimit":2000,"tests":[{"input":"8\n2\n2 3\n3\n1 2 3\n4\n1 2 3 4\n3\n0 0 2\n2\n6 2\n3\n0 0 2\n5\n8 2 0 1 1\n5\n0 1 0 0 6","output":"2\n1 2\n1 2\n3\n1 3\n2 3\n2 3\n5\n1 3\n2 4\n2 4\n3 4\n3 4\n0\n2\n1 2\n1 2\n0\n4\n1 2\n1 5\n1 4\n1 2\n1\n5 2","id":1632843441660},{"id":1632843867335,"input":"1\n4\n1 2 3 4","output":""}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"DProductiveMeeting"}},"batch":{"id":"596a769c-61fa-4cf6-b7f8-a9e9b9c05968","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/D_Productive_Meeting.cpp"} -------------------------------------------------------------------------------- /.cph/.D_Same_Differences.cpp_e6fc074ea04ecc7f44b9b62624c93372.prob: -------------------------------------------------------------------------------- 1 | {"name":"D. Same Differences","group":"Codeforces - Codeforces Round #719 (Div. 3)","url":"https://codeforces.com/contest/1520/problem/D","interactive":false,"memoryLimit":256,"timeLimit":2000,"tests":[{"id":1626813489835,"input":"4\n6\n3 5 1 4 6 6\n3\n1 2 3\n4\n1 3 3 4\n6\n1 6 3 4 5 6","output":"1\n3\n3\n10"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"DSameDifferences"}},"batch":{"id":"c47d37e1-3803-4456-b484-bd642c231d89","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/D_Same_Differences.cpp"} -------------------------------------------------------------------------------- /.cph/.D_Secret_Passwords.cpp_5d3c4e93d26b4ae92c92ce8f3d832d82.prob: -------------------------------------------------------------------------------- 1 | {"name":"D. Secret Passwords","group":"Codeforces - Codeforces Round #603 (Div. 2)","url":"https://codeforces.com/contest/1263/problem/D","interactive":false,"memoryLimit":256,"timeLimit":1000,"tests":[{"input":"4\na\nb\nab\nd","output":"2","id":1630682026457},{"input":"3\nab\nbc\nabc","output":"1","id":1630682026443},{"id":1630682026474,"input":"1\ncodeforces","output":"1"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"DSecretPasswords"}},"batch":{"id":"d5097367-bcb2-4a0e-8514-d5b851c7f443","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/D_Secret_Passwords.cpp"} -------------------------------------------------------------------------------- /.cph/.E1_Permutation_Minimization_by_Deque.cpp_23a8ade3caa4c816e674e8f9fe4b0879.prob: -------------------------------------------------------------------------------- 1 | {"name":"E1. Permutation Minimization by Deque","group":"Codeforces - Codeforces Round #744 (Div. 3)","url":"https://codeforces.com/contest/1579/problem/E1","interactive":false,"memoryLimit":256,"timeLimit":2000,"tests":[{"input":"5\n4\n3 1 2 4\n3\n3 2 1\n3\n3 1 2\n2\n1 2\n2\n2 1","output":"1 3 2 4\n1 2 3\n1 3 2\n1 2\n1 2","id":1632842208352}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"E1PermutationMinimizationByDeque"}},"batch":{"id":"1c6487b8-26ed-4902-a43e-b9ccdfa58e43","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/E1_Permutation_Minimization_by_Deque.cpp"} -------------------------------------------------------------------------------- /.cph/.E_Air_Conditioners.cpp_5194b95a134ec708eaebd5e87be33de3.prob: -------------------------------------------------------------------------------- 1 | {"name":"E. Air Conditioners","group":"Codeforces - Codeforces Round #731 (Div. 3)","url":"https://codeforces.com/contest/1547/problem/E","interactive":false,"memoryLimit":512,"timeLimit":2000,"tests":[{"id":1626706804926,"input":"5\n\n6 2\n2 5\n14 16\n\n10 1\n7\n30\n\n5 5\n3 1 4 2 5\n3 1 4 2 5\n\n7 1\n1\n1000000000\n\n6 3\n6 1 3\n5 5 5","output":"15 14 15 16 16 17\n36 35 34 33 32 31 30 31 32 33\n1 2 3 4 5\n1000000000 1000000001 1000000002 1000000003 1000000004 1000000005 1000000006\n5 6 5 6 6 5"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"EAirConditioners"}},"batch":{"id":"f5956761-d466-4d24-a56b-be04b9bebf88","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/E_Air_Conditioners.cpp"} -------------------------------------------------------------------------------- /.cph/.E_Arranging_The_Sheep.cpp_7b2ee259410e2d50289eae742d671367.prob: -------------------------------------------------------------------------------- 1 | {"name":"E. Arranging The Sheep","group":"Codeforces - Codeforces Round #719 (Div. 3)","url":"https://codeforces.com/contest/1520/problem/E","interactive":false,"memoryLimit":256,"timeLimit":2000,"tests":[{"id":1626939516333,"input":"5\n6\n**.*..\n5\n*****\n3\n.*.\n3\n...\n10\n*.*...*.**","output":"1\n0\n0\n0\n9"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"EArrangingTheSheep"}},"batch":{"id":"b7f2b385-7f30-4c64-9076-53b21d9305e5","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/E_Arranging_The_Sheep.cpp"} -------------------------------------------------------------------------------- /.cph/.E_Gardener_and_Tree.cpp_104dacd828b8757284155dc431096fb7.prob: -------------------------------------------------------------------------------- 1 | {"name":"E. Gardener and Tree","group":"Codeforces - Codeforces Round #748 (Div. 3)","url":"https://codeforces.com/contest/1593/problem/E","interactive":false,"memoryLimit":256,"timeLimit":4000,"tests":[{"input":"6\n\n14 1\n1 2\n2 3\n2 4\n4 5\n4 6\n2 7\n7 8\n8 9\n8 10\n3 11\n3 12\n1 13\n13 14\n\n2 200000\n1 2\n\n3 2\n1 2\n2 3\n\n5 1\n5 1\n3 2\n2 1\n5 4\n\n6 2\n5 1\n2 5\n5 6\n4 2\n3 4\n\n7 1\n4 3\n5 1\n1 3\n6 1\n1 7\n2 1\n","output":"7\n0\n0\n3\n1\n2\n","id":1634495792946}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"EGardenerAndTree"}},"batch":{"id":"149e65dc-ef7f-4ba7-b1af-ae192d69cbc1","size":8},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/E_Gardener_and_Tree.cpp"} -------------------------------------------------------------------------------- /.cph/.F_Red_Black_Number.cpp_d1d40bfcebb8b4243eae6a66de23af44.prob: -------------------------------------------------------------------------------- 1 | {"name":"F. Red-Black Number","group":"Codeforces - Codeforces Round #748 (Div. 3)","url":"https://codeforces.com/contest/1593/problem/F","interactive":false,"memoryLimit":256,"timeLimit":1000,"tests":[{"input":"4\n5 3 13\n02165\n4 2 1\n1357\n8 1 1\n12345678\n2 7 9\n90\n","output":"RBRBR\n-1\nBBRRRRBB\nBR\n","id":1634495796446}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"FRedBlackNumber"}},"batch":{"id":"149e65dc-ef7f-4ba7-b1af-ae192d69cbc1","size":8},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/F_Red_Black_Number.cpp"} -------------------------------------------------------------------------------- /.cph/.G_Changing_Brackets.cpp_37e1b9365ce0f3899992b620105a7bd5.prob: -------------------------------------------------------------------------------- 1 | {"name":"G. Changing Brackets","group":"Codeforces - Codeforces Round #748 (Div. 3)","url":"https://codeforces.com/contest/1593/problem/G","interactive":false,"memoryLimit":256,"timeLimit":2000,"tests":[{"input":"3\n([))[)()][]]\n3\n1 12\n4 9\n3 6\n))))))\n2\n2 3\n1 4\n[]\n1\n1 2\n","output":"0\n2\n1\n0\n0\n0\n","id":1634495800041}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"GChangingBrackets"}},"batch":{"id":"149e65dc-ef7f-4ba7-b1af-ae192d69cbc1","size":8},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/G_Changing_Brackets.cpp"} -------------------------------------------------------------------------------- /.cph/.Prime_Generator.cpp_8da4a72df0dfdc8a25da70ac2c94826f.prob: -------------------------------------------------------------------------------- 1 | {"name":"Prime Generator","group":"SPOJ - Classical","url":"https://www.spoj.com/problems/PRIME1/","interactive":false,"memoryLimit":1536,"timeLimit":6000,"tests":[{"id":1627675467324,"input":"3\n1 10\n3 5\n10 50","output":"2\n3\n5\n7\n\n3\n5\n\n11\n13\n17\n19\n23\n29\n31\n37\n41\n43\n47"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"PrimeGenerator"}},"batch":{"id":"8c6147e7-a766-4929-81ad-5b798cfb2ec1","size":1},"srcPath":"/home/bihan/codes/cp-dsa-questions/codeforces/Prime_Generator.cpp"} -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.exe -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "g++ - Build and debug active file", 9 | "type": "cppdbg", 10 | "request": "launch", 11 | "program": "${fileDirname}/${fileBasenameNoExtension}", 12 | "args": [], 13 | "stopAtEntry": false, 14 | "cwd": "${fileDirname}", 15 | "environment": [], 16 | "externalConsole": false, 17 | "MIMode": "gdb", 18 | "setupCommands": [ 19 | { 20 | "description": "Enable pretty-printing for gdb", 21 | "text": "-enable-pretty-printing", 22 | "ignoreFailures": true 23 | } 24 | ], 25 | "preLaunchTask": "C/C++: g++ build active file", 26 | "miDebuggerPath": "/usr/bin/gdb" 27 | } 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "C_Cpp.clang_format_fallbackStyle": "{ BasedOnStyle: Google, IndentWidth: 4, ColumnLimit: 150, AllowShortIfStatementsOnASingleLine: true, UseTab: Never}", 3 | "files.associations": { 4 | "iostream": "cpp", 5 | "ostream": "cpp", 6 | "*.tcc": "cpp", 7 | "deque": "cpp", 8 | "list": "cpp", 9 | "string": "cpp", 10 | "unordered_map": "cpp", 11 | "unordered_set": "cpp", 12 | "vector": "cpp", 13 | "ratio": "cpp", 14 | "string_view": "cpp" 15 | }, 16 | "C_Cpp.clang_format_style": "{ BasedOnStyle: Google, IndentWidth: 4, ColumnLimit: 150, AllowShortIfStatementsOnASingleLine: true, UseTab: Never}", 17 | "workbench.colorCustomizations": { 18 | "activityBar.background": "#002d35", 19 | "titleBar.activeBackground": "#002d35", 20 | "titleBar.activeForeground": "#dfdfdf" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "tasks": [ 3 | { 4 | "type": "cppbuild", 5 | "label": "C/C++: g++ build active file", 6 | "command": "/usr/bin/g++", 7 | "args": ["-g", "${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}"], 8 | "options": { 9 | "cwd": "${fileDirname}" 10 | }, 11 | "problemMatcher": ["$gcc"], 12 | "group": { 13 | "kind": "build", 14 | "isDefault": true 15 | }, 16 | "detail": "Task generated by Debugger." 17 | } 18 | ], 19 | "version": "2.0.0" 20 | } 21 | -------------------------------------------------------------------------------- /A_ABC.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define int long long int 9 | #define vi vector 10 | #define pii pair 11 | #define pb push_back 12 | #define mp make_pair 13 | #define all(a) a.begin(), a.end() 14 | const int MOD = 1e9 + 7; 15 | const int INF = 1e18; 16 | #define inputarr(arr, n) \ 17 | for (int i = 0; i < n; i++) cin >> arr[i]; 18 | #define printarr(arr, n) \ 19 | for (int i = 0; i < n; i++) cout << arr[i] << ' '; 20 | 21 | void solve() { 22 | int n; 23 | cin >> n; 24 | string s; 25 | cin >> s; 26 | if (n > 2) 27 | cout << "NO" << endl; 28 | else { 29 | if (n == 1) 30 | cout << "YES" << endl; 31 | else { 32 | if (s[0] == s[1]) 33 | cout << "NO" << endl; 34 | else 35 | cout << "YES" << endl; 36 | } 37 | } 38 | } 39 | 40 | // 101010 41 | 42 | int32_t main() { 43 | ios_base::sync_with_stdio(false); 44 | cin.tie(0); 45 | cout.tie(0); 46 | int t = 1; 47 | cin >> t; 48 | while (t--) { 49 | solve(); 50 | } 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /A_And_Matching.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define int long long int 9 | #define vi vector 10 | #define pii pair 11 | #define pb push_back 12 | #define mp make_pair 13 | #define all(a) a.begin(), a.end() 14 | const int MOD = 1e9 + 7; 15 | const int INF = 1e18; 16 | #define inputarr(arr, n) \ 17 | for (int i = 0; i < n; i++) cin >> arr[i]; 18 | #define printarr(arr, n) \ 19 | for (int i = 0; i < n; i++) cout << arr[i] << ' '; 20 | 21 | void solve() { 22 | int n, k; 23 | cin >> n >> k; 24 | int l = 0, r = n - 1; 25 | if (k == 0) { 26 | while (l < r) { 27 | cout << l << ' ' << r << endl; 28 | l++, r--; 29 | } 30 | return; 31 | } 32 | if (k == n - 1) { 33 | if (n < 8) { 34 | cout << -1 << endl; 35 | return; 36 | } 37 | cout << n - 1 << ' ' << n - 2 << endl; 38 | cout << n - 3 << ' ' << 1 << endl; 39 | cout << 0 << ' ' << 2 << endl; 40 | l = 3, r = n - 4; 41 | while (l < r) { 42 | cout << l << ' ' << r << endl; 43 | l++, r--; 44 | } 45 | return; 46 | } 47 | cout << k << ' ' << n - 1 << endl; 48 | l = 1, r = n - 2; 49 | while (l < r) { 50 | if (l != k && r != k) { 51 | cout << l << ' ' << r << endl; 52 | } else { 53 | if (l == k) { 54 | cout << 0 << ' ' << r << endl; 55 | } else { 56 | cout << 0 << ' ' << l << endl; 57 | } 58 | } 59 | l++, r--; 60 | } 61 | } 62 | 63 | int32_t main() { 64 | ios_base::sync_with_stdio(false); 65 | cin.tie(0); 66 | cout.tie(0); 67 | int t = 1; 68 | cin >> t; 69 | while (t--) { 70 | solve(); 71 | } 72 | return 0; 73 | } 74 | -------------------------------------------------------------------------------- /A_Casimir_s_String_Solitaire.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define int long long int 9 | #define vi vector 10 | #define pii pair 11 | #define pb push_back 12 | #define mp make_pair 13 | #define all(a) a.begin(), a.end() 14 | const int MOD = 1e9 + 7; 15 | const int INF = 1e18; 16 | #define inputarr(arr, n) \ 17 | for (int i = 0; i < n; i++) cin >> arr[i]; 18 | #define printarr(arr, n) \ 19 | for (int i = 0; i < n; i++) cout << arr[i] << ' '; 20 | 21 | void solve() { 22 | string s; 23 | cin >> s; 24 | unordered_map hash; 25 | for (char c : s) hash[c]++; 26 | bool f = true; 27 | while (true) { 28 | if (hash['A'] > 0 && hash['B'] > 0) { 29 | hash['A']--, hash['B']--; 30 | } else if (hash['B'] > 0 && hash['C'] > 0) { 31 | hash['B']--, hash['C']--; 32 | } else { 33 | if (hash['A'] == 0 && hash['B'] == 0 && hash['C'] == 0) { 34 | f = true; 35 | } else { 36 | f = false; 37 | } 38 | break; 39 | } 40 | } 41 | if (f) 42 | cout << "YES"; 43 | else 44 | cout << "NO"; 45 | cout << endl; 46 | } 47 | 48 | int32_t main() { 49 | ios_base::sync_with_stdio(false); 50 | cin.tie(0); 51 | cout.tie(0); 52 | int t = 1; 53 | cin >> t; 54 | while (t--) { 55 | solve(); 56 | } 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /A_Cherry.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define ll long long 9 | #define vi vector 10 | #define vll vector 11 | #define pii pair 12 | #define pll pair 13 | #define pb push_back 14 | #define mp make_pair 15 | const int MOD = 1e9 + 7; 16 | const ll INF = 1e18; 17 | #define inputarr(arr, n) \ 18 | for (ll i = 0; i < n; i++) cin >> arr[i]; 19 | #define printarr(arr, n) \ 20 | for (ll i = 0; i < n; i++) cout << arr[i] << ' '; 21 | 22 | void solve() { 23 | ll n; 24 | cin >> n; 25 | vll arr(n); 26 | inputarr(arr, n); 27 | if (n == 2) { 28 | cout << arr[0] * arr[1] << endl; 29 | return; 30 | } 31 | vll muls(n, 0); 32 | muls[0] = arr[0] * arr[1]; 33 | muls[n - 1] = arr[n - 1] * arr[n - 2]; 34 | for (int i = 1; i < n - 1; i++) { 35 | muls[i] = max(arr[i] * arr[i - 1], arr[i] * arr[i + 1]); 36 | } 37 | cout << *max_element(muls.begin(), muls.end()) << endl; 38 | } 39 | 40 | int main() { 41 | ios_base::sync_with_stdio(false); 42 | cin.tie(0); 43 | cout.tie(0); 44 | int t = 1; 45 | cin >> t; 46 | while (t--) { 47 | solve(); 48 | } 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /A_Dislike_of_Threes.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define ll long long 9 | #define vi vector 10 | #define vll vector 11 | #define pii pair 12 | #define pll pair 13 | #define pb push_back 14 | #define mp make_pair 15 | const int MOD = 1e9 + 7; 16 | const ll INF = 1e18; 17 | #define inputarr(arr, n) \ 18 | for (ll i = 0; i < n; i++) cin >> arr[i]; 19 | #define printarr(arr, n) \ 20 | for (ll i = 0; i < n; i++) cout << arr[i] << ' '; 21 | 22 | void solve() { 23 | ll n; 24 | cin >> n; 25 | vll arr; 26 | for (int i = 1; i <= 1000000; i++) { 27 | if (i % 3 == 0 || i % 10 == 3) continue; 28 | arr.pb(i); 29 | } 30 | cout << arr[n - 1] << endl; 31 | } 32 | 33 | int main() { 34 | ios_base::sync_with_stdio(false); 35 | cin.tie(0); 36 | cout.tie(0); 37 | int t = 1; 38 | cin >> t; 39 | while (t--) { 40 | solve(); 41 | } 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /A_Do_Not_Be_Distracted_.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define ll long long 9 | #define vi vector 10 | #define vll vector 11 | #define pii pair 12 | #define pll pair 13 | #define pb push_back 14 | #define mp make_pair 15 | const int MOD = 1e9 + 7; 16 | const ll INF = 1e18; 17 | #define inputarr(arr, n) \ 18 | for (ll i = 0; i < n; i++) cin >> arr[i]; 19 | #define printarr(arr, n) \ 20 | for (ll i = 0; i < n; i++) cout << arr[i] << ' '; 21 | 22 | void solve() { 23 | int n; 24 | cin >> n; 25 | string s; 26 | cin >> s; 27 | map hash; 28 | char prev = s[0]; 29 | hash[s[0]] = true; 30 | for (int i = 1; i < n; i++) { 31 | if (s[i] == prev) { 32 | hash[s[i]] = true; 33 | } else { 34 | if (hash[s[i]] == true) { 35 | cout << "NO\n"; 36 | return; 37 | } else { 38 | hash[s[i]] = true; 39 | prev = s[i]; 40 | } 41 | } 42 | } 43 | cout << "YES\n"; 44 | } 45 | 46 | int main() { 47 | ios_base::sync_with_stdio(false); 48 | cin.tie(0); 49 | cout.tie(0); 50 | int t = 1; 51 | cin >> t; 52 | while (t--) { 53 | solve(); 54 | } 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /A_Domino_Disaster.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define int long long int 9 | #define vi vector 10 | #define pii pair 11 | #define pb push_back 12 | #define mp make_pair 13 | #define all(a) a.begin(), a.end() 14 | const int MOD = 1e9 + 7; 15 | const int INF = 1e18; 16 | #define inputarr(arr, n) \ 17 | for (int i = 0; i < n; i++) cin >> arr[i]; 18 | #define printarr(arr, n) \ 19 | for (int i = 0; i < n; i++) cout << arr[i] << ' '; 20 | 21 | void solve() { 22 | int n; 23 | cin >> n; 24 | string s, t = ""; 25 | cin >> s; 26 | for (int i = 0; i < n; i++) { 27 | if (s[i] == 'U') 28 | t += 'D'; 29 | else if (s[i] == 'D') 30 | t += 'U'; 31 | else 32 | t += s[i]; 33 | } 34 | cout << t << endl; 35 | } 36 | 37 | int32_t main() { 38 | ios_base::sync_with_stdio(false); 39 | cin.tie(0); 40 | cout.tie(0); 41 | int t = 1; 42 | cin >> t; 43 | while (t--) { 44 | solve(); 45 | } 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /A_Download_More_RAM.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define int long long int 9 | #define vi vector 10 | #define pii pair 11 | #define pb push_back 12 | #define mp make_pair 13 | #define all(a) a.begin(), a.end() 14 | const int MOD = 1e9 + 7; 15 | const int INF = 1e18; 16 | #define inputarr(arr, n) \ 17 | for (int i = 0; i < n; i++) cin >> arr[i]; 18 | #define printarr(arr, n) \ 19 | for (int i = 0; i < n; i++) cout << arr[i] << ' '; 20 | 21 | void solve() { 22 | int n, k; 23 | cin >> n >> k; 24 | vector arr(n); 25 | for (int i = 0; i < n; i++) { 26 | int x; 27 | cin >> x; 28 | arr[i].first = x; 29 | } 30 | for (int i = 0; i < n; i++) { 31 | int x; 32 | cin >> x; 33 | arr[i].second = x; 34 | } 35 | sort(all(arr)); 36 | for (int i = 0; i < n; i++) { 37 | if (arr[i].first <= k) { 38 | k += arr[i].second; 39 | } else { 40 | break; 41 | } 42 | } 43 | cout << k << endl; 44 | } 45 | 46 | int32_t main() { 47 | ios_base::sync_with_stdio(false); 48 | cin.tie(0); 49 | cout.tie(0); 50 | int t = 1; 51 | cin >> t; 52 | while (t--) { 53 | solve(); 54 | } 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /A_Elections.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define int long long int 9 | #define vi vector 10 | #define pii pair 11 | #define pb push_back 12 | #define mp make_pair 13 | #define all(a) a.begin(), a.end() 14 | const int MOD = 1e9 + 7; 15 | const int INF = 1e18; 16 | #define inputarr(arr, n) \ 17 | for (int i = 0; i < n; i++) cin >> arr[i]; 18 | #define printarr(arr, n) \ 19 | for (int i = 0; i < n; i++) cout << arr[i] << ' '; 20 | 21 | void solve() { 22 | int a, b, c; 23 | cin >> a >> b >> c; 24 | if (a == b && b == c) { 25 | cout << 1 << ' ' << 1 << ' ' << 1 << endl; 26 | return; 27 | } 28 | if (a == b) { 29 | if (a < c) { 30 | cout << c - a + 1 << ' ' << c - b + 1 << ' ' << 0 << endl; 31 | return; 32 | } 33 | cout << 1 << ' ' << 1 << ' ' << a - c + 1 << endl; 34 | return; 35 | } 36 | if (b == c) { 37 | if (a < b) { 38 | cout << b - a + 1 << ' ' << 1 << ' ' << 1 << endl; 39 | return; 40 | } 41 | cout << 0 << ' ' << a - b + 1 << ' ' << a - c + 1 << endl; 42 | return; 43 | } 44 | if (a == c) { 45 | if (b > a) { 46 | cout << b - a + 1 << ' ' << 0 << ' ' << b - c + 1 << endl; 47 | return; 48 | } 49 | cout << 1 << ' ' << a - b + 1 << ' ' << 1 << endl; 50 | return; 51 | } 52 | int m = max({a, b, c}); 53 | if (m == a) 54 | cout << 0 << ' '; 55 | else 56 | cout << m - a + 1 << ' '; 57 | if (m == b) 58 | cout << 0 << ' '; 59 | else 60 | cout << m - b + 1 << ' '; 61 | if (m == c) 62 | cout << 0 << ' '; 63 | else 64 | cout << m - c + 1; 65 | cout << endl; 66 | } 67 | 68 | int32_t main() { 69 | ios_base::sync_with_stdio(false); 70 | cin.tie(0); 71 | cout.tie(0); 72 | int t = 1; 73 | cin >> t; 74 | while (t--) { 75 | solve(); 76 | } 77 | return 0; 78 | } 79 | -------------------------------------------------------------------------------- /A_Ezzat_and_Two_Subsequences.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define ll long long 9 | #define vi vector 10 | #define vll vector 11 | #define pii pair 12 | #define pll pair 13 | #define pb push_back 14 | #define mp make_pair 15 | const int MOD = 1e9 + 7; 16 | const ll INF = 1e18; 17 | #define inputarr(arr, n) \ 18 | for (ll i = 0; i < n; i++) cin >> arr[i]; 19 | #define printarr(arr, n) \ 20 | for (ll i = 0; i < n; i++) cout << arr[i] << ' '; 21 | 22 | void solve() { 23 | ll n; 24 | cin >> n; 25 | vll arr(n); 26 | inputarr(arr, n); 27 | sort(arr.begin(), arr.end()); 28 | double sum = 0; 29 | for (int i = 0; i < n - 1; i++) sum += arr[i]; 30 | cout << fixed << setprecision(9) << (double)arr[n - 1] + (sum / (n - 1)) << endl; 31 | } 32 | 33 | int main() { 34 | ios_base::sync_with_stdio(false); 35 | cin.tie(0); 36 | cout.tie(0); 37 | int t = 1; 38 | cin >> t; 39 | while (t--) { 40 | solve(); 41 | } 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /A_Find_The_Array.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define ll long long 9 | #define vi vector 10 | #define vll vector 11 | #define pii pair 12 | #define pll pair 13 | #define pb push_back 14 | #define mp make_pair 15 | const int MOD = 1e9 + 7; 16 | const ll INF = 1e18; 17 | #define inputarr(arr, n) \ 18 | for (ll i = 0; i < n; i++) cin >> arr[i]; 19 | #define printarr(arr, n) \ 20 | for (ll i = 0; i < n; i++) cout << arr[i] << ' '; 21 | 22 | void solve() { 23 | int s; 24 | cin >> s; 25 | vi arr; 26 | int sum = 0, start = 1; 27 | while (sum < s) { 28 | sum += start; 29 | arr.pb(sum); 30 | if (s - sum >= 2) start += 2; 31 | if (s - sum == 1) start += 1; 32 | } 33 | cout << arr.size() << endl; 34 | } 35 | 36 | int main() { 37 | ios_base::sync_with_stdio(false); 38 | cin.tie(0); 39 | cout.tie(0); 40 | int t = 1; 41 | cin >> t; 42 | while (t--) { 43 | solve(); 44 | } 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /A_Gregor_and_Cryptography.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define ll long long 9 | #define vi vector 10 | #define vll vector 11 | #define pii pair 12 | #define pll pair 13 | #define pb push_back 14 | #define mp make_pair 15 | const int MOD = 1e9 + 7; 16 | const ll INF = 1e18; 17 | #define inputarr(arr, n) \ 18 | for (ll i = 0; i < n; i++) cin >> arr[i]; 19 | #define printarr(arr, n) \ 20 | for (ll i = 0; i < n; i++) cout << arr[i] << ' '; 21 | 22 | void solve() { 23 | ll p; 24 | cin >> p; 25 | if (p == 5) { 26 | cout << 2 << ' ' << 4 << endl; 27 | return; 28 | } 29 | p -= 1; 30 | cout << 2 << ' ' << p / 2 << endl; 31 | } 32 | 33 | int main() { 34 | ios_base::sync_with_stdio(false); 35 | cin.tie(0); 36 | cout.tie(0); 37 | int t = 1; 38 | cin >> t; 39 | while (t--) { 40 | solve(); 41 | } 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /A_Min_Max_Swap.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define int long long int 9 | #define vi vector 10 | #define pii pair 11 | #define pb push_back 12 | #define mp make_pair 13 | #define all(a) a.begin(), a.end() 14 | const int MOD = 1e9 + 7; 15 | const int INF = 1e18; 16 | #define inputarr(arr, n) \ 17 | for (int i = 0; i < n; i++) cin >> arr[i]; 18 | #define printarr(arr, n) \ 19 | for (int i = 0; i < n; i++) cout << arr[i] << ' '; 20 | 21 | void solve() { 22 | int n; 23 | cin >> n; 24 | vi a(n), b(n); 25 | inputarr(a, n); 26 | inputarr(b, n); 27 | for (int i = 0; i < n; i++) { 28 | if (b[i] > a[i]) swap(a[i], b[i]); 29 | } 30 | cout << *max_element(all(a)) * *max_element(all(b)) << endl; 31 | } 32 | 33 | int32_t main() { 34 | ios_base::sync_with_stdio(false); 35 | cin.tie(0); 36 | cout.tie(0); 37 | int t = 1; 38 | cin >> t; 39 | while (t--) { 40 | solve(); 41 | } 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /A_Not_Shading.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define int long long int 9 | #define vi vector 10 | #define pii pair 11 | #define pb push_back 12 | #define mp make_pair 13 | #define all(a) a.begin(), a.end() 14 | const int MOD = 1e9 + 7; 15 | const int INF = 1e18; 16 | #define inputarr(arr, n) \ 17 | for (int i = 0; i < n; i++) cin >> arr[i]; 18 | #define printarr(arr, n) \ 19 | for (int i = 0; i < n; i++) cout << arr[i] << ' '; 20 | 21 | void solve() { 22 | int n, m, r, c; 23 | cin >> n >> m >> r >> c; 24 | r--, c--; 25 | vector> arr(n, vector(m)); 26 | bool blackPresent = false; 27 | for (int i = 0; i < n; i++) { 28 | for (int j = 0; j < m; j++) { 29 | cin >> arr[i][j]; 30 | if (arr[i][j] == 'B') blackPresent = true; 31 | } 32 | } 33 | if (!blackPresent) { 34 | cout << -1 << endl; 35 | return; 36 | } 37 | if (arr[r][c] == 'B') { 38 | cout << 0 << endl; 39 | return; 40 | } 41 | bool f = false; 42 | for (int i = 0; i < m; i++) { 43 | if (arr[r][i] == 'B') { 44 | f = true; 45 | break; 46 | } 47 | } 48 | if (!f) { 49 | for (int i = 0; i < n; i++) { 50 | if (arr[i][c] == 'B') { 51 | f = true; 52 | break; 53 | } 54 | } 55 | } 56 | if (f) { 57 | cout << 1 << endl; 58 | return; 59 | } 60 | cout << 2 << endl; 61 | } 62 | 63 | int32_t main() { 64 | ios_base::sync_with_stdio(false); 65 | cin.tie(0); 66 | cout.tie(0); 67 | int t = 1; 68 | cin >> t; 69 | while (t--) { 70 | solve(); 71 | } 72 | return 0; 73 | } 74 | -------------------------------------------------------------------------------- /A_PizzaForces.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define ll long long 9 | #define vi vector 10 | #define vll vector 11 | #define pii pair 12 | #define pll pair 13 | #define pb push_back 14 | #define mp make_pair 15 | const int MOD = 1e9 + 7; 16 | const ll INF = 1e18; 17 | #define inputarr(arr, n) \ 18 | for (ll i = 0; i < n; i++) cin >> arr[i]; 19 | #define printarr(arr, n) \ 20 | for (ll i = 0; i < n; i++) cout << arr[i] << ' '; 21 | 22 | void solve() { 23 | unsigned ll n; 24 | cin >> n; 25 | if (n % 2) n++; 26 | if (n <= 6) { 27 | cout << 15 << endl; 28 | return; 29 | } 30 | cout << (n * 5) / 2 << endl; 31 | } 32 | 33 | int main() { 34 | ios_base::sync_with_stdio(false); 35 | cin.tie(0); 36 | cout.tie(0); 37 | int t = 1; 38 | cin >> t; 39 | while (t--) { 40 | solve(); 41 | } 42 | return 0; 43 | } 44 | 45 | // 6 8 10 12 14 16 18 20 46 | // 15 20 25 30 35 40 45 50 -------------------------------------------------------------------------------- /A_Regular_Bracket_Sequences.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define int long long int 9 | #define vi vector 10 | #define pii pair 11 | #define pb push_back 12 | #define mp make_pair 13 | #define all(a) a.begin(), a.end() 14 | const int MOD = 1e9 + 7; 15 | const int INF = 1e18; 16 | #define inputarr(arr, n) \ 17 | for (int i = 0; i < n; i++) cin >> arr[i]; 18 | #define printarr(arr, n) \ 19 | for (int i = 0; i < n; i++) cout << arr[i] << ' '; 20 | 21 | vector res; 22 | void backtrack(string s, int open, int close, int n) { 23 | if (res.size() >= n) return; 24 | if (s.length() == n * 2) { 25 | res.push_back(s); 26 | return; 27 | } 28 | if (open < n) backtrack(s + "(", open + 1, close, n); 29 | if (close < open) backtrack(s + ")", open, close + 1, n); 30 | } 31 | 32 | void solve() { 33 | int n; 34 | cin >> n; 35 | res.clear(); 36 | backtrack("", 0, 0, n); 37 | for (int i = 0; i < n; i++) cout << res[i] << endl; 38 | } 39 | 40 | int32_t main() { 41 | ios_base::sync_with_stdio(false); 42 | cin.tie(0); 43 | cout.tie(0); 44 | int t = 1; 45 | cin >> t; 46 | while (t--) { 47 | solve(); 48 | } 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /A_Shortest_Path_with_Obstacle.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define ll long long 9 | #define vi vector 10 | #define vll vector 11 | #define pii pair 12 | #define pll pair 13 | #define pb push_back 14 | #define mp make_pair 15 | const int MOD = 1e9 + 7; 16 | const ll INF = 1e18; 17 | #define inputarr(arr, n) \ 18 | for (ll i = 0; i < n; i++) cin >> arr[i]; 19 | #define printarr(arr, n) \ 20 | for (ll i = 0; i < n; i++) cout << arr[i] << ' '; 21 | 22 | void solve() { 23 | int xa, ya, xb, yb, xf, yf; 24 | cin >> ya >> xa >> yb >> xb >> yf >> xf; 25 | int dist = abs(xa - xb) + abs(ya - yb); 26 | if (xa == xb) { 27 | if (xf == xa) { 28 | if ((yf < ya && yf > yb) || (yf > ya && yf < yb)) { 29 | dist += 2; 30 | } 31 | } 32 | } else if (ya == yb) { 33 | if (yf == ya) { 34 | if ((xf < xa && xf > xb) || (xf > xa && xf < xb)) { 35 | dist += 2; 36 | } 37 | } 38 | } 39 | cout << dist << endl; 40 | } 41 | 42 | int main() { 43 | ios_base::sync_with_stdio(false); 44 | cin.tie(0); 45 | cout.tie(0); 46 | int t = 1; 47 | cin >> t; 48 | while (t--) { 49 | solve(); 50 | } 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /A_Simply_Strange_Sort.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define ll long long 9 | #define vi vector 10 | #define vll vector 11 | #define pii pair 12 | #define pll pair 13 | #define pb push_back 14 | #define mp make_pair 15 | const int MOD = 1e9 + 7; 16 | const ll INF = 1e18; 17 | #define inputarr(arr, n) \ 18 | for (ll i = 0; i < n; i++) cin >> arr[i]; 19 | #define printarr(arr, n) \ 20 | for (ll i = 0; i < n; i++) cout << arr[i] << ' '; 21 | 22 | bool isSortedArray(vi &arr) { 23 | for (int i = 1; i < arr.size(); i++) { 24 | if (arr[i] < arr[i - 1]) return false; 25 | } 26 | return true; 27 | } 28 | 29 | void solve() { 30 | int n; 31 | cin >> n; 32 | vi arr(n); 33 | inputarr(arr, n); 34 | int i = 0; 35 | while (true) { 36 | if (isSortedArray(arr)) break; 37 | if ((i + 1) & 1) { 38 | for (int j = 0; j < n; j += 2) { 39 | if (j + 1 < n && arr[j] > arr[j + 1]) swap(arr[j], arr[j + 1]); 40 | } 41 | } else { 42 | for (int j = 1; j < n; j += 2) { 43 | if (j + 1 < n && arr[j] > arr[j + 1]) swap(arr[j], arr[j + 1]); 44 | } 45 | } 46 | i++; 47 | } 48 | cout << i << endl; 49 | } 50 | 51 | int main() { 52 | ios_base::sync_with_stdio(false); 53 | cin.tie(0); 54 | cout.tie(0); 55 | int t = 1; 56 | cin >> t; 57 | while (t--) { 58 | solve(); 59 | } 60 | return 0; 61 | } 62 | -------------------------------------------------------------------------------- /A_The_Miracle_and_the_Sleeper.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define ll long long 9 | #define vi vector 10 | #define vll vector 11 | #define pii pair 12 | #define pll pair 13 | #define pb push_back 14 | #define mp make_pair 15 | const int MOD = 1e9 + 7; 16 | const ll INF = 1e18; 17 | #define inputarr(arr, n) \ 18 | for (ll i = 0; i < n; i++) cin >> arr[i]; 19 | #define printarr(arr, n) \ 20 | for (ll i = 0; i < n; i++) cout << arr[i] << ' '; 21 | 22 | void solve() { 23 | ll l, r; 24 | cin >> l >> r; 25 | if (l == r) { 26 | cout << 0 << endl; 27 | } else if (r / 2 + 1 < l) { 28 | cout << r % l << endl; 29 | } else { 30 | cout << r % (r / 2 + 1) << endl; 31 | } 32 | } 33 | 34 | int main() { 35 | ios_base::sync_with_stdio(false); 36 | cin.tie(0); 37 | cout.tie(0); 38 | int t = 1; 39 | cin >> t; 40 | while (t--) { 41 | solve(); 42 | } 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /B_Alphabetical_Strings.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define ll long long 9 | #define vi vector 10 | #define vll vector 11 | #define pii pair 12 | #define pll pair 13 | #define pb push_back 14 | #define mp make_pair 15 | const int MOD = 1e9 + 7; 16 | const ll INF = 1e18; 17 | #define inputarr(arr, n) \ 18 | for (ll i = 0; i < n; i++) cin >> arr[i]; 19 | #define printarr(arr, n) \ 20 | for (ll i = 0; i < n; i++) cout << arr[i] << ' '; 21 | 22 | void solve() { 23 | string s; 24 | cin >> s; 25 | int n = s.length(); 26 | int left = 0, right = 0; 27 | for (int i = 0; i < n; i++) { 28 | if (s[i] == 'a') { 29 | left = i, right = i; 30 | break; 31 | } 32 | } 33 | map hash; 34 | map ind; 35 | for (int i = 0; i < n; i++) { 36 | hash[s[i]] = true; 37 | ind[s[i]] = i; 38 | } 39 | bool flag = false; 40 | for (int i = 0; i < n; i++) { 41 | if (!hash['a' + i]) { 42 | flag = true; 43 | break; 44 | } 45 | } 46 | if (flag) { 47 | cout << "NO\n"; 48 | return; 49 | } 50 | for (int i = 1; i < n; i++) { 51 | if (ind['a' + i] == left - 1) 52 | left -= 1; 53 | else if (ind['a' + i] == right + 1) 54 | right += 1; 55 | else { 56 | flag = true; 57 | break; 58 | } 59 | } 60 | if (flag) { 61 | cout << "NO\n"; 62 | } else { 63 | cout << "YES\n"; 64 | } 65 | } 66 | 67 | int main() { 68 | ios_base::sync_with_stdio(false); 69 | cin.tie(0); 70 | cout.tie(0); 71 | int t = 1; 72 | cin >> t; 73 | while (t--) { 74 | solve(); 75 | } 76 | return 0; 77 | } 78 | -------------------------------------------------------------------------------- /B_Badge.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define int long long int 9 | #define vi vector 10 | #define pii pair 11 | #define pb push_back 12 | #define mp make_pair 13 | #define all(a) a.begin(), a.end() 14 | const int MOD = 1e9 + 7; 15 | const int INF = 1e18; 16 | #define inputarr(arr, n) \ 17 | for (int i = 0; i < n; i++) cin >> arr[i]; 18 | #define printarr(arr, n) \ 19 | for (int i = 0; i < n; i++) cout << arr[i] << ' '; 20 | 21 | bool dfs(int u, vector &graph, vector &visited, vi &res) { 22 | visited[u] = true; 23 | for (int v : graph[u]) { 24 | if (!visited[v]) { 25 | if (!dfs(v, graph, visited, res)) return false; 26 | } else { 27 | res.pb(v); 28 | return false; 29 | } 30 | } 31 | return true; 32 | } 33 | 34 | void solve() { 35 | int n; 36 | cin >> n; 37 | vi arr(n); 38 | inputarr(arr, n); 39 | vector graph(n + 1); 40 | for (int i = 0; i < n; i++) { 41 | graph[i + 1].pb(arr[i]); 42 | } 43 | vi res; 44 | for (int i = 0; i < n; i++) { 45 | vector visited(n + 1, false); 46 | dfs(i + 1, graph, visited, res); 47 | } 48 | printarr(res, n); 49 | } 50 | 51 | int32_t main() { 52 | ios_base::sync_with_stdio(false); 53 | cin.tie(0); 54 | cout.tie(0); 55 | int t = 1; 56 | // cin >> t; 57 | while (t--) { 58 | solve(); 59 | } 60 | return 0; 61 | } 62 | -------------------------------------------------------------------------------- /B_Charmed_by_the_Game.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define ll long long 9 | #define vi vector 10 | #define vll vector 11 | #define pii pair 12 | #define pll pair 13 | #define pb push_back 14 | #define mp make_pair 15 | const int MOD = 1e9 + 7; 16 | const ll INF = 1e18; 17 | #define inputarr(arr, n) \ 18 | for (ll i = 0; i < n; i++) cin >> arr[i]; 19 | #define printarr(arr, n) \ 20 | for (ll i = 0; i < n; i++) cout << arr[i] << ' '; 21 | 22 | void solve() { 23 | ll a, b; 24 | cin >> a >> b; 25 | ll total = a + b, ans = 0; 26 | vll arr; 27 | arr.pb(total / 2); 28 | if (total & 1) { 29 | arr.pb(total / 2 + 1); 30 | } 31 | } 32 | 33 | int main() { 34 | ios_base::sync_with_stdio(false); 35 | cin.tie(0); 36 | cout.tie(0); 37 | int t = 1; 38 | cin >> t; 39 | while (t--) { 40 | solve(); 41 | } 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /B_Cobb.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define ll long long 9 | #define vi vector 10 | #define vll vector 11 | #define pii pair 12 | #define pll pair 13 | #define pb push_back 14 | #define mp make_pair 15 | const int MOD = 1e9 + 7; 16 | const ll INF = 1e18; 17 | #define inputarr(arr, n) \ 18 | for (ll i = 0; i < n; i++) cin >> arr[i]; 19 | #define printarr(arr, n) \ 20 | for (ll i = 0; i < n; i++) cout << arr[i] << ' '; 21 | 22 | void solve() { 23 | ll n, k; 24 | cin >> n >> k; 25 | vector arr(n); 26 | for (ll i = 0; i < n; i++) { 27 | int x; 28 | cin >> x; 29 | arr[i] = mp(x, i + 1); 30 | } 31 | sort(arr.begin(), arr.end()); 32 | ll maxval = INT_MIN; 33 | for (int i = 1; i < n; i++) { 34 | maxval = max(maxval, (arr[i].second * arr[i - 1].second) - (k * (arr[i].first | arr[i - 1].first))); 35 | } 36 | cout << maxval << endl; 37 | } 38 | 39 | int main() { 40 | ios_base::sync_with_stdio(false); 41 | cin.tie(0); 42 | cout.tie(0); 43 | int t = 1; 44 | cin >> t; 45 | while (t--) { 46 | solve(); 47 | } 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /B_Fence.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define int long long int 9 | #define vi vector 10 | #define pii pair 11 | #define pb push_back 12 | #define mp make_pair 13 | #define all(a) a.begin(), a.end() 14 | const int MOD = 1e9 + 7; 15 | const int INF = 1e18; 16 | #define inputarr(arr, n) \ 17 | for (int i = 0; i < n; i++) cin >> arr[i]; 18 | #define printarr(arr, n) \ 19 | for (int i = 0; i < n; i++) cout << arr[i] << ' '; 20 | 21 | void solve() { 22 | int n, k; 23 | cin >> n >> k; 24 | vi arr(n); 25 | inputarr(arr, n); 26 | int i = 0, j = k - 1, sum = 0, minsum = INT_MAX, minidx = -1; 27 | for (int x = 0; x < k; x++) sum += arr[x]; 28 | while (j < n) { 29 | if (sum < minsum) { 30 | minsum = sum; 31 | minidx = i; 32 | } 33 | if (j + 1 == n) break; 34 | sum -= arr[i]; 35 | i++, j++; 36 | sum += arr[j]; 37 | } 38 | cout << minidx + 1 << endl; 39 | } 40 | 41 | int32_t main() { 42 | ios_base::sync_with_stdio(false); 43 | cin.tie(0); 44 | cout.tie(0); 45 | int t = 1; 46 | // cin >> t; 47 | while (t--) { 48 | solve(); 49 | } 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /B_Fun_with_Even_Subarrays.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define int long long int 9 | #define vi vector 10 | #define pii pair 11 | #define pb push_back 12 | #define mp make_pair 13 | #define all(a) a.begin(), a.end() 14 | const int MOD = 1e9 + 7; 15 | const int INF = 1e18; 16 | #define inputarr(arr, n) \ 17 | for (int i = 0; i < n; i++) cin >> arr[i]; 18 | #define printarr(arr, n) \ 19 | for (int i = 0; i < n; i++) cout << arr[i] << ' '; 20 | 21 | void solve() { 22 | int n; 23 | cin >> n; 24 | vi arr(n); 25 | inputarr(arr, n); 26 | int ans = 0, k = 0; 27 | for (int l = n - 1; l >= 0; l--) { 28 | if (arr[l] == arr[n - 1]) { 29 | k++; 30 | } else { 31 | ans++; 32 | k += k; 33 | l = n - k; 34 | } 35 | } 36 | cout << ans << endl; 37 | } 38 | 39 | int32_t main() { 40 | ios_base::sync_with_stdio(false); 41 | cin.tie(0); 42 | cout.tie(0); 43 | int t = 1; 44 | cin >> t; 45 | while (t--) { 46 | solve(); 47 | } 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /B_GCD_Arrays.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define int long long int 9 | #define vi vector 10 | #define pii pair 11 | #define pb push_back 12 | #define mp make_pair 13 | #define all(a) a.begin(), a.end() 14 | const int MOD = 1e9 + 7; 15 | const int INF = 1e18; 16 | #define inputarr(arr, n) \ 17 | for (int i = 0; i < n; i++) cin >> arr[i]; 18 | #define printarr(arr, n) \ 19 | for (int i = 0; i < n; i++) cout << arr[i] << ' '; 20 | 21 | void solve() { 22 | int l, r, k; 23 | cin >> l >> r >> k; 24 | if (l == r) { 25 | if (l == 1) 26 | cout << "NO\n"; 27 | else 28 | cout << "YES\n"; 29 | return; 30 | } 31 | int n = r - l + 1; 32 | int oddcnt = n / 2; 33 | if (n & 1 && (l & 1 || r & 1)) oddcnt++; 34 | if (oddcnt <= k) { 35 | cout << "YES\n"; 36 | return; 37 | } 38 | cout << "NO\n"; 39 | } 40 | 41 | int32_t main() { 42 | ios_base::sync_with_stdio(false); 43 | cin.tie(0); 44 | cout.tie(0); 45 | int t = 1; 46 | cin >> t; 47 | while (t--) { 48 | solve(); 49 | } 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /B_Gregor_and_the_Pawn_Game.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define ll long long 9 | #define vi vector 10 | #define vll vector 11 | #define pii pair 12 | #define pll pair 13 | #define pb push_back 14 | #define mp make_pair 15 | const int MOD = 1e9 + 7; 16 | const ll INF = 1e18; 17 | #define inputarr(arr, n) \ 18 | for (ll i = 0; i < n; i++) cin >> arr[i]; 19 | #define printarr(arr, n) \ 20 | for (ll i = 0; i < n; i++) cout << arr[i] << ' '; 21 | 22 | void solve() { 23 | ll n; 24 | cin >> n; 25 | string enemy, player; 26 | cin >> enemy >> player; 27 | ll ans = 0; 28 | for (ll i = 0; i < n; i++) { 29 | if (player[i] == '0') continue; 30 | if (player[i] == '1' && enemy[i] == '0') { 31 | ans += 1; 32 | enemy[i] = 'F'; 33 | continue; 34 | } 35 | if (i - 1 >= 0 && enemy[i - 1] == '1') { 36 | ans += 1; 37 | enemy[i - 1] = 'F'; 38 | } else if (i + 1 < n && enemy[i + 1] == '1') { 39 | ans += 1; 40 | enemy[i + 1] = 'F'; 41 | } 42 | } 43 | cout << ans << endl; 44 | } 45 | 46 | int main() { 47 | ios_base::sync_with_stdio(false); 48 | cin.tie(0); 49 | cout.tie(0); 50 | int t = 1; 51 | cin >> t; 52 | while (t--) { 53 | solve(); 54 | } 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /B_Make_it_Divisible_by_25.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define int long long int 9 | #define vi vector 10 | #define pii pair 11 | #define pb push_back 12 | #define mp make_pair 13 | #define all(a) a.begin(), a.end() 14 | const int MOD = 1e9 + 7; 15 | const int INF = 1e18; 16 | #define inputarr(arr, n) \ 17 | for (int i = 0; i < n; i++) cin >> arr[i]; 18 | #define printarr(arr, n) \ 19 | for (int i = 0; i < n; i++) cout << arr[i] << ' '; 20 | 21 | void solve() { 22 | string s; 23 | cin >> s; 24 | vector arr = {"00", "25", "50", "75"}; 25 | int ans = INT_MAX; 26 | for (string t : arr) { 27 | int cnt = 0, i = s.length() - 1; 28 | while (i >= 0 and s[i] != t[1]) cnt++, i--; 29 | if (i < 0) continue; 30 | i--; 31 | while (i >= 0 and s[i] != t[0]) cnt++, i--; 32 | ans = min(ans, cnt); 33 | } 34 | cout << ans << endl; 35 | } 36 | 37 | int32_t main() { 38 | ios_base::sync_with_stdio(false); 39 | cin.tie(0); 40 | cout.tie(0); 41 | int t = 1; 42 | cin >> t; 43 | while (t--) { 44 | solve(); 45 | } 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /B_Not_Sitting.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define int long long int 9 | #define vi vector 10 | #define pii pair 11 | #define pb push_back 12 | #define mp make_pair 13 | #define all(a) a.begin(), a.end() 14 | const int MOD = 1e9 + 7; 15 | const int INF = 1e18; 16 | #define inputarr(arr, n) \ 17 | for (int i = 0; i < n; i++) cin >> arr[i]; 18 | #define printarr(arr, n) \ 19 | for (int i = 0; i < n; i++) cout << arr[i] << ' '; 20 | 21 | void solve() { 22 | int n, m; 23 | cin >> n >> m; 24 | vi arr; 25 | for (int i = 0; i < n; i++) { 26 | for (int j = 0; j < m; j++) { 27 | int d = max(i, n - i - 1) + max(j, m - j - 1); 28 | arr.pb(d); 29 | } 30 | } 31 | sort(all(arr)); 32 | printarr(arr, arr.size()); 33 | cout << endl; 34 | } 35 | 36 | int32_t main() { 37 | ios_base::sync_with_stdio(false); 38 | cin.tie(0); 39 | cout.tie(0); 40 | int t = 1; 41 | cin >> t; 42 | while (t--) { 43 | solve(); 44 | } 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /B_Ordinary_Numbers.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define ll long long 9 | #define vi vector 10 | #define vll vector 11 | #define pii pair 12 | #define pll pair 13 | #define pb push_back 14 | #define mp make_pair 15 | const int MOD = 1e9 + 7; 16 | const ll INF = 1e18; 17 | #define inputarr(arr, n) \ 18 | for (ll i = 0; i < n; i++) cin >> arr[i]; 19 | #define printarr(arr, n) \ 20 | for (ll i = 0; i < n; i++) cout << arr[i] << ' '; 21 | 22 | bool check(int n) { 23 | int prev = n % 10; 24 | n = n / 10; 25 | while (n) { 26 | int d = n % 10; 27 | if (d != prev) return false; 28 | n = n / 10; 29 | } 30 | return true; 31 | } 32 | 33 | int getClosestValue(int n) { 34 | int cnt = 0; 35 | while (n) { 36 | cnt += 1; 37 | n = n / 10; 38 | } 39 | string s = ""; 40 | while (cnt--) { 41 | s += "1"; 42 | } 43 | return stoi(s); 44 | } 45 | 46 | void solve() { 47 | int n; 48 | cin >> n; 49 | if (n < 10) { 50 | cout << n << endl; 51 | return; 52 | } 53 | int cnt = 9; 54 | int start = 10; 55 | while (start * 10 <= n) { 56 | start *= 10; 57 | cnt += 9; 58 | } 59 | start = getClosestValue(start); 60 | int tmp = start; 61 | while (start <= n) { 62 | if (check(start)) cnt += 1; 63 | start += tmp; 64 | } 65 | cout << cnt << endl; 66 | } 67 | 68 | int main() { 69 | ios_base::sync_with_stdio(false); 70 | cin.tie(0); 71 | cout.tie(0); 72 | int t = 1; 73 | cin >> t; 74 | while (t--) { 75 | solve(); 76 | } 77 | return 0; 78 | } 79 | -------------------------------------------------------------------------------- /B_Peculiar_Movie_Preferences.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define int long long int 9 | #define vi vector 10 | #define pii pair 11 | #define pb push_back 12 | #define mp make_pair 13 | #define all(a) a.begin(), a.end() 14 | const int MOD = 1e9 + 7; 15 | const int INF = 1e18; 16 | #define inputarr(arr, n) \ 17 | for (int i = 0; i < n; i++) cin >> arr[i]; 18 | #define printarr(arr, n) \ 19 | for (int i = 0; i < n; i++) cout << arr[i] << ' '; 20 | 21 | void solve() { 22 | int n; 23 | cin >> n; 24 | vector arr; 25 | set s; 26 | for (int i = 0; i < n; i++) { 27 | string str; 28 | cin >> str; 29 | arr.pb(str); 30 | } 31 | for (auto it : arr) { 32 | if (it.length() == 1) { 33 | cout << "YES" << endl; 34 | return; 35 | } 36 | } 37 | for (auto str : arr) { 38 | string srev = str; 39 | reverse(all(srev)); 40 | if (s.find(srev) != s.end()) { 41 | cout << "YES" << endl; 42 | return; 43 | } 44 | for (char ch = 'a'; ch <= 'z'; ch++) { 45 | if (srev.length() == 2) { 46 | if (s.find(srev + ch) != s.end()) { 47 | cout << "YES" << endl; 48 | return; 49 | } 50 | } else { 51 | if (s.find(srev.substr(0, srev.size() - 1)) != s.end()) { 52 | cout << "YES" << endl; 53 | return; 54 | } 55 | } 56 | } 57 | s.insert(str); 58 | } 59 | cout << "NO" << endl; 60 | } 61 | 62 | int32_t main() { 63 | ios_base::sync_with_stdio(false); 64 | cin.tie(0); 65 | cout.tie(0); 66 | int t = 1; 67 | cin >> t; 68 | while (t--) { 69 | solve(); 70 | } 71 | return 0; 72 | } 73 | -------------------------------------------------------------------------------- /B_Roof_Construction.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define int long long int 9 | #define vi vector 10 | #define pii pair 11 | #define pb push_back 12 | #define mp make_pair 13 | #define all(a) a.begin(), a.end() 14 | const int MOD = 1e9 + 7; 15 | const int INF = 1e18; 16 | #define inputarr(arr, n) \ 17 | for (int i = 0; i < n; i++) cin >> arr[i]; 18 | #define printarr(arr, n) \ 19 | for (int i = 0; i < n; i++) cout << arr[i] << ' '; 20 | 21 | void solve() { 22 | int n; 23 | cin >> n; 24 | int cnt = 0; 25 | for (int i = 32; i >= 0; i--) { 26 | if (((n - 1) >> i) & 1) { 27 | cnt = i; 28 | break; 29 | } 30 | } 31 | int x = (1 << cnt); // 2^cnt 32 | for (int i = n - 1; i >= x; i--) cout << i << " "; 33 | for (int i = 0; i < x; i++) cout << i << " "; 34 | cout << endl; 35 | } 36 | 37 | int32_t main() { 38 | ios_base::sync_with_stdio(false); 39 | cin.tie(0); 40 | cout.tie(0); 41 | int t = 1; 42 | cin >> t; 43 | while (t--) { 44 | solve(); 45 | } 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /B_Scenes_From_a_Memory.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define ll long long 9 | #define vi vector 10 | #define vll vector 11 | #define pii pair 12 | #define pll pair 13 | #define pb push_back 14 | #define mp make_pair 15 | const int MOD = 1e9 + 7; 16 | const ll INF = 1e18; 17 | #define inputarr(arr, n) \ 18 | for (ll i = 0; i < n; i++) cin >> arr[i]; 19 | #define printarr(arr, n) \ 20 | for (ll i = 0; i < n; i++) cout << arr[i] << ' '; 21 | 22 | void solve() { 23 | int n; 24 | string s; 25 | cin >> n >> s; 26 | bool n2 = false, n3 = false, n5 = false, n7 = false; 27 | for (int i = 0; i < n; i++) { 28 | char c = s[i]; 29 | if (c != '2' && c != '5' && c != '3' && c != '7') { 30 | cout << 1 << endl << c << endl; 31 | return; 32 | } 33 | } 34 | for (int i = 0; i < n; i++) { 35 | char c = s[i]; 36 | if (c == '2') { 37 | if (n2) { 38 | cout << 2 << endl << 22 << endl; 39 | return; 40 | } else if (n3) { 41 | cout << 2 << endl << 32 << endl; 42 | return; 43 | } else if (n5) { 44 | cout << 2 << endl << 52 << endl; 45 | return; 46 | } else if (n7) { 47 | cout << 2 << endl << 72 << endl; 48 | return; 49 | } 50 | n2 = true; 51 | } 52 | if (c == '5') { 53 | if (n2) { 54 | cout << 2 << endl << 25 << endl; 55 | return; 56 | } else if (n3) { 57 | cout << 2 << endl << 35 << endl; 58 | return; 59 | } else if (n5) { 60 | cout << 2 << endl << 55 << endl; 61 | return; 62 | } else if (n7) { 63 | cout << 2 << endl << 75 << endl; 64 | return; 65 | } 66 | n5 = true; 67 | } 68 | if (c == '3') { 69 | if (n3) { 70 | cout << 2 << endl << 33 << endl; 71 | return; 72 | } 73 | n3 = true; 74 | } 75 | if (c == '7') { 76 | if (n2) { 77 | cout << 2 << endl << 27 << endl; 78 | return; 79 | } else if (n5) { 80 | cout << 2 << endl << 57 << endl; 81 | return; 82 | } else if (n7) { 83 | cout << 2 << endl << 77 << endl; 84 | return; 85 | } 86 | n7 = true; 87 | } 88 | } 89 | } 90 | 91 | int main() { 92 | ios_base::sync_with_stdio(false); 93 | cin.tie(0); 94 | cout.tie(0); 95 | int t = 1; 96 | cin >> t; 97 | while (t--) { 98 | solve(); 99 | } 100 | return 0; 101 | } 102 | -------------------------------------------------------------------------------- /B_Two_Tables.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define ll long long 9 | #define vi vector 10 | #define vll vector 11 | #define pii pair 12 | #define pll pair 13 | #define pb push_back 14 | #define mp make_pair 15 | const int MOD = 1e9 + 7; 16 | const ll INF = 1e18; 17 | #define inputarr(arr, n) \ 18 | for (ll i = 0; i < n; i++) cin >> arr[i]; 19 | #define printarr(arr, n) \ 20 | for (ll i = 0; i < n; i++) cout << arr[i] << ' '; 21 | 22 | void solve() { 23 | double W, H, x1, y1, x2, y2, w, h; 24 | cin >> W >> H >> x1 >> y1 >> x2 >> y2 >> w >> h; 25 | double x = 0, y = 0; 26 | x = max((x1 - 0) - w, (W - x2) - w); 27 | x = x < 0 ? abs(x) : 0; 28 | y = max((y1 - 0) - h, (H - y2) - h); 29 | y = y < 0 ? abs(y) : 0; 30 | cout << (x + y) * (x + y) << endl; 31 | } 32 | 33 | int main() { 34 | ios_base::sync_with_stdio(false); 35 | cin.tie(0); 36 | cout.tie(0); 37 | int t = 1; 38 | cin >> t; 39 | while (t--) { 40 | solve(); 41 | } 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /B_Who_s_Opposite_.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define ll long long 9 | #define vi vector 10 | #define vll vector 11 | #define pii pair 12 | #define pll pair 13 | #define pb push_back 14 | #define mp make_pair 15 | const int MOD = 1e9 + 7; 16 | const ll INF = 1e18; 17 | #define inputarr(arr, n) \ 18 | for (ll i = 0; i < n; i++) cin >> arr[i]; 19 | #define printarr(arr, n) \ 20 | for (ll i = 0; i < n; i++) cout << arr[i] << ' '; 21 | 22 | void solve() { 23 | ll a, b, c; 24 | cin >> a >> b >> c; 25 | if (b < a) swap(a, b); 26 | if (a - 1 > b - a - 1) { 27 | cout << -1 << endl; 28 | return; 29 | } 30 | ll n = (b - a) * 2; 31 | if (c > a && c > b && c > n) { 32 | cout << -1 << endl; 33 | return; 34 | } 35 | if (c == n / 2) { 36 | cout << n << endl; 37 | return; 38 | } 39 | if (c > n / 2) { 40 | cout << (c + (n / 2)) % n << endl; 41 | return; 42 | } 43 | cout << c + (n / 2) << endl; 44 | } 45 | 46 | int main() { 47 | ios_base::sync_with_stdio(false); 48 | cin.tie(0); 49 | cout.tie(0); 50 | int t = 1; 51 | cin >> t; 52 | while (t--) { 53 | solve(); 54 | } 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /C_And_Matching.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define int long long int 9 | #define vi vector 10 | #define pii pair 11 | #define pb push_back 12 | #define mp make_pair 13 | #define all(a) a.begin(), a.end() 14 | const int MOD = 1e9 + 7; 15 | const int INF = 1e18; 16 | #define inputarr(arr, n) \ 17 | for (int i = 0; i < n; i++) cin >> arr[i]; 18 | #define printarr(arr, n) \ 19 | for (int i = 0; i < n; i++) cout << arr[i] << ' '; 20 | 21 | void solve() { 22 | int n, k; 23 | cin >> n >> k; 24 | int l = 0, r = n - 1; 25 | if (k == 0) { 26 | while (l < r) { 27 | cout << l << ' ' << r << endl; 28 | l++, r--; 29 | } 30 | return; 31 | } 32 | if (k == n - 1) { 33 | cout << -1 << endl; 34 | return; 35 | } 36 | cout << k << ' ' << n - 1 << endl; 37 | l = 1, r = n - 2; 38 | while (l < r) { 39 | if (l != k && r != k) { 40 | cout << l << ' ' << r << endl; 41 | } else { 42 | if (l == k) { 43 | cout << 0 << ' ' << r << endl; 44 | } else { 45 | cout << 0 << ' ' << l << endl; 46 | } 47 | } 48 | l++, r--; 49 | } 50 | } 51 | 52 | int32_t main() { 53 | ios_base::sync_with_stdio(false); 54 | cin.tie(0); 55 | cout.tie(0); 56 | int t = 1; 57 | cin >> t; 58 | while (t--) { 59 | solve(); 60 | } 61 | return 0; 62 | } 63 | -------------------------------------------------------------------------------- /C_Coin_Rows.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define ll long long 9 | #define vi vector 10 | #define vll vector 11 | #define pii pair 12 | #define pll pair 13 | #define pb push_back 14 | #define mp make_pair 15 | const int MOD = 1e9 + 7; 16 | const ll INF = 1e18; 17 | #define inputarr(arr, n) \ 18 | for (ll i = 0; i < n; i++) cin >> arr[i]; 19 | #define printarr(arr, n) \ 20 | for (ll i = 0; i < n; i++) cout << arr[i] << ' '; 21 | 22 | void solve() { 23 | int m; 24 | cin >> m; 25 | vector> arr(2, vector(m, 0)); 26 | vi prefix(m, 0), suffix(m, 0); 27 | for (int i = 0; i < m; i++) cin >> arr[0][i]; 28 | for (int i = 0; i < m; i++) cin >> arr[1][i]; 29 | 30 | if (m == 1) { 31 | cout << 0 << endl; 32 | return; 33 | } 34 | 35 | // Preprocessing 36 | arr[0][0] = 0; 37 | arr[1][m - 1] = 0; 38 | prefix[0] = arr[1][0]; 39 | suffix[m - 1] = arr[0][m - 1]; 40 | for (int i = 1; i < m; i++) prefix[i] = prefix[i - 1] + arr[1][i]; 41 | for (int i = m - 2; i >= 0; i--) suffix[i] = suffix[i + 1] + arr[0][i]; 42 | 43 | // Logic 44 | int ans = INT_MAX; 45 | ans = min({ans, suffix[1], prefix[m - 2]}); 46 | for (int i = 1; i < m - 1; i++) { 47 | ans = min(ans, max(prefix[i - 1], suffix[i + 1])); 48 | } 49 | if (ans >= INT_MAX) 50 | cout << 0; 51 | else 52 | cout << ans; 53 | cout << endl; 54 | } 55 | 56 | int main() { 57 | ios_base::sync_with_stdio(false); 58 | cin.tie(0); 59 | cout.tie(0); 60 | int t = 1; 61 | cin >> t; 62 | while (t--) { 63 | solve(); 64 | } 65 | return 0; 66 | } 67 | -------------------------------------------------------------------------------- /C_Deep_Down_Below.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define ll long long 9 | #define vi vector 10 | #define vll vector 11 | #define pii pair 12 | #define pll pair 13 | #define pb push_back 14 | #define mp make_pair 15 | const int MOD = 1e9 + 7; 16 | const ll INF = 1e18; 17 | #define inputarr(arr, n) \ 18 | for (ll i = 0; i < n; i++) cin >> arr[i]; 19 | #define printarr(arr, n) \ 20 | for (ll i = 0; i < n; i++) cout << arr[i] << ' '; 21 | 22 | bool isPossible(ll val, vector &arr) { 23 | ll currval = val; 24 | for (ll i = 0; i < arr.size(); i++) { 25 | if (currval <= arr[i][0]) return false; 26 | currval += arr[i].size() - 1; 27 | } 28 | return true; 29 | } 30 | 31 | void solve() { 32 | ll n; 33 | cin >> n; 34 | vector arr(n); 35 | for (ll i = 0; i < n; i++) { 36 | ll k; 37 | cin >> k; 38 | arr[i].resize(k + 1); 39 | ll maxval = 0; 40 | for (ll j = 1; j <= k; j++) { 41 | cin >> arr[i][j]; 42 | maxval = max(maxval, arr[i][j] - (j - 1)); 43 | } 44 | arr[i][0] = maxval; 45 | } 46 | sort(arr.begin(), arr.end()); 47 | ll start = 1; 48 | ll end = 2e9; // 1e9 is the max limit of the monster's armour, so end should be greater as in worst case required hp might be max(all monsters)+1 49 | ll ans = 0; 50 | while (start <= end) { 51 | ll mid = start + (end - start) / 2; 52 | if (isPossible(mid, arr)) { 53 | ans = mid; 54 | end = mid - 1; 55 | } else { 56 | start = mid + 1; 57 | } 58 | } 59 | cout << ans << endl; 60 | } 61 | 62 | int main() { 63 | ios_base::sync_with_stdio(false); 64 | cin.tie(0); 65 | cout.tie(0); 66 | int t = 1; 67 | cin >> t; 68 | while (t--) { 69 | solve(); 70 | } 71 | return 0; 72 | } 73 | -------------------------------------------------------------------------------- /C_King_s_Path.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define ll long long 9 | #define vi vector 10 | #define vll vector 11 | #define pii pair 12 | #define pll pair 13 | #define pb push_back 14 | #define mp make_pair 15 | const int MOD = 1e9 + 7; 16 | const ll INF = 1e18; 17 | #define inputarr(arr, n) \ 18 | for (ll i = 0; i < n; i++) cin >> arr[i]; 19 | #define printarr(arr, n) \ 20 | for (ll i = 0; i < n; i++) cout << arr[i] << ' '; 21 | 22 | bool sortComparator(pll a, pll b) { 23 | if (a.first < b.first) return true; 24 | if (a.first > b.first) return false; 25 | return a.second < b.second; 26 | } 27 | 28 | void solve() { 29 | ll x0, y0, x1, y1, n; 30 | cin >> x0 >> y0 >> x1 >> y1 >> n; 31 | pll start = mp(x0, y0), end = mp(x1, y1); 32 | map hash; 33 | vector arr; 34 | while (n--) { 35 | ll r, a, b; 36 | cin >> r >> a >> b; 37 | hash[mp(r, a)] = 1; 38 | arr.pb(mp(r, a)); 39 | if (mp(r, a) != mp(r, b)) { 40 | hash[mp(r, b)] = 2; 41 | arr.pb(mp(r, b)); 42 | } 43 | } 44 | sort(arr.begin(), arr.end(), sortComparator); 45 | ll startIdx = lower_bound(arr.begin(), arr.end(), start) - arr.begin(); 46 | ll endIdx = lower_bound(arr.begin(), arr.end(), end) - arr.begin(); 47 | 48 | // base case: start position or end position not allowed 49 | if ((arr[startIdx] != start && hash[arr[startIdx]] != 2) || (arr[endIdx] != end && hash[arr[endIdx]] != 2)) { 50 | cout << -1 << endl; 51 | return; 52 | } 53 | 54 | map distance, visited; 55 | queue q; 56 | q.push(start); 57 | visited[start] = true; 58 | distance[start] = 0; 59 | while (!q.empty()) { 60 | pll curr = q.front(); 61 | q.pop(); 62 | 63 | if (curr == end) break; 64 | 65 | vector neighbourCells = {{curr.first + 1, curr.second}, {curr.first - 1, curr.second}, {curr.first, curr.second + 1}, 66 | {curr.first, curr.second - 1}, {curr.first - 1, curr.second - 1}, {curr.first - 1, curr.second + 1}, 67 | {curr.first + 1, curr.second + 1}, {curr.first + 1, curr.second - 1}}; 68 | for (pll neighbour : neighbourCells) { 69 | ll neighbourIdx = lower_bound(arr.begin(), arr.end(), neighbour) - arr.begin(); 70 | if (arr[neighbourIdx].first != neighbour.first) continue; 71 | if (!visited[neighbour] && (arr[neighbourIdx] == neighbour || hash[arr[neighbourIdx]] == 2)) { 72 | visited[neighbour] = true; 73 | distance[neighbour] = distance[curr] + 1; 74 | q.push(neighbour); 75 | } 76 | } 77 | } 78 | if (distance[end]) { 79 | cout << distance[end] << endl; 80 | return; 81 | } 82 | cout << -1 << endl; 83 | } 84 | 85 | int main() { 86 | ios_base::sync_with_stdio(false); 87 | cin.tie(0); 88 | cout.tie(0); 89 | int t = 1; 90 | // cin >> t; 91 | while (t--) { 92 | solve(); 93 | } 94 | return 0; 95 | } 96 | -------------------------------------------------------------------------------- /C_Meximum_Array.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define int long long int 9 | #define vi vector 10 | #define pii pair 11 | #define pb push_back 12 | #define mp make_pair 13 | #define all(a) a.begin(), a.end() 14 | const int MOD = 1e9 + 7; 15 | const int INF = 1e18; 16 | #define inputarr(arr, n) \ 17 | for (int i = 0; i < n; i++) cin >> arr[i]; 18 | #define printarr(arr, n) \ 19 | for (int i = 0; i < n; i++) cout << arr[i] << ' '; 20 | 21 | void solve() { 22 | int n; 23 | cin >> n; 24 | vi arr(n); 25 | inputarr(arr, n); 26 | map hash; 27 | for (int it : arr) hash[it]++; 28 | set s; 29 | vi ans; 30 | int mex = 0; 31 | for (int i = 0; i < n; i++) { 32 | hash[arr[i]]--; 33 | s.insert(arr[i]); 34 | while (s.find(mex) != s.end()) { 35 | mex++; 36 | } 37 | if (hash[mex] == 0) { 38 | s.clear(); 39 | ans.pb(mex); 40 | mex = 0; 41 | } 42 | } 43 | cout << ans.size() << endl; 44 | printarr(ans, ans.size()); 45 | cout << endl; 46 | } 47 | 48 | int32_t main() { 49 | ios_base::sync_with_stdio(false); 50 | cin.tie(0); 51 | cout.tie(0); 52 | int t = 1; 53 | cin >> t; 54 | while (t--) { 55 | solve(); 56 | } 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /C_Not_Adjacent_Matrix.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define ll long long 9 | #define vi vector 10 | #define vll vector 11 | #define pii pair 12 | #define pll pair 13 | #define pb push_back 14 | #define mp make_pair 15 | const int MOD = 1e9 + 7; 16 | const ll INF = 1e18; 17 | #define inputarr(arr, n) \ 18 | for (ll i = 0; i < n; i++) cin >> arr[i]; 19 | #define printarr(arr, n) \ 20 | for (ll i = 0; i < n; i++) cout << arr[i] << ' '; 21 | 22 | void solve() { 23 | int n; 24 | cin >> n; 25 | if (n == 1) { 26 | cout << 1 << endl; 27 | return; 28 | } 29 | if (n == 2) { 30 | cout << -1 << endl; 31 | return; 32 | } 33 | int isEven = 0; 34 | int row = 0, cnt = 1; 35 | vector m(n, vi(n + 1)); 36 | for (int i = 0; i < n; i++) { 37 | m[i][n] = isEven; 38 | isEven = isEven == 1 ? 0 : 1; 39 | } 40 | bool ok = true; 41 | while (cnt <= n * n) { 42 | while (row < n) { 43 | int column = m[row][n]; 44 | while (column < n) { 45 | m[row][column] = cnt; 46 | cnt += 1; 47 | column += 2; 48 | if (cnt > n * n) { 49 | ok = false; 50 | break; 51 | } 52 | } 53 | if (!ok) break; 54 | m[row][n] = m[row][n] == 1 ? 0 : 1; 55 | row += 1; 56 | if (row == n) row = 0; 57 | } 58 | } 59 | for (int i = 0; i < n; i++) { 60 | for (int j = 0; j < n; j++) { 61 | cout << m[i][j] << ' '; 62 | } 63 | cout << endl; 64 | } 65 | } 66 | 67 | int main() { 68 | ios_base::sync_with_stdio(false); 69 | cin.tie(0); 70 | cout.tie(0); 71 | int t = 1; 72 | cin >> t; 73 | while (t--) { 74 | solve(); 75 | } 76 | return 0; 77 | } 78 | -------------------------------------------------------------------------------- /C_Not_Assigning.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define int long long int 9 | #define vi vector 10 | #define pii pair 11 | #define pb push_back 12 | #define mp make_pair 13 | #define all(a) a.begin(), a.end() 14 | const int MOD = 1e9 + 7; 15 | const int INF = 1e18; 16 | #define inputarr(arr, n) \ 17 | for (int i = 0; i < n; i++) cin >> arr[i]; 18 | #define printarr(arr, n) \ 19 | for (int i = 0; i < n; i++) cout << arr[i] << ' '; 20 | 21 | map m; 22 | 23 | bool dfs(int curr, int par, vector> &tree) { 24 | if (par == 0) { 25 | // root 26 | if (tree[curr].size() > 2) { 27 | return false; 28 | } 29 | bool f = false; 30 | for (pii &edge : tree[curr]) { 31 | int v = edge.first; 32 | if (!f) { 33 | f = true; 34 | edge.second = 11; 35 | m[{curr, v}] = m[{v, curr}] = 11; 36 | } else { 37 | edge.second = 2; 38 | m[{curr, v}] = m[{v, curr}] = 2; 39 | } 40 | if (!dfs(v, curr, tree)) { 41 | return false; 42 | } 43 | } 44 | } else { 45 | if (tree[curr].size() > 2) { 46 | return false; 47 | } 48 | for (pii &edge : tree[curr]) { 49 | int v = edge.first; 50 | if (v != par) { 51 | int prev = m[{par, curr}]; 52 | if (prev == 11) { 53 | edge.second = 2; 54 | m[{curr, v}] = m[{v, curr}] = 2; 55 | } else { 56 | edge.second = 11; 57 | m[{curr, v}] = m[{v, curr}] = 11; 58 | } 59 | if (!dfs(v, curr, tree)) { 60 | return false; 61 | } 62 | } 63 | } 64 | } 65 | return true; 66 | } 67 | 68 | void solve() { 69 | int n; 70 | cin >> n; 71 | vector> tree(n + 1); 72 | vector edges; 73 | for (int i = 1; i <= n - 1; i++) { 74 | int u, v; 75 | cin >> u >> v; 76 | edges.pb({u, v}); 77 | tree[u].pb({v, 0}); 78 | tree[v].pb({u, 0}); 79 | } 80 | if (!dfs(1, 0, tree)) { 81 | cout << -1 << endl; 82 | return; 83 | } 84 | for (pii edge : edges) { 85 | cout << m[edge] << " "; 86 | } 87 | cout << endl; 88 | } 89 | 90 | int32_t main() { 91 | ios_base::sync_with_stdio(false); 92 | cin.tie(0); 93 | cout.tie(0); 94 | int t = 1; 95 | cin >> t; 96 | while (t--) { 97 | solve(); 98 | } 99 | return 0; 100 | } 101 | -------------------------------------------------------------------------------- /C_Pair_Programming.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define ll long long 9 | #define vi vector 10 | #define vll vector 11 | #define pii pair 12 | #define pll pair 13 | #define pb push_back 14 | #define mp make_pair 15 | const int MOD = 1e9 + 7; 16 | const ll INF = 1e18; 17 | #define inputarr(arr, n) \ 18 | for (ll i = 0; i < n; i++) cin >> arr[i]; 19 | #define printarr(arr, n) \ 20 | for (ll i = 0; i < n; i++) cout << arr[i] << ' '; 21 | 22 | void solve() { 23 | int k, n, m; 24 | cin >> k >> n >> m; 25 | vi a(n), b(m), ans; 26 | inputarr(a, n); 27 | inputarr(b, m); 28 | int i = 0, j = 0; 29 | while (i < n || j < m) { 30 | if (i < n && a[i] == 0) { 31 | ans.pb(a[i]); 32 | k++, i++; 33 | } else if (j < m && b[j] == 0) { 34 | ans.pb(b[j]); 35 | k++, j++; 36 | } else { 37 | if (i < n && a[i] <= k) { 38 | ans.pb(a[i]); 39 | i += 1; 40 | } else if (j < m && b[j] <= k) { 41 | ans.pb(b[j]); 42 | j += 1; 43 | } else { 44 | cout << -1 << endl; 45 | return; 46 | } 47 | } 48 | } 49 | printarr(ans, ans.size()); 50 | cout << endl; 51 | } 52 | 53 | int main() { 54 | ios_base::sync_with_stdio(false); 55 | cin.tie(0); 56 | cout.tie(0); 57 | int t = 1; 58 | cin >> t; 59 | while (t--) { 60 | solve(); 61 | } 62 | return 0; 63 | } 64 | -------------------------------------------------------------------------------- /C_Save_More_Mice.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define int long long int 9 | #define vi vector 10 | #define pii pair 11 | #define pb push_back 12 | #define mp make_pair 13 | #define all(a) a.begin(), a.end() 14 | const int MOD = 1e9 + 7; 15 | const int INF = 1e18; 16 | #define inputarr(arr, n) \ 17 | for (int i = 0; i < n; i++) cin >> arr[i]; 18 | #define printarr(arr, n) \ 19 | for (int i = 0; i < n; i++) cout << arr[i] << ' '; 20 | 21 | void solve() { 22 | int n, k; 23 | cin >> n >> k; 24 | vi arr(k); 25 | inputarr(arr, k); 26 | sort(all(arr)); 27 | int cnt = 0, sum = 0; 28 | for (int i = k - 1; i >= 0; i--) { 29 | sum += n - arr[i]; 30 | if (sum >= n) break; 31 | cnt += 1; 32 | } 33 | cout << cnt << endl; 34 | } 35 | 36 | int32_t main() { 37 | ios_base::sync_with_stdio(false); 38 | cin.tie(0); 39 | cout.tie(0); 40 | int t = 1; 41 | cin >> t; 42 | while (t--) { 43 | solve(); 44 | } 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /C_Slay_the_Dragon.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define int long long int 9 | #define vi vector 10 | #define pii pair 11 | #define pb push_back 12 | #define mp make_pair 13 | #define all(a) a.begin(), a.end() 14 | const int MOD = 1e9 + 7; 15 | const int INF = 1e18; 16 | #define inputarr(arr, n) \ 17 | for (int i = 0; i < n; i++) cin >> arr[i]; 18 | #define printarr(arr, n) \ 19 | for (int i = 0; i < n; i++) cout << arr[i] << ' '; 20 | 21 | void solve() { 22 | int n; 23 | cin >> n; 24 | vi arr(n); 25 | inputarr(arr, n); 26 | sort(all(arr)); 27 | int sum = accumulate(all(arr), 0ll); 28 | int m; 29 | cin >> m; 30 | while (m--) { 31 | int x, y; 32 | cin >> x >> y; 33 | int i = lower_bound(all(arr), x) - arr.begin(); 34 | if (i == n) { 35 | i--; 36 | int ans = max(0ll, x - arr[i]); 37 | ans += max(0ll, y - (sum - arr[i])); 38 | cout << ans << endl; 39 | } else { 40 | int ans1 = max(0ll, x - arr[i]), ans2 = INF; 41 | ans1 += max(0ll, y - (sum - arr[i])); 42 | i--; 43 | if (i >= 0) { 44 | ans2 = max(0ll, x - arr[i]); 45 | ans2 += max(0ll, y - (sum - arr[i])); 46 | } 47 | cout << min(ans1, ans2) << endl; 48 | } 49 | } 50 | } 51 | 52 | int32_t main() { 53 | ios_base::sync_with_stdio(false); 54 | cin.tie(0); 55 | cout.tie(0); 56 | int t = 1; 57 | // cin >> t; 58 | while (t--) { 59 | solve(); 60 | } 61 | return 0; 62 | } 63 | -------------------------------------------------------------------------------- /C_Valhalla_Siege.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define int long long int 9 | #define vi vector 10 | #define pii pair 11 | #define pb push_back 12 | #define mp make_pair 13 | #define all(a) a.begin(), a.end() 14 | const int MOD = 1e9 + 7; 15 | const int INF = 1e18; 16 | #define inputarr(arr, n) \ 17 | for (int i = 0; i < n; i++) cin >> arr[i]; 18 | #define printarr(arr, n) \ 19 | for (int i = 0; i < n; i++) cout << arr[i] << ' '; 20 | 21 | void solve() { 22 | int n, q; 23 | cin >> n >> q; 24 | vi arr(n); 25 | inputarr(arr, n); 26 | vi prefixsum(n, 0); 27 | partial_sum(all(arr), prefixsum.begin()); 28 | int cnt = 0; 29 | while (q--) { 30 | int k; 31 | cin >> k; 32 | cnt += k; 33 | if (cnt >= prefixsum[n - 1]) cnt = 0; 34 | auto it = lower_bound(all(prefixsum), cnt); 35 | cout << distance(it, prefixsum.end()) - (*it == cnt) << endl; 36 | } 37 | } 38 | 39 | int32_t main() { 40 | ios_base::sync_with_stdio(false); 41 | cin.tie(0); 42 | cout.tie(0); 43 | int t = 1; 44 | // cin >> t; 45 | while (t--) { 46 | solve(); 47 | } 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /C_Web_of_Lies.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define ll long long 9 | #define vi vector 10 | #define vll vector 11 | #define pii pair 12 | #define pll pair 13 | #define pb push_back 14 | #define mp make_pair 15 | const int MOD = 1e9 + 7; 16 | const ll INF = 1e18; 17 | #define inputarr(arr, n) \ 18 | for (ll i = 0; i < n; i++) cin >> arr[i]; 19 | #define printarr(arr, n) \ 20 | for (ll i = 0; i < n; i++) cout << arr[i] << ' '; 21 | 22 | void solve() { 23 | int n, m; 24 | cin >> n >> m; 25 | int alive = n; 26 | vi stronger(n, 0); 27 | for (int i = 0; i < m; i++) { 28 | int u, v; 29 | cin >> u >> v; 30 | u--, v--; 31 | if (u > v) swap(u, v); 32 | if (stronger[u] == 0) alive--; 33 | stronger[u]++; 34 | } 35 | int q; 36 | cin >> q; 37 | while (q--) { 38 | int opt; 39 | cin >> opt; 40 | if (opt == 1) { 41 | int u, v; 42 | cin >> u >> v; 43 | u--, v--; 44 | if (u > v) swap(u, v); 45 | if (stronger[u] == 0) alive--; 46 | stronger[u]++; 47 | } else if (opt == 2) { 48 | int u, v; 49 | cin >> u >> v; 50 | u--, v--; 51 | if (u > v) swap(u, v); 52 | stronger[u]--; 53 | if (stronger[u] == 0) alive++; 54 | } else { 55 | cout << alive << endl; 56 | } 57 | } 58 | } 59 | 60 | int main() { 61 | ios_base::sync_with_stdio(false); 62 | cin.tie(0); 63 | cout.tie(0); 64 | int t = 1; 65 | // cin >> t; 66 | while (t--) { 67 | solve(); 68 | } 69 | return 0; 70 | } 71 | -------------------------------------------------------------------------------- /D_Co_growing_Sequence.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define ll long long 9 | #define vi vector 10 | #define vll vector 11 | #define pii pair 12 | #define pll pair 13 | #define pb push_back 14 | #define mp make_pair 15 | const int MOD = 1e9 + 7; 16 | const ll INF = 1e18; 17 | #define inputarr(arr, n) \ 18 | for (ll i = 0; i < n; i++) cin >> arr[i]; 19 | #define printarr(arr, n) \ 20 | for (ll i = 0; i < n; i++) cout << arr[i] << ' '; 21 | 22 | void solve() { 23 | int n; 24 | cin >> n; 25 | vi x(n); 26 | inputarr(x, n); 27 | vi y(n, 0); 28 | for (int i = 1; i < n; i++) { 29 | int t = x[i - 1] ^ y[i - 1]; 30 | y[i] = (t | x[i]) ^ x[i]; 31 | } 32 | printarr(y, n); 33 | cout << endl; 34 | } 35 | 36 | int main() { 37 | ios_base::sync_with_stdio(false); 38 | cin.tie(0); 39 | cout.tie(0); 40 | int t = 1; 41 | cin >> t; 42 | while (t--) { 43 | solve(); 44 | } 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /D_Lunar_New_Year_and_a_Wander.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define ll long long 9 | #define vi vector 10 | #define vll vector 11 | #define pii pair 12 | #define pll pair 13 | #define pb push_back 14 | #define mp make_pair 15 | const int MOD = 1e9 + 7; 16 | const ll INF = 1e18; 17 | #define inputarr(arr, n) \ 18 | for (ll i = 0; i < n; i++) cin >> arr[i]; 19 | #define printarr(arr, n) \ 20 | for (ll i = 0; i < n; i++) cout << arr[i] << ' '; 21 | 22 | void solve() { 23 | int n, m; 24 | cin >> n >> m; 25 | vector graph(n + 1); 26 | for (int i = 0; i < m; i++) { 27 | int u, v; 28 | cin >> u >> v; 29 | // Ignoring self loops 30 | if (u == v) continue; 31 | graph[u].pb(v); 32 | graph[v].pb(u); 33 | } 34 | vector visited(n + 1, false); 35 | vi order; 36 | priority_queue, greater> pq; 37 | visited[1] = true; 38 | pq.push(1); 39 | while (!pq.empty()) { 40 | int curr = pq.top(); 41 | pq.pop(); 42 | order.pb(curr); 43 | for (int next : graph[curr]) { 44 | if (!visited[next]) { 45 | visited[next] = true; 46 | pq.push(next); 47 | } 48 | } 49 | } 50 | printarr(order, order.size()); 51 | cout << endl; 52 | } 53 | 54 | int main() { 55 | ios_base::sync_with_stdio(false); 56 | cin.tie(0); 57 | cout.tie(0); 58 | int t = 1; 59 | // cin >> t; 60 | while (t--) { 61 | solve(); 62 | } 63 | return 0; 64 | } 65 | -------------------------------------------------------------------------------- /D_Productive_Meeting.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define int long long int 9 | #define vi vector 10 | #define pii pair 11 | #define pb push_back 12 | #define mp make_pair 13 | #define all(a) a.begin(), a.end() 14 | const int MOD = 1e9 + 7; 15 | const int INF = 1e18; 16 | #define inputarr(arr, n) \ 17 | for (int i = 0; i < n; i++) cin >> arr[i]; 18 | #define printarr(arr, n) \ 19 | for (int i = 0; i < n; i++) cout << arr[i] << ' '; 20 | 21 | void solve() { 22 | int n; 23 | cin >> n; 24 | vi arr(n); 25 | inputarr(arr, n); 26 | set s; 27 | for (int i = 0; i < n; i++) { 28 | if (arr[i] > 0) s.insert({arr[i], i}); 29 | } 30 | if (s.empty()) { 31 | cout << 0 << endl; 32 | return; 33 | } 34 | vector ans; 35 | while (!s.empty()) { 36 | int minval, maxval, mini, maxi; 37 | minval = (*s.begin()).first; 38 | mini = (*s.begin()).second; 39 | s.erase(s.begin()); 40 | if (s.empty()) break; 41 | maxval = (*s.rbegin()).first; 42 | maxi = (*s.rbegin()).second; 43 | s.erase(prev(s.end())); 44 | if (mini == maxi) break; 45 | ans.pb({mini + 1, maxi + 1}); 46 | if (minval - 1 > 0) s.insert({minval - 1, mini}); 47 | if (maxval - 1 > 0) s.insert({maxval - 1, maxi}); 48 | } 49 | cout << ans.size() << endl; 50 | for (auto it : ans) cout << it.first << ' ' << it.second << endl; 51 | } 52 | 53 | int32_t main() { 54 | ios_base::sync_with_stdio(false); 55 | cin.tie(0); 56 | cout.tie(0); 57 | int t = 1; 58 | cin >> t; 59 | while (t--) { 60 | solve(); 61 | } 62 | return 0; 63 | } 64 | -------------------------------------------------------------------------------- /D_Same_Differences.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define ll long long 9 | #define vi vector 10 | #define vll vector 11 | #define pii pair 12 | #define pll pair 13 | #define pb push_back 14 | #define mp make_pair 15 | const int MOD = 1e9 + 7; 16 | const ll INF = 1e18; 17 | #define inputarr(arr, n) \ 18 | for (ll i = 0; i < n; i++) cin >> arr[i]; 19 | #define printarr(arr, n) \ 20 | for (ll i = 0; i < n; i++) cout << arr[i] << ' '; 21 | 22 | void solve() { 23 | ll n; 24 | cin >> n; 25 | vll arr(n); 26 | inputarr(arr, n); 27 | ll cnt = 0; 28 | // Aj - Ai = j - i => Aj - j = Ai - i 29 | map hash; 30 | for (ll i = 0; i < n; i++) { 31 | if (hash[arr[i] - i] > 0) { 32 | cnt += hash[arr[i] - i]; 33 | } 34 | hash[arr[i] - i] += 1; 35 | } 36 | cout << cnt << endl; 37 | } 38 | 39 | int main() { 40 | ios_base::sync_with_stdio(false); 41 | cin.tie(0); 42 | cout.tie(0); 43 | int t = 1; 44 | cin >> t; 45 | while (t--) { 46 | solve(); 47 | } 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /D_Secret_Passwords.cpp: -------------------------------------------------------------------------------- 1 | // ? The problem is done using 2 approaches: Bipartite and DSU 2 | 3 | // * Bipartite Approach 4 | 5 | // #include 6 | // using namespace std; 7 | 8 | // #define ll long long 9 | // #define vi vector 10 | // #define vll vector 11 | // #define pii pair 12 | // #define pll pair 13 | // #define pb push_back 14 | // #define mp make_pair 15 | // const int MOD = 1e9 + 7; 16 | // const ll INF = 1e18; 17 | // #define inputarr(arr, n) \ 18 | // for (ll i = 0; i < n; i++) cin >> arr[i]; 19 | // #define printarr(arr, n) \ 20 | // for (ll i = 0; i < n; i++) cout << arr[i] << ' '; 21 | 22 | // void dfs(int i, vector &graph, vector &visited) { 23 | // visited[i] = true; 24 | // for (int it : graph[i]) { 25 | // if (!visited[it]) { 26 | // dfs(it, graph, visited); 27 | // } 28 | // } 29 | // } 30 | 31 | // void solve() { 32 | // int n; 33 | // cin >> n; 34 | // vector graph(n + 26); 35 | // for (int i = 0; i < n; i++) { 36 | // string s; 37 | // cin >> s; 38 | // // n vertices for n strings then another 26 vertices for each alphabet 39 | // // we add an undirected edge between the string and every alphabet present in the string 40 | // // then we can search for each connected component by running dfs over all the alphabets 41 | // for (char ch : s) { 42 | // graph[i].pb(n + (ch - 'a')); 43 | // graph[n + (ch - 'a')].pb(i); 44 | // } 45 | // } 46 | // int ans = 0; 47 | // vector visited(n + 26, false); 48 | // for (int i = n; i < n + 26; i++) { 49 | // if (!visited[i] && !graph[i].empty()) { 50 | // ans += 1; 51 | // dfs(i, graph, visited); 52 | // } 53 | // } 54 | // cout << ans << endl; 55 | // } 56 | 57 | // int main() { 58 | // ios_base::sync_with_stdio(false); 59 | // cin.tie(0); 60 | // cout.tie(0); 61 | // int t = 1; 62 | // // cin >> t; 63 | // while (t--) { 64 | // solve(); 65 | // } 66 | // return 0; 67 | // } 68 | 69 | // * DSU APPROACH 70 | 71 | #include 72 | using namespace std; 73 | 74 | #define int long long int 75 | #define vi vector 76 | #define pii pair 77 | #define pb push_back 78 | #define mp make_pair 79 | #define all(a) a.begin(), a.end() 80 | const int MOD = 1e9 + 7; 81 | const int INF = 1e18; 82 | #define inputarr(arr, n) \ 83 | for (int i = 0; i < n; i++) cin >> arr[i]; 84 | #define printarr(arr, n) \ 85 | for (int i = 0; i < n; i++) cout << arr[i] << ' '; 86 | 87 | vi parent, ranks; 88 | 89 | char find(char ch) { 90 | int c = ch - 'a'; 91 | if (c == parent[c]) return ch; 92 | return parent[c] = find(parent[c]); 93 | } 94 | 95 | void Union(char a, char b) { 96 | a = find(a); 97 | b = find(b); 98 | if (ranks[a - 'a'] < ranks[b - 'a']) 99 | parent[a - 'a'] = b; 100 | else if (ranks[b - 'a'] < ranks[a - 'a']) 101 | parent[b - 'a'] = a; 102 | else { 103 | parent[b - 'a'] = a; 104 | ranks[a - 'a']++; 105 | } 106 | } 107 | 108 | void solve() { 109 | int n; 110 | cin >> n; 111 | parent.resize(26); 112 | ranks.resize(26, 0); 113 | for (int i = 0; i < 26; i++) parent[i] = i; 114 | unordered_set ss; 115 | for (int i = 0; i < n; i++) { 116 | string s; 117 | cin >> s; 118 | for (int i = 0; i < s.length(); i++) { 119 | ss.insert(s[i]); 120 | for (int j = i + 1; j < s.length(); j++) { 121 | if (find(s[i]) != find(s[j])) { 122 | Union(s[i], s[j]); 123 | } 124 | } 125 | } 126 | } 127 | unordered_set s; 128 | for (auto it : ss) s.insert(find(it)); 129 | cout << s.size() << endl; 130 | } 131 | 132 | int32_t main() { 133 | ios_base::sync_with_stdio(false); 134 | cin.tie(0); 135 | cout.tie(0); 136 | int t = 1; 137 | // cin >> t; 138 | while (t--) { 139 | solve(); 140 | } 141 | return 0; 142 | } 143 | -------------------------------------------------------------------------------- /E1_Permutation_Minimization_by_Deque.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define int long long int 9 | #define vi vector 10 | #define pii pair 11 | #define pb push_back 12 | #define mp make_pair 13 | #define all(a) a.begin(), a.end() 14 | const int MOD = 1e9 + 7; 15 | const int INF = 1e18; 16 | #define inputarr(arr, n) \ 17 | for (int i = 0; i < n; i++) cin >> arr[i]; 18 | #define printarr(arr, n) \ 19 | for (int i = 0; i < n; i++) cout << arr[i] << ' '; 20 | 21 | void solve() { 22 | int n; 23 | cin >> n; 24 | vi arr(n); 25 | inputarr(arr, n); 26 | deque res; 27 | res.pb(arr[0]); 28 | for (int i = 1; i < n; i++) { 29 | if (arr[i] < res.front()) 30 | res.push_front(arr[i]); 31 | else 32 | res.push_back(arr[i]); 33 | } 34 | for (auto it : res) cout << it << ' '; 35 | cout << endl; 36 | } 37 | 38 | int32_t main() { 39 | ios_base::sync_with_stdio(false); 40 | cin.tie(0); 41 | cout.tie(0); 42 | int t = 1; 43 | cin >> t; 44 | while (t--) { 45 | solve(); 46 | } 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /E_Air_Conditioners.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define ll long long 9 | #define vi vector 10 | #define vll vector 11 | #define pii pair 12 | #define pll pair 13 | #define pb push_back 14 | #define mp make_pair 15 | const int MOD = 1e9 + 7; 16 | const ll INF = 1e18; 17 | #define inputarr(arr, n) \ 18 | for (ll i = 0; i < n; i++) cin >> arr[i]; 19 | #define printarr(arr, n) \ 20 | for (ll i = 0; i < n; i++) cout << arr[i] << ' '; 21 | 22 | void solve() { 23 | int n, k; 24 | cin >> n >> k; 25 | vi arr(k), temp(k), ans(n, INT_MAX); 26 | inputarr(arr, k); 27 | inputarr(temp, k); 28 | vll final_arr(n, INT_MAX), left(n), right(n); 29 | for (int i = 0; i < k; i++) final_arr[arr[i] - 1] = temp[i]; 30 | ll p = INT_MAX; 31 | for (int i = 0; i < n; i++) { 32 | left[i] = p = min(p + 1, final_arr[i]); 33 | } 34 | for (int i = n - 1; i >= 0; i--) { 35 | right[i] = p = min(p + 1, final_arr[i]); 36 | } 37 | for (int i = 0; i < n; i++) cout << min(left[i], right[i]) << ' '; 38 | cout << endl; 39 | } 40 | 41 | int main() { 42 | ios_base::sync_with_stdio(false); 43 | cin.tie(0); 44 | cout.tie(0); 45 | int t = 1; 46 | cin >> t; 47 | while (t--) { 48 | solve(); 49 | } 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /E_Arranging_The_Sheep.cpp: -------------------------------------------------------------------------------- 1 | // Author: Bihan Chakraborty 2 | // Linkedin: https://www.linkedin.com/in/bihan-chakraborty 3 | // Github: https://github.com/Bihan001 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define ll long long 9 | #define vi vector 10 | #define vll vector 11 | #define pii pair 12 | #define pll pair 13 | #define pb push_back 14 | #define mp make_pair 15 | const int MOD = 1e9 + 7; 16 | const ll INF = 1e18; 17 | #define inputarr(arr, n) \ 18 | for (ll i = 0; i < n; i++) cin >> arr[i]; 19 | #define printarr(arr, n) \ 20 | for (ll i = 0; i < n; i++) cout << arr[i] << ' '; 21 | 22 | void solve() { 23 | ll n; 24 | cin >> n; 25 | string s; 26 | cin >> s; 27 | vll left(n), right(n); 28 | ll ans = 0, cnt = 0; 29 | ll start = 0; 30 | for (ll i = 0; i < n; i++) { 31 | if (s[i] == '*') break; 32 | start += 1; 33 | } 34 | for (ll i = n - 1; i >= 0; i--) { 35 | if (s[i] == '*') break; 36 | n -= 1; 37 | } 38 | for (ll i = start; i < n; i++) { 39 | left[i] = cnt; 40 | if (s[i] == '*') cnt += 1; 41 | } 42 | cnt = 0; 43 | for (ll i = n - 1; i >= start; i--) { 44 | right[i] = cnt; 45 | if (s[i] == '*') cnt += 1; 46 | } 47 | for (ll i = start; i < n; i++) { 48 | if (s[i] == '*') continue; 49 | ans += min(left[i], right[i]); 50 | } 51 | cout << ans << endl; 52 | } 53 | 54 | int main() { 55 | ios_base::sync_with_stdio(false); 56 | cin.tie(0); 57 | cout.tie(0); 58 | int t = 1; 59 | cin >> t; 60 | while (t--) { 61 | solve(); 62 | } 63 | return 0; 64 | } 65 | --------------------------------------------------------------------------------