├── .gitignore ├── apac ├── round 1b │ ├── A-large.in │ ├── A-small-attempt0.in │ ├── A-small.cpp │ ├── B-largecode.cpp │ ├── B-small-attempt0.in │ ├── B-small.cpp │ ├── C-small-attempt0.in │ ├── C-small.cpp │ └── sub-src-3.zip ├── round 1e │ ├── A-large.in │ ├── A-output.txt │ ├── A-small-attempt0.in │ ├── A-small.cpp │ ├── B-large.in │ ├── B-output.txt │ ├── B-small-attempt0.in │ ├── B-small.cpp │ ├── C-large.in │ ├── C-small-attempt0.in │ └── C-small.cpp └── round1d │ ├── A-small-attempt0.in │ ├── A-small.cpp │ ├── A-small.in │ ├── B-large.in │ ├── B-largecode.cpp │ ├── B-small-attempt0.in │ ├── B-small.cpp │ ├── C-large.in │ ├── C-small.cpp │ ├── D-small-attempt0.in │ ├── D-small.cpp │ └── Vote.cpp ├── codechef ├── ACMIND17 │ ├── COMPEXP.cpp │ ├── EQUALMOD.cpp │ └── ORDTEAMS.cpp ├── April Challenge 17 │ ├── CHEFDIV.cpp │ ├── CLIQUED.cpp │ ├── DISHLIFE.cpp │ ├── ROWSOLD.cpp │ ├── SIMDISH.cpp │ └── SMARKET.cpp ├── August Challenge 16 │ ├── CHCHCL.cpp │ ├── CHEFCRUN.cpp │ ├── CHEFCRUNutil.cpp │ ├── CHEFRRUN.cpp │ └── input.txt ├── August Challenge 17 │ ├── CHEFFA.cpp │ ├── CHEFMOVR.cpp │ ├── GCAC.cpp │ ├── PALINGAM.cpp │ ├── RAINBOWA.cpp │ └── STRINGRA.cpp ├── August Lunchtime 16 │ ├── ALPHABET.cpp │ └── LFSTACK.cpp ├── BITFLIT │ ├── APJSWG.cpp │ ├── JUMBSTRY.cpp │ ├── SPECRK.cpp │ ├── SPECRK.py │ └── THESAV.cpp ├── BYD1610.cpp ├── CAKEDOOM.cpp ├── CB03.cpp ├── CHEFARRP.cpp ├── CHEFSPL.cpp ├── CHEFST.py ├── COOK89 │ ├── BTAR.cpp │ ├── FBMT.cpp │ └── MINSUBAR.cpp ├── COOK90 │ ├── MAGA.cpp │ ├── MULTHREE.cpp │ └── SURVIVE.cpp ├── COOK91 │ ├── CARRAY.cpp │ ├── CCOOK.cpp │ ├── CSUBSEQ.cpp │ └── CTHREE.cpp ├── COSH1503.cpp ├── December Challenge 16 │ ├── ALEXROSE-naive.cpp │ ├── ANKTRAIN.cpp │ ├── BASE-naive.cpp │ ├── BASE.cpp │ ├── KIRLAB-naive.cpp │ ├── KIRLAB.cpp │ ├── KIRLAB.py │ ├── KTHMAX-misunderstood_approach.cpp │ ├── KTHMAX.cpp │ └── THREECOL.cpp ├── December Challenge 17 │ ├── CHEFEXQ.cpp │ ├── CHEFHAM.cpp │ ├── CHEFUNI.cpp │ ├── CPLAY.cpp │ ├── GIT01.cpp │ ├── REDBLUE-naive.cpp │ ├── REDBLUE.py │ └── VK18.cpp ├── February Challenge 17 │ ├── CHEFAPAR.cpp │ ├── GERMANDE.cpp │ └── MAKETRI.cpp ├── GCDQ.cpp ├── JAN18 │ ├── KCON.cpp │ ├── MAXSC.cpp │ ├── MONSTER.cpp │ ├── PRTITION.cpp │ ├── RECTANGL.cpp │ └── STRMRG.cpp ├── January Challenge 17 │ ├── CAPIMOVE.cpp │ ├── CATSDOGS.cpp │ ├── CHEFCIRC.cpp │ ├── DIGITSEP.cpp │ ├── FOURSQ.cpp │ ├── RESERVOI.cpp │ └── TOURISTS.cpp ├── July long Challenge 17 │ ├── EXPTREE.cpp │ ├── IPCTRAIN.cpp │ └── PSHTTR.cpp ├── June Challenge 16 │ ├── BINOP.cpp │ ├── CHCOINSG.cpp │ ├── CHEARMY.cpp │ ├── CHEFARK.cpp │ ├── CHSQARR.cpp │ ├── DEVARRAY.cpp │ └── FRJUMP.cpp ├── June Challenge 17 │ ├── GOODSET.cpp │ ├── NE001.cpp │ ├── PRMQ.cpp │ ├── SUMQ.cpp │ ├── UNIONSET.cpp │ └── XENRANK.cpp ├── June Cook-Off 17 │ ├── ADACRA.cpp │ ├── ADADET.cpp │ ├── CENTREE.cpp │ ├── KNICOV.cpp │ └── SNACKUP.cpp ├── KOL15B.cpp ├── KTTABLE.cpp ├── MAXISUM.cpp ├── MMSUM.cpp ├── MTRNSFRM.cpp ├── May Challenge 16 │ ├── CHBLLS.cpp │ ├── CHEFMATH.cpp │ ├── CHEFNUM.cpp │ ├── CHEFSOC2.cpp │ ├── FORESTGA.cpp │ ├── LADDU.cpp │ ├── SEAGCD2.cpp │ ├── bruteCHEFMATH.cpp │ └── bruteSEAGCD2.cpp ├── November Chellenge 17 │ ├── CHEFHPAL.cpp │ ├── CSUBQ.cpp │ ├── PERPALIN.cpp │ └── SEGPROD.cpp ├── November Lunch Time 16 │ ├── CHEFSSET.cpp │ └── CHEFSTUD.cpp ├── OCT17 │ ├── CHEFCCYL.cpp │ ├── MEX.cpp │ ├── PERFCONT.cpp │ ├── temp_output0 │ ├── temp_output1 │ └── temp_output2 ├── ORACLCS.py ├── October Challenge 16 │ ├── BGQRS.cpp │ ├── CHDOGS.cpp │ ├── CHEFKEY.cpp │ ├── CHEFTWOS.cpp │ ├── FENWITER.cpp │ ├── GEOCHEAT_naive.cpp │ ├── SEARRI.cpp │ └── input.txt ├── PLANEDIV.py ├── SOPC2017 │ ├── OPC1702.cpp │ └── OPC1703.cpp ├── STRPALIN.cpp ├── September Challenge 16 │ ├── CHEFKC.cpp │ ├── CHFNFRN-brute.cpp │ ├── CHFNFRN.cpp │ ├── CHMTDV.cpp │ ├── DIVMAC-naive.cpp │ ├── DIVMAC.cpp │ ├── JTREE.cpp │ ├── LEXOPAL.cpp │ ├── LONGSEQ.cpp │ ├── RESCALC.cpp │ ├── input.txt │ └── newDIVMAC.cpp ├── September Challenge 17 │ ├── CHEFPDIG.cpp │ ├── CHEFSUM.cpp │ ├── FILLMTR.cpp │ ├── MINPERM.cpp │ ├── SEACO.cpp │ └── WEASELTX.cpp ├── September Cook Off 16 │ ├── TAASEQ.cpp │ ├── TACNTSTR.cpp │ └── TALAZY.cpp ├── SnackDown-16 │ ├── SnackDown elimination round │ │ ├── ALLIANCE.cpp │ │ ├── ARITHM.cpp │ │ ├── COLTREE.cpp │ │ └── RWALK.cpp │ ├── Snackdown Pre-Elimination round A │ │ ├── MAKELIS.cpp │ │ └── SUBSEG2.cpp │ └── Snackdown Pre-Elimination round B │ │ ├── ENTEXAM.cpp │ │ └── MMPROD.cpp ├── SnackDown-17 │ ├── Elimination Round 17 │ │ ├── ANCESTOR.cpp │ │ ├── MEXDIV.cpp │ │ └── PLUSMUL.cpp │ ├── Pre-Elimination round A │ │ ├── CONSESNK.cpp │ │ ├── PROTEPOI.cpp │ │ └── SNTEMPLE.cpp │ └── Pre-Elimination round B │ │ ├── SNCOUP.cpp │ │ ├── SNDISCUS.cpp │ │ ├── SNGRAPH.cpp │ │ └── SNSOCIAL.cpp ├── TSTIND17 │ ├── CHN05.cpp │ └── TYTACTIC.cpp ├── bruteMMSUM.cpp ├── march long challenge 17 │ ├── BANDMATR.cpp │ ├── EXTRAN.cpp │ ├── PSHTBRTH.cpp │ ├── SCHEDULE.cpp │ └── XENTASK.cpp ├── prefix_power_of_2.py └── shaastraOPc │ ├── SOPC1501.cpp │ ├── SOPC1502.cpp │ ├── SOPC1503.cpp │ ├── SOPC1504.cpp │ ├── SOPC1505.cpp │ ├── SOPC1506.cpp │ ├── SPC1601.cpp │ └── SPC1602.cpp ├── codefights ├── CodeLeader.cpp ├── May_Marathon │ └── hello world.cpp ├── christmastree.cpp ├── davinci.cpp ├── even.cpp ├── fibonaccicodingIII.cpp ├── fractalMatrix.cpp ├── poke_game.cpp ├── vending_machine.cpp └── waterFilling.cpp ├── codeforces ├── 1009A-Game_shopping.cpp ├── 1009B-Minimum_terenary_string.cpp ├── 1009C-Annoying_present.cpp ├── 1009D-Relatively_prime_graph.cpp ├── 1009E-Intercity_Travelling.cpp ├── 101510B.cpp ├── 101510D.cpp ├── 110A-nearly_lucky_number.cpp ├── 119A-epic_game.cpp ├── 122A-Lucky_division.cpp ├── 131A-caps_lock.cpp ├── 136A-presents.cpp ├── 148A-insomnia_cure.cpp ├── 148A-insomnia_cure.cpp~ ├── 158B-taxi.cpp ├── 208A-Dubstep.cpp ├── 231A-Team.cpp ├── 236A-boyorgirl.cpp ├── 271A-beautiful_year.cpp ├── 282A-Bit++.cpp ├── 344A-magnets.cpp ├── 383A-Arpas_hard_exam.cpp ├── 383B-Arpas_obvious_problem.cpp ├── 383C-arpas_loud_owf.cpp ├── 383D-arpas_weak_amphitheatre.cpp ├── 385A-hongcow_learns_cyclic_shift.cpp ├── 385B-hongcow_solves_puzzle.cpp ├── 385C-hongcow_builds_a_nation.cpp ├── 420A-startup.cpp ├── 425A-sasha_and_sticks.cpp ├── 425B-petya_and_exam.cpp ├── 425D-Misha_grisha_and_underground.cpp ├── 451A-game_with_sticks.cpp ├── 460A-vasya&socks.cpp ├── 467A-george_and_accomodation.cpp ├── 472A-learn_from_math.cpp ├── 540A-combination_lock.cpp ├── 540C-Ice_cave.cpp ├── 567A-lineland_mail.cpp ├── 567B-berland_national_library.cpp ├── 570A-elections.cpp ├── 570B-simple_game.cpp ├── 570C-replacement.cpp ├── 570D-tree_requests.cpp ├── 570d-tree_requests.py ├── 573B-bear_blocks.cpp ├── 58A-chat_room.cpp ├── 606B.cpp ├── 606C.cpp ├── 610A.cpp ├── 610B.cpp ├── 656A-Da_Vinci_Powers.cpp ├── 656A-Da_Vinci_Powers.py ├── 656G-You're_a_professional.cpp ├── 675A-Infinite_sequence.cpp ├── 675B-Restoring_painting.cpp ├── 675C-Money_Transfers.cpp ├── 675D-Tree_Construction.cpp ├── 676A-Nicholas_and_permutation.cpp ├── 676B-Pyramid_of_glasses.cpp ├── 676C-Vasya_and_String.cpp ├── 680A-Bear_and_Five_cards.cpp ├── 680B-Bear_and_finding_criminals.cpp ├── 680C-Bear_and_prime100.cpp ├── 680D-Bear_and_tower_of_cubes.cpp ├── 680bruteD-Bear_and_tower_of_cubes.cpp ├── 702A-Maximum_Increasse.cpp ├── 702B-Powers_of_Two.cpp ├── 702C-Cellular_Network.cpp ├── 709A-juicer.cpp ├── 709B-Checkpoints.cpp ├── 709C-Letters_Cyclic_shift.cpp ├── 709D-Recover_the_string.cpp ├── 712A-memory_and_crow.cpp ├── 712B-memory_and_trident.cpp ├── 712C-memory_and_deevolution.cpp ├── 714A-meeting_of_old_friends.cpp ├── 714B-Filya_and_homework.cpp ├── 714C-Sonya_and_queries.cpp ├── 714D-Searching_rectangles.cpp ├── 731A-Night_at_the_museum.cpp ├── 731B-Coupons_and_discounts.cpp ├── 731C-Socks.cpp ├── 732A-Buy_a_shovel.cpp ├── 732B-Cormen.cpp ├── 732C-Sanatorium.cpp ├── 735A-Ostap_and_grasshopper.cpp ├── 735B-Urbanization.cpp ├── 735C-Tennis_Championship.cpp ├── 735D-Taxes.cpp ├── 754A-Lesha_array_splitting.cpp ├── 754B-Ilya_and_tic_tac_toe_game.cpp ├── 754C-Vladik_and_chat.py ├── 755A-polandball_and_hypothesis.cpp ├── 755B-polandball_and_game.cpp ├── 755C-polandball_and_forest.cpp ├── 755D-polandball_and_polygon.cpp ├── 757A-Gotta_catch_em_all.cpp ├── 757B-Bashs_big_day.cpp ├── 757C-Felicity_is_coming.cpp ├── 760A-petr_and_calendar.cpp ├── 760B-Frodo_and_pillows.cpp ├── 760C-Pavel_and_barbeque.cpp ├── 760D-travel_card.cpp ├── 764A-Taymyr_is_calling_you.cpp ├── 764B-Timofey_and_cubes.cpp ├── 764C-Timofey_and_a_tree.cpp ├── 764D-Timofey_and_rectangels.cpp ├── 789A-Anastasia_and_pebbles.cpp ├── 822A-bored_with_life.cpp ├── 822B-Crossword_Solving.cpp ├── 822C-pack_your_bags.cpp ├── 822D-My_pretty_girl_noora.cpp ├── 828A-Restuarant_tables.cpp ├── 828B-Black_Square.cpp ├── 828C-String_reconstruction.cpp ├── 828D-High_Load.cpp ├── 82A-double_cola.cpp ├── 847A-Union_of_doubly_linked_lists.cpp ├── 847D-Dog_Show.cpp ├── 847E-Packmen.cpp ├── 847H-Load_testing.cpp ├── 847I-Noise_level.cpp ├── 847K-Travel_cards.cpp ├── 847M-Weather_tomorrow.cpp ├── 895A-Pizza_separation.cpp ├── 895B-XK_Segments.cpp ├── 897A-Scarborough_fair.cpp ├── 897B-Chthollys_request.py ├── 897C-Nephren_gives_a_riddle.cpp ├── 897C-Nephren_gives_a_riddle.py ├── 908A-CountingCards.cpp ├── 908B-Buggy_Bot.cpp ├── 908C-Curling.cpp ├── 911A-nearest_minimum.cpp ├── 911B-Two_cakes.cpp ├── 911C-garland.cpp ├── 911D-InversionCounting.cpp ├── 911E-Stack_sorting.cpp ├── 911F-Tree_Destruction.cpp ├── 911G-Mass_change_querries.cpp ├── 912A-Tricky_alchemy.cpp ├── 912B-New_years_eve.cpp ├── 912C-perun_ult.cpp ├── 912D-Fishes.cpp ├── 916A-Jaime_And_alarm_snooze.cpp ├── 916B-Jaime_and_binary_sequence.cpp ├── 916C-interesting_graph.cpp ├── 918A-Eleven.cpp ├── 918B-radio_station.cpp ├── 918C-Monster.cpp ├── 918D-MadMax.cpp ├── 922A-Cloning_toys.cpp ├── 922B-Magic_Forest.cpp ├── 922C-cave_painting.cpp ├── 922C-cave_painting.py ├── 922D-robot_vaccuum_cleaner.cpp ├── 935A-Fafa_and_his_company.cpp ├── 935B-Fafa_and_the_gates.cpp ├── 935C-Fifa_and_fafa.cpp ├── 935D-Fafa_and_ancient_alphabet.cpp ├── 959A-even-odd-game.cpp ├── 959B-ME-the-message.cpp ├── 959C-ME-wrong-algorithm.cpp ├── 959D-ME-another-array-construction-naive.cpp ├── 959E-ME-xor-MST.cpp ├── 959F-ME-yet-another-xor-task.cpp ├── 998A-balloons.cpp ├── 998B-Cutting.cpp ├── 998C-Convert_to_ones.cpp ├── Erothesthenes_seive.cpp ├── String_task-cf.cpp ├── avltree_insertion_non-recursive.c ├── bfs.cpp ├── dominoes_piling.cpp ├── floyd_warshall_recursion.cpp └── template ├── codejam-16 ├── qualification round │ ├── A-large.in │ ├── A-small-attempt0.in │ ├── B-large.in │ ├── B-small-attempt0.in │ ├── B-small-input.in │ ├── D-small-attempt0.in │ ├── Fractiles.cpp │ ├── Fractiles_util.cpp │ ├── INMO-2016 English Version.pdf │ ├── coin-jam.cpp │ ├── combinations │ ├── counting_sheep.py │ ├── input │ ├── jam-coin.py │ ├── primes.py │ ├── revenge_of_the_pancakes.cpp │ └── sol-inmo16.pdf ├── round 1a │ ├── A-large.in │ ├── A-small-attempt-0.in │ ├── A-small-attempt0.in │ ├── B-large.in │ ├── B-small-attempt0.in │ ├── BFF.cpp │ ├── C-small-attempt0.in │ ├── Rank_and_File.cpp │ ├── failed │ ├── sub-src-3.zip │ └── the_last_word.cpp ├── round 1b │ ├── A-large.in │ ├── A-small-attempt0.in │ ├── A.cpp │ ├── B-small-attempt0.in │ ├── B.cpp │ ├── BFF.cpp │ ├── C-small-attempt0.in │ ├── C.py │ ├── Rank_and_File.cpp │ ├── output │ ├── output1 │ ├── output3 │ ├── sub-1.in │ ├── sub-src-1.zip │ └── the_last_word.cpp └── round 1c │ ├── A-large.in │ ├── A-small-attempt0.in │ ├── A.cpp │ ├── B-large.in │ ├── B-small-attempt0.in │ ├── B.cpp │ ├── C-small-attempt.in │ ├── C-small-attempt0.in │ ├── C.cpp │ └── C.py ├── codejam-17 ├── qualification_round_2017 │ ├── A-small-attempt0.in │ ├── A-small.cpp │ ├── B-large.in │ ├── B-small-attempt0.in │ ├── B-small.cpp │ ├── C-large-correct.cpp │ ├── C-large-practice.in │ ├── C-large.in │ ├── C-small-2-attempt0.in │ ├── C-small-attempt0.in │ └── C-small.cpp ├── round 1b │ ├── A-large.in │ ├── A-small-attempt0.in │ ├── A-small.cpp │ ├── B-large.in │ ├── B-sample.in │ ├── B-small-attempt0.in │ ├── B-small.cpp │ ├── C-large-correct.cpp │ ├── C-small-attempt0.in │ └── C-small.cpp └── round 1c │ ├── A-large.in │ ├── A-small-attempt.in │ ├── A-small-attempt0.in │ ├── A-small-attempt1.in │ ├── A-small.cpp │ ├── B-large.in │ ├── B-small-attempt.in │ ├── B-small-attempt0.in │ ├── B-small.cpp │ ├── C-large-correct.cpp │ ├── C-small-1-attempt0.in │ ├── C-small-attempt0.in │ └── C-small.cpp ├── codejam-18 ├── qualification_round_2018 │ ├── A-small.cpp │ ├── B-small.cpp │ └── testing_tool.py ├── round 1b │ ├── mysterious_road_signs.cpp │ ├── rounding_error.cpp │ └── transmutation.cpp └── round 1c │ ├── a-whole-new-world.cpp │ └── ant-stack.cpp ├── hackercup ├── 2017 │ ├── qualification round │ │ ├── fighting_the_zombie.cpp │ │ ├── lazy_loading.cpp │ │ └── progress_pie.cpp │ ├── round1 │ │ ├── fighting_the_zombie.cpp │ │ ├── input_generator.py │ │ ├── manic_moving.cpp │ │ └── progress_pie.cpp │ └── round2 │ │ ├── big_top.cpp │ │ ├── fighting_the_zombie.cpp │ │ ├── naive.cpp │ │ └── subtle_sabotage.cpp └── 2018 │ └── qualification round │ ├── ethan_searches_for_a_string.cpp │ └── interception.cpp ├── hackerearth ├── codathon18-nitbhopal │ ├── day-1.cpp │ ├── day-2.cpp │ ├── day-3-game-of-disks.cpp │ ├── day-3-graph-question.cpp │ ├── day-4-training-the-joker.cpp │ ├── day-6.cpp │ ├── day-7.cpp │ └── test-gen.py └── lets-code-20 │ ├── bot-game.cpp │ ├── coin-problem.cpp │ ├── find_median_without_sorting.cpp │ ├── help-shivam-naive.cpp │ ├── help-shivam.cpp │ ├── lets-run.cpp │ └── mavis-and-his-problem.cpp ├── hackerrank ├── codeagon_contest_gohanandblocks.cpp ├── codestorm15 │ ├── boomarang.py │ ├── little-alexeys-tree-map.cpp │ └── little-alexeys-tree.cpp ├── hourrank11 │ ├── lcsreturns.cpp │ └── strangecounter.cpp ├── hourrank3 │ ├── divisor-exploration-4-problem-tester.cpp │ └── divisor-exploration-4.cpp ├── weekofcode17 │ ├── 13friday.cpp │ ├── cp.cpp │ ├── ctr.py │ └── roads_building.cpp ├── weekofcode19 │ └── two_robots.cpp ├── weekofcode21 │ └── n-letter.cpp ├── weekofcode23 │ └── lighthouse.cpp ├── world-code-sprint-April │ ├── permuations.cpp │ └── toh.cpp └── worldcup-university_level_hack │ ├── bishop-war │ └── bwar.cpp │ ├── delivery.cpp │ ├── quantumland.py │ └── worldcupcity.cpp ├── icpc16 ├── b.cpp ├── d.cpp ├── f.cpp ├── g.cpp ├── input.txt └── template.cpp ├── kickstart-17 ├── round c │ ├── A-large.in │ ├── A-small-attempt0.in │ ├── A-small.cpp │ ├── B-large.in │ ├── B-small-attempt0.in │ ├── B-small-attempt1.in │ ├── B-small-attempt2.in │ ├── B-small-attempt3.in │ ├── B-small.cpp │ ├── C-large.in │ ├── C-small-attempt0.in │ ├── C-small.cpp │ ├── D-small-attempt0.in │ └── D-small.cpp └── round f │ ├── A-large.in │ ├── A-small-attempt0.in │ ├── A-small.cpp │ ├── B-large.in │ ├── B-small-attempt0.in │ ├── B-small-attempt1.in │ ├── B-small.cpp │ ├── C-small-attempt0.in │ ├── C-small.cpp │ ├── D-generator.cpp │ ├── D-large.in │ ├── D-small-attempt0.in │ └── D-small.cpp ├── programming templates ├── Circles.cpp ├── Enumerating_MIS.cpp ├── Floyd_Warshall.cpp ├── Heavy_Light_Decomposition.cpp ├── Knapsack.cpp ├── LCA.cpp ├── LCS_dp.cpp ├── articulate_points.cpp ├── bfs_template.cpp ├── bitmask_template.cpp ├── connected_components.cpp ├── dfs_template.cpp ├── diameter_of_a_tree.cpp ├── dijkstras.cpp ├── divisorsOfAllNumbers.cpp ├── enumerating_subsequences.cpp ├── euler_totient.cpp ├── factorialMod.cpp ├── fasterPartitionProblem.cpp ├── fibonacci_matrix_logn.cpp ├── firstDigitProduct.cpp ├── graph_matrix_representation.cpp ├── kadane.cpp ├── lagranges_square_theorem.cpp ├── main_template.cpp ├── matrixTranspose.cpp ├── max_key_IndependentSet.cpp ├── multiplicative_Modular_Inverse.cpp ├── nCk.cpp ├── no_palindromic_subsequence.cpp ├── partition problem.cpp ├── point&ray.cpp ├── rank_a_tree.cpp ├── root_unrooted_tree.cpp ├── segment_trees.cpp ├── segment_trees_lazy_propagation.cpp ├── sieve_of_eratosthenes.cpp ├── sliding_Window_Maximum_1D.cpp ├── sliding_Window_Maximum_2D.cpp └── sumsubMatrix.cpp └── topcoder ├── BuildStrings.cpp ├── FrogSquare.cpp ├── StepsConstruct.cpp ├── armorup.cpp ├── poison.cpp └── sol.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | *.out 2 | *.vvp 3 | *.txt 4 | doomsday_fuel.py 5 | grand_staircase.py 6 | bomb_baby.py 7 | own_questions/* 8 | -------------------------------------------------------------------------------- /apac/round 1b/A-small-attempt0.in: -------------------------------------------------------------------------------- 1 | 100 2 | 0 10 3 | 1 8 4 | 17 1 5 | 18 1 6 | 14 4 7 | 11 2 8 | 12 8 9 | 0 2 10 | 18 2 11 | 5 13 12 | 2 1 13 | 12 8 14 | 13 1 15 | 11 4 16 | 9 11 17 | 18 2 18 | 0 2 19 | 14 3 20 | 18 1 21 | 11 3 22 | 16 2 23 | 2 0 24 | 1 1 25 | 1 7 26 | 13 3 27 | 6 4 28 | 11 9 29 | 7 10 30 | 13 1 31 | 4 6 32 | 1 5 33 | 12 1 34 | 2 7 35 | 10 4 36 | 10 10 37 | 13 3 38 | 7 12 39 | 1 0 40 | 0 1 41 | 13 6 42 | 16 2 43 | 14 3 44 | 6 5 45 | 4 10 46 | 2 11 47 | 12 6 48 | 2 11 49 | 0 20 50 | 6 2 51 | 18 1 52 | 12 8 53 | 15 5 54 | 18 1 55 | 4 13 56 | 16 3 57 | 6 1 58 | 18 1 59 | 20 0 60 | 16 4 61 | 4 3 62 | 16 2 63 | 9 3 64 | 0 20 65 | 6 4 66 | 7 13 67 | 5 8 68 | 15 3 69 | 16 2 70 | 6 14 71 | 11 9 72 | 3 1 73 | 3 6 74 | 10 1 75 | 13 1 76 | 12 7 77 | 10 6 78 | 18 1 79 | 16 4 80 | 17 2 81 | 14 1 82 | 18 2 83 | 15 2 84 | 0 1 85 | 8 10 86 | 7 13 87 | 4 4 88 | 2 9 89 | 13 1 90 | 15 5 91 | 13 7 92 | 18 2 93 | 9 9 94 | 10 9 95 | 17 3 96 | 19 1 97 | 15 2 98 | 7 12 99 | 3 3 100 | 1 9 101 | 1 5 102 | -------------------------------------------------------------------------------- /apac/round 1b/A-small.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(){ 4 | ifstream infile; 5 | ofstream outfile; 6 | long long t; 7 | infile.open("A-large.in"); 8 | outfile.open("A-output.out"); 9 | infile>>t; 10 | for(long long tk=1;tk<=t;tk++){ 11 | long long l,r; 12 | infile>>l>>r; 13 | long long mv = min(l,r); 14 | mv = mv*(mv+1)/2; 15 | outfile<<"Case #"< 2 | using namespace std; 3 | 4 | int t, N, M; 5 | 6 | double dp[2222][2222]; 7 | bool vis[2222][2222]; 8 | 9 | double f(int n, int m) { 10 | if (n > M) return 1; 11 | if (vis[n][m]) return dp[n][m]; 12 | vis[n][m] = 1; 13 | 14 | int tot = (N - n) + (M - m); 15 | 16 | dp[n][m] = (double) (N - n) / tot * f(n+1, m); 17 | if (m < M && n > m + 1) dp[n][m] += (double) (M - m) / tot * f(n, m+1); 18 | return dp[n][m]; 19 | } 20 | 21 | int Main() { 22 | scanf ("%d %d", &N, &M); 23 | for (int i=0; i<=M; i++) for (int j=0; j<=M; j++) vis[i][j] = 0; 24 | 25 | printf ("%.8lf\n", f(0, 0)); 26 | return 0; 27 | } 28 | 29 | int main() { 30 | int t; 31 | scanf ("%d", &t); 32 | for (int tc=0; tc 2 | #define ll long long 3 | #define pb push_back 4 | #define mp make_pair 5 | #define vll vector 6 | using namespace std; 7 | int main(){ 8 | int t; 9 | cin>>t; 10 | while(t--){ 11 | double n,k; 12 | cin>>n>>k; 13 | double ans = 2*(n-1)*(k-1); 14 | ans /= k; 15 | ans += 2; 16 | printf("%.8f\n",ans); 17 | } 18 | return 0; 19 | } -------------------------------------------------------------------------------- /codechef/ACMIND17/ORDTEAMS.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define pb push_back 4 | #define mp make_pair 5 | #define vll vector 6 | using namespace std; 7 | bool func(vector a, vector b, vector c) { 8 | for(int i=0;i<3;i++){ 9 | if(a[i] > b[i] || b[i] > c[i]) return false; 10 | } 11 | if(a == b || b == c || a == c) return false; 12 | return true; 13 | } 14 | int main(){ 15 | int t; 16 | cin>>t; 17 | while(t--){ 18 | vector a,b,c; 19 | for(int i=0;i<3;i++){ 20 | int x; 21 | cin>>x; 22 | a.pb(x); 23 | } 24 | for(int i=0;i<3;i++){ 25 | int x; 26 | cin>>x; 27 | b.pb(x); 28 | } 29 | for(int i=0;i<3;i++){ 30 | int x; 31 | cin>>x; 32 | c.pb(x); 33 | } 34 | if(func(a,b,c) || func(a,c,b) || func(b,a,c) || func(b,c,a) || func(c,a,b) || func(c,b,a)) 35 | cout<<"yes\n"; 36 | else cout<<"no\n"; 37 | } 38 | return 0; 39 | } -------------------------------------------------------------------------------- /codechef/April Challenge 17/DISHLIFE.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | int t; 5 | cin>>t; 6 | while(t--) { 7 | long n,k; 8 | cin>>n>>k; 9 | vector arr(k+1,0); 10 | arr[0] = 1; 11 | vector > q; 12 | while(n--) { 13 | long x; 14 | cin>>x; 15 | vector temp(x); 16 | for(int i=0;i>temp[i]; 18 | arr[temp[i]]++; 19 | } 20 | q.push_back(temp); 21 | } 22 | bool yes = true; 23 | for(int i = 0; i 2 | using namespace std; 3 | int main() { 4 | int t; 5 | cin>>t; 6 | while(t--) { 7 | long long ans= 0; 8 | long long no = 0; 9 | string x; 10 | cin>>x; 11 | long long streak = 0; 12 | for(long i=0;i 2 | using namespace std; 3 | int main() { 4 | int t; 5 | cin>>t; 6 | while(t--) { 7 | set a; 8 | for(int i=0;i<4;i++) { 9 | string x; 10 | cin>>x; 11 | a.insert(x); 12 | } 13 | int ans = 0; 14 | for(int i=0;i<4;i++) { 15 | string x; 16 | cin>>x; 17 | if(a.find(x)!=a.end()) 18 | ans++; 19 | } 20 | if(ans >= 2) 21 | cout<<"similar"< 2 | using namespace std; 3 | int main(){ 4 | long t; 5 | long long m,n; 6 | cin>>t; 7 | while(t--){ 8 | cin>>m>>n; 9 | if(m%2==0 || n%2 == 0){ 10 | cout<<"Yes"< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | long n, m; 8 | cin>>n>>m; 9 | vector arr(n); 10 | long long sum =0; 11 | for(long i=0;i>arr[i]; 13 | sum += arr[i]; 14 | } 15 | bool flag = true; 16 | long long ans = 0; 17 | long actual; 18 | if(sum % arr.size() == 0){ 19 | actual = sum /arr.size(); 20 | for(long i=0;i= n && arr[j] != actual){ 23 | flag = false; 24 | break; 25 | } 26 | if(arr[j] > actual){ 27 | ans += arr[j]-actual; 28 | arr[j+m] += arr[j]-actual; 29 | arr[j] = actual; 30 | } else if (arr[j] < actual){ 31 | ans += actual-arr[j]; 32 | arr[j+m] += arr[j]-actual; 33 | arr[j] = actual; 34 | } 35 | } 36 | } 37 | } else 38 | flag = false; 39 | cout<<(flag?ans:-1)< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--) { 7 | long n,m; 8 | cin>>n>>m; 9 | vector minsal(n); 10 | for(long i=0;i>minsal[i]; 12 | vector sal(m); 13 | vector vacancy(m); 14 | for(long i=0;i>sal[i]>>vacancy[i]; 16 | vector arr(n); 17 | long no_placed = 0; 18 | long long total_sal = 0; 19 | vector companies(m,true); 20 | long remaining = m; 21 | for(long i=0;i>arr[i]; 23 | long ans = -1; 24 | long sal_now = minsal[i]; 25 | for(int j=0;j 0){ 27 | ans = j; 28 | sal_now = sal[j]; 29 | } 30 | } 31 | if(ans != -1) { 32 | no_placed++; 33 | total_sal += sal[ans]; 34 | vacancy[ans]--; 35 | if(companies[ans]) { 36 | companies[ans] = false; 37 | remaining--; 38 | } 39 | } 40 | } 41 | cout< 2 | using namespace std; 3 | int main() { 4 | long t; 5 | cin>>t; 6 | while(t--) { 7 | string a, b; 8 | cin>>a>>b; 9 | vector hasha(26,0), hashb(26,0); 10 | for(int i=0;i 0 && hashb[i] > 0) || (hasha[i] == 0 && hashb[i] == 0)) continue; 17 | else flag = false; 18 | } 19 | if(flag) cout<<"B\n"; 20 | else { 21 | for(int i=0;i<26;i++) 22 | if(hasha[i] > 1 && hashb[i] == 0) flag = true; 23 | if(flag) cout<<"A\n"; 24 | else { 25 | int bspecial = 0, aspecial = 0; 26 | for(int i=0;i<26;i++){ 27 | if(hasha[i] == 0 && hashb[i] > 0) bspecial++; 28 | if(hashb[i] == 0 && hasha[i] > 0) aspecial++; 29 | } 30 | if(bspecial == 0) cout<<"A\n"; 31 | else cout<<"B\n"; 32 | } 33 | } 34 | } 35 | return 0; 36 | } -------------------------------------------------------------------------------- /codechef/August Challenge 17/RAINBOWA.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | long n; 8 | cin>>n; 9 | bool flag = true; 10 | vector arr(n); 11 | for(int i=0;i>arr[i]; 13 | vector ab = arr; 14 | reverse(ab.begin(),ab.end()); 15 | for(int i=0;i 2 | using namespace std; 3 | int main(){ 4 | string a,x; 5 | cin>> a; 6 | vector hash(26,false); 7 | for(int i=0;i>n; 12 | while(n--) { 13 | cin>>x; 14 | bool answer = true; 15 | for(long i=0;i 2 | using namespace std; 3 | int main() { 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | long n; 8 | cin>>n; 9 | vector a(n); 10 | for(long i=0;i>a[i]; 12 | long i; 13 | bool flag = true; 14 | int ans = 0; 15 | for(i=a.size()-1;i>=0;i--) { 16 | if(a[i]!=i+1) { 17 | if((i>=1) && (a[i-1] == i+1)) { 18 | long t = a[i]; 19 | a[i] = a[i-1]; 20 | a[i-1] = t; 21 | ans++; 22 | } else if((i>=2) && (a[i-2]==i+1)) { 23 | long t = a[i-1]; 24 | a[i-1] = a[i-2]; 25 | a[i-2] = t; 26 | t = a[i]; 27 | a[i] = a[i-1]; 28 | a[i-1] = t; 29 | ans += 2; 30 | } else { 31 | flag = false; 32 | break; 33 | } 34 | } 35 | } 36 | if(flag) 37 | cout< 2 | using namespace std; 3 | int main() { 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | long n; 8 | cin>>n; 9 | map hash; 10 | for(long i=0;i>x; 13 | if(hash.find(x) != hash.end()) 14 | hash[x] = false; 15 | else 16 | hash[x] = true; 17 | } 18 | for(map::iterator it = hash.begin();it!=hash.end();it++){ 19 | if(it->second) 20 | cout<first< 2 | using namespace std; 3 | int main() { 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | string a; 8 | cin>>a; 9 | long i; 10 | for(i=0;i=1 && a[i-1] == '*')||(i>=2 && a[i-2] == '*')) 13 | continue; 14 | else{ 15 | cout<<"NO"< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | long long n,i,s; 8 | long long ans; 9 | cin>>n; 10 | vector array; 11 | for(i=0;i>x; 14 | array.push_back(x); 15 | } 16 | ans = n; 17 | for(s=2;s<=n;s++){ 18 | for(i=0;i+s<=n;i++){ 19 | long long p = 1; 20 | long long sum = 0; 21 | for(int j=i;j 2 | #define ll long long 3 | #define pb push_back 4 | #define mp make_pair 5 | #define vll vector 6 | using namespace std; 7 | int main(){ 8 | long t; 9 | cin>>t; 10 | while(t--) { 11 | long n; 12 | cin>>n; 13 | ll v1, v2, v3, v4; 14 | v1 = v2 = v3 = v4 = 0; 15 | for(long i=0;i 2 | #define ll long long 3 | #define pb push_back 4 | #define mp make_pair 5 | #define vll vector 6 | using namespace std; 7 | int main(){ 8 | long t; 9 | cin>>t; 10 | while(t--) { 11 | long n; 12 | cin>>n; 13 | string a, b; 14 | a = b = "lakshmanaram"; 15 | long asc, bsc; 16 | asc = bsc = 0; 17 | while(n--){ 18 | string s; 19 | cin>>s; 20 | if(a == s){ 21 | asc++; 22 | } else if(b == s){ 23 | bsc++; 24 | } else if(a == "lakshmanaram"){ 25 | a = s; 26 | asc++; 27 | } else if(b == "lakshmanaram") { 28 | b = s; 29 | bsc++; 30 | } 31 | } 32 | if(asc > bsc){ 33 | cout< asc) { 35 | cout< 2 | #define ll long long 3 | #define pb push_back 4 | #define mp make_pair 5 | #define vll vector 6 | #define all(S) S.begin(), S.end() 7 | #define S(a) scanf("%lld", &a) 8 | using namespace std; 9 | int main(){ 10 | long t; 11 | scanf("%ld", &t); 12 | string yes = "YES", no = "NO"; 13 | while(t--) { 14 | ll k, d0, d1; 15 | scanf("%lld %lld %lld", &k, &d0, &d1); 16 | k -= 2; 17 | long start = -1; 18 | long long valsum = d0 + d1; 19 | ll sumd = (d0+d1)%10; 20 | if(sumd == 0 || sumd == 5){ 21 | cout< 0 && start == -1){ 25 | if(sumd == 2){ 26 | start = 1; 27 | break; 28 | } 29 | valsum += sumd; 30 | k--; 31 | sumd = (sumd*2)%10; 32 | } 33 | if(k > 0){ 34 | valsum += (k/4)*2; 35 | switch(k%4){ 36 | case 1: 37 | valsum += 2; 38 | break; 39 | case 2: 40 | valsum += 6; 41 | break; 42 | case 3: 43 | valsum += 14; 44 | break; 45 | } 46 | } 47 | if(valsum %3 ==0) cout< 2 | #define ll long long 3 | #define pb push_back 4 | #define mp make_pair 5 | #define vll vector 6 | #define all(S) S.begin(), S.end() 7 | #define S(a) scanf("%lld", &a) 8 | using namespace std; 9 | int main(){ 10 | long t; 11 | scanf("%ld", &t); 12 | while(t--) { 13 | ll n, k, s; 14 | S(n); 15 | S(k); 16 | S(s); 17 | if(s < 7){ 18 | if(n < k) cout<<"-1"< 2 | #define ll long long 3 | #define pb push_back 4 | #define mp make_pair 5 | #define vll vector 6 | #define all(S) S.begin(), S.end() 7 | #define S(a) scanf("%lld", &a) 8 | using namespace std; 9 | int main(){ 10 | long t; 11 | scanf("%ld", &t); 12 | while(t--) { 13 | ll n, k, b; 14 | cin>>n>>k>>b; 15 | vector arr(n); 16 | for(long i=0;i>arr[i]; 17 | set > s; 18 | sort(all(arr)); 19 | long ans = 0; 20 | for(long i=0;isecond; 30 | count++; 31 | auto val2 = s.upper_bound(mp(y, arr.size())); 32 | val2--; 33 | if(val2->second < count){ 34 | s.insert(mp(y, count)); 35 | ans = max(ans, count); 36 | } 37 | } 38 | } 39 | } 40 | printf("%ld\n", ans); 41 | } 42 | return 0; 43 | } -------------------------------------------------------------------------------- /codechef/COOK91/CCOOK.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define pb push_back 4 | #define mp make_pair 5 | #define vll vector 6 | #define all(S) S.begin(), S.end() 7 | #define S(a) scanf("%lld", &a) 8 | using namespace std; 9 | int main(){ 10 | long n; 11 | cin>>n; 12 | while(n--){ 13 | long a = 0; 14 | long x = 0; 15 | for(long i=0;i<5;i++){ 16 | cin>>x; 17 | a += x; 18 | } 19 | if(a < 1) cout<<"Beginner"; 20 | else if(a<2) cout<<"Junior Developer"; 21 | else if(a < 3) cout<<"Middle Developer"; 22 | else if(a < 4) cout<<"Senior Developer"; 23 | else if(a < 5) cout<<"Hacker"; 24 | else cout<<"Jeff Dean"; 25 | cout< 3 | using namespace std; 4 | long m; 5 | bool wayToSort(int i, int j) { return i > j; } 6 | void func(vector w,int i, long want,long sum){ 7 | if(m==0) 8 | return; 9 | if(i!=w.size() && want>=0 && want <= sum){ 10 | func(w,i+1,want-w[i],sum - w[i]); 11 | func(w,i+1,want,sum - w[i]); 12 | m = min(want,m); 13 | } 14 | return; 15 | } 16 | int main(){ 17 | int t; 18 | cin>>t; 19 | while(t--) 20 | { 21 | int n,i; 22 | cin>>n; 23 | vector w; 24 | long sum = 0; 25 | for(i=0;i>x; 28 | sum += x; 29 | w.push_back(x); 30 | } 31 | long want = sum/2; 32 | m = sum; 33 | sort(w.begin(),w.end(),wayToSort); 34 | i = 0; 35 | func(w,i,want,sum); 36 | cout<<(sum+1)/2 - sum/2 + m< 2 | using namespace std; 3 | int main() { 4 | int t; 5 | cin>>t; 6 | while(t--) { 7 | int n; 8 | cin>>n; 9 | if(n%8 == 7) 10 | n = n+1; 11 | else if(n%8 == 0) 12 | n = n-1; 13 | else if(n%8 < 4) { 14 | n = n+3; 15 | } else 16 | n = n-3; 17 | cout< 2 | using namespace std; 3 | int main(){ 4 | ofstream outfile; 5 | outfile.open("bnaive.txt"); 6 | for(long long n=0;n<=1000;n++){ 7 | if(n == 1) 8 | outfile<<"INFINITY\n"; 9 | else if(n == 2) 10 | outfile<<1<= cl && n < 2*cl){ 21 | ans++; 22 | break; 23 | } 24 | j++; 25 | cl = pow(temp,j); 26 | } 27 | } 28 | outfile< 2 | using namespace std; 3 | int main(){ 4 | long t; 5 | cin>>t; 6 | while(t--) { 7 | long long n; 8 | cin>>n; 9 | if(n == 1) 10 | cout<<"INFINITY\n"; 11 | else if(n == 2) 12 | cout<<1< 2 | using namespace std; 3 | long long gcd(long long a, long long b) { 4 | return (b == 0)?a:gcd(b,a%b); 5 | } 6 | int main(){ 7 | int t; 8 | cin>>t; 9 | while(t--) { 10 | long n; 11 | cin>>n; 12 | vector arr(n); 13 | for(long i=0;i>arr[i]; 15 | vector > mat(n); 16 | long mv = 0; 17 | for(long i=0;i 2 | #define ll long long 3 | #define pb push_back 4 | #define mp make_pair 5 | #define vll vector 6 | using namespace std; 7 | int main(){ 8 | while(1){ 9 | char x[23]; 10 | for(int i=0;i<23;i++) x[i] = '1'; 11 | scanf("%s", &x); 12 | if(strlen(x) == 23) break; 13 | int a = 0, b = 0; 14 | int rema = 5, remb = 5; 15 | int ans = 0; 16 | bool flag = true; 17 | for(int i=0;i<20;i++){ 18 | ans = i+1; 19 | if(x[i] == '1'){ 20 | if(i%2 == 0) a++; 21 | else b++; 22 | } 23 | if(i < 10){ 24 | if(i%2 == 0) rema--; 25 | else remb--; 26 | if((a > b+remb) || (b > a+rema)) 27 | break; 28 | } else { 29 | if((i&1) && (a != b)) break; 30 | } 31 | } 32 | if(a == b){ 33 | printf("TIE\n"); 34 | } else { 35 | if(a > b) printf("TEAM-A %d\n",ans); 36 | else printf("TEAM-B %d\n",ans); 37 | } 38 | 39 | } 40 | return 0; 41 | } -------------------------------------------------------------------------------- /codechef/December Challenge 17/VK18.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define pb push_back 4 | #define mp make_pair 5 | #define vll vector 6 | using namespace std; 7 | int main(){ 8 | vector arr(2000002); 9 | for(long i=0;i ans(1000001); 21 | ans[1] = 2; 22 | ll temp = 2; 23 | long start = 2; 24 | long end = 2; 25 | for(long i=2;i>t; 34 | while(t--){ 35 | long n; 36 | scanf("%d",&n); 37 | printf("%lld\n",ans[n]); 38 | } 39 | return 0; 40 | } -------------------------------------------------------------------------------- /codechef/February Challenge 17/CHEFAPAR.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | typedef long long ll; 4 | typedef vector vll; 5 | typedef vector vvll; 6 | typedef pair pll; 7 | #define s(a) int((a).size()) 8 | #define pb push_back 9 | #define mp make_pair 10 | #define all(c) (c).begin(),(c).end() 11 | #define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++) 12 | #define present(c,x) ((c).find(x) != (c).end()) 13 | #define F(i,n) for(typeof(n) i=0;i=0;i--) 15 | int main(){ 16 | int t; 17 | cin>>t; 18 | while(t--) { 19 | long n; 20 | cin>>n; 21 | vll arr(n,false); 22 | bool flag = false; 23 | ll ans = n, temp = n; 24 | F(i,n) { 25 | int a; 26 | cin>>a; 27 | if(a) { 28 | arr[i] = true; 29 | ans--; 30 | } else { 31 | flag = true; 32 | } 33 | if(!flag) { 34 | temp--; 35 | } 36 | } 37 | cout< 2 | using namespace std; 3 | long gcd ( long a, long b ) { 4 | return (!b)?a:gcd(b,a%b); 5 | } 6 | int main() { 7 | long t; 8 | cin>>t; 9 | while(t--) { 10 | long n,q; 11 | scanf("%ld %ld", &n, &q); 12 | vector arr(n); 13 | for(long i=0;i gcdf(n), gcdb(n); 16 | gcdf[0] = arr[0]; 17 | for(long i=1;i 2 | #define ll long long 3 | #define pb push_back 4 | #define mp make_pair 5 | #define vll vector 6 | #define all(S) S.begin(), S.end() 7 | #define S(a) scanf("%lld", &n) 8 | using namespace std; 9 | int main(){ 10 | long t; 11 | scanf("%ld", &t); 12 | while(t--) { 13 | long n; 14 | cin>>n; 15 | vector temp(n, 0); 16 | vector > arr(n, temp); 17 | for(long i=0;i>arr[i][j]; 20 | } 21 | } 22 | for(long i = 0; i < n; ++i){ 23 | sort(all(arr[i])); 24 | } 25 | bool flag = false; 26 | ll to_search = arr[n-1][n-1]+1; 27 | ll ans = 0; 28 | for(long i = n-1; i>=0 ;i--){ 29 | vector::iterator it = lower_bound(all(arr[i]), to_search); 30 | if(it == arr[i].begin()){ 31 | flag = true; 32 | break; 33 | } 34 | it--; 35 | ans += *it; 36 | to_search = *it; 37 | } 38 | if(flag){ 39 | cout<<"-1\n"; 40 | } else { 41 | cout< 2 | #define ll long long 3 | #define pb push_back 4 | #define mp make_pair 5 | #define vll vector 6 | #define all(S) S.begin(), S.end() 7 | #define S(a) scanf("%lld", &n) 8 | using namespace std; 9 | int main(){ 10 | long t; 11 | scanf("%ld", &t); 12 | while(t--) { 13 | vector arr; 14 | for(long i = 0; i < 4; ++i){ 15 | ll x; 16 | cin>>x; 17 | arr.pb(x); 18 | } 19 | sort(all(arr)); 20 | if( arr[0] == arr[1] && arr[2] == arr[3]) 21 | cout<<"YES\n"; 22 | else cout<<"NO\n"; 23 | } 24 | return 0; 25 | } -------------------------------------------------------------------------------- /codechef/January Challenge 17/CATSDOGS.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | long t; 5 | cin>>t; 6 | string yes = "yes"; 7 | string no = "no"; 8 | while(t--) { 9 | long long c,d,l; 10 | cin>>c>>d>>l; 11 | if(l%4!=0 || d*4 > l){ 12 | cout< 2*d) 17 | cout< 2 | using namespace std; 3 | int main() { 4 | long t; 5 | cin>>t; 6 | string yes = "yes"; 7 | string no = "no"; 8 | while(t--) { 9 | int n,m; 10 | cin>>n>>m; 11 | vector arr(n); 12 | for(int i=0;i>arr[i]; 14 | bool flag = true; 15 | for(int i=0;i 2 | using namespace std; 3 | int main() { 4 | long t; 5 | cin>>t; 6 | while(t--){ 7 | long n,d; 8 | cin>>n>>d; 9 | vector > > arr(n); 10 | for(long i=0;i>arr[i].second.first>>arr[i].second.second>>arr[i].first; 12 | } 13 | sort(arr.begin(),arr.end()); 14 | reverse(arr.begin(),arr.end()); 15 | long long ans = 0; 16 | vector a(d+1,0); 17 | for(long i=0;i temp; 22 | while(days != 0 && begin != d+1){ 23 | if(a[begin]!=0){ 24 | temp.push_back(begin); 25 | begin = a[begin]; 26 | } else { 27 | temp.push_back(begin); 28 | begin++; 29 | days--; 30 | } 31 | } 32 | for(long i=0;i 2 | using namespace std; 3 | int main(){ 4 | long long n,t; 5 | cin>>n; 6 | while(n--){ 7 | cin>>t; 8 | if(t%6==0) 9 | cout<<"Misha"< 2 | using namespace std; 3 | int main(){ 4 | long long n,t; 5 | cin>>n; 6 | while(n--){ 7 | cin>>t; 8 | t--; 9 | long long ans=0; 10 | long long p=2; 11 | while(t){ 12 | ans += (t%5)*p; 13 | p *= 10; 14 | t /= 5; 15 | } 16 | cout< 2 | using namespace std; 3 | int main(){ 4 | long long n,q,t; 5 | cin>>n>>q; 6 | long long maxv = INT_MIN,minv = INT_MAX; 7 | while(n--){ 8 | cin>>t; 9 | maxv = max(maxv,t); 10 | minv = min(minv,t); 11 | } 12 | while(q--){ 13 | cin>>t; 14 | if(t>=minv && t<=maxv) 15 | cout<<"Yes"< 2 | using namespace std; 3 | int main() { 4 | int t; 5 | cin>>t; 6 | while(t--) { 7 | int n; 8 | cin>>n; 9 | int count = 499; 10 | while(n--) cout< 2 | using namespace std; 3 | int main() { 4 | int t; 5 | cin>>t; 6 | while(t--) { 7 | long n; 8 | cin>>n; 9 | vector arr(n); 10 | for(long i=0;i>arr[i]; 11 | long count = 0; 12 | long long sum = 0; 13 | long long ans = 0; 14 | vector minarr; 15 | for(long i=0;i= 0) { 17 | count++; 18 | sum += arr[i]; 19 | } else minarr.push_back(arr[i]); 20 | } 21 | sort(minarr.begin(),minarr.end()); 22 | reverse(minarr.begin(),minarr.end()); 23 | for(long i=0;i= sum*count+minarr[i] ) { 25 | sum += minarr[i]; 26 | count++; 27 | } else { 28 | ans += minarr[i]; 29 | } 30 | } 31 | ans += sum*count; 32 | cout< 2 | using namespace std; 3 | int main() { 4 | int t; 5 | cin>>t; 6 | while(t--) { 7 | long long u,v; 8 | cin>>u>>v; 9 | long long ans = u+v; 10 | ans = ans*(ans+1)/2; 11 | ans += u+1; 12 | cout< 2 | #define ll long long 3 | using namespace std; 4 | 5 | int main (){ 6 | 7 | long t; 8 | cin>>t; 9 | while(t--) { 10 | string s; 11 | cin>>s; 12 | int count = 0; 13 | char prev = '1'; 14 | for(long i=0;i 2 | #define ll long long 3 | using namespace std; 4 | 5 | int main (){ 6 | 7 | long t; 8 | cin>>t; 9 | while(t--) { 10 | long n; 11 | cin>>n; 12 | long b; 13 | cin>>b; 14 | long starno = (n+1)/2; 15 | if(n == 2) { 16 | if(b == 1) 17 | cout<<"YES\n1 2\n"; 18 | else 19 | cout<<"NO\n"; 20 | continue; 21 | } 22 | long chain = 2; 23 | chain += n-starno; 24 | if(chain/2 -1 < b) 25 | printf("NO\n"); 26 | else { 27 | printf("YES\n"); 28 | while(chain/2 -1 != b) { 29 | starno++; 30 | chain--; 31 | } 32 | starno -= 2; 33 | for(long i=1;i 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | long n; 8 | cin>>n; 9 | vector a(n),b(n); 10 | long long pa = 0; 11 | for(long i=0;i>a[i]; 13 | } 14 | for(long i=0;i>b[i]; 16 | } 17 | long ans = 0; 18 | for(long i=0;i= b[i]) 20 | ans++; 21 | pa = a[i]; 22 | } 23 | cout< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | long long n,k; 8 | cin>>n>>k; 9 | vector a(n),b(n); 10 | for(long long i=0;i>a[i]; 12 | long long edge = 0; 13 | for(long long i=0;i>b[i]; 15 | if(abs(b[i])>abs(b[edge])) 16 | edge = i; 17 | } 18 | if(b[edge]>0) 19 | a[edge] += k; 20 | else 21 | a[edge] -= k; 22 | long long sum = 0; 23 | for(long long i=0;i 2 | using namespace std; 3 | int main() 4 | { 5 | int val; 6 | cout<<1<>val; 13 | cout<<2< 2 | using namespace std; 3 | long long mod = 1000000007; 4 | int main() 5 | { 6 | int t; 7 | cin>>t; 8 | while(t--){ 9 | int n,m,s; 10 | cin>>n>>m>>s; 11 | vector a(m); 12 | for(int i=0;i>a[i]; 14 | vector ans(n,0); 15 | ans[s-1] = 1; 16 | for(int i=0;i temp(n,0); 18 | for(int j=0;j= 0){ 20 | temp[j] += ans[j-a[i]]; 21 | temp[j] %= mod; 22 | } 23 | if(j+a[i] 2 | using namespace std; 3 | int main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--){ 8 | int ans=0; 9 | int n; 10 | string temp; 11 | cin>>n>>temp; 12 | int divisor; 13 | if(temp == "INDIAN") 14 | divisor = 200; 15 | else 16 | divisor = 400; 17 | while(n--){ 18 | int x; 19 | cin>>temp; 20 | if(temp == "CONTEST_WON"){ 21 | ans += 300; 22 | cin>>x; 23 | if(x<=20) 24 | ans += 20-x; 25 | } else if(temp == "TOP_CONTRIBUTOR") 26 | ans += 300; 27 | else if(temp == "CONTEST_HOSTED") 28 | ans += 50; 29 | else{ 30 | cin>>x; 31 | ans += x; 32 | } 33 | } 34 | cout< 2 | #define ll long long 3 | #define pb push_back 4 | #define mp make_pair 5 | #define vll vector 6 | using namespace std; 7 | int main(){ 8 | int t; 9 | cin>>t; 10 | while(t--) { 11 | long p, n; 12 | cin>>n>>p; 13 | if(p == 1 || p == 2){ 14 | cout<<"impossible\n"; 15 | } else { 16 | string s = ""; 17 | s += 'a'; 18 | for(int i=0;i 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--) { 7 | string n; 8 | cin>>n; 9 | long ans = 0; 10 | for(long i=0;i'){ 14 | n[i] = '<'; 15 | if(i!=0 && n[i-1] == '>') 16 | ans++; 17 | } 18 | } 19 | cout< 2 | #define ll long long 3 | #define pb push_back 4 | #define mp make_pair 5 | #define vll vector 6 | using namespace std; 7 | int main(){ 8 | long t; 9 | cin>>t; 10 | while(t--) { 11 | long n; 12 | cin>>n; 13 | long k; 14 | cin>>k; 15 | vector arr(n); 16 | for (long i = 0; i < arr.size(); ++i) 17 | cin>>arr[i]; 18 | arr.push_back(-1); 19 | sort(arr.begin(),arr.end()); 20 | long ans = -1; 21 | for(long i=1;i 2 | #define ll long long 3 | using namespace std; 4 | int main(){ 5 | long t; 6 | cin>>t; 7 | while(t--) { 8 | long n; 9 | cin>>n; 10 | ll p; 11 | cin>>p; 12 | long cakewalk = 0, hard = 0; 13 | for (long i = 0; i < n; ++i){ 14 | ll x; 15 | cin>>x; 16 | if(x >= p/2) cakewalk++; 17 | else if (x <= p/10) hard++; 18 | } 19 | if(cakewalk == 1 && hard == 2) cout<<"yes\n"; 20 | else cout<<"no\n"; 21 | } 22 | return 0; 23 | } -------------------------------------------------------------------------------- /codechef/OCT17/temp_output0: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lakshmanaram/Competitive-programming/31f4276ff529b3066e04497555bdb379fb2674c2/codechef/OCT17/temp_output0 -------------------------------------------------------------------------------- /codechef/OCT17/temp_output1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lakshmanaram/Competitive-programming/31f4276ff529b3066e04497555bdb379fb2674c2/codechef/OCT17/temp_output1 -------------------------------------------------------------------------------- /codechef/OCT17/temp_output2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lakshmanaram/Competitive-programming/31f4276ff529b3066e04497555bdb379fb2674c2/codechef/OCT17/temp_output2 -------------------------------------------------------------------------------- /codechef/ORACLCS.py: -------------------------------------------------------------------------------- 1 | #ORACLCS codechef 2 | def finda(s): 3 | a = 0 4 | for i in s: 5 | if i == 'a': 6 | a += 1 7 | return a 8 | def findb(s): 9 | b = 0 10 | for i in s: 11 | if i == 'b': 12 | b += 1 13 | return b 14 | t = input() 15 | for T in range(t): 16 | n = input() 17 | rem = "" 18 | for N in range(n): 19 | s = raw_input() 20 | if N==0: 21 | a = finda(s) 22 | b = findb(s) 23 | else: 24 | if a > finda(s): 25 | a = finda(s) 26 | if b > findb(s): 27 | b = findb(s) 28 | if a > b: 29 | a,b = b,a 30 | print a 31 | 32 | -------------------------------------------------------------------------------- /codechef/October Challenge 16/CHDOGS.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) { 8 | double a,b; 9 | cin>>a>>b; 10 | a = a*2/(b*3); 11 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) { 8 | long n,m,c; 9 | cin>>n>>m>>c; 10 | long ans = 0; 11 | for(long i=1; i<=n; i++){ 12 | if(c%i ==0 && c/i <= m) 13 | ans++; 14 | } 15 | cout< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | long long ans = 0; 8 | string a, b, c; 9 | cin>>a>>b>>c; 10 | long n; 11 | cin>>n; 12 | bool flag = false; 13 | for(long i=c.size()-1;i>=0;i--){ 14 | if(c[i]=='1' && flag) 15 | ans++; 16 | else if(c[i] == '0') 17 | flag = true; 18 | } 19 | for(long i=b.size()-1;i>=0;i--){ 20 | if(b[i]=='1' && flag) 21 | ans++; 22 | else if(b[i] == '0') 23 | flag = true; 24 | } 25 | if(flag){ 26 | long long temp = 0; 27 | for(long i=b.size()-1;i>=0;i--){ 28 | if(b[i]=='1') 29 | temp++; 30 | } 31 | ans += temp*(n-1); 32 | } 33 | for(long i=a.size()-1;i>=0;i--){ 34 | if(a[i]=='1' && flag) 35 | ans++; 36 | else if(a[i] == '0') 37 | flag = true; 38 | } 39 | cout< 2 | using namespace std; 3 | long long distance_pts ( pair a, pair b) { 4 | return (a.first-b.first)*(a.first-b.first) + (a.second-b.second)*(a.second-b.second); 5 | } 6 | int main() { 7 | long long n; 8 | cin>>n; 9 | vector > points(n); 10 | long long d = 0; 11 | for(long long i=0;i>points[i].first>>points[i].second; 13 | for(long long j=0;j d) 16 | d = x; 17 | } 18 | cout<maxv: 24 | maxv = len(m[i].keys()) 25 | print maxv 26 | -------------------------------------------------------------------------------- /codechef/SOPC2017/OPC1702.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define pb push_back 4 | #define mp make_pair 5 | #define vll vector 6 | using namespace std; 7 | int main(){ 8 | long t; 9 | cin>>t; 10 | while(t--) { 11 | long b, s; 12 | cin>>s>>b; 13 | double p; 14 | cin>>p; 15 | double strength = b; 16 | strength /= 2; 17 | long days = 0; 18 | cout< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | string a,b; 8 | cin>>a>>b; 9 | int flag = 0; 10 | for(int i=0;i 2 | using namespace std; 3 | int main(){ 4 | 5 | return 0; 6 | } -------------------------------------------------------------------------------- /codechef/September Challenge 16/LEXOPAL.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--) { 7 | string s; 8 | cin>>s; 9 | int j = s.size()-1; 10 | bool pal = true; 11 | for(int i=0;i <= j;i++,j--){ 12 | if(s[i] != s[j]){ 13 | if(s[i] == '.') { 14 | s[i] = s[j]; 15 | } else if(s[j] == '.'){ 16 | s[j] = s[i]; 17 | } else { 18 | pal = false; 19 | break; 20 | } 21 | } else if(s[i] == '.'){ 22 | s[i] = s[j] = 'a'; 23 | } 24 | } 25 | if(pal) 26 | cout< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--) { 7 | string d; 8 | cin>>d; 9 | int no = 0, nz = 0; 10 | for(int i=0;i 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--) { 7 | int n; 8 | cin>>n; 9 | long maxval = -1; 10 | int maxind; 11 | for(int i=0;i>x; 14 | vector types(6,0); 15 | for(int j=0;j>y; 18 | types[y-1]++; 19 | } 20 | sort(types.begin(),types.end()); 21 | while(types.size()>=4){ 22 | int y = types[0]; 23 | for(int j=0;j maxval){ 34 | maxval = x; 35 | maxind = i+1; 36 | } else if( x == maxval ){ 37 | maxind = -1; 38 | } 39 | } 40 | if(maxind == -1) 41 | cout<<"tie"< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | string nos; 8 | cin>>nos; 9 | vector arr(10,0); 10 | for(long i=0;i= 1){ 19 | arr[x]--; 20 | if(arr[y] >= 1){ 21 | ans += a; 22 | } 23 | arr[x]++; 24 | } 25 | } 26 | cout< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--) { 7 | long n; 8 | cin>>n; 9 | vector arr(n); 10 | long ans = 0; 11 | long ansval; 12 | for(long i=0;i>arr[i]; 14 | if(i == 0) ansval = arr[i]; 15 | if(arr[i] < ansval){ 16 | ansval = arr[i]; 17 | ans = i; 18 | } 19 | } 20 | cout< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | long n; 8 | cin>>n; 9 | vector arr(n); 10 | for(long i=0;i 2 | using namespace std; 3 | long long find_ans(long long n, long long b, long long m) { 4 | if(n == 1) 5 | return m; 6 | long long problems = (n+1)/2; 7 | return m*problems + b + find_ans(n-problems,b,2*m); 8 | } 9 | int main(){ 10 | 11 | int t; 12 | cin>>t; 13 | while(t--){ 14 | long long n,b,m; 15 | cin>>n>>b>>m; 16 | long long ans = find_ans(n,b,m); 17 | cout< 2 | using namespace std; 3 | int main(){ 4 | long t; 5 | cin>>t; 6 | while(t--){ 7 | long long n,c; 8 | cin>>n>>c; 9 | c *= 2; 10 | if(n==1){ 11 | cout<<"Yes"<n){ 22 | cout<<"Yes"<= n){ 24 | cout<<"Yes"<= n){ 26 | cout<<"Yes"< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | long n,k; 8 | long long m; 9 | int e; 10 | cin>>n>>k>>e>>m; 11 | vector marks; 12 | for(long i=1;i>x; 17 | ans += x; 18 | } 19 | marks.push_back(ans); 20 | } 21 | long long ans = 0; 22 | for(long j =1; j>x; 25 | ans += x; 26 | } 27 | sort(marks.begin(),marks.end()); 28 | reverse(marks.begin(),marks.end()); 29 | ans = marks[k-1] - ans + 1; 30 | if(ans < 0) ans = 0; 31 | if(ans > m) 32 | cout<<"Impossible"< 2 | using namespace std; 3 | vector arr; 4 | long long mod = 1000000007; 5 | int main() { 6 | int t; 7 | cin>>t; 8 | while(t--) { 9 | long n; 10 | cin>>n; 11 | arr.resize(n); 12 | for(long i=0;i>arr[i]; 13 | long long ans = arr[0]; 14 | long long sum = arr[0]; 15 | long long prod = 1; 16 | for(long long i=1;i 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | long n,m; 8 | cin>>n>>m; 9 | if(n == 1) cout<<0< 2 | using namespace std; 3 | int main() { 4 | int t; 5 | cin>>t; 6 | while(t--) { 7 | int n; 8 | cin>>n; 9 | int z=0, o=0; 10 | for(long i=0;i>a; 14 | if(a == 0) 15 | z++; 16 | else 17 | o++; 18 | } 19 | if(o == 0 || o == n) 20 | cout<<0< z) 24 | x--; 25 | cout< 2 | using namespace std; 3 | int main() { 4 | int t; 5 | cin>>t; 6 | while(t--) { 7 | long n; 8 | scanf("%ld",&n); 9 | vector a(n); 10 | for(long i=0; i arr; 17 | long i; 18 | for(i=0;i max1) 34 | max1 = a[i]; 35 | } 36 | if(i == n) { 37 | if(max1 - min2 == n-2) 38 | printf("%ld\n",min1); 39 | else 40 | printf("%ld\n",max1); 41 | } 42 | } 43 | return 0; 44 | } -------------------------------------------------------------------------------- /codechef/march long challenge 17/XENTASK.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | int t; 5 | cin>>t; 6 | while(t--) { 7 | long n; 8 | cin>>n; 9 | vector a(n),b(n); 10 | for(long i=0; i 2 | using namespace std; 3 | int main(){ 4 | vector f; 5 | f.push_back(0); 6 | f.push_back(1); 7 | long i = 2; 8 | long m,n; 9 | cin>>m>>n; 10 | int ans = 0; 11 | while(i<=n){ 12 | if(i%2==0) 13 | f.push_back(f[i/2]); 14 | else 15 | f.push_back(f[i/2]+1); 16 | if(i>=m) 17 | ans = max(ans,f[i]); 18 | i++; 19 | } 20 | cout< 2 | using namespace std; 3 | vector num; 4 | int main(){ 5 | int n,m; 6 | cin>>n>>m; 7 | vector num; 8 | int ans[n+1][m+1],i,j,k; 9 | num.push_back(0); 10 | for(i=0;i>x; 13 | num.push_back(x); 14 | } 15 | for(i=1;i<=n;i++){ 16 | ans[i][0] = 1; 17 | } 18 | for(i=1;i<=num[1]&&i<=m;i++){ 19 | ans[1][i] = 1; 20 | } 21 | for(;i<=m;i++){ 22 | ans[1][i] = 0; 23 | } 24 | for(i=2;i<=n;i++){ 25 | for(j=1;j<=m;j++){ 26 | int v = 0; 27 | for(int k = j;j-k<=num[i]&&k>=0;k--){ 28 | v += ans[i-1][k]; 29 | } 30 | ans[i][j] = v; 31 | } 32 | } 33 | cout< 2 | using namespace std; 3 | int main() { 4 | long n; 5 | cin>>n; 6 | map h; 7 | set sh; 8 | for(long i=0;i>x; 11 | h[x]++; 12 | sh.insert(x); 13 | } 14 | long t = 0; 15 | long ppl_remaining = 0; 16 | long total_ppl = 0; 17 | for(set::iterator it = sh.begin();it != sh.end(); it++) { 18 | // cout<<*it<<" "; 19 | if(it != sh.begin() && *it > total_ppl && ppl_remaining >= 0) 20 | break; 21 | total_ppl += h[*it]; 22 | t = max(*it,total_ppl); 23 | if(sh.begin() == it) 24 | ppl_remaining = - *it + h[*it]; 25 | else 26 | ppl_remaining = total_ppl - *it; 27 | // cout< 2 | using namespace std; 3 | int evenSum(int n) { 4 | long long c = 0, a = 2,b,d = 0; 5 | while(true){ 6 | for(b = 1;b 2 | using namespace std; 3 | vector num; 4 | int main(){ 5 | while(true){ 6 | int n,m; 7 | cin>>n>>m; 8 | vector num; 9 | long long ans[n+1][m+1],i,j,k; 10 | num.push_back(0); 11 | for(i=0;i>x; 14 | num.push_back(x); 15 | } 16 | for(i=1;i<=n;i++){ 17 | ans[i][0] = 1; 18 | } 19 | for(i=1;i<=num[1]&&i<=m;i++){ 20 | ans[1][i] = 1; 21 | } 22 | for(;i<=m;i++){ 23 | ans[1][i] = 0; 24 | } 25 | for(i=2;i<=n;i++){ 26 | for(j=1;j<=m;j++){ 27 | int v = 0; 28 | for(int k = j;j-k<=num[i]&&k>=0;k--){ 29 | v += ans[i-1][k]; 30 | } 31 | ans[i][j] = v; 32 | } 33 | } 34 | cout< 2 | #define ll long long 3 | #define pb push_back 4 | #define mp make_pair 5 | #define vll vector 6 | #define all(S) S.begin(), S.end() 7 | #define S(a) scanf("%lld", &a) 8 | using namespace std; 9 | int main(){ 10 | long n, m; 11 | cin >> n >> m; 12 | vll arr(m), cost(n); 13 | for (long i = 0; i < n; i++) cin >> cost[i]; 14 | for (long i = 0; i < m; i++) cin >> arr[i]; 15 | long i = 0, j = 0; 16 | long ans = 0; 17 | while(i < n && j < m) { 18 | if(cost[i] <= arr[j]) { 19 | j++; 20 | ans++; 21 | } 22 | i++; 23 | } 24 | cout << ans << endl; 25 | return 0; 26 | } -------------------------------------------------------------------------------- /codeforces/1009B-Minimum_terenary_string.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define pb push_back 4 | #define mp make_pair 5 | #define vll vector 6 | #define all(S) S.begin(), S.end() 7 | #define S(a) scanf("%lld", &a) 8 | using namespace std; 9 | int main(){ 10 | string s; 11 | cin >> s; 12 | string ans = ""; 13 | string ones = ""; 14 | for (long i = 0; i < s.size(); i++) { 15 | if (s[i] == '1') 16 | ones += s[i]; 17 | else ans += s[i]; 18 | } 19 | long i = 0; 20 | while(i < ans.size()) { 21 | if(ans[i] == '2') 22 | break; 23 | i++; 24 | } 25 | cout << ans.substr(0, i) + ones + ans.substr(i) << endl; 26 | return 0; 27 | } -------------------------------------------------------------------------------- /codeforces/1009C-Annoying_present.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define pb push_back 4 | #define mp make_pair 5 | #define vll vector 6 | #define all(S) S.begin(), S.end() 7 | #define S(a) scanf("%lld", &a) 8 | using namespace std; 9 | int main(){ 10 | long double ans = 0; 11 | long n, m; 12 | cin >> n >> m; 13 | long double c = n/2; 14 | long double d = n - c - 1; 15 | c *= c+1; 16 | d *= d+1; 17 | for (long i = 0; i < m; i++) { 18 | long double a, b; 19 | cin >> a >> b; 20 | ans += a; 21 | if (b > 0) { 22 | long double p = b*(n-1); 23 | p /= 2.0; 24 | ans += p; 25 | } else { 26 | long double p = b*(c+d); 27 | p /= 2.0; 28 | p /= n; 29 | ans += p; 30 | } 31 | } 32 | for(long i = 1; i <= 10000; i++) { 33 | long double a = i/10001.0, b = (10001-i)/10001.0; 34 | cout << fixed << setprecision(7) << 100000*(a+b)*1000 << endl; 35 | } 36 | cout << fixed << setprecision(15) << ans << endl; 37 | return 0; 38 | } -------------------------------------------------------------------------------- /codeforces/1009E-Intercity_Travelling.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define pb push_back 4 | #define mp make_pair 5 | #define vll vector 6 | #define all(S) S.begin(), S.end() 7 | #define S(a) scanf("%lld", &a) 8 | using namespace std; 9 | ll mod = 998244353; 10 | int main(){ 11 | long n; 12 | scanf("%ld", &n); 13 | vll arr(n); 14 | for (long i =0; i< n; i++) 15 | scanf("%lld", &arr[i]); 16 | vll sarr; 17 | ll sum = 0; 18 | for (long i = 0; i < arr.size(); i++) { 19 | sum += arr[i]; 20 | sum %= mod; 21 | sarr.pb(sum); 22 | } 23 | vll mul; 24 | mul.pb(1); 25 | sum = 1; 26 | ll pow = 1; 27 | for (long i = 1; i < n; i++) { 28 | mul.pb((sum + pow)%mod); 29 | sum += (sum + pow)%mod; 30 | sum %= mod; 31 | pow *= 2; 32 | pow %= mod; 33 | } 34 | // for (long i = 0; i < n; i++) 35 | // cout << mul[i] << " "; 36 | // cout << endl; 37 | ll ans = 0; 38 | reverse(all(sarr)); 39 | for (long i = 0; i < n; i++) { 40 | ans += (mul[i] * sarr[i])%mod; 41 | ans %= mod; 42 | } 43 | printf("%lld\n", ans); 44 | return 0; 45 | } -------------------------------------------------------------------------------- /codeforces/101510D.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define pb push_back 4 | #define mp make_pair 5 | #define vll vector 6 | using namespace std; 7 | long h,n; 8 | map, ll> ma; 9 | long long find_ans(long x, long m, long remaining) { 10 | long avail = h-x; 11 | long avail_col = m-x; 12 | if((avail*(avail+1))/2 >= remaining){ 13 | if(ma.find(mp(avail_col,remaining))!=ma.end()) 14 | return ma[mp(avail_col,remaining)]; 15 | } 16 | if(remaining == 0) return 1; 17 | if(x >= h) return 0; 18 | long long ans = 0; 19 | // long long diff = ((h-x)*(h-x-1))/2; 20 | for(long i=remaining-1;i>=0;i--){ 21 | long used = remaining-i; 22 | // long long check = (h-x)*used; 23 | // if(check-diff m) break; 25 | if(x != 0) 26 | ans += (m-(x+used)+1)*find_ans(x+1,x+used,i); 27 | else 28 | ans += find_ans(x+1,x+used,i); 29 | } 30 | if((avail*(avail+1))/2 >= remaining){ 31 | ma[mp(avail_col,remaining)] = ans; 32 | } 33 | return ans; 34 | } 35 | int main(){ 36 | cin>>h>>n; 37 | cout< 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | string s; 7 | cin>>s; 8 | int i=0,ans=0; 9 | for(;i 2 | using namespace std; 3 | int HCF(int a,int b) 4 | { 5 | if(a==0) 6 | return b; 7 | if(b==0) 8 | return a; 9 | if(a>b) 10 | { 11 | if(a%b==0) 12 | return b; 13 | else 14 | return HCF(a%b,b); 15 | } 16 | else 17 | { 18 | if(b%a==0) 19 | return a; 20 | else 21 | return HCF(a,b%a); 22 | } 23 | } 24 | int main() 25 | { 26 | int a,b,n,ga,gb; 27 | cin>>a>>b>>n; 28 | do 29 | { 30 | ga=HCF(a,n); 31 | if(ga>n) 32 | { 33 | cout<<"1"; 34 | break; 35 | } 36 | n=n-ga; 37 | gb=HCF(b,n); 38 | if(gb>n) 39 | { 40 | cout<<"0"; 41 | break; 42 | } 43 | n=n-gb; 44 | }while(true); 45 | return 0; 46 | } -------------------------------------------------------------------------------- /codeforces/122A-Lucky_division.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int a[] = {4,7,44,47,74,77,447,477,444,777,744,747,774,474}; 6 | int n; 7 | cin>>n; 8 | int i=0; 9 | for(;i<14;i++) 10 | { 11 | if(n%a[i]==0) 12 | { 13 | cout<<"YES"; 14 | return 0; 15 | } 16 | } 17 | cout<<"NO"; 18 | return 0; 19 | } -------------------------------------------------------------------------------- /codeforces/131A-caps_lock.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int init=0, 6 | String s; 7 | cin>>s; 8 | for() 9 | 10 | return 0; 11 | } -------------------------------------------------------------------------------- /codeforces/136A-presents.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | return 0; 6 | } -------------------------------------------------------------------------------- /codeforces/148A-insomnia_cure.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int LCM(int a,int b) 4 | { 5 | if(a>b) 6 | { 7 | if(a%b==0) 8 | return b; 9 | else 10 | return LCM(a%b,b); 11 | } 12 | else 13 | { 14 | if(b%a==0) 15 | return a; 16 | else 17 | return LCM(a,b%a); 18 | } 19 | } 20 | int HCF(int a,int b) 21 | { 22 | return (a*b)/LCM(a,b); 23 | } 24 | int main() 25 | { 26 | int a,b,c,d,n; 27 | cin>>a>>b>>c>>d>>n; 28 | int ans=0; 29 | if(a==1||b==1||c==1||d==1) 30 | { 31 | cout< 2 | using namespace std; 3 | int LCM(int a,int b) 4 | { 5 | if(a>b) 6 | { 7 | if(a%b==0) 8 | return b; 9 | else 10 | return LCM(a%b,b); 11 | } 12 | else 13 | { 14 | if(b%a==0) 15 | return a; 16 | else 17 | return LCM(a,b%a); 18 | } 19 | } 20 | int HCF(int a,int b) 21 | { 22 | return (a*b)/LCM(a,b); 23 | } 24 | int main() 25 | { 26 | int a,b,c,d,n; 27 | cin>>a>>b>>c>>d>>n; 28 | int ans=0; 29 | if(a==1||b==1||c==1||d==1) 30 | { 31 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | long n; 6 | cin>>n; 7 | long f=0,th=0,tw=0,o=0; 8 | int temp; 9 | while(n--) 10 | { 11 | cin>>temp; 12 | if(temp==4) 13 | f++; 14 | else if(temp==3) th++; 15 | else if(temp==2) tw++; 16 | else o++; 17 | } 18 | long ans =f; 19 | if(o>=th) 20 | { 21 | ans+=th; 22 | o-=th; 23 | } 24 | else 25 | { 26 | o=0; 27 | ans+=th; 28 | } 29 | if(tw%2==0) 30 | ans+=tw/2; 31 | else 32 | { 33 | if(o>=2) 34 | { 35 | ans+=tw/2 + 1; 36 | o-=2; 37 | } 38 | else 39 | { 40 | ans+=tw/2 + 1; 41 | o=0; 42 | } 43 | 44 | } 45 | if(o%4==0) 46 | ans+=o/4; 47 | else 48 | ans+=(o/4)+1; 49 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int i; 6 | stack mys; 7 | string a; 8 | cin>>a; 9 | int flag=0; 10 | for(i=a.length()-1;i>=0;i--) 11 | { 12 | mys.push(a[i]); 13 | if(flag==0) 14 | { 15 | if(mys.top()=='B') 16 | flag=1; 17 | } 18 | else if(flag==1) 19 | { 20 | if (mys.top()=='U') { 21 | flag=2; 22 | } 23 | else 24 | { 25 | if(mys.top()=='B') 26 | flag=1; 27 | else 28 | flag=0; 29 | } 30 | } 31 | else 32 | { 33 | if(mys.top()=='W'){ 34 | mys.pop(); 35 | mys.pop(); 36 | mys.pop(); 37 | if(!mys.empty()) 38 | if(mys.top()!=' ') 39 | mys.push(' '); 40 | flag=0; 41 | } 42 | else if(mys.top()=='B') 43 | flag=1; 44 | else 45 | flag=0; 46 | } 47 | } 48 | while(mys.top()==' ') 49 | mys.pop(); 50 | while(!mys.empty()) 51 | { 52 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int n; 6 | cin>>n; 7 | int a,b,c,ans=0; 8 | while(n--) 9 | { 10 | cin>>a>>b>>c; 11 | if((a==b&&a==1)||(a==c&&a==1)||(c==b&&c==1)) 12 | ans++; 13 | } 14 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | 6 | return 0; 7 | } -------------------------------------------------------------------------------- /codeforces/271A-beautiful_year.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | bool dist(int a) 4 | { 5 | bool ch[10]; 6 | fill(ch,ch+10,false); 7 | while(a!=0) 8 | { 9 | if(ch[a%10]==true) 10 | { 11 | return false; 12 | } 13 | ch[a%10]=true; 14 | a/=10; 15 | } 16 | return true; 17 | } 18 | int main() 19 | { 20 | int y,flag=0; 21 | cin>>y; 22 | do 23 | { 24 | y++; 25 | }while(!dist(y)); 26 | cout< 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | int n=0,ans=0; 7 | cin>>n; 8 | while(n--) 9 | { 10 | char ch[3]; 11 | cin>>ch; 12 | if(ch[1]=='+'||ch[0]=='+') 13 | ans++; 14 | else 15 | ans--; 16 | } 17 | cout< 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | int n,ans=1; 7 | cin>>n; 8 | string a,temp; 9 | cin>>a; 10 | temp=a; 11 | n--; 12 | while(n--) 13 | { 14 | cin>>a; 15 | if(temp!=a) 16 | { 17 | temp=a; 18 | ans++; 19 | } 20 | } 21 | cout< 2 | using namespace std; 3 | int mod10(long long a) { 4 | if(a == 0) 5 | return 1; 6 | if(a == 1) 7 | return 8; 8 | int temp = mod10(a/2); 9 | if(a%2 == 0) 10 | return (temp*temp) %10; 11 | else 12 | return (temp*temp*8) %10; 13 | } 14 | int main() { 15 | long long n; 16 | cin>>n; 17 | cout< 2 | using namespace std; 3 | int main() { 4 | long n; 5 | long x; 6 | cin>>n>>x; 7 | vector arr(n); 8 | map m; 9 | for(long i=0;i>arr[i]; 11 | m[arr[i]]++; 12 | } 13 | long long ans = 0; 14 | for(long i=0;i 2 | using namespace std; 3 | long long gcd(long long a, long long b) { 4 | return (b==0)?a:gcd(b,a%b); 5 | } 6 | int main() { 7 | long n; 8 | cin>>n; 9 | vector arr(n); 10 | for(long i=0;i>arr[i]; 12 | arr[i]--; 13 | } 14 | vector b(n,false); 15 | bool exists = true; 16 | long long ans = 1; 17 | for(long i=0;i 2 | using namespace std; 3 | int main(){ 4 | string s; 5 | cin>>s; 6 | set stset; 7 | for(int i=0;i 2 | using namespace std; 3 | int main(){ 4 | int n,m; 5 | cin>>n>>m; 6 | string s; 7 | string puz; 8 | bool ans = true; 9 | for (int i=0;i>s; 11 | if(s.find('X')==string::npos) 12 | continue; 13 | string x = ""; 14 | bool started = false; 15 | bool ended = false; 16 | for(int j=0;j 2 | using namespace std; 3 | vector c; 4 | void init(){ 5 | c.push_back('A'); 6 | c.push_back('H'); 7 | c.push_back('I'); 8 | c.push_back('M'); 9 | c.push_back('O'); 10 | c.push_back('T'); 11 | c.push_back('U'); 12 | c.push_back('V'); 13 | c.push_back('W'); 14 | c.push_back('X'); 15 | c.push_back('Y'); 16 | } 17 | bool notfunc(char a ){ 18 | int i; 19 | for(i=0;i>x; 30 | int i; 31 | string y = x; 32 | reverse(x.begin(),x.end()); 33 | if(x == y){ 34 | for(i=0;i 2 | using namespace std; 3 | int main(){ 4 | long long n,k; 5 | cin>>n>>k; 6 | long long ans = n/k; 7 | if(ans & 1) 8 | cout<<"YES"< 2 | using namespace std; 3 | int main() 4 | { 5 | 6 | return 0; 7 | } -------------------------------------------------------------------------------- /codeforces/460A-vasya&socks.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int n,m,ans=0,rem; 6 | cin>>n>>m; 7 | while(n!=0) 8 | { 9 | ans += ((int)(n/m) * m); 10 | n = (n%m)+n/m; 11 | if(n 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | int n; 7 | int ans=0; 8 | int p,q; 9 | cin>>n; 10 | while(n--) 11 | { 12 | cin>>p>>q; 13 | if(q-p>=2) 14 | ans++; 15 | } 16 | cout< 2 | using namespace std; 3 | bool arr[1000001]; 4 | void markMultiples(int a, int n) 5 | { 6 | int i = 2, num; 7 | while ( (num = i*a) <= n ) 8 | { 9 | arr[num] = true; 10 | ++i; 11 | } 12 | } 13 | void SieveOfEratosthenes(int n) 14 | { 15 | if (n >= 2) 16 | { 17 | fill(arr,arr+1000001,false); 18 | for (int i=2; i>n; 38 | while(true) 39 | { 40 | if(!isprime(i)&&!isprime(n-i)) 41 | { 42 | cout< 2 | using namespace std; 3 | int main(){ 4 | long n; 5 | cin>>n; 6 | long long ans = 0; 7 | string arr; 8 | cin>>arr; 9 | for(long i=0;i>x; 12 | ans += min(abs(x-arr[i]),10 - abs(x-arr[i])); 13 | } 14 | cout< 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | vector lv; 7 | long long temp; 8 | long n,i; 9 | cin>>n; 10 | for(i=0;i>temp; 13 | lv.push_back(temp); 14 | } 15 | long long small = *(lv.begin()); 16 | long long big = *(lv.end()-1); 17 | vector::iterator it; 18 | it = lv.begin(); 19 | cout<<(*(it+1)-*it)<<" "<temp2) 33 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int hash[1000002]; 6 | fill(hash,hash+1000001,0); 7 | int t; 8 | long val=0; 9 | int maxav=0,tempav=0; 10 | cin>>t; 11 | char ch; 12 | while(t--) 13 | { 14 | cin>>ch; 15 | cin>>val; 16 | if(ch=='+') 17 | { 18 | tempav++; 19 | hash[val]=1; 20 | } 21 | else 22 | { 23 | if(hash[val]==1) 24 | { 25 | hash[val]=0; 26 | if(tempav>maxav) 27 | maxav = tempav; 28 | tempav--; 29 | } 30 | else 31 | { 32 | if(maxav!=0) 33 | maxav++; 34 | else 35 | maxav+=tempav+1; 36 | } 37 | } 38 | } 39 | if(tempav>maxav) 40 | maxav = tempav; 41 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int m,n; 6 | map cit; 7 | cin>>m>>n; 8 | int i,j; 9 | for(i=0;i>val; 14 | for(j=1;j>temp; 17 | if(temp>val) 18 | { 19 | val=temp; 20 | pos = j; 21 | } 22 | } 23 | cit[pos]++; 24 | } 25 | int val=0,pos=101; 26 | map::iterator it = cit.begin(); 27 | while(it!=cit.end()) 28 | { 29 | if(it->second>val) 30 | { 31 | val = it->second; 32 | pos = it->first; 33 | } 34 | else if(it->second==val) 35 | { 36 | if(pos>it->first) 37 | { 38 | pos= it->first; 39 | } 40 | } 41 | it++; 42 | } 43 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | long long n,m; 6 | cin>>n>>m; 7 | if(n!=1) 8 | { 9 | if(m>n/2) 10 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | long m,n; 6 | cin>>m>>n; 7 | string a; 8 | cin>>a; 9 | long f=0,i,ans=0; 10 | for(i=0;i>pos>>val; 30 | if(val=='.') 31 | { 32 | if(a[pos-1]!='.') 33 | { 34 | if(((pos-2)>=0) && (a[pos-2]=='.')) 35 | ans++; 36 | if((pos=0) && (a[pos-2]=='.')) 45 | ans--; 46 | if((pos 2 | using namespace std; 3 | int main() 4 | { 5 | 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /codeforces/570d-tree_requests.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lakshmanaram/Competitive-programming/31f4276ff529b3066e04497555bdb379fb2674c2/codeforces/570d-tree_requests.py -------------------------------------------------------------------------------- /codeforces/58A-chat_room.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | string s,ts="hello"; 7 | cin>>s; 8 | int i=0,j=0; 9 | for(;i 3 | using namespace std; 4 | int main(){ 5 | int m,n,x,y; 6 | cin>>m>>n>>x>>y; 7 | string s; 8 | cin>>s; 9 | int i; 10 | bool check[m][n]; 11 | for(i=0;ians) 24 | cout<=n) 33 | y--; 34 | break; 35 | case 'L': 36 | y--; 37 | if (y<0) 38 | y++; 39 | break; 40 | case 'U': 41 | x--; 42 | if(x<0) 43 | x++; 44 | break; 45 | case 'D': 46 | x++; 47 | if(x>=m) 48 | x--; 49 | } 50 | if(check[x][y]==false){ 51 | check[x][y] = true; 52 | cout<<1<<" "; 53 | ans++; 54 | } 55 | else{ 56 | cout<<0<<" "; 57 | } 58 | } 59 | return 0; 60 | } 61 | -------------------------------------------------------------------------------- /codeforces/606C.cpp: -------------------------------------------------------------------------------- 1 | //606 C 2 | #include 3 | using namespace std; 4 | long insertion_sort1 (vector a){ 5 | long j, temp; 6 | long ans = 0; 7 | for (long i = 0; i < a.size(); i++){ 8 | j = i; 9 | if(j > 0 && a[j] < a[j-1]){ 10 | ans++; 11 | temp = a[j]; 12 | a[j] = a[j-1]; 13 | a[j-1] = temp; 14 | } 15 | } 16 | return ans; 17 | } 18 | long insertion_sort2 (vector a){ 19 | long j, temp; 20 | long ans = 0; 21 | for (long i = a.size()-1; i>=0; i--){ 22 | j = i; 23 | if(j a[j+1]){ 24 | ans++; 25 | temp = a[j]; 26 | a[j] = a[j+1]; 27 | a[j+1] = temp; 28 | } 29 | } 30 | return ans; 31 | } 32 | int main(){ 33 | long n; 34 | cin>>n; 35 | vector a; 36 | while(n--){ 37 | long q; 38 | cin>>q; 39 | a.push_back(q); 40 | } 41 | if(insertion_sort1(a) 3 | using namespace std; 4 | int main(){ 5 | long long n; 6 | cin>>n; 7 | if (n%2==1){ 8 | cout<<0< 3 | using namespace std; 4 | int main(){ 5 | long long n; 6 | cin>>n; 7 | vector a; 8 | for(long long i=0;i>x; 11 | a.push_back(x); 12 | } 13 | long long minval = a[0]; 14 | long long minin = 0; 15 | long long maxin = 0; 16 | long long dist = 0; 17 | for(long long i=1;i 2 | using namespace std; 3 | int main(){ 4 | int a; 5 | cin>>a; 6 | long long b = 1; 7 | while(a--){ 8 | b*=2; 9 | } 10 | cout< 2 | using namespace std; 3 | int main(){ 4 | int f,i,t; 5 | cin>>f>>i>>t; 6 | vector temp(i,'N'); 7 | vector > likes(f,temp); 8 | for(int j=0;j>likes[j][k]; 11 | int ans = 0; 12 | for(int j=0;j=t) 19 | ans++; 20 | } 21 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | long long a,b,c; 6 | cin>>a>>b>>c; 7 | bool flag = false; 8 | if(c!=0 && (b-a)%c==0){ 9 | if(c>0){ 10 | if(b>=a) 11 | flag = true; 12 | }else{ 13 | if(b<=a) 14 | flag = true; 15 | } 16 | }else{ 17 | if(a==b) 18 | flag = true; 19 | } 20 | if(flag) 21 | cout<<"YES"< 2 | using namespace std; 3 | int main() 4 | { 5 | long long a,b,c,d,n; 6 | cin>>n>>a>>b>>c>>d; 7 | vector comp; 8 | comp.push_back(0); 9 | comp.push_back(d-a); 10 | comp.push_back(c-b); 11 | comp.push_back(c+d-a-b); 12 | vector::iterator maxit = max_element(comp.begin(),comp.end()); 13 | vector::iterator minit = min_element(comp.begin(),comp.end()); 14 | long long l = n + *minit, r = 1+*maxit; 15 | long long ans = n; 16 | if(l>=r) 17 | ans *= (l-r+1); 18 | else 19 | ans = 0; 20 | cout< 2 | using namespace std; 3 | 4 | int main() { 5 | ios_base::sync_with_stdio(false); cin.tie(0); 6 | 7 | int n; 8 | cin >> n; 9 | map d; 10 | long long sum = 0; 11 | int ans = n - 1; 12 | for (int i = 0; i < n; i++) { 13 | int t; 14 | cin >> t; 15 | sum += t; 16 | d[sum]++; 17 | ans = min(ans, n - d[sum]); 18 | } 19 | 20 | cout << ans << endl; 21 | } 22 | -------------------------------------------------------------------------------- /codeforces/676A-Nicholas_and_permutation.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(){ 4 | int n; 5 | cin>>n; 6 | vector arr(n); 7 | int mini,maxi; 8 | for(int i=0;i>arr[i]; 10 | if(arr[i]==1) 11 | mini = i; 12 | if(arr[i] == n) 13 | maxi = i; 14 | } 15 | int temp = min(mini,maxi); 16 | maxi = max(mini,maxi); 17 | mini = temp; 18 | cout< 2 | using namespace std; 3 | int main(){ 4 | long n,k; 5 | string a; 6 | cin>>n>>k; 7 | cin>>a; 8 | long answer = 0; 9 | long i,j; 10 | i = 0; 11 | long aval = 0,bval = 0; 12 | for(j=i;j k && bval > k) 18 | break; 19 | } 20 | answer = max(answer,j-i); 21 | while(i k && bval > k){ 34 | break; 35 | } 36 | } 37 | answer = max(answer,j-i); 38 | // cout< 2 | using namespace std; 3 | int main(){ 4 | long n; 5 | cin>>n; 6 | vector arr(n); 7 | for(long i=0;i>arr[i]; 9 | } 10 | long maxv = 1, count= 1; 11 | for(long i=1;i arr[i-1]) 13 | count++; 14 | else 15 | count = 1; 16 | maxv = max(count,maxv); 17 | } 18 | cout< 2 | using namespace std; 3 | int main(){ 4 | long n; 5 | cin>>n; 6 | vector arr(n); 7 | for(long i=0;i>arr[i]; 9 | long long ans = 0; 10 | map ansmap; 11 | for(long i=0;i 2 | using namespace std; 3 | int main(){ 4 | long n,m; 5 | cin>>n>>m; 6 | vector cities(n), cns(m); 7 | for(long i=0;i>cities[i]; 9 | } 10 | for(long i=0;i>cns[i]; 12 | } 13 | sort(cities.begin(),cities.end()); 14 | sort(cns.begin(),cns.end()); 15 | long long maxv = 0, cnsp = 0; 16 | long i; 17 | for(i=0;i= cns[cnsp] && cnsp < m){ 21 | minv = min(abs(cities[i] - cns[cnsp]), minv); 22 | //cout<<"----"< 2 | using namespace std; 3 | int main(){ 4 | long long n,b,d; 5 | cin>>n>>b>>d; 6 | long long ans = 0; 7 | long long waste = 0; 8 | for(long long i=0;i>x; 11 | if(x > b) 12 | continue; 13 | waste += x; 14 | if(waste > d){ 15 | waste = 0; 16 | ans++; 17 | } 18 | } 19 | cout< 2 | using namespace std; 3 | int main(){ 4 | string init; 5 | bool running = false; 6 | bool changes = false; 7 | cin>>init; 8 | for(long i=0;i 2 | using namespace std; 3 | int main(){ 4 | long n; 5 | cin>>n; 6 | vector arr(n); 7 | for(long i=0;i>arr[i]; 9 | for(long i=0;i 2 | using namespace std; 3 | int main(){ 4 | string s; 5 | cin>>s; 6 | long u,d,l,r; 7 | u = d = l = r = 0; 8 | for(long i=0;i 2 | using namespace std; 3 | int main(){ 4 | long long l,r,q,w,p; 5 | cin>>l>>r>>q>>w>>p; 6 | long long ans = 0; 7 | long long start = max(l,q), end = min(r,w); 8 | ans = end-start+1; 9 | if(ans < 0) 10 | ans = 0; 11 | if(p >= start && p <= end) 12 | ans--; 13 | cout< 2 | using namespace std; 3 | int main(){ 4 | long n; 5 | cin>>n; 6 | set arr; 7 | for(long i=0;i>x; 10 | arr.insert(x); 11 | } 12 | if(arr.size()>3) 13 | cout<<"NO"<::iterator sit = arr.begin(); 18 | vector ans; 19 | while(sit!= arr.end()){ 20 | ans.push_back(*sit); 21 | sit++; 22 | } 23 | if(ans[1]-ans[0] == ans[2] - ans[1]) 24 | cout<<"YES"< 2 | using namespace std; 3 | int main(){ 4 | string s; 5 | cin>>s; 6 | s = "a"+s; 7 | int ans = 0; 8 | for(int i=1;i 2 | using namespace std; 3 | int main(){ 4 | int n; 5 | cin>>n; 6 | vector arr(n); 7 | for(int i=0;i>arr[i]; 9 | bool carry = false, flag = true; 10 | for(int i=0;i 0) { 13 | if(arr[i]%2 != 0) 14 | carry = false; 15 | } else { 16 | flag = false; 17 | break; 18 | } 19 | } 20 | else if(arr[i]%2!=0) 21 | carry = true; 22 | 23 | } 24 | if(flag && !carry) 25 | cout<<"YES"< 2 | using namespace std; 3 | int main() { 4 | int k,r; 5 | cin>>k>>r; 6 | k = k%10; 7 | label: 8 | int i; 9 | for(i=1;i<=10;i++) { 10 | if((i*k)%10 == r){ 11 | cout< 2 | using namespace std; 3 | int main() { 4 | int n,k; 5 | cin>>n>>k; 6 | vector arr(n); 7 | for(int i=0;i>arr[i]; 9 | long long ans = 0; 10 | for(int i=1;i 2 | using namespace std; 3 | int main() { 4 | long long b,d,s; 5 | cin>>b>>d>>s; 6 | long long ans = 0; 7 | long long temp; 8 | //*before bf 9 | //after supper 10 | ans = max(max(b,d),s)*3 - (b+d+s); 11 | //before supper 12 | temp = max(max((b-1),(d-1)),s)*3 - ((b-1)+(d-1)+s); 13 | if(temp < ans && temp >= 0) 14 | ans = temp; 15 | // before lunch 16 | temp = max(max((b-1),d),s)*3 - ((b-1)+d+s); 17 | if(temp < ans && temp >= 0) 18 | ans = temp; 19 | //*after bf 20 | temp = max(max(b,(d-1)),(s-1))*3 - (b+(d-1)+(s-1)); 21 | if(temp < ans && temp >= 0) 22 | ans = temp; 23 | temp = max(max((b-1),(d-1)),(s-1))*3 - ((b-1)+(d-1)+(s-1)); 24 | if(temp < ans && temp >= 0) 25 | ans = temp; 26 | temp = max(max((b-1),(d-2)),(s-1))*3 - ((b-1)+(d-2)+(s-1)); 27 | if(temp < ans && temp >= 0) 28 | ans = temp; 29 | temp = max(max(b,d),(s-1))*3 - (b+d+(s-1)); 30 | if(temp < ans && temp >= 0) 31 | ans = temp; 32 | temp = max(max((b-1),d),(s-1))*3 - ((b-1)+d+(s-1)); 33 | if(temp < ans && temp >= 0) 34 | ans = temp; 35 | cout< 2 | using namespace std; 3 | int main() { 4 | 5 | int n,k; 6 | cin>>n>>k; 7 | string s; 8 | cin>>s; 9 | bool flag = false; 10 | int start; 11 | for(int i=0;i= 0){ 16 | if(flag) 17 | break; 18 | if(s[x] == '#') 19 | break; 20 | if(s[x] == 'T') 21 | flag = true; 22 | x -= k; 23 | } 24 | x = start; 25 | while(x < s.size()){ 26 | if(flag) 27 | break; 28 | if(s[x] == '#') 29 | break; 30 | if(s[x] == 'T') 31 | flag = true; 32 | x += k; 33 | } 34 | if(flag) 35 | cout<<"YES"< 2 | using namespace std; 3 | int main() { 4 | long n, na, nb; 5 | cin>>n>>na>>nb; 6 | vector arr(n); 7 | for(long i=0;i>arr[i]; 9 | double ans=0; 10 | double temp = 0; 11 | long i=0; 12 | sort(arr.begin(),arr.end()); 13 | reverse(arr.begin(),arr.end()); 14 | for(;i 2 | using namespace std; 3 | int main() { 4 | long long n; 5 | cin>>n; 6 | long long prev = 1,i=2, ans = 0; 7 | while(n >= i) { 8 | i += prev; 9 | prev = i - prev; 10 | ans++; 11 | } 12 | cout< 2 | #include 3 | using namespace std; 4 | bool isprime(long long n) { 5 | for(long long i=2;i*i<=n;i++) { 6 | if(n%i == 0) 7 | return false; 8 | } 9 | return true; 10 | } 11 | int main() 12 | { 13 | long long n; 14 | cin>>n; 15 | if(isprime(n)) 16 | cout<<1< 2 | using namespace std; 3 | int main() { 4 | int n; 5 | cin>>n; 6 | bool flag = false; 7 | vector arr(n); 8 | for(int i=0;i>arr[i]; 10 | if(arr[i]!=0) 11 | flag = true; 12 | } 13 | if(flag){ 14 | cout<<"YES"< > ans; 16 | 17 | int l = 1, r = 1; 18 | 19 | for(int i=0;i 2 | using namespace std; 3 | bool arr[1000001]; 4 | void markMultiples(long a, long n) 5 | { 6 | long i = 2, num; 7 | while ( (num = i*a) <= n ) { 8 | arr[num] = true; 9 | ++i; 10 | } 11 | } 12 | void SieveOfEratosthenes(long n) 13 | { 14 | if (n >= 2) { 15 | fill(arr,arr+1000001,false); 16 | arr[0] = true; 17 | arr[1] = true; 18 | for (long i=2; i>n; 33 | if( n == 1) 34 | cout<<3< 2 | using namespace std; 3 | int main() { 4 | long n,m; 5 | cin>>n>>m; 6 | long a, b, c; 7 | set x; 8 | while(n--){ 9 | string t; 10 | cin>>t; 11 | x.insert(t); 12 | } 13 | a = 0, b = 0, c = 0; 14 | while(m--) { 15 | string t; 16 | cin>>t; 17 | if (x.find(t) == x.end()) 18 | b++; 19 | else 20 | c++; 21 | } 22 | a = x.size()-c; 23 | if(a>b) 24 | cout<<"YES"; 25 | else if(a 2 | #define pb push_back 3 | #define ll long long 4 | using namespace std; 5 | ll gcd(ll a, ll b) { 6 | if(b==0) 7 | return a; 8 | else 9 | return gcd(b,a%b); 10 | } 11 | int main() { 12 | ll n,k; 13 | cin>>n>>k; 14 | ll start = 0; 15 | long long i = 1, inc = 1; 16 | if(k!=n-1){ 17 | if( k > n/2) 18 | k = n-k; 19 | do { 20 | start += k; 21 | if(start > n) { 22 | inc ++; 23 | i += inc; 24 | inc++; 25 | } else i += inc; 26 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | string s; 6 | cin>>s; 7 | long capb = 0; 8 | vector hash(26,0); 9 | for(long i=0;i= 'a' && s[i] <= 'z') 11 | hash[s[i]-'a']++; 12 | else if(s[i] == 'B') 13 | capb++; 14 | } 15 | capb = min(capb,hash[0]/2); 16 | capb = min(capb,hash['u'-'a']/2); 17 | capb = min(capb,hash[1]); 18 | capb = min(capb,hash['l'-'a']); 19 | capb = min(capb,hash['s'-'a']); 20 | capb = min(capb,hash['r'-'a']); 21 | cout< 2 | using namespace std; 3 | #define ll long long 4 | int main() { 5 | int m,d; 6 | cin>>m>>d; 7 | int days = 0; 8 | switch(m) { 9 | case 1: 10 | case 3: 11 | case 5: 12 | case 7: 13 | case 8: 14 | case 10: 15 | case 12: 16 | days = 31; 17 | break; 18 | case 2: 19 | days = 28; 20 | break; 21 | case 4: 22 | case 6: 23 | case 9: 24 | case 11: 25 | days = 30; 26 | } 27 | days = days - (7-d+1); 28 | cout< 2 | using namespace std; 3 | #define ll long long 4 | int main() { 5 | long long n,m,k; 6 | cin>>n>>m>>k; 7 | ll ans = 1; 8 | m -= n; 9 | long long aff, afb; 10 | aff = 0; 11 | afb = 0; 12 | // bool init = true; 13 | while(m > 0) { 14 | m -= aff+afb+1; 15 | ans++; 16 | aff++; 17 | if(aff == k) 18 | aff = k-1; 19 | if(afb + k < n) 20 | afb++; 21 | if(aff + afb + 1 == n) { 22 | // cout<<"coming in at ans = "< dp(n); 17 | it = it1 = 0; 18 | for(long i = 0; i < n; i++,sit++) { 19 | b = a + 20; 20 | while(it != arr.size() && arr[it] <= arr[sit] - 90) 21 | it++; 22 | if(it == 0) 23 | b = min(b,(ll)50); 24 | else { 25 | it--; 26 | b = min(b,dp[it]+50); 27 | } 28 | while(it1 != arr.size() && arr[it1] <= arr[sit] - 1440) 29 | it1++; 30 | if(it1 == 0) 31 | b = min(b,(ll)120); 32 | else { 33 | it1--; 34 | b = min(b,dp[it1]+120); 35 | } 36 | // cout<<"it = "<<*it<<" it1 = "<<*it1<<" sit = "<<*sit< 2 | using namespace std; 3 | int main() { 4 | long n; 5 | cin>>n; 6 | cout<<"YES"<>a>>b>>c>>d; 10 | a = a%2; 11 | b = b%2; 12 | if(a&&b) 13 | cout<<1; 14 | else if(a&&!b) 15 | cout<<2; 16 | else if(!a&&b) 17 | cout<<3; 18 | else 19 | cout<<4; 20 | cout< 2 | using namespace std; 3 | 4 | int main() { 5 | double n, k; 6 | double s , pockets; 7 | cin>>n>>k; 8 | while(n--) { 9 | cin>>s; 10 | pockets += ceil(s/k); 11 | } 12 | cout<<(long long)ceil(pockets/2.0); 13 | return 0; 14 | 15 | } 16 | -------------------------------------------------------------------------------- /codeforces/822A-bored_with_life.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | long long fac(long n){ 4 | if(n <= 1) 5 | return 1; 6 | return n*fac(n-1); 7 | } 8 | int main() { 9 | long long a,b; 10 | cin>>a>>b; 11 | cout< 2 | using namespace std; 3 | vector get_ans(string s, string t, int x){ 4 | vector ans; 5 | for(long i=x;i>a>>b; 15 | string s, t; 16 | cin>>s>>t; 17 | vector ans; 18 | for(int i=0;i<=t.size()-s.size();i++){ 19 | vector temp = get_ans(s,t,i); 20 | if(i == 0) { 21 | ans = temp; 22 | } 23 | else if (temp.size() < ans.size()) { 24 | ans = temp; 25 | } 26 | } 27 | cout< 2 | using namespace std; 3 | int main(){ 4 | long n,a,b; 5 | cin>>n>>a>>b; 6 | long va = 0; 7 | long long ans = 0; 8 | while(n--){ 9 | int c; 10 | cin>>c; 11 | if(c == 2){ 12 | if(b==0) ans+=2; 13 | else b--; 14 | } else { 15 | if(a == 0 && va == 0 && b == 0) ans++; 16 | else if(a==0 && b == 0){ 17 | va--; 18 | } else if(a==0){ 19 | b--; 20 | va++; 21 | } else { 22 | a--; 23 | } 24 | } 25 | // cout< 2 | using namespace std; 3 | int main(){ 4 | long x,y; 5 | cin>>x>>y; 6 | vector arr(x); 7 | for(long i=0;i>arr[i]; 9 | } 10 | long black = 0; 11 | long top = -1; 12 | long bottom = -1, left = -1, right = -1; 13 | for(long i=0;i i) top = i; 18 | if(bottom == -1 || bottom < i) bottom = i; 19 | if(left == -1 || left > j) left = j; 20 | if(right == -1 || right < j) right = j; 21 | } 22 | } 23 | } 24 | long side = max(abs(left-right)+1,abs(top-bottom)+1); 25 | long area = side*side; 26 | if(area > x*y || side > x || side > y) 27 | cout<<-1< 2 | using namespace std; 3 | int main(){ 4 | long n,k; 5 | cin>>n>>k; 6 | if(k == 2){ 7 | printf("%ld\n",n-1); 8 | for(long i=1;i 2 | using namespace std; 3 | int main() 4 | { 5 | long long n; 6 | cin>>n; 7 | long long num=0,numbef=0,i; 8 | for(i=1;;i*=2) 9 | { 10 | numbef=num; 11 | num+=5*i; 12 | if(num>=n) 13 | break; 14 | } 15 | cout<<"num-"< 2 | #define pb push_back 3 | #define mp make_pair 4 | using namespace std; 5 | int main(){ 6 | int n; 7 | cin>>n; 8 | vector starts; 9 | vector left(n+1), right(n+1); 10 | for(int i=1;i<=n;i++){ 11 | cin>>left[i]>>right[i]; 12 | if(left[i] == 0) starts.pb(i); 13 | } 14 | vector > lists; 15 | for(int i=0;i slist; 17 | slist.pb(starts[i]); 18 | int val = starts[i]; 19 | while(right[val] != 0){ 20 | val = right[val]; 21 | slist.pb(val); 22 | } 23 | lists.pb(slist); 24 | } 25 | for(int i=0;i 2 | using namespace std; 3 | int main(){ 4 | long n, t; 5 | cin>>n>>t; 6 | return 0; 7 | } -------------------------------------------------------------------------------- /codeforces/847K-Travel_cards.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define pb push_back 3 | #define mp make_pair 4 | using namespace std; 5 | int main(){ 6 | int n, a, b, k, f; 7 | cin>>n>>a>>b>>k>>f; 8 | vector ss(n), es(n); 9 | map, long> m; 10 | for(int i=0;i>ss[i]>>es[i]; 12 | if(m.find(mp(min(ss[i],es[i]),max(ss[i],es[i]))) == m.end()){ 13 | m[mp(min(ss[i],es[i]),max(ss[i],es[i]))] = 0; 14 | } 15 | if(i != 0 && ss[i] == es[i-1]) 16 | m[mp(min(ss[i],es[i]),max(ss[i],es[i]))] += b; 17 | else 18 | m[mp(min(ss[i],es[i]),max(ss[i],es[i]))] += a; 19 | } 20 | map, long>::iterator mit; 21 | vector arr; 22 | long long ans = 0; 23 | for(mit = m.begin();mit != m.end();mit++){ 24 | arr.pb(mit->second); 25 | ans += mit->second; 26 | } 27 | sort(arr.begin(),arr.end()); 28 | for(long i = arr.size()-1; i >= 0 && k > 0 && arr[i] > f; i--, k--) { 29 | ans -= arr[i]; 30 | ans += f; 31 | } 32 | cout< 2 | using namespace std; 3 | int main(){ 4 | int n; 5 | cin>>n; 6 | vector t(n); 7 | int diff; 8 | bool bval = true; 9 | for(int i=0;i>t[i]; 11 | if(i > 1){ 12 | if(t[i] - t[i-1] != diff) 13 | bval = false; 14 | } else if(i == 1) 15 | diff = t[1]-t[0]; 16 | } 17 | if(bval) cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int n; 6 | cin>>n; 7 | vector arr(n); 8 | for(long i=0;i>arr[i]; 9 | for(long i=0;i 180){ 19 | sum -= arr[start]; 20 | start++; 21 | } 22 | ans = max(ans,sum); 23 | // cout< 2 | using namespace std; 3 | string s; 4 | void func(int l, int r, char c, char d){ 5 | for(int i=l;i>n>>q; 12 | cin>>s; 13 | while(q--){ 14 | int l,r; 15 | char c,d; 16 | cin>>l>>r>>c>>d; 17 | func(l-1,r,c,d); 18 | } 19 | cout<= k: 17 | return f1[k-1] 18 | c = count(n-1) 19 | k -= lf1 20 | if c >= k: 21 | return func(n-1,k) 22 | k -= c 23 | if lf2 >= k: 24 | return f2[k-1] 25 | k -= lf2 26 | if c >= k: 27 | return func(n-1,k) 28 | k -= c 29 | if lf3 >= k: 30 | return f3[k-1] 31 | q = input() 32 | ans = "" 33 | while q: 34 | n,k = map(int,raw_input().split()) 35 | ans += func(n,k) 36 | q -= 1 37 | print ans -------------------------------------------------------------------------------- /codeforces/897C-Nephren_gives_a_riddle.py: -------------------------------------------------------------------------------- 1 | s = "What are you doing at the end of the world? Are you busy? Will you save us?" 2 | f1 = 'What are you doing while sending "' 3 | f2 = '"? Are you busy? Will you send "' 4 | f3 = '"?' 5 | lf1 = len(f1) 6 | lf2 = len(f2) 7 | lf3 = len(f3) 8 | m = 10**20 9 | def count(n): 10 | if n >= 60: 11 | return m 12 | temp = 1<= k: 20 | return f1[k-1],1,0 21 | c = count(n-1) 22 | k -= lf1 23 | if c >= k: 24 | return n-1,k,1 25 | k -= c 26 | if lf2 >= k: 27 | return f2[k-1],1,0 28 | k -= lf2 29 | if c >= k: 30 | return n-1,k,1 31 | k -= c 32 | if lf3 >= k: 33 | return f3[k-1],1,0 34 | q = input() 35 | ans = "" 36 | while q: 37 | n,k = map(int,raw_input().split()) 38 | a,b,c = func(n,k) 39 | while c == 1: 40 | a,b,c = func(a,b) 41 | ans += a 42 | q -= 1 43 | print ans -------------------------------------------------------------------------------- /codeforces/908A-CountingCards.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define pb push_back 4 | #define mp make_pair 5 | #define vll vector 6 | using namespace std; 7 | int main(){ 8 | string s; 9 | cin>>s; 10 | ll ans = 0; 11 | string k = "aeiou13579"; 12 | for(long i=0;i 2 | #define ll long long 3 | #define pb push_back 4 | #define mp make_pair 5 | #define vll vector 6 | using namespace std; 7 | int main(){ 8 | long n, m; 9 | cin>>n>>m; 10 | vll arr(n); 11 | for(long i=0;i>arr[i]; 12 | vector centers(1010, -m); 13 | for(long i=0;i r) continue; 20 | // cout< 2 | #define ll long long 3 | #define pb push_back 4 | #define mp make_pair 5 | #define vll vector 6 | using namespace std; 7 | int main(){ 8 | ll n, a, b; 9 | cin>>n>>a>>b; 10 | ll aval = ceil(((double)a*n)/(a+b)); 11 | ll bval = n-aval; 12 | // cout< 0 && bval > 0) 15 | ans = max(ans, min(a/aval, b/bval)); 16 | aval = floor(((double)a*n)/(a+b)); 17 | bval = n-aval; 18 | if(aval > 0 && bval > 0) 19 | ans = max(ans, min(a/aval, b/bval)); 20 | cout< 2 | #define ll long long 3 | #define pb push_back 4 | #define mp make_pair 5 | #define vll vector 6 | using namespace std; 7 | int main(){ 8 | ll n, a, b; 9 | cin>>n>>a>>b; 10 | ll aval = ceil(((double)a*n)/(a+b)); 11 | ll bval = n-aval; 12 | // cout< 0 && bval > 0) 15 | ans = max(ans, min(a/aval, b/bval)); 16 | aval = floor(((double)a*n)/(a+b)); 17 | bval = n-aval; 18 | if(aval > 0 && bval > 0) 19 | ans = max(ans, min(a/aval, b/bval)); 20 | cout< 2 | #define ll long long 3 | #define pb push_back 4 | #define mp make_pair 5 | #define vll vector 6 | using namespace std; 7 | int main(){ 8 | bool flag = false; 9 | ll a, b, c; 10 | cin>>a>>b>>c; 11 | if(a == 1 || b == 1 || c == 1) flag = true; 12 | else { 13 | vector arr; 14 | arr.pb(a); 15 | arr.pb(b); 16 | arr.pb(c); 17 | sort(arr.begin(), arr.end()); 18 | if(arr[1] == 2) flag = true; 19 | else { 20 | if(b == 3 && c == 3 && a == 3) flag = true; 21 | if(arr[0] == 2 && arr[1] == 4 && arr[2] == 4) flag = true; 22 | } 23 | } 24 | if(flag) cout<<"YES"< 2 | #define ll long long 3 | #define pb push_back 4 | #define mp make_pair 5 | #define vll vector 6 | using namespace std; 7 | int main(){ 8 | long n; 9 | cin>>n; 10 | vll arr(n); 11 | for(long i=0;i arr[i]){ 16 | ans++; 17 | } 18 | } 19 | } 20 | ll m; 21 | cin>>m; 22 | bool f = true; 23 | if(ans&1) f = false; 24 | while(m--){ 25 | ll l, r; 26 | scanf("%lld %lld", &l, &r); 27 | ll x = r-l; 28 | x = (x*(x+1))/2; 29 | if(x&1) f = !f; 30 | if(f) cout<<"even\n"; 31 | else cout<<"odd\n"; 32 | } 33 | return 0; 34 | } -------------------------------------------------------------------------------- /codeforces/911G-Mass_change_querries.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define pb push_back 4 | #define mp make_pair 5 | #define vll vector 6 | #define S(a) scanf("%lld", &a) 7 | using namespace std; 8 | int main(){ 9 | long n; 10 | cin>>n; 11 | vector arr(n); 12 | for(long i=0;i>arr[i]; 14 | } 15 | long m; 16 | S(m); 17 | while(m--) { 18 | long l, r; 19 | 20 | S(l); 21 | S(r); 22 | } 23 | return 0; 24 | } -------------------------------------------------------------------------------- /codeforces/912A-Tricky_alchemy.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define pb push_back 4 | #define mp make_pair 5 | #define vll vector 6 | #define all(S) S.begin(),S.end() 7 | #define S(a) scanf("%lld", &n) 8 | using namespace std; 9 | int main(){ 10 | ll a, b, x, y, z; 11 | cin>>a>>b>>x>>y>>z; 12 | x = 2*x; 13 | z = 3*z; 14 | x += y; 15 | z += y; 16 | // cout< 2 | #define ll long long 3 | #define pb push_back 4 | #define mp make_pair 5 | #define vll vector 6 | #define all(S) S.begin(),S.end() 7 | #define S(a) scanf("%lld", &n) 8 | using namespace std; 9 | int main(){ 10 | ll a, k; 11 | cin>>a>>k; 12 | ll p = 0; 13 | ll b = a; 14 | while(a){ 15 | p++; 16 | a /= 2; 17 | } 18 | if(k > 1){ 19 | ll ans = pow(2, p); 20 | ans--; 21 | cout< 2 | #define ll long long 3 | #define pb push_back 4 | #define mp make_pair 5 | #define vll vector 6 | #define all(S) S.begin(), S.end() 7 | #define S(a) scanf("%lld", &a) 8 | using namespace std; 9 | ll get_mins(ll h, ll m){ 10 | return h*60 + m; 11 | } 12 | pair get_form(ll m){ 13 | return mp(m/60, m%60); 14 | } 15 | bool ch(ll a){ 16 | if(a%10 == 7) 17 | return true; 18 | return false; 19 | } 20 | int main(){ 21 | ll x, h, m; 22 | S(x); 23 | S(h); 24 | S(m); 25 | ll val = get_mins(h, m); 26 | ll ans = 0; 27 | while(true){ 28 | // cout<<"val = "< c = get_form(val); 30 | // cout< 2 | #define ll long long 3 | #define pb push_back 4 | #define mp make_pair 5 | #define vll vector 6 | #define all(S) S.begin(), S.end() 7 | #define S(a) scanf("%lld", &a) 8 | using namespace std; 9 | int main(){ 10 | long n; 11 | S(n); 12 | long a = 3; 13 | long b = 5; 14 | string s = "OOOo"; 15 | long i = 5; 16 | while(i <= 1010){ 17 | if(i == b){ 18 | s += "O"; 19 | long c = a; 20 | a = b; 21 | b = c+b; 22 | } else { 23 | s += "o"; 24 | } 25 | i++; 26 | } 27 | cout< 2 | #define ll long long 3 | #define pb push_back 4 | #define mp make_pair 5 | #define vll vector 6 | #define all(S) S.begin(), S.end() 7 | #define S(a) scanf("%ld", &a) 8 | using namespace std; 9 | int main(){ 10 | map ma; 11 | long n, m; 12 | S(n); 13 | S(m); 14 | while(n--){ 15 | string s, t; 16 | cin>>s>>t; 17 | ma[t+";"] = s; 18 | } 19 | while(m--) { 20 | string s, t; 21 | cin>>s>>t; 22 | cout< 2 | #define ll long long 3 | #define pb push_back 4 | #define mp make_pair 5 | #define vll vector 6 | #define all(S) S.begin(), S.end() 7 | #define S(a) scanf("%lld", &a) 8 | using namespace std; 9 | int main(){ 10 | string s; 11 | cin>>s; 12 | long ans = 0; 13 | for(long i=0;i mnoq) 27 | mnoq++; 28 | } 29 | if(ano < 0) ano = 0; 30 | if(nc > no + noq) break; 31 | if(nc > no){ 32 | noq -= nc-no; 33 | no = nc; 34 | if(mnoq > noq) mnoq = noq; 35 | } 36 | if(nc == no){ 37 | if(noq%2 == 0){ 38 | ans++; 39 | } 40 | } else if (no > nc){ 41 | if(ano == 0 && (j-i+1)%2 ==0){ 42 | ans++; 43 | } 44 | } 45 | } 46 | } 47 | cout< 2 | using namespace std; 3 | int main(){ 4 | long long x, y; 5 | cin>>x>>y; 6 | y--; 7 | x -= y; 8 | if( x < 0 || y < 0 || x&1){ 9 | cout<<"No"< 2 | using namespace std; 3 | int main(){ 4 | long n; 5 | cin>>n; 6 | // set > b; 7 | long ans = 0; 8 | for(long i=1;i<=n;i++) { 9 | for(long j=i;j<=n;j++) { 10 | long k = i^j; 11 | if(i+j > k && i+k > j && j+k > i && k != 0 && k <= n && k > i && k > j) { 12 | // vector a; 13 | // a.push_back(i); 14 | // a.push_back(j); 15 | // a.push_back(k); 16 | // sort(a.begin(), a.end()); 17 | ans++; 18 | // b.insert(a); 19 | } 20 | } 21 | } 22 | cout< 2 | #define ll long long 3 | #define pb push_back 4 | #define mp make_pair 5 | #define vll vector 6 | #define all(S) S.begin(), S.end() 7 | #define S(a) scanf("%lld", &a) 8 | using namespace std; 9 | ll gcd(ll a, ll b){ 10 | if(b == 0) return a; 11 | else return gcd(b, a%b); 12 | } 13 | int main(){ 14 | ll n, k; 15 | cin>>n>>k; 16 | if(k == 1){ 17 | cout<<"Yes"< n || (n-ans)%step != 0) 36 | cout<<"No"< n: 23 | break 24 | step /= gcd(step, i) 25 | step *= i 26 | i += 1 27 | if (ans > n) or ((n-ans)%step != 0): 28 | print no 29 | else: 30 | print yes -------------------------------------------------------------------------------- /codeforces/935A-Fafa_and_his_company.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define pb push_back 4 | #define mp make_pair 5 | #define vll vector 6 | #define all(S) S.begin(), S.end() 7 | #define S(a) scanf("%lld", &a) 8 | using namespace std; 9 | int main(){ 10 | long t; 11 | scanf("%ld", &t); 12 | set s; 13 | for(long i=1;i<=sqrt(t);i++) { 14 | if(t%i == 0){ 15 | s.insert(i); 16 | s.insert(t/i); 17 | } 18 | } 19 | cout< 2 | #define ll long long 3 | #define pb push_back 4 | #define mp make_pair 5 | #define vll vector 6 | #define all(S) S.begin(), S.end() 7 | #define S(a) scanf("%lld", &a) 8 | using namespace std; 9 | int main(){ 10 | long n; 11 | cin>>n; 12 | string s; 13 | cin>>s; 14 | int direction = -1; 15 | long x = 0; 16 | long y = 0; 17 | long ans = 0; 18 | for(long i = 0; i y) direction = 1; 24 | else direction = 0; 25 | } 26 | if(x > y && direction == 0) { 27 | direction = 1; 28 | ans++; 29 | } 30 | if(x < y && direction == 1) { 31 | direction = 0; 32 | ans++; 33 | } 34 | } 35 | cout< 2 | #define ll long long 3 | #define pb push_back 4 | #define mp make_pair 5 | #define vll vector 6 | #define all(S) S.begin(), S.end() 7 | #define S(a) scanf("%lld", &a) 8 | using namespace std; 9 | int main(){ 10 | ll a; 11 | cin>>a; 12 | if(a&1) cout<<"Ehab"; 13 | else cout<<"Mahmoud"; 14 | return 0; 15 | } -------------------------------------------------------------------------------- /codeforces/959B-ME-the-message.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define pb push_back 4 | #define mp make_pair 5 | #define vll vector 6 | #define all(S) S.begin(), S.end() 7 | #define S(a) scanf("%lld", &a) 8 | using namespace std; 9 | int main(){ 10 | ll w, g, n; 11 | S(w); 12 | S(g); 13 | S(n); 14 | vector words(w); 15 | for(long i=0;i>words[i]; 17 | } 18 | vector mval(w); 19 | for(long i=0;i>mval[i]; 21 | map m; 22 | vector groups(g); 23 | for(long i=0; i>j; 26 | bool first = true; 27 | while(j--) { 28 | long k; 29 | cin>>k; 30 | k--; 31 | if(first) { 32 | groups[i] = mval[k]; 33 | } 34 | first = false; 35 | m[words[k]] = i; 36 | groups[i] = min(groups[i], mval[k]); 37 | } 38 | } 39 | ll ans = 0; 40 | for(long i=0; i< n;i++) { 41 | string s; 42 | cin>>s; 43 | ans += groups[m[s]]; 44 | } 45 | cout< 2 | #define ll long long 3 | #define pb push_back 4 | #define mp make_pair 5 | #define vll vector 6 | #define all(S) S.begin(), S.end() 7 | #define S(a) scanf("%lld", &a) 8 | using namespace std; 9 | int main(){ 10 | ll n; 11 | cin >> n; 12 | if (n <= 5) { 13 | cout << -1 << endl; 14 | } else { 15 | cout << "1 2" << endl; 16 | cout << "2 3" << endl; 17 | cout << "2 4" << endl; 18 | for(long i = 5; i <= n; i++) { 19 | cout << "1 " << i << endl; 20 | } 21 | } 22 | for(long i = 2; i <= n; i++) { 23 | cout << "1 " << i << endl; 24 | } 25 | return 0; 26 | } -------------------------------------------------------------------------------- /codeforces/959E-ME-xor-MST.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define pb push_back 4 | #define mp make_pair 5 | #define vll vector 6 | #define all(S) S.begin(), S.end() 7 | #define S(a) scanf("%lld", &a) 8 | using namespace std; 9 | map m, am; 10 | ll ans( ll n ) { 11 | if(n == 0) return 0; 12 | ll k = 1; 13 | while (k <= n) { 14 | k <<= 1; 15 | } 16 | k >>= 1; 17 | return m[k] + ans(n-k); 18 | } 19 | int main(){ 20 | m[1] = 1; 21 | ll cum = 1; 22 | ll val = 2; 23 | while( val <= 1000000000000LL) { 24 | m[val] = cum + val; 25 | cum += m[val]; 26 | val <<= 1; 27 | } 28 | ll n; 29 | cin>> n; 30 | cout<< ans(n-1); 31 | return 0; 32 | } -------------------------------------------------------------------------------- /codeforces/998A-balloons.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define pb push_back 4 | #define mp make_pair 5 | #define vll vector 6 | #define all(S) S.begin(), S.end() 7 | #define S(a) scanf("%lld", &a) 8 | using namespace std; 9 | int main(){ 10 | long n; 11 | cin >> n; 12 | vll arr(n); 13 | for (long i = 0; i < n; i++) { 14 | cin >> arr[i]; 15 | } 16 | vll::iterator it = min_element(arr.begin(), arr.end()); 17 | ll ts = accumulate(arr.begin(), arr.end(), 0); 18 | ll x = *it; 19 | ll y = ts - x; 20 | if (n == 1 || x == y) { 21 | cout << -1 << endl; 22 | } else { 23 | cout << 1 << endl << distance(arr.begin(), it)+1 << endl; 24 | } 25 | return 0; 26 | } -------------------------------------------------------------------------------- /codeforces/998B-Cutting.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define pb push_back 4 | #define mp make_pair 5 | #define vll vector 6 | #define all(S) S.begin(), S.end() 7 | #define S(a) scanf("%lld", &a) 8 | using namespace std; 9 | int main(){ 10 | long n; 11 | ll a; 12 | cin >> n >> a; 13 | vll arr(n); 14 | for (long i = 0; i < n; i++) { 15 | cin >> arr[i]; 16 | } 17 | vll ans_arr; 18 | long odd, even; 19 | odd = even = 0; 20 | for (long i = 0; i < n-1; i++) { 21 | if (arr[i] & 1) odd++; 22 | else even++; 23 | if (odd == even) { 24 | ans_arr.pb(abs(arr[i+1] - arr[i])); 25 | } 26 | } 27 | sort(all(ans_arr)); 28 | long ans = 0; 29 | for (long i = 0; i < ans_arr.size(); i++) { 30 | if (ans_arr[i] <= a) { 31 | a -= ans_arr[i]; 32 | ans++; 33 | } 34 | } 35 | cout << ans << endl; 36 | return 0; 37 | } -------------------------------------------------------------------------------- /codeforces/998C-Convert_to_ones.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define pb push_back 4 | #define mp make_pair 5 | #define vll vector 6 | #define all(S) S.begin(), S.end() 7 | #define S(a) scanf("%lld", &a) 8 | using namespace std; 9 | int main(){ 10 | long n; 11 | ll x, y; 12 | cin >> n >> x >> y; 13 | string s; 14 | cin >> s; 15 | long cont_z = 0, noz = 0; 16 | for (long i = 0; i < s.size(); i++) { 17 | if (s[i] == '0') { 18 | cont_z++; 19 | } else { 20 | if (cont_z > 0) { 21 | cont_z = 0; 22 | noz++; 23 | } 24 | } 25 | } 26 | if(cont_z > 0) noz++; 27 | ll ans = noz * y; 28 | long xc = 0; 29 | while (noz > 0) { 30 | // cout << xc * x + noz * y << endl; 31 | ans = min(ans, xc * x + noz * y); 32 | noz--; 33 | xc++; 34 | } 35 | cout << ans << endl; 36 | return 0; 37 | } -------------------------------------------------------------------------------- /codeforces/Erothesthenes_seive.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | bool arr[1000001]; 4 | void markMultiples(int a, int n) 5 | { 6 | int i = 2, num; 7 | while ( (num = i*a) <= n ) 8 | { 9 | arr[num] = true; 10 | ++i; 11 | } 12 | } 13 | void SieveOfEratosthenes(int n) 14 | { 15 | if (n >= 2) 16 | { 17 | fill(arr,arr+1000001,false); 18 | for (int i=2; i 2 | #include 3 | using namespace std; 4 | int checkv(char ch) 5 | { 6 | if(ch=='A') 7 | } 8 | -------------------------------------------------------------------------------- /codeforces/bfs.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /codeforces/dominoes_piling.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int m,n; 6 | cin>>m>>n; 7 | cout<<(int)((m*n)/2); 8 | return 0; 9 | } -------------------------------------------------------------------------------- /codeforces/template: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /codejam-16/qualification round/A-small-attempt0.in: -------------------------------------------------------------------------------- 1 | 100 2 | 0 3 | 1 4 | 2 5 | 11 6 | 30 7 | 9 8 | 39 9 | 145 10 | 25 11 | 200 12 | 160 13 | 34 14 | 92 15 | 108 16 | 153 17 | 181 18 | 50 19 | 67 20 | 173 21 | 147 22 | 75 23 | 62 24 | 10 25 | 136 26 | 107 27 | 134 28 | 27 29 | 131 30 | 152 31 | 140 32 | 8 33 | 121 34 | 105 35 | 100 36 | 3 37 | 83 38 | 175 39 | 123 40 | 76 41 | 70 42 | 125 43 | 15 44 | 193 45 | 150 46 | 54 47 | 63 48 | 116 49 | 186 50 | 171 51 | 42 52 | 185 53 | 183 54 | 198 55 | 21 56 | 184 57 | 81 58 | 6 59 | 138 60 | 169 61 | 96 62 | 88 63 | 137 64 | 7 65 | 194 66 | 4 67 | 5 68 | 151 69 | 130 70 | 177 71 | 91 72 | 77 73 | 124 74 | 122 75 | 118 76 | 166 77 | 14 78 | 43 79 | 78 80 | 182 81 | 162 82 | 111 83 | 20 84 | 119 85 | 157 86 | 40 87 | 189 88 | 23 89 | 87 90 | 56 91 | 197 92 | 22 93 | 190 94 | 127 95 | 29 96 | 13 97 | 103 98 | 41 99 | 133 100 | 53 101 | 179 102 | -------------------------------------------------------------------------------- /codejam-16/qualification round/B-small-input.in: -------------------------------------------------------------------------------- 1 | 5 2 | - 3 | -+ 4 | +- 5 | +++ 6 | --+- 7 | -------------------------------------------------------------------------------- /codejam-16/qualification round/Fractiles.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | ifstream inp; 6 | ofstream op; 7 | inp.open("D-small-attempt0.in"); 8 | op.open("D-small.out"); 9 | int t; 10 | inp>>t; 11 | for(int i=1;i<=t;i++){ 12 | int k,c,s; 13 | inp>>k>>c>>s; 14 | op<<"Case #"< 2 | using namespace std; 3 | ofstream file; 4 | void getstring(string a, int c){ 5 | c--; 6 | string old = a; 7 | while(c--){ 8 | string b = ""; 9 | for(int i=0;i>n; 28 | file.open("Fractiles-util.out"); 29 | ifstream infile; 30 | infile.open("combinations"); 31 | int i = 64; 32 | while(i--){ 33 | string a; 34 | infile>>a; 35 | replace(a.begin(),a.end(),'1','G'); 36 | replace(a.begin(),a.end(),'0','L'); 37 | getstring(a,n); 38 | } 39 | file.close(); 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /codejam-16/qualification round/INMO-2016 English Version.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lakshmanaram/Competitive-programming/31f4276ff529b3066e04497555bdb379fb2674c2/codejam-16/qualification round/INMO-2016 English Version.pdf -------------------------------------------------------------------------------- /codejam-16/qualification round/coin-jam.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | ofstream file; 4 | void getstring(string a, int c){ 5 | c--; 6 | string old = a; 7 | while(c--){ 8 | string b = ""; 9 | for(int i=0;i>n; 28 | file.open("Fractiles-util.out"); 29 | ifstream infile; 30 | infile.open("combinations"); 31 | long long i = 16384; 32 | while(i--){ 33 | string a; 34 | infile>>a; 35 | string s = "1"; 36 | s += a; 37 | s += "1\0"; 38 | cout<=0: 6 | if s[i] == '1': 7 | val += base**(15-i) 8 | i-=1 9 | print val 10 | f1 = open('combinations','r') 11 | for i in range(1,16385): 12 | a = str(f1.readline()) 13 | s = "1" + a[:-1] + "1" 14 | #print s 15 | count = 0 16 | 17 | #if check_valid(s): 18 | # count += 1 19 | print count 20 | #f2.write("Case #"+str(i)+": "+str(no*a)+"\n") 21 | f1.close() 22 | -------------------------------------------------------------------------------- /codejam-16/qualification round/primes.py: -------------------------------------------------------------------------------- 1 | def primes_sieve1(limit): 2 | limitn = limit+1 3 | primes = dict() 4 | for i in range(2, limitn): primes[i] = True 5 | 6 | for i in primes: 7 | factors = range(i,limitn, i) 8 | for f in factors[1:]: 9 | primes[f] = False 10 | return [i for i in primes if primes[i]==True] 11 | n = input() 12 | print primes_sieve1(n) 13 | -------------------------------------------------------------------------------- /codejam-16/qualification round/revenge_of_the_pancakes.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | ifstream inp; 6 | ofstream op; 7 | inp.open("B-large.in"); 8 | op.open("B-large.out"); 9 | int t; 10 | inp>>t; 11 | for(int i=1;i<=t;i++){ 12 | string a; 13 | inp>>a; 14 | int count = 0; 15 | char last = '+'; 16 | for(int j=a.size()-1;j>=0;j--){ 17 | if(a[j] != last){ 18 | last = a[j]; 19 | count++; 20 | } 21 | } 22 | op<<"Case #"< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | ifstream infile; 6 | ofstream outfile; 7 | infile.open("B-large.in"); 8 | outfile.open("B-output.out"); 9 | infile>>t; 10 | for(int j=1;j<=t; j++){ 11 | vector hash(2500,0); 12 | int x; 13 | infile>>x; 14 | for(int k = 1; k<2*x;k++){ 15 | for(int i=0;i>a; 18 | hash[a-1]++; 19 | } 20 | } 21 | vector nos; 22 | for(int i=0;i<2500;i++){ 23 | if(hash[i]%2 != 0) 24 | nos.push_back(i+1); 25 | } 26 | sort(nos.begin(),nos.end()); 27 | outfile<<"Case #"< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | ifstream infile; 6 | ofstream outfile; 7 | infile.open("B-small-attempt0.in"); 8 | outfile.open("B-output.out"); 9 | infile>>t; 10 | cout<<"Got 1"< hash(2500,0); 13 | int x; 14 | infile>>x; 15 | for(int k = 1; k<2*x;k++){ 16 | for(int i=0;i>a; 19 | hash[a-1]++; 20 | } 21 | } 22 | cout<<"Got 1"< nos; 24 | for(int i=0;i<2500;i++){ 25 | if(hash[i]%2 != 0) 26 | nos.push_back(i+1); 27 | } 28 | cout<<"Got 1"< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | ifstream infile; 6 | ofstream outfile; 7 | infile.open("A-large.in"); 8 | outfile.open("A-output.out"); 9 | infile>>t; 10 | for(int j=1;j<=t; j++){ 11 | string x,temp = ""; 12 | infile>>x; 13 | if(x.size() == 1){ 14 | temp = x; 15 | }else{ 16 | if(x[1]>x[0]){ 17 | temp = x.substr(1,1)+x.substr(0,1); 18 | } else{ 19 | temp = x.substr(0,2); 20 | } 21 | for(int i = 2; i < x.size();i++){ 22 | if(x[i]>=temp[0]){ 23 | temp = x.substr(i,1) + temp; 24 | }else{ 25 | temp = temp + x.substr(i,1); 26 | } 27 | } 28 | } 29 | outfile<<"Case #"< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | ifstream infile; 6 | ofstream outfile; 7 | infile.open("B-large.in"); 8 | outfile.open("B-output.out"); 9 | infile>>t; 10 | for(int j=1;j<=t; j++){ 11 | vector hash(2500,0); 12 | int x; 13 | infile>>x; 14 | for(int k = 1; k<2*x;k++){ 15 | for(int i=0;i>a; 18 | hash[a-1]++; 19 | } 20 | } 21 | vector nos; 22 | for(int i=0;i<2500;i++){ 23 | if(hash[i]%2 != 0) 24 | nos.push_back(i+1); 25 | } 26 | sort(nos.begin(),nos.end()); 27 | outfile<<"Case #"< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | ifstream infile; 6 | ofstream outfile; 7 | infile.open("A-large.in"); 8 | outfile.open("A-output.out"); 9 | infile>>t; 10 | for(int j=1;j<=t; j++){ 11 | string x,temp = ""; 12 | infile>>x; 13 | if(x.size() == 1){ 14 | temp = x; 15 | }else{ 16 | if(x[1]>x[0]){ 17 | temp = x.substr(1,1)+x.substr(0,1); 18 | } else{ 19 | temp = x.substr(0,2); 20 | } 21 | for(int i = 2; i < x.size();i++){ 22 | if(x[i]>=temp[0]){ 23 | temp = x.substr(i,1) + temp; 24 | }else{ 25 | temp = temp + x.substr(i,1); 26 | } 27 | } 28 | } 29 | outfile<<"Case #"< 2 | using namespace std; 3 | int main(){ 4 | ifstream infile; 5 | ofstream outfile; 6 | long long t; 7 | infile.open("A-small-attempt0.in"); 8 | outfile.open("A-output.out"); 9 | infile>>t; 10 | for(long long tk=1;tk<=t;tk++){ 11 | long long x; 12 | string s; 13 | infile>>s>>x; 14 | long long ans = 0; 15 | for(long i=0;i s.size()) { 19 | ans = -1; 20 | break; 21 | } 22 | for(long j=i;j 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | ifstream infile; 6 | ofstream outfile; 7 | infile.open("C-large-practice.in"); 8 | outfile.open("C-output.out"); 9 | infile>>t; 10 | for(int tk=1;tk<=t;tk++){ 11 | long long n,k; 12 | infile>>n>>k; 13 | long long x = 1; 14 | long long ans, nov, uv; 15 | if(k == 1) ans = n; 16 | else { 17 | while(x*2+1 < k && x*2+1 > x) x = x*2+1; 18 | k-=x; 19 | n-=x; 20 | x++; 21 | uv = n/x; 22 | if(n %x != 0) uv++; 23 | nov = uv*x - n; 24 | nov = x-nov; 25 | if(k <= nov) ans = uv; 26 | else ans = uv-1; 27 | } 28 | // ans = uv or uv-1; 29 | outfile<<"Case #"<>t; 10 | for(long long tk=1;tk<=t;tk++){ 11 | double p; 12 | infile>>p; 13 | double x,y; 14 | infile>>x>>y; 15 | bool flag = true; 16 | if( p!=0 && ((x-50)*(x-50)+(y-50)*(y-50) <= 50*50) ) 17 | if (atan2(x-50,y-50)-atan2(0,50) <= p*22/350) 18 | flag = false; 19 | outfile<<"Case #"< 2 | #define ll long long 3 | #define pb push_back 4 | #define mp make_pair 5 | #define vll vector 6 | #define all(S) S.begin(), S.end() 7 | #define S(a) scanf("%lld", &a) 8 | using namespace std; 9 | int main(){ 10 | ifstream infile; 11 | ofstream outfile; 12 | infile.open("interception.txt"); 13 | outfile.open("output.txt"); 14 | long t; 15 | infile>>t; 16 | for (long t1 = 1; t1 <= t; t1++) { 17 | long n; 18 | infile >> n; 19 | long long x; 20 | for (long i = 0; i <= n; i++) { 21 | infile >> x; 22 | } 23 | outfile << "Case #" << t1 << ":"; 24 | if (n&1) 25 | outfile << " 1\n0.0\n"; 26 | else 27 | outfile << " 0\n"; 28 | } 29 | infile.close(); 30 | outfile.close(); 31 | return 0; 32 | } -------------------------------------------------------------------------------- /hackerearth/codathon18-nitbhopal/day-1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define pb push_back 4 | #define mp make_pair 5 | #define vll vector 6 | #define all(S) S.begin(), S.end() 7 | #define S(a) scanf("%lld", &a) 8 | using namespace std; 9 | int main(){ 10 | long t; 11 | scanf("%ld", &t); 12 | while(t--) { 13 | long n; 14 | scanf("%ld", &n); 15 | vector arr(n); 16 | for(long i=0;i 2 | #define ll long long 3 | #define pb push_back 4 | #define mp make_pair 5 | #define vll vector 6 | #define all(S) S.begin(), S.end() 7 | #define S(a) scanf("%lld", &a) 8 | using namespace std; 9 | long check (string a, string b) { 10 | vector ar(26, 0), br(26, 0); 11 | for(long i=0;i>x; 29 | for(long i=0;i<4;i++) a[i] = ""; 30 | long fac = x.size()/4; 31 | for(long i=0;i 2 | #define ll long long 3 | #define pb push_back 4 | #define mp make_pair 5 | #define vll vector 6 | #define all(S) S.begin(), S.end() 7 | #define S(a) scanf("%lld", &a) 8 | using namespace std; 9 | int main(){ 10 | long t; 11 | scanf("%ld", &t); 12 | while(t--) { 13 | ll n, m, x, y; 14 | S(n); 15 | S(m); 16 | S(x); 17 | S(y); 18 | ll ans = min(x-1, y-1); 19 | ans = min(ans, min(n-x, m-y)); 20 | ans--; 21 | if(ans >= 4) 22 | printf("Shivam\n"); 23 | else 24 | printf("Mavis\n"); 25 | } 26 | return 0; 27 | } -------------------------------------------------------------------------------- /hackerearth/lets-code-20/coin-problem.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define pb push_back 4 | #define mp make_pair 5 | #define vll vector 6 | #define all(S) S.begin(), S.end() 7 | #define S(a) scanf("%lld", &a) 8 | using namespace std; 9 | ll mod = 1E9 + 7; 10 | int main(){ 11 | vll temp(1000005, 0); 12 | vector ans(3, temp); 13 | ans[0][1] = 1; 14 | ans[1][1] = 1; 15 | for(long i=2;i 2 | #define ll long long 3 | #define pb push_back 4 | #define mp make_pair 5 | #define vll vector 6 | #define all(S) S.begin(), S.end() 7 | #define S(a) scanf("%lld", &a) 8 | using namespace std; 9 | vector arr; 10 | ll find_mid(ll a, ll b){ 11 | // cout< 2 | using namespace std; 3 | set s; 4 | void func(string n, stack c, string old) 5 | { 6 | if(!c.empty()) 7 | { 8 | string n1 = n; 9 | n1.append(1,c.top()); 10 | stack c1 = c; 11 | c1.pop(); 12 | func(n1,c1,old); 13 | } 14 | if(old.length()!=0) 15 | { 16 | c.push(old[0]); 17 | old.erase(old.begin()); 18 | func(n,c,old); 19 | } 20 | if(c.empty()&&old.length()==0) 21 | { 22 | s.insert(n); 23 | } 24 | return; 25 | } 26 | int main() 27 | { 28 | string a; 29 | cin>>a; 30 | stack c; 31 | string n; 32 | func(n,c,a); 33 | set::iterator it; 34 | int i=1; 35 | for (it=s.begin(); it!=s.end(); ++i,++it) 36 | cout< 2 | using namespace std; 3 | int main(){ 4 | 5 | long long t; 6 | cin>>t; 7 | t--; 8 | long long n = t/3; 9 | n++; 10 | n = log2(n); 11 | // cout< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | int r1 = 0,r2 = 0; 8 | long ans = 0; 9 | int m,n; 10 | cin>>m>>n; 11 | for(int i = 0;i>a>>b; 14 | if(r1==0){ 15 | r1 = b; 16 | ans += abs(b-a); 17 | }else{ 18 | if(a == r1){ 19 | r1 = b; 20 | ans += abs(b-a); 21 | }else if(r2 == 0){ 22 | r2 = b; 23 | ans += abs(b-a); 24 | }else{ 25 | if(abs(r1 - a) 2 | using namespace std; 3 | int main() { 4 | long t; 5 | cin>>t; 6 | while(t--) { 7 | long n; 8 | scanf("%ld",&n); 9 | long others = 0,minus=0,zeros =0,ones=0; 10 | long long x; 11 | for(long i=0;i1)||(others==1)&&(minus>0)) 23 | printf("no\n"); 24 | else { 25 | if(minus>1 && ones==0){ 26 | printf("no\n"); 27 | } else 28 | printf("yes\n"); 29 | } 30 | } 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /icpc16/d.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | vector > divisor(750001); 4 | void pre() { 5 | for(long i=1; i<=750000; i++) { 6 | long j = i; 7 | while( j <= 750000 ) { 8 | divisor[j].push_back( i ); 9 | j += i; 10 | } 11 | } 12 | } 13 | long long mod = 1000000007; 14 | int main() { 15 | pre(); 16 | int t; 17 | cin>>t; 18 | while(t--) { 19 | long n; 20 | cin>>n; 21 | vector a(n); 22 | vector dp(750001,0); 23 | long ans = 0; 24 | for(long i=0;i::iterator it,divisorit; 30 | for(it = a.begin();it!=a.end();it++) { 31 | long temp = 0; 32 | for(divisorit = divisor[*it].begin();divisorit != divisor[*it].end();divisorit++) { 33 | temp += dp[*divisorit]; 34 | temp %= mod; 35 | } 36 | dp[*it] = temp; 37 | // cout<<*it<<" "< 2 | using namespace std; 3 | int main() { 4 | int t; 5 | cin>>t; 6 | while(t--) { 7 | int n,m,d,D; 8 | cin>>n>>m>>d>>D; 9 | if(m < n*d || m > n*D) 10 | cout<<-1< 2 | using namespace std; 3 | int main() { 4 | 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /kickstart-17/round c/A-small-attempt0.in: -------------------------------------------------------------------------------- 1 | 100 2 | OMDU 3 | BCB 4 | FWDT 5 | MI 6 | PSMD 7 | ABWS 8 | ASCB 9 | DZEU 10 | RKOF 11 | BDB 12 | UDPY 13 | KATT 14 | LYVM 15 | QK 16 | FRFC 17 | SQJC 18 | KAXE 19 | UGU 20 | HQGU 21 | AA 22 | IT 23 | SGFY 24 | PESS 25 | ULCO 26 | ALGH 27 | WBTL 28 | CPBU 29 | DD 30 | IV 31 | AAZZ 32 | FEF 33 | MBKV 34 | HP 35 | MZYT 36 | OU 37 | YFPS 38 | OCFW 39 | KIK 40 | ZYZ 41 | VMCA 42 | MBLT 43 | SNKM 44 | CPWJ 45 | ZZTL 46 | RDOC 47 | CP 48 | SS 49 | VD 50 | HAFZ 51 | KJXN 52 | VFV 53 | EAVK 54 | KZ 55 | EKZS 56 | VLVJ 57 | FO 58 | DLYQ 59 | HU 60 | FYOB 61 | XFPG 62 | AAAA 63 | VXCY 64 | NKNU 65 | EUTB 66 | JQSI 67 | LZXP 68 | AAA 69 | AFA 70 | JJ 71 | BFYW 72 | PL 73 | HPBV 74 | LAVM 75 | GUNJ 76 | JVNN 77 | ISWW 78 | JCBA 79 | BH 80 | YA 81 | UU 82 | FQVH 83 | RZ 84 | ZT 85 | ORKT 86 | DBRH 87 | HIH 88 | VBNS 89 | TNTF 90 | JUTF 91 | HPWD 92 | DCJW 93 | PTIV 94 | ZN 95 | CATB 96 | VQVU 97 | OXMH 98 | QQ 99 | APA 100 | TP 101 | YYWM 102 | -------------------------------------------------------------------------------- /kickstart-17/round c/C-small-attempt0.in: -------------------------------------------------------------------------------- 1 | 3 2 | 1 2 3 | TF 4 | FF 5 | 1 6 | 1 3 7 | TTT 8 | TTF 9 | 0 10 | 2 3 11 | TTF 12 | FTF 13 | TTT 14 | 1 2 15 | -------------------------------------------------------------------------------- /kickstart-17/round f/A-small-attempt0.in: -------------------------------------------------------------------------------- 1 | 32 2 | 4 3 | 2 4 1 3 4 | 4 5 | 2 1 3 4 6 | 3 7 | 3 1 2 8 | 4 9 | 1 4 3 2 10 | 4 11 | 3 4 1 2 12 | 4 13 | 4 2 1 3 14 | 4 15 | 4 1 2 3 16 | 4 17 | 1 4 2 3 18 | 3 19 | 1 2 3 20 | 4 21 | 2 3 4 1 22 | 4 23 | 4 3 1 2 24 | 4 25 | 1 3 2 4 26 | 4 27 | 4 1 3 2 28 | 2 29 | 1 2 30 | 4 31 | 3 4 2 1 32 | 4 33 | 2 3 1 4 34 | 3 35 | 2 1 3 36 | 4 37 | 2 1 4 3 38 | 4 39 | 4 3 2 1 40 | 3 41 | 3 2 1 42 | 4 43 | 1 2 4 3 44 | 2 45 | 2 1 46 | 3 47 | 1 3 2 48 | 3 49 | 2 3 1 50 | 4 51 | 3 2 1 4 52 | 4 53 | 3 1 4 2 54 | 4 55 | 3 2 4 1 56 | 4 57 | 2 4 3 1 58 | 4 59 | 1 2 3 4 60 | 4 61 | 1 3 4 2 62 | 4 63 | 4 2 3 1 64 | 4 65 | 3 1 2 4 66 | -------------------------------------------------------------------------------- /kickstart-17/round f/B-large.in: -------------------------------------------------------------------------------- 1 | 100 2 | 3 3 | 4 4 | 5 5 | 6196 6 | 3200 7 | 7929 8 | 534 9 | 6403 10 | 610 11 | 5914 12 | 2297 13 | 5810 14 | 9044 15 | 1906 16 | 4681 17 | 5173 18 | 4569 19 | 7610 20 | 6960 21 | 8201 22 | 9249 23 | 466 24 | 486 25 | 6293 26 | 4308 27 | 8679 28 | 5839 29 | 10000 30 | 1904 31 | 6934 32 | 6538 33 | 6582 34 | 1274 35 | 8386 36 | 5640 37 | 2652 38 | 9923 39 | 1336 40 | 9999 41 | 4311 42 | 8800 43 | 6959 44 | 2989 45 | 4138 46 | 8529 47 | 7186 48 | 2957 49 | 9159 50 | 7210 51 | 6555 52 | 2058 53 | 2593 54 | 3760 55 | 2839 56 | 1554 57 | 732 58 | 4101 59 | 1068 60 | 4403 61 | 9346 62 | 303 63 | 182 64 | 5068 65 | 9611 66 | 9604 67 | 1099 68 | 6253 69 | 1 70 | 5213 71 | 7361 72 | 2123 73 | 1531 74 | 6738 75 | 5498 76 | 7141 77 | 8299 78 | 5305 79 | 4914 80 | 6043 81 | 4365 82 | 9521 83 | 1729 84 | 8079 85 | 5924 86 | 1992 87 | 4009 88 | 8640 89 | 7300 90 | 1746 91 | 6040 92 | 7512 93 | 5058 94 | 3626 95 | 3894 96 | 974 97 | 9716 98 | 1889 99 | 5880 100 | 1960 101 | 5624 102 | -------------------------------------------------------------------------------- /kickstart-17/round f/B-small-attempt0.in: -------------------------------------------------------------------------------- 1 | 50 2 | 3 3 | 4 4 | 5 5 | 17 6 | 22 7 | 46 8 | 26 9 | 36 10 | 7 11 | 44 12 | 41 13 | 50 14 | 42 15 | 2 16 | 23 17 | 15 18 | 28 19 | 37 20 | 45 21 | 43 22 | 18 23 | 27 24 | 1 25 | 9 26 | 11 27 | 35 28 | 19 29 | 39 30 | 38 31 | 6 32 | 31 33 | 48 34 | 32 35 | 24 36 | 47 37 | 20 38 | 33 39 | 40 40 | 12 41 | 49 42 | 13 43 | 30 44 | 29 45 | 25 46 | 21 47 | 8 48 | 10 49 | 34 50 | 14 51 | 16 52 | -------------------------------------------------------------------------------- /kickstart-17/round f/B-small-attempt1.in: -------------------------------------------------------------------------------- 1 | 50 2 | 3 3 | 4 4 | 5 5 | 14 6 | 33 7 | 37 8 | 50 9 | 21 10 | 29 11 | 41 12 | 32 13 | 26 14 | 22 15 | 12 16 | 36 17 | 23 18 | 7 19 | 20 20 | 1 21 | 35 22 | 27 23 | 34 24 | 8 25 | 30 26 | 28 27 | 24 28 | 48 29 | 19 30 | 11 31 | 10 32 | 18 33 | 15 34 | 25 35 | 13 36 | 6 37 | 2 38 | 49 39 | 47 40 | 31 41 | 9 42 | 44 43 | 39 44 | 42 45 | 43 46 | 40 47 | 17 48 | 16 49 | 45 50 | 38 51 | 46 52 | -------------------------------------------------------------------------------- /kickstart-17/round f/B-small.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(){ 4 | ifstream infile; 5 | ofstream outfile; 6 | vector memo(1,0); 7 | for(long i=1;i<100010;i++){ 8 | int ans = 1+memo[i-1]; 9 | for(long j=1;j*j <= i; j++){ 10 | ans = min(ans, 1 + memo[i-j*j]); 11 | } 12 | memo.push_back(ans); 13 | } 14 | long long t; 15 | infile.open("B-large.in"); 16 | outfile.open("B-output.out"); 17 | infile>>t; 18 | for(long long tk=1;tk<=t;tk++){ 19 | long long ans = 0; 20 | long n; 21 | infile>>n; 22 | // cout< 2 | using namespace std; 3 | int main(){ 4 | int t = 100; 5 | ofstream outfile; 6 | outfile.open("D-small-attempt0.in"); 7 | outfile< 4 | #define ll long long 5 | #define vll vector 6 | using namespace std; 7 | vector getDivisors(long n){ 8 | vector divisors(n+1); 9 | divisors[0].push_back(-1); 10 | for(long i=1;i<=n;i++){ 11 | for(long j=i;j<=n;j+=i){ 12 | divisors[j].push_back(i); 13 | } 14 | } 15 | return divisors; 16 | } 17 | int main(){ 18 | long n; 19 | cin>>n; 20 | vector divisors = getDivisors(n); 21 | for(long i=1;i<=n;i++){ 22 | for(long j=0;j 2 | using namespace std; 3 | void enumerate_subsequences (vector arr, int i, vector so_far) { 4 | if(i == arr.size()){ 5 | for(long j=0;j>n; 18 | vector arr(n); 19 | for(long i=0;i>arr[i]; 21 | } 22 | vector emptyarr; 23 | enumerate_subsequences(arr,0,emptyarr); 24 | return 0; 25 | } -------------------------------------------------------------------------------- /programming templates/euler_totient.cpp: -------------------------------------------------------------------------------- 1 | // Program to find the euler totient of a number 2 | #include 3 | using namespace std; 4 | typedef long long ll; 5 | 6 | ll phi(ll n) { 7 | ll result = n; 8 | vector seive(sqrt(n)+1,true); 9 | for (ll p=2; p*p<=n; ++p) { 10 | if (seive[p]) { 11 | if (n % p == 0){ 12 | result -= result/p; 13 | while (n%p == 0) 14 | n /= p; 15 | } 16 | for (ll j = 2*p; j*j < n; j+= p) { 17 | seive[j] = false; 18 | } 19 | } 20 | } 21 | if (n > 1) 22 | result -= result/n; 23 | return (int)result; 24 | } 25 | int main() { 26 | long long n; 27 | // cin>>n; 28 | for(n=1;n<11;n++) 29 | cout< 2 | using namespace std; 3 | vector factorial; 4 | long long mod; 5 | long long findfac(long long a){ 6 | if(factorial.size() > a) 7 | return factorial[a]; 8 | if(factorial.size() == 0) 9 | factorial.push_back(1); 10 | for(long long i = factorial.size(); i <= a;i++) 11 | factorial.push_back((factorial[i-1]*i)%mod); 12 | return factorial[a]; 13 | } 14 | int main(){ 15 | cout<<"Enter mod value: "; 16 | cin>>mod; 17 | while(true){ 18 | cout<<"Enter value to find factorial \% mod: "; 19 | long long x; 20 | cin>>x; 21 | cout< 2 | #define ll long long 3 | #define vll vector 4 | #define vbl vector 5 | using namespace std; 6 | int main(){ 7 | long n; 8 | cin>>n; 9 | vll x(n); 10 | ll sum = 0; 11 | for(long i=0;i>x[i]; 13 | sum += x[i]; 14 | } 15 | sum++; 16 | sum /= 2; 17 | vector dp(sum+1,0); 18 | for(long i=1;i=0 && dp[i-x[j-1]]!=-1 && j-1>=dp[i-x[j-1]]){ 22 | dp[i] = j; 23 | break; 24 | } 25 | } 26 | } 27 | for(long i=0;i 4 | using namespace std; 5 | int ffd(double x){ 6 | // find first digit 7 | return pow(10,x-floor(x)); 8 | } 9 | double getLog(vector arr){ 10 | double log_value = 0; 11 | for(long i=0;i>n; 19 | vector arr(n); 20 | for(long i=0;i>arr[i]; 22 | cout< 2 | using namespace std; 3 | vector > getMatrixRepresentation(long n, long m){ 4 | //n - no of nodes, m - no of edges 5 | vector temp(n,false); 6 | vector > mat(n,temp); 7 | while(m--){ 8 | long a,b; 9 | cin>>a>>b; 10 | mat[a][b] = true; 11 | mat[b][a] = true; 12 | } 13 | return mat; 14 | } 15 | void showMatrixRepresentation(vector > graph){ 16 | for(long i=0;i>n>>m; 29 | vector > graph = getMatrixRepresentation(n,m); 30 | showMatrixRepresentation(graph); 31 | return 0; 32 | } -------------------------------------------------------------------------------- /programming templates/kadane.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | long long max_sum_subarray(vector arr){ 4 | long long ans = 0, current_max = 0; 5 | for(long i=0;i ans) 8 | ans = current_max; 9 | if(current_max < 0) 10 | current_max = 0; 11 | } 12 | return ans; 13 | } 14 | int main() { 15 | vector arr; 16 | arr.push_back(-2); 17 | arr.push_back(-3); 18 | arr.push_back(4); 19 | arr.push_back(-1); 20 | arr.push_back(-2); 21 | arr.push_back(1); 22 | arr.push_back(5); 23 | arr.push_back(-3); 24 | cout <<"Max sum of a contiguous sub array is "< 2 | using namespace std; 3 | int main() 4 | { 5 | 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /programming templates/matrixTranspose.cpp: -------------------------------------------------------------------------------- 1 | // Transpose a given matrix 2 | #include 3 | #define ll long long 4 | using namespace std; 5 | vector > matrixTranspose(vector > arr){ 6 | vector temp(arr.size(),0); 7 | vector > result(arr[0].size(),temp); 8 | for(int i=0;i>n>>m; 17 | vector temp(m,0); 18 | vector > arr(n,temp); 19 | for(int i=0;i>arr[i][j]; 22 | } 23 | arr = matrixTranspose(arr); 24 | for(int i=0;i 2 | #define ll long long 3 | #define vll vector 4 | #define vbl vector 5 | using namespace std; 6 | int main(){ 7 | long n; 8 | cin>>n; 9 | vll x(n); 10 | ll sum = 0; 11 | for(long i=0;i>x[i]; 13 | sum += x[i]; 14 | } 15 | sum++; 16 | sum /= 2; 17 | vbl temp(n+1,true); 18 | vector dp(sum+1,temp); 19 | for(long i=1;i=0 && dp[i-x[j-1]][j-1]) 23 | dp[i][j] = true; 24 | else 25 | dp[i][j] = false; 26 | } 27 | } 28 | for(long i=0;i 2 | using namespace std; 3 | class BuildingStrings { 4 | public: 5 | vector findAny(int k) { 6 | vector ans; 7 | if(k <= 50) { 8 | string a(k,'a'); 9 | ans.push_back(a); 10 | return ans; 11 | } else { 12 | int x = 26; 13 | while(50 * x <= k) { 14 | string a(50,'a'); 15 | for(int i=0;i k ) { 22 | x--; 23 | } 24 | if(x != 0) { 25 | string a(50,'a'); 26 | for(int i=0;i>y; 44 | vector x = bs.findAny(y); 45 | for(int i=0;i 2 | using namespace std; 3 | double nCk (double n, int k){ 4 | double ans = 1.0; 5 | for(int i=1;i<=k;i++){ 6 | ans *= n--; 7 | ans /= i; 8 | if(i != 1) ans /= 365.0; 9 | } 10 | return ans; 11 | } 12 | int main(){ 13 | int arr[] = {0,1,23, 88, 187, 313, 460, 623, 798, 985, 1181, 1385, 1596, 1813, 2035, 2263, 2494, 2730, 2970, 3213, 3459}; 14 | for(int i=0;i<=20;i++) cout< 2 | using namespace std; 3 | int getCount(string a, string b) { 4 | sort(a.begin(),a.end()); 5 | sort(b.begin(),b.end()); 6 | int ans = 0; 7 | int i = 0, j = 0; 8 | while(i < a.size()){ 9 | if(a[i] <= b[j]){ 10 | ans += b[j]-a[i]; 11 | j++; 12 | } else { 13 | if(j < a.size()) { 14 | b += b[j]; 15 | j++; 16 | i--; 17 | } else { 18 | ans += 26 - a[i] + b[j]; 19 | j++; 20 | } 21 | } 22 | i++; 23 | } 24 | return ans; 25 | } 26 | int main(){ 27 | 28 | while(true){ 29 | string a, b; 30 | cin>>a>>b; 31 | sort(a.begin(),a.end()); 32 | sort(b.begin(),b.end()); 33 | int count = 2000; 34 | for(int i=0;i= a[j]) { 38 | lcount += (b[k]-a[j]); 39 | } else { 40 | lcount += 26 - a[j] + b[k]; 41 | } 42 | } 43 | count = min(count, lcount); 44 | } 45 | cout<