├── .gitattributes ├── .gitignore ├── README.md ├── UVA ├── uva10450_world_cup_noise_combinatorics.cpp ├── uva10541_stripe_combinatorics.py ├── uva10738_riemann_vs_mertens.cpp ├── uva10755.cpp ├── uva10943_DP_coinchangeish.cpp ├── uva763_fibinary.cpp ├── uva763_fibinary.go ├── uva763_fibinary_string.cpp ├── uva991_safe_salutations_good_prob.py ├── uva_10541_stripe_combinatorics.cpp └── uva_11396_claw_decomposition.cpp ├── acm-practice ├── 2014 ICPC Central Europe Regional Contest [Practice] │ ├── Good_Morning.cpp │ └── Sums.cpp ├── 2016-04-25 │ └── 144D.cpp ├── 2016-09-27 │ └── two_characters.py ├── 2016-09-29 │ ├── bear_and_steady_gene.cpp │ ├── making_anagrams.cpp │ └── palindrome_index.cpp ├── 2017-01-10 │ └── palindrome.cpp ├── 2017-01-24 │ ├── nimble_game.cpp │ └── nimble_game.py ├── 2017-01-26 │ ├── back_to_the_origin.py │ └── matchstick_warehouse_thief.py ├── 2017-01-31 │ ├── README.md │ ├── a.cpp │ └── b.cpp ├── 2017-02-14 │ ├── hackerrank_in_a_string.cpp │ ├── knightL_on_a_chessboard.cpp │ └── readme.md ├── 2017-04-18 │ └── A_py_heap.py ├── 2017-04-27 │ └── tree_diameter_longest_path.py ├── 2017-05-11 │ ├── flatland_space_stations.py │ └── greedy_florist.py ├── 2017-10-26 │ ├── A_kitten_tree.py │ ├── B_gold.py │ ├── C_weak.py │ ├── D_suspension_binary_search.py │ └── E_euclid_tsp.py ├── 2017-11-30 │ ├── A.cpp │ ├── B.py │ └── c.cpp ├── 2018-01-09 │ └── A_forwarding_emails.py ├── 2019-01-13-internal-test │ ├── acm_contest_scoring.py │ ├── beatspread.py │ ├── closest_sums.py │ ├── exact_change_2.py │ └── god_save_the_ith_queen.py ├── 2019-01-29 │ ├── A_arithmetic.py │ ├── B_code_cleanups.py │ ├── C_bing_it_on.py │ ├── D_the_trip.py │ └── readme.md ├── 2019-02-19 │ ├── a_3d_printer.py │ ├── c_classpicture.py │ ├── d_islands.py │ ├── e.cpp │ ├── e_ecoins.py │ └── readme.md ├── CPP_Practice │ ├── CPP_Practice.sln │ └── CPP_Practice │ │ ├── CPP_Practice.vcxproj │ │ ├── CPP_Practice.vcxproj.filters │ │ ├── Change-By-Mass.cpp │ │ ├── LIS.h │ │ ├── LIS2.h │ │ ├── collatz.cpp │ │ ├── collatz.h │ │ ├── main.cpp │ │ └── mit.h ├── Change-By-Mass.py ├── ICPC-EU-Regional │ ├── boulevard.py │ ├── boulevard_commented.py │ ├── cleanerrobot.py │ ├── emailaliases.py │ ├── layercake.cpp │ └── lottery.py ├── TRAINING │ ├── 2016-Fall │ │ ├── binary_search.cpp │ │ ├── binary_search_sample.txt │ │ ├── recursive-backtracking-uva-11195.cpp │ │ └── recursive-backtracking-uva-11195_sample.txt │ └── 2017-Winter │ │ └── 2017-01-28 segment trees │ │ ├── Xenia_and_bit_operations_naive.cpp │ │ └── knight_tournament.cpp ├── equalsRange.py ├── jan28 │ ├── .classpath │ ├── .gitignore │ ├── .project │ └── src │ │ └── findgivensum │ │ ├── Main.java │ │ └── Tree.java ├── markovfrogger.py └── quasibinary.cpp ├── codechef └── snackdown_2017 │ ├── A_snakes_mongooses_ultimate_election.py │ ├── B.py │ ├── C.py │ └── Qualifier │ └── TEMPLELA.py ├── codeforces ├── Good_Bye_2017 │ ├── a.py │ ├── b.py │ ├── c.cpp │ └── c_hack.cpp ├── Hello_2018 │ ├── A.cpp │ ├── A.py │ ├── B.cpp │ ├── C.cpp │ ├── D.cpp │ └── hack_a.cpp ├── april_fools_2017 │ └── A.py ├── april_fools_2021 │ ├── I_explore.txt │ ├── a.py │ ├── b.py │ ├── c.py │ ├── e.py │ └── f.py ├── april_fools_2022 │ ├── a.py │ ├── b.py │ └── b.txt ├── codeton_round3_2022 │ ├── a.py │ ├── b.py │ ├── c.cpp │ ├── c.py │ └── d.cpp ├── codeton_round5_2023 │ ├── a.py │ ├── b.py │ ├── c.py │ └── e.py ├── croc_elimination │ └── amity_assessment.cpp ├── croc_qual │ ├── hostname_aliases.cpp │ ├── parliament.cpp │ └── processing_queries.cpp ├── deltix_spring_2021 │ ├── a.py │ ├── b.py │ ├── c.py │ ├── e.py │ └── e_brute.py ├── edu_round10 │ ├── foe_pairs.cpp │ └── zsort.cpp ├── edu_round105 │ ├── a.py │ ├── b.py │ ├── c.py │ └── d.py ├── edu_round106 │ ├── a.py │ ├── b.py │ ├── c.py │ └── d.py ├── edu_round108 │ ├── a.py │ ├── b.py │ ├── c.cpp │ ├── d.cpp │ └── e.py ├── edu_round111 │ ├── a.py │ ├── b.py │ ├── c.py │ └── d.py ├── edu_round112 │ ├── a.py │ ├── b.py │ ├── c.py │ ├── d.cpp │ └── d.py ├── edu_round123 │ ├── a.py │ ├── b.py │ ├── c.py │ ├── d.py │ └── e.py ├── edu_round128 │ ├── a.py │ ├── b.py │ ├── c │ ├── c.go │ ├── d │ └── d.go ├── edu_round145 │ ├── a.py │ ├── b.py │ ├── c.py │ └── d.py ├── edu_round146 │ ├── a.py │ ├── b.py │ └── c.py ├── edu_round150 │ ├── a.py │ ├── b.py │ ├── c.py │ └── d.py ├── edu_round169 │ ├── a.py │ ├── b.py │ ├── c.py │ ├── d.py │ └── e.py ├── edu_round32 │ ├── A.py │ ├── B.cpp │ └── C.py ├── edu_round42 │ ├── A.py │ ├── B.py │ ├── C.py │ └── D.cpp ├── edu_round51 │ ├── C.py │ ├── a.py │ ├── b.py │ └── d.cpp ├── edu_round93 │ ├── a.py │ ├── b.py │ ├── c.py │ ├── d.go │ ├── d.py │ └── readme.md ├── edu_round94 │ ├── a.py │ ├── b.py │ ├── c.go │ ├── c.py │ ├── d.cpp │ └── d_broken.cpp ├── global_round10 │ ├── a.py │ ├── b.py │ ├── c.py │ ├── d.go │ ├── d.py │ ├── e.py │ └── readme.md ├── global_round14 │ ├── a.py │ ├── b.py │ ├── c.py │ ├── d.cpp │ └── e.py ├── global_round7 │ ├── C_permutation_partitions.cpp │ ├── D_prefix_suffix_palindrome.cpp │ ├── a_bad_ugly_numbers.py │ └── b_maximums.py ├── indiahacks │ ├── bear_and_compression.cpp │ ├── bear_and_three_balls.cpp │ └── bear_and_up_down.cpp ├── marathon_1 │ ├── confidence.py │ ├── evolution_clean.py │ └── evolution_notebook.py ├── round344 │ ├── fuck.cpp │ ├── fuck2.cpp │ ├── interview.cpp │ ├── printer.cpp │ └── printer_naive.cpp ├── round345 │ ├── image_preview.cpp │ ├── joysticks.cpp │ ├── paintings.cpp │ ├── table_compression.cpp │ └── watchmen.cpp ├── round346 │ ├── bicycle_race.cpp │ ├── new_reform.cpp │ ├── qualifying_contest.cpp │ ├── round_house.cpp │ └── toys.cpp ├── round350 │ ├── A.cpp │ ├── B.cpp │ ├── D.cpp │ ├── E.cpp │ ├── E_try.cpp │ └── c.cpp ├── round355 │ ├── A_vanya_and_fence.cpp │ ├── B_vanya_and_potato.cpp │ └── C_vanya_and_label.cpp ├── round358 │ ├── A_alyona_and_numbers.cpp │ ├── B_alyona_and_mex.cpp │ └── C_Alyona_and_the_tree.cpp ├── round366 │ ├── A_Hulk.cpp │ ├── B_Spiderman.cpp │ └── C_Thor.cpp ├── round375 │ ├── a_new_year_meeting_friends.cpp │ ├── b_sample.txt │ ├── b_text.cpp │ ├── c_radio.cpp │ ├── d_lakes.cpp │ ├── d_sample.txt │ ├── e_one_way_reform.cpp │ └── e_sample.txt ├── round376 │ ├── A_museum.cpp │ ├── B_coupons.cpp │ ├── C_sample.txt │ ├── C_socks.cpp │ ├── D_heiroglyphics.cpp │ ├── D_sample.txt │ ├── E_funny_game.cpp │ └── F_videocards.cpp ├── round378 │ ├── A_grasshopper.cpp │ ├── B_parade.cpp │ ├── C_epidemic_in_monstropolis.cpp │ ├── D_kostya_the_sculptor.cpp │ └── F_drivers_dissatisfaction.cpp ├── round379 │ ├── A.cpp │ ├── B_digits.cpp │ ├── C_potions.cpp │ ├── D_chess.cpp │ └── E_treeee.cpp ├── round380 │ ├── A.cpp │ ├── A.txt │ ├── B_spotlight.cpp │ └── C.cpp ├── round383 │ ├── A.cpp │ ├── B_xor_sum.cpp │ ├── C_permutation_cycles.cpp │ └── D_knapsack_CC.cpp ├── round384 │ ├── a.cpp │ ├── b.cpp │ └── d.cpp ├── round385 │ ├── A.cpp │ ├── A.py │ ├── B.cpp │ ├── C.cpp │ └── D.py ├── round387 │ ├── a.py │ ├── b.py │ ├── c.cpp │ ├── c.py │ └── d.cpp ├── round391 │ ├── A.py │ ├── B.cpp │ ├── Bhack.py │ ├── C.cpp │ └── D.cpp ├── round392 │ ├── a.cpp │ ├── b.cpp │ ├── c.cpp │ └── d.cpp ├── round394 │ ├── a.py │ ├── b.cpp │ ├── c.cpp │ └── d.cpp ├── round397 │ ├── a.cpp │ └── e.cpp ├── round400 │ ├── A.py │ ├── B.cpp │ ├── C.cpp │ └── D.cpp ├── round404 │ └── d.cpp ├── round408 │ ├── a.py │ ├── b.cpp │ └── c.cpp ├── round410 │ ├── a.py │ ├── b.py │ ├── c.cpp │ └── c.py ├── round411 │ ├── a.py │ └── b.py ├── round413 │ ├── a.py │ ├── b.cpp │ ├── c.cpp │ └── c.in2 ├── round426 │ ├── A.py │ ├── B.cpp │ └── C.cpp ├── round435 │ ├── a.py │ ├── b.py │ ├── c.py │ └── d_playground.py ├── round439 │ ├── C_2d_segment_tree.cpp │ ├── a.py │ └── b.py ├── round444 │ ├── a.py │ ├── b.py │ ├── cube.cpp │ └── d.cpp ├── round449 │ ├── a.py │ ├── b.cpp │ ├── c.cpp │ ├── c_test.py │ └── d.cpp ├── round451 │ ├── a.py │ ├── b.cpp │ ├── b.py │ ├── c.py │ ├── d.cpp │ ├── e.cpp │ └── test.cpp ├── round452 │ ├── a.py │ ├── b.py │ ├── c.py │ ├── d.cpp │ └── e.py ├── round457 │ ├── a.py │ ├── b.cpp │ └── c.cpp ├── round458 │ ├── a.py │ ├── ahacktest.cpp │ ├── b.py │ └── c.cpp ├── round469 │ ├── a.py │ ├── b.cpp │ ├── bsample.py │ ├── c.cpp │ ├── d.cpp │ ├── e_SCC_tarjan.cpp │ └── readme.md ├── round476 │ ├── A.py │ ├── B_battleship.py │ ├── C_greedy_arkady.py │ └── D_frogs_stones.py ├── round505 │ ├── A.py │ └── B_weakened_common_divisor.cpp ├── round508 │ ├── B.py │ ├── C.py │ ├── D.py │ └── a.py ├── round513 │ ├── a.py │ ├── b.py │ ├── c.cpp │ └── e.cpp ├── round608 │ ├── a.py │ ├── b.py │ ├── c.py │ └── e.py ├── round612 │ ├── A.py │ ├── A_angry_students.py │ ├── B_hyperset.py │ ├── C.py │ └── C_garland.py ├── round665 │ ├── a.py │ ├── b.py │ ├── c.go │ ├── d.go │ └── readme.md ├── round666 │ ├── a.py │ ├── b.py │ └── c.py ├── round670 │ ├── a.py │ ├── b.cpp │ └── c.cpp ├── round671 │ ├── a.py │ ├── b.py │ ├── c.cpp │ ├── d.cpp │ ├── d_easy.cpp │ └── e.cpp ├── round675 │ ├── a.py │ ├── b.py │ ├── c.cpp │ ├── e.cpp │ └── e.py ├── round687 │ ├── a.py │ ├── b.cpp │ ├── c.cpp │ └── d.cpp ├── round705 │ ├── a.py │ ├── b.py │ └── c.py ├── round708 │ ├── a.py │ ├── c.py │ └── c_gen.py ├── round711 │ ├── a.py │ ├── b.py │ ├── c.py │ ├── d.cpp │ └── e.py ├── round712 │ ├── a.py │ ├── b.py │ ├── c.py │ └── readme.md ├── round716 │ ├── a.py │ ├── b.py │ ├── c.py │ └── d.cpp ├── round717 │ ├── a.py │ ├── b.py │ ├── c.py │ └── d.cpp ├── round718 │ ├── a.py │ ├── b.py │ ├── c.py │ └── d.cpp ├── round720 │ ├── a.py │ ├── b.py │ └── c.py ├── round721 │ ├── a.py │ ├── b.cpp │ └── c.py ├── round726 │ ├── a.py │ ├── b.py │ ├── c.py │ ├── d.py │ ├── ebig.py │ ├── ebiggen.py │ └── esmall.py ├── round728 │ ├── a.py │ ├── b.py │ ├── c.py │ └── d.py ├── round730 │ ├── a.py │ ├── b.py │ ├── c.cpp │ ├── c.py │ └── readme.md ├── round741 │ ├── a.py │ └── b.py ├── round774 │ ├── a.py │ ├── b.py │ ├── c.py │ └── d.py ├── round782 │ ├── a.py │ ├── b │ ├── b.go │ ├── c │ ├── c.go │ └── d.go ├── round788 │ ├── a.py │ ├── b │ ├── b.go │ ├── b.py │ ├── c │ ├── c.go │ ├── d │ └── d.go ├── round795 │ ├── a.py │ ├── b.py │ ├── c │ ├── c.go │ └── d.go ├── round800 │ ├── a.py │ ├── b.py │ ├── c.cpp │ └── d.cpp ├── round801 │ ├── a.py │ ├── b.py │ ├── c.cpp │ └── d.cpp ├── round803 │ ├── a.py │ ├── b.py │ ├── c.py │ └── d.py ├── round812 │ ├── a.py │ ├── b.py │ └── c.py ├── round816 │ ├── a.py │ ├── b.py │ ├── d.cpp │ └── d.py ├── round833 │ ├── a.py │ ├── b.py │ ├── c.cpp │ └── d.py ├── round864 │ ├── a.py │ ├── b.py │ ├── c.py │ ├── d.cpp │ └── e.py ├── round880 │ ├── a.py │ ├── b.py │ └── d.cpp ├── round967 │ ├── a.py │ ├── b.py │ ├── c.py │ ├── d.cpp │ └── readme.md └── vkcup ru qual │ └── voting_for_photos.cpp ├── facebook-hacker-cup ├── 2017 │ └── qualification │ │ ├── fighting_zombies.py │ │ ├── lazy_loading.py │ │ └── progress_pie.py ├── 2018 │ ├── qualification │ │ ├── A_tourist.py │ │ ├── B_interception.py │ │ ├── C_in.txt │ │ ├── C_string_counterexample.cpp │ │ ├── C_string_counterexample.py │ │ ├── ethan_searches_for_a_string.txt │ │ ├── interception.txt │ │ └── tourist.txt │ └── round1 │ │ ├── A_let_it_flow_DP.cpp │ │ ├── B_ethan_traverses_a_tree.cpp │ │ ├── ethan_traverses_a_tree.txt │ │ └── let_it_flow.txt ├── 2020 │ ├── qual │ │ └── A_travel_restrictions.py │ ├── round1 │ │ ├── a.py │ │ ├── a2.py │ │ ├── a3.py │ │ ├── b.py │ │ └── readme.md │ └── round2 │ │ ├── a.py │ │ ├── a_test_gen.py │ │ ├── b │ │ ├── b.cpp │ │ ├── c.cpp │ │ └── readme.md └── 2021 │ ├── qual │ ├── a1.py │ └── a2.py │ ├── readme.md │ ├── round1 │ ├── a1 │ │ └── a1.py │ ├── a2 │ │ └── a2.py │ └── a3 │ │ └── a3.py │ └── round2 │ ├── a │ └── a.py │ └── b │ ├── b.cpp │ └── b.py ├── google-code-jam ├── 2016 │ ├── qual │ │ ├── pancakes.cpp │ │ └── sheep.py │ ├── rnd1c │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c,py.py │ │ ├── c.cpp │ │ └── c.py │ └── rnd2_virtual │ │ └── A_RPS.py ├── 2017 │ ├── qualification │ │ ├── A_pancake.py │ │ ├── B_numbers.py │ │ └── C_toilets.py │ ├── round1a │ │ ├── a.py │ │ └── aout │ ├── round1b │ │ ├── a.py │ │ ├── b-small.py │ │ └── c.cpp │ └── round2 │ │ ├── a.py │ │ └── b-small.py ├── 2018 │ ├── qualification │ │ ├── A_saving_the_universe_again.py │ │ ├── B_trouble_sort.py │ │ ├── C_go_gopher.py │ │ ├── C_testing_tool.py │ │ └── D_cubic_ufo.py │ ├── round1a │ │ ├── A_in.txt │ │ ├── A_waffle_chompers.py │ │ ├── B_bit_party.py │ │ ├── B_in.txt │ │ └── C_edgy_baking.py │ └── round2 │ │ ├── A_balls.py │ │ ├── B_juggling.py │ │ ├── B_juggling_large.cpp │ │ ├── C_costume_change_large.cpp │ │ ├── C_costume_change_small.py │ │ └── C_short_dumb.cpp ├── 2019 │ ├── qualification │ │ ├── A_foregone_solution.py │ │ ├── B_you_can_go_your_way.py │ │ ├── C_cryptopangrams.py │ │ └── C_gen_test.py │ ├── round1a │ │ ├── A.py │ │ ├── B_golf_gophers.cpp │ │ ├── C.py │ │ ├── interactive_runner.py │ │ └── testing_tool.py │ ├── round1b │ │ ├── a.py │ │ ├── readme.md │ │ └── untitled │ ├── round1c │ │ ├── A_rps.py │ │ ├── B_power_arrangers.py │ │ ├── C_bacterial_tactics_small.py │ │ ├── c.in.py │ │ ├── interactive_runner.py │ │ └── testing_tool.py │ └── round2 │ │ └── A.py ├── 2020 │ ├── qualification │ │ ├── a_vestigium.py │ │ ├── b_nesting_depth.py │ │ └── c_parenting_partnering_returns.py │ ├── round1a │ │ ├── a.py │ │ ├── b.py │ │ ├── b_powers_of_2.py │ │ └── c_small.py │ ├── round1b │ │ ├── a.py │ │ ├── a_small.py │ │ ├── b.py │ │ ├── interactive_runner.py │ │ ├── readme.md │ │ └── testing_tool.py │ └── round2 │ │ ├── a.py │ │ ├── b.py │ │ └── readme.md ├── 2021 │ ├── qualification │ │ ├── a.py │ │ ├── b.py │ │ └── c.py │ ├── round1a │ │ ├── a.py │ │ ├── b_med.py │ │ ├── b_tiny.py │ │ ├── c_large.py │ │ ├── c_med.py │ │ └── readme.md │ └── round2 │ │ ├── a.py │ │ ├── b.py │ │ ├── b_large.py │ │ ├── c.py │ │ ├── d_small.py │ │ └── readme.md ├── 2022 │ ├── qualification │ │ ├── a.py │ │ ├── b.py │ │ ├── c.py │ │ └── d.py │ ├── round1a │ │ ├── a.py │ │ ├── b.py │ │ ├── c.py │ │ └── readme.md │ ├── round1c │ │ ├── a.py │ │ ├── b_large.py │ │ ├── b_small.py │ │ ├── c_small.py │ │ └── readme.md │ └── round2 │ │ ├── a.cpp │ │ ├── a.py │ │ ├── b_small.py │ │ ├── c_small.py │ │ └── readme.md ├── 2023 │ └── farewell_c │ │ ├── e.py │ │ └── readme.md └── readme.md ├── google-kick-start └── 2020 │ ├── round_a │ ├── a_allocation.py │ ├── b_plates.cpp │ ├── b_plates.py │ ├── c_workout.cpp │ ├── d_bundling.cpp │ ├── d_bundling.py │ └── readme.md │ ├── round_b │ ├── a_bike_tour.py │ ├── b_bus_routes.py │ ├── c_robot_path_decoding.py │ ├── d_wandering_robot.py │ └── readme.md │ ├── round_d │ ├── a.py │ ├── b.py │ └── c.py │ └── round_e │ ├── a.py │ ├── b.py │ ├── c.py │ └── readme.md ├── graph_test_case_gen.py ├── hackerrank ├── 101hack42 │ ├── lights_out_OG_DP.cpp │ └── rectangle.cpp ├── 2015_world_cup_university_codesprint │ └── C_world_cup_game.cpp ├── GENERAL │ ├── ACM_ICPC_team.py │ ├── algorithmic_crush_one_line.py │ ├── fib.py │ ├── longest_increasing_subsequence.cpp │ ├── longest_increasing_subsequence_nlogn.cpp │ ├── maxsubarray.py │ ├── the_great_xor_one_line.py │ └── two_characters_one_line.py ├── ad_infinitum_18 │ ├── A_oneline.py │ └── B_pythagorean_triples.py ├── asian_pacific_american_heritage_month_2021 │ ├── a.py │ ├── b.py │ ├── c.py │ ├── d.cpp │ ├── d.py │ └── readme.md ├── celebrate_junteenth_2021 │ ├── a.py │ ├── b.py │ ├── c.py │ ├── d.png │ └── d.py ├── celebrate_neurodiversity_2021 │ ├── a.py │ ├── b.py │ ├── c.py │ ├── d.py │ └── readme.md ├── celebrate_pride_2021 │ ├── a.py │ ├── b.py │ ├── c.py │ ├── d.py │ └── readme.md ├── code_cpp3 │ ├── bitset.cpp │ ├── classes.cpp │ ├── inheritedmethods.cpp │ ├── operatoroverloading.cpp │ └── variablesizedarrays.cpp ├── codesprint_2016_may │ ├── B_richie_rich.cpp │ └── C_absolute_permutation.cpp ├── codesprint_april_2016 │ ├── B_beautiful_triplets.cpp │ └── D_yet_another_kmp_problem.cpp ├── codiva │ ├── A_prime_number_and_queries.cpp │ ├── B_camera_purchase.cpp │ └── C_cost_of_merging_strings.cpp ├── covid19_relief_for_india │ ├── a.py │ ├── b.py │ ├── c.py │ ├── d.py │ ├── d_problem_statement.png │ └── readme.md ├── ctf │ └── dfs.py ├── dtcc_coding_contest │ ├── a.py │ ├── b.py │ ├── c.sql │ └── d.sql ├── general │ ├── Euler │ │ └── Problem2_one_line.py │ └── palindrome-index.py ├── hack_the_interview_6 │ ├── a.py │ ├── b.py │ ├── c.py │ ├── d.py │ └── readme.md ├── hackfest2020 │ ├── a.py │ ├── b.py │ ├── c.py │ ├── d.py │ └── readme.md ├── hiring_contest_18_01_28 │ └── b_bitmask_winning_lottery_ticket.cpp ├── hourrank_24 │ ├── A_password_check.py │ ├── B_tree.cpp │ └── C_greedyish.cpp ├── hourrank_25 │ ├── a_constructing_a_number.py │ └── b_maximum_palindromes.py ├── hourrank_8 │ └── tiltedwhatsnext.cpp ├── hourrank_9 │ └── B_Mandragora_forest.cpp ├── icpc2014EU │ ├── microwave.cpp │ └── sums.cpp ├── moodys_women_2018 │ └── E_marmelade_wall.py ├── pythonist │ └── most_commons.py ├── reaadme.md ├── regular expresso 2 │ ├── digicrush_game_checker.py │ ├── rescue_angie.php │ └── superior_string.py ├── university_codesprint │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ └── D_nim_trees_game.cpp ├── university_codesprint_3 │ ├── A_python2.py │ ├── B.py │ ├── C.py │ ├── D.py │ └── E.py ├── week_of_code_19 │ └── TwoRobots.cpp ├── week_of_code_20 │ ├── A_divisble_sum_pairs_bruteforce.cpp │ ├── B_nondivisible_subset.cpp │ ├── C_synchronous_shopping.cpp │ ├── D_simple_game.cpp │ ├── E_jogging_cats.cpp │ └── F_catcation_rentals.cpp ├── week_of_code_21 │ ├── A_kangaroo.cpp │ ├── B_luck_balance.cpp │ └── C_lazy_sorting.cpp ├── week_of_code_24 │ └── chess.cpp ├── week_of_code_25 │ ├── D_stone_division.cpp │ └── D_test.txt ├── week_of_code_27 │ ├── a.py │ ├── b.py │ ├── c.py │ ├── d.py │ └── readme.md ├── week_of_code_28 │ ├── B_xor.py │ └── C_multiple_subsequence.py ├── week_of_code_33 │ ├── B_pattern_count_one_line.py │ └── D_palindrome_table.cpp ├── week_of_code_35 │ ├── A_lucky_purchase_first.py │ ├── B_triple_recursion.py │ ├── C_3d_surface_area_fast.py │ ├── D_matrix_land_DP_good_problem.cpp │ └── E_highway_construction_faulhabers_formula.cpp ├── week_of_code_37 │ ├── A_average_rating_of_top_employees.py │ ├── B_simple_language.py │ ├── C_superior_characters.py │ └── D_dynamic_line_intersection.py ├── world_codesprint_11 │ ├── A_balanced_array_one_line.py │ └── B_numeric_string_one_line.py ├── world_codesprint_9 │ ├── a.cpp │ ├── b_weighted_uniform_strings.cpp │ └── c_queens_attack_II.cpp └── zalando_codesprint │ ├── A_match_the_shoes.cpp │ ├── A_match_the_shoes.py │ ├── B_the_inquiring_manager.cpp │ ├── B_the_inquiring_manager.py │ ├── C_minimal_wrapping_surface_area.cpp │ ├── D_does_it_fit.cpp │ ├── E_which_warehouses_can_fulfill_these_orders.cpp │ ├── F_make_our_customers_happy.cpp │ ├── G_Processing_time_inside_a_warehouse.cpp │ └── H_give_me_the_order.cpp ├── icpc ├── 2010_Swerc │ └── three_sided_dice_kattis.py ├── 2014_central_europe │ ├── C_sums.cpp │ ├── C_sums2.cpp │ ├── D_sample.txt │ ├── D_wheels.cpp │ ├── H.out2 │ ├── H.py │ ├── H_cpp.cpp │ ├── Hcheck.py │ ├── J_pork.cpp │ ├── J_test │ ├── K_imp.cpp │ ├── K_test │ ├── L.py │ └── readme.md ├── 2015_midcentral_icpc │ ├── A_acm_contest_scoring.cpp │ ├── A_sample.txt │ ├── B_dance_recital.cpp │ ├── B_sample.txt │ ├── C_hidden_password.cpp │ ├── C_sample.txt │ ├── D_kitchen_measurements.cpp │ ├── D_sample.txt │ ├── E_line_them_up.cpp │ ├── E_sample.txt │ ├── G.cpp │ ├── G_sample.txt │ ├── I.cpp │ ├── h_agglomerator.cpp │ ├── h_sample.txt │ ├── readme.md │ └── readme.txt ├── 2015_new_york_regional │ ├── A_rational_sequence_2.cpp │ ├── A_sample.txt │ ├── B_sum_kind_of_problem.cpp │ ├── C_farey.cpp │ ├── C_sample.txt │ ├── D_composition.cpp │ ├── D_sample.txt │ ├── E_running_steps.cpp │ ├── E_running_steps.python.py │ ├── F_immortal_porpoise_fibonnaci.cpp │ ├── F_sample.txt │ ├── G_robots.cpp │ ├── G_sample.txt │ ├── H_RATS.cpp │ └── rats.py ├── 2015_northwest │ ├── A_airports.cpp │ ├── G_racing_gems.cpp │ └── G_sample.txt ├── 2015_socal_regional │ ├── H_persistence_7398.cpp │ ├── H_persistence_7398.py │ └── H_sample.txt ├── 2016_midcentral_icpc │ ├── A.py │ ├── B_apple_gravity_sim.cpp │ ├── C_square_rectangles.py │ ├── G_ada.py │ └── I_postal.py ├── 2016_new_york_regional │ ├── A_amazing.py │ ├── b_a_rational_sequence_3.py │ ├── c_da_sort.py │ ├── d_fbi_universal_control_numbers.py │ ├── f_m_ary_partitions.cpp │ ├── f_m_ary_partitions.py │ ├── g_permutation_descent_counts.py │ └── j_which_base_is_it_anyway.py ├── 2016_north_central_regional │ └── flow_shop.cpp ├── 2016_northwestern_europe_regional │ ├── C_firefly.cpp │ ├── F_freeweights.cpp │ ├── F_freeweights.py │ └── H_hypercube.py ├── 2016_pacific_northwest │ ├── A_alphabet.py │ ├── B_buggy_robot.cpp │ ├── C_cameras.cpp │ ├── H_paint.cpp │ ├── I_postman.cpp │ └── J_shopping.cpp ├── 2016_socal_regional │ ├── Problem1.py │ ├── Problem10.py │ ├── Problem2.cpp │ ├── Problem3.py │ ├── Problem4.cpp │ ├── Problem5.py │ ├── Problem6.cpp │ ├── Problem7.cpp │ ├── Problem8.cpp │ ├── SC2016ICPCProblems.pdf │ └── readme.md ├── 2017_east_central_NA_regional │ ├── C_DRM_messages.py │ ├── D_game_of_throwns.py │ ├── E_isa_hasa.cpp │ ├── F_keeping_on_track.cpp │ ├── G_ingestion.cpp │ ├── H_shebas_amoebas.cpp │ └── J_workout_dumbbell.cpp ├── 2017_neerc_southern_subregional_quals │ ├── b.cpp │ ├── b.py │ ├── b_redux.cpp │ ├── bbad.cpp │ └── c.cpp ├── 2017_world_finals │ ├── E_speed.py │ └── I_secretchamber.py ├── 2018_asia_singapore │ ├── B_hoppers.py │ └── c_sg_coin.py ├── 2018_nwerc │ ├── I_inflation.py │ ├── h_hard_drive.py │ └── readme.md ├── ghostbusters.cpp ├── maps_2020 │ ├── c_easy_multiplication.py │ ├── d_greedy_polygons.py │ ├── g_litespace.py │ ├── h_magical_cows.py │ ├── loool.png │ ├── placement.png │ └── readme.md ├── naipc2015 │ └── naipcplayground.py ├── naipc2016 │ └── f │ │ ├── 1.ans │ │ ├── 2.ans │ │ ├── dp.cpp │ │ ├── mountain_scenes.cpp │ │ ├── scenes-0000.ans │ │ ├── scenes-0001.ans │ │ ├── scenes-0002.ans │ │ └── scenes-0003.ans ├── naipc2017 │ ├── a_parentheses.cpp │ └── j.py ├── naq2017 │ ├── B.cpp │ ├── C.cpp │ ├── D.cpp │ ├── G.cpp │ ├── K.cpp │ └── L.py └── naq2020 │ ├── a.py │ ├── e.py │ ├── h.py │ ├── readme.md │ └── results.png ├── ieeextreme ├── IEEEXtreme10 │ ├── B_20_questions.cpp │ ├── D_painter.py │ ├── F_memory_management.cpp │ ├── G_pirates_TLE.cpp │ ├── G_pirates_no_TLE.cpp │ ├── J_checkers.cpp │ ├── J_sample.txt │ ├── N_safety.cpp │ ├── P_island_hopping_1.cpp │ ├── Q_finding_shelter.py │ ├── R_control.py │ ├── V_binary_quilts.cpp │ └── V_sample.txt ├── IEEEXtreme8 │ ├── CELLULARAUTOMATA.py │ ├── README.md │ ├── coffe3.txt │ ├── coffee.py │ ├── coffee.txt │ ├── heist.py │ ├── heist.txt │ ├── heist2.py │ ├── heist25.py │ ├── heist3.py │ ├── heist4.py │ ├── ieeepalindrome.py │ ├── ieeepalindrome.txt │ ├── kabloom.py │ ├── kabloom.txt │ ├── lottery.py │ ├── lottery.txt │ ├── lottery2.txt │ ├── magic.py │ ├── magic.txt │ ├── pipeline.py │ ├── pipeline.txt │ ├── sumitup.py │ └── sumitup.txt ├── IEEEXtreme9 │ ├── Pattern3_naive_unoptimized.py │ ├── palindromicmoment.py │ ├── snakesbunnies.cpp │ └── zoomin.py └── IEEExtreme11 │ ├── B_quipu_function_primes_divisors.cpp │ ├── collecting_gold.cpp │ ├── disc.py │ ├── fill_the_pixels_floodfill_dfs.cpp │ ├── orienteering_simple_dijkstra.cpp │ ├── stupid_interactive_question.py │ └── torus_game_of_life.cpp ├── leetcode ├── b33 │ ├── a.py │ ├── b.py │ ├── c.py │ ├── d.py │ └── readme.md ├── b36 │ ├── a.py │ ├── b.py │ ├── c.py │ └── d.cpp ├── b38 │ ├── a.py │ ├── b.py │ ├── c.py │ └── d.py ├── b57 │ ├── a.py │ ├── b.py │ ├── c.py │ ├── d.py │ └── readme.md ├── b75 │ ├── a.py │ ├── b.py │ └── c.py ├── c158 │ ├── a.py │ ├── b.py │ ├── c_dp.py │ ├── d.py │ └── readme.md ├── c168 │ ├── a.py │ ├── b.py │ ├── c.py │ └── d.py ├── c181 │ ├── a_target_array_in_order.py │ ├── b_four_divisors.py │ ├── c_valid_path_grid.py │ └── d_longest_happy_prefix.py ├── c189 │ ├── a.py │ ├── b.py │ ├── c.py │ └── d.py ├── c190 │ ├── a.py │ ├── b.py │ ├── c.py │ └── d.py ├── c192 │ ├── a.py │ ├── b.py │ ├── c.py │ └── d.py ├── c193 │ ├── a.py │ ├── b.py │ ├── c_binary_search.py │ ├── d_binary_lifting_tree.py │ └── readme.md ├── c194 │ ├── a.py │ ├── b.py │ ├── c.py │ ├── d_mst_prims.py │ └── readme.md ├── c196 │ ├── a.py │ ├── b.py │ ├── c.py │ ├── d_unfinished.py │ └── readme.md ├── c197 │ ├── a.py │ ├── b.py │ ├── c.py │ ├── d.py │ └── readme.md ├── c198 │ ├── a.py │ ├── b.py │ ├── c.py │ ├── d.py │ └── readme.md ├── c199 │ ├── a.py │ ├── b.py │ ├── c.py │ ├── d.py │ └── readme.md ├── c200 │ ├── a.py │ ├── b.py │ ├── c.py │ ├── d.py │ └── readme.md ├── c203 │ ├── a.py │ ├── b.py │ ├── c.py │ ├── d.py │ └── readme.md ├── c204 │ ├── a.py │ ├── b.py │ ├── c.py │ ├── d.py │ └── readme.md ├── c206 │ ├── a.py │ ├── b.py │ └── c.py ├── c207 │ ├── a.py │ ├── b.py │ └── c.py ├── c209 │ ├── b.py │ ├── c.py │ └── d.py ├── c210 │ ├── a.py │ ├── b.py │ ├── c.py │ └── d.py ├── c254 │ ├── a.py │ ├── b.py │ ├── c.py │ ├── d.py │ └── readme.md ├── c289 │ ├── a.py │ ├── b.py │ ├── c.py │ └── d.py ├── c304 │ ├── a.py │ ├── b.py │ ├── c.py │ └── d.py ├── c364 │ ├── a.py │ ├── b.py │ ├── c.py │ └── d.py ├── c386 │ ├── a.py │ ├── b.py │ ├── c.py │ └── readme.md ├── c8 │ └── c417_atlantic_water.cpp └── miscellaneous │ ├── p135_candy.py │ ├── p416_partition_equal_subset_sum_array.py │ ├── p416_partition_equal_subset_sum_set.py │ └── p523_continuous_subarray_sum_mod.py ├── miscellaneous ├── advent-of-code │ ├── 2018 │ │ ├── boilerplate.py │ │ ├── day5.py │ │ ├── day_1.py │ │ ├── day_11.py │ │ ├── day_12.py │ │ ├── day_13.py │ │ ├── day_2.py │ │ ├── day_3.py │ │ ├── day_4.py │ │ ├── day_6.py │ │ ├── day_7.py │ │ ├── day_8.py │ │ ├── ldrbrd.png │ │ └── readme.md │ ├── 2019 │ │ ├── boilerplate.py │ │ ├── day_1.py │ │ ├── day_10.py │ │ ├── day_11.py │ │ ├── day_12.py │ │ ├── day_13.py │ │ ├── day_14.py │ │ ├── day_15.py │ │ ├── day_16.py │ │ ├── day_17.py │ │ ├── day_18.py │ │ ├── day_18_pt2.py │ │ ├── day_19.py │ │ ├── day_2.py │ │ ├── day_20.py │ │ ├── day_20_pt1.py │ │ ├── day_21.py │ │ ├── day_22.py │ │ ├── day_22_pt2.py │ │ ├── day_24.py │ │ ├── day_25.py │ │ ├── day_3.py │ │ ├── day_4.py │ │ ├── day_5.py │ │ ├── day_6.py │ │ ├── day_7.py │ │ ├── day_7_pt2.py │ │ ├── day_8.py │ │ ├── day_9.py │ │ ├── ldrbrd.png │ │ ├── readme.md │ │ └── utils.py │ ├── 2020 │ │ ├── boilerplate.py │ │ ├── day_1.py │ │ ├── day_10.py │ │ ├── day_11.py │ │ ├── day_12.py │ │ ├── day_13.py │ │ ├── day_13_attempt.png │ │ ├── day_14.py │ │ ├── day_14_pt2.py │ │ ├── day_15.py │ │ ├── day_16.py │ │ ├── day_16_pt2.py │ │ ├── day_17.py │ │ ├── day_18.py │ │ ├── day_18_pt2.py │ │ ├── day_19.py │ │ ├── day_2.py │ │ ├── day_20.py │ │ ├── day_21.py │ │ ├── day_22.py │ │ ├── day_23.py │ │ ├── day_23_pt2.py │ │ ├── day_24.py │ │ ├── day_3.py │ │ ├── day_4.py │ │ ├── day_5.py │ │ ├── day_6.py │ │ ├── day_7.py │ │ ├── day_8.py │ │ ├── day_9.py │ │ ├── ldrbrd.png │ │ └── readme.md │ ├── 2021 │ │ ├── boilerplate.py │ │ ├── day_1.py │ │ ├── day_10.py │ │ ├── day_11.py │ │ ├── day_12.py │ │ ├── day_13.py │ │ ├── day_14.py │ │ ├── day_15.py │ │ ├── day_16.py │ │ ├── day_17.py │ │ ├── day_18.py │ │ ├── day_19.py │ │ ├── day_2.py │ │ ├── day_20.py │ │ ├── day_21.py │ │ ├── day_22.py │ │ ├── day_23.py │ │ ├── day_24.py │ │ ├── day_25.py │ │ ├── day_3.py │ │ ├── day_4.py │ │ ├── day_5.py │ │ ├── day_6.py │ │ ├── day_7.py │ │ ├── day_8.py │ │ ├── day_9.py │ │ ├── ldrbrd.png │ │ └── readme.md │ ├── 2022 │ │ ├── boilerplate.py │ │ ├── day1.py │ │ ├── day10.py │ │ ├── day11.py │ │ ├── day12.py │ │ ├── day13.py │ │ ├── day14.py │ │ ├── day15.py │ │ ├── day16.py │ │ ├── day16pt2.py │ │ ├── day17.py │ │ ├── day18.py │ │ ├── day19.py │ │ ├── day2.py │ │ ├── day20.py │ │ ├── day21.py │ │ ├── day22.py │ │ ├── day23.py │ │ ├── day24.py │ │ ├── day25.py │ │ ├── day3.py │ │ ├── day4.py │ │ ├── day5.py │ │ ├── day6.py │ │ ├── day7.py │ │ ├── day8.py │ │ ├── day9.py │ │ └── ldrbrd.jpg │ ├── 2023 │ │ ├── boilerplate.py │ │ ├── day1.py │ │ ├── day10.py │ │ ├── day11.py │ │ ├── day12.py │ │ ├── day13.py │ │ ├── day14.py │ │ ├── day15.py │ │ ├── day16.py │ │ ├── day17.py │ │ ├── day18.py │ │ ├── day19.py │ │ ├── day2.py │ │ ├── day20.py │ │ ├── day21.py │ │ ├── day22.py │ │ ├── day23.py │ │ ├── day24.py │ │ ├── day25.py │ │ ├── day3.py │ │ ├── day4.py │ │ ├── day5.py │ │ ├── day6.py │ │ ├── day7.py │ │ ├── day8.py │ │ ├── day9.py │ │ ├── ldrbrd.jpg │ │ └── readme.md │ ├── my_star_summary.jpg │ └── readme.md ├── edge-matching.py ├── google-foobar │ ├── Google Foobar 2nd run │ │ ├── challenge_solutions.py │ │ ├── count_spanning_graphs.py │ │ └── string_cleaning.py │ ├── challengesolutions.py │ └── pirates.py ├── hacktech-heat │ ├── campus_directions.py │ ├── campusgenout.txt │ ├── campusinput03.txt │ ├── campusoutput03.txt │ ├── computers.py │ ├── computers_mistaked.py │ ├── computers_nonmistaken.py │ └── mural.py └── openai-codex-challenge │ ├── a.py │ ├── b.py │ ├── b_lcs.py │ ├── b_openai.py │ ├── c.py │ ├── d.py │ ├── e.py │ └── readme.md ├── notebook ├── boilerplate.cpp ├── boilerplate.go ├── boilerplate.py ├── checklists │ └── python.md ├── cpp │ ├── notebook.cpp │ └── notebook.md ├── racket │ ├── readme.md │ ├── sorting.bak │ └── sorting.rkt └── readme.md ├── problem-statements ├── Not_Quite_Solved │ ├── README.MD │ └── airports-English.pdf └── Solved │ ├── README.MD │ └── string_cleaning.txt ├── project-euler ├── e10.py ├── e11.py ├── e12.py ├── e13.py ├── e14.py ├── e14.rkt ├── e15.py ├── e16.py ├── e169.py ├── e17.py ├── e18.py ├── e19.py ├── e20.py ├── e21.py ├── e22.py ├── e23.py ├── e24.py ├── e25.py ├── e26.py ├── e27.py ├── e28.py ├── e29.py ├── e30.py ├── e31.py ├── e32.py ├── e33.py ├── e34.py ├── e35.py ├── e36.py ├── e37.py ├── e38.py ├── e39.py ├── e4.py ├── e40.py ├── e41.py ├── e42.py ├── e5.py ├── e6.py ├── e67.txt ├── e7.py ├── e87.py ├── e88.py ├── e9.py ├── eight.py └── readme.md └── quora └── qpc_2021 ├── .ipynb_checkpoints └── g_scratch-checkpoint.ipynb ├── a_connect_4.py ├── b_treasure.py ├── c_small.py ├── g_message.py ├── g_scratch.ipynb ├── h_malicious.py ├── problemset.pdf ├── readme.md └── results.png /UVA/uva763_fibinary.go: -------------------------------------------------------------------------------- 1 | // You can edit this code! 2 | // Click here and start typing. 3 | package main 4 | 5 | import "fmt" 6 | 7 | func main() { 8 | fmt.Println("Hello, 世界") 9 | } -------------------------------------------------------------------------------- /UVA/uva_10541_stripe_combinatorics.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define ll long long 5 | #define ull unsigned long long 6 | using namespace std; 7 | 8 | int main(){ 9 | std::ios::sync_with_stdio(false); 10 | int T; 11 | cin >> T; 12 | for(int t = 0; t < T; t++){ 13 | int n, k; 14 | cin >> n >> k; 15 | //nvm just realized this problem requires numbers up to 16 | //50 fucking digits, so i'm going to switch to python. 17 | //why the fuck would they not accept the answer modulo 10^7..... 18 | } 19 | return 0; 20 | } -------------------------------------------------------------------------------- /acm-practice/2016-09-27/two_characters.py: -------------------------------------------------------------------------------- 1 | print((lambda _, w: max(len([l for l in w if l in (i,j)]) if not (lambda x: (any(x[y]==x[y-1] for y in range(1,len(x))) or len(x)==1) )([l for l in w if l in (i,j)]) else 0 for i in 'abcdefghijklmnopqrstuvwxyz' for j in 'abcdefghijklmnopqrstuvwxyz'))(input(), input())) 2 | #https://www.hackerrank.com/contests/world-codesprint-7/challenges/two-characters/copy-from/1301772613 -------------------------------------------------------------------------------- /acm-practice/2017-01-10/palindrome.cpp: -------------------------------------------------------------------------------- 1 | //http://poj.org/problem?id=1159 2 | #include 3 | #define ll long long 4 | using namespace std; 5 | int main(){ 6 | std::ios::sync_with_stdio(false); 7 | ll n; 8 | cin >> n; 9 | string s; 10 | cin >> s; 11 | vector> dp(n, vector(n, -1)); 12 | for(ll i = 1; i < n; i++){ 13 | for(ll j = ) 14 | } 15 | } -------------------------------------------------------------------------------- /acm-practice/2017-01-24/nimble_game.py: -------------------------------------------------------------------------------- 1 | T = int(input().strip()) 2 | for i in range(T): 3 | _ = input() 4 | from functools import reduce 5 | #a one-liner for fun, using enumerate, map, and reduce :) 6 | print("Second" if reduce(lambda a, b: a^b, map(lambda x: x[0]*(int(x[1])%2), enumerate(input().split()))) == 0 else "First") -------------------------------------------------------------------------------- /acm-practice/2017-01-26/back_to_the_origin.py: -------------------------------------------------------------------------------- 1 | #https://www.hackerrank.com/contests/codeagon/challenges/back-to-origin 2 | 3 | xTreasure,yTreasure = input().strip().split(' ') 4 | xTreasure,yTreasure = [int(xTreasure),int(yTreasure)] 5 | n = int(input().strip()) 6 | dx_total = 0 7 | dy_total = 0 8 | for i in range(n): 9 | dx, dy = input().split() 10 | dx_total += int(dx) 11 | dy_total += int(dy) 12 | print(xTreasure - dx_total, yTreasure - dy_total) -------------------------------------------------------------------------------- /acm-practice/2017-01-31/README.md: -------------------------------------------------------------------------------- 1 | ## January 31, 2017: Educational Codeforces Round 17 2 | 3 | Problems: http://codeforces.com/contest/762 4 | 5 | Editorial (hints + solution explanations): http://codeforces.com/blog/entry/50010 6 | 7 | In my solutions, I use `#define ll long long`, so `ll` everywhere in the code represents `long long`. -------------------------------------------------------------------------------- /acm-practice/2017-05-11/greedy_florist.py: -------------------------------------------------------------------------------- 1 | #https://www.hackerrank.com/challenges/greedy-florist 2 | n, k = map(int, input().split()) 3 | prices = list(map(int, input().split())) 4 | prices.sort() 5 | prices = prices[:n] 6 | f = 0 7 | ans = 0 8 | for i in reversed(prices): 9 | ans += i * ((k+f)//k) 10 | f += 1 11 | print(ans) -------------------------------------------------------------------------------- /acm-practice/2017-10-26/A_kitten_tree.py: -------------------------------------------------------------------------------- 1 | x = int(input()) 2 | i = input() 3 | from collections import defaultdict 4 | parents = dict() 5 | while i != '-1': 6 | l = [int(j) for j in i.split()[1:]] 7 | for j in l: 8 | parents[j] = (int(i.split()[0])) 9 | i = input() 10 | 11 | print(x) 12 | while(x in parents): 13 | x = parents[x] 14 | print(x) 15 | 16 | -------------------------------------------------------------------------------- /acm-practice/2017-10-26/C_weak.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | while n != -1: 3 | am = [] 4 | for i in range(n): 5 | am.append([int(x) for x in input().split()]) 6 | ans = [] 7 | for i in range(n): 8 | part = False 9 | for j in range(n): 10 | for k in range(n): 11 | if am[i][j] and am[i][k] and am[j][k]: 12 | part = True 13 | if not part: 14 | ans.append(i) 15 | print(' '.join(map(str,ans))) 16 | n = int(input()) 17 | -------------------------------------------------------------------------------- /acm-practice/2017-10-26/D_suspension_binary_search.py: -------------------------------------------------------------------------------- 1 | d, s = map(int, input().split()) 2 | l = 0 3 | r = 123456789 4 | eps = 0.000001 5 | import math 6 | for i in range(123456): 7 | a = (r+l)/2 8 | term = (d/(2*a)) 9 | sag = 0.5*a*(math.exp(term) + math.exp(-term)) - a 10 | if sag < s: 11 | r = a 12 | else: 13 | l = a 14 | term = d/(2*l) 15 | print(l * (math.exp(term) - math.exp(-term))) 16 | -------------------------------------------------------------------------------- /acm-practice/2017-10-26/E_euclid_tsp.py: -------------------------------------------------------------------------------- 1 | inp = input().split() 2 | n = int(inp[0]) 3 | p = float(inp[1]) 4 | s = float(inp[2]) 5 | v = float(inp[3]) 6 | import math 7 | l = 0.0000000001 8 | r = 30 9 | 10 | def f(c): 11 | top = n/(p*1000000000) * pow(math.log(n,2), c * math.sqrt(2)) + (s*(1+(1/c))/v) 12 | return top 13 | 14 | eps = 0.000001 15 | for i in range(123456): 16 | m = (l+r)/2 17 | if f(m) - f(m+eps) > 0: 18 | l = m 19 | else: 20 | r = m 21 | 22 | print(f(l), l) 23 | -------------------------------------------------------------------------------- /acm-practice/2019-01-13-internal-test/acm_contest_scoring.py: -------------------------------------------------------------------------------- 1 | from collections import defaultdict 2 | time = 0 3 | probs = 0 4 | penalties = defaultdict(int) 5 | while True: 6 | inp = input() 7 | if inp.strip() == '-1': 8 | break 9 | i, p, res = inp.split() 10 | i = int(i) 11 | if res == 'right': 12 | probs +=1 13 | time += i + penalties[p] 14 | else: 15 | penalties[p] += 20 16 | print(probs, time) -------------------------------------------------------------------------------- /acm-practice/2019-01-13-internal-test/beatspread.py: -------------------------------------------------------------------------------- 1 | # x + y = b 2 | # x - y = a 3 | # x = a + y 4 | # a + 2y = b 5 | #y = (b-a)/2 6 | #x = b-y 7 | 8 | n = int(input()) 9 | for i in range(n): 10 | b, a = map(int, input().split()) 11 | y = (b-a)//2 12 | x = (b-y) 13 | x, y = sorted([x,y]) 14 | if y < 0 or x < 0 or (b-a)%2!=0: 15 | print('impossible') 16 | else: 17 | print(y, x) -------------------------------------------------------------------------------- /acm-practice/2019-01-13-internal-test/god_save_the_ith_queen.py: -------------------------------------------------------------------------------- 1 | x, y, n = map(int, input().split()) 2 | rows = set(range(1,y+1)) 3 | cols = set(range(1, x+1)) 4 | back_diags = set() 5 | for i in range(n): 6 | x, y = map(int, input().split()) 7 | rows.remove(y) 8 | cols.remove(x) 9 | input() -------------------------------------------------------------------------------- /acm-practice/2019-01-29/A_arithmetic.py: -------------------------------------------------------------------------------- 1 | a = int(input(), 8) 2 | print(hex(a)[2:].upper()) -------------------------------------------------------------------------------- /acm-practice/2019-01-29/B_code_cleanups.py: -------------------------------------------------------------------------------- 1 | thresh = 20 2 | days = int(input()) 3 | xs = [int(x) for x in input().split()] 4 | xs.reverse() 5 | n = 0 6 | s = 0 7 | ans = 0 8 | for day in range(1,366): 9 | if len(xs) > 0 and xs[-1] == day: 10 | n += 1 11 | xs.pop() 12 | s += n 13 | if s >= thresh: 14 | n = 0 15 | s = 0 16 | ans += 1 17 | if n > 0 or s > 0: 18 | ans += 1 19 | print(ans) -------------------------------------------------------------------------------- /acm-practice/2019-01-29/C_bing_it_on.py: -------------------------------------------------------------------------------- 1 | from collections import defaultdict 2 | d = defaultdict(int) 3 | n = int(input()) 4 | for i in range(n): 5 | w = input() 6 | k = "" 7 | print(d[w]) 8 | for letter in w: 9 | k+=letter 10 | d[k]+=1 11 | -------------------------------------------------------------------------------- /acm-practice/2019-01-29/readme.md: -------------------------------------------------------------------------------- 1 | kattis contest that i participated in remotely (i have graduated) 2 | 3 | https://open.kattis.com/contests/yg85hz/problems 4 | 5 | problems: Arithmetic, Code Cleanups, Bing It On, The Trip, Collecting Beepers -------------------------------------------------------------------------------- /acm-practice/2019-02-19/a_3d_printer.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | #i dunno why this works but it does 3 | import math 4 | if n == 1: 5 | print(1) 6 | else: 7 | print(int(math.log2(n-1))+2) -------------------------------------------------------------------------------- /acm-practice/2019-02-19/readme.md: -------------------------------------------------------------------------------- 1 | there was an internal contest! 2 | 3 | unfortunately, I already did problem B (Inflation) at [an NAIPC practice contest](https://open.kattis.com/contests/na19warmup5) which was a re-run of NWERC 2018 which it's from. 4 | 5 | https://open.kattis.com/contests/uijenc -------------------------------------------------------------------------------- /acm-practice/CPP_Practice/CPP_Practice/Change-By-Mass.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | std::vector> cache; 7 | float* getChange(int goal){ 8 | return 0; 9 | } -------------------------------------------------------------------------------- /acm-practice/CPP_Practice/CPP_Practice/collatz.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitamintK/AlgorithmProblems/7f3b88d15513c24424254a6b44a1a557267ea1c7/acm-practice/CPP_Practice/CPP_Practice/collatz.cpp -------------------------------------------------------------------------------- /acm-practice/CPP_Practice/CPP_Practice/collatz.h: -------------------------------------------------------------------------------- 1 | #include 2 | int collatz(int x){ 3 | std::cout << x << std::endl; 4 | if (x == 1){ 5 | return 0; 6 | } 7 | if (x % 2 == 0){ 8 | return collatz(x / 2) + 1; 9 | } 10 | else { 11 | return collatz(3 * x + 1) + 1; 12 | } 13 | } 14 | void collatz_start(){ 15 | int x; 16 | std::cin >> x; 17 | std::cout << collatz(x); 18 | } 19 | -------------------------------------------------------------------------------- /acm-practice/CPP_Practice/CPP_Practice/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include"collatz.h" 3 | #include"mit.h" 4 | #include"LIS2.h" 5 | int main(){ 6 | //collatz_start(); 7 | lis2(); 8 | int y; 9 | std::cin >> y; 10 | return 0; 11 | } -------------------------------------------------------------------------------- /acm-practice/ICPC-EU-Regional/layercake.cpp: -------------------------------------------------------------------------------- 1 | int main(){ 2 | int n; 3 | std::cin >> n; 4 | int* x = new x[n]; 5 | for (int i = 0; i < n; i++){ 6 | std::cin >> x[i]; 7 | } 8 | return 0; 9 | } -------------------------------------------------------------------------------- /acm-practice/ICPC-EU-Regional/lottery.py: -------------------------------------------------------------------------------- 1 | n,k = [int(x) for x in input().split()] 2 | balls = [int(x) for x in input().split()] 3 | 4 | from collections import defaultdict 5 | d = defaultdict(int) 6 | for b in balls: 7 | d[b] += 1 8 | correct_num = n/k 9 | paint_needed = 0 10 | for color, amount in d.items(): 11 | if amount > correct_num: 12 | paint_needed += amount - correct_num 13 | 14 | print(int(paint_needed)) 15 | -------------------------------------------------------------------------------- /acm-practice/TRAINING/2016-Fall/binary_search_sample.txt: -------------------------------------------------------------------------------- 1 | 8 2 | 8 3 | 0 1 2 3 4 5 6 7 -------------------------------------------------------------------------------- /acm-practice/TRAINING/2016-Fall/recursive-backtracking-uva-11195_sample.txt: -------------------------------------------------------------------------------- 1 | 8 2 | ........ 3 | ........ 4 | ........ 5 | ........ 6 | ........ 7 | ........ 8 | ........ 9 | ........ 10 | 4 11 | .*.. 12 | .... 13 | .... 14 | .... 15 | 0 -------------------------------------------------------------------------------- /acm-practice/jan28/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /acm-practice/jan28/.gitignore: -------------------------------------------------------------------------------- 1 | /bin/ 2 | -------------------------------------------------------------------------------- /acm-practice/jan28/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | findgivensum 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /acm-practice/jan28/src/findgivensum/Main.java: -------------------------------------------------------------------------------- 1 | package findgivensum; 2 | 3 | public class Main { 4 | public static void main(String[] args){ 5 | Tree mytree = new Tree(); 6 | mytree.addAll(); 7 | 8 | } 9 | } -------------------------------------------------------------------------------- /acm-practice/markovfrogger.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | inp = """2 r 4 | 1 r 5 | 0 r""" 6 | 7 | firstmarkov = [[0,1,0,1,0,0,0,0,0],[],[],[],[],[],[],[],[]] 8 | -------------------------------------------------------------------------------- /codechef/snackdown_2017/A_snakes_mongooses_ultimate_election.py: -------------------------------------------------------------------------------- 1 | [print((lambda x: "mongooses" if x > 0 else ("snakes" if x <0 else "tie")) ((lambda s, l: (s.count('m') - s.count('s') + len(l)) if [l.append(i-1) if i > 0 and s[i] == 'm' and s[i-1] == 's' and (i-1) not in l else (l.append(i+1) if s[i] == 'm' and i < len(s)-1 and s[i+1] == 's' else None) for i in range(len(s))] else None)(input(), []))) for t in range(int(input()))] -------------------------------------------------------------------------------- /codechef/snackdown_2017/Qualifier/TEMPLELA.py: -------------------------------------------------------------------------------- 1 | [(lambda _, hs: print("yes" if len(hs)%2==1 and all(i+1==j for i,j in enumerate(hs[:len(hs)//2])) and hs == list(reversed(hs)) else "no"))(input(), [int(x) for x in input().split()]) for p in range(int(input()))] 2 | -------------------------------------------------------------------------------- /codeforces/Good_Bye_2017/a.py: -------------------------------------------------------------------------------- 1 | s = input() 2 | ans = 0 3 | for i in s: 4 | if i in 'aeiou13579': 5 | ans += 1 6 | print(ans) -------------------------------------------------------------------------------- /codeforces/Hello_2018/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define ll long long 4 | #define ull unsigned long long 5 | using namespace std; 6 | 7 | int main(){ 8 | std::ios::sync_with_stdio(false); 9 | int n, m; 10 | cin >> n >> m; 11 | if(n > 33){ 12 | cout << m << endl; 13 | } else { 14 | cout << (m%(pow(2,n))) << endl; 15 | } 16 | return 0; 17 | } -------------------------------------------------------------------------------- /codeforces/Hello_2018/A.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | m = int(input()) 3 | 4 | if n > 33: 5 | print(m) 6 | else: 7 | print(m%(pow(2,n))) 8 | -------------------------------------------------------------------------------- /codeforces/Hello_2018/hack_a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define ll long long 4 | #define ull unsigned long long 5 | using namespace std; 6 | 7 | int main(){ 8 | std::ios::sync_with_stdio(false); 9 | // ll a, b, m; 10 | // cin >> b >> a; 11 | // m = pow(2,b); 12 | // cout << m << endl; 13 | // ll ans = a%m; 14 | // cout << ans << endl; 15 | int a, b; 16 | cin >> a >> b; 17 | int c = pow(2,a); 18 | if(b%c == 0){ 19 | cout << "0"; 20 | } else { 21 | cout << b%c; 22 | } 23 | return 0; 24 | } -------------------------------------------------------------------------------- /codeforces/april_fools_2021/a.py: -------------------------------------------------------------------------------- 1 | while True: 2 | try: 3 | a = input() 4 | except: 5 | break 6 | print("NO") -------------------------------------------------------------------------------- /codeforces/april_fools_2021/b.py: -------------------------------------------------------------------------------- 1 | # whoops it was supposed to be a Digital Sum 2 | a = input() 3 | print(sum(int(x) for x in a)) -------------------------------------------------------------------------------- /codeforces/april_fools_2021/c.py: -------------------------------------------------------------------------------- 1 | s = input() 2 | ords = [ord(x) - ord('A') for x in s] 3 | good = True 4 | for i in range(2, len(ords)): 5 | if (ords[i-2] + ords[i-1])%26 != ords[i]: 6 | good = False 7 | break 8 | if good: 9 | print("YES") 10 | else: 11 | print("NO") -------------------------------------------------------------------------------- /codeforces/april_fools_2021/f.py: -------------------------------------------------------------------------------- 1 | a = int(input()) 2 | print(-a + 2) -------------------------------------------------------------------------------- /codeforces/april_fools_2022/a.py: -------------------------------------------------------------------------------- 1 | BucketPotato -------------------------------------------------------------------------------- /codeforces/april_fools_2022/b.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | print(3000-n + 2999) -------------------------------------------------------------------------------- /codeforces/april_fools_2022/b.txt: -------------------------------------------------------------------------------- 1 | 3000 -------------------------------------------------------------------------------- /codeforces/codeton_round3_2022/a.py: -------------------------------------------------------------------------------- 1 | # based on the code of https://codeforces.com/profile/pajenegod and https://codeforces.com/profile/conqueror_of_tourist 2 | # for printing: they use print('\n'.join(map(str, out))) instead of for ...: print(ans) 3 | # use pypy 3-64 4 | import sys 5 | input = sys.stdin.readline 6 | 7 | T = int(input()) 8 | for t in range(T): 9 | n = int(input()) 10 | xs = [int(x) for x in input().split()] 11 | xmin = min(xs) 12 | if xs[0] == xmin: 13 | print("Yes") 14 | else: 15 | print("No") 16 | -------------------------------------------------------------------------------- /codeforces/codeton_round3_2022/c.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitamintK/AlgorithmProblems/7f3b88d15513c24424254a6b44a1a557267ea1c7/codeforces/codeton_round3_2022/c.py -------------------------------------------------------------------------------- /codeforces/deltix_spring_2021/b.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n = int(input()) 4 | xs = [int(x) for x in input().split()] 5 | print(6 * n//2) 6 | for i in range(n//2): 7 | a = i*2 + 1 8 | b = a+1 9 | print(1,a,b) 10 | print(1,a,b) 11 | print(2,a,b) 12 | print(1,a,b) 13 | print(1,a,b) 14 | print(2,a,b) 15 | -------------------------------------------------------------------------------- /codeforces/deltix_spring_2021/c.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n = int(input()) 4 | xs = [] 5 | for i in range(n): 6 | xs.append(int(input())) 7 | stack = [] 8 | for x in xs: 9 | if x == 1: 10 | stack.append(1) 11 | else: 12 | while x != stack[-1] + 1: 13 | stack.pop() 14 | stack[-1] += 1 15 | print('.'.join(str(y) for y in stack)) 16 | -------------------------------------------------------------------------------- /codeforces/edu_round105/d.py: -------------------------------------------------------------------------------- 1 | from collections import defaultdict 2 | n = int(input()) 3 | leaves = [] 4 | for i in range(n): 5 | xs = [int(x) for x in input().split()] 6 | leaves.append(xs) 7 | parent = dict() 8 | children = defaultdict(list) 9 | 10 | node_number = n 11 | # def dfs(leaves, parent): 12 | # global node_number 13 | # node = node_number 14 | # node_number +=1 15 | # segmentation = defaultdict(list) 16 | # for leaf in leaves: 17 | # ... 18 | 19 | dfs(leaves, None) -------------------------------------------------------------------------------- /codeforces/edu_round106/a.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n, k1, k2 = map(int, input().split()) 4 | w, b = map(int, input().split()) 5 | if w*2<=k1+k2 and b*2<=n*2-k1-k2: 6 | print("YES") 7 | else: 8 | print("NO") -------------------------------------------------------------------------------- /codeforces/edu_round106/b.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | s = input() 4 | leftmost_ones = None 5 | rightmost_zeroes = None 6 | for i in range(len(s)-1): 7 | if s[i]=='0' and s[i+1]=='0': 8 | rightmost_zeroes = i 9 | if s[i]=='1' and s[i+1]=='1' and leftmost_ones is None: 10 | leftmost_ones = i 11 | if leftmost_ones is not None and rightmost_zeroes is not None and leftmost_ones < rightmost_zeroes: 12 | print("NO") 13 | else: 14 | print("YES") -------------------------------------------------------------------------------- /codeforces/edu_round108/a.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | r, b, d = map(int, input().split()) 4 | x, y = min(r,b), max(r,b) 5 | if y > (x*(d+1)): 6 | print("NO") 7 | else: 8 | print("YES") -------------------------------------------------------------------------------- /codeforces/edu_round108/b.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n,m,k = map(int,input().split()) 4 | ans = n-1 + (m-1)*n 5 | # print(ans, k) 6 | if ans == k: 7 | print("YES") 8 | else: 9 | print("NO") -------------------------------------------------------------------------------- /codeforces/edu_round111/a.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | import bisect 3 | start = 1 4 | prev = 0 5 | arr = [] 6 | while start <= 5000: 7 | arr.append(start + prev) 8 | prev += start 9 | start += 2 10 | for t in range(T): 11 | s = int(input()) 12 | ans = bisect.bisect_left(arr, s) 13 | # print(arr[ans]) 14 | print(ans + 1) -------------------------------------------------------------------------------- /codeforces/edu_round111/b.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | 3 | def count_runs(s): 4 | ans = 0 5 | prev = '.' 6 | for x in s: 7 | if x != prev: 8 | ans += 1 9 | prev = x 10 | return ans 11 | 12 | for t in range(T): 13 | n,a,b = map(int, input().split()) 14 | s = input() 15 | if b > 0: 16 | ans = n * (a+b) 17 | else: 18 | runs = count_runs(s) 19 | actions = runs//2 + 1 20 | # print(actions) 21 | ans = actions * b + a * n 22 | print(ans) -------------------------------------------------------------------------------- /codeforces/edu_round111/d.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n,l,r = map(int, input().split()) 4 | mid = (l+r)/2 -------------------------------------------------------------------------------- /codeforces/edu_round112/a.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n = int(input()) 4 | if n%2==1: 5 | n += 1 6 | if n < 6: 7 | n = 6 8 | print(n * 2 + n//2) 9 | -------------------------------------------------------------------------------- /codeforces/edu_round112/b.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | w,h = map(int, input().split()) 4 | x,y,xx,yy = map(int, input().split()) 5 | ww,hh = map(int, input().split()) 6 | 7 | ans = 1123456789 8 | if ww + xx-x <= w: 9 | ans = min(ans, max(0, ww-x), max(0, ww-(w-xx))) 10 | if hh + yy-y <= h: 11 | ans = min(ans, max(0, hh-(h-yy)), max(0, hh-y)) 12 | if ans == 1123456789: 13 | print(-1) 14 | else: 15 | print(ans) -------------------------------------------------------------------------------- /codeforces/edu_round123/a.py: -------------------------------------------------------------------------------- 1 | from collections import defaultdict 2 | n = int(input()) 3 | for i in range(n): 4 | s = input() 5 | keys = defaultdict(bool) 6 | for x in s: 7 | if x==x.lower(): 8 | keys[x] = True 9 | else: 10 | if not keys[x.lower()]: 11 | print("NO") 12 | break 13 | else: 14 | print("YES") 15 | -------------------------------------------------------------------------------- /codeforces/edu_round123/b.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n = int(input()) 4 | if n == 3: 5 | print('3 2 1') 6 | print('1 3 2') 7 | print('3 1 2') 8 | else: 9 | l = list(reversed(range(1,n+1))) 10 | for i in range(n): 11 | print(' '.join(str(x) for x in l)) 12 | l = l[1:] + [l[0]] -------------------------------------------------------------------------------- /codeforces/edu_round128/a.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | l1,r1,l2,r2 = map(int, input().split()) 4 | ll = max(l1,l2) 5 | rr = min(r1,r2) 6 | if rr >= ll: 7 | print(ll) 8 | else: 9 | print(l1 + l2) -------------------------------------------------------------------------------- /codeforces/edu_round128/c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitamintK/AlgorithmProblems/7f3b88d15513c24424254a6b44a1a557267ea1c7/codeforces/edu_round128/c -------------------------------------------------------------------------------- /codeforces/edu_round128/d: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitamintK/AlgorithmProblems/7f3b88d15513c24424254a6b44a1a557267ea1c7/codeforces/edu_round128/d -------------------------------------------------------------------------------- /codeforces/edu_round145/a.py: -------------------------------------------------------------------------------- 1 | import sys 2 | input = sys.stdin.readline 3 | 4 | T = int(input()) 5 | for t in range(T): 6 | s = input().strip() 7 | if len(set(s)) == 1: 8 | print('-1') 9 | elif len(set(s))==4: 10 | print(4) 11 | elif len(set(s))==3: 12 | print(4) 13 | else: 14 | c = dict() 15 | for x in s: 16 | if x not in c: 17 | c[x] = 1 18 | else: 19 | c[x] += 1 20 | if c[x] == 2: 21 | print(4) 22 | else: 23 | print(6) -------------------------------------------------------------------------------- /codeforces/edu_round145/b.py: -------------------------------------------------------------------------------- 1 | import sys 2 | input = sys.stdin.readline 3 | import math 4 | from decimal import * 5 | getcontext().prec = 100 6 | T = int(input()) 7 | for t in range(T): 8 | n = int(input()) 9 | # print(math.sqrt(n)) 10 | d = math.ceil(Decimal(n).sqrt()) - 1 11 | print(d) -------------------------------------------------------------------------------- /codeforces/edu_round145/c.py: -------------------------------------------------------------------------------- 1 | import sys 2 | input = sys.stdin.readline 3 | 4 | T = int(input()) 5 | for t in range(T): 6 | n, k = map(int, input().split()) 7 | arr = [-1000] * n 8 | pos = 0 9 | for i in range(n): 10 | if pos + i+1 <= k: 11 | arr[i] = 2 12 | pos += i+1 13 | continue 14 | desire = k - pos 15 | arr[i] = - 2 * (i - desire) - 1 16 | break 17 | print(' '.join(str(x) for x in arr)) -------------------------------------------------------------------------------- /codeforces/edu_round146/a.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n, k = map(int, input().split()) 4 | if n%2 == 0: 5 | print("YES") 6 | continue 7 | if k%2 == 0: 8 | print("NO") 9 | continue 10 | if k > n: 11 | print("NO") 12 | continue 13 | print("YES") -------------------------------------------------------------------------------- /codeforces/edu_round146/b.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | import math 3 | from decimal import * 4 | def fn(a,b,k): 5 | return (k-1) + (a+k-1)//k + (b+k-1)//k 6 | for t in range(T): 7 | a, b = map(int, input().split()) 8 | k = int(Decimal(a+b).sqrt()) 9 | ans = a+b 10 | for i in range(-100,100): 11 | kk = k+i 12 | if kk < 1 or kk > a+b: 13 | continue 14 | ans = min(ans, fn(a,b,kk)) 15 | # x,y,z = fn(a,b,k), fn(a,b,k-2), fn(a,b,k+2) 16 | # assert x<=y and x<=z, (x,y,z) 17 | print(ans) -------------------------------------------------------------------------------- /codeforces/edu_round150/a.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n = int(input()) 4 | if n == 2 or n == 3 or n == 4: 5 | print("Bob") 6 | else: 7 | print("Alice") -------------------------------------------------------------------------------- /codeforces/edu_round169/a.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n = int(input()) 4 | xs = [int(x) for x in input().split()] 5 | if n == 1: 6 | print("YES") 7 | elif n == 2: 8 | if abs(xs[0] - xs[1]) == 1: 9 | print("NO") 10 | else: 11 | print("YES") 12 | else: 13 | print("NO") 14 | -------------------------------------------------------------------------------- /codeforces/edu_round169/b.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | l, r = map(int, input().split()) 4 | L, R = map(int, input().split()) 5 | if L < l: 6 | l, r, L, R = L, R, l, r 7 | if l == L and r == R: 8 | print(R - L) 9 | elif r < L: 10 | print(1) 11 | else: 12 | i = min(r, R) - max(l, L) 13 | if r == R or l == L: 14 | print(i + 1) 15 | else: 16 | print(i + 2) 17 | -------------------------------------------------------------------------------- /codeforces/edu_round169/c.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n, k = map(int, input().split()) 4 | xs = [int(x) for x in input().split()] 5 | xs.sort(reverse=True) 6 | makeup = 0 7 | score = 0 8 | for i in range(n): 9 | if i%2 == 1: 10 | makeup += xs[i-1] - xs[i] 11 | score -= xs[i] 12 | else: 13 | score += xs[i] 14 | score -= min(makeup, k) 15 | print(score) 16 | -------------------------------------------------------------------------------- /codeforces/edu_round32/A.py: -------------------------------------------------------------------------------- 1 | n, k = map(int, input().split()) 2 | xs = [int(x) for x in input().split()] 3 | print(k//max(x for x in xs if k%x==0)) -------------------------------------------------------------------------------- /codeforces/edu_round32/B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define ll long long 5 | #define ull unsigned long long 6 | using namespace std; 7 | 8 | int main(){ 9 | std::ios::sync_with_stdio(false); 10 | int n, pos, l, r; 11 | cin >> n >> pos >> l >> r; 12 | int ans = 0; 13 | if(l>1 && r < n){ 14 | ans += (r-l); 15 | ans += min(abs(l - pos), abs(r - pos)); 16 | ans += 2; 17 | } else if(l>1){ 18 | ans += abs(l - pos) + 1; 19 | } else if(r < n){ 20 | ans += abs(r-pos) + 1; 21 | } 22 | cout << ans << endl; 23 | return 0; 24 | } -------------------------------------------------------------------------------- /codeforces/edu_round32/C.py: -------------------------------------------------------------------------------- 1 | a = list(input()) 2 | b = input() 3 | a.sort(reverse=True) 4 | ans = [] 5 | equal_so_far = True 6 | if len(a) < len(b): 7 | print(''.join(a)) 8 | exit() 9 | for i in range(len(b)): 10 | for digit in a: 11 | c = a[:] 12 | c.remove(digit) 13 | #print(sorted(c), sorted(b[i+1:])) 14 | if not equal_so_far or digit < b[i] or (digit==b[i] and list(sorted(c)) <= list(b[i+1:])): 15 | if b[i] != digit: 16 | equal_so_far = False 17 | ans.append(digit) 18 | a.remove(digit) 19 | break 20 | print(''.join(ans)) -------------------------------------------------------------------------------- /codeforces/edu_round42/A.py: -------------------------------------------------------------------------------- 1 | n= int(input()) 2 | l = [int(x) for x in input().split()] 3 | s = sum(l) 4 | k= 0 5 | for i in range(n): 6 | k+= l[i] 7 | if k >= s//2: 8 | print(i+1) 9 | break 10 | -------------------------------------------------------------------------------- /codeforces/edu_round51/b.py: -------------------------------------------------------------------------------- 1 | l, r = map(int, input().split()) 2 | print("YES") 3 | i = l 4 | while i < r: 5 | print(i, i+1) 6 | i+=2 -------------------------------------------------------------------------------- /codeforces/edu_round93/a.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n = int(input()) 4 | xs = [int(x) for x in input().split()] 5 | # for i in range(len(xs)-2): 6 | # if xs[i]+xs[i+1] >= xs[i+2]: 7 | # print(i+1, i+2, i+3) 8 | # break 9 | # else: 10 | # print(-1) 11 | # lol I thought the prompt was the inverse 12 | if xs[0] + xs[1] <= xs[len(xs)-1]: 13 | print(1, 2, len(xs)) 14 | else: 15 | print(-1) -------------------------------------------------------------------------------- /codeforces/edu_round93/b.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | s = input() 4 | blocks = s.split('0') 5 | size = [len(block) for block in blocks] 6 | ans = 0 7 | for i, x in enumerate(sorted(size, reverse=True)): 8 | if i%2 == 0: 9 | ans += x 10 | print(ans) -------------------------------------------------------------------------------- /codeforces/edu_round93/c.py: -------------------------------------------------------------------------------- 1 | from collections import defaultdict 2 | T = int(input()) 3 | for t in range(T): 4 | n = int(input()) 5 | xs = [int(x) for x in input()] 6 | seen = defaultdict(int) 7 | ans = 0 8 | cum = 0 9 | seen[cum]+=1 10 | for i, x in enumerate(xs): 11 | x-=1 12 | cum+=x 13 | ans += seen[cum] 14 | seen[cum]+=1 15 | print(ans) -------------------------------------------------------------------------------- /codeforces/edu_round93/readme.md: -------------------------------------------------------------------------------- 1 | [Educational Codeforces Round 93](https://codeforces.com/contest/1398) 2 | 3 | solved 4/7 4 | 5 | rank 1537 out of X 6 | 7 | 5 incorrect submissions for D because I thought greedy would work, and then because python and pypy were too slow, so I rewrote it in Go. 8 | 9 | Problem titles: 10 | - Bad Triangle 11 | - Substring Removal Game 12 | - Good Subarrays 13 | - Colored Rectangles 14 | 15 | and then I couldn't do E because neither python nor golang has a BST in the stdlib ;_; 16 | 17 | I guess I really do need to pick up C++ again ;_; -------------------------------------------------------------------------------- /codeforces/edu_round94/a.py: -------------------------------------------------------------------------------- 1 | T =int(input()) 2 | for t in range(T): 3 | n = int(input()) 4 | s = input() 5 | g = s[n-1] 6 | print(''.join(g*n)) -------------------------------------------------------------------------------- /codeforces/global_round10/a.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n = int(input()) 4 | xs = [int(x) for x in input().split()] 5 | if len(set(xs)) == 1: 6 | print(len(xs)) 7 | else: 8 | print(1) -------------------------------------------------------------------------------- /codeforces/global_round10/c.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n = int(input()) 4 | xs = [int(x) for x in input().split()] 5 | ans = 0 6 | for i in reversed(range(1, n)): 7 | if xs[i-1]> xs[i]: 8 | ans += xs[i-1]-xs[i] 9 | print(ans) -------------------------------------------------------------------------------- /codeforces/global_round14/a.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n, k= map(int, input().split()) 4 | ws = [int(x) for x in input().split()] 5 | tot = 0 6 | can = True 7 | for i in range(n): 8 | if tot+ws[i] == k: 9 | if i == n-1: 10 | can = False 11 | break 12 | else: 13 | ws[i+1], ws[i] = ws[i], ws[i+1] 14 | tot += ws[i] 15 | if can: 16 | print("YES") 17 | print(*ws) 18 | else: 19 | print("NO") 20 | -------------------------------------------------------------------------------- /codeforces/global_round14/b.py: -------------------------------------------------------------------------------- 1 | #### ????? 2 | import math 3 | T = int(input()) 4 | def is_square(n): 5 | return n//math.sqrt(n) == math.sqrt(n) 6 | 7 | for t in range(T): 8 | n = int(input()) 9 | if(n%2 == 1): 10 | print("NO") 11 | continue 12 | while(n%2==0): 13 | n//=2 14 | if is_square(n): 15 | print("YES") 16 | else: 17 | print("NO") -------------------------------------------------------------------------------- /codeforces/global_round14/c.py: -------------------------------------------------------------------------------- 1 | from heapq import heappush, heappop 2 | T = int(input()) 3 | for t in range(T): 4 | n,m,x = map(int, input().split()) 5 | hs = [int(h) for h in input().split()] 6 | ms = [] 7 | ans = [] 8 | for i in range(m): 9 | heappush(ms, (0,i)) 10 | for i in range(n): 11 | h = hs[i] 12 | c, tower = heappop(ms) 13 | ans.append(tower+1) 14 | heappush(ms, (c+h, tower)) 15 | print("YES") 16 | print(*ans) -------------------------------------------------------------------------------- /codeforces/global_round7/a_bad_ugly_numbers.py: -------------------------------------------------------------------------------- 1 | # https://codeforces.com/contest/1326/problem/A 2 | T = int(input()) 3 | for t in range(T): 4 | n = int(input()) 5 | if n == 1: 6 | print(-1) 7 | continue 8 | for i in range(2,10): 9 | ans = str(i)*(n-1) 10 | for k in [3,4,6,7,8,9]: 11 | cand = int(ans+str(k)) 12 | if cand%k == 0 or cand%i == 0: 13 | continue 14 | ans += str(k) 15 | print(ans) 16 | break 17 | else: 18 | continue 19 | break -------------------------------------------------------------------------------- /codeforces/global_round7/b_maximums.py: -------------------------------------------------------------------------------- 1 | # https://codeforces.com/contest/1326/problem/B 2 | 3 | n = int(input()) 4 | xs = [int(x) for x in input().split()] 5 | 6 | ans = [] 7 | pmax = 0 8 | for x in xs: 9 | ans.append(x + pmax) 10 | pmax = max(ans[-1], pmax) 11 | print(' '.join(str(x) for x in ans)) -------------------------------------------------------------------------------- /codeforces/indiahacks/bear_and_three_balls.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main(){ 5 | int k; 6 | cin >> k; 7 | vector r(1001, 0); 8 | int l; 9 | for(int i = 0; i < k; i++){ 10 | cin >> l; 11 | r[l] = 1; 12 | } 13 | int count = 0; 14 | for(int i = 1; i < 1001; i++){ 15 | if(r[i] == 1){ 16 | count++; 17 | } else { 18 | count = 0; 19 | } 20 | if(count == 3){ 21 | cout << "YES" << endl; 22 | return 0; 23 | } 24 | } 25 | cout << "NO" << endl; 26 | return 0; 27 | } -------------------------------------------------------------------------------- /codeforces/indiahacks/bear_and_up_down.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | 9 | int main(){ 10 | long n; 11 | long t; 12 | long previous; 13 | cin >> n; 14 | vector v; 15 | for(long i = 0; i < n; i++){ 16 | cin >> t; 17 | v.push_back(t); 18 | } 19 | vector bads; 20 | for(long i = 0; i < n; i++){ 21 | if(i != 0 && i != n-1){ 22 | if((v[i-1] > v[i]) == (v[i] > v[i+1])){ 23 | bads.push_back() 24 | } 25 | } 26 | } 27 | return 0; 28 | } -------------------------------------------------------------------------------- /codeforces/round344/interview.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main(){ 5 | int n; 6 | 7 | cin >> n; 8 | int o; 9 | int currenta = 0; 10 | int currentb = 0; 11 | for(int i = 0; i < n; i++){ 12 | cin >> o; 13 | currenta |= o; 14 | } 15 | for(int i = 0; i < n; i++){ 16 | cin >> o; 17 | currentb |= o; 18 | } 19 | 20 | 21 | 22 | cout << currenta+currentb; 23 | 24 | return 0; 25 | } -------------------------------------------------------------------------------- /codeforces/round345/joysticks.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(){ 4 | int n, m; 5 | int count = 0; 6 | scanf("%d %d", &n, &m); 7 | while(n != 0 && m != 0 && !(n<=1 && m<=1)){ 8 | if(n > m){ 9 | m++; 10 | n-=2; 11 | } else { 12 | n++; 13 | m-=2; 14 | } 15 | count++; 16 | } 17 | cout << count; 18 | return 0; 19 | } -------------------------------------------------------------------------------- /codeforces/round345/table_compression.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main(){ 7 | long n, m; 8 | scanf("%ld %ld", &n, &m); 9 | vector > grid(n); 10 | //long max_value = 0; 11 | //pair max_pos; 12 | long num; 13 | for(long i = 0; i < n; i++){ 14 | for(long j = 0; j < m; j++){ 15 | scanf("%ld", &num); 16 | //if(num > max_value){ 17 | //max_value = num; 18 | //max_pos = make_pair(i, j); 19 | //} 20 | grid[i].push_back() 21 | } 22 | } 23 | return 0; 24 | } -------------------------------------------------------------------------------- /codeforces/round346/new_reform.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | 10 | int main(){ 11 | long long n, m; 12 | 13 | return 0; 14 | } -------------------------------------------------------------------------------- /codeforces/round346/round_house.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | 9 | int main(){ 10 | int n, a, b; 11 | cin >> n >> a >> b; 12 | cout << (n-1 + a-1)%b + 1; 13 | return 0; 14 | } -------------------------------------------------------------------------------- /codeforces/round350/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | //ios::sync_with_stdio(false); 8 | 9 | int main() { 10 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 11 | int T; 12 | cin >> T; 13 | int k = T%7; 14 | if(k>2){ 15 | k = 2; 16 | } 17 | cout << ((T+2)/7) << " " << (T/7)+k; 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /codeforces/round355/A_vanya_and_fence.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | 9 | int main(){ 10 | int n, h; 11 | cin >> n >> h; 12 | int a; 13 | int ans = 0; 14 | for(int i = 0; i < n; i++){ 15 | cin >> a; 16 | ans+= (a>h)?2: 1; 17 | } 18 | cout << ans; 19 | } -------------------------------------------------------------------------------- /codeforces/round358/A_alyona_and_numbers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | int main(){ 11 | long long n, m; 12 | cin >> n >> m; 13 | long long ans = 0; 14 | for(int i = 0; i < 5; i++){ 15 | ans+=((n/5)+(n%5 >= i) - (i == 0))*((m/5) + (m%5 >= (5-i)) - (1 == 0)); 16 | } 17 | cout << ans; 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /codeforces/round375/b_sample.txt: -------------------------------------------------------------------------------- 1 | 5 2 | (___) -------------------------------------------------------------------------------- /codeforces/round375/d_sample.txt: -------------------------------------------------------------------------------- 1 | 50 50 43 2 | .*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* 3 | *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*. 4 | .*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* 5 | *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*. 6 | .*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* 7 | *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*. 8 | .*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* 9 | *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*. 10 | .*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* 11 | *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*... -------------------------------------------------------------------------------- /codeforces/round375/e_sample.txt: -------------------------------------------------------------------------------- 1 | 2 2 | 5 5 3 | 2 1 4 | 4 5 5 | 2 3 6 | 1 3 7 | 3 5 8 | 7 2 9 | 4 3 10 | 4 2 -------------------------------------------------------------------------------- /codeforces/round376/C_sample.txt: -------------------------------------------------------------------------------- 1 | 3 3 3 2 | 2 3 3 3 | 1 2 4 | 2 1 5 | 1 3 -------------------------------------------------------------------------------- /codeforces/round376/D_sample.txt: -------------------------------------------------------------------------------- 1 | 4 3 2 | 2 3 2 3 | 1 1 4 | 3 2 3 1 5 | 4 2 3 1 2 -------------------------------------------------------------------------------- /codeforces/round379/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define ll long long 4 | using namespace std; 5 | 6 | int main(){ 7 | ll ans = 0; 8 | ll p; 9 | cin >> p; 10 | string n; 11 | cin >> n; 12 | for(int i = 0; i < n.length(); i++){ 13 | if(n[i] == 'A'){ 14 | ans++; 15 | } else { 16 | ans--; 17 | } 18 | } 19 | if (ans == 0){ 20 | cout << "Friendship" << endl; 21 | } else if(ans < 0){ 22 | cout << "Danik" << endl; 23 | } else { 24 | cout << "Anton" << endl; 25 | } 26 | } -------------------------------------------------------------------------------- /codeforces/round379/B_digits.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define ll long long 4 | using namespace std; 5 | 6 | int main(){ 7 | //2, 3, 5, 6 8 | ll a, b, c, d; 9 | cin >> a >> b >> c >> d; 10 | ll bigs = 0; 11 | ll smalls = 0; 12 | bigs = min({a, c, d}); 13 | a -= bigs; 14 | c-= bigs; 15 | d-= bigs; 16 | smalls = min(a, b); 17 | cout << smalls*32 + bigs*256 << endl; 18 | } -------------------------------------------------------------------------------- /codeforces/round380/A.txt: -------------------------------------------------------------------------------- 1 | 13 2 | ogogmgogogogo -------------------------------------------------------------------------------- /codeforces/round385/A.py: -------------------------------------------------------------------------------- 1 | s = input() 2 | ss = set() 3 | for i in range(len(s)): 4 | ss.add(s[i:] + s[:i]) 5 | print(len(ss)) 6 | -------------------------------------------------------------------------------- /codeforces/round387/a.py: -------------------------------------------------------------------------------- 1 | n = int(input().strip()) 2 | import math 3 | for i in range(1, int(1+math.sqrt(n))): 4 | if n%i == 0: 5 | p = i 6 | p = min(p, n/p) 7 | n = n//p 8 | print(p, n) 9 | -------------------------------------------------------------------------------- /codeforces/round387/b.py: -------------------------------------------------------------------------------- 1 | n = int(input().strip()) 2 | s = input().strip() 3 | from collections import Counter 4 | c = Counter(s) 5 | if n%4 != 0: 6 | print("===") 7 | exit() 8 | correct = n//4 9 | inputs = ['A']*(correct-c['A']) + ['G']*(correct-c['G']) + ['C']*(correct-c['C']) + ['T']*(correct-c['T']) 10 | s = list(s) 11 | for ind, i in enumerate(s): 12 | if i == '?': 13 | s[ind] = inputs.pop() 14 | if(len(inputs) > 0): 15 | print("===") 16 | else: 17 | print(''.join(s)) 18 | -------------------------------------------------------------------------------- /codeforces/round391/A.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | s = input().strip() 3 | c = Counter(s) 4 | word = Counter("Bulbasaur") 5 | ans = min(c[i]//word[i] for i in word) 6 | print(ans) 7 | -------------------------------------------------------------------------------- /codeforces/round391/Bhack.py: -------------------------------------------------------------------------------- 1 | print(100000) 2 | import random 3 | print(' '.join([str(i) for i in range(1,100001)])) 4 | -------------------------------------------------------------------------------- /codeforces/round391/D.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | using namespace std; 4 | int main(){ 5 | std::ios::sync_with_stdio(false); 6 | 7 | return 0; 8 | } -------------------------------------------------------------------------------- /codeforces/round392/a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | using namespace std; 4 | int main(){ 5 | std::ios::sync_with_stdio(false); 6 | ll n; 7 | ll maxx = -1; 8 | cin >> n; 9 | vector as(n); 10 | for(ll i = 0; i < n; i++){ 11 | cin >> as[i]; 12 | maxx = max(maxx, as[i]); 13 | } 14 | ll ans = 0; 15 | for(ll i = 0; i < n; i++){ 16 | ans += maxx - as[i]; 17 | } 18 | cout << ans; 19 | return 0; 20 | } -------------------------------------------------------------------------------- /codeforces/round394/a.py: -------------------------------------------------------------------------------- 1 | a, b = [int(x) for x in input().split()] 2 | if(a == 0 and b==0): 3 | print("NO") 4 | else: 5 | print("YES" if abs(a-b) <= 1 else "NO") 6 | -------------------------------------------------------------------------------- /codeforces/round400/A.py: -------------------------------------------------------------------------------- 1 | a, b = input().strip().split() 2 | n = int(input()) 3 | for i in range(n): 4 | print(a, b) 5 | c, d = input().strip().split() 6 | if a == c: 7 | a = d 8 | else: 9 | b = d 10 | print(a, b) 11 | -------------------------------------------------------------------------------- /codeforces/round408/a.py: -------------------------------------------------------------------------------- 1 | n, m, k = [int(x) for x in input().split()] 2 | costs = [int(x) for x in input().split()] 3 | ans = 10000000000 4 | m = m-1 5 | for index, cost in enumerate(costs): 6 | if cost != 0 and cost <= k: 7 | ans = min(ans, abs(m-index)) 8 | print(ans*10) 9 | -------------------------------------------------------------------------------- /codeforces/round410/a.py: -------------------------------------------------------------------------------- 1 | s = input() 2 | n = 0 3 | for i in range(len(s)): 4 | if s[i] != s[-i-1]: 5 | n+=1 6 | #print(s[i]) 7 | if(n == 2) or (n == 0 and len(s)%2 == 1): 8 | print("YES") 9 | else: 10 | print("NO") 11 | -------------------------------------------------------------------------------- /codeforces/round410/c.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define ll long long 5 | #define ull unsigned long long 6 | using namespace std; 7 | int main(){ 8 | std::ios::sync_with_stdio(false); 9 | int n; 10 | cin >> n; 11 | vector as(n); 12 | for(int i = 0; i < n; i++){ 13 | ll a; 14 | cin >> a[i]; 15 | } 16 | return 0; 17 | } -------------------------------------------------------------------------------- /codeforces/round410/c.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | a = map(int, input().split()) 3 | import math 4 | def get_primes(num): 5 | p = num 6 | primes = [] 7 | for i in range(2,int(math.sqrt(num))+1): 8 | if num%i == 0: 9 | primes.append(i) 10 | while(p%i == 0): 11 | p//=i 12 | if(p != 1): 13 | primes.append(p) 14 | return primes 15 | 16 | print(get_primes(1)) 17 | -------------------------------------------------------------------------------- /codeforces/round411/a.py: -------------------------------------------------------------------------------- 1 | a, b = map(int, input().split()) 2 | if(a == b): 3 | print(a) 4 | else: 5 | print(2) 6 | -------------------------------------------------------------------------------- /codeforces/round411/b.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | print(('aabb'*100000)[:n]) 3 | -------------------------------------------------------------------------------- /codeforces/round413/a.py: -------------------------------------------------------------------------------- 1 | n, t, k, d = map(int, input().split()) 2 | t1 = t*((n+k-1)//k) 3 | #t2 = d + t * ((n+2*k-1)//(2*k)) 4 | n2 = 0 5 | t2 = 0 6 | while n2 < n: 7 | t2 += 1 8 | if t2%t == 0: 9 | n2 += k 10 | if (t2-d)%t == 0 and t2-d > 0: 11 | n2 += k 12 | 13 | #print(t1, t2) 14 | if t2 < t1: 15 | print("YES") 16 | else: 17 | print("NO") 18 | #print(t1, d, t) 19 | #if d + t >= t1: 20 | # print("NO") 21 | #else: 22 | # print("YES") 23 | -------------------------------------------------------------------------------- /codeforces/round413/c.in2: -------------------------------------------------------------------------------- 1 | 3 10 10 2 | 4 7 C 3 | 4 4 C 4 | 5 1 C 5 | 1 30 D 6 | 1 30 D -------------------------------------------------------------------------------- /codeforces/round426/A.py: -------------------------------------------------------------------------------- 1 | first, last = input().split() 2 | n = int(input()) 3 | directions = {"^":0, ">":1, "v":2, "<":3} 4 | first = directions[first] 5 | last = directions[last] 6 | cw = False 7 | ccw = False 8 | if (last - first)%4 == n%4: 9 | cw = True 10 | if (first - last)%4 == n%4: 11 | ccw = True 12 | 13 | if ccw and not cw: 14 | print("ccw") 15 | elif cw and not ccw: 16 | print("cw") 17 | else: 18 | print("undefined") -------------------------------------------------------------------------------- /codeforces/round435/a.py: -------------------------------------------------------------------------------- 1 | n, x = map(int, input().split()) 2 | xs = [int(i) for i in input().split()] 3 | smaller_than_x = [p for p in xs if p < x] 4 | print(x - smaller_than_x + int(x in xs)) -------------------------------------------------------------------------------- /codeforces/round435/c.py: -------------------------------------------------------------------------------- 1 | n, x = map(int, input().split()) 2 | ans = [] 3 | xor = 0 4 | 5 | if n == 1: 6 | print("YES") 7 | print(x) 8 | exit() 9 | 10 | if n == 2 and x == 0: 11 | print("NO") 12 | exit() 13 | 14 | for i in range(1,n+1): 15 | ans.append(i) 16 | xor ^= i 17 | to_add = xor ^ x 18 | 19 | if to_add != 0: 20 | if to_add == 3: 21 | if n >= 3: 22 | ans[2] = 0 23 | else: 24 | ans[0] ^= 262144 25 | ans[1] ^= 262144 ^ to_add 26 | 27 | if len(ans) == n: 28 | print("YES") 29 | print(" ".join(str(i) for i in ans)) 30 | else: 31 | print("NO") -------------------------------------------------------------------------------- /codeforces/round435/d_playground.py: -------------------------------------------------------------------------------- 1 | import random 2 | number = [random.randint(0,1) for x in range(15)] 3 | for i in range(15): 4 | guess = input() 5 | if guess == "done": 6 | print(number) 7 | break 8 | print(sum(int(a) != int(b) for a,b in zip(guess, number))) -------------------------------------------------------------------------------- /codeforces/round439/a.py: -------------------------------------------------------------------------------- 1 | n= int(input()) 2 | a = [int(x) for x in input().split()] 3 | b = [int(x) for x in input().split()] 4 | s = set(a) | set(b) 5 | ans = 0 6 | for i in a: 7 | for j in b: 8 | if i ^ j in s: 9 | ans += 1 10 | if ans%2 == 0: 11 | print("Karen") 12 | else: 13 | print("Koyomi") 14 | -------------------------------------------------------------------------------- /codeforces/round439/b.py: -------------------------------------------------------------------------------- 1 | a, b = map(int, input().split()) 2 | ans = 1 3 | for i in range(a+1, b+1): 4 | ans*= i 5 | if ans%10 == 0: 6 | break 7 | print(ans%10) 8 | -------------------------------------------------------------------------------- /codeforces/round444/a.py: -------------------------------------------------------------------------------- 1 | s = input() 2 | s2 = '1000000' 3 | p = 0 4 | for i in s: 5 | if p >= len(s2): 6 | break 7 | if i == s2[p]: 8 | p+=1 9 | if p >= len(s2): 10 | print('yes') 11 | else: 12 | print('no') 13 | -------------------------------------------------------------------------------- /codeforces/round449/a.py: -------------------------------------------------------------------------------- 1 | n, m = map(int, input().split()) 2 | s = list(input()) 3 | for i in range(m): 4 | l, r, c1, c2 = input().split() 5 | l, r = map(int, (l,r)) 6 | for j in range(l-1, r): 7 | if s[j] == c1: 8 | s[j] = c2 9 | print(''.join(s)) 10 | -------------------------------------------------------------------------------- /codeforces/round449/c_test.py: -------------------------------------------------------------------------------- 1 | n = 10 2 | def make_string(n): 3 | if n == 0: 4 | return 'What are you doing at the end of the world? Are you busy? Will you save us?' 5 | m = make_string(n-1) 6 | return 'What are you doing while sending "' + m + '"? Are you busy? Will you send "' + m + '"?' 7 | print(make_string(2)) 8 | -------------------------------------------------------------------------------- /codeforces/round449/d.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define ll long long 4 | #define ull unsigned long long 5 | using namespace std; 6 | 7 | int main(){ 8 | std::ios::sync_with_stdio(false); 9 | 10 | return 0; 11 | } -------------------------------------------------------------------------------- /codeforces/round451/a.py: -------------------------------------------------------------------------------- 1 | a = int(input()) 2 | if a%10 > 5: 3 | print(a - (a%10) + 10) 4 | else: 5 | print(a - (a%10)) -------------------------------------------------------------------------------- /codeforces/round451/b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define ll long long 4 | #define ull unsigned long long 5 | using namespace std; 6 | 7 | int main(){ 8 | std::ios::sync_with_stdio(false); 9 | ll n, a, b; 10 | cin >> n >> a >> b; 11 | for(ll i = 0; i < 100000005; i++){ 12 | if(a*i > n){ 13 | break; 14 | } 15 | if(((n - a*i)%b) == 0){ 16 | cout << "YES" << endl; 17 | cout << i << " " << ((n - a*i)/b) << endl; 18 | return 0; 19 | } 20 | } 21 | cout << "NO" << endl; 22 | return 0; 23 | } -------------------------------------------------------------------------------- /codeforces/round451/b.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitamintK/AlgorithmProblems/7f3b88d15513c24424254a6b44a1a557267ea1c7/codeforces/round451/b.py -------------------------------------------------------------------------------- /codeforces/round451/test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define ll long long 4 | #define ull unsigned long long 5 | using namespace std; 6 | 7 | int main(){ 8 | std::ios::sync_with_stdio(false); 9 | int n; 10 | cin >> n; 11 | cout << n << endl; 12 | return 0; 13 | } -------------------------------------------------------------------------------- /codeforces/round452/a.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | l = [int(x) for x in input().split()] 3 | from collections import Counter 4 | a = Counter(l) 5 | ans = 0 6 | ans += min(a[2], a[1]) 7 | a[1] -= ans 8 | ans += a[1]//3 9 | print(ans) -------------------------------------------------------------------------------- /codeforces/round452/b.py: -------------------------------------------------------------------------------- 1 | calendar = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] * 3 + [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] 2 | calendar = calendar + calendar 3 | 4 | n = int(input()) 5 | l = [int(x) for x in input().split()] 6 | 7 | ans = "NO" 8 | for i in range(len(calendar)): 9 | if i+n > len(calendar): 10 | break 11 | if l == calendar[i:i+n]: 12 | ans = "YES" 13 | break 14 | print(ans) 15 | -------------------------------------------------------------------------------- /codeforces/round452/c.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | # a = [] 3 | # b = [] 4 | # for i in range(1, n+1): 5 | # if (i//2)%2 == 0: 6 | # a.append(i) 7 | # else: 8 | # b.append(i) 9 | # print(abs(sum(a) - sum(b))) 10 | # print(len(a), ' '.join(str(x) for x in a)) 11 | 12 | l = list(range(1, n+1)) 13 | a = [] 14 | target = (n * (n+1))//4 15 | accum = 0 16 | for i in reversed(l): 17 | if accum + i <= target: 18 | a.append(i) 19 | accum += i 20 | 21 | print(abs(accum - (n*(n+1))//2 + accum)) 22 | print(len(a), ' '.join(str(x) for x in a)) 23 | -------------------------------------------------------------------------------- /codeforces/round457/a.py: -------------------------------------------------------------------------------- 1 | x = int(input()) 2 | hh, mm = map(int, input().split()) 3 | i= 0 4 | while(True): 5 | if str(hh).find('7') >= 0 or str(mm).find('7') >= 0: 6 | break 7 | mm -= x 8 | if mm < 0: 9 | mm %= 60 10 | hh -= 1 11 | hh %= 24 12 | i+=1 13 | print(i) 14 | -------------------------------------------------------------------------------- /codeforces/round458/a.py: -------------------------------------------------------------------------------- 1 | s = set() 2 | for i in range(1001): 3 | s.add(i*i) 4 | n = input() 5 | xs = [int(x) for x in input().split()] 6 | print(max(x for x in xs if x not in s)) 7 | -------------------------------------------------------------------------------- /codeforces/round458/ahacktest.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define ll long long 5 | #define ull unsigned long long 6 | using namespace std; 7 | 8 | int main(){ 9 | std::ios::sync_with_stdio(false); 10 | cout << sqrt(-16) << endl; 11 | cout << (double)(sqrt(-16)) << endl; 12 | cout << (int)(sqrt(-16)) << endl; 13 | ll n = 677329; 14 | if((double)(sqrt(n)) == (int)(sqrt(n))){ 15 | cout << "it is equal" << endl; 16 | } 17 | return 0; 18 | } -------------------------------------------------------------------------------- /codeforces/round458/b.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | n = input() 3 | xs = Counter([int(x) for x in input().split()]) 4 | if any(xs[x]%2 == 1 for x in xs): 5 | print("Conan") 6 | else: 7 | print("Agasa") 8 | -------------------------------------------------------------------------------- /codeforces/round469/a.py: -------------------------------------------------------------------------------- 1 | l, r, a = map(int, input().split()) 2 | small, big = sorted((l, r)) 3 | if big-small > a: 4 | print(2* (small+a)) 5 | else: 6 | a-=(big-small) 7 | print(2*(big + a//2)) 8 | -------------------------------------------------------------------------------- /codeforces/round469/bsample.py: -------------------------------------------------------------------------------- 1 | import random 2 | s = [] 3 | #for i in range(20000): 4 | #s.append(random.choice("01")) 5 | for i in range(20000): 6 | s.append('0') 7 | #for i in range(10000): 8 | # s.append('1') 9 | print(''.join(s)) 10 | -------------------------------------------------------------------------------- /codeforces/round469/d.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define ll long long 5 | #define ull unsigned long long 6 | using namespace std; 7 | 8 | int main(){ 9 | std::ios::sync_with_stdio(false); 10 | ll n; 11 | int q; 12 | cin >> n >> q; 13 | for(int i = 0; i < q; i++){ 14 | ll x; 15 | cin >> x; 16 | while(x%2 != 1){ 17 | ll already_in_place = x/2; 18 | ll not_in_place = n-already_in_place; 19 | x = x+not_in_place; 20 | } 21 | cout << (x+1)/2 << endl; 22 | } 23 | return 0; 24 | } -------------------------------------------------------------------------------- /codeforces/round476/A.py: -------------------------------------------------------------------------------- 1 | k, n, s, p = map(int, input().split()) 2 | sheets_per_person = (n+s-1)//s 3 | sheets = sheets_per_person*k 4 | print((sheets+p-1)//p) 5 | -------------------------------------------------------------------------------- /codeforces/round476/D_frogs_stones.py: -------------------------------------------------------------------------------- 1 | l, w = map(int, input().split()) 2 | 3 | s = [int(x) for x in input().split()] 4 | 5 | from queue import Queue 6 | queue_frogs = Queue() 7 | stack_stones = [] 8 | 9 | stack_frogs 10 | 11 | for i in range(len(s)): 12 | 13 | -------------------------------------------------------------------------------- /codeforces/round505/A.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | s = input() 3 | cnt = 0 4 | for i in set(s): 5 | if s.count(i) != 1: 6 | cnt +=1 7 | 8 | if cnt > 0 or len(s) == 1: 9 | print("Yes") 10 | else: 11 | print("No") 12 | -------------------------------------------------------------------------------- /codeforces/round508/B.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | if n == 1: 3 | print("No") 4 | elif n == 2: 5 | print("No") 6 | else: 7 | print("Yes") 8 | if n%2 == 0: 9 | A = n//2 10 | else: 11 | A = (n+1)//2 12 | print(1, A) 13 | print(n-1, **[b for b in range(1,n+1) if b != A]) 14 | -------------------------------------------------------------------------------- /codeforces/round508/a.py: -------------------------------------------------------------------------------- 1 | n, k = map(int, input().split()) 2 | s = input() 3 | alph = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 4 | mn = 10000000 5 | for i in range(k): 6 | mn = min(mn, s.count(alph[i])) 7 | print(mn*k) -------------------------------------------------------------------------------- /codeforces/round513/a.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | from collections import Counter 3 | s = Counter(input()) 4 | digs = 0 5 | eights = None 6 | for i in range(10): 7 | if str(i) == '8': 8 | if str(i) in s: 9 | eights = s[str(i)] 10 | else: 11 | eights = 0 12 | else: 13 | if str(i) in s: 14 | digs += s[str(i)] 15 | ans = 0 16 | for i in range(15): 17 | if i > eights: 18 | break 19 | eightz = i 20 | oth = digs + (eights - i) 21 | ans = max(ans, min(oth//10, eightz)) 22 | print(ans) 23 | 24 | -------------------------------------------------------------------------------- /codeforces/round513/b.py: -------------------------------------------------------------------------------- 1 | #1998 2 | #1000000 3 | 4 | n = input() 5 | ans = 0 6 | carry = 0 7 | for i in range(len(n)): 8 | if i == len(n) -1: 9 | to_make = carry + int(n[i]) 10 | ans += to_make 11 | else: 12 | to_make = carry + int(n[i]) 13 | if to_make > 0: 14 | to_make -=1 15 | carry = 10 16 | else: 17 | carry = 0 18 | 19 | ans += to_make 20 | 21 | print(ans) 22 | -------------------------------------------------------------------------------- /codeforces/round513/e.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | #define ll long long 10 | #define ull unsigned long long 11 | using namespace std; 12 | 13 | int main(){ 14 | 15 | return 0; 16 | } -------------------------------------------------------------------------------- /codeforces/round608/a.py: -------------------------------------------------------------------------------- 1 | a = int(input()) 2 | b = int(input()) 3 | c = int(input()) 4 | d = int(input()) 5 | e = int(input()) 6 | f = int(input()) 7 | ans = 0 8 | if f > e: 9 | fs = min(b, c, d) 10 | c -= fs 11 | b -= fs 12 | d -= fs 13 | ans += f * fs 14 | 15 | es = min(a, d) 16 | ans += es * e 17 | else: 18 | es = min(a, d) 19 | d -= es 20 | ans += es * e 21 | fs = min(b, c, d) 22 | ans += f * fs 23 | print(ans) -------------------------------------------------------------------------------- /codeforces/round608/c.py: -------------------------------------------------------------------------------- 1 | n, sx, sy = map(int, input().split()) 2 | u, r, d, l = 0, 0, 0, 0 3 | for i in range(n): 4 | x, y = map(int, input().split()) 5 | if x < sx: 6 | l += 1 7 | if x > sx: 8 | r += 1 9 | if y < sy: 10 | u += 1 11 | if y > sy: 12 | d += 1 13 | 14 | ans = max(u,r,d,l) 15 | print(ans) 16 | if u == ans: 17 | print(sx, sy-1) 18 | elif r == ans: 19 | print(sx+1, sy) 20 | elif d == ans: 21 | print(sx, sy+1) 22 | elif l == ans: 23 | print(sx-1, sy) -------------------------------------------------------------------------------- /codeforces/round608/e.py: -------------------------------------------------------------------------------- 1 | n, k = map(int, input().split()) 2 | s = bin(n)[2:] 3 | # i fell asleep here... damn 1 am contests -------------------------------------------------------------------------------- /codeforces/round612/A.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitamintK/AlgorithmProblems/7f3b88d15513c24424254a6b44a1a557267ea1c7/codeforces/round612/A.py -------------------------------------------------------------------------------- /codeforces/round612/A_angry_students.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | k = int(input()) 4 | s = list(input()) 5 | i = 0 6 | to_change = [i for i,x in enumerate(s) if i>0 and s[i-1]=='A' and s[i]=='P'] 7 | while len(to_change) > 0: 8 | for tc in to_change: 9 | s[tc] = 'A' 10 | to_change = [i for i,x in enumerate(s) if i>0 and s[i-1]=='A' and s[i]=='P'] 11 | i += 1 12 | print(i) -------------------------------------------------------------------------------- /codeforces/round665/a.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n, k = map(int, input().split()) 4 | if k <= n: 5 | if (n%2 == 0) == (k%2 == 0): 6 | print(0) 7 | continue 8 | else: 9 | print(1) 10 | continue 11 | else: 12 | print(k - n) -------------------------------------------------------------------------------- /codeforces/round665/b.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | a0, a1, a2 = map(int, input().split()) 4 | b0, b1, b2 = map(int, input().split()) 5 | #best is to match 2 with 1 6 | # match 0 with 2 7 | # and match 1 with 1 8 | # b a 0 1 2 9 | # 0 0 0 0 10 | # 1 0 0 2 11 | # 2 0 -2 0 12 | ans = 0 13 | goods = min(a2, b1) 14 | ans += goods*2 15 | # b = b0 + b1-ans 16 | # a = a0 + a2-ans 17 | n = a0+a1+a2 - goods 18 | if a1 + b2 > n: 19 | ans -= (b2 + a1 - n) * 2 20 | print(ans) 21 | 22 | -------------------------------------------------------------------------------- /codeforces/round666/a.py: -------------------------------------------------------------------------------- 1 | from collections import defaultdict 2 | T = int(input()) 3 | for t in range(T): 4 | n = int(input()) 5 | c = defaultdict(int) 6 | for i in range(n): 7 | s = input() 8 | for x in s: 9 | c[x] +=1 10 | for l in c: 11 | if c[l]%n != 0: 12 | print("NO") 13 | break 14 | else: 15 | print("YES") -------------------------------------------------------------------------------- /codeforces/round666/c.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | xs = [int(x) for x in input().split()] 3 | ans = [] 4 | for i in range(len(xs)-1): 5 | c = (n-1) * xs[i] 6 | ans.append(c) 7 | if n == 1: 8 | print(1, 1) 9 | print(0) 10 | else: 11 | print(1, n-1) 12 | print(' '.join(str(x) for x in ans)) 13 | print(n, n) 14 | print((n-1) * xs[-1]) 15 | print(1, n) 16 | ans = [] 17 | for x in xs: 18 | c = -n * x 19 | ans.append(c) 20 | print(' '.join(str(x) for x in ans)) -------------------------------------------------------------------------------- /codeforces/round670/a.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n = int(input()) 4 | xs = [int(x) for x in input().split()] 5 | for i in range(102): 6 | if xs.count(i) < 2: 7 | a = i 8 | for j in range(i, 102): 9 | if xs.count(j) < 1: 10 | b = j 11 | break 12 | break 13 | print(j+i) 14 | -------------------------------------------------------------------------------- /codeforces/round671/a.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n = int(input()) 4 | b = input() 5 | odds = [] 6 | evens = [] 7 | for i in range(len(b)): 8 | if i%2 ==1: 9 | evens.append(int(b[i])) 10 | else: 11 | odds.append(int(b[i])) 12 | if len(odds) == len(evens): 13 | if any(x%2 == 0 for x in evens): 14 | print(2) 15 | else: 16 | print(1) 17 | else: 18 | if any(x%2 == 1 for x in odds): 19 | print(1) 20 | else: 21 | print(2) -------------------------------------------------------------------------------- /codeforces/round671/b.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | 3 | def need(n): 4 | return (n*(n+1))//2 5 | 6 | for t in range(T): 7 | x = int(input()) 8 | ans = 0 9 | nxt = 1 10 | while True: 11 | if x < need(nxt): 12 | break 13 | ans+=1 14 | x -= need(nxt) 15 | nxt = nxt*2+1 16 | print(ans) -------------------------------------------------------------------------------- /codeforces/round675/a.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | xs = [int(x) for x in input().split()] 4 | g = sum(xs) 5 | print(g-1) -------------------------------------------------------------------------------- /codeforces/round675/e.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitamintK/AlgorithmProblems/7f3b88d15513c24424254a6b44a1a557267ea1c7/codeforces/round675/e.cpp -------------------------------------------------------------------------------- /codeforces/round687/a.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n, m, r, c = map(int, input().split()) 4 | r, c = r-1, c-1 5 | h = max(n-r-1, r) 6 | v = max(m-c-1, c) 7 | print(h+v) -------------------------------------------------------------------------------- /codeforces/round708/a.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | T = int(input()) 3 | for t in range(T): 4 | n = int(input()) 5 | xs = [int(x) for x in input().split()] 6 | c = Counter(xs) 7 | ans = [] 8 | for x in range(105): 9 | if x not in c: 10 | break 11 | else: 12 | ans.append(x) 13 | c[x] -=1 14 | for x, occurence in c.items(): 15 | for i in range(occurence): 16 | ans.append(x) 17 | 18 | print(*ans) -------------------------------------------------------------------------------- /codeforces/round708/c_gen.py: -------------------------------------------------------------------------------- 1 | ans = [] 2 | for n in range(3,40): 3 | for k in range(3,n+1): 4 | ans.append((n,k)) 5 | print(len(ans)) 6 | for x in ans: 7 | print(*x) -------------------------------------------------------------------------------- /codeforces/round711/a.py: -------------------------------------------------------------------------------- 1 | import math 2 | T = int(input()) 3 | for t in range(T): 4 | n = int(input()) 5 | while math.gcd(n, sum(int(x) for x in str(n))) == 1: 6 | n += 1 7 | print(n) -------------------------------------------------------------------------------- /codeforces/round711/b.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | T = int(input()) 3 | for t in range(T): 4 | n, W = map(int, input().split()) 5 | ws = [int(x) for x in input().split()] 6 | ws = Counter(ws) 7 | ans = 1 8 | lineleft = W 9 | while n > 0: 10 | cands = [w for w in ws if ws[w]>0 and w<=lineleft] 11 | if len(cands) == 0: 12 | ans += 1 13 | lineleft = W 14 | else: 15 | pick = max(cands) 16 | n -=1 17 | ws[pick] -= 1 18 | lineleft -= pick 19 | print(ans) -------------------------------------------------------------------------------- /codeforces/round711/c.py: -------------------------------------------------------------------------------- 1 | MOD = 1000000007 2 | T = int(input()) 3 | for t in range(T): 4 | n,k = map(int, input().split()) 5 | DP = [[0 for i in range(n+1)] for j in range(k+1)] 6 | for i in range(k+1): 7 | DP[i][0] = 1 8 | for i in range(n+1): 9 | DP[0][i] = 0 10 | for i in range(1,k+1): 11 | for j in range(1,n+1): 12 | DP[i][j] = (DP[i][j-1] + DP[i-1][n-j])%MOD 13 | print(DP[-1][-1]) -------------------------------------------------------------------------------- /codeforces/round712/c.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | inps = [] 3 | ans = 0 4 | for i in range(n): 5 | a,c = map(int, input().split()) 6 | ans += c 7 | inps.append((a,c)) 8 | inps.sort() 9 | # ans += inps[-1][0] - inps[0][0] 10 | topcover = inps[0][0] 11 | for i in range(len(inps)): 12 | if inps[i][0] > topcover: 13 | ans += inps[i][0] - topcover 14 | # print(ans) 15 | topcover = max(topcover, inps[i][0]+inps[i][1]) 16 | print(ans) -------------------------------------------------------------------------------- /codeforces/round712/readme.md: -------------------------------------------------------------------------------- 1 | Div 1 (first time being in div 1 since 2017/2018 when I was in college xD) 2 | 3 | https://codeforces.com/contest/1503 4 | 471th place. Luckily the problems were forgiving enough that python3 solutions (without even using pypy) passed for A, B, and C. -------------------------------------------------------------------------------- /codeforces/round716/b.py: -------------------------------------------------------------------------------- 1 | MOD = 1000000007 2 | T = int(input()) 3 | for t in range(T): 4 | n, k = map(int, input().split()) 5 | ans = 1 6 | for i in range(k): 7 | ans *= n 8 | ans %= MOD 9 | print(ans) -------------------------------------------------------------------------------- /codeforces/round716/c.py: -------------------------------------------------------------------------------- 1 | import math 2 | n = int(input()) 3 | ans = [] 4 | acc = 1 5 | for i in range(1,n): 6 | if math.gcd(n,i) != 1: 7 | continue 8 | ans.append(i) 9 | acc = (acc*i)%n 10 | if acc != 1: 11 | ans = [x for x in ans if x!=acc] 12 | print(len(ans)) 13 | print(*ans) -------------------------------------------------------------------------------- /codeforces/round717/a.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n, k = map(int, input().split()) 4 | xs = [int(x) for x in input().split()] 5 | l = 0 6 | r = n-1 7 | while k > 0 and l != r: 8 | amount = min(xs[l], k) 9 | k -= amount 10 | xs[l] -= amount 11 | xs[r] += amount 12 | if xs[l] == 0: 13 | l +=1 14 | print(*xs) -------------------------------------------------------------------------------- /codeforces/round718/a.py: -------------------------------------------------------------------------------- 1 | N = 2050 2 | T = int(input()) 3 | for t in range(T): 4 | n = int(input()) 5 | if n%N != 0: 6 | print(-1) 7 | continue 8 | ans = 0 9 | m = 20500000000000000000000 10 | while m > n: 11 | m//=10 12 | if m == 0: 13 | break 14 | ans += n//m 15 | n = n-m*(n//m) 16 | if n != 0: 17 | print(-1) 18 | else: 19 | print(ans) -------------------------------------------------------------------------------- /codeforces/round720/a.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | a,b = map(int, input().split()) 4 | if b==1: 5 | print("NO") 6 | else: 7 | print("YES") 8 | print(a, a*b, a*b+a) -------------------------------------------------------------------------------- /codeforces/round721/a.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n = int(input()) 4 | m = 1 5 | while m*2 <= n: 6 | m *=2 7 | print(m - 1) -------------------------------------------------------------------------------- /codeforces/round721/c.py: -------------------------------------------------------------------------------- 1 | from collections import defaultdict 2 | T = int(input()) 3 | for t in range(T): 4 | n = int(input()) 5 | xs = [int(x) for x in input().split()] 6 | nums = defaultdict(list) 7 | for i,x in enumerate(xs): 8 | nums[x].append(i) 9 | ans = 0 10 | for num in nums: 11 | subweight = 0 12 | for i in nums[num]: 13 | ans += (n-i)*subweight 14 | subweight += i+1 15 | print(ans) -------------------------------------------------------------------------------- /codeforces/round726/a.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n = int(input()) 4 | xs = [int(x) for x in input().split()] 5 | if sum(xs) <= 0: 6 | print(1) 7 | else: 8 | if sum(xs) - len(xs) < 0: 9 | print(1) 10 | else: 11 | print(sum(xs) - len(xs)) -------------------------------------------------------------------------------- /codeforces/round726/c.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n = int(input()) 4 | hs = [int(x) for x in input().split()] 5 | hs.sort() 6 | mindiff = 112345678901 7 | argmindiff = None 8 | for i in range(1,len(hs)): 9 | if hs[i] - hs[i-1] < mindiff: 10 | mindiff = hs[i] - hs[i-1] 11 | argmindiff = i-1 12 | if hs[1] - hs[0] == mindiff: 13 | print(*([hs[0]] + hs[2:] + [hs[1]])) 14 | else: 15 | print(*(hs[argmindiff+1:] + hs[:argmindiff+1])) -------------------------------------------------------------------------------- /codeforces/round726/ebiggen.py: -------------------------------------------------------------------------------- 1 | s = 'bananananananananananananananaananana' 2 | print(len(s) * (500000//len(s)), 500000) 3 | print(s*(500000//len(s))) -------------------------------------------------------------------------------- /codeforces/round728/a.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n = int(input()) 4 | ans = [] 5 | for i in range(1,n+1): 6 | if i%2 == 1: 7 | ans.append(i+1) 8 | else: 9 | ans.append(i-1) 10 | if n%2 == 1: 11 | ans[-3] = n 12 | ans[-2] = n-2 13 | ans[-1] = n-1 14 | print(*ans) -------------------------------------------------------------------------------- /codeforces/round728/c.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n = int(input()) 4 | ds = [int(x) for x in input().split()] 5 | ds.sort() 6 | ans = max(ds) 7 | run = 0 8 | for i in range(1,n): 9 | run += i * (ds[i]-ds[i-1]) 10 | ans -= run 11 | print(ans) -------------------------------------------------------------------------------- /codeforces/round730/a.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | a, b = map(int, input().split()) 4 | a, b = sorted([a,b]) 5 | if a == b: 6 | print(0, 0) 7 | continue 8 | diff = b-a 9 | target = diff - (b%diff) 10 | target2 = b%diff 11 | if a < target2: 12 | target2 = 112345678901234567890 13 | print(diff, min(target, target2)) -------------------------------------------------------------------------------- /codeforces/round730/b.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n = int(input()) 4 | xs = [int(x) for x in input().split()] 5 | s = sum(xs) 6 | a = s//n 7 | x = n * (a+1) - s 8 | ans = x * (n-x) 9 | print(ans) -------------------------------------------------------------------------------- /codeforces/round730/readme.md: -------------------------------------------------------------------------------- 1 | only solved A and B because I struggled for an hour with precision issues on C :(( 2 | 3 | Lost 140 rating points XD -------------------------------------------------------------------------------- /codeforces/round741/a.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | l,r = map(int, input().split()) 4 | lmin = (r+2)//2 5 | l = max(lmin, l) 6 | print(r-l) -------------------------------------------------------------------------------- /codeforces/round774/a.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n, s = map(int, input().split()) 4 | ns = n*n 5 | ans = s//ns 6 | print(ans) -------------------------------------------------------------------------------- /codeforces/round774/b.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n = int(input()) 4 | xs = [int(x) for x in input().split()] 5 | xs.sort() 6 | ans = False 7 | l = 1 8 | r = n-1 9 | blu = xs[0] 10 | red = 0 11 | while l < r: 12 | blu += xs[l] 13 | l += 1 14 | if l <= r: 15 | red += xs[r] 16 | r -= 1 17 | if blu < red: 18 | ans = True 19 | break 20 | print("YES" if ans else "NO") -------------------------------------------------------------------------------- /codeforces/round782/a.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n,r,b = map(int, input().split()) 4 | val = (r+b)//(b+1) 5 | ans = [] 6 | remaining_rs = r 7 | for i in range(b): 8 | for k in range(val): 9 | ans.append('R') 10 | remaining_rs -= 1 11 | if remaining_rs == b-i-1: 12 | break 13 | ans.append('B') 14 | for k in range(r - val*b): 15 | ans.append('R') 16 | print(''.join(ans)) -------------------------------------------------------------------------------- /codeforces/round782/b: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitamintK/AlgorithmProblems/7f3b88d15513c24424254a6b44a1a557267ea1c7/codeforces/round782/b -------------------------------------------------------------------------------- /codeforces/round782/c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitamintK/AlgorithmProblems/7f3b88d15513c24424254a6b44a1a557267ea1c7/codeforces/round782/c -------------------------------------------------------------------------------- /codeforces/round788/b: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitamintK/AlgorithmProblems/7f3b88d15513c24424254a6b44a1a557267ea1c7/codeforces/round788/b -------------------------------------------------------------------------------- /codeforces/round788/b.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n = int(input()) 4 | s = input() 5 | ks = input().split() 6 | k = ks[0] 7 | ks = {ki for ki in ks[1:]} 8 | ans = 0 9 | cnt = 0 10 | for i in range(n): 11 | if s[i] in ks: 12 | ans = max(ans, cnt) 13 | cnt = 1 14 | else: 15 | cnt += 1 16 | print(ans) -------------------------------------------------------------------------------- /codeforces/round788/c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitamintK/AlgorithmProblems/7f3b88d15513c24424254a6b44a1a557267ea1c7/codeforces/round788/c -------------------------------------------------------------------------------- /codeforces/round788/d: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitamintK/AlgorithmProblems/7f3b88d15513c24424254a6b44a1a557267ea1c7/codeforces/round788/d -------------------------------------------------------------------------------- /codeforces/round795/a.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n = int(input()) 4 | xs = [int(x) for x in input().split()] 5 | evens = len([x for x in xs if x%2==0]) 6 | odds = n-evens 7 | print(min(odds, evens)) -------------------------------------------------------------------------------- /codeforces/round795/b.py: -------------------------------------------------------------------------------- 1 | from collections import Counter, defaultdict 2 | 3 | 4 | T = int(input()) 5 | for t in range(T): 6 | n = int(input()) 7 | xs = [int(x) for x in input().split()] 8 | c = Counter(xs) 9 | if any(c[k]==1 for k in c): 10 | print(-1) 11 | continue 12 | d = defaultdict(list) 13 | for i, x in enumerate(xs): 14 | d[x].append(i) 15 | ans = [None for i in range(n)] 16 | for k in d: 17 | for i in range(len(d[k])): 18 | ans[d[k][i]] = d[k][i-1] 19 | print(*[x+1 for x in ans]) -------------------------------------------------------------------------------- /codeforces/round795/c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitamintK/AlgorithmProblems/7f3b88d15513c24424254a6b44a1a557267ea1c7/codeforces/round795/c -------------------------------------------------------------------------------- /codeforces/round800/a.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | a, b = map(int, input().split()) 4 | ans = [] 5 | while a > 0 and b > 0: 6 | a-=1 7 | b-=1 8 | ans.append('0') 9 | ans.append('1') 10 | for i in range(b): 11 | ans.append('1') 12 | for i in range(a): 13 | ans.append('0') 14 | print(''.join(ans)) -------------------------------------------------------------------------------- /codeforces/round800/b.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n = int(input()) 4 | s = input() 5 | ans = n 6 | for i in range(1,n): 7 | if s[i] == s[i-1]: 8 | continue 9 | ans += i 10 | print(ans) -------------------------------------------------------------------------------- /codeforces/round801/a.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n, m = map(int, input().split()) 4 | grid = [] 5 | max_num = -9999999999 6 | for i in range(n): 7 | xs = [int(x) for x in input().split()] 8 | max_num = max(max_num, max(xs)) 9 | grid.append(xs) 10 | for i in range(n): 11 | for j in range(m): 12 | if grid[i][j] == max_num: 13 | w = max(j+1, m-j) 14 | h = max(i+1, n-i) 15 | ans = w*h 16 | print(ans) -------------------------------------------------------------------------------- /codeforces/round801/b.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n = int(input()) 4 | xs = [int(x) for x in input().split()] 5 | if n%2==0: 6 | smallest_pile = min(xs) 7 | for i in range(n): 8 | if xs[i] == smallest_pile: 9 | if i%2==0: 10 | print("Joe") 11 | break 12 | else: 13 | print("Mike") 14 | break 15 | else: 16 | print("Mike") -------------------------------------------------------------------------------- /codeforces/round803/a.py: -------------------------------------------------------------------------------- 1 | import sys 2 | input = sys.stdin.readline 3 | 4 | T = int(input()) 5 | for t in range(T): 6 | n = int(input()) 7 | xs = [int(x) for x in input().split()] 8 | print(xs[0]) -------------------------------------------------------------------------------- /codeforces/round803/b.py: -------------------------------------------------------------------------------- 1 | import sys 2 | input = sys.stdin.readline 3 | 4 | T = int(input()) 5 | for t in range(T): 6 | n, k = map(int, input().split()) 7 | xs = [int(x) for x in input().split()] 8 | if k == 1: 9 | if n%2==1: 10 | print(n//2) 11 | else: 12 | print((n-1)//2) 13 | else: 14 | ans = 0 15 | for i in range(1,n-1): 16 | if xs[i] > xs[i-1]+xs[i+1]: 17 | ans += 1 18 | print(ans) -------------------------------------------------------------------------------- /codeforces/round812/a.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n = int(input()) 4 | xmax, xmin, ymax, ymin = 0,0,0,0 5 | for i in range(n): 6 | x,y = map(int, input().split()) 7 | xmax = max(xmax, x) 8 | xmin = min(xmin, x) 9 | ymax = max(ymax, y) 10 | ymin = min(ymin, y) 11 | print(2 * (xmax-xmin + ymax-ymin)) -------------------------------------------------------------------------------- /codeforces/round812/b.py: -------------------------------------------------------------------------------- 1 | import sys 2 | input = sys.stdin.readline 3 | T = int(input()) 4 | for t in range(T): 5 | n = int(input()) 6 | xs = [int(x) for x in input().split()] 7 | decrease_encountered = False 8 | ans = "YES" 9 | for i in range(1,n): 10 | if xs[i] > xs[i-1]: 11 | if decrease_encountered: 12 | ans = "NO" 13 | break 14 | if xs[i] < xs[i-1]: 15 | decrease_encountered = True 16 | print(ans) -------------------------------------------------------------------------------- /codeforces/round816/a.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n,m = map(int, input().split()) 4 | print(n+m-1-1 + min(n,m)-1 + (0 if max(n,m)==1 else 1)) -------------------------------------------------------------------------------- /codeforces/round833/a.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n = int(input()) 4 | print((n+1)//2) -------------------------------------------------------------------------------- /codeforces/round864/a.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n, m = map(int, input().split()) 4 | x1,y1,x2,y2 = map(int, input().split()) 5 | ans = 4 6 | for (x,y) in [(x1,y1), (x2,y2)]: 7 | num = 4 8 | if x == 1 or x==n: 9 | num -= 1 10 | if y==1 or y==m: 11 | num -= 1 12 | ans = min(ans, num) 13 | print(ans) -------------------------------------------------------------------------------- /codeforces/round864/e.py: -------------------------------------------------------------------------------- 1 | from functools import lru_cache 2 | import math 3 | @lru_cache 4 | def totient(x): 5 | uhhhhhhhhhhhhhhh 6 | while x != 1: 7 | x //= sieve[x] 8 | 9 | # ans = 0 10 | # for i in range(1,x): 11 | # if math.gcd(i,x) == 1: 12 | # ans += 1 13 | # return ans 14 | 15 | sieve = [0 for i in range(5000000)] 16 | 17 | for i in range(2,10000): 18 | if sieve[i] == 0: 19 | for j in range(i, 5000000, i): 20 | sieve[j] = i 21 | 22 | -------------------------------------------------------------------------------- /codeforces/round967/a.py: -------------------------------------------------------------------------------- 1 | import sys 2 | input = sys.stdin.readline 3 | from collections import Counter 4 | 5 | T = int(input()) 6 | for t in range(T): 7 | n = int(input()) 8 | xs = list(map(int, input().split())) 9 | c = Counter(xs) 10 | m = max(c.values()) 11 | print(n - m) -------------------------------------------------------------------------------- /codeforces/round967/b.py: -------------------------------------------------------------------------------- 1 | import sys 2 | input = sys.stdin.readline 3 | 4 | T = int(input()) 5 | for t in range(T): 6 | n = int(input()) 7 | if n % 2 == 0: 8 | print(-1) 9 | else: 10 | l = [0 for i in range(n)] 11 | p = n//2 12 | parity = -1 13 | for i in range(n): 14 | l[p] = i+1 15 | p += parity * (i+1) 16 | parity *= -1 17 | print(' '.join(map(str, l))) 18 | -------------------------------------------------------------------------------- /codeforces/round967/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitamintK/AlgorithmProblems/7f3b88d15513c24424254a6b44a1a557267ea1c7/codeforces/round967/readme.md -------------------------------------------------------------------------------- /codeforces/vkcup ru qual/voting_for_photos.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main(){ 5 | long n; 6 | int k; 7 | unordered_map ans 8 | int best = 0; 9 | int best_id = 0; 10 | cin >> n; 11 | for(long i = 0; i < n; i ++){ 12 | cin >> k; 13 | ans[k]++; 14 | if(ans[k] > best){ 15 | best = ans[k]; 16 | best_id = k; 17 | } 18 | } 19 | cout << best_id << endl; 20 | return 0; 21 | } -------------------------------------------------------------------------------- /facebook-hacker-cup/2017/qualification/lazy_loading.py: -------------------------------------------------------------------------------- 1 | t = int(input()) 2 | for i in range(t): 3 | n = int(input()) 4 | stuff = [] 5 | for j in range(n): 6 | stuff.append(int(input())) 7 | stuff.sort() 8 | ans = 0 9 | top = len(stuff)-1 10 | bottom = 0 11 | while(bottom <= top): 12 | perceived = stuff[top] 13 | top-=1 14 | bottom+= (50+perceived - 1)//perceived - 1 15 | if bottom-1 < top+1: 16 | ans+=1 17 | print("Case #{}: {}".format(i+1,ans)) 18 | -------------------------------------------------------------------------------- /facebook-hacker-cup/2018/qualification/A_tourist.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n, k, v = map(int, input().split()) 4 | facebook = [] 5 | for i in range(n): 6 | facebook.append(input()) 7 | seen_already = (v-1)*k 8 | current_start = seen_already%n 9 | l = [] 10 | for i in range(k): 11 | l.append(facebook[(current_start+i)%n]) 12 | l.sort(key = lambda x: facebook.index(x)) 13 | print("Case #{}: {}".format(t+1, ' '.join(l))) 14 | -------------------------------------------------------------------------------- /facebook-hacker-cup/2018/qualification/B_interception.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n = int(input()) 4 | for i in range(n+1): 5 | input() 6 | if n%2 == 1: 7 | print("Case #{}: 1".format(t+1)) 8 | print("0.0") 9 | else: 10 | print("Case #{}: 0".format(t+1)) 11 | -------------------------------------------------------------------------------- /facebook-hacker-cup/2018/qualification/C_in.txt: -------------------------------------------------------------------------------- 1 | 9 2 | ABACUS 3 | ABACU 4 | ABABUS 5 | FACEBOOK 6 | XYZXZYX 7 | FBFBF 8 | FBBFBBF 9 | FBBFBBC 10 | FBFBFC 11 | -------------------------------------------------------------------------------- /facebook-hacker-cup/2020/round2/a_test_gen.py: -------------------------------------------------------------------------------- 1 | T = 100 2 | for t in range(T): 3 | N, K = 1000000, 1000 4 | for i in range(K): 5 | print() -------------------------------------------------------------------------------- /facebook-hacker-cup/2020/round2/b: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitamintK/AlgorithmProblems/7f3b88d15513c24424254a6b44a1a557267ea1c7/facebook-hacker-cup/2020/round2/b -------------------------------------------------------------------------------- /facebook-hacker-cup/2021/qual/a1.py: -------------------------------------------------------------------------------- 1 | # consistency: chapter 1 2 | import string 3 | 4 | def is_vowel(x): 5 | return x in 'AEIOU' 6 | 7 | T = int(input()) 8 | for t in range(T): 9 | s = input() 10 | ans = 1000 11 | for letter in string.ascii_uppercase: 12 | ops = 0 13 | for x in s: 14 | if x == letter: 15 | continue 16 | if is_vowel(x) != is_vowel(letter): 17 | ops += 1 18 | else: 19 | ops += 2 20 | ans = min(ans, ops) 21 | print(f'Case #{t+1}: {ans}') -------------------------------------------------------------------------------- /facebook-hacker-cup/2021/readme.md: -------------------------------------------------------------------------------- 1 | qual: 5810 out of 34585 2 | round 1: 833 out of 12692 3 | round 2: 2208 out of 6789 (blaming this one on macOS's tiny stack size) -------------------------------------------------------------------------------- /facebook-hacker-cup/2021/round1/a1/a1.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n = int(input()) 4 | s = input() 5 | ans = 0 6 | prev = None 7 | for x in s: 8 | if x =='F': 9 | continue 10 | if prev is None or prev == x: 11 | prev = x 12 | else: 13 | ans +=1 14 | prev = x 15 | print(f'Case #{t+1}: {ans}') -------------------------------------------------------------------------------- /facebook-hacker-cup/2021/round1/a2/a2.py: -------------------------------------------------------------------------------- 1 | MOD = 1000000007 2 | T = int(input()) 3 | for t in range(T): 4 | n = int(input()) 5 | s = input() 6 | ans = 0 7 | prev = None 8 | prev_index = None 9 | for i, x in enumerate(s): 10 | if x == 'F': 11 | continue 12 | if prev is not None and x != prev: 13 | ans += (prev_index+1) * (n-i) 14 | ans %= MOD 15 | prev = x 16 | prev_index = i 17 | print(f'Case #{t+1}: {ans}') -------------------------------------------------------------------------------- /google-code-jam/2016/qual/sheep.py: -------------------------------------------------------------------------------- 1 | k = int(input()) 2 | for i in range(k): 3 | n = int(input()) 4 | digitset = set() 5 | if n == 0: 6 | print("Case #{}: INSOMNIA".format(i+1)) 7 | continue 8 | else: 9 | num = 0 10 | while(len(digitset) < 10): 11 | num = num + n 12 | digitset.update(set(str(num))) 13 | print("Case #{}: {}".format(i+1, num)) 14 | 15 | 16 | -------------------------------------------------------------------------------- /google-code-jam/2016/rnd1c/c,py.py: -------------------------------------------------------------------------------- 1 | T = input() 2 | for i in range(T): 3 | j, p, s, k = map(int, input().split()) 4 | first, second = list(sorted(enumerate([j,p,s]), key = lambda x: x[1]))[0:1] 5 | 6 | -------------------------------------------------------------------------------- /google-code-jam/2016/rnd2_virtual/A_RPS.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | 3 | beats = {'r':'s', 's':'p', 'p':'r'} 4 | 5 | 6 | 7 | for t in range(T): 8 | n, r, p, s = map(int, input().split()) 9 | bintree = [None]*pow(2,n) 10 | for winnar in 'rps': 11 | 12 | -------------------------------------------------------------------------------- /google-code-jam/2017/qualification/B_numbers.py: -------------------------------------------------------------------------------- 1 | t = int(input().strip()) 2 | for i in range(t): 3 | n = list(int(p) for p in input().strip()) 4 | for c in range(len(n)-1,0,-1): 5 | if n[c-1] > n[c]: 6 | n[c-1] = n[c-1] -1 7 | for c2 in range(c,len(n)): 8 | n[c2] = 9 9 | stitched = ''.join(str(p) for p in n) 10 | print("Case #{}: {}".format(i+1, int(stitched))) 11 | 12 | -------------------------------------------------------------------------------- /google-code-jam/2017/round1b/a.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | d, n = map(int, input().split()) 4 | slowest_time = 0 5 | for i in range(n): 6 | k, s = map(int, input().split()) 7 | time = (d - k)/s 8 | slowest_time = max(time, slowest_time) 9 | print("Case #{}: {}".format(t+1, d/slowest_time)) 10 | -------------------------------------------------------------------------------- /google-code-jam/2018/qualification/C_go_gopher.py: -------------------------------------------------------------------------------- 1 | #what a question 2 | T = int(input()) 3 | for t in range(T): 4 | a = int(input()) 5 | 6 | x, y = None, None 7 | i = 0 8 | while (x,y) != (0,0): 9 | if a == 20: 10 | v, w = [(3,3),(4,3),(3,4),(4,4),(3,5),(4,5)][i%6] 11 | else: 12 | v,w = (3, 3 + (i%68)) 13 | print(v, w) 14 | i+=1 15 | x,y = map(int, input().split()) 16 | if (x,y) == (-1,-1): 17 | exit() 18 | 19 | -------------------------------------------------------------------------------- /google-code-jam/2018/round1a/A_in.txt: -------------------------------------------------------------------------------- 1 | 6 2 | 3 6 1 1 3 | .@@..@ 4 | .....@ 5 | @.@.@@ 6 | 4 3 1 1 7 | @@@ 8 | @.@ 9 | @.@ 10 | @@@ 11 | 4 5 1 1 12 | ..... 13 | ..... 14 | ..... 15 | ..... 16 | 4 4 1 1 17 | ..@@ 18 | ..@@ 19 | @@.. 20 | @@.. 21 | 3 4 2 2 22 | @.@@ 23 | @@.@ 24 | @.@@ 25 | 3 4 1 2 26 | .@.@ 27 | @.@. 28 | .@.@ 29 | -------------------------------------------------------------------------------- /google-code-jam/2018/round1a/B_in.txt: -------------------------------------------------------------------------------- 1 | 3 2 | 3 4 5 3 | 2 3 3 4 | 2 1 5 5 | 2 4 2 6 | 2 2 4 7 | 2 5 1 8 | 2 2 2 9 | 1 2 3 10 | 1 1 2 11 | 2 2 2 12 | 1 2 3 13 | 2 1 2 14 | -------------------------------------------------------------------------------- /google-code-jam/2019/qualification/C_gen_test.py: -------------------------------------------------------------------------------- 1 | primes = [3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103] 2 | import string 3 | def output(s): 4 | ans = [] 5 | for i in range(len(s)-1): 6 | ans.append(primes[string.ascii_uppercase.index(s[i])] * primes[string.ascii_uppercase.index(s[i+1])]) 7 | print(103, len(s)) 8 | print(' '.join(str(x) for x in ans)) 9 | 10 | n = int(input()) 11 | print(n) 12 | for i in range(n): 13 | output(input()) -------------------------------------------------------------------------------- /google-code-jam/2019/round1a/A.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | r, c = map(int, input().split()) 4 | -------------------------------------------------------------------------------- /google-code-jam/2019/round1b/readme.md: -------------------------------------------------------------------------------- 1 | started late with only 1 hr to go :( -------------------------------------------------------------------------------- /google-code-jam/2019/round1b/untitled: -------------------------------------------------------------------------------- 1 | started late with only 1 hr to go :( -------------------------------------------------------------------------------- /google-code-jam/2019/round1c/c.in.py: -------------------------------------------------------------------------------- 1 | 6 2 | 2 2 3 | .. 4 | .# 5 | 4 4 6 | .#.. 7 | ..#. 8 | #... 9 | ...# 10 | 3 4 11 | #.## 12 | .... 13 | #.## 14 | 1 1 15 | . 16 | 1 2 17 | ## 18 | 4 4 19 | #### 20 | #### 21 | .... 22 | #### -------------------------------------------------------------------------------- /google-code-jam/2020/qualification/a_vestigium.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | N = int(input()) 4 | square = [] 5 | for i in range(N): 6 | square.append([int(x) for x in input().split()]) 7 | cols = 0 8 | rows = 0 9 | trace = 0 10 | for i in range(N): 11 | trace += square[i][i] 12 | for i in range(N): 13 | if len(set(square[i])) != N: 14 | rows += 1 15 | if len(set(square[j][i] for j in range(N))) != N: 16 | cols +=1 17 | print("Case #{}: {} {} {}".format(t+1, trace, rows, cols)) -------------------------------------------------------------------------------- /google-code-jam/2020/qualification/b_nesting_depth.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | s = input() 4 | ans = [] 5 | l = 0 6 | for i in s: 7 | n = int(i) 8 | while n > l: 9 | ans.append('(') 10 | l+=1 11 | while n < l: 12 | ans.append(')') 13 | l-=1 14 | ans.append(i) 15 | # deal with closing here 16 | for i in range(l): 17 | ans.append(')') 18 | print("Case #{}: {}".format(t+1, ''.join(ans))) -------------------------------------------------------------------------------- /google-code-jam/2020/round1b/readme.md: -------------------------------------------------------------------------------- 1 | solved B (blindfolded bullseye) and A small and medium (Expogo) for 752nd place. 2 | Expogo was actually a pretty nice problem but I just couldn't figure it out during the contest. -------------------------------------------------------------------------------- /google-code-jam/2020/round2/readme.md: -------------------------------------------------------------------------------- 1 | took me bout an hour to come up with the soln for A (kept thinking I was doing it wrong and thinking there must be some easy way to solve the x = n*(n+1)/2 quadratic equation but from the editorials this was actually essentially the intended solution) and debug it. 2 | then it took me a while to come up with a soln for B easy, and I ran out of time while writing it. 3 | Ended up just solving A hard. 4 | Needed to solve both A hard and B hard within a good enough time to pass :( -------------------------------------------------------------------------------- /google-code-jam/2021/qualification/a.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n = int(input()) 4 | ls = [int(x) for x in input().split()] 5 | ans = 0 6 | for i in range(len(ls)-1): 7 | minimum = min(enumerate(ls[i:]),key=lambda x:x[1])[0] 8 | ans += minimum + 1 9 | minimum += i + 1 10 | # print(list(reversed(ls[i:minimum]))) 11 | ls[i:minimum] = list(reversed(ls[i:minimum])) 12 | # print(ls) 13 | print(f'Case #{t+1}: {ans}') -------------------------------------------------------------------------------- /google-code-jam/2021/qualification/b.py: -------------------------------------------------------------------------------- 1 | # no extra credit 2 | 3 | T = int(input()) 4 | for t in range(T): 5 | x,y,s = input().split() 6 | x,y = int(x), int(y) 7 | cost_by_latter = {'C':y,'J':x} 8 | prev = None 9 | ans = 0 10 | for i in range(len(s)): 11 | if s[i] != '?' and s[i] != prev and prev is not None: 12 | ans += cost_by_latter[s[i]] 13 | if s[i] != '?': 14 | prev = s[i] 15 | print(f'Case #{t+1}: {ans}') -------------------------------------------------------------------------------- /google-code-jam/2021/round1a/c_large.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitamintK/AlgorithmProblems/7f3b88d15513c24424254a6b44a1a557267ea1c7/google-code-jam/2021/round1a/c_large.py -------------------------------------------------------------------------------- /google-code-jam/2021/round1a/c_med.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n, q = map(int, input().split()) 4 | inputs = [] 5 | for i in range(n): 6 | a, s = input().split() 7 | s = int(s) 8 | if s < q/2: 9 | s = q- s 10 | a = ''.join('T' if x=='F' else 'F' for x in a) 11 | inputs.append((a, s)) 12 | best = max(inputs, key=lambda x: x[1]) 13 | print(f'Case #{t+1}: {best[0]} {best[1]}/1') 14 | -------------------------------------------------------------------------------- /google-code-jam/2021/round1a/readme.md: -------------------------------------------------------------------------------- 1 | Solved A, B small and medium, and C small and medium for 744th place! Good enough to qualify straight to round 2. My best placement in round 1a since 2018 when I was still in college! 2 | 3 | https://codingcompetitions.withgoogle.com/codejam/round/000000000043585d 4 | 5 | https://codingcompetitions.withgoogle.com/codejam/submissions/000000000043585d/Q3ljbG9tYXRpYw 6 | -------------------------------------------------------------------------------- /google-code-jam/2021/round2/a.py: -------------------------------------------------------------------------------- 1 | T, n = map(int, input().split()) 2 | for t in range(T): 3 | for i in range(1,n): 4 | print(f'M {i} {n}') 5 | m = int(input()) 6 | if m != i: 7 | print(f'S {i} {m}') 8 | input() 9 | print('D') 10 | input() -------------------------------------------------------------------------------- /google-code-jam/2021/round2/readme.md: -------------------------------------------------------------------------------- 1 | well, this is incredibly awkward. 2 | 3 | So, I would have gotten 950th-ish place, but I forgot sys.setrecursionlimit, and as a result, my C Hidden Test Case failed, and I ended up with 1806th place. [my sorrow documented in twitter](https://twitter.com/010010110000110/status/1393607204696174595) 4 | 5 | Really really sad :(((( 6 | 7 | [link to contest](https://codingcompetitions.withgoogle.com/codejam/round/0000000000435915) 8 | 9 | [link to my submissions](https://codingcompetitions.withgoogle.com/codejam/submissions/0000000000435915/Q3ljbG9tYXRpYw) -------------------------------------------------------------------------------- /google-code-jam/2022/qualification/a.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | r, c = map(int, input().split()) 4 | print(f"Case #{t+1}:") 5 | print(f"..{'+-'*(c-1)}+") 6 | print(f"..{'|.'*(c-1)}|") 7 | print('+-'*c + '+') 8 | for i in range(r-1): 9 | print('|.'*c + '|') 10 | print('+-'*c + '+') -------------------------------------------------------------------------------- /google-code-jam/2022/qualification/c.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n = int(input()) 4 | ss = [int(x) for x in input().split()] 5 | ss.sort() 6 | ans = 0 7 | for x in ss: 8 | if x >= ans+1: 9 | ans += 1 10 | print(f"Case #{t+1}: {ans}") 11 | -------------------------------------------------------------------------------- /google-code-jam/2022/round1a/readme.md: -------------------------------------------------------------------------------- 1 | Made the eternal mistake of getting high at 6 PM before the contest at 9 PM. To make it worse it was edibles, so I was still quite high during this contest. Made 10 (ten!) RE/WA submissions for problem B, with a variety of dumb mistakes, and didn't solve C (it was actually really hard-- I should have just tried to solve C small). Did not qualify: got 2117th place. -------------------------------------------------------------------------------- /google-code-jam/2022/round1c/b_small.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n,k = map(int, input().split()) 4 | xs = [int(x) for x in input().split()] 5 | sumx = sum(xs) 6 | sumsqx = sum(x*x for x in xs) 7 | diff = sumsqx - sumx*sumx 8 | if sumx==0: 9 | if diff==0: 10 | print(f'Case #{t+1}: 0') 11 | else: 12 | print(f'Case #{t+1}: IMPOSSIBLE') 13 | elif diff%(sumx*2)==0: 14 | ans = diff//(sumx*2) 15 | print(f'Case #{t+1}: {ans}') 16 | else: 17 | print(f'Case #{t+1}: IMPOSSIBLE') -------------------------------------------------------------------------------- /google-code-jam/2022/round1c/c_small.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | m,k = map(int, input().split()) 4 | dp = 5 | for i in range(m): 6 | # do dp -------------------------------------------------------------------------------- /google-code-jam/2022/round2/a.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | nvm -------------------------------------------------------------------------------- /google-code-jam/2023/farewell_c/readme.md: -------------------------------------------------------------------------------- 1 | I tried to rainboy this one. Unfortunately, I had to start late because my family is visiting and we got breakfast. 2 | 3 | Fortunately, the last problem in round C looked really easy, so I tackled it. Unfortunately, I was kind of halfhearted and it's hot so I took a long time to solve it, and didn't even end up finishing the Small testcase by the contest end time. I debugged and got AC a few minutes after contest finished. -------------------------------------------------------------------------------- /google-kick-start/2020/round_a/a_allocation.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n, b = map(int, input().split()) 4 | xs = [int(x) for x in input().split()] 5 | xs.sort() 6 | ans = 0 7 | for i in xs: 8 | if b >= i: 9 | ans += 1 10 | b -= i 11 | print("Case #{}: {}".format(t+1, ans)) -------------------------------------------------------------------------------- /google-kick-start/2020/round_a/readme.md: -------------------------------------------------------------------------------- 1 | first time making a trie B) 2 | 3 | solved all 4 problems and got rank 736/10925 :) -------------------------------------------------------------------------------- /google-kick-start/2020/round_b/a_bike_tour.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n = int(input()) 4 | xs = [int(x) for x in input().split()] 5 | ans = 0 6 | for i in range(len(xs)): 7 | if i == 0 or i == len(xs)-1: 8 | continue 9 | if xs[i] > xs[i-1] and xs[i] > xs[i+1]: 10 | ans += 1 11 | print("Case #{}: {}".format(t+1, ans)) -------------------------------------------------------------------------------- /google-kick-start/2020/round_b/b_bus_routes.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n, d = map(int, input().split()) 4 | xs = [int(x) for x in input().split()] 5 | day = d 6 | for x in reversed(xs): 7 | day = day - day%x 8 | print("Case #{}: {}".format(t+1, day)) -------------------------------------------------------------------------------- /google-kick-start/2020/round_b/readme.md: -------------------------------------------------------------------------------- 1 | 555/9355 2 | -------------------------------------------------------------------------------- /google-kick-start/2020/round_d/a.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n = int(input()) 4 | ps = [int(x) for x in input().split()] 5 | ans = 0 6 | record = 0 7 | for i in range(n): 8 | if i == 0: 9 | if n == 1: 10 | ans += 1 11 | elif ps[i] > ps[i+1]: 12 | ans += 1 13 | elif ps[i] <= record: 14 | continue 15 | elif i == n-1 or ps[i] > ps[i+1]: 16 | ans += 1 17 | record = max(record, ps[i]) 18 | print("Case #{}: {}".format(t+1, ans)) -------------------------------------------------------------------------------- /google-kick-start/2020/round_d/c.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n = int(input()) 4 | n, a, b = map(int, input().split()) 5 | ps = [int(x) for x in input().split()] 6 | 7 | print("Case #{}: {}".format(t+1, ans)) -------------------------------------------------------------------------------- /google-kick-start/2020/round_e/a.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n = int(input()) 4 | xs = [int(x) for x in input().split()] 5 | ans = 1 6 | cur = 1 7 | curdiff = None 8 | for i, x in enumerate(xs): 9 | if i == 0: 10 | continue 11 | diff = x - xs[i-1] 12 | if diff == curdiff: 13 | cur +=1 14 | else: 15 | curdiff = diff 16 | cur = 1 17 | ans = max(ans, cur) 18 | print("Case #{}: {}".format(t+1, ans+1)) -------------------------------------------------------------------------------- /google-kick-start/2020/round_e/readme.md: -------------------------------------------------------------------------------- 1 | https://codingcompetitions.withgoogle.com/kickstart/round/000000000019ff47 2 | 3 | really tough problems in this one... got rank 1606 4 | 5 | B was hard af to figure out the corner cases 6 | 7 | C was so hard... I spent a couple hours on it and didn't figure it out -------------------------------------------------------------------------------- /hackerrank/GENERAL/ACM_ICPC_team.py: -------------------------------------------------------------------------------- 1 | n, m = map(int, input().split()) 2 | bitstrings = [] 3 | best = 0 4 | amt = 0 5 | for c in range(n): 6 | s = input() 7 | for bitstring in bitstrings: 8 | cnt = 0 9 | for subject in range(m): 10 | if bitstring[subject]=='1' or s[subject]=='1': 11 | cnt+=1 12 | if cnt == best: 13 | amt+=1 14 | elif cnt > best: 15 | best = cnt 16 | amt = 1 17 | bitstrings.append(s) 18 | print(best) 19 | print(amt) -------------------------------------------------------------------------------- /hackerrank/GENERAL/algorithmic_crush_one_line.py: -------------------------------------------------------------------------------- 1 | print(reduce((lambda x, y: (x[0]+y, max(x[1], x[0]+y))), (lambda l, N, M: l if [(lambda a, b, k: l.__setitem__(a-1,l[a-1]+k) if (l.__setitem__(b,l[b]-k) or True) else None)(*map(int, raw_input().split())) for i in range(M)] else None)(*(lambda N, M: ([0]*(N+1), N, M))(*map(int, raw_input().split()))), (0,0))[1]) #updating a difference table and then reducing it to find the max -------------------------------------------------------------------------------- /hackerrank/GENERAL/fib.py: -------------------------------------------------------------------------------- 1 | b, a, n = [int(x) for x in input().split()] 2 | for i in range(n-2): 3 | new = a*a + b 4 | b = a 5 | a = new 6 | print(a) 7 | -------------------------------------------------------------------------------- /hackerrank/GENERAL/the_great_xor_one_line.py: -------------------------------------------------------------------------------- 1 | [print((lambda x: (pow(2, x.bit_length())-1) ^ x)(int(input()))) for q in range(int(input()))] 2 | #https://www.hackerrank.com/challenges/the-great-xor/problem -------------------------------------------------------------------------------- /hackerrank/GENERAL/two_characters_one_line.py: -------------------------------------------------------------------------------- 1 | print((lambda _, w: max(len([l for l in w if l in (i,j)]) if not (lambda x: (any(x[y]==x[y-1] for y in range(1,len(x))) or len(x)==1) )([l for l in w if l in (i,j)]) else 0 for i in 'abcdefghijklmnopqrstuvwxyz' for j in 'abcdefghijklmnopqrstuvwxyz'))(input(), input())) 2 | #https://www.hackerrank.com/contests/world-codesprint-7/challenges/two-characters/copy-from/1301772613 -------------------------------------------------------------------------------- /hackerrank/ad_infinitum_18/A_oneline.py: -------------------------------------------------------------------------------- 1 | print((lambda b, a: int(2*a/b + 0.999999999))(*map(int, input().split()))) -------------------------------------------------------------------------------- /hackerrank/asian_pacific_american_heritage_month_2021/readme.md: -------------------------------------------------------------------------------- 1 | I guess (python?) recursion uses too much of the stack and segfaults hackerrank, so I lost a bunch of time. I think I would have been firstish place? Ended up with 8th place, finishing in 1:07:53. -------------------------------------------------------------------------------- /hackerrank/celebrate_junteenth_2021/c.py: -------------------------------------------------------------------------------- 1 | # same problem as c in `covid19_relief_for_india` contest. just copy-pasted from that solution. 2 | -------------------------------------------------------------------------------- /hackerrank/celebrate_junteenth_2021/d.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitamintK/AlgorithmProblems/7f3b88d15513c24424254a6b44a1a557267ea1c7/hackerrank/celebrate_junteenth_2021/d.png -------------------------------------------------------------------------------- /hackerrank/celebrate_pride_2021/readme.md: -------------------------------------------------------------------------------- 1 | 5th out of 1071 participants 2 | (ostensibly 8th out of 1074 participants, but the top 3 cheated, since they each finished in 2 minutes) -------------------------------------------------------------------------------- /hackerrank/code_cpp3/operatoroverloading.cpp: -------------------------------------------------------------------------------- 1 | std::ostream& operator << (std::ostream& outs, const Complex& x){ 2 | outs << x.a << "+i" << x.b << endl; 3 | return outs; 4 | } 5 | Complex operator + (const Complex& a, const Complex& b){ 6 | Complex ret = Complex(); 7 | ret.a = a.a + b.a; 8 | ret.b = a.b + b.b; 9 | return ret; 10 | } -------------------------------------------------------------------------------- /hackerrank/code_cpp3/variablesizedarrays.cpp: -------------------------------------------------------------------------------- 1 | long N; 2 | long Q; 3 | cin >> N; 4 | cin >> Q; 5 | long k; 6 | long n; 7 | int** ns = new int*[N]; 8 | for(long i = 0; i < N; i++){ 9 | cin >> k; 10 | ns[i] = new int[k]; 11 | for(long x= 0; x < k; x++){ 12 | cin >> n; 13 | ns[i][x] = n; 14 | } 15 | } 16 | int a; 17 | int e; 18 | for(long j = 0; j < Q; j++){ 19 | cin >> a; 20 | cin >> e; 21 | cout << ns[a][e] << endl; 22 | } 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /hackerrank/covid19_relief_for_india/d_problem_statement.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitamintK/AlgorithmProblems/7f3b88d15513c24424254a6b44a1a557267ea1c7/hackerrank/covid19_relief_for_india/d_problem_statement.png -------------------------------------------------------------------------------- /hackerrank/covid19_relief_for_india/readme.md: -------------------------------------------------------------------------------- 1 | So far I'm in fifth place, finishing in 1:12:50 2 | All easy problems except d, which was quite interesting and I think my solution is actually suboptimal? -------------------------------------------------------------------------------- /hackerrank/dtcc_coding_contest/c.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Enter your query below. 3 | Please append a semicolon ";" at the end of the query 4 | */ 5 | -- select avg(b) from ( 6 | -- select count(*) as b from customer group by city_id) as t; 7 | SET @av = (SELECT AVG(b) from (select count(*) as b from customer group by city_id) as tt); 8 | 9 | select country_name, city_name, c from 10 | (select country_name, city_name, count(*) as c 11 | from customer join city on customer.city_id=city.id join country on city.country_id=country.id group by city_id) as t 12 | where c > @av; -------------------------------------------------------------------------------- /hackerrank/dtcc_coding_contest/d.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Enter your query below. 3 | Please append a semicolon ";" at the end of the query 4 | */ 5 | set @max_loc = (select location_id as c 6 | from companies 7 | group by location_id 8 | order by count(*) 9 | DESC 10 | limit 1); 11 | 12 | select people.name, companies.name 13 | from people join companies on people.COMPANY_ID=companies.id 14 | where companies.location_id=@max_loc; 15 | -------------------------------------------------------------------------------- /hackerrank/general/Euler/Problem2_one_line.py: -------------------------------------------------------------------------------- 1 | [print((lambda f: f(f,int(input())))(lambda f, n, x=0,y=1: (int(y%2==0))*y+f(f,n,y,x+y) if y\d)(?P=dig){2}|(?P\d)(.{4}(?P=dig2)){2})" # Do not delete 'r'. 2 | -------------------------------------------------------------------------------- /hackerrank/regular expresso 2/rescue_angie.php: -------------------------------------------------------------------------------- 1 | $Regex_Pattern = "/^(R(?2)|(?(princess)$|R(?2)))(?:(R(?4)|U(?3)|L(?1)))?(?:(D(?2)))?(?:(L(?2)|T(?5)))?(?:(U(?6)|T(?4)))?(?:(L(?7)|D(?5)))?(?:((?(princess)(?:L(?9)|R(?6))|(?:(?'princess'P)(?7)|L(?9)|R(?6)))))?(?:(R(?7)|J(?3)))?/"; //Do not delete '/'. Replace __________ with your regex. -------------------------------------------------------------------------------- /hackerrank/regular expresso 2/superior_string.py: -------------------------------------------------------------------------------- 1 | Regex_Pattern = r'^(.{2})*10(?!(.{2})*01)' # Do not delete 'r'. -------------------------------------------------------------------------------- /hackerrank/university_codesprint_3/A_python2.py: -------------------------------------------------------------------------------- 1 | print(input()) -------------------------------------------------------------------------------- /hackerrank/week_of_code_25/D_test.txt: -------------------------------------------------------------------------------- 1 | 1351029384619837703 10 2 | 3 5 7 9 11 13 17 19 23 29 -------------------------------------------------------------------------------- /hackerrank/week_of_code_27/a.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import sys 4 | 5 | 6 | n = int(input().strip()) 7 | p = int(input().strip()) 8 | # your code goes here 9 | from_back = n//2 - p//2 10 | from_front = p//2 11 | print(min(from_back, from_front)) -------------------------------------------------------------------------------- /hackerrank/week_of_code_27/b.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import sys 4 | 5 | 6 | n,p = input().strip().split(' ') 7 | n,p = [int(n),int(p)] 8 | a = [(int(a_temp)+p-1)//p for a_temp in input().strip().split(' ')] 9 | # your code goes here 10 | a.sort() 11 | for ind, i in enumerate(a): 12 | if ind > 0 and a[ind-1] >= a[ind]: 13 | a[ind] = a[ind-1]+1 14 | print(sum(a)) -------------------------------------------------------------------------------- /hackerrank/week_of_code_27/d.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import sys 4 | 5 | 6 | g = int(input().strip()) 7 | for a0 in range(g): 8 | n = int(input().strip()) 9 | p = [int(p_temp) for p_temp in input().strip().split(' ')] 10 | # your code goes here 11 | p = [x+2*(x%2)-1 for x in p] 12 | from functools import reduce 13 | print("L" if reduce(lambda a,b: a^b, p, 0)==0 else "W") 14 | 15 | -------------------------------------------------------------------------------- /hackerrank/week_of_code_27/readme.md: -------------------------------------------------------------------------------- 1 | [week of code 27](https://www.hackerrank.com/contests/w27/challenges) 2 | 3 | a = drawing book 4 | b = tailor shop 5 | c = hackonacci matrix rotations 6 | d = zero-move nim -------------------------------------------------------------------------------- /hackerrank/week_of_code_28/B_xor.py: -------------------------------------------------------------------------------- 1 | q = int(input().strip()) 2 | for a0 in range(q): 3 | x = int(input().strip()) 4 | b = bin(x)[2:] 5 | ans = 0 6 | for i in range(len(b)): 7 | if b[i] == '0': 8 | ans+= pow(2,len(b) - i -1) 9 | print(ans) 10 | -------------------------------------------------------------------------------- /hackerrank/week_of_code_33/B_pattern_count_one_line.py: -------------------------------------------------------------------------------- 1 | [print((lambda S: (lambda f: f(S, 0, -1, f))(lambda s, i, state, f: 0 if i >= len(s) else (1+f(s, i+1, 0, f) if state == 1 and s[i] == '1' else f(s, i+1, (0 if s[i] == '1' else (1 if s[i] == '0' and state in (0,1) else -1)), f))))(input())) for i in range(int(input()))] -------------------------------------------------------------------------------- /hackerrank/week_of_code_37/B_simple_language.py: -------------------------------------------------------------------------------- 1 | #I was the first one to solve this problem :D 2 | 3 | n = int(input()) 4 | x = 0 5 | for i in range(n): 6 | cmd, v = input().split() 7 | v = int(v) 8 | if cmd == 'set': 9 | if v < x: 10 | continue 11 | else: 12 | x = v 13 | else: 14 | if v < 0: 15 | continue 16 | else: 17 | x+=v 18 | print(x) 19 | -------------------------------------------------------------------------------- /hackerrank/world_codesprint_11/A_balanced_array_one_line.py: -------------------------------------------------------------------------------- 1 | print((lambda _, a: abs(sum(a[:len(a)//2]) - sum(a[len(a)//2:])))(input(), [int(x) for x in input().split()])) -------------------------------------------------------------------------------- /hackerrank/world_codesprint_11/B_numeric_string_one_line.py: -------------------------------------------------------------------------------- 1 | print(((lambda s, k, b, m: reduce(lambda n,i: ((b*(n[0]-int(s[i-k])*pow(b,k-1,m))%m+int(s[i]))%m,n[1]+(b*(n[0]-int(s[i-k])*pow(b,k-1,m))+int(s[i]))%m), range(k,len(s)), (int(s[:k],b)%m,int(s[:k],b)%m)))(raw_input(), *map(int, raw_input().split())))[1]) -------------------------------------------------------------------------------- /hackerrank/zalando_codesprint/A_match_the_shoes.py: -------------------------------------------------------------------------------- 1 | k, m, n = map(int, input().split()) 2 | from collections import defaultdict 3 | d = defaultdict(int) 4 | for i in range(n): 5 | d[input()]+=1 6 | print('\n'.join([i[0] for i in sorted(d.items(), key = lambda x: (x[1], -int(x[0])), reverse=True)[:k]])) -------------------------------------------------------------------------------- /hackerrank/zalando_codesprint/B_the_inquiring_manager.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | from collections import defaultdict 3 | d = defaultdict(lambda: -1) 4 | for i in range(n): 5 | inp = input().split() 6 | if(inp[0] == '1'): 7 | b, a = int(inp[1]), int(inp[2]) 8 | d[a] = max(d[a], b) 9 | else: 10 | a = int(inp[1]) 11 | maxmax = -1 12 | for j in range(60): 13 | maxmax = max(maxmax, d[a-j]) 14 | print(maxmax) -------------------------------------------------------------------------------- /icpc/2010_Swerc/three_sided_dice_kattis.py: -------------------------------------------------------------------------------- 1 | # https://open.kattis.com/problems/3sideddice 2 | # 40th most "difficult" problem on kattis with an 8% AC/submissions ratio 3 | 4 | while True: 5 | d1 = [int(x) for x in input().split()] 6 | if sum(d1) == 0: 7 | break 8 | d2 = [int(x) for x in input().split()] 9 | d3 = [int(x) for x in input().split()] 10 | g = [int(x) for x in input().split()] 11 | 12 | 13 | 14 | try: 15 | input() 16 | except EOFError: 17 | break -------------------------------------------------------------------------------- /icpc/2014_central_europe/D_sample.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 5 3 | 0 0 6 4 | 6 8 4 5 | -9 0 3 6 | 6 16 4 7 | 0 -11 4 -------------------------------------------------------------------------------- /icpc/2014_central_europe/Hcheck.py: -------------------------------------------------------------------------------- 1 | with open("H.out") as f1: 2 | r1 = f1.read() 3 | with open("H.out2") as f2: 4 | r2 = f2.read() 5 | 6 | for a,b in zip(r1.split('\n'), r2.split('\n')): 7 | print(a, b, "good!") 8 | if a not in b.split(): 9 | print(a, b, "oh shit") 10 | -------------------------------------------------------------------------------- /icpc/2014_central_europe/J_test: -------------------------------------------------------------------------------- 1 | 2 2 | 5 7 3 | 1 2 2 4 | 2 3 4 5 | 3 4 3 6 | 4 5 1 7 | 5 1 3 8 | 2 5 4 9 | 1 4 5 10 | 5 11 | 1 2 12 | 4 7 13 | 11 12 14 | 11 13 15 | 18 19 16 | 5 7 17 | 1 2 2 18 | 2 3 4 19 | 3 4 3 20 | 4 5 1 21 | 5 1 3 22 | 2 5 4 23 | 1 4 5 24 | 5 25 | 1 2 26 | 4 7 27 | 11 12 28 | 11 13 29 | 18 19 30 | -------------------------------------------------------------------------------- /icpc/2014_central_europe/K_test: -------------------------------------------------------------------------------- 1 | 1 2 | 3 1 3 | 10 5 4 | 8 1 5 | 20 12 6 | -------------------------------------------------------------------------------- /icpc/2014_central_europe/L.py: -------------------------------------------------------------------------------- 1 | a = int(input()) 2 | for i in range(a): 3 | b = int(input()) 4 | temp = [] 5 | for i in range(b): 6 | temp2 =[] 7 | for i in range(3): 8 | temp2.append(int(input())) 9 | temp.append(temp2) 10 | temp3 = [] 11 | for i in temp: 12 | temp3.append(tuple(i)) 13 | 14 | temp3 = sorted(temp3, key = lambda t: (t[0])) 15 | while(True): 16 | if temp3[0][0] == 1: 17 | return max([i[2] for i in temp3]) 18 | else: 19 | for i in temp3: 20 | i[2] = i[2] - 1 21 | i[0] = i[0] -1 22 | 23 | -------------------------------------------------------------------------------- /icpc/2014_central_europe/readme.md: -------------------------------------------------------------------------------- 1 | fully solved 1 2 | Kevin Wang 3 | Karthik Gajulapalli 4 | Linh Chu -------------------------------------------------------------------------------- /icpc/2015_midcentral_icpc/A_sample.txt: -------------------------------------------------------------------------------- 1 | 7 H right 2 | 15 B wrong 3 | 30 E wrong 4 | 35 E right 5 | 80 B wrong 6 | 80 B right 7 | 100 D wrong 8 | 100 C wrong 9 | 300 C right 10 | 300 D wrong 11 | -1 -------------------------------------------------------------------------------- /icpc/2015_midcentral_icpc/B_sample.txt: -------------------------------------------------------------------------------- 1 | 10 2 | ABC 3 | ABC 4 | ABC 5 | ABC 6 | ABC 7 | ABC 8 | ABC 9 | ABC 10 | ABC 11 | ABC 12 | -------------------------------------------------------------------------------- /icpc/2015_midcentral_icpc/C_sample.txt: -------------------------------------------------------------------------------- 1 | ABC HAPPYBIRTHDAY 2 | -------------------------------------------------------------------------------- /icpc/2015_midcentral_icpc/D_sample.txt: -------------------------------------------------------------------------------- 1 | 5 64 45 41 28 2 63 2 | -------------------------------------------------------------------------------- /icpc/2015_midcentral_icpc/E_sample.txt: -------------------------------------------------------------------------------- 1 | 4 2 | GEORGE 3 | JOHN 4 | PAUL 5 | RINGO -------------------------------------------------------------------------------- /icpc/2015_midcentral_icpc/G_sample.txt: -------------------------------------------------------------------------------- 1 | 2083 2 | 15093 3 | 15285 4 | 25147 5 | 31413 6 | 47797 7 | 49723 8 | 55989 9 | 58171 10 | 60085 11 | 95670 12 | -1 -------------------------------------------------------------------------------- /icpc/2015_midcentral_icpc/h_sample.txt: -------------------------------------------------------------------------------- 1 | 4 2 | -8 3 3 0 2 3 | -2 4 2 0 2 4 | 2 -2 2 0 2 5 | 8 -2 0 0 2 -------------------------------------------------------------------------------- /icpc/2015_midcentral_icpc/readme.md: -------------------------------------------------------------------------------- 1 | practice on October 1, 2015 2 | Performed on Kattis 3 | Karthik Gajulapalli 4 | Pasha Khosravi 5 | Kevin Wang -------------------------------------------------------------------------------- /icpc/2015_midcentral_icpc/readme.txt: -------------------------------------------------------------------------------- 1 | https://open.kattis.com/contests/na16warmup1 2 | https://open.kattis.com/contests/na16warmup1/problems 3 | A practice contest that Karthik, Pasha, and I did in a simulated ICPC setting on Kattis (prepared by NAIPC for practice) 4 | The first of hopefully many we will do. -------------------------------------------------------------------------------- /icpc/2015_new_york_regional/A_sample.txt: -------------------------------------------------------------------------------- 1 | 4 2 | 1 1/1 3 | 2 1/3 4 | 3 5/2 5 | 4 2178309/1346269 -------------------------------------------------------------------------------- /icpc/2015_new_york_regional/C_sample.txt: -------------------------------------------------------------------------------- 1 | 4 2 | 1 6 3 | 2 15 4 | 3 57 5 | 4 9999 -------------------------------------------------------------------------------- /icpc/2015_new_york_regional/D_sample.txt: -------------------------------------------------------------------------------- 1 | 3 2 | 1 10 0 2 3 | 2 15 1 4 4 | 3 28 3 7 -------------------------------------------------------------------------------- /icpc/2015_new_york_regional/E_running_steps.python.py: -------------------------------------------------------------------------------- 1 | #transcribed from my c++ code because the resulting numbers can be 2 | #too big to be stored in c++ long longs :( 3 | fact = [1] 4 | for i in range(1,200): 5 | fact.append(fact[-1]*i) 6 | p = int(input()) 7 | for i in range(p): 8 | n, s = map(int, input().split()) 9 | ans = 0 10 | for twos in range(0, s+1, 4): 11 | if s-twos <= twos/2: 12 | ones = s-twos 13 | res = fact[twos//4 + ones//2]//(fact[twos//4]*fact[ones//2]) 14 | ans+= res*res 15 | print(n, ans) 16 | -------------------------------------------------------------------------------- /icpc/2015_new_york_regional/F_sample.txt: -------------------------------------------------------------------------------- 1 | 11 2 | 1 1 3 | 2 2 4 | 3 8 5 | 4 20 6 | 5 46 7 | 6 60 8 | 7 3749999998 9 | 8 3749999999 10 | 9 3750000000 11 | 10 3750000001 12 | 11 281474976710656 -------------------------------------------------------------------------------- /icpc/2015_new_york_regional/G_sample.txt: -------------------------------------------------------------------------------- 1 | 2 2 | 1 4 3 | 1 2 3 0 4 | 3 0 1 0 5 | 2 4 6 | 1 2 3 0 7 | 2 2 1 2 -------------------------------------------------------------------------------- /icpc/2015_northwest/G_sample.txt: -------------------------------------------------------------------------------- 1 | 5 1 10 10 2 | 8 8 3 | 5 1 4 | 4 6 5 | 4 7 6 | 7 9 7 | 5 1 100 100 8 | 27 75 9 | 79 77 10 | 40 93 11 | 62 41 12 | 52 45 13 | 10 3 30 30 14 | 14 9 15 | 2 20 16 | 3 23 17 | 15 19 18 | 13 5 19 | 17 24 20 | 6 16 21 | 21 5 22 | 14 10 23 | 3 6 24 | 10 10 100 1000000000 25 | 99 1 26 | 0 1 27 | 50 1 28 | 100000000 1000000000 29 | 1 1000000000 30 | 1000000000 1 31 | 0 100 32 | 1 5 33 | 5 1 34 | 5 0 -------------------------------------------------------------------------------- /icpc/2015_socal_regional/H_persistence_7398.py: -------------------------------------------------------------------------------- 1 | from functools import reduce 2 | import operator 3 | while(True): 4 | try: 5 | n = int(input()) 6 | og = n 7 | except: 8 | break 9 | ans = 0 10 | while(n > 9): 11 | n = reduce(operator.mul, (int(x) for x in str(n))) 12 | ans+=1 13 | print(og, ans) 14 | -------------------------------------------------------------------------------- /icpc/2015_socal_regional/H_sample.txt: -------------------------------------------------------------------------------- 1 | 5 2 | 10 3 | 25 4 | 39 5 | 679 6 | 6788 7 | 26888999 8 | 999999999 9 | 1 10 | 10 11 | 100 12 | 1100 13 | 1500 14 | 552 15 | 55 16 | 5552 17 | 1 18 | 2 19 | 3 20 | 4 21 | 5 22 | 6 23 | 7 24 | 8 25 | 9 26 | 10 27 | 11 28 | 12 29 | 13 30 | 14 31 | 15 32 | 20 33 | 100 34 | 111 35 | 222 36 | 333 37 | 444 38 | 89 39 | 98 40 | 980 41 | 981 42 | 9811111111eof -------------------------------------------------------------------------------- /icpc/2016_midcentral_icpc/G_ada.py: -------------------------------------------------------------------------------- 1 | inp = [int(x) for x in input().split()] 2 | n = inp[0] 3 | xs = inp[1:] 4 | xss = [xs] 5 | while len(set(xs)) != 1: 6 | neo_xs = [] 7 | for i in range(1, len(xs)): 8 | neo_xs.append(xs[i] - xs[i-1]) 9 | xss.append(neo_xs) 10 | xs = neo_xs 11 | incr = 0 12 | for i in reversed(xss): 13 | new_val = i[-1] + incr 14 | incr = new_val 15 | print(len(xss) - 1, new_val) 16 | -------------------------------------------------------------------------------- /icpc/2016_new_york_regional/b_a_rational_sequence_3.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n = int(input().split()[1]) 4 | x = 0 5 | p = 1 6 | q = 1 7 | stack = [] 8 | nn = n 9 | while(nn != 1): 10 | stack.append(nn%2) 11 | nn//=2 12 | for i in reversed(stack): 13 | if i == 0: 14 | q = p+q 15 | else: 16 | p = p+q 17 | print(t+1, str(p)+'/'+str(q)) 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /icpc/2016_new_york_regional/c_da_sort.py: -------------------------------------------------------------------------------- 1 | #LIS? 2 | 3 | T = int(input()) 4 | for t in range(T): 5 | n = int(input().split()[1]) 6 | L = [] 7 | for i in range((n+9)//10): 8 | L.extend([int(x) for x in input().split()]) 9 | pt = 0 10 | LL = sorted(L) 11 | for i in L: 12 | if i == LL[pt]: 13 | pt += 1 14 | print(t+1, n - pt) 15 | -------------------------------------------------------------------------------- /icpc/2016_new_york_regional/f_m_ary_partitions.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | _, m, n = map(int, input().split()) 4 | multiplier = 1 5 | DP = [0] * (n+1) 6 | DP[0] = 1 7 | mm = 1 8 | ans = 1 9 | while mm <= n: 10 | for i in range(n+1): 11 | #if i%mm == 0: 12 | if i >= mm: 13 | DP[i] += DP[i-mm] 14 | mm*=m 15 | print(t+1, DP[-1]) 16 | -------------------------------------------------------------------------------- /icpc/2016_new_york_regional/j_which_base_is_it_anyway.py: -------------------------------------------------------------------------------- 1 | T = int(input()) 2 | for t in range(T): 3 | n = input().split()[1] 4 | oc = int(n,8) if all(x < '8' for x in n) else 0 5 | print(t+1, oc, int(n), int(n,16)) 6 | -------------------------------------------------------------------------------- /icpc/2016_northwestern_europe_regional/F_freeweights.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define ll long long 4 | #define ull unsigned long long 5 | using namespace std; 6 | 7 | int main(){ 8 | std::ios::sync_with_stdio(false); 9 | ll n; 10 | cin >> n; 11 | vector< 12 | for(ll i = 0; i < n; i++){ 13 | 14 | } 15 | for(ll i = 0; i < n; i++){ 16 | 17 | } 18 | return 0; 19 | } -------------------------------------------------------------------------------- /icpc/2016_northwestern_europe_regional/F_freeweights.py: -------------------------------------------------------------------------------- 1 | n = int(input().strip()) 2 | weight_weights = set() 3 | a = [int(x) for x in input().split()] 4 | b = [int(x) for x in input().split()] 5 | weight_weights.update(set(a)) 6 | weight_weights.update(set(b)) 7 | weight_weights = sorted(list(weight_weights)) 8 | weights = [(x,[]) for x in weight_weights] 9 | for ind, i in enumerate(a): 10 | weights[i].append((1,ind)) 11 | for ind, i in enumerate(b): 12 | weights[i].append((2,ind)) 13 | weights = zip( 14 | -------------------------------------------------------------------------------- /icpc/2016_northwestern_europe_regional/H_hypercube.py: -------------------------------------------------------------------------------- 1 | n, a, b = input().split() 2 | n = int(n) 3 | def get_position(bs): 4 | pos = 0 5 | parity = 1 6 | for index, bit in enumerate(bs): 7 | segment = pow(2,len(bs)-index - 1) 8 | if bit == '1': 9 | pos += segment*parity 10 | parity = 1-parity 11 | else: 12 | pos += segment * (1-parity) 13 | return pos 14 | print(get_position(b) - get_position(a) -1) 15 | -------------------------------------------------------------------------------- /icpc/2016_pacific_northwest/A_alphabet.py: -------------------------------------------------------------------------------- 1 | s = input() 2 | dp = [0 for x in s] 3 | for i in range(len(s)): 4 | for j in range(0,i): 5 | if s[i] > s[j]: 6 | dp[i] = max(dp[i], dp[j]+1) 7 | 8 | print(26 - max(dp) - 1) 9 | -------------------------------------------------------------------------------- /icpc/2016_socal_regional/Problem4.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define REP(i,a,b) for(int i = (a); i < b; i++) 4 | typedef long long ll; 5 | using namespace std; 6 | int main(){ 7 | int N, C, P; 8 | stack stk; 9 | int cur = 1; 10 | cin >> N >> C >> P; 11 | 12 | map m; 13 | m[1]++; 14 | 15 | REP(i, 0, C){ 16 | int command; 17 | cin >> command; 18 | cur += command; 19 | 20 | if (cur > N) cur %= N; 21 | 22 | else if (cur == 0) cur = N; 23 | m[cur]++; 24 | } 25 | 26 | cout << m[P] << '\n'; 27 | } 28 | -------------------------------------------------------------------------------- /icpc/2016_socal_regional/SC2016ICPCProblems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitamintK/AlgorithmProblems/7f3b88d15513c24424254a6b44a1a557267ea1c7/icpc/2016_socal_regional/SC2016ICPCProblems.pdf -------------------------------------------------------------------------------- /icpc/2017_east_central_NA_regional/C_DRM_messages.py: -------------------------------------------------------------------------------- 1 | s = raw_input() 2 | a = s[:len(s)/2] 3 | b = s[len(s)/2:] 4 | rot = sum(ord(x) - ord('A') for x in a) 5 | a = [(ord(x)-ord('A')+rot)%26 for x in a] 6 | 7 | rot = sum(ord(x) - ord('A') for x in b) 8 | b = [(ord(x)-ord('A')+rot)%26 for x in b] 9 | 10 | ans = [] 11 | for i in range(len(a)): 12 | ans.append(chr((a[i]+b[i])%26+ord('A'))) 13 | print(''.join(ans)) -------------------------------------------------------------------------------- /icpc/2017_east_central_NA_regional/D_game_of_throwns.py: -------------------------------------------------------------------------------- 1 | n, k = map(int, raw_input().split()) 2 | pos = 0 3 | s = raw_input().split() 4 | cmd = [] 5 | und = False 6 | for i in range(len(s)): 7 | if und: 8 | for j in range(int(s[i])): 9 | cmd.pop() 10 | und = False 11 | else: 12 | 13 | if s[i] == 'undo': 14 | und = True 15 | else: 16 | cmd.append(int(s[i])) 17 | 18 | print(sum(cmd)%n) -------------------------------------------------------------------------------- /icpc/2018_nwerc/I_inflation.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | balloons = list(range(1,n+1)) 3 | canisters = [int(x) for x in input().split()] 4 | canisters.sort() 5 | ans = 1 6 | ans = min(x/y if x<=y else -1 for x,y in zip(canisters, balloons)) 7 | if ans == -1: 8 | print('impossible') 9 | else: 10 | print(ans) 11 | -------------------------------------------------------------------------------- /icpc/2018_nwerc/h_hard_drive.py: -------------------------------------------------------------------------------- 1 | n, c, b = map(int, input().split()) 2 | 3 | broken = set(int(x)-1 for x in input().split()) 4 | 5 | dp = [0,0] 6 | 7 | ans = [0 for i in range(n)] 8 | 9 | cnt = 0 10 | 11 | flag = c%2 12 | for i in range(n): 13 | if cnt == c: 14 | break 15 | if i in broken: 16 | flag = 1 17 | else: 18 | ans[i] = flag 19 | flag = 1 - flag 20 | if i > 0 and ans[i] != ans[i-1]: 21 | cnt +=1 22 | print(''.join(str(x) for x in ans)) -------------------------------------------------------------------------------- /icpc/2018_nwerc/readme.md: -------------------------------------------------------------------------------- 1 | doing NAIPC practice contest 5 on kattis, which is nwerc 2018: https://open.kattis.com/contests/na19warmup5/standings -------------------------------------------------------------------------------- /icpc/maps_2020/d_greedy_polygons.py: -------------------------------------------------------------------------------- 1 | N = int(input()) 2 | import math 3 | for i in range(N): 4 | n, l, d, g = map(int, input().split()) 5 | apothem = l/(2*math.tan(math.pi/n)) 6 | initial_area = (apothem*l/2) * n 7 | rectangle_expansion = d * l * g * n 8 | circle_expansion = d * g * d * g * math.pi * n 9 | circle_proportion = (180 - (180 - 360/n))/360 10 | circle_expansion *= circle_proportion 11 | # print(initial_area, rectangle_expansion, circle_expansion) 12 | print(initial_area + rectangle_expansion + circle_expansion) 13 | 14 | # tan(2*pi/n) -------------------------------------------------------------------------------- /icpc/maps_2020/h_magical_cows.py: -------------------------------------------------------------------------------- 1 | c, n, m = map(int, input().split()) 2 | cows = [] 3 | import math 4 | for i in range(n): 5 | cow = int(input()) 6 | cows.append(math.ceil(math.log(c/(cow-0.00001), 2))) 7 | # print(cows) 8 | for j in range(m): 9 | d = int(input()) 10 | ans = 0 11 | for i in cows: 12 | if d < i: 13 | ans += 1 14 | else: 15 | ans += pow(2, d-i+1) 16 | print(ans) -------------------------------------------------------------------------------- /icpc/maps_2020/loool.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitamintK/AlgorithmProblems/7f3b88d15513c24424254a6b44a1a557267ea1c7/icpc/maps_2020/loool.png -------------------------------------------------------------------------------- /icpc/maps_2020/placement.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitamintK/AlgorithmProblems/7f3b88d15513c24424254a6b44a1a557267ea1c7/icpc/maps_2020/placement.png -------------------------------------------------------------------------------- /icpc/naipc2016/f/1.ans: -------------------------------------------------------------------------------- 1 | 0,0: 1 2 | 0,1: 1 3 | 0,2: 1 4 | 0,3: 1 5 | 0,4: 1 6 | 1,0: 0 7 | 1,1: 1 8 | 1,2: 2 9 | 1,3: 3 10 | 1,4: 4 11 | 2,0: 0 12 | 2,1: 1 13 | 2,2: 3 14 | 2,3: 6 15 | 2,4: 10 16 | 3,0: 0 17 | 3,1: 1 18 | 3,2: 4 19 | 3,3: 10 20 | 3,4: 20 21 | 4,0: 0 22 | 4,1: 1 23 | 4,2: 5 24 | 4,3: 15 25 | 4,4: 35 26 | 6050 -------------------------------------------------------------------------------- /icpc/naipc2016/f/2.ans: -------------------------------------------------------------------------------- 1 | 3876 2 | 15483 -------------------------------------------------------------------------------- /icpc/naipc2016/f/scenes-0000.ans: -------------------------------------------------------------------------------- 1 | 7770 2 | -------------------------------------------------------------------------------- /icpc/naipc2016/f/scenes-0001.ans: -------------------------------------------------------------------------------- 1 | 6050 2 | -------------------------------------------------------------------------------- /icpc/naipc2016/f/scenes-0002.ans: -------------------------------------------------------------------------------- 1 | 1022 2 | -------------------------------------------------------------------------------- /icpc/naipc2016/f/scenes-0003.ans: -------------------------------------------------------------------------------- 1 | 6 2 | -------------------------------------------------------------------------------- /icpc/naipc2017/a_parentheses.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define ll long long 5 | #define ull unsigned long long 6 | using namespace std; 7 | int main(){ 8 | std::ios::sync_with_stdio(false); 9 | int n; 10 | for(int i = 0; i < n; i++){ 11 | 12 | } 13 | return 0; 14 | } -------------------------------------------------------------------------------- /icpc/naipc2017/j.py: -------------------------------------------------------------------------------- 1 | print(1 if(sum([1 if i=="W" else -1 for i in input()]) == 0) else 0) 2 | -------------------------------------------------------------------------------- /icpc/naq2017/L.py: -------------------------------------------------------------------------------- 1 | import math 2 | def cosh(x): 3 | return (math.exp(x) + math.exp(-x))/2 4 | def sinh(x): 5 | return (math.exp(x) - math.exp(-x))/2 6 | 7 | eps = 1e-12 8 | 9 | d, s = map(int, input().split()) 10 | R = 1e13 11 | L = 0 12 | for i in range(123456): 13 | mid = (L+R)/2 14 | 15 | num = mid * (cosh(d/(2*mid))) - mid 16 | 17 | if num > s: 18 | L = mid 19 | else: 20 | R = mid 21 | 22 | a = (L+R)/2 23 | print(2 * a * sinh(d/(2*a))) 24 | -------------------------------------------------------------------------------- /icpc/naq2020/e.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | edges = [[] for i in range(n)] 3 | total = 0 4 | for i in range(n-1): 5 | u, v, p = map(int, input().split()) 6 | edges[u].append((v,p)) 7 | edges[v].append((u,p)) 8 | total += p 9 | 10 | ans = total 11 | for i in range(n): 12 | vals = [p for v,p in edges[i]] 13 | sm = sum(vals) 14 | mx = max(vals) 15 | if mx > sm-mx: 16 | save = sm-mx 17 | else: 18 | save = sm//2 19 | ans -= save 20 | print(ans) -------------------------------------------------------------------------------- /icpc/naq2020/results.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitamintK/AlgorithmProblems/7f3b88d15513c24424254a6b44a1a557267ea1c7/icpc/naq2020/results.png -------------------------------------------------------------------------------- /ieeextreme/IEEEXtreme10/J_sample.txt: -------------------------------------------------------------------------------- 1 | 3 2 | .......o 3 | .x.x.x.. 4 | xxxx.xx. 5 | ........ 6 | ........ 7 | .x.xx..x 8 | x....... 9 | ..x...x. 10 | 11 | ........ 12 | ........ 13 | ....o... 14 | ........ 15 | ....x... 16 | ........ 17 | ........ 18 | ........ 19 | 20 | ...o.... 21 | ........ 22 | ...x.... 23 | ........ 24 | ........ 25 | ........ 26 | ........ 27 | ........ -------------------------------------------------------------------------------- /ieeextreme/IEEEXtreme10/V_sample.txt: -------------------------------------------------------------------------------- 1 | 4 2 | 3 | ..... ..... 4 | ..... .X... 5 | .X.X. XXX.. 6 | ..X.. .X... 7 | .X.X. .X... 8 | 9 | ..... ..... 10 | XXX.. XXXX. 11 | X..X. XXXX. 12 | X.... X.... 13 | X.... XXXX. 14 | 15 | ..... ..... 16 | X...X XXXX. 17 | XX.XX XXXX. 18 | X.X.X X.... 19 | X...X XXXX. 20 | 21 | ..X.. ..X.. 22 | ..X.. .X.X. 23 | ..X.. .X.X. 24 | ..X.. .X.X. 25 | ..X.. ..X.. -------------------------------------------------------------------------------- /ieeextreme/IEEEXtreme8/README.md: -------------------------------------------------------------------------------- 1 | IEEEXtreme-8.0 2 | ============== 3 | 4 | Python solutions for some IEEEXtreme 8.0 5 | -------------------------------------------------------------------------------- /ieeextreme/IEEEXtreme8/coffe3.txt: -------------------------------------------------------------------------------- 1 | 3 4 2 | -*H*- 3 | M*M*- 4 | H*-*L 5 | H*L*M 6 | Monday 7 | 30*1*1 8 | 20*13*1 9 | 0*0*0 10 | 2*20*10 11 | Tuesday 12 | 0*2*2 13 | 0*1*1 14 | 1*1*1 15 | 3*5*0 16 | Wednesday 17 | 0*0*2 18 | 1*1*3 19 | 0*0*1 20 | 15*0*2 21 | Thursday 22 | 0*1*1 23 | 0*1*0 24 | 0*1*1 25 | 1*0*2 26 | Friday 27 | 0*0*0 28 | 0*2*3 29 | 0*1*1 30 | 5*100*0 31 | Saturday 32 | 0*2*0 33 | 1*3*0 34 | 0*1*2 35 | 0*20*20 36 | Sunday 37 | 0*2*3 38 | 0*1*0 39 | 1*0*0 40 | 0*25*20 -------------------------------------------------------------------------------- /ieeextreme/IEEEXtreme8/coffee.txt: -------------------------------------------------------------------------------- 1 | 3 3 2 | -*H*- 3 | M*M*- 4 | H*-*L 5 | Monday 6 | 30*1*1 7 | 20*13*1 8 | 0*0*0 9 | Tuesday 10 | 0*2*2 11 | 0*1*1 12 | 1*1*1 13 | Wednesday 14 | 0*0*2 15 | 1*1*3 16 | 0*0*1 17 | Thursday 18 | 0*1*1 19 | 0*1*0 20 | 0*1*1 21 | Friday 22 | 0*0*0 23 | 0*2*3 24 | 0*1*1 25 | Saturday 26 | 0*2*0 27 | 1*3*0 28 | 0*1*2 29 | Sunday 30 | 0*2*3 31 | 0*1*0 32 | 1*0*0 -------------------------------------------------------------------------------- /ieeextreme/IEEEXtreme8/heist.txt: -------------------------------------------------------------------------------- 1 | 4 8089000 2 | Diamond,2000000,200 3 | Ruby,3500000,400 4 | Gold,10000000,1000 5 | Jewelry,1500000,160 6 | Money,1000000,100 7 | END -------------------------------------------------------------------------------- /ieeextreme/IEEEXtreme8/ieeepalindrome.txt: -------------------------------------------------------------------------------- 1 | lukeiamyourfather -------------------------------------------------------------------------------- /ieeextreme/IEEEXtreme8/kabloom.py: -------------------------------------------------------------------------------- 1 | def make_thing(inplist): 2 | stuff = inplist[:-1] 3 | things = [] 4 | for ind in range(0, len(stuff), 3): 5 | things.append((stuff[ind+1], stuff[ind+2])) 6 | return things 7 | 8 | def get_all_matches(): 9 | pass 10 | 11 | def main(): 12 | inp = open('kabloom.txt', 'r') 13 | #inp = sys.stdin 14 | inplist = [] 15 | for line in inp: 16 | inplist.append(line.strip()) 17 | games = make_thing(inplist) 18 | print(games) 19 | 20 | main() 21 | -------------------------------------------------------------------------------- /ieeextreme/IEEEXtreme8/kabloom.txt: -------------------------------------------------------------------------------- 1 | 7 2 | R R 5 4 A T Q 3 | Q 3 T A 8 8 8 4 | 13 5 | A 2 3 4 5 6 7 8 9 T J Q K 6 | K Q J T 9 8 7 6 5 4 3 2 A 7 | 6 8 | A A A A A A 9 | K Q J T 9 8 10 | 13 11 | A 2 3 4 5 6 7 8 9 T J Q K 12 | A 2 3 4 5 6 7 8 9 T J Q K 13 | 0 -------------------------------------------------------------------------------- /ieeextreme/IEEEXtreme8/lottery.txt: -------------------------------------------------------------------------------- 1 | 1 10000 4 2 2 | 62 3 | 63 -------------------------------------------------------------------------------- /ieeextreme/IEEEXtreme8/lottery2.txt: -------------------------------------------------------------------------------- 1 | 1 10000 999999 2 2 | 62 3 | 63 -------------------------------------------------------------------------------- /ieeextreme/IEEEXtreme8/magic.txt: -------------------------------------------------------------------------------- 1 | 4 2 | 16 3 2 13 3 | 5 10 11 8 4 | 6 9 7 12 5 | 4 15 14 1 -------------------------------------------------------------------------------- /ieeextreme/IEEEXtreme8/pipeline.txt: -------------------------------------------------------------------------------- 1 | 5 2 | 1 1 9 1 1 3 | 3 1 9 7 1 4 | 4 1 9 1 1 5 | 5 1 1 1 5 6 | 6 1 9 3 1 -------------------------------------------------------------------------------- /ieeextreme/IEEEXtreme8/sumitup.txt: -------------------------------------------------------------------------------- 1 | 5 2 | 1 2 3 4 5 3 | 2 4 | 1 5 | 0 -------------------------------------------------------------------------------- /ieeextreme/IEEEXtreme9/Pattern3_naive_unoptimized.py: -------------------------------------------------------------------------------- 1 | import math 2 | n = int(input()) 3 | for _ in range(n): 4 | s = input() 5 | so_far = "" 6 | for i in s: 7 | so_far += i 8 | if all((x[0] == x[1] for x in zip((so_far*math.ceil(len(s)/len(so_far)))[:len(s)],s))): 9 | print(len(so_far)) 10 | break 11 | -------------------------------------------------------------------------------- /ieeextreme/IEEEXtreme9/zoomin.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | m = int(input()) 3 | k = int(input()) 4 | alphabet = dict() 5 | for k in range(k): 6 | letter = input() 7 | zoomed = [] 8 | for line in range(m): 9 | zoomed.append(input()) 10 | alphabet[letter] = zoomed 11 | x = int(input()) 12 | for sample in range(x): 13 | s = input() 14 | if s == '': 15 | for _ in range(m): 16 | print('') 17 | else: 18 | string = '\n'.join([''.join(y) for y in zip(*[alphabet[z] for z in s])]) 19 | print(string) 20 | -------------------------------------------------------------------------------- /leetcode/b33/a.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def thousandSeparator(self, n: int) -> str: 3 | return '{0:,}'.format(n).replace(',','.') -------------------------------------------------------------------------------- /leetcode/b33/b.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findSmallestSetOfVertices(self, n: int, edges: List[List[int]]) -> List[int]: 3 | s = set(range(n)) 4 | for e in edges: 5 | u, v = e 6 | s.discard(v) 7 | return list(s) -------------------------------------------------------------------------------- /leetcode/b33/c.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minOperations(self, nums: List[int]) -> int: 3 | ans = 0 4 | doubles = 0 5 | for n in nums: 6 | d = 0 7 | while n > 1: 8 | ans += n%2 9 | d += 1 10 | n//=2 11 | if n > 0: 12 | ans += 1 13 | doubles = max(doubles, d) 14 | return ans + doubles -------------------------------------------------------------------------------- /leetcode/b33/readme.md: -------------------------------------------------------------------------------- 1 | [Biweekly contest 33](https://leetcode.com/contest/biweekly-contest-33) 2 | 3 | super easy problems, got rank 43 / 11366 4 | 5 | - Thousand Separator 6 | - Minimum Number of Vertices to Reach All Nodes 7 | - Minimum Numbers of Function Calls to Make Target Array 8 | - Detect Cycles in 2D Grid -------------------------------------------------------------------------------- /leetcode/b36/a.py: -------------------------------------------------------------------------------- 1 | class ParkingSystem: 2 | 3 | def __init__(self, big: int, medium: int, small: int): 4 | self.slots = [big, medium, small] 5 | 6 | def addCar(self, carType: int) -> bool: 7 | c = carType-1 8 | if self.slots[c] > 0: 9 | self.slots[c] -= 1 10 | return True 11 | return False 12 | 13 | 14 | # Your ParkingSystem object will be instantiated and called as such: 15 | # obj = ParkingSystem(big, medium, small) 16 | # param_1 = obj.addCar(carType) -------------------------------------------------------------------------------- /leetcode/b38/a.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def frequencySort(self, nums: List[int]) -> List[int]: 3 | print([nums.count(x) for x in nums]) 4 | n = list(sorted(nums, key = lambda x: (nums.count(x), -x))) 5 | # print(list(sorted(nums, key= lambda x: (nums.count(x))))) 6 | return n 7 | # APPARENTLY nums.sort(key=lambda x: nums.count(x)) DOES NOT WORK 8 | # because nums gets set to [] as an implementation detail of cpython >:( 9 | -------------------------------------------------------------------------------- /leetcode/b38/b.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int: 3 | p = [x for x,y in points] 4 | p.sort() 5 | ans = 0 6 | for i in range(1,len(p)): 7 | ans = max(ans, p[i]-p[i-1]) 8 | return ans -------------------------------------------------------------------------------- /leetcode/b57/a.py: -------------------------------------------------------------------------------- 1 | # https://leetcode.com/contest/biweekly-contest-57/problems/check-if-all-characters-have-equal-number-of-occurrences/ 2 | from collections import Counter 3 | class Solution: 4 | def areOccurrencesEqual(self, s: str) -> bool: 5 | c = Counter(s) 6 | return len(set(c.values())) == 1 -------------------------------------------------------------------------------- /leetcode/b57/readme.md: -------------------------------------------------------------------------------- 1 | 172th place 2 | 3 | https://leetcode.com/contest/biweekly-contest-57/ranking/7/ -------------------------------------------------------------------------------- /leetcode/b75/a.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minBitFlips(self, start: int, goal: int) -> int: 3 | x = 1 4 | ans = 0 5 | while x < 1123456789: 6 | if (x&start) != (x&goal): 7 | ans += 1 8 | x *= 2 9 | return ans 10 | -------------------------------------------------------------------------------- /leetcode/b75/b.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def triangularSum(self, nums: List[int]) -> int: 3 | while len(nums) > 1: 4 | nums = [(nums[i-1]+nums[i])%10 for i in range(1, len(nums))] 5 | return nums[0] -------------------------------------------------------------------------------- /leetcode/c158/a.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def balancedStringSplit(self, s: str): 3 | i = 0 4 | ans = 0 5 | for c in s: 6 | if c == 'R': 7 | i += 1 8 | else: 9 | i -=1 10 | if i == 0: 11 | ans +=1 12 | return ans -------------------------------------------------------------------------------- /leetcode/c168/a.py: -------------------------------------------------------------------------------- 1 | # Find Numbers with Even Number of Digits 2 | class Solution: 3 | def findNumbers(self, nums: List[int]) -> int: 4 | return len([x for x in nums if len(str(x))%2 == 0]) -------------------------------------------------------------------------------- /leetcode/c168/b.py: -------------------------------------------------------------------------------- 1 | # Divide Array in Sets of K Consecutive Numbers 2 | from collections import Counter 3 | class Solution: 4 | def isPossibleDivide(self, nums: List[int], k: int) -> bool: 5 | c = Counter(nums) 6 | if len(nums)%k != 0: 7 | return False 8 | for i in range(0, len(nums), k): 9 | start = min(k for k,v in c.items() if v != 0) 10 | for j in range(k): 11 | x = start+j 12 | if c[x] <= 0: 13 | return False 14 | c[x] -= 1 15 | return True -------------------------------------------------------------------------------- /leetcode/c181/a_target_array_in_order.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]: 3 | ans = [] 4 | for n, i in zip(nums, index): 5 | ans.insert(i, n) 6 | return ans 7 | -------------------------------------------------------------------------------- /leetcode/c189/a.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def busyStudent(self, startTime: List[int], endTime: List[int], queryTime: int) -> int: 3 | ans = 0 4 | for s, e in zip(startTime, endTime): 5 | if s <= queryTime <= e: 6 | ans += 1 7 | return ans 8 | -------------------------------------------------------------------------------- /leetcode/c189/b.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def arrangeWords(self, text: str) -> str: 3 | t = [x.lower() for x in text.split()] 4 | t.sort(key = lambda x: len(x)) 5 | t[0] = t[0].title() 6 | return ' '.join(t) -------------------------------------------------------------------------------- /leetcode/c189/c.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def peopleIndexes(self, favoriteCompanies: List[List[str]]) -> List[int]: 3 | ans = [] 4 | favoriteCompanies = [set(x) for x in favoriteCompanies] 5 | for i in range(len(favoriteCompanies)): 6 | for j in range(len(favoriteCompanies)): 7 | if i == j: 8 | continue 9 | if favoriteCompanies[i].issubset(favoriteCompanies[j]): 10 | break 11 | else: 12 | ans.append(i) 13 | return ans -------------------------------------------------------------------------------- /leetcode/c190/a.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isPrefixOfWord(self, sentence: str, searchWord: str) -> int: 3 | ans = -1 4 | for i, w in enumerate(sentence.split()): 5 | if searchWord == w[:len(searchWord)]: 6 | ans = i+1 7 | break 8 | return ans -------------------------------------------------------------------------------- /leetcode/c190/b.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxVowels(self, s: str, k: int) -> int: 3 | l = 0 4 | r = k-1 5 | ans = 0 6 | vowels = 0 7 | vlist = 'aeiou' 8 | for i in range(k): 9 | if s[i] in vlist: 10 | vowels +=1 11 | ans = vowels 12 | for i in range(k, len(s)): 13 | if s[i] in vlist: 14 | vowels +=1 15 | if s[i-k] in vlist: 16 | vowels -= 1 17 | ans = max(ans, vowels) 18 | return ans -------------------------------------------------------------------------------- /leetcode/c192/a.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def shuffle(self, nums: List[int], n: int) -> List[int]: 3 | ans = [] 4 | for i in range(n): 5 | ans.append(nums[i]) 6 | ans.append(nums[n+i]) 7 | return ans -------------------------------------------------------------------------------- /leetcode/c192/b.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def getStrongest(self, arr: List[int], k: int) -> List[int]: 3 | marr = [(v, i) for i,v in enumerate(arr)] 4 | marr.sort() 5 | m = marr[(len(arr)-1)//2][0] 6 | print(m) 7 | marr.sort(key=lambda x: (abs(m-x[0]),x[0]) , reverse=True) 8 | return [v for v,i in marr[:k]] 9 | 10 | 11 | -------------------------------------------------------------------------------- /leetcode/c193/a.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def runningSum(self, nums: List[int]) -> List[int]: 3 | presum = [] 4 | accum = 0 5 | for n in nums: 6 | accum += n 7 | presum.append(accum) 8 | return presum -------------------------------------------------------------------------------- /leetcode/c193/b.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | class Solution: 3 | def findLeastNumOfUniqueInts(self, arr: List[int], k: int) -> int: 4 | nums = Counter(arr) 5 | cnts = [v for k,v in nums.items()] 6 | cnts.sort(reverse=True) 7 | while k > 0: 8 | if cnts[-1] <= k: 9 | k -= cnts[-1] 10 | cnts.pop() 11 | else: 12 | break 13 | return len(cnts) -------------------------------------------------------------------------------- /leetcode/c193/readme.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/contest/weekly-contest-193/ 2 | 3 | finished in 32 min with 5 penalties (so a final time of 35 + 5*5 = 57 min) xD for 335/13794 place -------------------------------------------------------------------------------- /leetcode/c194/a.py: -------------------------------------------------------------------------------- 1 | # solved at 0:01:07 2 | class Solution: 3 | def xorOperation(self, n: int, start: int) -> int: 4 | nums = [start + 2*i for i in range(n)] 5 | accum = 0 6 | for i in nums: 7 | accum ^= i 8 | return accum -------------------------------------------------------------------------------- /leetcode/c194/readme.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/contest/weekly-contest-194 2 | 3 | 134 / 13808 best placement yet YEET 4 | 5 | solved the last problem at 1:29:09 (contest ends at 1:30:00) whew! didn't even realize I was close to the deadline though I thought I had 30 minutes to spare lol -------------------------------------------------------------------------------- /leetcode/c196/a.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def canMakeArithmeticProgression(self, arr: List[int]) -> bool: 3 | arr.sort() 4 | f = arr[1] - arr[0] 5 | for i in range(1, len(arr)-1): 6 | if arr[i+1]-arr[i] != f: 7 | return False 8 | return True -------------------------------------------------------------------------------- /leetcode/c196/b.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def getLastMoment(self, n: int, left: List[int], right: List[int]) -> int: 3 | h = [n-r for r in right] 4 | left.extend(h) 5 | return max(left) -------------------------------------------------------------------------------- /leetcode/c196/readme.md: -------------------------------------------------------------------------------- 1 | 554 / 14301 2 | 3 | partly because I was trying to get an O(n) solution for D and didn't finish in time but other submitted an O(n^2) solution that worked (constraint was 1 <= num.length <= 30000) -------------------------------------------------------------------------------- /leetcode/c197/a.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def numIdenticalPairs(self, nums: List[int]) -> int: 3 | ans = 0 4 | for i in range(len(nums)): 5 | for j in range(i+1, len(nums)): 6 | if nums[i] == nums[j]: 7 | ans += 1 8 | return ans -------------------------------------------------------------------------------- /leetcode/c197/b.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def numSub(self, s: str) -> int: 3 | ans = 0 4 | cur = 0 5 | for i in range(len(s)): 6 | if s[i] == '1': 7 | cur += 1 8 | ans += cur 9 | else: 10 | cur = 0 11 | return ans%1000000007 -------------------------------------------------------------------------------- /leetcode/c197/readme.md: -------------------------------------------------------------------------------- 1 | rank 196 / 13984 2 | 3 | Number of Good Pairs 4 | Number of Substrings With Only 1s 5 | Path with Maximum Probability 6 | Best Position for a Service Centre 7 | 8 | almost got rank 197 on contest 197 :( -------------------------------------------------------------------------------- /leetcode/c198/a.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def numWaterBottles(self, numBottles: int, numExchange: int) -> int: 3 | ans = 0 4 | b = 0 5 | while numBottles > 0: 6 | ans += numBottles 7 | b += numBottles 8 | numBottles = 0 9 | x = b//numExchange 10 | b -= x*numExchange 11 | numBottles += x 12 | return ans -------------------------------------------------------------------------------- /leetcode/c198/readme.md: -------------------------------------------------------------------------------- 1 | rank 75 / 15151 2 | 3 | solved the last problem at 1:28:08 proving that i am very clutch 4 | 5 | Water Bottles 6 | Number of Nodes in the Sub-Tree With the Same Label 7 | Maximum Number of Non-Overlapping Substrings 8 | Find a Value of a Mysterious Function Closest to Target -------------------------------------------------------------------------------- /leetcode/c199/a.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def restoreString(self, s: str, indices: List[int]) -> str: 3 | out = [None for i in range(len(s))] 4 | for i, j in enumerate(indices): 5 | out[j] = s[i] 6 | return ''.join(out) 7 | -------------------------------------------------------------------------------- /leetcode/c199/b.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minFlips(self, target: str) -> int: 3 | ans = 0 4 | c = '0' 5 | for i in range(len(target)): 6 | if target[i] != c: 7 | ans +=1 8 | c = target[i] 9 | return ans -------------------------------------------------------------------------------- /leetcode/c199/readme.md: -------------------------------------------------------------------------------- 1 | rank 135/14309 2 | 3 | https://leetcode.com/contest/weekly-contest-199/ 4 | 5 | A: Shuffle String 6 | B: Bulb Switcher IV 7 | C: Number of Good Leaf Nodes Pairs 8 | D: String Compression II 9 | 10 | solved D with 2 min to go (1:27:34) for another clutch finish -------------------------------------------------------------------------------- /leetcode/c200/a.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def countGoodTriplets(self, arr: List[int], a: int, b: int, c: int) -> int: 3 | ans = 0 4 | for k in range(len(arr)): 5 | for j in range(k): 6 | for i in range(j): 7 | if abs(arr[i]-arr[j]) <= a and abs(arr[k]-arr[j])<= b and abs(arr[i]-arr[k]) <= c: 8 | ans += 1 9 | return ans -------------------------------------------------------------------------------- /leetcode/c200/b.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def getWinner(self, arr: List[int], k: int) -> int: 3 | cnt = 0 4 | wn = 0 5 | for i in range(len(arr)): 6 | if wn > arr[i]: 7 | cnt +=1 8 | else: 9 | wn = arr[i] 10 | if i == 0: 11 | cnt = 0 12 | else: 13 | cnt = 1 14 | if cnt == k: 15 | return wn 16 | return max(arr) -------------------------------------------------------------------------------- /leetcode/c200/readme.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/contest/weekly-contest-200 2 | 3 | Count Good Triplets 4 | Find the Winner of an Array Game 5 | Minimum Swaps to Arrange a Binary Grid 6 | Get the Maximum Score 7 | 8 | worst placement in a while - 669 / 15383 -------------------------------------------------------------------------------- /leetcode/c203/a.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def mostVisited(self, n: int, rounds: List[int]) -> List[int]: 3 | start = rounds[0]-1 4 | end = rounds[-1]-1 5 | ans = [] 6 | while start != end: 7 | ans.append(start+1) 8 | start = (start + 1)%n 9 | ans.append(end+1) 10 | ans.sort() 11 | return ans -------------------------------------------------------------------------------- /leetcode/c203/b.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxCoins(self, piles: List[int]) -> int: 3 | piles.sort() 4 | ans = 0 5 | # print(piles) 6 | for i, e in enumerate(piles): 7 | if i < len(piles)//3: 8 | continue 9 | if i%2 == (len(piles)//3)%2: 10 | ans += e 11 | 12 | return ans -------------------------------------------------------------------------------- /leetcode/c203/readme.md: -------------------------------------------------------------------------------- 1 | Weekly contest 203 2 | 3 | I did this one while watching the Lakers game, so it took very long 4 | 5 | rank 868 / 15080 6 | 7 | - Most Visited Sector in a Circular Track 8 | - Maximum Number of Coins You Can Get 9 | - Find Latest Group of Size M 10 | - Stone Game V -------------------------------------------------------------------------------- /leetcode/c204/a.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def containsPattern(self, arr: List[int], m: int, k: int) -> bool: 3 | for start in range(len(arr)): 4 | if start + m*k > len(arr): 5 | break 6 | for j in range(m): 7 | if len(set(arr[start+j+n*m] for n in range(k))) != 1: 8 | break 9 | else: 10 | return True 11 | return False 12 | 13 | -------------------------------------------------------------------------------- /leetcode/c206/a.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def numSpecial(self, mat: List[List[int]]) -> int: 3 | rows = [sum(x) for x in mat] 4 | cols = [sum(mat[i][j] for i in range(len(mat))) for j in range(len(mat[0]))] 5 | ans = 0 6 | for i in range(len(mat)): 7 | for j in range(len(mat[0])): 8 | if mat[i][j] and rows[i] == 1 and cols[j] == 1: 9 | ans +=1 10 | return ans -------------------------------------------------------------------------------- /leetcode/c207/a.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def reorderSpaces(self, text: str) -> str: 3 | spaces = text.count(' ') 4 | words = text.strip().split() 5 | if len(words) > 1: 6 | num_space = spaces//(len(words)-1) 7 | s = (' '*num_space).join(words) 8 | s += ' '*(spaces%(len(words)-1)) 9 | else: 10 | s = words[0] + ' '*spaces 11 | return s -------------------------------------------------------------------------------- /leetcode/c210/a.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxDepth(self, s: str) -> int: 3 | ans = 0 4 | b = 0 5 | for l in s: 6 | if l == '(': 7 | b += 1 8 | elif l == ')': 9 | b -= 1 10 | ans = max(b, ans) 11 | return ans 12 | -------------------------------------------------------------------------------- /leetcode/c210/b.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maximalNetworkRank(self, n: int, roads: List[List[int]]) -> int: 3 | adj = [[] for i in range(n)] 4 | for u,v in roads: 5 | adj[u].append(v) 6 | adj[v].append(u) 7 | ans = 0 8 | for i in range(len(adj)): 9 | for j in range(i+1, len(adj)): 10 | x = len(adj[i]) + len(adj[j]) 11 | if j in adj[i]: 12 | x -= 1 13 | ans = max(ans, x) 14 | return ans -------------------------------------------------------------------------------- /leetcode/c254/a.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def numOfStrings(self, patterns: List[str], word: str) -> int: 3 | ans = 0 4 | for w in patterns: 5 | if w in word: 6 | ans +=1 7 | return ans -------------------------------------------------------------------------------- /leetcode/c254/b.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def rearrangeArray(self, nums: List[int]) -> List[int]: 3 | nums.sort() 4 | for i in range(2,len(nums),2): 5 | nums[i-1],nums[i] = nums[i], nums[i-1] 6 | return nums -------------------------------------------------------------------------------- /leetcode/c254/c.py: -------------------------------------------------------------------------------- 1 | MOD = 1000000007 2 | class Solution: 3 | def minNonZeroProduct(self, p: int) -> int: 4 | return (pow(pow(2,p)-2, pow(2,p-1) - 1, MOD) * (pow(2,p)-1))%MOD -------------------------------------------------------------------------------- /leetcode/c254/readme.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/contest/weekly-contest-254 -------------------------------------------------------------------------------- /leetcode/c289/a.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def digitSum(self, s: str, k: int) -> str: 3 | while len(s) > k: 4 | s = [int(x) for x in s] 5 | ss = [] 6 | for i in range(0,len(s),k): 7 | ss.append(sum(s[i:i+k])) 8 | s = ''.join(str(x) for x in ss) 9 | return s -------------------------------------------------------------------------------- /leetcode/c289/b.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | class Solution: 3 | def minimumRounds(self, tasks: List[int]) -> int: 4 | ans = 0 5 | ts = Counter(tasks) 6 | for k, v in ts.items(): 7 | if v==1: 8 | return -1 9 | ans += (v+2)//3 10 | return ans -------------------------------------------------------------------------------- /leetcode/c304/a.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minimumOperations(self, nums: List[int]) -> int: 3 | l = [x for x in nums if x > 0] 4 | return len(set(l)) -------------------------------------------------------------------------------- /leetcode/c304/b.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maximumGroups(self, grades: List[int]) -> int: 3 | grades.sort(reverse=True) 4 | i = 0 5 | while len(grades) > i: 6 | i += 1 7 | for j in range(i): 8 | grades.pop() 9 | return i -------------------------------------------------------------------------------- /leetcode/c364/a.py: -------------------------------------------------------------------------------- 1 | # 2864. Maximum Odd Binary Number 2 | class Solution: 3 | def maximumOddBinaryNumber(self, s: str) -> str: 4 | ones = s.count('1') 5 | zs = s.count('0') 6 | return '1' * (ones-1) + '0' * zs + '1' -------------------------------------------------------------------------------- /leetcode/c386/a.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isPossibleToSplit(self, nums: List[int]) -> bool: 3 | c = Counter(nums) 4 | for x in c: 5 | if c[x] > 2: 6 | return False 7 | return True -------------------------------------------------------------------------------- /leetcode/c386/readme.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/contest/weekly-contest-386 2 | Solved 3 out of 4. 3 | The ranking table says I got 46th out of 28377 or 71st, not sure why the two different numbers. My rating increased from 2367 to 2440, which is top 1,851 out of 579,240 (top 0.34%). -------------------------------------------------------------------------------- /leetcode/miscellaneous/p416_partition_equal_subset_sum_set.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def canPartition(self, nums): 3 | """ 4 | :type nums: List[int] 5 | :rtype: bool 6 | """ 7 | half = sum(nums)//2 8 | if half*2 != sum(nums): 9 | return False 10 | 11 | DP = {0} 12 | for i in range(len(nums)): 13 | n = {x for x in DP} 14 | for j in DP: 15 | n.add(j + nums[i]) 16 | DP = n 17 | 18 | return half in DP -------------------------------------------------------------------------------- /miscellaneous/advent-of-code/2018/boilerplate.py: -------------------------------------------------------------------------------- 1 | if True: 2 | while True: 3 | try: 4 | 5 | except EOFError: 6 | break 7 | else: 8 | pass -------------------------------------------------------------------------------- /miscellaneous/advent-of-code/2018/ldrbrd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitamintK/AlgorithmProblems/7f3b88d15513c24424254a6b44a1a557267ea1c7/miscellaneous/advent-of-code/2018/ldrbrd.png -------------------------------------------------------------------------------- /miscellaneous/advent-of-code/2018/readme.md: -------------------------------------------------------------------------------- 1 | ![personal stats](ldrbrd.png) -------------------------------------------------------------------------------- /miscellaneous/advent-of-code/2019/day_1.py: -------------------------------------------------------------------------------- 1 | if True: 2 | ans = 0 3 | while True: 4 | try: 5 | x = int(input()) 6 | x = x//3 - 2 7 | while x > 0: 8 | ans += x 9 | x = x//3 -2 10 | except EOFError: 11 | break 12 | print(ans) 13 | else: 14 | pass -------------------------------------------------------------------------------- /miscellaneous/advent-of-code/2019/day_8.py: -------------------------------------------------------------------------------- 1 | inp = input() 2 | seq = 25 * 6 3 | layers = [inp[x:x+seq] for x in range(0, len(inp), seq)] 4 | a = min(layers, key=lambda x: x.count('0')) 5 | print(a.count('1') * a.count('2')) 6 | 7 | pic = [] 8 | for i in range(seq): 9 | for j in layers: 10 | if j[i] != '2': 11 | pic.append(j[i]) 12 | break 13 | print(pic) 14 | i = 0 15 | for b in range(7): 16 | print(''.join(["@" if x=='1'else ' ' for x in pic[i:i+26]])) 17 | i += 25 -------------------------------------------------------------------------------- /miscellaneous/advent-of-code/2019/ldrbrd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitamintK/AlgorithmProblems/7f3b88d15513c24424254a6b44a1a557267ea1c7/miscellaneous/advent-of-code/2019/ldrbrd.png -------------------------------------------------------------------------------- /miscellaneous/advent-of-code/2019/readme.md: -------------------------------------------------------------------------------- 1 | ![personal stats](ldrbrd.png) 2 | 3 | woohoo! got on the global leaderboard this year - 82nd! 4 | -------------------------------------------------------------------------------- /miscellaneous/advent-of-code/2019/utils.py: -------------------------------------------------------------------------------- 1 | # bfs 2 | # dfs 3 | # dfs (recursive) 4 | # simple union find 5 | # segtree (obviously not going to be the expected/only solution, but could make an implementation task trivial?) 6 | # dijkstra/A* -------------------------------------------------------------------------------- /miscellaneous/advent-of-code/2020/day_13_attempt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitamintK/AlgorithmProblems/7f3b88d15513c24424254a6b44a1a557267ea1c7/miscellaneous/advent-of-code/2020/day_13_attempt.png -------------------------------------------------------------------------------- /miscellaneous/advent-of-code/2020/ldrbrd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitamintK/AlgorithmProblems/7f3b88d15513c24424254a6b44a1a557267ea1c7/miscellaneous/advent-of-code/2020/ldrbrd.png -------------------------------------------------------------------------------- /miscellaneous/advent-of-code/2020/readme.md: -------------------------------------------------------------------------------- 1 | ![personal stats](ldrbrd.png) 2 | 3 | Did not end up on the global top 100 this year :( 4 | -------------------------------------------------------------------------------- /miscellaneous/advent-of-code/2021/ldrbrd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitamintK/AlgorithmProblems/7f3b88d15513c24424254a6b44a1a557267ea1c7/miscellaneous/advent-of-code/2021/ldrbrd.png -------------------------------------------------------------------------------- /miscellaneous/advent-of-code/2021/readme.md: -------------------------------------------------------------------------------- 1 | ![personal stats](ldrbrd.png) 2 | 3 | Was very far off of the global leaderboard this year :( 4 | 5 | Tough year: I think the leaderboard got stronger, and I got weaker. I had fun though! 6 | 7 | -------------------------------------------------------------------------------- /miscellaneous/advent-of-code/2022/ldrbrd.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitamintK/AlgorithmProblems/7f3b88d15513c24424254a6b44a1a557267ea1c7/miscellaneous/advent-of-code/2022/ldrbrd.jpg -------------------------------------------------------------------------------- /miscellaneous/advent-of-code/2023/ldrbrd.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitamintK/AlgorithmProblems/7f3b88d15513c24424254a6b44a1a557267ea1c7/miscellaneous/advent-of-code/2023/ldrbrd.jpg -------------------------------------------------------------------------------- /miscellaneous/advent-of-code/my_star_summary.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitamintK/AlgorithmProblems/7f3b88d15513c24424254a6b44a1a557267ea1c7/miscellaneous/advent-of-code/my_star_summary.jpg -------------------------------------------------------------------------------- /miscellaneous/advent-of-code/readme.md: -------------------------------------------------------------------------------- 1 | 2017 is here: https://github.com/VitamintK/FrivolousStuffs/tree/master/advent_of_code/2017 2 | 3 | ![summary of my stars](my_star_summary.jpg) 4 | 5 | Results per year: 6 | 7 | 2018 8 | ![2018](2018/ldrbrd.png) 9 | 10 | 2019 11 | ![2019](2019/ldrbrd.png) 12 | 13 | 2020 14 | ![2020](2020/ldrbrd.png) 15 | 16 | 2021 17 | ![2021](2021/ldrbrd.png) 18 | 19 | 2022 20 | ![2022](2022/ldrbrd.jpg) 21 | 22 | 2023 23 | ![2023](2023/ldrbrd.jpg) -------------------------------------------------------------------------------- /miscellaneous/google-foobar/Google Foobar 2nd run/count_spanning_graphs.py: -------------------------------------------------------------------------------- 1 | import math 2 | def answer(N, K): 3 | necessary = N-1 4 | extra = K - necessary 5 | necessary_enum = math.factorial(N)/2 6 | if extra > 0: 7 | extra_enum = math.factorial(N*(N-1))/(math.factorial(extra)*math.factorial(N*(N-1) - extra)) 8 | else: 9 | extra_enum = 0 10 | return necessary_enum, extra_enum 11 | -------------------------------------------------------------------------------- /miscellaneous/google-foobar/pirates.py: -------------------------------------------------------------------------------- 1 | def answer(numbers): 2 | assert(len(numbers) >= 2) 3 | traversed = [0] 4 | current_pirate = numbers[0] 5 | while current_pirate not in traversed: 6 | traversed.append(current_pirate) 7 | current_pirate = numbers[current_pirate] 8 | return len(traversed) - traversed.index(current_pirate) 9 | 10 | -------------------------------------------------------------------------------- /miscellaneous/hacktech-heat/campus_directions.py: -------------------------------------------------------------------------------- 1 | t = int(input()) 2 | tests = map(int, input().split()) 3 | def gcd(num, div): 4 | #num = max(num, div) 5 | #div = min(num, div) 6 | if(div == 0): 7 | return num 8 | else: 9 | return gcd(div, num%div) 10 | for i in tests: 11 | print(int((((i+1) * i*4 )/gcd(i*4, i+1))/(i+1) + 1)) 12 | -------------------------------------------------------------------------------- /miscellaneous/hacktech-heat/computers.py: -------------------------------------------------------------------------------- 1 | n, m, s, x, y, z = map(int, input().split()) 2 | cost = x + y + z 3 | import math 4 | comps = s/n 5 | if comps * cost <= m: 6 | print(int(m - comps*cost)) 7 | else : 8 | print( int(m%cost)) 9 | -------------------------------------------------------------------------------- /miscellaneous/hacktech-heat/computers_mistaked.py: -------------------------------------------------------------------------------- 1 | #this version gets complete credit and passes all the test, but the logic 2 | #INCORRECT. However, a version with correct logic will fail the tests. 3 | #Meaning: the test cases were incorrect, and this is the program that is 4 | #likewise incorrect, and passes those incorrect testcases. 5 | n, m, s, x, y, z = map(int, input().split()) 6 | cost = x + y + z 7 | import math 8 | comps = s/n 9 | if comps * cost <= m: 10 | print(int(m - comps*cost)) 11 | else : 12 | print( int(m%cost)) 13 | -------------------------------------------------------------------------------- /miscellaneous/hacktech-heat/computers_nonmistaken.py: -------------------------------------------------------------------------------- 1 | #this version's logic is correct, but since the testcases were wrong, 2 | #this will not pass all the testcases. 3 | n, m, s, x, y, z = map(int, input().split()) 4 | cost = x + y + z 5 | import math 6 | comps = math.ceil(s/n) 7 | if comps * cost <= m: 8 | print(m - comps*cost)) 9 | else : 10 | print(m%cost) 11 | -------------------------------------------------------------------------------- /miscellaneous/openai-codex-challenge/c.py: -------------------------------------------------------------------------------- 1 | from typing import Dict, Union 2 | 3 | Tree = Dict[str, Union[str, "Tree"]] 4 | 5 | 6 | def decompress(compressed: str, tree: Tree) -> str: 7 | ans = [] 8 | t = tree 9 | for x in compressed: 10 | t = t[x] 11 | if t == str(t): 12 | ans.append(t) 13 | t = tree 14 | return ''.join(ans) 15 | 16 | # Examples 17 | print(decompress('110100100', {'0': 'a', '1': {'0': 'n', '1': 'b'}})) 18 | print(decompress('0111010100', {'0': {'0': 'x', '1': 'z'}, '1': 'y'})) -------------------------------------------------------------------------------- /notebook/boilerplate.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "os" 7 | ) 8 | 9 | func main() { 10 | var reader *bufio.Reader = bufio.NewReader(os.Stdin) 11 | var writer *bufio.Writer = bufio.NewWriter(os.Stdout) 12 | defer writer.Flush() 13 | var T int 14 | fmt.Scan(&T) 15 | var n int 16 | var k int 17 | var s string 18 | for t := 0; t < T; t++ { 19 | fmt.Fscan(reader, &n, &k) 20 | fmt.Fscan(reader, &s) 21 | 22 | fmt.Fprintln(writer, ans) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /notebook/boilerplate.py: -------------------------------------------------------------------------------- 1 | # based on the code of https://codeforces.com/profile/pajenegod and https://codeforces.com/profile/conqueror_of_tourist 2 | # for printing: they use print('\n'.join(map(str, out))) instead of for ...: print(ans) 3 | # use pypy 3-64 4 | import sys 5 | input = sys.stdin.readline -------------------------------------------------------------------------------- /notebook/checklists/python.md: -------------------------------------------------------------------------------- 1 | 1. sys.setrecursionlimit? 2 | -------------------------------------------------------------------------------- /notebook/cpp/notebook.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitamintK/AlgorithmProblems/7f3b88d15513c24424254a6b44a1a557267ea1c7/notebook/cpp/notebook.cpp -------------------------------------------------------------------------------- /notebook/racket/readme.md: -------------------------------------------------------------------------------- 1 | Implemented sorting as an exercise, not for practical purposes, since it's already part of the standard library. -------------------------------------------------------------------------------- /notebook/racket/sorting.bak: -------------------------------------------------------------------------------- 1 | #lang racket 2 | -------------------------------------------------------------------------------- /notebook/racket/sorting.rkt: -------------------------------------------------------------------------------- 1 | #lang racket 2 | (define (process-input) 3 | (let ([input (read)]) 4 | (+ input 3) 5 | ) 6 | ) 7 | 8 | (process-input) -------------------------------------------------------------------------------- /notebook/readme.md: -------------------------------------------------------------------------------- 1 | Code Snippets that I can copy-paste when I need a certain algorithm. 2 | 3 | TODO: 4 | - 2SAT 5 | - toposort 6 | - union-find stuff? 7 | - dijkstra skeleton 8 | - KMP 9 | - tree/graph stuff like fast LCA, fast tree diameter? 10 | - fulfill 6-year long intent to learn about segtrees + interval trees -------------------------------------------------------------------------------- /problem-statements/Not_Quite_Solved/README.MD: -------------------------------------------------------------------------------- 1 | This folder is for problems that I either barely solved, nearly solved, didn't solve, or didn't solve satisfactorily. -------------------------------------------------------------------------------- /problem-statements/Not_Quite_Solved/airports-English.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitamintK/AlgorithmProblems/7f3b88d15513c24424254a6b44a1a557267ea1c7/problem-statements/Not_Quite_Solved/airports-English.pdf -------------------------------------------------------------------------------- /problem-statements/Solved/README.MD: -------------------------------------------------------------------------------- 1 | This folder is for problems that I completely solved. -------------------------------------------------------------------------------- /project-euler/e10.py: -------------------------------------------------------------------------------- 1 | M = 2000000 + 1 2 | N = 10001 3 | sieve = [0 for i in range(M)] 4 | primesum = 0 5 | for i in range(2,M): 6 | if sieve[i] == 0: 7 | for j in range(i*2, M, i): 8 | sieve[j] = 1 9 | primesum += i 10 | print(primesum) -------------------------------------------------------------------------------- /project-euler/e14.py: -------------------------------------------------------------------------------- 1 | from functools import lru_cache 2 | n = 1000000 3 | 4 | @lru_cache 5 | def collatz(i): 6 | if i == 1: 7 | return 1 8 | if i%2 == 0: 9 | return 1 + collatz(i//2) 10 | else: 11 | return 1 + collatz(3*i+1) 12 | 13 | argmax = None 14 | maxval = 0 15 | for i in range(1,n+1): 16 | val = collatz(i) 17 | if val > maxval: 18 | maxval = val 19 | argmax = i 20 | print(argmax) -------------------------------------------------------------------------------- /project-euler/e15.py: -------------------------------------------------------------------------------- 1 | import math 2 | print(math.comb(20+20, 20)) -------------------------------------------------------------------------------- /project-euler/e16.py: -------------------------------------------------------------------------------- 1 | # thank god for python... no idea how i'd do this in any language without bignum... 2 | ans = pow(2,1000) 3 | print(sum(int(x) for x in str(ans))) -------------------------------------------------------------------------------- /project-euler/e169.py: -------------------------------------------------------------------------------- 1 | # doesn't work and problems after 100 should be private anyways 2 | # n = pow(10,25) 3 | # b = bin(n)[2:] 4 | # oneruns = [] 5 | # onerun = 0 6 | # for i in range(len(b)): 7 | # if b[i] == '1': 8 | # onerun +=1 9 | # else: 10 | # oneruns.append(onerun+1) 11 | # onerun = 0 12 | # print(oneruns) 13 | # if len(oneruns) == 0: 14 | # print(1) 15 | # else: 16 | # import functools 17 | # replaceways = functools.reduce(lambda x,y:x*y, oneruns, 1) 18 | # print(1 + replaceways) -------------------------------------------------------------------------------- /project-euler/e20.py: -------------------------------------------------------------------------------- 1 | # another problem that i legitimately wouldn't know how to solve without python... 2 | fac = 1 3 | for i in range(1,101): 4 | fac *= i 5 | ans = sum([int(x) for x in str(fac)]) 6 | print(ans) -------------------------------------------------------------------------------- /project-euler/e21.py: -------------------------------------------------------------------------------- 1 | import math 2 | storage = dict() 3 | ans = 0 4 | for i in range(1,10000): 5 | sm = 1 6 | for j in range(2,int(math.sqrt(i))+1): 7 | if i%j == 0: 8 | sm += j 9 | if i//j > j: 10 | sm += i//j 11 | if sm < i and storage[sm] == i: 12 | ans += sm + i 13 | print(i, sm) 14 | storage[i] = sm 15 | print(ans) -------------------------------------------------------------------------------- /project-euler/e22.py: -------------------------------------------------------------------------------- 1 | s = input() 2 | names = [] 3 | for name in s.split(','): 4 | name = name.strip('"') 5 | names.append(name) 6 | names.sort() 7 | ans = 0 8 | def get_score(name): 9 | return sum((1+ord(x)-ord('A')) for x in name) 10 | print(get_score('COLIN')) 11 | for i, name in enumerate(names): 12 | i = i+1 13 | ans += i * get_score(name) 14 | print(ans) -------------------------------------------------------------------------------- /project-euler/e24.py: -------------------------------------------------------------------------------- 1 | def get_next(perm): 2 | for i in reversed(range(len(perm))): 3 | if perm[i-1] < perm[i]: 4 | n = i-1 5 | break 6 | for i in reversed(range(n+1, len(perm))): 7 | if perm[i] > perm[n]: 8 | m = i 9 | break 10 | perm[m], perm[n] = perm[n], perm[m] 11 | perm[n+1:] = perm[:n:-1] 12 | return perm 13 | perm = [0,1,2,3,4,5,6,7,8,9] 14 | for i in range(1,1000000): 15 | perm = get_next(perm) 16 | # print(perm) 17 | print(*perm, sep='') -------------------------------------------------------------------------------- /project-euler/e25.py: -------------------------------------------------------------------------------- 1 | fib = [0,1] 2 | for i in range(2,200100): 3 | a = sum(fib) 4 | # print(i, a) 5 | fib = [fib[1], a] 6 | if len(str(a)) >= 1000: 7 | print(i) 8 | break 9 | -------------------------------------------------------------------------------- /project-euler/e28.py: -------------------------------------------------------------------------------- 1 | N = 1001 2 | ans = 1 3 | c = 1 4 | for i in range(1,N, 2): 5 | for _ in range(4): 6 | c += i+1 7 | ans += c 8 | # print(c) 9 | print(ans) -------------------------------------------------------------------------------- /project-euler/e30.py: -------------------------------------------------------------------------------- 1 | N = 5 2 | ans = 0 3 | for i in range(10,1123456): 4 | sm = 0 5 | x = i 6 | while x != 0: 7 | dig = x%10 8 | sm += pow(dig, N) 9 | x//=10 10 | if sm == i: 11 | ans += sm 12 | print(ans) -------------------------------------------------------------------------------- /project-euler/e31.py: -------------------------------------------------------------------------------- 1 | coins = [1,2,5,10,20,50,100,200] 2 | 3 | dp = [0 for i in range(201)] 4 | dp[0] = 1 5 | for i in range(len(coins)): 6 | coin = coins[i] 7 | for j in range(201): 8 | if j>=coin: 9 | dp[j] += dp[j-coin] 10 | print(dp[200]) -------------------------------------------------------------------------------- /project-euler/e32.py: -------------------------------------------------------------------------------- 1 | # brute force seems adequate. 2 | products = set() 3 | for a in range(100000): 4 | if len(set(str(a))) < len(str(a)): 5 | continue 6 | for b in range(100000): 7 | if len(set(str(a)+str(b))) < len(str(a)+str(b)): 8 | continue 9 | p = a*b 10 | cludge = str(a)+str(b)+str(p) 11 | if len(cludge) > 9: 12 | break 13 | if set(cludge) == set('123456789') and len(cludge)==9: 14 | print(a, b, p) 15 | products.add(p) 16 | print(sum(products)) -------------------------------------------------------------------------------- /project-euler/e34.py: -------------------------------------------------------------------------------- 1 | facs = [1] 2 | f = 1 3 | for i in range(1,10): 4 | f *= i 5 | facs.append(f) 6 | 7 | ans = 0 8 | for i in range (3, 4000000): 9 | agg = 0 10 | x = i 11 | while x != 0: 12 | agg += facs[x%10] 13 | x //= 10 14 | if agg==i: 15 | print(i) 16 | ans += i 17 | print(ans) -------------------------------------------------------------------------------- /project-euler/e35.py: -------------------------------------------------------------------------------- 1 | M = 1000000 2 | sieve = [-1 for i in range(M+1)] 3 | for i in range(2,M+1): 4 | if sieve[i] != -1: 5 | continue 6 | for j in range(i, M+1, i): 7 | sieve[j] = i 8 | 9 | 10 | def cyclic_shift(x, i): 11 | sx = str(x) 12 | return int(sx[i:] + sx[:i]) 13 | 14 | ans = 0 15 | for i in range(2, M): 16 | x = i 17 | for j in range(len(str(i))): 18 | if sieve[x] != x: 19 | break 20 | x = cyclic_shift(i, j+1) 21 | else: 22 | print(i) 23 | ans += 1 24 | 25 | print(ans) -------------------------------------------------------------------------------- /project-euler/e36.py: -------------------------------------------------------------------------------- 1 | def is_palindrome(string): 2 | return list(string)==list(reversed(string)) 3 | ans = 0 4 | for i in range(1000001): 5 | if not is_palindrome(str(i)): 6 | continue 7 | if not is_palindrome(bin(i)[2:]): 8 | continue 9 | ans += i 10 | print(ans) -------------------------------------------------------------------------------- /project-euler/e38.py: -------------------------------------------------------------------------------- 1 | 2 | from re import S 3 | 4 | 5 | best = "" 6 | argbest = None 7 | for i in range(1,900000): 8 | s = "" 9 | for j in range(1,10): 10 | prod = j*i 11 | s += str(prod) 12 | if len(s) > 9: 13 | break 14 | if len(s) > len(set(s)): 15 | break 16 | if set(s) == set('123456789'): 17 | if s > best: 18 | best = s 19 | argbest = i 20 | print(best, argbest) -------------------------------------------------------------------------------- /project-euler/e39.py: -------------------------------------------------------------------------------- 1 | from collections import defaultdict 2 | squares = dict() 3 | for i in range(2000): 4 | squares[i*i] = i 5 | perims = defaultdict(int) 6 | for a in range(1,1001): 7 | for b in range(a+1, 1001): 8 | if a*a+b*b not in squares: 9 | continue 10 | c = squares[a*a+b*b] 11 | perims[a+b+c] += 1 12 | for perim, v in sorted(perims.items(), key=lambda x:x[1]): 13 | if v >1 and perim <= 1000: 14 | print(perim, v) -------------------------------------------------------------------------------- /project-euler/e4.py: -------------------------------------------------------------------------------- 1 | ans = 0 2 | 3 | def is_pal(x): 4 | return str(x) == ''.join(reversed(str(x))) 5 | 6 | for i in range(1000): 7 | for j in range(i, 1000): 8 | x = i*j 9 | if is_pal(x) and x > ans: 10 | ans = x 11 | print(ans) -------------------------------------------------------------------------------- /project-euler/e42.py: -------------------------------------------------------------------------------- 1 | # zzzzz... wow a lot of these early problems are pretty uninteresting by today's standards. 2 | # then again, in 2004 doritos locos tacos were not yet invented, so there wasn't a whole lot to do 3 | 4 | # also this might be a decent jr engineer interviewing question 5 | 6 | 7 | -------------------------------------------------------------------------------- /project-euler/e5.py: -------------------------------------------------------------------------------- 1 | for i in range(1,1234567890): 2 | if i%10000 == 0: 3 | print(i) 4 | for j in range(1,21): 5 | if i%j != 0: 6 | break 7 | else: 8 | print(i) 9 | break 10 | -------------------------------------------------------------------------------- /project-euler/e6.py: -------------------------------------------------------------------------------- 1 | # well this is easy in python 2 | n = 100 3 | print(pow(sum(range(1,n+1)),2)-sum(i*i for i in range(1,n+1))) -------------------------------------------------------------------------------- /project-euler/e67.txt: -------------------------------------------------------------------------------- 1 | use code for e18.py -------------------------------------------------------------------------------- /project-euler/e7.py: -------------------------------------------------------------------------------- 1 | M = 112345678 2 | N = 10001 3 | sieve = [0 for i in range(M)] 4 | primes = 0 5 | for i in range(2,M): 6 | if sieve[i] == 0: 7 | for j in range(i*2, M, i): 8 | sieve[j] = 1 9 | primes += 1 10 | if primes == N: 11 | print(i) 12 | break -------------------------------------------------------------------------------- /project-euler/e9.py: -------------------------------------------------------------------------------- 1 | for i in range(1001): 2 | for j in range(i, 1001-i): 3 | k = 1000-i-j 4 | if k < 0: 5 | continue 6 | if i*i+j*j == k*k: 7 | print(i,j,k,i*j*k) 8 | break -------------------------------------------------------------------------------- /project-euler/readme.md: -------------------------------------------------------------------------------- 1 | just found out you're not supposed to reveal project euler solutions on the internet... 2 | 3 | It looks like the first 50-100 or so have pretty good coverage on the internet anyways, 4 | so I'm just going to include those here 5 | 6 | ![Project Euler badge](https://projecteuler.net/profile/vitaminK.png) 7 | 8 | friend code: `257898_9GOoLfAD5man36VuU9BqQirjwcSsrlbY` -------------------------------------------------------------------------------- /quora/qpc_2021/.ipynb_checkpoints/g_scratch-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [], 3 | "metadata": {}, 4 | "nbformat": 4, 5 | "nbformat_minor": 4 6 | } 7 | -------------------------------------------------------------------------------- /quora/qpc_2021/problemset.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitamintK/AlgorithmProblems/7f3b88d15513c24424254a6b44a1a557267ea1c7/quora/qpc_2021/problemset.pdf -------------------------------------------------------------------------------- /quora/qpc_2021/results.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VitamintK/AlgorithmProblems/7f3b88d15513c24424254a6b44a1a557267ea1c7/quora/qpc_2021/results.png --------------------------------------------------------------------------------