├── .gitignore ├── 10kindsofpeople.cpp ├── 2048.cpp ├── 3dprinter.cpp ├── 4thought.py ├── 8queens.cpp ├── a1paper.cpp ├── aaah.cpp ├── abandonedanimal.cpp ├── abc.cpp ├── aboveaverage.cpp ├── absurdistan3.cpp ├── acm.cpp ├── acm2.cpp ├── ada.cpp ├── addingwords.py ├── adjoin.cpp ├── airconditioned.cpp ├── akcija.cpp ├── alicedigital.cpp ├── aliennumbers.cpp ├── alldifferentdirections.cpp ├── allpairspath.cpp ├── almostperfect.cpp ├── almostunionfind.cpp ├── alphabet.cpp ├── alphabetspam.cpp ├── amanda.cpp ├── amazingadventures.cpp ├── amoebas.cpp ├── amsterdamdistance.cpp ├── anagramcounting.py ├── androids.cpp ├── anotherbrick.cpp ├── anothercandies.cpp ├── anthonyanddiablo.cpp ├── anti11.py ├── antiarithmetic.cpp ├── ants.cpp ├── apaxiaaans.cpp ├── aplusb.cpp ├── apples.cpp ├── applesack.cpp ├── aprizenoonecanwin.cpp ├── arachnophobia.cpp ├── arcticnetwork.cpp ├── areal.cpp ├── arithmetic.cpp ├── armystrengtheasy.cpp ├── armystrengthhard.cpp ├── artichoke.cpp ├── artwork.cpp ├── asciiaddition.cpp ├── asciifigurerotation.cpp ├── assemblyline.cpp ├── automatictrading.cpp ├── autori.cpp ├── averageseasy.cpp ├── averageshard.cpp ├── avion.cpp ├── avoidingtheapocalypse.cpp ├── avoidland.cpp ├── awkwardparty.cpp ├── babelfish.cpp ├── babybites.cpp ├── babylonian.cpp ├── backspace.cpp ├── baconeggsandspam.py ├── balanceddiet.cpp ├── ballbearings.cpp ├── ballotboxes.cpp ├── ballsandneedles.cpp ├── baloni.cpp ├── bank.cpp ├── bard.cpp ├── base2palindrome.cpp ├── basicremains.cpp ├── basketballoneonone.cpp ├── batmanacci.py ├── batterup.cpp ├── battlesimulation.cpp ├── beatspread.cpp ├── beavergnaw.cpp ├── beehives.cpp ├── beehives2.cpp ├── beekeeper.cpp ├── bela.cpp ├── bells.cpp ├── bestbefore.cpp ├── bestcompression.cpp ├── bestrelayteam.cpp ├── bigtruck.cpp ├── bijele.cpp ├── bikegears.cpp ├── billiard.cpp ├── bing.cpp ├── bingoties.cpp ├── birdrescue.cpp ├── birthday.cpp ├── birthdayboy.cpp ├── bishops.cpp ├── bitbybit.cpp ├── bits.cpp ├── bitsequalizer.cpp ├── blackfriday.cpp ├── blobsofdoom.cpp ├── blockcrusher.cpp ├── boatparts.cpp ├── boggle.cpp ├── bookcircle.cpp ├── bookclub.cpp ├── bookingaroom.cpp ├── borg.cpp ├── bossbattle.cpp ├── bottledup.cpp ├── boundingrobots.cpp ├── boxes.cpp ├── bracketmatrix.cpp ├── brackets.cpp ├── bread.cpp ├── breakingbad.cpp ├── brexit.cpp ├── brickwall.cpp ├── bst.cpp ├── bubbletea.cpp ├── buggyrobot.cpp ├── buggyrobot2.cpp ├── builddeps.cpp ├── bumped.cpp ├── bus.cpp ├── busnumbers.py ├── busnumbers2.cpp ├── busyschedule.cpp ├── buttonbashing.cpp ├── caching.cpp ├── cake.cpp ├── cakeymccakeface.cpp ├── calculator.py ├── candlebox.cpp ├── candydivision.cpp ├── canofworms.cpp ├── canonical.cpp ├── cantinaofbabel.cpp ├── cantor.cpp ├── canvas.cpp ├── capsules.cpp ├── cardboardcontainer.cpp ├── cardtrick2.py ├── cargame.cpp ├── carrots.cpp ├── casual.cpp ├── catalan.py ├── catalansquare.py ├── catering.cpp ├── cats.cpp ├── catvsdog.cpp ├── caveexploration.cpp ├── cd.cpp ├── ceiling.cpp ├── centsavings.cpp ├── ceremony.cpp ├── cetiri.cpp ├── cetvrta.cpp ├── cezar.cpp ├── chanukah.cpp ├── character.cpp ├── chartingprogress.cpp ├── checkmateinone.cpp ├── chemistsvows.cpp ├── chess.cpp ├── chesstournament.cpp ├── chewbacca.cpp ├── chopin.cpp ├── citrusintern.cpp ├── classpicture.cpp ├── classrooms.cpp ├── classy.cpp ├── closestsums.cpp ├── closingtheloop.cpp ├── coast.cpp ├── coci.cpp ├── cokolada.cpp ├── cold.cpp ├── collatz.cpp ├── collatzconjecture.cpp ├── color.cpp ├── coloring.cpp ├── colouringbook.cpp ├── combinationlock.cpp ├── comma.cpp ├── committeeassignment.cpp ├── communicatingstrategy.cpp ├── communication.cpp ├── communicationssatellite.cpp ├── compass.cpp ├── compasscard.cpp ├── completingthesquare.cpp ├── compoundwords.cpp ├── compromise.cpp ├── concentration.cpp ├── conformity.cpp ├── congest.cpp ├── connectthedots.cpp ├── conquestcampaign.cpp ├── consecutivesums.cpp ├── conservation.cpp ├── control.cpp ├── conundrum.cpp ├── conversationlog.py ├── convexhull.cpp ├── convexhull2.cpp ├── convexpolygonarea.cpp ├── conveyorbelts.cpp ├── convoy.cpp ├── cookieselection.cpp ├── cookingwater.cpp ├── cool1.cpp ├── copsandrobbers.cpp ├── cordonbleu.cpp ├── countcircuits.cpp ├── countingstars.cpp ├── countingtriangles.cpp ├── coverup.cpp ├── crackingrsa.cpp ├── crane2.cpp ├── cranes.cpp ├── crne.py ├── cropeasy.cpp ├── crophard.cpp ├── crosscountry.cpp ├── crypto.cpp ├── cuchitunnels.cpp ├── cuckoo.cpp ├── cudoviste.cpp ├── cups.cpp ├── cursethedarkness.cpp ├── dancerecital.cpp ├── dartscores.cpp ├── dartscoring.cpp ├── dasblinkenlights.cpp ├── dasort.cpp ├── datum.cpp ├── deathknight.cpp ├── deathstar.cpp ├── deathtaxes.cpp ├── decodingthehallway.cpp ├── deduplicatingfiles.cpp ├── delivery.cpp ├── detaileddifferences.cpp ├── detour.cpp ├── diagonalcut.cpp ├── dicebetting.cpp ├── dicecup.cpp ├── dicegame.cpp ├── different.cpp ├── differentdistances.cpp ├── digicomp2.cpp ├── digraphs.cpp ├── diplomacy.cpp ├── dirtydriving.cpp ├── disastrousdoubling.py ├── display.cpp ├── distinctivecharacter.cpp ├── distributingseats.cpp ├── divideby100.cpp ├── divisible.cpp ├── dna.cpp ├── dominoes2.cpp ├── dominos.cpp ├── doodling.cpp ├── doorman.cpp ├── doors.cpp ├── doubleplusgood.cpp ├── downtime.cpp ├── dragonball1.cpp ├── draughts.cpp ├── dreamer.cpp ├── drivinglanes.cpp ├── drivingrange.cpp ├── drmmessages.cpp ├── droppingdirections.cpp ├── dst.cpp ├── dungeon.cpp ├── dutyscheduler.cpp ├── dvds.cpp ├── dyslectionary.cpp ├── easiest.cpp ├── eastereggs.cpp ├── easyascab.cpp ├── eatingout.cpp ├── egypt.cpp ├── elementarymath.cpp ├── elevatortrouble.cpp ├── eligibility.cpp ├── empleh.cpp ├── emptyingbaltic.cpp ├── encodedmessage.cpp ├── endlessknight.cpp ├── endor.cpp ├── enemyterritory.cpp ├── engineeringenglish.cpp ├── enlarginghashtables.cpp ├── enteringthetime.cpp ├── entertainmentbox.cpp ├── enviousexponents.cpp ├── equalsumseasy.cpp ├── equilibrium.cpp ├── equivalences.cpp ├── erase.cpp ├── erraticants.cpp ├── esej.cpp ├── estate.cpp ├── estimatingtheareaofacircle.cpp ├── euclidsgame.cpp ├── eulersnumber.cpp ├── europeantrip.cpp ├── evenodd.py ├── eventplanning.cpp ├── evenup.cpp ├── exactchange2.cpp ├── exactlyeletrical.cpp ├── exam.cpp ├── excellentengineers.cpp ├── excursion.cpp ├── explosion.cpp ├── factorfree.cpp ├── factovisors.cpp ├── factstone.cpp ├── factstone.py ├── factstone_nomath.cpp ├── factstone_nomath.py ├── fakescoreboard.cpp ├── faktor.cpp ├── falling.cpp ├── fallingapart.cpp ├── falsesecurity.cpp ├── fantasydraft.cpp ├── farmingmars.cpp ├── fastfood.cpp ├── fbiuniversal.cpp ├── fenwick.cpp ├── ferryloading4.cpp ├── figurinefigures.cpp ├── filip.cpp ├── findinglines.cpp ├── fire2.cpp ├── firefly.cpp ├── fishmongers.cpp ├── fizzbuzz.cpp ├── flagquiz.cpp ├── flexible.cpp ├── flipfive.cpp ├── flippingcards.cpp ├── floodingfields.cpp ├── flowergarden.cpp ├── flowerytrails.cpp ├── flowlayout.cpp ├── flowshop.cpp ├── flyingsafely.cpp ├── foldingacube.cpp ├── font.cpp ├── foosball.cpp ├── forestforthetrees.cpp ├── fractalarea.cpp ├── fractionallotion.cpp ├── freckles.cpp ├── freefood.cpp ├── freeweights.cpp ├── friday.cpp ├── fridge.cpp ├── froggie.cpp ├── froshweek.cpp ├── froshweek2.cpp ├── frosting.cpp ├── fruitslicer.cpp ├── fundamentalneighbors.cpp ├── funhouse.cpp ├── galaksija.cpp ├── game.cpp ├── gamenight.cpp ├── gamerank.cpp ├── gcds.cpp ├── gcpc.cpp ├── gearchanging.cpp ├── geneticsearch.cpp ├── genius.cpp ├── geometry.cpp ├── geppetto.cpp ├── getshorty.cpp ├── gettowork.cpp ├── glitchbot.cpp ├── globalwarming.cpp ├── goatrope.cpp ├── goingdutch.cpp ├── goldbach2.cpp ├── golfbot.cpp ├── golombrulers.cpp ├── gottacatchemall.cpp ├── gowithflow.cpp ├── grandopening.cpp ├── grandpabernie.cpp ├── grass.cpp ├── grasshopper.cpp ├── grassseed.cpp ├── greatswercporto.cpp ├── greedilyincreasing.cpp ├── greetingcard.cpp ├── greetings.cpp ├── grid.cpp ├── gridgame.cpp ├── gridmst.cpp ├── growlinggears.cpp ├── gruesomecave.cpp ├── guess.cpp ├── guessinggame.cpp ├── guessthedatastructure.cpp ├── halfacircle.cpp ├── hangingout.cpp ├── hangman.cpp ├── happyprime.cpp ├── happytrails.cpp ├── harshadnumbers.cpp ├── haybales.cpp ├── haypoints.cpp ├── heapstrees.cpp ├── heartrate.cpp ├── height.cpp ├── heirsdilemma.cpp ├── heliocentric.cpp ├── hello.cpp ├── helpaphd.py ├── helpme.cpp ├── herman.cpp ├── hiddenwords.cpp ├── hidingplaces.cpp ├── hindex.cpp ├── hissingmicrophone.cpp ├── hittingtargets.cpp ├── hogwarts2.cpp ├── holeynqueensbatman.cpp ├── honeyheist.cpp ├── hoppers.cpp ├── horror.cpp ├── horrorfilmnight.cpp ├── hothike.cpp ├── houseofcards.py ├── humancannonball2.py ├── hyacinth.cpp ├── hydrasheads.cpp ├── hypercube.cpp ├── iboard.cpp ├── icpcawards.cpp ├── icpcteamselection.cpp ├── iks.cpp ├── illiteracy.cpp ├── imagedecoding.py ├── importspaghetti.cpp ├── incaseofinvasion.cpp ├── incognito.cpp ├── industrialspy.cpp ├── insert.py ├── integerdivision.cpp ├── integerlists.cpp ├── intergalacticbidding.py ├── intersectingrectangles.cpp ├── introtation.cpp ├── inversefactorial.cpp ├── irepeatmyself.py ├── irrationaldivision.cpp ├── isahasa.cpp ├── isithalloween.cpp ├── islandhopping.cpp ├── islands.cpp ├── islands3.cpp ├── isomorphicinversion.cpp ├── itcanbearranged.cpp ├── iwannabe.cpp ├── jabuke.cpp ├── jabuke2.cpp ├── jackpot.cpp ├── janitortroubles.cpp ├── jewelrybox.cpp ├── jobexpenses.cpp ├── jobpostings.cpp ├── jointattack.cpp ├── jollyjumpers.cpp ├── joylessgame.cpp ├── judging.cpp ├── judgingmoose.cpp ├── juggler.cpp ├── jughard.cpp ├── jumpingmonkey.cpp ├── jumpingyoshi.cpp ├── junk.cpp ├── juryjeopardy.cpp ├── justaminute.cpp ├── karte.cpp ├── kastenlauf.cpp ├── kayaking.cpp ├── kemija.cpp ├── keyboard.cpp ├── keytocrypto.cpp ├── kingdoms.cpp ├── kingofthewaves.cpp ├── kingpinescape.cpp ├── kinversions.cpp ├── kitten.cpp ├── kletva.cpp ├── knapsack.cpp ├── knightsearch.cpp ├── knightsfen.cpp ├── kolone.cpp ├── kornislav.cpp ├── krizaljka.cpp ├── kutevi.cpp ├── ladder.cpp ├── landscaping.cpp ├── largesttriangle.cpp ├── lastfactorialdigit.cpp ├── lawnmower.cpp ├── leftandright.cpp ├── leftbeehind.cpp ├── lektira.cpp ├── lemonadetrade.cpp ├── licensetolaunch.cpp ├── likenooneeverwas.cpp ├── limbo1.py ├── lindenmayorsystem.cpp ├── lipschitzconstant.cpp ├── listgame.cpp ├── lockblocked.cpp ├── lockedtreasure.cpp ├── logo.cpp ├── longestlife.cpp ├── longincsubseq.cpp ├── longswaps.cpp ├── loopycabdrivers.cpp ├── loowater.cpp ├── lost.cpp ├── lostlineup.cpp ├── lostmap.cpp ├── loworderzeros.cpp ├── ls.cpp ├── luhnchecksum.cpp ├── mafija.cpp ├── magical3.cpp ├── magicalcrystals.cpp ├── magicalgcd.cpp ├── magicallights.cpp ├── mali.cpp ├── mancala.cpp ├── manhattanmornings.cpp ├── maptiles2.cpp ├── marblestree.cpp ├── marko.cpp ├── marswindow.cpp ├── marypartitions.cpp ├── mastermind.cpp ├── mathemagicians.cpp ├── matrix.cpp ├── maxflow.cpp ├── maximalsequences.cpp ├── measurement.cpp ├── megainversions.cpp ├── meowfactor.cpp ├── messages.cpp ├── metaprogramming.py ├── mia.cpp ├── millionairemadness.cpp ├── mincostmaxflow.cpp ├── minimumscalar.py ├── minorsetback.cpp ├── minspantree.cpp ├── mirror.cpp ├── misa.cpp ├── missinggnomes.cpp ├── mixedfractions.cpp ├── mjehuric.cpp ├── modulo.cpp ├── moneymatters.cpp ├── monotony.cpp ├── moretriangles.cpp ├── mosquito.cpp ├── moveablemaze.cpp ├── moviecollection.cpp ├── mububa.cpp ├── muddyhike.cpp ├── multigram.cpp ├── musicalnotation.cpp ├── musicalscales.cpp ├── musicyourway.cpp ├── nanagrams.cpp ├── narrowartgallery.cpp ├── nastyhacks.cpp ├── natjecanje.cpp ├── natrij.cpp ├── naturereserve.cpp ├── neighborhoodwatch.cpp ├── nesteddolls.cpp ├── newfiber.cpp ├── nikola.cpp ├── nine.cpp ├── nineknights.cpp ├── ninepacks.cpp ├── nodup.cpp ├── nonboringsequences.cpp ├── nonprimefactors.cpp ├── notamused.cpp ├── npuzzle.cpp ├── numberfun.cpp ├── numbersetseasy.cpp ├── numbersetshard.cpp ├── numbertree.cpp ├── nuremberg.cpp ├── obfuscation.cpp ├── oddgnome.cpp ├── oddities.cpp ├── oddmanout.cpp ├── officespace.cpp ├── oil2.cpp ├── oktalni.cpp ├── okvir.cpp ├── okviri.cpp ├── olderbrother.cpp ├── onechicken.cpp ├── ones.cpp ├── ontrack.cpp ├── openpitmining.cpp ├── opensource.py ├── orderlyclass.cpp ├── orders.cpp ├── ornaments.cpp ├── ostgotska.cpp ├── outing.cpp ├── overlappingmaps.cpp ├── owlandfox.cpp ├── ozljeda.cpp ├── pachinkoprobability.cpp ├── pachydermpeanutpacking.cpp ├── paint.cpp ├── paintings.cpp ├── pairingsocks.cpp ├── palindromesubstring.cpp ├── palindromicdna.cpp ├── palindromicpassword.cpp ├── parallelanalysis.cpp ├── parking.cpp ├── parking2.cpp ├── parsinghex.py ├── pascal.cpp ├── password.cpp ├── pathtracing.cpp ├── patuljci.cpp ├── pauleigon.cpp ├── pebblesolitaire.cpp ├── peg.cpp ├── peggamefortwo.cpp ├── penguins.cpp ├── peragrams.cpp ├── perfectpowers.cpp ├── periodicstrings.cpp ├── perket.cpp ├── permutationdescent.cpp ├── permutationencryption.cpp ├── permutedarithmeticsequence.cpp ├── persistent.py ├── pervasiveheartmonitor.py ├── pet.cpp ├── phonelist.cpp ├── pianolessons.cpp ├── pickupsticks.cpp ├── pieceofcake.cpp ├── pieceofcake2.cpp ├── piecesofparentheses.cpp ├── piglatin.cpp ├── pirate.cpp ├── pivot.cpp ├── pizza.cpp ├── pizza2.cpp ├── pizzahawaii.cpp ├── planestrainsnotautos.cpp ├── planina.cpp ├── plantingtrees.cpp ├── platforme.cpp ├── playfair.cpp ├── plowking.py ├── pointinpolygon.cpp ├── pokemon.cpp ├── pokemongogo.cpp ├── pokerhand.cpp ├── poklon.cpp ├── polygonarea.cpp ├── polymul1.cpp ├── polymul2.cpp ├── porpoises.cpp ├── pot.cpp ├── powers.cpp ├── powerstrings.cpp ├── prefixfreecode.cpp ├── prerequisites.cpp ├── primal.cpp ├── primalrepresentation.cpp ├── primaryarithmetic.py ├── primedrive.cpp ├── primepath.cpp ├── primereduction.cpp ├── primes2.cpp ├── primesieve.cpp ├── printingcosts.cpp ├── pripreme.cpp ├── problemclassification.cpp ├── program.cpp ├── programmingtutors.cpp ├── progressivescramble.cpp ├── promotions.cpp ├── prosjek2.cpp ├── provincesandgold.cpp ├── prozor.cpp ├── prsteni.cpp ├── prva.cpp ├── pseudoprime.cpp ├── ptice.cpp ├── putovanje.py ├── pyro.cpp ├── qaly.cpp ├── quadrant.cpp ├── quantumsuperposition.cpp ├── queens.cpp ├── quickbrownfox.cpp ├── quickestimate.cpp ├── quiteaproblem.cpp ├── r2.cpp ├── racingalphabet.cpp ├── radiotransmission.cpp ├── raggedright.cpp ├── ragingriver.cpp ├── railroad2.cpp ├── railway2.cpp ├── rainbowroadrace.cpp ├── rationalarithmetic.py ├── rationalsequence2.cpp ├── rationalsequence3.cpp ├── reachableroads.cpp ├── rebeldie.cpp ├── rebelportals.cpp ├── recenice.cpp ├── recipes.cpp ├── reconnaissance.cpp ├── recount.cpp ├── recovery.cpp ├── rectanglesurrounding.cpp ├── redbluetree.cpp ├── redistribution.cpp ├── redrover.py ├── reducedidnumbers.cpp ├── register.cpp ├── relatives.cpp ├── relocation.cpp ├── repeatedsubstrings.cpp ├── repeatingdecimal.cpp ├── reservoir.cpp ├── reseto.cpp ├── reversebinary.cpp ├── reverserot.cpp ├── rhyming.py ├── ricochetrobots.cpp ├── rijeci.cpp ├── rings2.cpp ├── robotopia.cpp ├── robotprotection.cpp ├── rockband.cpp ├── rockpaperscissors.cpp ├── rockscissorspaper.cpp ├── rollcall.cpp ├── romans.cpp ├── rotatecut.cpp ├── roundedbuttons.cpp ├── rubiksrevenge.cpp ├── runlengthencodingrun.cpp ├── runningmom.cpp ├── sabor.cpp ├── safe.cpp ├── safehouses.cpp ├── satisfiability.cpp ├── savez.cpp ├── savingdaylight.cpp ├── savingforretirement.cpp ├── saxophone.cpp ├── secretchamber.cpp ├── secretmessage.cpp ├── secretsantacycles.cpp ├── securedoors.cpp ├── sensornetwork.cpp ├── sequence.cpp ├── sequences.cpp ├── server.cpp ├── set.cpp ├── sevenwonders.cpp ├── shatteredcake.cpp ├── sheldon.py ├── shibuyacrossing.cpp ├── shiritori.cpp ├── shopaholic.py ├── shoppingmalls.cpp ├── shortestpath1.cpp ├── showroom.cpp ├── shuffling.cpp ├── sibice.cpp ├── sidewayssorting.cpp ├── signals.cpp ├── simon.cpp ├── simonsays.cpp ├── simpleaddition.cpp ├── simplicity.cpp ├── single.cpp ├── sjecista.cpp ├── skener.cpp ├── skocimis.cpp ├── slalom.cpp ├── slatkisi.py ├── slidingblocks.cpp ├── slika.cpp ├── smallestmultiple.py ├── smallschedule.cpp ├── smartphone.cpp ├── snappereasy.cpp ├── snapperhard.cpp ├── snowflakes.cpp ├── sodasurpler.cpp ├── softpasswords.cpp ├── sortofsorting.cpp ├── sound.cpp ├── soylent.cpp ├── spavanac.cpp ├── speed.cpp ├── speedlimit.cpp ├── spiderman.cpp ├── spiral.cpp ├── splat.cpp ├── sprocketscience.cpp ├── squaredeal.cpp ├── squares.cpp ├── squawk.cpp ├── srednji.cpp ├── standings.cpp ├── stararrangements.cpp ├── statistics.cpp ├── stickysituation.cpp ├── stockbroker.cpp ├── stogovi.cpp ├── stol.cpp ├── subsequencesinsubstrings.cpp ├── substringswitcheroo.cpp ├── subway.cpp ├── succession.cpp ├── suma.cpp ├── sumandproduct.cpp ├── sumkindofproblem.cpp ├── sumoftheothers.cpp ├── sumsquareddigits.cpp ├── supercomputer.cpp ├── superdoku.cpp ├── suspensionbridges.cpp ├── swapspace.cpp ├── swaptosort.cpp ├── symmetricorder.cpp ├── synchronizinglists.cpp ├── t9spelling.cpp ├── taisform.cpp ├── tajna.cpp ├── tank.cpp ├── targetpractice.cpp ├── tarifa.cpp ├── teamup.cpp ├── temperature.cpp ├── temperatureconfusion.cpp ├── terraces.cpp ├── tetration.cpp ├── tetris.cpp ├── textureanalysis.cpp ├── thanos.cpp ├── thebackslashproblem.cpp ├── thermostat.cpp ├── thesaurus.cpp ├── thinkingofanumber.cpp ├── threedigits.cpp ├── threepowers.py ├── throwns.cpp ├── tictactoe2.cpp ├── tiles.cpp ├── timebomb.cpp ├── timeloop.cpp ├── tiredterry.cpp ├── toilet.cpp ├── tolower.cpp ├── tomography.cpp ├── torn2pieces.cpp ├── touchscreenkeyboard.cpp ├── tower.cpp ├── towering.cpp ├── tractor.cpp ├── traffic.cpp ├── trainaddiction.cpp ├── trainpassengers.cpp ├── trainsorting.cpp ├── transportationplanning.cpp ├── traveltheskies.cpp ├── treasurehunt.cpp ├── treasurespotting.cpp ├── treehouses.cpp ├── treequivalence.cpp ├── trendingtopic.cpp ├── tri.cpp ├── triangle.py ├── triangles3.cpp ├── trik.cpp ├── trilemma.cpp ├── trip.cpp ├── trojke.cpp ├── trollhunt.cpp ├── tsp.cpp ├── turbo.cpp ├── turtlemaster.cpp ├── tutorial.py ├── twoknights.cpp ├── typo.cpp ├── ummcode.cpp ├── unionfind.cpp ├── uniquedice.cpp ├── unlockpattern.cpp ├── unterwavedistance.cpp ├── urbandesign.cpp ├── vacuumba.cpp ├── variablearithmetic.py ├── vauvau.cpp ├── veci.cpp ├── vegetables.cpp ├── virtualfriends.cpp ├── virus.cpp ├── visualgo.cpp ├── vivoparc.cpp ├── volim.cpp ├── vudu.cpp ├── vuk.cpp ├── walkforest.cpp ├── walrusweights.cpp ├── warehouse.cpp ├── watchdog.cpp ├── water.cpp ├── weakvertices.cpp ├── welcomeeasy.cpp ├── welcomehard.py ├── wertyu.cpp ├── whatdoesthefoxsay.py ├── wheresmyinternet.cpp ├── wheretolive.cpp ├── whichbase.cpp ├── whostheboss.cpp ├── wifi.cpp ├── wizardofodds.py ├── wolf.cpp ├── woodcutting.cpp ├── wordcloud.cpp ├── wordsfornumbers.py ├── workstations.cpp ├── wrapping.cpp ├── xenotopia.cpp ├── xorequation.cpp ├── xortris.cpp ├── yinyangstones.cpp ├── yoda.cpp ├── zagrade.cpp ├── zamka.cpp ├── zanzibar.cpp ├── zebrasocelots.cpp ├── zigzag.cpp ├── zigzag2.cpp ├── zipfsong.cpp ├── znanstvenik.cpp ├── zoning.cpp └── zoo.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !*.cpp 3 | !*.py 4 | -------------------------------------------------------------------------------- /3dprinter.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | double n; 8 | cin >> n; 9 | 10 | n = log2(n); 11 | n = ceil(n); 12 | n++; 13 | 14 | cout << n << endl; 15 | } 16 | -------------------------------------------------------------------------------- /4thought.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | def main(): 4 | ans = {} 5 | 6 | ops = [' / ', ' * ', ' - ', ' + '] 7 | 8 | for i in ops: 9 | for j in ops: 10 | for k in ops: 11 | temp = '4' + i + '4' + j + '4' + k + '4' 12 | val = eval(temp.replace('/','//')) 13 | ans[val] = temp 14 | 15 | n = input() 16 | for line in sys.stdin: 17 | line = line[:-1] 18 | if int(line) in ans: 19 | print(str(ans[int(line)]) + ' = ' + line) 20 | else: 21 | print('no solution') 22 | 23 | if __name__ == "__main__": 24 | main() 25 | -------------------------------------------------------------------------------- /aaah.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | string a, b; 8 | cin >> a >> b; 9 | 10 | if(a.length() < b.length()) { 11 | cout << "no" << endl; 12 | } 13 | else { 14 | cout << "go" << endl; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /abc.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() { 9 | vector v; 10 | v.resize(3); 11 | 12 | cin >> v[0] >> v[1] >> v[2]; 13 | sort(v.begin(), v.end()); 14 | 15 | string s; 16 | cin >> s; 17 | 18 | if(s == "ABC") { 19 | cout << v[0] << " " << v[1] << " " << v[2] << endl; 20 | } 21 | if(s == "ACB") { 22 | cout << v[0] << " " << v[2] << " " << v[1] << endl; 23 | } 24 | if(s == "BAC") { 25 | cout << v[1] << " " << v[0] << " " << v[2] << endl; 26 | } 27 | if(s == "BCA") { 28 | cout << v[1] << " " << v[2] << " " << v[0] << endl; 29 | } 30 | if(s == "CAB") { 31 | cout << v[2] << " " << v[0] << " " << v[1] << endl; 32 | } 33 | if(s == "CBA") { 34 | cout << v[2] << " " << v[1] << " " << v[0] << endl; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /aboveaverage.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | typedef long long ll; 7 | typedef long double ld; 8 | 9 | int main() { 10 | ll cases; 11 | cin >> cases; 12 | 13 | while(cases--) { 14 | ll s; 15 | cin >> s; 16 | 17 | vector students(s); 18 | 19 | for(auto& i : students) { 20 | cin >> i; 21 | } 22 | 23 | ll total = 0; 24 | for(auto i : students) { 25 | total += i; 26 | } 27 | 28 | ll better = 0; 29 | ld average = total / ld(s); 30 | for(auto i : students) { 31 | if(i > average) { 32 | better++; 33 | } 34 | } 35 | 36 | cout << fixed; 37 | cout.precision(3); 38 | cout << 100 * better / double(s) << "%" << endl; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /acm.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | struct question { 6 | bool ac = false; 7 | int time = 0; 8 | }; 9 | 10 | int main() { 11 | map m; 12 | int t; 13 | while(cin >> t && t != -1) { 14 | char q; 15 | string s; 16 | cin >> q >> s; 17 | 18 | if(s == "right") { 19 | m[q].ac = true; 20 | m[q].time += t; 21 | } 22 | else { 23 | m[q].time += 20; 24 | } 25 | } 26 | 27 | int rights = 0; 28 | int total = 0; 29 | for(auto i : m) { 30 | if(i.second.ac) { 31 | rights++; 32 | total += i.second.time; 33 | } 34 | } 35 | 36 | cout << rights << " " << total << endl; 37 | } 38 | -------------------------------------------------------------------------------- /airconditioned.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | bool cmp(pair lhs, pair rhs) { 8 | if(lhs.second == rhs.second) { 9 | return lhs.first < rhs.first; 10 | } 11 | return lhs.second < rhs.second; 12 | } 13 | 14 | int main() { 15 | int n; 16 | cin >> n; 17 | vector> minions; 18 | 19 | for(int i = 0; i < n; i++) { 20 | pair p; 21 | cin >> p.first >> p.second; 22 | minions.push_back(p); 23 | } 24 | 25 | sort(minions.begin(), minions.end(), cmp); 26 | 27 | int rooms = 1; 28 | int threshold = minions[0].second; 29 | 30 | for(int i = 1; i < minions.size(); i++) { 31 | if(minions[i].first > threshold) { 32 | threshold = minions[i].second; 33 | rooms++; 34 | } 35 | } 36 | 37 | cout << rooms << endl; 38 | } 39 | -------------------------------------------------------------------------------- /akcija.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | int n; 9 | cin >> n; 10 | 11 | vector v; 12 | 13 | for(int i = 0; i < n; i++) { 14 | int price; 15 | cin >> price; 16 | v.push_back(price); 17 | } 18 | 19 | sort(v.rbegin(), v.rend()); 20 | 21 | int cost = 0; 22 | 23 | for(int j = 0; j < v.size(); j++) { 24 | if(j % 3 != 2) { 25 | cost += v[j]; 26 | } 27 | } 28 | 29 | cout << cost << endl; 30 | } 31 | -------------------------------------------------------------------------------- /almostperfect.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | long long sumdivisors(long long n) { 7 | long long sum = 0; 8 | 9 | for(int i = 1; i <= sqrt(n); i++) { 10 | if(n % i == 0) { 11 | if(i == sqrt(n)) { 12 | sum += i; 13 | } 14 | else { 15 | sum += i; 16 | sum += n/i; 17 | } 18 | } 19 | } 20 | 21 | sum -= n; 22 | return sum; 23 | } 24 | 25 | int main() { 26 | long long n; 27 | while(cin >> n) { 28 | long long d = sumdivisors(n); 29 | if(n == d) { 30 | cout << n << " perfect" << endl; 31 | } 32 | else if(abs(n-d) <= 2) { 33 | cout << n << " almost perfect" << endl; 34 | } 35 | else { 36 | cout << n << " not perfect" << endl; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /alphabetspam.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | string str; 7 | cin >> str; 8 | 9 | double w = 0; 10 | double l = 0; 11 | double u = 0; 12 | double s = 0; 13 | 14 | cout.precision(10); 15 | 16 | for(auto c : str) { 17 | if(c == '_') { 18 | w++; 19 | } 20 | else if(islower(c)) { 21 | l++; 22 | } 23 | else if(isupper(c)) { 24 | u++; 25 | } 26 | else { 27 | s++; 28 | } 29 | } 30 | 31 | int len = str.length(); 32 | cout << w/len << endl; 33 | cout << l/len << endl; 34 | cout << u/len << endl; 35 | cout << s/len << endl; 36 | } 37 | -------------------------------------------------------------------------------- /anagramcounting.py: -------------------------------------------------------------------------------- 1 | import fileinput 2 | 3 | # Build factorial memo table 4 | memo = [1] 5 | for i in range(1,101): 6 | memo.append(memo[i-1] * i) 7 | 8 | # Solve 9 | for line in fileinput.input(): 10 | # Strip line 11 | line = line[:-1] 12 | 13 | # Get total 14 | total = memo[len(line)] 15 | 16 | # Build count array 17 | count = [0] * 128 18 | for c in line: 19 | count[ord(c)] += 1 20 | 21 | # Remove based on count array 22 | for i in count: 23 | if i > 0: 24 | total //= memo[i] 25 | 26 | print(total) 27 | -------------------------------------------------------------------------------- /anotherbrick.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int h, w; 7 | cin >> h >> w; 8 | 9 | int n; 10 | cin >> n; 11 | 12 | int laid = 0; 13 | for(int i = 0; i < n; i++) { 14 | int temp; 15 | cin >> temp; 16 | laid += temp; 17 | 18 | if(laid > w) { 19 | cout << "NO" << endl; 20 | return 0; 21 | } 22 | if(laid == w) { 23 | laid = 0; 24 | h--; 25 | } 26 | if(h == 0) { 27 | break; 28 | } 29 | } 30 | 31 | if(h == 0) { 32 | cout << "YES" << endl; 33 | } 34 | else { 35 | cout << "NO" << endl; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /anothercandies.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | typedef unsigned long long ull; 7 | 8 | int main() { 9 | int n; 10 | cin >> n; 11 | 12 | for(int i = 0; i < n; i++) { 13 | int num; 14 | cin >> num; 15 | 16 | int leftover = 0; 17 | 18 | for(int j = 0; j < num; j++) { 19 | ull temp; 20 | cin >> temp; 21 | 22 | leftover += temp % num; 23 | } 24 | 25 | if(leftover % num == 0) { 26 | cout << "YES" << endl; 27 | } 28 | else { 29 | cout << "NO" << endl; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /anthonyanddiablo.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | double d1, d2; 8 | cin >> d1 >> d2; 9 | 10 | double c = 2 * M_PI * sqrt(d1 / M_PI); 11 | 12 | if(c - d2 <= 0) { 13 | cout << "Diablo is happy!" << endl; 14 | } 15 | else { 16 | cout << "Need more materials!" << endl; 17 | } 18 | } 19 | 20 | -------------------------------------------------------------------------------- /anti11.py: -------------------------------------------------------------------------------- 1 | memo = [0, 2, 3, 5] 2 | 3 | cases = int(input()) 4 | 5 | for i in range(3, 10005): 6 | memo.append(memo[i-1] + memo[i]) 7 | 8 | for i in range(cases): 9 | n = int(input()) 10 | 11 | print(memo[n] % 1000000007) 12 | -------------------------------------------------------------------------------- /antiarithmetic.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | void solve(int n) { 6 | vector v(n); 7 | vector pos(n); 8 | for(int i = 0; i < n; i++) { 9 | cin >> v[i]; 10 | pos[v[i]] = i; 11 | } 12 | 13 | for(int s = 0; s < n; s++) { 14 | for(int d = -n; d <= n; d++) { 15 | if(s+d+d >= 0 && s+d+d < n) { 16 | if(pos[s] < pos[s+d] && pos[s+d] < pos[s+d+d]) { 17 | cout << "no" << endl; 18 | return; 19 | } 20 | } 21 | } 22 | } 23 | 24 | cout << "yes" << endl; 25 | } 26 | 27 | int main() { 28 | ios::sync_with_stdio(false); 29 | cin.tie(0); cout.tie(0); 30 | 31 | int n; 32 | while(cin >> n && n != 0) { 33 | cin.ignore(); 34 | solve(n); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /ants.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | 9 | int cases; 10 | cin >> cases; 11 | 12 | while(cases--) { 13 | int n, m; 14 | cin >> n >> m; 15 | 16 | vector v(m); 17 | for(auto& i : v) { 18 | cin >> i; 19 | } 20 | 21 | int lo = min(v[0], n-v[0]); 22 | int hi = max(v[0], n-v[0]); 23 | 24 | for(auto i : v) { 25 | lo = max(lo, min(i, n-i)); 26 | hi = max(hi, max(i, n-i)); 27 | } 28 | 29 | cout << lo << " " << hi << endl; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /apaxiaaans.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | string name; 9 | cin >> name; 10 | 11 | string::iterator it; 12 | it = unique(name.begin(), name.end()); 13 | name.resize(distance(name.begin(), it)); 14 | 15 | cout << name << endl; 16 | } 17 | -------------------------------------------------------------------------------- /applesack.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | int n; 8 | int k; 9 | cin >> n >> k; 10 | 11 | int total = 1; 12 | while(n > k) { 13 | total++; 14 | n -= ceil(double(n)/k); 15 | } 16 | 17 | total += n; 18 | 19 | cout << total << endl; 20 | } 21 | -------------------------------------------------------------------------------- /aprizenoonecanwin.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | ios::sync_with_stdio(false); 6 | cin.tie(NULL); cout.tie(NULL); 7 | int n, x; 8 | cin >> n >> x; 9 | vector arr(n); 10 | for(int i = 0; i < n; ++i) { 11 | cin >> arr[i]; 12 | } 13 | sort(arr.begin(), arr.end()); 14 | int res = 1; 15 | for(int i = 1; i < n; ++i) { 16 | if(arr[i] + arr[i-1] <= x) res = i+1; 17 | } 18 | cout << res << '\n'; 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /areal.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | long int area; 8 | cin >> area; 9 | 10 | cout.precision(8); 11 | cout << fixed << sqrt(area) * 4 << endl; 12 | } 13 | -------------------------------------------------------------------------------- /autori.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | string s, t; 8 | cin >> s; 9 | t.push_back(s[0]); 10 | for(int i = 0; i < s.size(); i++) { 11 | if(s[i] == '-') { 12 | t.push_back(s[i+1]); 13 | } 14 | } 15 | cout << t << endl; 16 | } 17 | -------------------------------------------------------------------------------- /avion.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | bool printed = false; 7 | for(int i = 1; i <= 5; i++) { 8 | string s; 9 | cin >> s; 10 | 11 | if(s.find("FBI") != -1) { 12 | cout << i << " "; 13 | printed = true; 14 | } 15 | } 16 | 17 | if(printed) { 18 | cout << endl; 19 | } 20 | else { 21 | cout << "HE GOT AWAY!" << endl; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /awkwardparty.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | typedef long long ll; 5 | 6 | int main() { 7 | map> m; 8 | ll n; 9 | cin >> n; 10 | for(ll i = 0; i < n; i++) { 11 | ll t; 12 | cin >> t; 13 | m[t].push_back(i); 14 | } 15 | 16 | ll ans = n; 17 | for(auto i : m) { 18 | for(ll j = 1; j < i.second.size(); j++) { 19 | ans = min(ans, ll(i.second[j] - i.second[j-1])); 20 | } 21 | } 22 | 23 | cout << ans << endl; 24 | } 25 | -------------------------------------------------------------------------------- /babelfish.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() { 9 | string line; 10 | unordered_map words; 11 | while(getline(cin, line) && line != "") { 12 | string english, foreign; 13 | int index = line.find(' '); 14 | english = line.substr(0, index); 15 | foreign = line.substr(index+1, line.size()-1); 16 | 17 | words.insert({foreign, english}); 18 | } 19 | 20 | while(getline(cin, line)) { 21 | if(words.count(line) > 0) { 22 | cout << words.find(line)->second << endl; 23 | } 24 | else { 25 | cout << "eh" << endl; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /babybites.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n; 7 | cin >> n; 8 | 9 | bool found = false; 10 | int diff; 11 | 12 | bool works = true; 13 | for(int i = 0; i < n; i++) { 14 | string s; 15 | cin >> s; 16 | if(s == "mumble") { 17 | continue; 18 | } 19 | int t = stoi(s); 20 | if(t != i+1) works = false; 21 | } 22 | 23 | if(works) { 24 | cout << "makes sense" << endl; 25 | } 26 | else { 27 | cout << "something is fishy" << endl; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /backspace.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | 9 | string s; 10 | cin >> s; 11 | 12 | string ans; 13 | 14 | for(auto i : s) { 15 | if(i == '<') { 16 | ans.pop_back(); 17 | } 18 | else { 19 | ans.push_back(i); 20 | } 21 | } 22 | 23 | cout << ans << endl; 24 | } 25 | -------------------------------------------------------------------------------- /baconeggsandspam.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | def main(): 4 | while True: 5 | n = int(raw_input()) 6 | if n == 0: 7 | break; 8 | 9 | foods = {} 10 | sortable = [] 11 | 12 | 13 | for i in range(0, n): 14 | vars = sys.stdin.readline().split() 15 | for food in vars[1:]: 16 | if food not in foods: 17 | foods[food] = [vars[0]] 18 | sortable.append(food) 19 | else: 20 | foods[food].append(vars[0]) 21 | 22 | sortable.sort() 23 | 24 | for food in sortable: 25 | print food + ' ', 26 | foods[food].sort() 27 | print ' '.join(foods[food]) 28 | 29 | print '' 30 | 31 | if __name__ == "__main__": 32 | main() 33 | -------------------------------------------------------------------------------- /ballbearings.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | int n; 8 | cin >> n; 9 | 10 | while(n--) { 11 | double big, small, space; 12 | cin >> big >> small >> space; 13 | 14 | double l = (big - small) / 2; 15 | 16 | double angle1 = acos((-pow(small+space, 2) + (2*pow(l, 2))) / (2*pow(l, 2))) * 180/M_PI; 17 | 18 | cout << fixed; 19 | cout.precision(0); 20 | cout << floor(360 / angle1) << endl; 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /baloni.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | ios::sync_with_stdio(false); 8 | cin.tie(NULL); 9 | 10 | int n; 11 | cin >> n; 12 | 13 | vector counts; 14 | counts.resize(1000001, 0); 15 | 16 | for(int i = 0; i < n; i++) { 17 | int temp; 18 | cin >> temp; 19 | 20 | if(counts[temp] == 0) { 21 | counts[temp-1]++; 22 | } 23 | else { 24 | counts[temp-1]++; 25 | counts[temp]--; 26 | } 27 | } 28 | 29 | int throws = 0; 30 | for(int i = 0; i < 1000000; i++) { 31 | throws += counts[i]; 32 | } 33 | cout << throws << endl; 34 | } 35 | -------------------------------------------------------------------------------- /bank.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | int n, t; 8 | cin >> n >> t; 9 | 10 | vector best(t+1, 0); 11 | 12 | for(int i = 0; i < n; i++) { 13 | int money, time; 14 | cin >> money >> time; 15 | 16 | for(int j = time; j >= 0; j--) { 17 | if(money > best[j]) { 18 | swap(money, best[j]); 19 | } 20 | } 21 | } 22 | 23 | int total = 0; 24 | for(auto i : best) { 25 | total += i; 26 | } 27 | 28 | cout << total << endl; 29 | } 30 | -------------------------------------------------------------------------------- /basketballoneonone.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | typedef long long ll; 5 | 6 | int main() { 7 | string s; 8 | cin >> s; 9 | 10 | int a = 0; 11 | int b = 0; 12 | 13 | for(int i = 0; i < s.size(); i += 2) { 14 | if(s[i] == 'A') a += s[i+1]-'0'; 15 | else b += s[i+1]-'0'; 16 | 17 | if(a >= 11 && a-b >= 2) { 18 | cout << "A" << endl; 19 | return 0; 20 | } 21 | 22 | if(b >= 11 && b-a >= 2) { 23 | cout << "B" << endl; 24 | return 0; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /batmanacci.py: -------------------------------------------------------------------------------- 1 | data = input() 2 | data = data.split() 3 | n = int(data[0]) 4 | k = int(data[1]) 5 | 6 | fib = [0,1,1] 7 | for i in range(n+1): 8 | fib.append(fib[-1] + fib[-2]) 9 | 10 | while n > 2: 11 | if k > fib[n-2]: 12 | k -= fib[n-2] 13 | n -= 1 14 | else: 15 | n -= 2 16 | 17 | if n == 1: 18 | print("N") 19 | 20 | if n == 2: 21 | print("A") 22 | -------------------------------------------------------------------------------- /batterup.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n; 7 | cin >> n; 8 | 9 | double total = 0; 10 | double count = 0; 11 | 12 | while(n--) { 13 | double temp; 14 | cin >> temp; 15 | if(temp >= 0) { 16 | count++; 17 | total += temp; 18 | } 19 | } 20 | 21 | cout << fixed; 22 | cout.precision(9); 23 | 24 | cout << total/count << endl; 25 | } 26 | -------------------------------------------------------------------------------- /battlesimulation.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | unordered_map m; 9 | m['R'] = 'S'; 10 | m['B'] = 'K'; 11 | m['L'] = 'H'; 12 | 13 | deque q; 14 | char c; 15 | while(cin >> c) { 16 | q.push_back(c); 17 | } 18 | 19 | while(!q.empty()) { 20 | if(q.size() >= 3 && q[0] != q[1] && q[1] != q[2] && q[0] != q[2]) { 21 | q.pop_front(); 22 | q.pop_front(); 23 | q.pop_front(); 24 | cout << "C"; 25 | } 26 | else { 27 | cout << m[q.front()]; 28 | q.pop_front(); 29 | } 30 | } 31 | cout << endl; 32 | } 33 | -------------------------------------------------------------------------------- /beatspread.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n; 7 | cin >> n; 8 | 9 | for(int i = 0; i < n; i++) { 10 | int a, b; 11 | cin >> a >> b; 12 | 13 | if(a < b) { 14 | cout << "impossible" << endl; 15 | continue; 16 | } 17 | 18 | if((a + b) % 2 == 1) { 19 | cout << "impossible" << endl; 20 | continue; 21 | } 22 | 23 | int hi = (a + b) / 2; 24 | int lo = a - hi; 25 | 26 | if(lo > hi) { 27 | swap(lo, hi); 28 | } 29 | 30 | cout << hi << " " << lo << endl; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /beavergnaw.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | double D, V; 8 | while(cin >> D && cin >> V && D != 0 && V != 0) { 9 | double total = M_PI * pow(D/2, 2) * D; 10 | double wood = total - V; 11 | double bigCones = M_PI * pow(D/2,2) * (D/3); 12 | double shape = wood - bigCones; 13 | double cylinder = shape * 1.5; 14 | double r = pow((cylinder / (2 * M_PI)), (1.0/3)); 15 | 16 | cout << fixed; 17 | cout.precision(9); 18 | cout << r * 2 << endl; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /bestcompression.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | long long n, b; 8 | cin >> n >> b; 9 | 10 | if(n <= pow(2,(b+1)) - 1) { 11 | cout << "yes" << endl; 12 | } 13 | else { 14 | cout << "no" << endl; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /bijele.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int king; 7 | int queens; 8 | int rooks; 9 | int bishops; 10 | int knights; 11 | int pawns; 12 | cin >> king >> queens >> rooks >> bishops >> knights >> pawns; 13 | 14 | cout << 1 - king << " " << 1 - queens << " " << 2 - rooks << " " << 2 - bishops << " " << 2 - knights << " " << 8 - pawns << endl; 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /bikegears.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #define int long long 5 | 6 | bool cmp(pair x, pair y) { 7 | if(x.first*y.second == y.first*x.second) { 8 | return x.first < y.first; 9 | } 10 | return x.first*y.second < y.first*x.second; 11 | } 12 | 13 | signed main() { 14 | int f, b; 15 | cin >> f >> b; 16 | vector F(f), B(b); 17 | for(int i = 0; i < f; ++i) { 18 | cin >> F[i]; 19 | } 20 | for(int i = 0; i < b; ++i) { 21 | cin >> B[i]; 22 | } 23 | vector> arr; 24 | for(int i = 0; i < f; ++i) { 25 | for(int j = 0; j < b; ++j) { 26 | arr.push_back({F[i], B[j]}); 27 | } 28 | } 29 | sort(arr.begin(), arr.end(), cmp); 30 | for(auto &p : arr) { 31 | cout << '(' << p.first << ',' << p.second << ")\n"; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /billiard.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | double a, b, s, m, n; 8 | while(cin >> a >> b >> s >> m >> n) { 9 | if(a == 0 && b == 0 && s == 0 && m == 0 && n == 0) { 10 | break; 11 | } 12 | 13 | double xDist = a * m; 14 | double yDist = b * n; 15 | 16 | double angle = atan(yDist / xDist) * 180 / M_PI; 17 | double dist = sqrt(pow(xDist, 2) + pow(yDist, 2)); 18 | 19 | cout << fixed; 20 | cout.precision(2); 21 | cout << angle << " " << dist / s << endl; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /bishops.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | int size; 8 | while(cin >> size) { 9 | if(size < 1) { 10 | cout << 0 << endl; 11 | } 12 | else if(size == 1) { 13 | cout << 1 << endl; 14 | } 15 | else { 16 | cout << 2 * size - 2 << endl; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /bits.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | typedef unsigned long long ull; 7 | 8 | ull getBits(ull n) { 9 | ull bits = 0; 10 | while(n > 0) { 11 | if(n%2 == 1) { 12 | bits++; 13 | } 14 | n >>= 1; 15 | } 16 | return bits; 17 | } 18 | 19 | int main() { 20 | ull n; 21 | cin >> n; 22 | 23 | for(ull i = 0; i < n; i++) { 24 | ull temp; 25 | cin >> temp; 26 | ull maxBits = 0; 27 | while(temp > 0) { 28 | maxBits = max(maxBits, getBits(temp)); 29 | temp /= 10; 30 | } 31 | cout << maxBits << endl; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /blackfriday.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | int n; 8 | cin >> n; 9 | 10 | vector people; 11 | vector rolls; 12 | 13 | rolls.resize(7, 0); 14 | 15 | for(int i = 0; i < n; i++) { 16 | int temp; 17 | cin >> temp; 18 | people.push_back(temp); 19 | rolls[temp]++; 20 | } 21 | 22 | bool found = false; 23 | for(int i = 6; i >= 1; i--) { 24 | if(rolls[i] == 1) { 25 | for(int j = 0; j < people.size(); j++) { 26 | if(people[j] == i) { 27 | cout << j+1 << endl; 28 | return 0; 29 | } 30 | } 31 | } 32 | } 33 | 34 | if(!found) { 35 | cout << "none" << endl; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /bookingaroom.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | int r, n; 8 | cin >> r >> n; 9 | 10 | vector v; 11 | v.resize(n+1, false); 12 | 13 | for(int i = 0; i < n; i++) { 14 | int temp; 15 | cin >> temp; 16 | v[temp] = true; 17 | } 18 | 19 | if(n >= r) { 20 | cout << "too late" << endl; 21 | } 22 | else { 23 | for(int i = 1; i < r+1; i++) { 24 | if(!v[i]) { 25 | cout << i << endl; 26 | break; 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /bossbattle.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n; 7 | cin >> n; 8 | 9 | n -= 2; 10 | n = max(n, 1); 11 | 12 | cout << n << endl; 13 | } 14 | -------------------------------------------------------------------------------- /bottledup.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int total, v1, v2; 7 | cin >> total >> v1 >> v2; 8 | 9 | bool swapped = false; 10 | if(v2 < v1) { 11 | swap(v1, v2); 12 | swapped = true; 13 | } 14 | 15 | bool printed = false; 16 | 17 | int v1_count = 0; 18 | while(total >= 0) { 19 | if(total % v2 == 0) { 20 | if(!swapped) { 21 | cout << v1_count << " " << total/v2 << endl; 22 | } 23 | else { 24 | cout << total/v2 << " " << v1_count << endl; 25 | } 26 | printed = true; 27 | break; 28 | } 29 | total -= v1; 30 | v1_count++; 31 | } 32 | 33 | if(!printed) { 34 | cout << "Impossible" << endl; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /bubbletea.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | typedef long long ll; 8 | ll inf = (ll) 2 << 60; 9 | 10 | int main() { 11 | ll n; 12 | cin >> n; 13 | 14 | vector teas(n); 15 | for(auto& i : teas) { 16 | cin >> i; 17 | } 18 | 19 | ll m; 20 | cin >> m; 21 | 22 | vector toppings(m); 23 | for(auto& i : toppings) { 24 | cin >> i; 25 | } 26 | 27 | ll best = inf; 28 | for(ll i = 0; i < n; i++) { 29 | ll p; 30 | cin >> p; 31 | 32 | for(ll j = 0; j < p; j++) { 33 | ll temp; 34 | cin >> temp; 35 | 36 | best = min(best, teas[i] + toppings[temp-1]); 37 | } 38 | } 39 | 40 | ll total; 41 | cin >> total; 42 | 43 | ll ans = (total / best) - 1; 44 | ans = max(ans, (ll)0); 45 | 46 | cout << ans << endl; 47 | } 48 | -------------------------------------------------------------------------------- /bus.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | int n; 8 | cin >> n; 9 | 10 | for(int i = 0; i < n; i++) { 11 | int temp; 12 | cin >> temp; 13 | 14 | double ans = 0; 15 | for(int i = 0; i < temp; i++) { 16 | ans += .5; 17 | ans *= 2; 18 | } 19 | 20 | cout << (long long)ans << endl; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /busnumbers.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | def group(vals): 4 | run = [] 5 | result = [run] 6 | expect = None 7 | 8 | for v in vals: 9 | if (v == expect) or (expect is None): 10 | run.append(v) 11 | else: 12 | run = [v] 13 | result.append(run) 14 | expect = v + 1 15 | return result 16 | 17 | def main(): 18 | n = int(raw_input()) 19 | 20 | for line in sys.stdin: 21 | nums = map(int, line.split()) 22 | 23 | nums.sort() 24 | nums = group(nums) 25 | 26 | for i in nums: 27 | if(len(i) > 2): 28 | print str(i[0]) + '-' + str(i[-1]), 29 | else: 30 | for j in i: 31 | print str(j), 32 | 33 | 34 | if __name__ == '__main__': 35 | main() 36 | -------------------------------------------------------------------------------- /busnumbers2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n; 7 | cin >> n; 8 | 9 | vector cubes; 10 | for(int i = 1; i*i*i <= n; i++) { 11 | cubes.push_back(i*i*i); 12 | } 13 | 14 | map sums; 15 | for(int i = 0; i < cubes.size(); i++) { 16 | for(int j = i+1; j < cubes.size(); j++) { 17 | sums[cubes[i]+cubes[j]]++; 18 | } 19 | } 20 | 21 | int best = -1; 22 | for(auto i : sums) { 23 | if(i.second > 1 && i.first <= n) { 24 | best = i.first; 25 | } 26 | } 27 | 28 | if(best == -1) { 29 | cout << "none" << endl; 30 | } 31 | else { 32 | cout << best << endl; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /calculator.py: -------------------------------------------------------------------------------- 1 | import fileinput 2 | 3 | for line in fileinput.input(): 4 | line = line[:-1] 5 | line = "x = " + line 6 | exec(line) 7 | print("{0:.2f}".format(x)) 8 | -------------------------------------------------------------------------------- /candlebox.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | vector t; 8 | vector r; 9 | t.resize(70, 0); 10 | r.resize(70, 0); 11 | 12 | int d, c1, c2; 13 | cin >> d >> c1 >> c2; 14 | 15 | for(int i = 0; i < t.size(); i++) { 16 | if(i >= 3) { 17 | t[i] = i + t[i-1]; 18 | } 19 | if(i >= 4) { 20 | r[i] = i + r[i-1]; 21 | } 22 | } 23 | 24 | for(int i = d; i < t.size(); i++) { 25 | if(t[i-d] + r[i] == c1 + c2) { 26 | cout << c1 - r[i] << endl; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /candydivision.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | typedef long long ll; 9 | 10 | int main() { 11 | ll n; 12 | cin >> n; 13 | 14 | vector p; 15 | for(ll i = 1; i < sqrt(n)+2; i++) { 16 | if(n % i == 0) { 17 | p.push_back(i); 18 | p.push_back(n/i); 19 | } 20 | } 21 | 22 | sort(p.begin(), p.end()); 23 | 24 | p.resize(distance(p.begin(), unique(p.begin(), p.end()))); 25 | 26 | for(auto i : p) { 27 | cout << i-1 << " "; 28 | } 29 | cout << endl; 30 | } 31 | -------------------------------------------------------------------------------- /canvas.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | typedef long long ll; 5 | 6 | int main() { 7 | int cases; 8 | cin >> cases; 9 | while(cases--) { 10 | int n; 11 | cin >> n; 12 | 13 | priority_queue q; 14 | for(int i = 0; i < n; i++) { 15 | ll c; 16 | cin >> c; 17 | q.push(-c); 18 | } 19 | 20 | ll total = 0; 21 | while(q.size() >= 2) { 22 | ll t = 0; 23 | t += q.top(); 24 | q.pop(); 25 | t += q.top(); 26 | q.pop(); 27 | total += t; 28 | q.push(t); 29 | } 30 | 31 | cout << -total << endl; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /cardboardcontainer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define int long long 3 | using namespace std; 4 | 5 | int32_t main() { 6 | int n; 7 | cin >> n; 8 | vector factors; 9 | for(int i = 1; i*i <= n; ++i) { 10 | if(n%i == 0) { 11 | factors.push_back(i); 12 | if(i*i != n) factors.push_back(n/i); 13 | } 14 | } 15 | sort(factors.begin(), factors.end()); 16 | int res = 1e18; 17 | for(int f : factors) { 18 | const int l = f; 19 | int remaining = n/f; 20 | for(int f2 : factors) { 21 | if(remaining%f2 != 0) continue; 22 | const int w = remaining/f2; 23 | const int h = f2; 24 | assert(l*w*h == n); 25 | res = min(res, 2LL*(l*w+w*h+h*l)); 26 | } 27 | } 28 | cout << res << '\n'; 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /cardtrick2.py: -------------------------------------------------------------------------------- 1 | def main(): 2 | n = int(raw_input()) 3 | 4 | while n > 0: 5 | n -= 1 6 | cards = int(raw_input()) 7 | deck = [] 8 | 9 | for i in range(cards, 0, -1): 10 | deck.insert(0, i) 11 | 12 | for j in range(0, i): 13 | deck.insert(0, deck.pop()) 14 | 15 | for i in deck: 16 | print str(i) + " ", 17 | 18 | print "" 19 | 20 | if __name__ == "__main__": 21 | main() 22 | -------------------------------------------------------------------------------- /carrots.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int i, j; 7 | cin >> i >> j; 8 | cout << j << endl; 9 | } 10 | -------------------------------------------------------------------------------- /catalan.py: -------------------------------------------------------------------------------- 1 | fact = [1] 2 | 3 | for i in range(1,10001): 4 | fact.append(fact[i-1] * i) 5 | 6 | cases = int(input()) 7 | for i in range(cases): 8 | n = int(input()) 9 | print(fact[2*n] // (fact[n+1]*fact[n])) 10 | -------------------------------------------------------------------------------- /catalansquare.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | 3 | catalan = {} 4 | catalan[0] = 1 5 | 6 | for i in range(0,n+1): 7 | catalan[i+1] = catalan[i] * (4*i + 2) // (i+2) 8 | 9 | print(catalan[n+1]) 10 | -------------------------------------------------------------------------------- /cd.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() { 9 | int n, m; 10 | 11 | while(cin >> n >> m && n != 0 && m != 0) { 12 | vector jack, jill, ans; 13 | 14 | int temp; 15 | for(int i = 0; i < n; i++) { 16 | cin >> temp; 17 | jack.push_back(temp); 18 | } 19 | 20 | for(int i = 0; i < m; i++) { 21 | cin >> temp; 22 | jill.push_back(temp); 23 | } 24 | 25 | set_intersection(jack.begin(), jack.end(), jill.begin(), jill.end(), back_inserter(ans)); 26 | 27 | cout << ans.size() << endl; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /ceremony.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | int n; 9 | cin >> n; 10 | 11 | vector v(n); 12 | for(auto& i : v) { 13 | cin >> i; 14 | } 15 | 16 | sort(v.begin(), v.end()); 17 | 18 | int charges = 0; 19 | 20 | int location = 0; 21 | 22 | int i; 23 | for(i = 0; i < v.size(); i++) { 24 | if(v[i] - charges > v.size() - location) { 25 | break; 26 | } 27 | if(v[i] > charges) { 28 | charges++; 29 | } 30 | } 31 | 32 | charges += v.size() - i; 33 | 34 | cout << charges << endl; 35 | } 36 | -------------------------------------------------------------------------------- /cetvrta.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int getOutlier(int a, int b, int c) { 6 | if(a == b) { 7 | return c; 8 | } 9 | if(b == c) { 10 | return a; 11 | } 12 | return b; 13 | } 14 | 15 | int main() { 16 | int x1,x2,x3,y1,y2,y3; 17 | cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3; 18 | cout << getOutlier(x1,x2,x3) << " " << getOutlier(y1,y2,y3) << endl; 19 | } 20 | -------------------------------------------------------------------------------- /chanukah.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | void solve() { 6 | int a, b; 7 | cin >> a >> b; 8 | cout << a << " " << (b * (b + 1) / 2) + b << endl; 9 | } 10 | 11 | int main() { 12 | int cases; 13 | cin >> cases; 14 | while(cases--) { 15 | solve(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /character.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int character(int n) { 7 | if(n == 0 || n == 1) { 8 | return 0; 9 | } 10 | 11 | return pow(2, n-1) - 1 + character(n-1); 12 | } 13 | 14 | int main() { 15 | int n; 16 | cin >> n; 17 | 18 | cout << character(n) << endl; 19 | } 20 | -------------------------------------------------------------------------------- /chewbacca.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | 7 | int main() { 8 | ll n, k, q; 9 | cin >> n >> k >> q; 10 | 11 | for(ll i = 0; i < q; i++) { 12 | ll a, b; 13 | cin >> a >> b; 14 | 15 | ll moves = 0; 16 | a--; 17 | b--; 18 | while(a != b) { 19 | moves++; 20 | if(b > a) { 21 | swap(a, b); 22 | } 23 | 24 | a--; 25 | a /= k; 26 | } 27 | 28 | cout << moves << endl; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /cold.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int j, k=0; 7 | cin >> j; 8 | for(int i = 0; i < j; i++) { 9 | int l; 10 | cin >> l; 11 | if(l < 0) { 12 | k++; 13 | } 14 | } 15 | cout << k << endl; 16 | } 17 | -------------------------------------------------------------------------------- /communication.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | int n; 9 | cin >> n; 10 | 11 | vector ans; 12 | ans.resize(1024, -1); 13 | 14 | for(int i = 0; i < 511; i++) { 15 | int temp = i ^ (i << 1) & 255; 16 | ans[temp] = i; 17 | } 18 | 19 | for(int i = 0; i < n; i++) { 20 | int temp; 21 | cin >> temp; 22 | 23 | cout << ans[temp] << " "; 24 | } 25 | 26 | cout << endl; 27 | } 28 | -------------------------------------------------------------------------------- /compass.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int a, b; 7 | cin >> a >> b; 8 | b -= a; 9 | if(b <= -180) { 10 | b += 360; 11 | } 12 | if(b > 180) { 13 | b -= 360; 14 | } 15 | cout << b << endl; 16 | } 17 | -------------------------------------------------------------------------------- /compoundwords.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() { 9 | vector v; 10 | vector print; 11 | string s; 12 | while(cin >> s) { 13 | v.push_back(s); 14 | } 15 | for(int i = 0; i < v.size(); i++) { 16 | for(int j = 0; j < v.size(); j++) { 17 | if(i != j) { 18 | string temp = v[i] + v[j]; 19 | print.push_back(temp); 20 | } 21 | } 22 | } 23 | 24 | sort(print.begin(), print.end()); 25 | 26 | string last = ""; 27 | for(int i = 0; i < print.size(); i++) { 28 | if(last != print[i]) { 29 | cout << print[i] << endl; 30 | last = print[i]; 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /consecutivesums.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | typedef long long ll; 5 | 6 | void print(int n, int start, int nums) { 7 | cout << n << " = "; 8 | for(int i = 0; i < nums; i++) { 9 | cout << start+i; 10 | if(i != nums-1) cout << " + "; 11 | } 12 | cout << endl; 13 | } 14 | 15 | void solve() { 16 | ll n; 17 | cin >> n; 18 | 19 | ll nums = 2; 20 | while(true) { 21 | ll sub = nums * (nums-1) / 2; 22 | 23 | ll temp = n - sub; 24 | if(temp <= 0) break; 25 | 26 | 27 | if(temp % nums == 0) { 28 | print(n, temp / nums, nums); 29 | return; 30 | } 31 | 32 | nums++; 33 | } 34 | 35 | cout << "IMPOSSIBLE" << endl; 36 | } 37 | 38 | int main() { 39 | int cases; 40 | cin >> cases; 41 | while(cases--) { 42 | solve(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /conundrum.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | string s; 8 | cin >> s; 9 | int different = 0; 10 | for(int i = 0; i < s.length(); i += 3) { 11 | if(s[i] != 'P') { 12 | different++; 13 | } 14 | if(s[i+1] != 'E') { 15 | different++; 16 | } 17 | if(s[i+2] != 'R') { 18 | different++; 19 | } 20 | } 21 | cout << different << endl; 22 | } 23 | -------------------------------------------------------------------------------- /convexpolygonarea.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | int cases; 8 | cin >> cases; 9 | 10 | for(int i = 0; i < cases; i++) { 11 | int points; 12 | cin >> points; 13 | 14 | vector> v; 15 | for(int j = 0; j < points; j++) { 16 | pair p; 17 | cin >> p.first >> p.second; 18 | v.push_back(p); 19 | } 20 | 21 | double result = 0; 22 | 23 | for(int i = 0, j = 1, n = v.size(); i < n; i++, j = (i+1) % n) { 24 | result += (v[i].first * v[j].second) - (v[i].second * v[j].first); 25 | } 26 | 27 | cout << result / 2 << endl; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /crackingrsa.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | 7 | ll solve(ll e, ll t) { 8 | int i = 1; 9 | while(true) { 10 | int x = (e * i - 1) % t; 11 | if(x == 0) { 12 | return i; 13 | } 14 | i++; 15 | } 16 | } 17 | 18 | int main() { 19 | ll cases; 20 | cin >> cases; 21 | 22 | while(cases--) { 23 | ll p, q, e; 24 | cin >> p >> e; 25 | 26 | for(int i = 2; i <= p; i++) { 27 | if(p % i == 0) { 28 | p /= i; 29 | q = i; 30 | break; 31 | } 32 | } 33 | 34 | ll t = (p-1) * (q-1); 35 | 36 | cout << solve(e, t) << endl; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /crne.py: -------------------------------------------------------------------------------- 1 | def main(): 2 | n = int(raw_input()) 3 | temp = (n/2)+1 4 | ans = temp**2 5 | if n % 2 == 1: 6 | ans += temp 7 | print ans 8 | 9 | if __name__ == '__main__': 10 | main() 11 | -------------------------------------------------------------------------------- /cuchitunnels.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | typedef long long ll; 5 | 6 | int main() { 7 | ll n; 8 | cin >> n; 9 | 10 | vector child(n); 11 | ll t = 0; 12 | for(int i = 0; i < n; i++) { 13 | cin >> child[i]; 14 | if(i != 0) child[i]--; 15 | t += child[i]; 16 | } 17 | 18 | ll leaves = 0; 19 | bool works = true; 20 | for(int i = n-1; i >= 0; i--) { 21 | if(child[i] > leaves) works = false; 22 | leaves -= child[i]; 23 | leaves++; 24 | } 25 | 26 | if(works && t == n-1) { 27 | cout << "YES" << endl; 28 | } 29 | else { 30 | cout << "NO" << endl; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /cups.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | int n; 9 | cin >> n; 10 | 11 | vector v; 12 | v.resize(2500, ""); 13 | 14 | for(int i = 0; i < n; i++) { 15 | int size; 16 | string color; 17 | 18 | cin.ignore(); 19 | if(isalpha(cin.peek())) { 20 | cin >> color; 21 | cin >> size; 22 | size *= 2; 23 | } 24 | else { 25 | cin >> size; 26 | cin >> color; 27 | } 28 | 29 | v[size] = color; 30 | } 31 | 32 | for(int i = 0; i < v.size(); i++) { 33 | if(v[i] != "") { 34 | cout << v[i] << endl; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /cursethedarkness.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | typedef long double ld; 7 | 8 | ld dist(ld x1, ld y1, ld x2, ld y2) { 9 | return sqrt(pow(x1-x2, 2) + pow(y1-y2, 2)); 10 | } 11 | 12 | int main() { 13 | int cases; 14 | cin >> cases; 15 | 16 | while(cases--) { 17 | ld x, y; 18 | cin >> x >> y; 19 | 20 | int n; 21 | cin >> n; 22 | 23 | bool works = false; 24 | for(int i = 0; i < n; i++) { 25 | ld x1, y1; 26 | cin >> x1 >> y1; 27 | if(dist(x, y, x1, y1) <= 8.000000001) { 28 | works = true; 29 | } 30 | } 31 | 32 | if(works) { 33 | cout << "light a candle" << endl; 34 | } 35 | else { 36 | cout << "curse the darkness" << endl; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /dartscores.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | int n; 8 | cin >> n; 9 | 10 | for(int i = 0; i < n; i++) { 11 | int score = 0; 12 | int throws; 13 | cin >> throws; 14 | 15 | for(int j = 0; j < throws; j++) { 16 | double x, y; 17 | cin >> x >> y; 18 | double dist = sqrt(pow(x, 2) + pow(y, 2)); 19 | 20 | if(dist == 0) { 21 | score--; 22 | } 23 | 24 | while(dist <= 200) { 25 | score++; 26 | dist += 20; 27 | } 28 | } 29 | 30 | cout << score << endl; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /dasblinkenlights.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int p, q, s; 7 | cin >> p >> q >> s; 8 | 9 | if(p*q/__gcd(p,q) <= s) { 10 | cout << "yes" << endl; 11 | } 12 | else { 13 | cout << "no" << endl; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /dasort.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | typedef long long ll; 8 | 9 | int main() { 10 | ios::sync_with_stdio(false); 11 | cin.tie(NULL); 12 | 13 | int cases; 14 | cin >> cases; 15 | while(cases--) { 16 | ll garbo, size; 17 | cin >> garbo >> size; 18 | 19 | cout << garbo << " "; 20 | 21 | vector v; 22 | for(int i = 0; i < size; i++) { 23 | ll temp; 24 | cin >> temp; 25 | v.push_back(temp); 26 | } 27 | 28 | vector s = v; 29 | sort(s.begin(), s.end()); 30 | 31 | int index = 0; 32 | for(int i = 0; i < size; i++) { 33 | if(v[i] == s[index]) { 34 | index++; 35 | } 36 | } 37 | 38 | cout << size - index << endl; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /datum.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() { 9 | vector v = {"Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"}; 10 | 11 | tm time = {}; 12 | 13 | cin >> time.tm_mday; 14 | cin >> time.tm_mon; 15 | time.tm_mon--; 16 | time.tm_year = 2009; 17 | 18 | mktime(&time); 19 | 20 | cout << v[time.tm_wday] << endl; 21 | } 22 | -------------------------------------------------------------------------------- /deathknight.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | int n; 8 | cin >> n; 9 | 10 | int wins = 0; 11 | for(int i = 0; i < n; i++) { 12 | string s; 13 | cin >> s; 14 | 15 | wins++; 16 | for(int i = 0; i < s.size()-1; i++) { 17 | if(s[i] == 'C' && s[i+1] == 'D') { 18 | wins--; 19 | break; 20 | } 21 | } 22 | } 23 | 24 | cout << wins << endl; 25 | } 26 | -------------------------------------------------------------------------------- /deathstar.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | int size; 8 | cin >> size; 9 | 10 | vector plans; 11 | plans.resize(size, 0); 12 | 13 | for(int i = 0; i < size; i++) { 14 | for(int j = 0; j < size; j++) { 15 | int num; 16 | cin >> num; 17 | plans[i] |= num; 18 | } 19 | } 20 | 21 | for(int i = 0; i < size; i++) { 22 | cout << plans[i] << " "; 23 | } 24 | cout << endl; 25 | } 26 | -------------------------------------------------------------------------------- /detaileddifferences.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | int n; 8 | cin >> n; 9 | for(int i = 0; i < n; i++) { 10 | string a, b; 11 | cin >> a >> b; 12 | 13 | cout << a << endl; 14 | cout << b << endl; 15 | 16 | int size = a.size(); 17 | for(int j = 0; j < size; j++) { 18 | if(a[j] == b[j]) { 19 | cout << '.'; 20 | } 21 | else { 22 | cout << '*'; 23 | } 24 | } 25 | 26 | cout << endl << endl; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /diagonalcut.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | typedef long long ll; 5 | 6 | int main() { 7 | ll a, b; 8 | cin >> a >> b; 9 | ll g = __gcd(a,b); 10 | a /= g; 11 | b /= g; 12 | if(a % 2 == 0 || b % 2 == 0) g = 0; 13 | cout << g << endl; 14 | } 15 | 16 | -------------------------------------------------------------------------------- /dicecup.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int a, b; 7 | cin >> a >> b; 8 | 9 | if(b < a) { 10 | swap(a, b); 11 | } 12 | 13 | for(int i = a + 1; i < b + 2; i++) { 14 | cout << i << endl; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /dicegame.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int e1, e2, e3, e4; 7 | int g1, g2, g3, g4; 8 | 9 | cin >> e1 >> e2 >> e3 >> e4; 10 | cin >> g1 >> g2 >> g3 >> g4; 11 | 12 | int e = e1 + e2 + e3 + e4; 13 | int g = g1 + g2 + g3 + g4; 14 | 15 | if(e > g) { 16 | cout << "Gunnar" << endl; 17 | } 18 | else if(e < g) { 19 | cout << "Emma" << endl; 20 | } 21 | else { 22 | cout << "Tie" << endl; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /different.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | long long a, b; 7 | while(cin >> a >> b) { 8 | cout << abs(a - b) << endl; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /differentdistances.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | long double x1, x2, y1, y2, p; 8 | cout.precision(8); 9 | while(cin>>x1 && cin>>y1 && cin>>x2 && cin>>y2 && cin>>p) { 10 | long double x = pow(abs(x1-x2), p); 11 | long double y = pow(abs(y1-y2), p); 12 | cout << fixed << pow(x+y,(1/p)) << endl; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /dirtydriving.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | typedef long long ll; 5 | 6 | int main() { 7 | ll n, p; 8 | cin >> n >> p; 9 | 10 | vector v(n); 11 | for(auto& i : v) { 12 | cin >> i; 13 | } 14 | 15 | sort(v.begin(), v.end()); 16 | 17 | ll dist = 0; 18 | for(ll i = 0; i < v.size(); i++) { 19 | ll dist_to_keep = p * (i+1); 20 | ll dist_already = v[i]; 21 | dist = max(dist, dist_to_keep - dist_already); 22 | } 23 | 24 | cout << dist + v[0] << endl; 25 | } 26 | -------------------------------------------------------------------------------- /disastrousdoubling.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | bac = 1; 3 | rem = input().split() 4 | 5 | for i in rem: 6 | bac *= 2; 7 | bac -= int(i); 8 | 9 | printed = False 10 | if bac < 0: 11 | print("error") 12 | printed = True 13 | break; 14 | 15 | if not printed: 16 | print(bac % 1000000007) 17 | -------------------------------------------------------------------------------- /divisible.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | typedef long long ll; 5 | 6 | void solve() { 7 | ll d, n; 8 | cin >> d >> n; 9 | 10 | vector v = {0}; 11 | vector p = {0}; 12 | for(int i = 1; i <= n; i++) { 13 | int t; cin >> t; 14 | v.push_back(t); 15 | p.push_back((p.back() + t)%d); 16 | } 17 | 18 | ll ans = 0; 19 | map buckets; 20 | buckets[0] = 1; 21 | for(int i = 1; i <= n; i++) { 22 | ans += buckets[p[i]%d]; 23 | buckets[p[i]%d]++; 24 | } 25 | 26 | cout << ans << endl; 27 | } 28 | 29 | int main() { 30 | int cases; 31 | cin >> cases; 32 | while(cases--) { 33 | solve(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /dna.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios::sync_with_stdio(false); 7 | cin.tie(NULL); cout.tie(NULL); 8 | 9 | int n; 10 | cin >> n; 11 | 12 | string s; 13 | cin >> s; 14 | 15 | int moves = 0; 16 | bool wanta = true; 17 | for(int i = n-1; i >= 0; i--) { 18 | if(wanta && s[i] == 'A') continue; 19 | if(!wanta && s[i] == 'B') continue; 20 | 21 | if(i == 0) { 22 | moves++; 23 | continue; 24 | } 25 | 26 | moves++; 27 | 28 | if(wanta) { 29 | if(s[i-1] != 'A') { 30 | wanta = false; 31 | } 32 | } 33 | else { 34 | if(s[i-1] != 'B') { 35 | wanta = true; 36 | } 37 | } 38 | } 39 | 40 | cout << moves << endl; 41 | } 42 | -------------------------------------------------------------------------------- /doodling.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | void solve() { 6 | int n, m; 7 | cin >> n >> m; 8 | 9 | n--; 10 | m--; 11 | 12 | int lcm = n * m / __gcd(n, m); 13 | int ans = lcm + 1 - ((lcm / n - 1) * (lcm / m - 1) / 2); 14 | cout << ans << endl; 15 | } 16 | 17 | int main() { 18 | int cases; 19 | cin >> cases; 20 | while(cases--) { 21 | solve(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /doubleplusgood.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | typedef long long ll; 5 | 6 | int main() { 7 | vector v; 8 | ll i; 9 | while(cin >> i) { 10 | v.push_back(i); 11 | } 12 | 13 | set nums; 14 | 15 | for(ll i = 0; i < (1 << (v.size()-1)); i++) { 16 | ll total = 0; 17 | ll curr = 0; 18 | 19 | curr = v[0]; 20 | for(ll j = 1; j < v.size(); j++) { 21 | if(i & (1<<(j-1))) { 22 | total += curr; 23 | curr = v[j]; 24 | } 25 | else { 26 | string t = to_string(curr) + to_string(v[j]); 27 | ll i = stoll(t); 28 | curr = i; 29 | } 30 | } 31 | total += curr; 32 | nums.insert(total); 33 | } 34 | 35 | cout << nums.size() << endl; 36 | } 37 | -------------------------------------------------------------------------------- /downtime.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int ceildivide(int top, int bot) { 6 | return (bot + top - 1) / bot; 7 | } 8 | 9 | int main() { 10 | ios::sync_with_stdio(false); 11 | cin.tie(NULL); 12 | 13 | int n, m; 14 | cin >> n >> m; 15 | 16 | unordered_map seen; 17 | for(int i = 0; i < n; i++) { 18 | int temp; 19 | cin >> temp; 20 | seen[temp]++; 21 | } 22 | 23 | 24 | int processing = 0; 25 | for(int i = 0; i <= 999; i++) { 26 | processing += seen[i]; 27 | } 28 | 29 | int best = processing; 30 | for(int i = 1000; i <= 100000; i++) { 31 | processing += seen[i]; 32 | processing -= seen[i-1000]; 33 | best = max(best, processing); 34 | } 35 | 36 | cout << ceildivide(best, m) << endl; 37 | } 38 | -------------------------------------------------------------------------------- /dvds.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | ios::sync_with_stdio(false); 8 | cin.tie(NULL); 9 | 10 | int n; 11 | cin >> n; 12 | 13 | for(int i = 0; i < n; i++) { 14 | int size; 15 | cin >> size; 16 | vector v; 17 | 18 | for(int j = 0; j < size; j++) { 19 | int temp; 20 | cin >> temp; 21 | v.push_back(temp); 22 | } 23 | 24 | int minfound = 0; 25 | for(auto i : v) { 26 | if(i == minfound+1) { 27 | minfound++; 28 | } 29 | } 30 | 31 | cout << size - minfound << endl; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /easiest.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int getDigits(int num); 6 | 7 | int main() { 8 | int i;// The number that the user entered 9 | cin >> i; 10 | while(i != 0) { 11 | int j = 11; 12 | while(getDigits(i) != getDigits(i * j)) { 13 | j++; 14 | } 15 | cout << j << endl; 16 | cin >> i; 17 | } 18 | } 19 | 20 | int getDigits(int num) { 21 | int digits = 0; 22 | while(num > 0) { 23 | digits += num % 10; 24 | num /= 10; 25 | } 26 | return digits; 27 | } 28 | -------------------------------------------------------------------------------- /eatingout.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int m, a, b, c; 7 | cin >> m >> a >> b >> c; 8 | 9 | a += b; 10 | a += c; 11 | 12 | if(2*m - a >= 0) { 13 | cout << "possible" << endl; 14 | } 15 | else { 16 | cout << "impossible" << endl; 17 | } 18 | } 19 | 20 | -------------------------------------------------------------------------------- /egypt.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | vector v(3); 7 | while(true) { 8 | for(auto& i : v) { 9 | cin >> i; 10 | } 11 | if(v[0] == 0 && v[1] == 0 && v[2] == 0) { 12 | return 0; 13 | } 14 | 15 | 16 | sort(v.begin(), v.end()); 17 | 18 | if(v[0] * v[0] + v[1] * v[1] == v[2] * v[2]) { 19 | cout << "right" << endl; 20 | } 21 | else { 22 | cout << "wrong" << endl; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /eligibility.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | int num; 8 | cin >> num; 9 | 10 | for(int i = 0; i < num; i++) { 11 | string name; 12 | string school; 13 | string age; 14 | int courses; 15 | 16 | cin >> name >> school >> age; 17 | cin >> courses; 18 | 19 | bool elgible = true; 20 | 21 | cout << name << " "; 22 | 23 | if(school >= "2010/00/00") { 24 | cout << "eligible" << endl; 25 | continue; 26 | } 27 | 28 | if(age >= "1991/00/00") { 29 | cout << "eligible" << endl; 30 | continue; 31 | } 32 | 33 | if(courses > 40) { 34 | cout << "ineligible" << endl; 35 | continue; 36 | } 37 | 38 | cout << "coach petitions" << endl; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /encodedmessage.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() { 9 | int n; 10 | cin >> n; 11 | 12 | for(int i = 0; i < n; i++) { 13 | string s; 14 | cin >> s; 15 | 16 | vector> v; 17 | 18 | int size = sqrt(s.length()); 19 | v.resize(size); 20 | for(int j = 0; j < size; j++) { 21 | v[j].resize(size); 22 | for(int k = 0; k < size; k++) { 23 | v[j][k] = s[j*size+k]; 24 | } 25 | } 26 | 27 | for(int j = size-1; j >= 0; j--) { 28 | for(int k = 0; k < size; k++) { 29 | cout << v[k][j]; 30 | } 31 | } 32 | cout << endl; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /engineeringenglish.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | unordered_set dict; 9 | 10 | string s; 11 | while(cin >> s) { 12 | string temp = s; 13 | for(auto &c : temp) { 14 | c = tolower(c); 15 | } 16 | 17 | if(dict.count(temp) > 0) { 18 | cout << ". "; 19 | } 20 | else { 21 | dict.insert(temp); 22 | cout << s << " "; 23 | } 24 | 25 | if(cin.peek() == '\n') { 26 | cout << endl; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /enlarginghashtables.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | bool isprime(int n) { 7 | if(n == 2) { 8 | return true; 9 | } 10 | for(int i = 2; i < sqrt(n)+1; i++) { 11 | if(n % i == 0) { 12 | return false; 13 | } 14 | } 15 | return true; 16 | } 17 | 18 | int main() { 19 | int n; 20 | while(cin >> n && n != 0) { 21 | int copy = n; 22 | n *= 2; 23 | n++; 24 | while(!isprime(n)) { 25 | n++; 26 | } 27 | 28 | cout << n; 29 | if(!isprime(copy)) { 30 | cout << " (" << copy << " is not prime)"; 31 | } 32 | cout << endl; 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /erase.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | string a; 9 | string b; 10 | 11 | int n; 12 | cin >> n; 13 | 14 | cin >> a >> b; 15 | 16 | bool success = true; 17 | 18 | if(n%2 == 1) { 19 | for(int i = 0; i < a.length(); i++) { 20 | if(a[i] == b[i]) { 21 | success = false; 22 | } 23 | } 24 | } 25 | else { 26 | for(int i = 0; i < a.length(); i++) { 27 | if(a[i] != b[i]) { 28 | success = false; 29 | } 30 | } 31 | } 32 | 33 | if(success) { 34 | cout << "Deletion succeeded" << endl; 35 | } 36 | else { 37 | cout << "Deletion failed" << endl; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /esej.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | string toword(int n) { 6 | string temp; 7 | while(n > 0) { 8 | temp.push_back(n % 26 + 'a'); 9 | n /= 26; 10 | } 11 | return temp; 12 | } 13 | 14 | int main() { 15 | int n; 16 | cin >> n; 17 | cin >> n; 18 | 19 | for(int i = 1; i <= n; i++) { 20 | cout << toword(i) << " "; 21 | } 22 | cout << endl; 23 | } 24 | -------------------------------------------------------------------------------- /estimatingtheareaofacircle.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | double r; 8 | int m, c; 9 | cin >> r >> m >> c; 10 | 11 | cout.precision(17); 12 | 13 | double real = 0, sim = 0; 14 | while(!(r==0 && m==0 && c==0)) { 15 | real = M_PI * pow((double)r, 2); 16 | sim = pow((double)r*2, 2) * ((double)c / m); 17 | 18 | cout << fixed << real << " " << fixed << sim << endl; 19 | 20 | cin >> r >> m >> c; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /euclidsgame.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | typedef long long ll; 8 | 9 | bool play(ll a, ll b) { 10 | // Swap nums 11 | if(a > b) { 12 | return play(b, a); 13 | } 14 | 15 | // Winning move 16 | if(b % a == 0) { 17 | return true; 18 | } 19 | 20 | // Forced move 21 | if((b/a) == 1) { 22 | return !play(a, b-a); 23 | } 24 | 25 | // Normal move 26 | return true; 27 | } 28 | 29 | int main() { 30 | ll a, b; 31 | while(cin >> a && cin >> b && !(a == 0 && b == 0)) { 32 | if(b > a) { 33 | swap(a, b); 34 | } 35 | 36 | bool winner = play(a, b); 37 | 38 | if(winner) { 39 | cout << "Stan wins" << endl; 40 | } 41 | else { 42 | cout << "Ollie wins" << endl; 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /eulersnumber.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | typedef long double ld; 5 | 6 | int main() { 7 | ld ans = 0; 8 | ld curr = 1; 9 | 10 | int n; 11 | cin >> n; 12 | if(n > 30) n = 30; 13 | for(int i = 1; i <= n+1; i++) { 14 | ans += 1 / curr; 15 | curr *= i; 16 | } 17 | 18 | cout << fixed; 19 | cout.precision(15); 20 | cout << ans << endl; 21 | } 22 | -------------------------------------------------------------------------------- /evenodd.py: -------------------------------------------------------------------------------- 1 | l, r = raw_input().split() 2 | l = int(l) 3 | r = int(r) 4 | 5 | def f(x): 6 | i = 0 7 | while x != 1: 8 | if x % 2 == 0: 9 | x /= 2 10 | else: 11 | x += 1 12 | i += 1 13 | return i 14 | 15 | def solve(l, r): 16 | if l == r: 17 | return f(l) 18 | 19 | if l == 1: 20 | return solve(l+1, r) 21 | 22 | if l % 2 == 0: 23 | return solve(l+1, r) + f(l) 24 | 25 | if r % 2 == 1: 26 | return solve(l, r-1) + f(r) 27 | 28 | return 2*solve((l+1)/2, r/2) + 3*(r - l + 1)/2 29 | 30 | print int(solve(l, r) % (10**9 + 7)) 31 | -------------------------------------------------------------------------------- /eventplanning.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int participants, budget, hotels, weekends; 7 | cin >> participants >> budget >> hotels >> weekends; 8 | 9 | int bestprice = budget+1; 10 | 11 | for(int i = 0; i < hotels; i++) { 12 | int cost; 13 | cin >> cost; 14 | 15 | for(int j = 0; j < weekends; j++) { 16 | int rooms; 17 | cin >> rooms; 18 | 19 | if(rooms >= participants) { 20 | bestprice = min(bestprice, participants*cost); 21 | } 22 | } 23 | } 24 | 25 | if(bestprice <= budget) { 26 | cout << bestprice << endl; 27 | } 28 | else { 29 | cout << "stay home" << endl; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /exactchange2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int inf = 2 << 28; 7 | 8 | int main() { 9 | int cases; 10 | cin >> cases; 11 | 12 | while(cases--) { 13 | int n; 14 | cin >> n; 15 | 16 | vector v(10001, inf); 17 | v[0] = 0; 18 | 19 | int k; 20 | cin >> k; 21 | 22 | for(int i = 0; i < k; i++) { 23 | int coin; 24 | cin >> coin; 25 | 26 | for(int i = 10000 - coin; i >= 0; i--) { 27 | v[i+coin] = min(v[i+coin], v[i]+1); 28 | } 29 | } 30 | 31 | for(int i = n; i <= 10000; i++) { 32 | if(v[i] < inf/2) { 33 | cout << i << " " << v[i] << endl; 34 | break; 35 | } 36 | } 37 | 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /exactlyeletrical.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int x1, y1, x2, y2; 7 | cin >> x1 >> y1 >> x2 >> y2; 8 | int gas; 9 | cin >> gas; 10 | 11 | int dist = abs(y2-y1) + abs(x2-x1); 12 | gas -= dist; 13 | 14 | if(gas < 0) { 15 | cout << "N" << endl; 16 | return 0; 17 | } 18 | 19 | if(gas % 2 == 0) { 20 | cout << "Y" << endl; 21 | } 22 | else { 23 | cout << "N" << endl; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /exam.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n; 7 | cin >> n; 8 | string s1, s2; 9 | cin >> s1 >> s2; 10 | 11 | int s=0, d=0; 12 | for(int i = 0; i < s1.size(); i++) { 13 | if(s1[i] == s2[i]) s++; 14 | else d++; 15 | } 16 | 17 | int swaps = s1.size() - n; 18 | int lo = min(swaps, d); 19 | d -= lo; 20 | swaps -= lo; 21 | s += lo; 22 | 23 | cout << s - swaps << endl; 24 | } 25 | -------------------------------------------------------------------------------- /excursion.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | typedef long long ll; 7 | 8 | int main() { 9 | vector count(3, 0); 10 | 11 | string s; 12 | cin >> s; 13 | 14 | for(auto& i : s) { 15 | count[i-'0']++; 16 | } 17 | 18 | ll swaps = 0; 19 | 20 | for(auto& i : s) { 21 | if(i == '0') { 22 | count[0]--; 23 | } 24 | else { 25 | swaps += count[0]; 26 | } 27 | } 28 | 29 | for(auto& i : s) { 30 | if(i == '1') { 31 | count[1]--; 32 | } 33 | if(i == '2') { 34 | swaps += count[1]; 35 | } 36 | } 37 | 38 | cout << swaps << endl; 39 | } 40 | -------------------------------------------------------------------------------- /factstone.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int getRating(int n) { 7 | int total = 2; 8 | for(int i = 0; i < n; i++) { 9 | total += i; 10 | } 11 | return total; 12 | } 13 | 14 | int main() { 15 | int year; 16 | 17 | while(cin >> year) { 18 | if(year == 0) { 19 | return 0; 20 | } 21 | 22 | year -= 1940; 23 | int rating = getRating(year / 10); 24 | cout << rating << endl; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /factstone.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | def getBitsFromYear(year): 4 | year = long(year) 5 | year -= 1940 6 | year /= 10 7 | return 2**year 8 | 9 | def getMaxFromBits(bits): 10 | return (2**(bits))-1 11 | 12 | def getHighestFactorial(num): 13 | ret = 1 14 | count = 1 15 | 16 | while(ret < num): 17 | count += 1 18 | ret *= count 19 | 20 | return count - 1 21 | 22 | def main(): 23 | for line in sys.stdin: 24 | if line == '0\n': 25 | break 26 | 27 | bits = getBitsFromYear(line) 28 | max = getMaxFromBits(bits) 29 | fact = getHighestFactorial(max) 30 | print fact 31 | 32 | if __name__ == "__main__": 33 | main() 34 | 35 | -------------------------------------------------------------------------------- /faktor.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int a, b; 7 | cin >> a >> b; 8 | 9 | int ans = a * (b-1); 10 | 11 | cout << ans + 1 << endl; 12 | } 13 | -------------------------------------------------------------------------------- /fallingapart.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n; 7 | cin >> n; 8 | vector v(n); 9 | for(auto& i : v) { 10 | cin >> i; 11 | } 12 | 13 | sort(v.rbegin(), v.rend()); 14 | 15 | int a = 0; 16 | int b = 0; 17 | 18 | for(int i = 0; i < v.size(); i++) { 19 | if(i % 2 == 0) { 20 | a += v[i]; 21 | } 22 | else { 23 | b += v[i]; 24 | } 25 | } 26 | 27 | cout << a << " " << b << endl; 28 | } 29 | -------------------------------------------------------------------------------- /filip.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | string a; 9 | string b; 10 | 11 | cin >> a >> b; 12 | 13 | reverse(a.begin(), a.end()); 14 | reverse(b.begin(), b.end()); 15 | 16 | if(a < b) { 17 | cout << b << endl; 18 | } 19 | else { 20 | cout << a << endl; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /fizzbuzz.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int i, j, k; 7 | cin >> i >> j >> k; 8 | for(int m = 1; m <= k; m++) { 9 | if(m % i == 0 && m%j == 0) { 10 | cout << "FizzBuzz" << endl; 11 | } 12 | else if(m % i == 0) { 13 | cout << "Fizz" << endl; 14 | } 15 | else if(m % j == 0) { 16 | cout << "Buzz" << endl; 17 | } 18 | else { 19 | cout << m << endl; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /flowlayout.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n; 7 | while(cin >> n && n != 0) { 8 | int x, y; 9 | 10 | int savH = 0, savW = 0; 11 | int curH = 0, curW = 0; 12 | 13 | while(cin >> x && cin >> y && x != -1 && y != -1) { 14 | if(curW + x > n) { 15 | // Start new row 16 | savH += curH; 17 | savW = max(savW, curW); 18 | curH = 0; 19 | curW = 0; 20 | } 21 | 22 | curH = max(curH, y); 23 | curW += x; 24 | } 25 | 26 | savH += curH; 27 | savW = max(savW, curW); 28 | curH = 0; 29 | curW = 0; 30 | 31 | cout << savW << " x " << savH << endl; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /flowshop.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | int a, b; 8 | cin >> a >> b; 9 | 10 | vector> arr; 11 | arr.resize(a); 12 | 13 | for(int i = 0; i < a; i++) { 14 | for(int j = 0; j < b; j++) { 15 | int temp; 16 | cin >> temp; 17 | arr[i].push_back(temp); 18 | } 19 | } 20 | 21 | for(int i = 1; i < a; i++) { 22 | arr[i][0] += arr[i-1][0]; 23 | } 24 | 25 | for(int j = 1; j < b; j++) { 26 | arr[0][j] += arr[0][j-1]; 27 | } 28 | 29 | for(int i = 1; i < a; i++) { 30 | for(int j = 1; j < b; j++) { 31 | int x = arr[i][j-1]; 32 | int y = arr[i-1][j]; 33 | arr[i][j] += max(x,y); 34 | } 35 | } 36 | 37 | for(int i = 0; i < a; i++) { 38 | cout << arr[i][b-1] << " "; 39 | } 40 | cout << endl; 41 | } 42 | -------------------------------------------------------------------------------- /flyingsafely.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | ios::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | 9 | int cases; 10 | cin >> cases; 11 | 12 | int cities, pilots, a, b, i, j; 13 | for(i = 0; i < cases; i++) { 14 | cin >> cities >> pilots; 15 | 16 | for(j = 0; j < pilots; j++) { 17 | cin >> a >> b; 18 | } 19 | 20 | cout << cities - 1 << endl; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /fractalarea.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | typedef long long ll; 5 | typedef long double ld; 6 | 7 | void solve() { 8 | ld r; 9 | ll n; 10 | cin >> r >> n; 11 | 12 | ld currarea = M_PI * r * r; 13 | ld currcircles = 4; 14 | 15 | ld ans = 0; 16 | ans += currarea; 17 | 18 | ld curradd = currarea * currcircles / 4; 19 | 20 | for(ll i = 0; i < n-1; i++) { 21 | ans += curradd; 22 | curradd *= .75; 23 | } 24 | 25 | cout << fixed; 26 | cout.precision(8); 27 | cout << ans << endl; 28 | } 29 | 30 | int main() { 31 | ll cases; 32 | cin >> cases; 33 | while(cases--) { 34 | solve(); 35 | } 36 | } 37 | 38 | 39 | -------------------------------------------------------------------------------- /freefood.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | vector keep(365,false); 7 | 8 | int n; 9 | cin >> n; 10 | 11 | for(int i = 0; i < n; i++) { 12 | int n1, n2; 13 | cin >> n1 >> n2; 14 | 15 | for(int j = n1-1; j <= n2-1; j++) { 16 | keep[j] = true; 17 | } 18 | } 19 | 20 | int sum = 0; 21 | for(int i = 0; i < 365; i++) { 22 | if(keep[i]) sum++; 23 | } 24 | 25 | cout << sum << endl; 26 | } 27 | -------------------------------------------------------------------------------- /friday.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | int n; 8 | cin >> n; 9 | 10 | for(int i = 0; i < n; i++) { 11 | int d, m; 12 | cin >> d >> m; 13 | 14 | vector year; 15 | 16 | for(int i = 0; i < m; i++) { 17 | int days; 18 | cin >> days; 19 | 20 | for(int i = 1; i <= days; i++) { 21 | year.push_back(i); 22 | } 23 | } 24 | 25 | int fridays = 0; 26 | 27 | for(int i = 0; i < d; i++) { 28 | if(year[i] == 13 && i % 7 == 5) { 29 | fridays++; 30 | } 31 | } 32 | 33 | cout << fridays << endl; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /fridge.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() { 9 | string s; 10 | cin >> s; 11 | 12 | vector count; 13 | count.resize(11, 0); 14 | 15 | for(auto c : s) { 16 | count[c-'0']++; 17 | } 18 | 19 | count[10] = count[0]; 20 | 21 | int num = 1; 22 | int m = count[1]; 23 | for(int i = 1; i <= 10; i++) { 24 | if(count[i] < m) { 25 | num = i; 26 | } 27 | m = min(m, count[i]); 28 | } 29 | 30 | if(num == 10) { 31 | cout << 1; 32 | num = 0; 33 | } 34 | 35 | for(int i = 0; i < m+1; i++) { 36 | cout << num; 37 | } 38 | 39 | cout << endl; 40 | } 41 | -------------------------------------------------------------------------------- /froshweek2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | int n, m; 9 | cin >> n >> m; 10 | 11 | vector v1(n); 12 | vector v2(m); 13 | 14 | for(auto& i : v1) { 15 | cin >> i; 16 | } 17 | for(auto& i : v2) { 18 | cin >> i; 19 | } 20 | 21 | sort(v1.rbegin(), v1.rend()); 22 | sort(v2.rbegin(), v2.rend()); 23 | 24 | int work = 0; 25 | 26 | int idx1 = 0; 27 | int idx2 = 0; 28 | while(idx1 < v1.size() && idx2 < v2.size()) { 29 | if(v1[idx1] <= v2[idx2]) { 30 | work++; 31 | idx2++; 32 | } 33 | idx1++; 34 | } 35 | 36 | cout << work << endl; 37 | } 38 | -------------------------------------------------------------------------------- /grassseed.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | double cost; 7 | cin >> cost; 8 | 9 | int lawns; 10 | cin >> lawns; 11 | 12 | double totalArea; 13 | for(int i = 0; i < lawns; i++) { 14 | double l, w; 15 | cin >> l >> w; 16 | totalArea += l * w; 17 | } 18 | 19 | cout.precision(10); 20 | cout << fixed << totalArea * cost << endl; 21 | } 22 | -------------------------------------------------------------------------------- /greedilyincreasing.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | ios::sync_with_stdio(false); 8 | cin.tie(NULL); 9 | 10 | int n; 11 | cin >> n; 12 | 13 | vector v(n); 14 | for(auto& i : v) { 15 | cin >> i; 16 | } 17 | 18 | vector line; 19 | line.push_back(v[0]); 20 | 21 | for(int i = 1; i < v.size(); i++) { 22 | if(v[i] > line[line.size()-1]) { 23 | line.push_back(v[i]); 24 | } 25 | } 26 | 27 | cout << line.size() << endl; 28 | for(auto i : line) { 29 | cout << i << " "; 30 | } 31 | cout << endl; 32 | } 33 | -------------------------------------------------------------------------------- /growlinggears.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | int n; 9 | cin >> n; 10 | 11 | for(int i = 0; i < n; i++) { 12 | int m; 13 | cin >> m; 14 | 15 | vector v; 16 | 17 | for(int j = 0; j < m; j++) { 18 | double a, b, c; 19 | cin >> a >> b >> c; 20 | 21 | double pos = b / (2 * a); 22 | 23 | double val = a * pow(pos, 2) + b * pos + c; 24 | v.push_back(val); 25 | } 26 | 27 | int max = 0; 28 | for(int j = 0; j < m; j++) { 29 | if(v[j] > v[max]) { 30 | max = j; 31 | } 32 | } 33 | 34 | cout << max+1 << endl; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /guess.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int min = 1; 7 | int max = 1001; 8 | int guess = 500; 9 | string result; 10 | 11 | int i = 0; 12 | while(i < 11) { 13 | guess = (max - min) / 2 + min; 14 | cout << guess << endl; 15 | cin >> result; 16 | 17 | if(result == "correct") { 18 | return 0; 19 | } 20 | if(result == "lower") { 21 | max = guess; 22 | } 23 | if(result == "higher") { 24 | min = guess; 25 | } 26 | i++; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /halfacircle.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | double r, x, y; 8 | while(cin >> r && cin >> x && cin >> y) { 9 | double length = sqrt(pow(x, 2) + pow(y, 2)); 10 | if(length >= r) { 11 | cout << "miss" << endl; 12 | continue; 13 | } 14 | double area = M_PI * pow(r, 2); 15 | double height = r - length; 16 | double theta = 2 * acos(1-(height/r)); 17 | double chordArea = (pow(r, 2)/2) * (theta - sin(theta)); 18 | double otherArea = area - chordArea; 19 | 20 | if(chordArea < otherArea) { 21 | swap(chordArea, otherArea); 22 | } 23 | 24 | cout.precision(6); 25 | cout << fixed; 26 | cout << chordArea << " " << otherArea << endl; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /hangingout.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int total, queries; 7 | cin >> total >> queries; 8 | 9 | int rejected = 0; 10 | int current = 0; 11 | for(int i = 0; i < queries; i++) { 12 | string s; 13 | int size; 14 | 15 | cin >> s >> size; 16 | 17 | if(s == "enter") { 18 | if(current + size > total) { 19 | rejected++; 20 | } 21 | else { 22 | current += size; 23 | } 24 | } 25 | else { 26 | current -= size; 27 | } 28 | } 29 | 30 | cout << rejected << endl; 31 | } 32 | -------------------------------------------------------------------------------- /hangman.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | string word; 6 | string perm; 7 | cin >> word >> perm; 8 | int wrong = 0; 9 | set st; 10 | for(char c : word) { 11 | st.insert(c); 12 | } 13 | for(char c : perm) { 14 | if(st.count(c)) { 15 | st.erase(c); 16 | if(st.empty()) { 17 | cout << "WIN\n"; 18 | return 0; 19 | } 20 | } else { 21 | ++wrong; 22 | if(wrong == 10) { 23 | cout << "LOSE\n"; 24 | return 0; 25 | } 26 | } 27 | } 28 | cout << "WIN\n"; 29 | } 30 | 31 | 32 | -------------------------------------------------------------------------------- /happytrails.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | typedef long double ld; 7 | 8 | int main() { 9 | int segments; 10 | cin >> segments; 11 | 12 | ld height = 0; 13 | while(segments--) { 14 | ld angle, dist; 15 | cin >> angle >> dist; 16 | 17 | height += sin(angle * M_PI / 180) * dist; 18 | } 19 | 20 | cout << fixed; 21 | cout.precision(2); 22 | cout << height << endl; 23 | } 24 | -------------------------------------------------------------------------------- /harshadnumbers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | typedef long long ll; 5 | 6 | bool harshad(ll n) { 7 | ll c = n; 8 | 9 | ll t = 0; 10 | while(c > 0) { 11 | t += c % 10; 12 | c /= 10; 13 | } 14 | 15 | return n % t == 0; 16 | } 17 | 18 | int main() { 19 | ll n; 20 | cin >> n; 21 | while(!harshad(n)) { 22 | n++; 23 | } 24 | cout << n << endl; 25 | } 26 | -------------------------------------------------------------------------------- /haypoints.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | int m, n; 9 | cin >> m >> n; 10 | 11 | map values; 12 | 13 | for(int i = 0; i < m; i++) { 14 | string word; 15 | int value; 16 | cin >> word; 17 | cin >> value; 18 | 19 | values[word] = value; 20 | } 21 | 22 | for(int i = 0; i < n; i++) { 23 | int score = 0; 24 | string word; 25 | while(cin >> word && word != ".") { 26 | score += values[word]; 27 | } 28 | cout << score << endl; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /heartrate.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int cases; 7 | cin >> cases; 8 | 9 | while(cases--) { 10 | double d1, d2; 11 | cin >> d1 >> d2; 12 | 13 | double ans = 60.0 * (d1 / d2); 14 | double var = 60.0 / d2; 15 | 16 | cout << fixed; 17 | cout.precision(4); 18 | cout << ans - var << " " << ans << " " << ans + var << endl; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /height.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | int n; 8 | cin >> n; 9 | 10 | for(int i = 0; i < n; i++) { 11 | int temp; 12 | cin >> temp; 13 | cout << temp << " "; 14 | 15 | vector v; 16 | v.resize(20); 17 | for(int j = 0; j < 20; j++) { 18 | cin >> v[j]; 19 | } 20 | 21 | int steps = 0; 22 | 23 | while(v.size() > 0) { 24 | int m = 0; 25 | for(int j = 1; j < v.size(); j++) { 26 | if(v[j] < v[m]) { 27 | m = j; 28 | } 29 | } 30 | 31 | steps += m; 32 | v.erase(v.begin() + m); 33 | } 34 | 35 | cout << steps << endl; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /heirsdilemma.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | bool works(int n) { 6 | int tmp = n; 7 | vector cnt(10,0); 8 | while(n > 0) { 9 | if((n%10) == 0) return false; 10 | if(tmp % (n%10) != 0) return false; 11 | cnt[n%10]++; 12 | n /= 10; 13 | } 14 | for(auto i : cnt) { 15 | if(i > 1) return false; 16 | } 17 | return true; 18 | } 19 | 20 | int main() { 21 | int lo, hi; 22 | cin >> lo >> hi; 23 | 24 | int total = 0; 25 | for(int i = lo; i <= hi; i++) { 26 | if(works(i)) { 27 | total++; 28 | } 29 | } 30 | 31 | cout << total << endl; 32 | } 33 | -------------------------------------------------------------------------------- /heliocentric.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n = 1; 7 | int earth, mars; 8 | while(cin >> earth && cin >> mars) { 9 | cout << "Case " << n << ": "; 10 | 11 | int days = 0; 12 | while(earth != 0 || mars != 0) { 13 | days++; 14 | earth++; 15 | mars++; 16 | 17 | earth %= 365; 18 | mars %= 687; 19 | } 20 | 21 | cout << days << endl; 22 | 23 | n++; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /hello.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | cout << "Hello World!" << endl; 7 | } 8 | -------------------------------------------------------------------------------- /helpaphd.py: -------------------------------------------------------------------------------- 1 | import fileinput 2 | 3 | for line in fileinput.input(): 4 | line = line[:-1] 5 | 6 | if '=' in line: 7 | print('skipped') 8 | 9 | if '+' not in line: 10 | continue 11 | 12 | line = line.split('+') 13 | print(int(line[0]) + int(line[1])) 14 | -------------------------------------------------------------------------------- /herman.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | double i; 8 | cin >> i; 9 | cout.precision(8); 10 | 11 | cout << fixed << M_PI * pow(i, 2) << endl; 12 | cout << fixed << pow(i, 2) * 2 << endl; 13 | } 14 | -------------------------------------------------------------------------------- /hindex.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | ios::sync_with_stdio(false); 6 | cin.tie(0); 7 | cout.tie(0); 8 | int n; 9 | cin >> n; 10 | vector v(n); 11 | for(auto& i : v) { 12 | cin >> i; 13 | } 14 | sort(v.rbegin(),v.rend()); 15 | 16 | int ans = 0; 17 | for(int i = 0; i < n; i++) { 18 | if(v[i] >= i+1) { 19 | ans = i+1; 20 | } 21 | else break; 22 | } 23 | 24 | cout << ans << endl; 25 | } 26 | -------------------------------------------------------------------------------- /hissingmicrophone.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | string s; 7 | cin >> s; 8 | 9 | int i = 0; 10 | bool f = false; 11 | for(auto c : s) { 12 | if(c == 's') { 13 | i++; 14 | if(i == 2) { 15 | f = true; 16 | } 17 | } 18 | else { 19 | i = 0; 20 | } 21 | } 22 | 23 | if(f) { 24 | cout << "hiss" << endl; 25 | } 26 | else { 27 | cout << "no hiss" << endl; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /hothike.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n; 7 | cin >> n; 8 | 9 | vector v(n); 10 | for(auto& i : v) { 11 | cin >> i; 12 | } 13 | 14 | int ans = 50; 15 | int idx = 0; 16 | for(int i = 2; i < n; i++) { 17 | if(ans > max(v[i], v[i-2])) { 18 | ans = max(v[i], v[i-2]); 19 | idx = i-1; 20 | } 21 | } 22 | 23 | cout << idx << " " << ans << endl; 24 | } 25 | -------------------------------------------------------------------------------- /houseofcards.py: -------------------------------------------------------------------------------- 1 | def get_num_cards(height): 2 | return (3 * height**2 + height) // 2 3 | 4 | def main(): 5 | height = int(input()) 6 | 7 | while get_num_cards(height) % 4 != 0: 8 | height += 1 9 | 10 | print(height) 11 | 12 | if __name__ == "__main__": 13 | main() 14 | -------------------------------------------------------------------------------- /humancannonball2.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import math 3 | 4 | 5 | 6 | def main(): 7 | sys.stdin.readline() 8 | 9 | for line in sys.stdin: 10 | vars = line.split() 11 | 12 | v = float(vars[0]) 13 | theta = float(vars[1]) 14 | x = float(vars[2]) 15 | h1 = float(vars[3]) 16 | h2 = float(vars[4]) 17 | 18 | h1 += 1 19 | h2 -= 1 20 | 21 | theta = math.radians(theta) 22 | t = x / (v * math.cos(theta)) 23 | y = (v * t * math.sin(theta)) - (.5 * 9.81 * (t**2)) 24 | 25 | if y > h1 and y < h2: 26 | print 'Safe' 27 | else: 28 | print 'Not Safe' 29 | 30 | 31 | 32 | """ Launch main """ 33 | if __name__ == '__main__': 34 | main() 35 | -------------------------------------------------------------------------------- /iboard.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | string s; 8 | while(getline(cin, s)) { 9 | int ones = 0; 10 | int zeroes = 0; 11 | 12 | for(auto c : s) { 13 | for(int i = 0; i < 7; i++) { 14 | if(c % 2 == 0) { 15 | zeroes++; 16 | } 17 | else { 18 | ones++; 19 | } 20 | c >>= 1; 21 | } 22 | } 23 | 24 | if(ones % 2 == 1 || zeroes % 2 == 1) { 25 | cout << "trapped" << endl; 26 | } 27 | else { 28 | cout << "free" << endl; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /icpcawards.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n; 7 | cin >> n; 8 | 9 | unordered_set seen; 10 | 11 | int count = 0; 12 | for(int i = 0; i < n; i++) { 13 | string s1, s2; 14 | cin >> s1 >> s2; 15 | 16 | if(seen.count(s1) == 0 && count < 12) { 17 | cout << s1 << " " << s2 << endl; 18 | count++; 19 | } 20 | seen.insert(s1); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /icpcteamselection.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n; 7 | cin >> n; 8 | 9 | while(n--) { 10 | int p; 11 | cin >> p; 12 | 13 | vector v(p*3); 14 | for(auto& i : v) { 15 | cin >> i; 16 | } 17 | 18 | sort(v.rbegin(), v.rend()); 19 | 20 | int total = 0; 21 | for(int i = 0; i < p; i++) { 22 | total += v[i*2+1]; 23 | } 24 | 25 | cout << total << endl; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /incognito.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | void solve() { 6 | int n; 7 | cin >> n; 8 | 9 | map m; 10 | 11 | for(int i = 0; i < n; i++) { 12 | string s1, s2; 13 | cin >> s1 >> s2; 14 | 15 | m[s2]++; 16 | } 17 | 18 | int ans = 1; 19 | for(auto i : m) { 20 | ans *= i.second + 1; 21 | } 22 | 23 | cout << ans - 1 << endl; 24 | } 25 | 26 | int main() { 27 | int cases; 28 | cin >> cases; 29 | while(cases--) { 30 | solve(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /integerdivision.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | typedef long long ll; 5 | 6 | int main() { 7 | ll n, d; 8 | cin >> n >> d; 9 | map m; 10 | for(int i = 0; i < n; i++) { 11 | ll t; 12 | cin >> t; 13 | m[t/d]++; 14 | } 15 | ll total = 0; 16 | for(auto i : m) { 17 | ll t = i.second; 18 | total += t * (t-1) / 2; 19 | } 20 | cout << total << endl; 21 | } 22 | -------------------------------------------------------------------------------- /intergalacticbidding.py: -------------------------------------------------------------------------------- 1 | import fileinput 2 | 3 | ct = 0 4 | bidders = [] 5 | 6 | for line in fileinput.input(): 7 | if ct == 0: 8 | n, m = line.split() 9 | n = int(n) 10 | m = int(m) 11 | else: 12 | line = line.split() 13 | bidders.append([line[0], int(line[1])]) 14 | ct += 1 15 | 16 | bidders = sorted(bidders, key = lambda x : (-x[1])) 17 | 18 | ans = [] 19 | for i in bidders: 20 | if m - i[1] >= 0: 21 | m -= i[1] 22 | ans.append(i[0]) 23 | 24 | if m == 0: 25 | print(len(ans)) 26 | for i in ans: 27 | print(i) 28 | else: 29 | print(0) 30 | 31 | -------------------------------------------------------------------------------- /inversefactorial.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | string s; 8 | cin >> s; 9 | 10 | // Small factorials 11 | if(s.size() < 7) { 12 | int n = stoi(s); 13 | 14 | if(n <= 1) { 15 | cout << 1 << endl; 16 | return 0; 17 | } 18 | 19 | int divisor = 0; 20 | while(n != 1) { 21 | divisor++; 22 | n /= divisor; 23 | } 24 | 25 | cout << divisor << endl; 26 | return 0; 27 | } 28 | 29 | // Big factorials 30 | else { 31 | int i = 1; 32 | double ans = 1; 33 | 34 | while(true) { 35 | ans += log10(i); 36 | 37 | if(floor(ans) == s.size()) { 38 | cout << i << endl; 39 | break; 40 | } 41 | 42 | i++; 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /irepeatmyself.py: -------------------------------------------------------------------------------- 1 | import fileinput 2 | 3 | def main(): 4 | first = True 5 | for line in fileinput.input(): 6 | line = line[:-1] 7 | if first: 8 | first = False 9 | continue 10 | printed = False 11 | for i in range(1, len(line)): 12 | templine = line[0:i] 13 | templine = templine * len(line) 14 | templine = templine[:len(line)] 15 | if templine == line: 16 | printed = True 17 | print(i) 18 | break 19 | if not printed: 20 | print(len(line)) 21 | 22 | if __name__ == "__main__": 23 | main() 24 | -------------------------------------------------------------------------------- /isithalloween.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | string s1, s2; 7 | cin >> s1 >> s2; 8 | if((s1 == "OCT" && s2 == "31") || (s1 == "DEC" && s2 == "25")) { 9 | cout << "yup" << endl; 10 | } 11 | else { 12 | cout << "nope" << endl; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /janitortroubles.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | vector arr(4); 6 | double s = 0; 7 | for(int i = 0; i < 4; ++i) { 8 | cin >> arr[i]; 9 | s += arr[i]; 10 | } 11 | s /= 2; 12 | sort(arr.begin(), arr.end()); 13 | double res = 0; 14 | do { 15 | double area = (s-arr[0])*(s-arr[1])*(s-arr[2])*(s-arr[3]); 16 | area = sqrt(area); 17 | res = max(res, area); 18 | } while(next_permutation(arr.begin(), arr.end())); 19 | cout << setprecision(8) << fixed << res << '\n'; 20 | return 0; 21 | } 22 | 23 | 24 | -------------------------------------------------------------------------------- /jobexpenses.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n; 7 | cin >> n; 8 | 9 | int total = 0; 10 | for(int i = 0; i < n; i++) { 11 | int t; 12 | cin >> t; 13 | 14 | if(t < 0) { 15 | total -= t; 16 | } 17 | } 18 | 19 | cout << total << endl; 20 | } 21 | -------------------------------------------------------------------------------- /jollyjumpers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | typedef long long ll; 5 | 6 | int main() { 7 | ios::sync_with_stdio(false); 8 | cin.tie(NULL); 9 | 10 | ll n; 11 | while(cin >> n) { 12 | vector v(n); 13 | for(auto& i : v) { 14 | cin >> i; 15 | } 16 | 17 | vector seen(n, false); 18 | 19 | for(ll i = 1; i < n; i++) { 20 | ll diff = abs(v[i] - v[i-1]); 21 | if(diff >= 0 && diff < n) { 22 | seen[diff] = true; 23 | } 24 | } 25 | 26 | bool works = true; 27 | for(int i = 1; i < n; i++) { 28 | works &= seen[i]; 29 | } 30 | 31 | if(works) { 32 | cout << "Jolly" << endl; 33 | } 34 | else { 35 | cout << "Not jolly" << endl; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /judgingmoose.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | int a, b; 8 | cin >> a >> b; 9 | 10 | if(a == 0 && b == 0) { 11 | cout << "Not a moose" << endl; 12 | return 0; 13 | } 14 | 15 | if(a == b) { 16 | cout << "Even "; 17 | } 18 | else { 19 | cout << "Odd "; 20 | } 21 | 22 | cout << 2 * max(a, b) << endl; 23 | } 24 | -------------------------------------------------------------------------------- /jughard.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | typedef long long ll; 7 | 8 | int main() { 9 | int cases; 10 | cin >> cases; 11 | 12 | while(cases--) { 13 | ll a, b, c; 14 | cin >> a >> b >> c; 15 | 16 | ll s = __gcd(a, b); 17 | 18 | if(c % s == 0) { 19 | cout << "Yes" << endl; 20 | } 21 | else { 22 | cout << "No" << endl; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /justaminute.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n; 7 | cin >> n; 8 | 9 | long double mins = 0, seconds = 0; 10 | 11 | for(int i = 0; i < n; i++) { 12 | int m, s; 13 | cin >> m >> s; 14 | mins += m; 15 | seconds += s; 16 | } 17 | 18 | long double sl = (seconds / (mins * 60)); 19 | 20 | if(sl <= 1) { 21 | cout << "measurement error" << endl; 22 | } 23 | else { 24 | cout.precision(9); 25 | cout << fixed << sl << endl; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /kemija.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | string s, t; 8 | getline(cin,s); 9 | 10 | for(int i = 0; i < s.size(); i++) { 11 | if(s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u') { 12 | i += 2; 13 | } 14 | t.push_back(s[i]); 15 | } 16 | 17 | cout << t << endl; 18 | } 19 | -------------------------------------------------------------------------------- /keytocrypto.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | string a, b; 7 | cin >> a >> b; 8 | 9 | for(int i = 0; i < a.size(); i++) { 10 | int idx = i % b.size(); 11 | 12 | int val = (a[i] - 'A') - (b[idx] - 'A'); 13 | if(val >= 26) { 14 | val -= 26; 15 | } 16 | if(val < 0) { 17 | val += 26; 18 | } 19 | 20 | a[i] = val + 'A'; 21 | b[idx] = a[i]; 22 | } 23 | 24 | cout << a << endl; 25 | } 26 | -------------------------------------------------------------------------------- /kitten.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() { 9 | // Setup 10 | vector nextStep; 11 | nextStep.resize(100, -1); 12 | 13 | int kitten; 14 | cin >> kitten; 15 | 16 | int n; 17 | cin.ignore(); 18 | 19 | // Store all input into tree 20 | while(cin >> n && n != -1) { 21 | string s; 22 | getline(cin, s); 23 | 24 | stringstream line(s); 25 | 26 | int temp; 27 | while(line >> temp) { 28 | nextStep[temp] = n; 29 | } 30 | } 31 | 32 | while(kitten != -1) { 33 | cout << kitten << " "; 34 | kitten = nextStep[kitten]; 35 | } 36 | cout << endl; 37 | } 38 | -------------------------------------------------------------------------------- /kornislav.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | vector v; 9 | v.resize(4); 10 | cin >> v[0] >> v[1] >> v[2] >> v[3]; 11 | 12 | sort(v.begin(), v.end()); 13 | 14 | cout << v[0] * v[2] << endl; 15 | } 16 | -------------------------------------------------------------------------------- /kutevi.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n, m; 7 | cin >> n >> m; 8 | 9 | int num = 360; 10 | for(int i = 0; i < n; i++) { 11 | int t; 12 | cin >> t; 13 | num = __gcd(num, t); 14 | } 15 | 16 | for(int i = 0; i < m; i++) { 17 | int t; 18 | cin >> t; 19 | if(t % num == 0) { 20 | cout << "YES" << endl; 21 | } 22 | else { 23 | cout << "NO" << endl; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /ladder.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | int a, b; 8 | cin >> a >> b; 9 | 10 | cout << ceil(a / sin(b * M_PI / 180)) << endl; 11 | } 12 | -------------------------------------------------------------------------------- /lastfactorialdigit.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | void solve() { 6 | int n; 7 | cin >> n; 8 | 9 | int ans = 1; 10 | for(int i = 1; i <= n; i++) { 11 | ans *= i; 12 | ans %= 10; 13 | } 14 | 15 | cout << ans << endl; 16 | } 17 | 18 | int main() { 19 | int cases; 20 | cin >> cases; 21 | while(cases--) { 22 | solve(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /leftbeehind.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | while(true) { 7 | int a, b; 8 | cin >> a >> b; 9 | if(a == 0 && b == 0) { 10 | return 0; 11 | } 12 | 13 | if(a + b == 13) { 14 | cout << "Never speak again." << endl; 15 | continue; 16 | } 17 | if(a == b) { 18 | cout << "Undecided." << endl; 19 | continue; 20 | } 21 | if(a > b) { 22 | cout << "To the convention." << endl; 23 | continue; 24 | } 25 | if(a < b) { 26 | cout << "Left beehind." << endl; 27 | continue; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /lektira.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | void check(string s, string& best, int i, int j) { 8 | reverse(s.begin(), s.begin()+i); 9 | reverse(s.begin()+i, s.begin()+j); 10 | reverse(s.begin()+j, s.end()); 11 | 12 | if(s < best) { 13 | best = s; 14 | } 15 | } 16 | 17 | int main() { 18 | string s; 19 | cin >> s; 20 | 21 | string best = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"; 22 | for(int i = 1; i < s.size()-1; i++) { 23 | for(int j = i + 1; j < s.size()-0; j++) { 24 | check(s, best, i, j); 25 | } 26 | } 27 | 28 | cout << best << endl; 29 | } 30 | -------------------------------------------------------------------------------- /licensetolaunch.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | typedef long long ll; 5 | ll inf = (ll)1 << 61; 6 | 7 | int main() { 8 | ll lo = inf; 9 | ll idx = 0; 10 | 11 | ll n; 12 | cin >> n; 13 | for(ll i = 0; i < n; i++) { 14 | ll t; 15 | cin >> t; 16 | if(t < lo) { 17 | lo = t; 18 | idx = i; 19 | } 20 | } 21 | 22 | cout << idx << endl; 23 | } 24 | -------------------------------------------------------------------------------- /limbo1.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | 3 | def get(n): 4 | return n * (n-1) / 2 5 | 6 | for i in range(n): 7 | l,r = map(int,raw_input().split()) 8 | 9 | ''' NAIVE 10 | ans = 1 11 | for i in range(l): 12 | ans += i+1 13 | for i in range(r): 14 | ans += i+l+2 15 | 16 | print(ans) 17 | ''' 18 | 19 | ans = 1 20 | ans += l 21 | ans += 2*r 22 | ans += get(l+r) 23 | 24 | print(ans) 25 | -------------------------------------------------------------------------------- /lindenmayorsystem.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | int n, m; 9 | cin >> n >> m; 10 | 11 | unordered_map translate; 12 | for(int i = 0; i < n; i++) { 13 | char c; 14 | cin >> c; 15 | cin.ignore(4); 16 | string s; 17 | cin >> s; 18 | translate[c] = s; 19 | } 20 | 21 | string s, e; 22 | cin >> e; 23 | 24 | for(int i = 0; i < m; i++) { 25 | s = e; 26 | e = ""; 27 | for(auto j : s) { 28 | if(translate.count(j) > 0) { 29 | e += translate[j]; 30 | } 31 | else { 32 | e += j; 33 | } 34 | } 35 | } 36 | 37 | cout << e << endl; 38 | } 39 | -------------------------------------------------------------------------------- /lipschitzconstant.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | typedef long double ld; 5 | ld inf = (ld)1000000000000; 6 | 7 | int main() { 8 | int n; 9 | cin >> n; 10 | vector> v(n); 11 | for(auto& i : v) { 12 | cin >> i.first >> i.second; 13 | } 14 | 15 | sort(v.begin(),v.end()); 16 | 17 | ld best = -inf; 18 | for(int i = 1; i < n; i++) { 19 | ld bot = v[i].first - v[i-1].first; 20 | ld top = v[i].second - v[i-1].second; 21 | best = max(best, abs(top / bot)); 22 | } 23 | 24 | cout << fixed; 25 | cout.precision(12); 26 | cout << best << endl; 27 | } 28 | -------------------------------------------------------------------------------- /listgame.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | long long n; 8 | cin >> n; 9 | 10 | int total = 0; 11 | while(n > 1) { 12 | int i; 13 | for(i = 2; i <= sqrt(n)+2; i++) { 14 | if(n % i == 0) { 15 | total++; 16 | n /= i; 17 | break; 18 | } 19 | } 20 | if(i > sqrt(n)) { 21 | total++; 22 | break; 23 | } 24 | } 25 | 26 | cout << total << endl; 27 | } 28 | -------------------------------------------------------------------------------- /lockedtreasure.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | vector> v; 8 | v.resize(31, vector(31, 1)); 9 | 10 | for(int i = 2; i <= 30; i++) { 11 | for(int j = 2; j <= i; j++) { 12 | v[i][j] = v[i-1][j] + v[i-1][j-1]; 13 | } 14 | } 15 | 16 | int cases; 17 | cin >> cases; 18 | 19 | for(int i = 0; i < cases; i++) { 20 | int pirates, groups; 21 | cin >> pirates >> groups; 22 | cout << v[pirates][groups] << endl; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /lostlineup.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n; 7 | cin >> n; 8 | 9 | vector ans(n); 10 | ans[0] = 1; 11 | 12 | for(int i = 2; i <= n; i++) { 13 | int t; 14 | cin >> t; 15 | ans[t+1] = i; 16 | } 17 | 18 | for(auto i : ans) { 19 | cout << i << " "; 20 | } 21 | cout << endl; 22 | } 23 | -------------------------------------------------------------------------------- /luhnchecksum.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | bool solve() { 6 | string s; 7 | cin >> s; 8 | 9 | reverse(s.begin(),s.end()); 10 | 11 | int total = 0; 12 | 13 | for(int i = 0; i < s.size(); i++) { 14 | int d = s[i] - '0'; 15 | if(i % 2 == 1) { 16 | d *= 2; 17 | } 18 | if(d >= 10) { 19 | d = (d%10) + (d/10); 20 | } 21 | total += d; 22 | } 23 | 24 | return total % 10 == 0; 25 | } 26 | 27 | int main() { 28 | int n; 29 | cin >> n; 30 | while(n--) { 31 | if(solve()) { 32 | cout << "PASS" << endl; 33 | } 34 | else { 35 | cout << "FAIL" << endl; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /maptiles2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | string s; 8 | cin >> s; 9 | 10 | int n = s.length(); 11 | int i = 0, j = 0; 12 | for(auto c : s) { 13 | i *= 2; 14 | j *= 2; 15 | if(int(c-'0')&1) i++; 16 | if(int(c-'0')&2) j++; 17 | } 18 | 19 | cout << n << " " << i << " " << j << endl; 20 | } 21 | -------------------------------------------------------------------------------- /mastermind.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() { 9 | int n; 10 | cin >> n; 11 | 12 | string code, guess; 13 | cin >> code >> guess; 14 | 15 | string codeleft, guessleft; 16 | 17 | int r = 0, s = 0; 18 | for(int i = 0; i < n; i++) { 19 | if(code[i] == guess[i]) { 20 | r++; 21 | } 22 | else { 23 | codeleft.push_back(code[i]); 24 | guessleft.push_back(guess[i]); 25 | } 26 | } 27 | 28 | while(!codeleft.empty()) { 29 | int index = guessleft.find(codeleft[0]); 30 | if(index >= 0) { 31 | s++; 32 | guessleft.erase(guessleft.begin()+index); 33 | } 34 | codeleft.erase(codeleft.begin()); 35 | } 36 | 37 | cout << r << " " << s << endl; 38 | } 39 | -------------------------------------------------------------------------------- /matrix.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | long long a, b, c, d; 7 | int count = 1; 8 | while(cin >> a && cin >> b && cin >> c && cin >> d) { 9 | cout << "Case " << count << ":" << endl; 10 | count++; 11 | 12 | long long denom = (a*d) - (b*c); 13 | 14 | cout << d / denom << " " << -b / denom << endl; 15 | cout << -c / denom << " " << a / denom << endl; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /metaprogramming.py: -------------------------------------------------------------------------------- 1 | import fileinput 2 | 3 | def main(): 4 | words = {} 5 | for line in fileinput.input(): 6 | line = line.split() 7 | if line[0] == "define": 8 | words[line[2]] = int(line[1]) 9 | if line[0] == "eval": 10 | try: 11 | to_print = True 12 | if line[2] == ">": 13 | to_print = words[line[1]] > words[line[3]] 14 | if line[2] == "<": 15 | to_print = words[line[1]] < words[line[3]] 16 | if line[2] == "=": 17 | to_print = words[line[1]] == words[line[3]] 18 | 19 | if to_print: 20 | print("true") 21 | else: 22 | print("false") 23 | 24 | except: 25 | print("undefined") 26 | 27 | 28 | if __name__ == "__main__": 29 | main() 30 | -------------------------------------------------------------------------------- /mia.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int getScore(int hi, int lo) { 6 | if(lo > hi) { 7 | swap(lo, hi); 8 | } 9 | if(hi == 2 && lo == 1) { 10 | return 100000; 11 | } 12 | if(hi == lo) { 13 | return hi * 100; 14 | } 15 | return hi * 10 + lo; 16 | } 17 | 18 | int main() { 19 | int a, b, c, d; 20 | while(cin >> a >> b >> c >> d && a != 0 && b != 0) { 21 | int score1 = getScore(a, b); 22 | int score2 = getScore(c, d); 23 | 24 | if(score1 == score2) { 25 | cout << "Tie." << endl; 26 | continue; 27 | } 28 | if(score1 > score2) { 29 | cout << "Player 1 wins." << endl; 30 | continue; 31 | } 32 | if(score1 < score2) { 33 | cout << "Player 2 wins." << endl; 34 | continue; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /minimumscalar.py: -------------------------------------------------------------------------------- 1 | def main(): 2 | n = int(raw_input()) 3 | 4 | for i in range(n): 5 | print "Case #" + str(i+1) + ":", 6 | m = int(raw_input()) 7 | 8 | a = raw_input() 9 | b = raw_input() 10 | 11 | a = a.split() 12 | b = b.split() 13 | 14 | a = [int(k) for k in a] 15 | b = [int(k) for k in b] 16 | 17 | a.sort() 18 | b.sort(reverse=True) 19 | 20 | total = 0 21 | 22 | for j in range(m): 23 | total += a[j] * b[j] 24 | 25 | print total 26 | 27 | if __name__ == "__main__": 28 | main() 29 | -------------------------------------------------------------------------------- /mirror.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | int n; 8 | cin >> n; 9 | 10 | for(int i = 0; i < n; i++) { 11 | int x, y; 12 | cin >> x >> y; 13 | 14 | vector> v; 15 | v.resize(x); 16 | 17 | for(int j = 0; j < x; j++) { 18 | for(int k = 0; k < y; k++) { 19 | char temp; 20 | cin >> temp; 21 | v[j].push_back(temp); 22 | } 23 | } 24 | 25 | cout << "Test " << i+1 << endl; 26 | for(int j = x-1; j >= 0; j--) { 27 | for(int k = y-1; k >= 0; k--) { 28 | cout << v[j][k]; 29 | } 30 | cout << endl; 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /mixedfractions.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | long int num, div; 7 | while(cin >> num >> div) { 8 | if(num == 0 && div == 0) { 9 | return 0; 10 | } 11 | cout << num / div << " " << num % div << " / " << div << endl; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /mjehuric.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | vector v; 8 | 9 | void print() { 10 | for(int i = 0; i < 5; i++) { 11 | cout << v[i] << " "; 12 | } 13 | cout << endl; 14 | } 15 | 16 | int main() { 17 | v.resize(5); 18 | cin >> v[0] >> v[1] >> v[2] >> v[3] >> v[4]; 19 | 20 | while(!is_sorted(v.begin(), v.end())) { 21 | if(v[0] > v[1]) { 22 | swap(v[0], v[1]); 23 | print(); 24 | } 25 | if(v[1] > v[2]) { 26 | swap(v[1], v[2]); 27 | print(); 28 | } 29 | if(v[2] > v[3]) { 30 | swap(v[2], v[3]); 31 | print(); 32 | } 33 | if(v[3] > v[4]) { 34 | swap(v[3], v[4]); 35 | print(); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /modulo.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | bool mod[42]; 7 | for(int i = 0; i < 42; i++) { 8 | mod[i] = false; 9 | } 10 | 11 | for(int i = 0; i < 10; i++) { 12 | int temp; 13 | cin >> temp; 14 | mod[temp%42] = true; 15 | } 16 | 17 | int trues = 0; 18 | 19 | for(int i = 0; i < 42; i++) { 20 | if(mod[i]) { 21 | trues++; 22 | } 23 | } 24 | 25 | cout << trues << endl; 26 | } 27 | -------------------------------------------------------------------------------- /mosquito.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int m, p, l; 7 | int e; 8 | int r, s; 9 | int n; 10 | 11 | while(cin >> m && cin >> p && cin >> l) { 12 | cin >> e >> r >> s >> n; 13 | 14 | for(int i = 0; i < n; i++) { 15 | int temp_m, temp_p, temp_l; 16 | temp_l = e * m; 17 | temp_p = l / r; 18 | temp_m = p / s; 19 | m = temp_m; 20 | l = temp_l; 21 | p = temp_p; 22 | } 23 | 24 | cout << m << endl; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /nastyhacks.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n; 7 | cin >> n; 8 | 9 | for(int i = 0; i < n; i++) { 10 | long long r, e, c; 11 | cin >> r >> e >> c; 12 | 13 | if(e - c == r) { 14 | cout << "does not matter" << endl; 15 | } 16 | else if(e - c > r) { 17 | cout << "advertise" << endl; 18 | } 19 | else { 20 | cout << "do not advertise" << endl; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /neighborhoodwatch.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | typedef long long ll; 5 | 6 | int main() { 7 | ll n, k; 8 | cin >> n >> k; 9 | 10 | ll total = n * (n+1) / 2; 11 | 12 | vector houses; 13 | houses.push_back(0); 14 | for(ll i = 0; i < k; i++) { 15 | ll t; 16 | cin >> t; 17 | houses.push_back(t); 18 | } 19 | houses.push_back(n+1); 20 | 21 | for(ll i = 1; i < houses.size(); i++) { 22 | ll diff = houses[i] - houses[i-1] - 1; 23 | total -= diff * (diff + 1) / 2; 24 | } 25 | 26 | cout << total << endl; 27 | } 28 | -------------------------------------------------------------------------------- /nine.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | 7 | ll fast(ll base, ll exp, ll mod) { 8 | ll res = 1; 9 | while(exp > 0) { 10 | if(exp & 1 == 1) { 11 | res = (res * base) % mod; 12 | } 13 | base = (base * base) % mod; 14 | exp /= 2; 15 | } 16 | 17 | return res % mod; 18 | } 19 | 20 | int main() { 21 | ll n; 22 | cin >> n; 23 | ll mod = 1000000007; 24 | 25 | for(int i = 0; i < n; i++) { 26 | ll num; 27 | cin >> num; 28 | num--; 29 | 30 | ll ans = (8 * fast(9, num, mod)) % mod; 31 | cout << ans << endl; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /nodup.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | unordered_map s; 8 | 9 | string temp; 10 | while(cin >> temp) { 11 | s[temp]++; 12 | if(s[temp] > 1) { 13 | cout << "no" << endl; 14 | return 0; 15 | } 16 | } 17 | 18 | cout << "yes" << endl; 19 | } 20 | -------------------------------------------------------------------------------- /numberfun.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int cases; 7 | cin >> cases; 8 | 9 | while(cases--) { 10 | int a, b, c; 11 | cin >> a >> b >> c; 12 | 13 | bool possible = false; 14 | if(a + b == c) { 15 | possible = true; 16 | } 17 | if(a * b == c) { 18 | possible = true; 19 | } 20 | if(a - b == c) { 21 | possible = true; 22 | } 23 | if(b - a == c) { 24 | possible = true; 25 | } 26 | if(a % b == 0 && a / b == c) { 27 | possible = true; 28 | } 29 | if(b % a == 0 && b / a == c) { 30 | possible = true; 31 | } 32 | 33 | if(possible) { 34 | cout << "Possible" << endl; 35 | } 36 | else { 37 | cout << "Impossible" << endl; 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /numbertree.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | int n; 9 | cin >> n; 10 | 11 | string path; 12 | cin >> path; 13 | 14 | int maxi = pow(2, n + 1); 15 | 16 | int pos = 1; 17 | for(auto c : path) { 18 | pos *= 2; 19 | if(c == 'R') { 20 | pos++; 21 | } 22 | } 23 | 24 | cout << maxi - pos << endl; 25 | } 26 | -------------------------------------------------------------------------------- /oddgnome.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int total, num, temp1, temp2; 7 | 8 | cin >> total; 9 | 10 | for(int i = 0; i < total; i++) { 11 | bool test = true; 12 | temp1 = 0; 13 | num = 0; 14 | cin >> num; 15 | cin >> temp1; 16 | for(int i = 1; i < num; i++) { 17 | temp2 = temp1; 18 | cin >> temp1; 19 | if(temp2+1 != temp1 && test) { 20 | cout << i+1 << endl; 21 | test = false; 22 | } 23 | 24 | } 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /oddities.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int cases; 7 | cin >> cases; 8 | 9 | int num; 10 | for(int i = 0; i < cases; i++) { 11 | cin >> num; 12 | if(num % 2 == 0) { 13 | cout << num << " is even" << endl; 14 | } 15 | else { 16 | cout << num << " is odd" << endl; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /oddmanout.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | int n; 9 | cin >> n; 10 | 11 | for(int i = 0; i < n; i++) { 12 | int items; 13 | cin >> items; 14 | 15 | vector v; 16 | 17 | cout << "Case #" << i+1 << ": "; 18 | 19 | for(int j = 0; j < items; j++) { 20 | long int item; 21 | cin >> item; 22 | v.push_back(item); 23 | } 24 | 25 | sort(v.begin(), v.end()); 26 | 27 | bool printed = false; 28 | for(int i = 0; i < v.size() - 1; i+=2) { 29 | if(v[i] != v[i+1] && !printed) { 30 | cout << v[i] << endl; 31 | printed = true; 32 | } 33 | } 34 | if(!printed) { 35 | cout << v[items-1] << endl; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /oktalni.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int conv(string s, int index) { 7 | int n = 0; 8 | if(s[index] == '1') { 9 | n += 4; 10 | } 11 | if(s[index+1] == '1') { 12 | n += 2; 13 | } 14 | if(s[index+2] == '1') { 15 | n += 1; 16 | } 17 | return n; 18 | } 19 | 20 | int main() { 21 | string s; 22 | cin >> s; 23 | 24 | while(s.length() % 3 != 0) { 25 | s.insert(s.begin(),'0'); 26 | } 27 | 28 | for(int i = 0; i < s.length(); i+=3) { 29 | cout << conv(s, i); 30 | } 31 | 32 | cout << endl; 33 | } 34 | -------------------------------------------------------------------------------- /olderbrother.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | typedef long long ll; 8 | 9 | int main() { 10 | ll n; 11 | cin >> n; 12 | 13 | if(n == 1) { 14 | cout << "no" << endl; 15 | return 0; 16 | } 17 | 18 | vector factors; 19 | while(n % 2 == 0) { 20 | factors.push_back(2); 21 | n >>= 1; 22 | } 23 | for(ll i = 3; i <= sqrt(n) + 1; i += 2) { 24 | while(n % i == 0) { 25 | factors.push_back(i); 26 | n /= i; 27 | } 28 | } 29 | if(n != 1) { 30 | factors.push_back(n); 31 | } 32 | 33 | for(int i = 1; i < factors.size(); i++) { 34 | if(factors[i-1] != factors[i]) { 35 | cout << "no" << endl; 36 | return 0; 37 | } 38 | } 39 | cout << "yes" << endl; 40 | } 41 | -------------------------------------------------------------------------------- /onechicken.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int a, b; 7 | cin >> a >> b; 8 | 9 | b -= a; 10 | 11 | if(b == 1) { 12 | cout << "Dr. Chaz will have 1 piece of chicken left over!" << endl; 13 | } 14 | else if(b == -1) { 15 | cout << "Dr. Chaz needs 1 more piece of chicken!" << endl; 16 | } 17 | else if(b < 0) { 18 | cout << "Dr. Chaz needs " << -b << " more pieces of chicken!" << endl; 19 | } 20 | else { 21 | cout << "Dr. Chaz will have " << b << " pieces of chicken left over!" << endl; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /ornaments.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | double r, h, s; 8 | while(cin >> r >> h >> s && !(s == 0 && h == 0 && r == 0)) { 9 | double total = 0; 10 | 11 | // Calculate the straight edges 12 | double x = sqrt(pow(h, 2) - pow(r, 2)); 13 | total += 2 * x; 14 | 15 | // Calculate the round bottom 16 | double angle = 360 - 2 * acos(r/h) * (180 / M_PI); 17 | total += 2 * M_PI * (angle/360) * r; 18 | 19 | // Add the string to tie 20 | total += total * (s / 100); 21 | 22 | cout << fixed; 23 | cout.precision(2); 24 | cout << total << endl; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /ostgotska.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | string s; 7 | int total = 0; 8 | int count = 0; 9 | while(cin >> s) { 10 | total++; 11 | for(int i = 0; i < s.size()-1; i++) { 12 | if(s[i] == 'a' && s[i+1] == 'e') { 13 | count++; 14 | break; 15 | } 16 | } 17 | } 18 | 19 | if(total == 0 || double(count) / double(total) >= .4) { 20 | cout << "dae ae ju traeligt va" << endl; 21 | } 22 | else { 23 | cout << "haer talar vi rikssvenska" << endl; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /owlandfox.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | int n; 8 | cin >> n; 9 | 10 | string temp; 11 | while(cin >> temp) { 12 | int i = temp.size()-1; 13 | while(temp[i] == '0') { 14 | i--; 15 | } 16 | temp[i]--; 17 | cout << stoi(temp) << endl; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /parallelanalysis.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | void solve() { 6 | int n; 7 | cin >> n; 8 | 9 | int best = 0; 10 | unordered_map m; 11 | for(int i = 0; i < n; i++) { 12 | int t; 13 | cin >> t; 14 | int besthere = 0; 15 | int v; 16 | for(int j = 0; j < t-1; j++) { 17 | cin >> v; 18 | besthere = max(besthere, m[v]); 19 | } 20 | cin >> v; 21 | besthere++; 22 | m[v] = besthere; 23 | best = max(best, besthere); 24 | } 25 | 26 | cout << best << endl; 27 | } 28 | 29 | int main() { 30 | ios::sync_with_stdio(false); 31 | cin.tie(NULL); cout.tie(NULL); 32 | 33 | int cases; 34 | cin >> cases; 35 | for(int i = 1; i <= cases; i++) { 36 | cout << i << " "; 37 | solve(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /parking.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int a, b, c; 7 | cin >> a >> b >> c; 8 | 9 | int a1, a2, a3; 10 | int d1, d2, d3; 11 | 12 | cin >> a1 >> d1; 13 | cin >> a2 >> d2; 14 | cin >> a3 >> d3; 15 | 16 | int cost = 0; 17 | for(int i = 1; i <= 100; i++) { 18 | int parked = 0; 19 | 20 | if(a1 <= i && i < d1) { 21 | parked++; 22 | } 23 | if(a2 <= i && i < d2) { 24 | parked++; 25 | } 26 | if(a3 <= i && i < d3) { 27 | parked++; 28 | } 29 | 30 | if(parked == 1) { 31 | cost += a; 32 | } 33 | if(parked == 2) { 34 | cost += 2*b; 35 | } 36 | if(parked == 3) { 37 | cost += 3*c; 38 | } 39 | 40 | } 41 | 42 | cout << cost << endl; 43 | } 44 | -------------------------------------------------------------------------------- /parking2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | int n; 8 | cin >> n; 9 | for(int i = 0; i < n; i++) { 10 | int stops; 11 | cin >> stops; 12 | 13 | int s, l, temp; 14 | cin >> temp; 15 | s = temp; 16 | l = temp; 17 | 18 | for(int i = 0; i < stops - 1; i++) { 19 | cin >> temp; 20 | s = min(s, temp); 21 | l = max(l, temp); 22 | } 23 | 24 | cout << (l - s) * 2 << endl; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /pascal.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | typedef long long ll; 7 | 8 | int main() { 9 | int n; 10 | cin >> n; 11 | 12 | if(n == 1) { 13 | cout << "0" << endl; 14 | return 0; 15 | } 16 | 17 | for(int i = 2; i < sqrt(n) + 1; i++) { 18 | if(n % i == 0) { 19 | cout << n - (n/i) << endl; 20 | return 0; 21 | } 22 | } 23 | 24 | cout << n-1 << endl; 25 | } 26 | -------------------------------------------------------------------------------- /password.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() { 9 | int passwords; 10 | cin >> passwords; 11 | 12 | vector probabilities; 13 | 14 | for(int i = 0; i < passwords; i++) { 15 | string garbage; 16 | double prob; 17 | cin >> garbage >> prob; 18 | probabilities.push_back(prob); 19 | } 20 | 21 | sort(probabilities.rbegin(), probabilities.rend()); 22 | 23 | double total = 0; 24 | for(int i = 1; i <= passwords; i++) { 25 | total += probabilities[i-1] * i; 26 | } 27 | 28 | cout << fixed; 29 | cout.precision(5); 30 | 31 | cout << total << endl; 32 | } 33 | -------------------------------------------------------------------------------- /patuljci.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | vector v; 8 | int sum = 0; 9 | 10 | for(int i = 0; i < 9; i++) { 11 | int temp; 12 | cin >> temp; 13 | 14 | sum += temp; 15 | v.push_back(temp); 16 | } 17 | 18 | for(int i = 0; i < 9; i++) { 19 | for(int j = 0; j < 9; j++) { 20 | if(i != j && sum - v[i] - v[j] == 100) { 21 | for(auto n : v) { 22 | if(n != v[i] && n != v[j]) { 23 | cout << n << endl; 24 | } 25 | } 26 | return 0; 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /pauleigon.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n, a, b; 7 | cin >> n >> a >> b; 8 | 9 | a += b; 10 | 11 | if((a / n) % 2 == 0) { 12 | cout << "paul" << endl; 13 | return 0; 14 | } 15 | 16 | cout << "opponent" << endl; 17 | } 18 | -------------------------------------------------------------------------------- /peragrams.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | string s; 9 | cin >> s; 10 | 11 | vector v; 12 | v.resize(26, 0); 13 | 14 | for(auto c : s) { 15 | v[c-'a']++; 16 | } 17 | 18 | int odds = 0; 19 | 20 | for(auto i : v) { 21 | if(i % 2 == 1) { 22 | odds++; 23 | } 24 | } 25 | 26 | int result = odds - 1; 27 | 28 | if(result < 0) { 29 | result = 0; 30 | } 31 | 32 | cout << result << endl; 33 | } 34 | -------------------------------------------------------------------------------- /periodicstrings.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | typedef long long ll; 4 | 5 | 6 | string s; 7 | 8 | bool periodic(int k) { 9 | if(s.size()%k != 0) return false; 10 | vector arr; 11 | for(int i = 0; i < s.size(); i += k) { 12 | arr.push_back(s.substr(i,k)); 13 | } 14 | for(int i = 1; i < arr.size(); ++i) { 15 | string prev = arr[i-1]; 16 | prev = prev.back() + prev; 17 | prev.pop_back(); 18 | if(arr[i] != prev) return false; 19 | } 20 | return true; 21 | } 22 | 23 | int main() { 24 | cin >> s; 25 | for(int k = 1; k <= s.size(); ++k) { 26 | if(periodic(k)) { 27 | cout << k << '\n'; 28 | return 0; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /permutationencryption.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() { 9 | int n; 10 | while(cin >> n && n != 0) { 11 | vector permuted; 12 | for(int i = 0; i < n; i++) { 13 | int temp; 14 | cin >> temp; 15 | permuted.push_back(temp); 16 | } 17 | 18 | string s; 19 | cin.ignore(); 20 | getline(cin, s); 21 | 22 | while(s.size() % n != 0) { 23 | s.push_back(' '); 24 | } 25 | 26 | int segments = s.size() / n; 27 | 28 | string encrypt = ""; 29 | for(int i = 0; i < segments; i++) { 30 | for(auto j : permuted) { 31 | encrypt += s[i*n+j-1]; 32 | } 33 | } 34 | 35 | cout << '\'' << encrypt << '\'' << endl; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /persistent.py: -------------------------------------------------------------------------------- 1 | import fileinput 2 | 3 | for line in fileinput.input(): 4 | if line == "-1\n": 5 | continue 6 | 7 | line = int(line) 8 | if line < 10: 9 | print(line + 10) 10 | else: 11 | factors = [] 12 | works = True 13 | while line >= 10: 14 | divided = False 15 | for i in range(9, 2, -1): 16 | if line % i == 0: 17 | divided = True 18 | line //= i 19 | factors.append(i) 20 | break 21 | 22 | if not divided: 23 | works = False 24 | break 25 | 26 | factors.append(line) 27 | 28 | if works: 29 | factors.sort() 30 | for i in factors: 31 | print(i, end='') 32 | print() 33 | else: 34 | print("There is no such number.") 35 | -------------------------------------------------------------------------------- /pervasiveheartmonitor.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | def main(): 4 | for line in sys.stdin: 5 | name = "" 6 | numbers = [] 7 | for item in line.split(): 8 | try: 9 | float(item) 10 | except: 11 | name += item + " " 12 | else: 13 | numbers.append(float(item)) 14 | 15 | total = 0 16 | 17 | for num in numbers: 18 | total += num 19 | 20 | avg = total / len(numbers), 21 | print '%.6f' % avg, 22 | print name 23 | 24 | if __name__ == "__main__": 25 | main() 26 | -------------------------------------------------------------------------------- /pet.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int scores[5][4]; 7 | 8 | for(int i = 0; i < 5; i++) { 9 | for(int j = 0; j < 4; j++) { 10 | cin >> scores[i][j]; 11 | } 12 | } 13 | 14 | for(int i = 0; i < 5; i++) { 15 | for(int j = 1; j < 4; j++) { 16 | scores[i][0] += scores[i][j]; 17 | } 18 | } 19 | 20 | 21 | int max = -1; 22 | int loc = -1; 23 | for(int i = 0; i < 5; i++) { 24 | if(scores[i][0] > max) { 25 | max = scores[i][0]; 26 | loc = i; 27 | } 28 | } 29 | cout << loc+1 << " " << max << endl; 30 | } 31 | -------------------------------------------------------------------------------- /phonelist.cpp: -------------------------------------------------------------------------------- 1 | 2 2 | 3 3 | 911 4 | 97625999 5 | 91125426 6 | 5 7 | 113 8 | 12340 9 | 123440 10 | 12345 11 | 98346 12 | -------------------------------------------------------------------------------- /pieceofcake2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | typedef long long ll; 5 | 6 | int main() { 7 | ll n, v, h; 8 | cin >> n >> v >> h; 9 | 10 | cout << max(v,n-v)*max(h,n-h)*4 << endl; 11 | } 12 | -------------------------------------------------------------------------------- /piglatin.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | bool isVowel(char c) { 7 | return (c=='a' || c=='e' || c=='i' || c=='o' || c=='u' || c=='y'); 8 | } 9 | 10 | string piglatin(string s) { 11 | if(isVowel(s[0])) { 12 | s += "yay"; 13 | return s; 14 | } 15 | 16 | string temp; 17 | int i = 0; 18 | while(!isVowel(s[i])) { 19 | temp += s[i]; 20 | i++; 21 | } 22 | 23 | s.erase(0, i); 24 | s += temp; 25 | s += "ay"; 26 | 27 | return s; 28 | } 29 | 30 | int main() { 31 | string s; 32 | 33 | while(cin >> s) { 34 | 35 | cout << piglatin(s) << " "; 36 | 37 | if(cin.peek() == '\n') { 38 | cout << endl; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /pizza2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int C, R; 7 | cin >> R >> C; 8 | C = R - C; 9 | 10 | long double out = R * R; 11 | long double in = C * C; 12 | 13 | cout.precision(10); 14 | cout << in / out * 100.0 << endl; 15 | } 16 | -------------------------------------------------------------------------------- /planina.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n; 7 | cin >> n; 8 | 9 | long long num = 2; 10 | 11 | while(n > 0) { 12 | num *= 2; 13 | num--; 14 | 15 | n--; 16 | } 17 | 18 | cout << num * num << endl; 19 | } 20 | -------------------------------------------------------------------------------- /plantingtrees.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int trees; 7 | cin >> trees; 8 | vector t; 9 | t.resize(trees+1); 10 | for(int i = 0; i < trees; i++) { 11 | int temp; 12 | cin >> temp; 13 | t[i] = temp; 14 | } 15 | 16 | sort(t.rbegin(), t.rend()); 17 | 18 | int partayTime = 0; 19 | for(int i = 0; i < trees; i++) { 20 | if(t[i] + i > partayTime) { 21 | partayTime = t[i] + i; 22 | } 23 | } 24 | 25 | cout << partayTime + 2 << endl; 26 | } 27 | -------------------------------------------------------------------------------- /plowking.py: -------------------------------------------------------------------------------- 1 | n, m = map(int, input().split()) 2 | 3 | ans = 0 4 | currNode = 2 5 | currWeight = 1 6 | 7 | while currNode <= n: 8 | ans += currWeight 9 | currWeight = currWeight+1 10 | m = m-1 11 | edgesWasted = max(0, currNode-2) 12 | edgesNeeded = n-currNode 13 | edgesWasted = min(edgesWasted, m-edgesNeeded) 14 | m -= edgesWasted 15 | currWeight += edgesWasted 16 | currNode = currNode+1 17 | 18 | print(ans) 19 | 20 | 21 | -------------------------------------------------------------------------------- /pokerhand.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | map m; 7 | string s; 8 | while(cin >> s) { 9 | m[s[0]]++; 10 | } 11 | 12 | int best = 0; 13 | for(auto i : m) { 14 | best = max(best, i.second); 15 | } 16 | 17 | cout << best << endl; 18 | } 19 | -------------------------------------------------------------------------------- /pot.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | int times; 9 | cin >> times; 10 | 11 | long long total = 0; 12 | for(int i = 0; i < times; i++) { 13 | long long temp; 14 | cin >> temp; 15 | long long num, exp; 16 | num = temp / 10; 17 | exp = temp % 10; 18 | temp = pow(num, exp); 19 | total += temp; 20 | } 21 | cout << total << endl; 22 | } 23 | -------------------------------------------------------------------------------- /primaryarithmetic.py: -------------------------------------------------------------------------------- 1 | import fileinput 2 | 3 | def main(): 4 | for line in fileinput.input(): 5 | a, b = line.split() 6 | if a == '0' and b == '0': 7 | break 8 | a = a.zfill(10) 9 | b = b.zfill(10) 10 | 11 | a = a[::-1] 12 | b = b[::-1] 13 | 14 | carries = 0 15 | carry = 0 16 | for i in range(10): 17 | if int(a[i]) + int(b[i]) + carry > 9: 18 | carries += 1 19 | carry = 1 20 | else: 21 | carry = 0 22 | 23 | if carries == 0: 24 | print("No carry operation.") 25 | if carries == 1: 26 | print("1 carry operation.") 27 | if carries > 1: 28 | print(carries, "carry operations.") 29 | 30 | 31 | if __name__ == "__main__": 32 | main() 33 | -------------------------------------------------------------------------------- /pripreme.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | typedef long long ll; 7 | 8 | int main() { 9 | int n; 10 | cin >> n; 11 | 12 | ll m=0, t=0; 13 | while(n--) { 14 | ll temp; 15 | cin >> temp; 16 | m = max(temp, m); 17 | t += temp; 18 | } 19 | 20 | cout << max(t, m*2) << endl; 21 | } 22 | -------------------------------------------------------------------------------- /provincesandgold.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n1, n2, n3; 7 | cin >> n1 >> n2 >> n3; 8 | 9 | int t = 3*n1 + 2*n2 + 1*n3; 10 | 11 | vector ans; 12 | 13 | if(t >= 8) { 14 | ans.push_back("Province"); 15 | } 16 | else if(t >= 5) { 17 | ans.push_back("Duchy"); 18 | } 19 | else if(t >= 2) { 20 | ans.push_back("Estate"); 21 | } 22 | 23 | if(t >= 6) { 24 | ans.push_back("Gold"); 25 | } 26 | else if(t >= 3) { 27 | ans.push_back("Silver"); 28 | } 29 | else if(t >= 0) { 30 | ans.push_back("Copper"); 31 | } 32 | 33 | if(ans.size() == 1) { 34 | cout << ans[0] << endl; 35 | } 36 | else { 37 | cout << ans[0] << " or " << ans[1] << endl; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /prsteni.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | void reduce(int& l, int& r) { 7 | for(int i = 2; i <= l && i <= r; i++) { 8 | if(l % i == 0 && r % i == 0) { 9 | l /= i; 10 | r /= i; 11 | 12 | // Set i to 1, it will be incremented to 2 13 | i = 1; 14 | } 15 | } 16 | } 17 | 18 | int main() { 19 | int n; 20 | cin >> n; 21 | n--; 22 | 23 | int big; 24 | cin >> big; 25 | 26 | for(int i = 0; i < n; i++) { 27 | int temp; 28 | cin >> temp; 29 | 30 | int copy = big; 31 | 32 | reduce(copy, temp); 33 | 34 | cout << copy << "/" << temp << endl; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /putovanje.py: -------------------------------------------------------------------------------- 1 | def main(): 2 | x, y = raw_input().split() 3 | x = int(x) 4 | y = int(y) 5 | 6 | inputs = raw_input().split() 7 | inputs = [int(j) for j in inputs] 8 | 9 | foods = [0] 10 | for i in range(len(inputs)): 11 | foods.append(foods[i] + inputs[i]) 12 | 13 | total = 0 14 | for i in range(1, len(foods)): 15 | for j in range(i, len(foods)): 16 | if foods[j] - foods[i-1] <= y and j - i + 1 > total: 17 | total = j - i + 1 18 | 19 | print total 20 | 21 | if __name__ == "__main__": 22 | main() 23 | -------------------------------------------------------------------------------- /qaly.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | typedef long double ld; 5 | 6 | int main() { 7 | int n; 8 | cin >> n; 9 | 10 | ld ans = 0; 11 | for(int i = 0; i < n; i++) { 12 | ld l, r; 13 | cin >> l >> r; 14 | ans += l*r; 15 | } 16 | 17 | cout << fixed; 18 | cout.precision(4); 19 | cout << ans << endl; 20 | } 21 | -------------------------------------------------------------------------------- /quadrant.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int x, y; 7 | cin >> x >> y; 8 | 9 | if(x > 0 && y > 0) { 10 | cout << 1 << endl; 11 | } 12 | if(x < 0 && y > 0) { 13 | cout << 2 << endl; 14 | } 15 | if(x > 0 && y < 0) { 16 | cout << 4 << endl; 17 | } 18 | if(x < 0 && y < 0) { 19 | cout << 3 << endl; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /queens.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | int size; 8 | cin >> size; 9 | 10 | int diagonal = size * 2 - 1; 11 | 12 | vector a; 13 | vector b; 14 | vector c; 15 | vector d; 16 | 17 | a.resize(diagonal, false); 18 | b.resize(diagonal, false); 19 | c.resize(size, false); 20 | d.resize(size, false); 21 | 22 | 23 | int x, y; 24 | for(int i = 0; i < size; i++) { 25 | cin >> x >> y; 26 | if(a[y-x+size-1] || b[x+y] || c[x] || d[y]) { 27 | cout << "INCORRECT" << endl; 28 | return 0; 29 | } 30 | a[y - x + size-1] = true; 31 | b[x + y] = true; 32 | c[x] = true; 33 | d[y] = true; 34 | } 35 | 36 | cout << "CORRECT" << endl; 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /quickestimate.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | int n; 8 | cin >> n; 9 | for(int i = 0; i < n; i++) { 10 | string num; 11 | cin >> num; 12 | cout << num.length() << endl; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /quiteaproblem.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | string s; 8 | 9 | while(getline(cin, s)) { 10 | for(auto& x : s) { 11 | x = tolower(x); 12 | } 13 | if(s.find("problem") != string::npos) { 14 | cout << "yes" << endl; 15 | } 16 | else { 17 | cout << "no" << endl; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /r2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int r1, r2; 7 | cin >> r1 >> r2; 8 | cout << r2 + (r2-r1) << endl; 9 | } 10 | -------------------------------------------------------------------------------- /raggedright.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() { 9 | vector v; 10 | string s; 11 | 12 | int m = 0; 13 | while(getline(cin,s)) { 14 | int temp = s.length(); 15 | m = max(temp, m); 16 | v.push_back(temp); 17 | } 18 | 19 | int total = 0; 20 | for(int i = 0; i < v.size() - 1; i++) { 21 | total += pow(abs(m-v[i]), 2); 22 | } 23 | 24 | cout << total << endl; 25 | } 26 | -------------------------------------------------------------------------------- /railroad2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int a, b; 7 | cin >> a >> b; 8 | 9 | if(b % 2 == 0) { 10 | cout << "possible" << endl; 11 | } 12 | else { 13 | cout << "impossible" << endl; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /rationalsequence2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int solve(int l, int r) { 6 | if(l == r) { 7 | return 1; 8 | } 9 | 10 | if(l > r) { 11 | return 2 * solve(l-r, r) + 1; 12 | } 13 | 14 | if(l < r) { 15 | return 2 * solve(l, r-l); 16 | } 17 | } 18 | 19 | int main() { 20 | int n; 21 | cin >> n; 22 | 23 | for(int i = 0; i < n; i++) { 24 | int temp; 25 | cin >> temp; 26 | cout << temp << " "; 27 | 28 | int l, r; 29 | cin >> l; 30 | cin.ignore(); 31 | cin >> r; 32 | 33 | cout << solve(l, r) << endl; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /reachableroads.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int find(vector& d, int a) { 6 | if(d[a] == -1) return a; 7 | return d[a] = find(d, d[a]); 8 | } 9 | 10 | void join(vector& d, int a, int b) { 11 | a = find(d, a); 12 | b = find(d, b); 13 | if(a == b) return; 14 | d[a] = b; 15 | } 16 | 17 | void solve() { 18 | int n, m; 19 | cin >> n >> m; 20 | vector d(n,-1); 21 | for(int i = 0; i < m; i++) { 22 | int n1, n2; 23 | cin >> n1 >> n2; 24 | join(d,n1,n2); 25 | } 26 | 27 | int cc = 0; 28 | for(int i = 0; i < n; i++) { 29 | if(d[i] == -1) cc++; 30 | } 31 | 32 | cout << cc-1 << endl; 33 | } 34 | 35 | int main() { 36 | int cases; 37 | cin >> cases; 38 | while(cases--) { 39 | solve(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /redrover.py: -------------------------------------------------------------------------------- 1 | s = input() 2 | 3 | best = len(s) 4 | for i in range(len(s)): 5 | for j in range(i+1, len(s)): 6 | temp = s[i:j] 7 | replaced = s.replace(temp, "M") 8 | best = min(best, len(replaced) + len(temp)) 9 | 10 | print((best)) 11 | -------------------------------------------------------------------------------- /relocation.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | typedef long long ll; 5 | 6 | int main() { 7 | ios::sync_with_stdio(false); 8 | cin.tie(NULL); cout.tie(NULL); 9 | 10 | ll n, m; 11 | cin >> n >> m; 12 | 13 | vector v(n+1); 14 | for(ll i = 1; i <= n; i++) { 15 | cin >> v[i]; 16 | } 17 | 18 | for(ll i = 0; i < m; i++) { 19 | ll t, a, b; 20 | cin >> t >> a >> b; 21 | if(t == 1) { 22 | v[a] = b; 23 | } 24 | else { 25 | cout << abs(v[a]-v[b]) << endl; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /reversebinary.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | unsigned long long a = 0, b = 0; 7 | cin >> a; 8 | while(a != 0) { 9 | b <<= 1; 10 | if(a % 2 == 1) { 11 | b++; 12 | } 13 | a >>= 1; 14 | } 15 | cout << b << endl; 16 | } 17 | -------------------------------------------------------------------------------- /reverserot.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | void rotate(char& c) { 8 | c++; 9 | if(c == 'Z' + 1) { 10 | c = '_'; 11 | } 12 | if(c == '_' + 1) { 13 | c = '.'; 14 | } 15 | if(c == '.' + 1) { 16 | c = 'A'; 17 | } 18 | } 19 | 20 | int main() { 21 | int rotation; 22 | string s; 23 | 24 | while(cin >> rotation && cin >> s) { 25 | reverse(s.begin(), s.end()); 26 | for(int j = 0; j < s.length(); j++) { 27 | for(int i = 0; i < rotation; i++) { 28 | rotate(s[j]); 29 | } 30 | } 31 | cout << s << endl; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /rijeci.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | 7 | int main() { 8 | int n; 9 | cin >> n; 10 | 11 | int a = 1, b = 0; 12 | 13 | for(int i = 0; i < n; i++) { 14 | int tempa, tempb; 15 | tempa = b; 16 | tempb = a + b; 17 | a = tempa; 18 | b = tempb; 19 | } 20 | cout << a << " " << b << endl; 21 | } 22 | -------------------------------------------------------------------------------- /romans.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | typedef long double ld; 5 | typedef long long ll; 6 | 7 | int main() { 8 | ld d; 9 | cin >> d; 10 | 11 | d *= 1000 * 5280; 12 | d /= 4854; 13 | 14 | d += .50001; 15 | 16 | cout << ll(d) << endl; 17 | } 18 | -------------------------------------------------------------------------------- /runlengthencodingrun.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | void decode(string s) { 6 | for(int i = 0; i < s.size(); i += 2) { 7 | for(int j = 0; j < s[i+1]-'0'; j++) { 8 | cout << s[i]; 9 | } 10 | } 11 | cout << endl; 12 | } 13 | 14 | void encode(string s) { 15 | char prev = s[0]; 16 | int ct = 1; 17 | for(int i = 1; i < s.size(); i++) { 18 | if(s[i] != prev) { 19 | cout << prev << ct; 20 | ct = 1; 21 | prev = s[i]; 22 | } 23 | else { 24 | ct++; 25 | } 26 | } 27 | cout << prev << ct; 28 | cout << endl; 29 | } 30 | 31 | int main() { 32 | char c; 33 | cin >> c; 34 | string s; 35 | cin >> s; 36 | 37 | if(c == 'E') { 38 | encode(s); 39 | } 40 | else { 41 | decode(s); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /safehouses.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int dist(pair p1, pair p2) { 6 | return abs(p1.first-p2.first) + 7 | abs(p1.second-p2.second); 8 | } 9 | 10 | int main() { 11 | int n; 12 | cin >> n; 13 | 14 | vector> s; 15 | vector> h; 16 | 17 | for(int i = 0; i < n; i++) { 18 | for(int j = 0; j < n; j++) { 19 | char c; 20 | cin >> c; 21 | 22 | if(c == 'S') s.push_back({i,j}); 23 | if(c == 'H') h.push_back({i,j}); 24 | } 25 | } 26 | 27 | int ans = 0; 28 | for(int i = 0; i < s.size(); i++) { 29 | int d = 100000; 30 | for(int j = 0; j < h.size(); j++) { 31 | d = min(d,dist(s[i],h[j])); 32 | } 33 | ans = max(ans,d); 34 | } 35 | 36 | cout << ans << endl; 37 | } 38 | -------------------------------------------------------------------------------- /savez.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | struct trie { 6 | int ends = 0; 7 | map, trie> m; 8 | }; 9 | 10 | int insert(string& s, trie& t, int pos, int val) { 11 | if(pos == s.size()) { 12 | t.ends = max(t.ends + 1, val + 1); 13 | return t.ends; 14 | } 15 | 16 | char c1 = s[pos]; 17 | char c2 = s[s.size()-pos-1]; 18 | 19 | t.ends = max(t.ends, val); 20 | return insert(s, t.m[{c1,c2}], pos+1, t.ends); 21 | } 22 | 23 | int main() { 24 | ios::sync_with_stdio(false); 25 | cin.tie(NULL); cout.tie(NULL); 26 | 27 | int n; 28 | cin >> n; 29 | 30 | trie t; 31 | int best = 0; 32 | for(int i = 0; i < n; i++) { 33 | string s; 34 | cin >> s; 35 | 36 | best = max(best, insert(s,t,0,0)); 37 | } 38 | 39 | cout << best << endl; 40 | } 41 | -------------------------------------------------------------------------------- /savingdaylight.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | string month, day, year; 8 | int hour1, minute1, hour2, minute2; 9 | while(cin >> month && cin >> day && cin >> year) { 10 | cin >> hour1; 11 | cin.ignore(); 12 | cin >> minute1; 13 | 14 | cin >> hour2; 15 | cin.ignore(); 16 | cin >> minute2; 17 | 18 | cout << month << " " << day << " " << year << " "; 19 | 20 | int hours = hour2 - hour1; 21 | int minutes = minute2 - minute1; 22 | 23 | if(minutes < 0) { 24 | minutes += 60; 25 | hours--; 26 | } 27 | 28 | cout << hours << " hours " << minutes << " minutes" << endl; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /savingforretirement.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | int b, br, bs, a, as; 8 | cin >> b >> br >> bs >> a >> as; 9 | 10 | int bobMoney = (br - b) * bs; 11 | int aliceYears = ceil(double(bobMoney)/double(as)); 12 | 13 | if(bobMoney == aliceYears * as) { 14 | aliceYears++; 15 | } 16 | 17 | cout << aliceYears + a << endl; 18 | } 19 | -------------------------------------------------------------------------------- /sequence.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | int n; 9 | cin >> n; 10 | 11 | vector v; 12 | v.push_back(1); 13 | 14 | while(v.back() < n) { 15 | v.push_back(v.back()*2); 16 | } 17 | 18 | while(v.back() > n) { 19 | v.pop_back(); 20 | } 21 | 22 | cout << v.size() << endl; 23 | for(int i = 0; i < v.size(); i++) { 24 | cout << v[i] << " "; 25 | } 26 | cout << endl; 27 | } 28 | -------------------------------------------------------------------------------- /server.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n, time; 7 | cin >> n >> time; 8 | 9 | int i; 10 | int total = 0; 11 | for(i = 0; i < n; i++) { 12 | int temp; 13 | cin >> temp; 14 | total += temp; 15 | if(total > time) { 16 | break; 17 | } 18 | } 19 | 20 | cout << i << endl; 21 | } 22 | -------------------------------------------------------------------------------- /sevenwonders.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | string s; 8 | cin >> s; 9 | 10 | 11 | int t = 0, c = 0, g = 0; 12 | for(auto a : s) { 13 | if(a == 'C') { 14 | c++; 15 | } 16 | if(a == 'T') { 17 | t++; 18 | } 19 | if(a == 'G') { 20 | g++; 21 | } 22 | } 23 | 24 | int sum = min(min(t, c), g) * 7; 25 | sum += (t*t)+(c*c)+(g*g); 26 | 27 | cout << sum << endl; 28 | } 29 | -------------------------------------------------------------------------------- /sheldon.py: -------------------------------------------------------------------------------- 1 | n, m = raw_input().split() 2 | n = int(n) 3 | m = int(m) 4 | 5 | nums = set() 6 | 7 | for a in range(1,64): 8 | for b in range(0,64): 9 | for c in range(1,64): 10 | s = '1' * a + '0' * b 11 | s1 = s * c 12 | s2 = s * c + '1' * a 13 | val1 = int(s1, 2) 14 | val2 = int(s2, 2) 15 | if(val1 >= 2**65): 16 | break 17 | nums.add(val1) 18 | if(val2 >= 2**65): 19 | break 20 | nums.add(val2) 21 | 22 | nums = sorted(list(nums)) 23 | 24 | count = 0 25 | for i in nums: 26 | if i >= n and i <= m: 27 | count += 1 28 | 29 | print(count) 30 | -------------------------------------------------------------------------------- /shiritori.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n; 7 | cin >> n; 8 | 9 | string c; 10 | cin >> c; 11 | 12 | set s; 13 | s.insert(c); 14 | 15 | for(int i = 0; i < n-1; i++) { 16 | string t; 17 | cin >> t; 18 | 19 | if(s.count(t)) { 20 | cout << "Player " << ((i+1)%2)+1 << " lost" << endl; 21 | return 0; 22 | } 23 | s.insert(t); 24 | if(c.back() != t.front()) { 25 | cout << "Player " << ((i+1)%2)+1 << " lost" << endl; 26 | return 0; 27 | } 28 | 29 | c = t; 30 | } 31 | 32 | cout << "Fair Game" << endl; 33 | } 34 | -------------------------------------------------------------------------------- /shopaholic.py: -------------------------------------------------------------------------------- 1 | def main(): 2 | n = int(raw_input()) 3 | arr = raw_input().split() 4 | arr = [int(x) for x in arr] 5 | 6 | arr.sort(reverse=True) 7 | 8 | total = 0 9 | 10 | for i in range(0, len(arr)): 11 | if i % 3 == 2: 12 | total += int(arr[i]) 13 | 14 | print total 15 | 16 | if __name__ == "__main__": 17 | main() 18 | -------------------------------------------------------------------------------- /sibice.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | int n; 8 | cin >> n; 9 | 10 | double x, y; 11 | cin >> x >> y; 12 | 13 | double length = sqrt((x*x)+(y*y)); 14 | 15 | for(int i = 0; i < n; i++) { 16 | int temp; 17 | cin >> temp; 18 | if(temp <= length) { 19 | cout << "DA" << endl; 20 | } 21 | else { 22 | cout << "NE" << endl; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /simon.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | int times; 8 | cin >> times; 9 | cin.ignore(); 10 | for(int i = 0; i < times; i++) { 11 | string s; 12 | getline(cin, s); 13 | if(s.find("simon says") == 0) { 14 | s.erase(0,11); 15 | cout << s << endl; 16 | } 17 | else { 18 | cout << endl; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /simonsays.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | int times; 8 | cin >> times; 9 | cin.ignore(); 10 | for(int i = 0; i < times; i++) { 11 | string s; 12 | getline(cin, s); 13 | if(s.find("Simon says") == 0) { 14 | s.erase(0,11); 15 | cout << s << endl; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /simplicity.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() { 9 | vector v; 10 | v.resize(26, 0); 11 | 12 | string s; 13 | cin >> s; 14 | 15 | for(auto c : s) { 16 | v[c-'a']++; 17 | } 18 | 19 | sort(v.rbegin(), v.rend()); 20 | 21 | cout << s.size() - (v[0] + v[1]) << endl; 22 | } 23 | -------------------------------------------------------------------------------- /sjecista.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n; 7 | cin >> n; 8 | 9 | int max = n-3; 10 | 11 | int total = 0; 12 | for(int i = 1; i <= max; i++) { 13 | for(int j = max - i + 1; j >= 1; j--) { 14 | total += j*i; 15 | } 16 | } 17 | 18 | cout << total << endl; 19 | } 20 | -------------------------------------------------------------------------------- /skener.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | int r, c, x, y; 8 | cin >> r >> c >> x >> y; 9 | 10 | vector> v; 11 | v.resize(r); 12 | for(auto &row : v) { 13 | row.resize(c); 14 | } 15 | 16 | for(int i = 0; i < r; i++) { 17 | for(int j = 0; j < c; j++) { 18 | cin >> v[i][j]; 19 | } 20 | } 21 | 22 | for(int i = 0; i < r * x; i++) { 23 | for(int j = 0; j < c * y; j++) { 24 | cout << v[i/x][j/y]; 25 | } 26 | cout << endl; 27 | } 28 | cout << endl; 29 | } 30 | -------------------------------------------------------------------------------- /skocimis.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int a, b, c; 7 | cin >> a >> b >> c; 8 | 9 | int ans = max(b-a, c-b); 10 | ans--; 11 | 12 | cout << ans << endl; 13 | } 14 | -------------------------------------------------------------------------------- /slatkisi.py: -------------------------------------------------------------------------------- 1 | import fileinput 2 | 3 | def main(): 4 | for line in fileinput.input(): 5 | cost, zeros = line.split() 6 | 7 | cost = int(cost) 8 | zeros = int(zeros) 9 | 10 | zeros = 10 ** zeros 11 | 12 | cost /= zeros 13 | cost = round(cost) 14 | cost *= zeros 15 | 16 | print(cost) 17 | 18 | if __name__ == "__main__": 19 | main() 20 | -------------------------------------------------------------------------------- /snappereasy.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | int n; 8 | cin >> n; 9 | 10 | for(int i = 0; i < n; i++) { 11 | cout << "Case #" << i+1 << ": "; 12 | 13 | int snappers; 14 | int snaps; 15 | cin >> snappers >> snaps; 16 | 17 | bool works = true; 18 | for(int j = 0; j < snappers; j++) { 19 | if(snaps % 2 == 0) { 20 | works = false; 21 | } 22 | snaps /= 2; 23 | } 24 | 25 | if(works) { 26 | cout << "ON" << endl; 27 | } 28 | else { 29 | cout << "OFF" << endl; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /snapperhard.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | int n; 8 | cin >> n; 9 | 10 | for(int i = 0; i < n; i++) { 11 | cout << "Case #" << i+1 << ": "; 12 | 13 | int snappers; 14 | int snaps; 15 | cin >> snappers >> snaps; 16 | 17 | bool works = true; 18 | for(int j = 0; j < snappers; j++) { 19 | if(snaps % 2 == 0) { 20 | works = false; 21 | } 22 | snaps /= 2; 23 | } 24 | 25 | if(works) { 26 | cout << "ON" << endl; 27 | } 28 | else { 29 | cout << "OFF" << endl; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /sodasurpler.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int a, b, cost; 7 | cin >> a >> b >> cost; 8 | 9 | int starting = a + b; 10 | int total = 0; 11 | 12 | while(starting >= cost) { 13 | int drank = starting / cost; 14 | int left = starting % cost; 15 | total += drank; 16 | starting = left + drank; 17 | } 18 | 19 | cout << total << endl; 20 | } 21 | -------------------------------------------------------------------------------- /softpasswords.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | typedef long long ll; 5 | 6 | int main() { 7 | string P, S; 8 | cin >> P >> S; 9 | swap(P,S); 10 | 11 | set alls; 12 | alls.insert(P); 13 | 14 | // Prepend 15 | for(int i = 0; i < 10; i++) { 16 | char c = '0' + i; 17 | string t = ""; 18 | t += c; 19 | t += P; 20 | alls.insert(t); 21 | } 22 | 23 | // Append 24 | for(int i = 0; i < 10; i++) { 25 | char c = '0' + i; 26 | string t = P; 27 | t.push_back(c); 28 | alls.insert(t); 29 | } 30 | 31 | // Switch case 32 | string g = P; 33 | for(auto& i : g) { 34 | if(islower(i)) i = toupper(i); 35 | else if(isupper(i)) i = tolower(i); 36 | } 37 | alls.insert(g); 38 | 39 | if(alls.count(S) > 0) cout << "Yes" << endl; 40 | else cout << "No" << endl; 41 | } 42 | -------------------------------------------------------------------------------- /sortofsorting.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | bool strless(const string& lhs, const string& rhs) { 9 | if(lhs[0] == rhs[0]) { 10 | return lhs[1] < rhs[1]; 11 | } 12 | else { 13 | return lhs[0] < rhs[0]; 14 | } 15 | } 16 | 17 | int main() { 18 | int n; 19 | while(cin >> n && n != 0) { 20 | vector v; 21 | 22 | for(int i = 0; i < n; i++) { 23 | string s; 24 | cin >> s; 25 | 26 | v.push_back(s); 27 | } 28 | 29 | stable_sort(v.begin(), v.end(), strless); 30 | 31 | for(auto s : v) { 32 | cout << s << endl; 33 | } 34 | 35 | cout << endl; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /soylent.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | int n; 8 | cin >> n; 9 | for(int i = 0; i < n; i++) { 10 | int num; 11 | cin >> num; 12 | cout << ceil(num / 400.0) << endl; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /spavanac.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int hour, min; 7 | cin >> hour >> min; 8 | 9 | hour--; 10 | min += 15; 11 | 12 | if(hour < 0) { 13 | hour += 24; 14 | } 15 | 16 | if(min >= 60) { 17 | min -= 60; 18 | hour++; 19 | } 20 | 21 | cout << hour << " " << min << endl; 22 | } 23 | -------------------------------------------------------------------------------- /speedlimit.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | int n; 8 | while(true) { 9 | cin >> n; 10 | if(n == -1) { 11 | return 0; 12 | } 13 | int prev = 0; 14 | int miles = 0; 15 | for(int i = 0; i < n; i++) { 16 | int speed, curr; 17 | cin >> speed >> curr; 18 | miles += speed * (curr - prev); 19 | prev = curr; 20 | } 21 | cout << miles << " miles" << endl; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /srednji.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | typedef long long ll; 5 | 6 | int main() { 7 | int n, med; 8 | cin >> n >> med; 9 | 10 | vector v(n); 11 | int pos; 12 | for(int i = 0; i < n; i++) { 13 | cin >> v[i]; 14 | if(v[i] == med) { 15 | pos = i; 16 | } 17 | } 18 | 19 | map m; 20 | m[0] = 1; 21 | int sum = 0; 22 | for(int i = pos+1; i < n; i++) { 23 | if(v[i] > med) sum++; 24 | else sum--; 25 | m[sum]++; 26 | } 27 | 28 | ll ans = m[0]; 29 | sum = 0; 30 | for(int i = pos-1; i >= 0; i--) { 31 | if(v[i] > med) sum++; 32 | else sum--; 33 | ans += m[-sum]; 34 | } 35 | 36 | cout << ans << endl; 37 | } 38 | -------------------------------------------------------------------------------- /standings.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | typedef long long ll; 10 | 11 | int main() { 12 | ll cases; 13 | cin >> cases; 14 | 15 | while(cases--) { 16 | ll n; 17 | cin >> n; 18 | vector v(n); 19 | 20 | for(auto& i : v) { 21 | string s; 22 | cin >> s >> i; 23 | } 24 | 25 | sort(v.begin(), v.end()); 26 | 27 | ll total = 0; 28 | for(ll i = 0; i < n; i++) { 29 | total += abs(v[i] - (i+1)); 30 | } 31 | 32 | cout << total << endl; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /stararrangements.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | bool solve(int n, int a, int b) { 6 | if(n % (a+b) == 0 || n % (a + b) == a) { 7 | return true; 8 | } 9 | return false; 10 | } 11 | 12 | int main() { 13 | int n; 14 | cin >> n; 15 | cout << n << ":" << endl; 16 | 17 | for(int i = 2; i <= (n+1)/2; i++) { 18 | for(int j = -1; j <= 0; j++) { 19 | if(solve(n, i, i+j)) { 20 | cout << i << "," << i+j << endl; 21 | } 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /statistics.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int i = 1; 7 | int n; 8 | 9 | while(cin >> n) { 10 | int min; 11 | int max; 12 | cin >> max; 13 | min = max; 14 | 15 | for(int j = 0; j < n-1; j++) { 16 | int temp; 17 | cin >> temp; 18 | if(temp < min) { 19 | min = temp; 20 | } 21 | if(temp > max) { 22 | max = temp; 23 | } 24 | } 25 | 26 | cout << "Case " << i << ": " << min << " " << max 27 | << " " << max-min << endl; 28 | i++; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /stickysituation.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | typedef unsigned long long ull; 6 | 7 | int main() { 8 | int sticks; 9 | cin >> sticks; 10 | vector s; 11 | for(int i = 0; i < sticks; i++) { 12 | ull temp; 13 | cin >> temp; 14 | s.push_back(temp); 15 | } 16 | 17 | sort(s.begin(), s.end()); 18 | 19 | for(int i = 0; i < sticks - 2; i++) { 20 | if(s[i]+s[i+1] > s[i+2]) { 21 | cout << "possible" << endl; 22 | return 0; 23 | } 24 | } 25 | 26 | cout << "impossible" << endl; 27 | } 28 | -------------------------------------------------------------------------------- /stockbroker.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | typedef long long ll; 5 | 6 | int main() { 7 | int n; 8 | cin >> n; 9 | 10 | ll prev; 11 | cin >> prev; 12 | 13 | ll money = 100; 14 | for(int i = 1; i < n; i++) { 15 | ll curr; 16 | cin >> curr; 17 | 18 | if(curr > prev) { 19 | money += min(money/prev, (ll)100000) * (curr - prev); 20 | } 21 | 22 | prev = curr; 23 | } 24 | 25 | cout << money << endl; 26 | } 27 | -------------------------------------------------------------------------------- /sumkindofproblem.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | 6 | int s1(int n) { 7 | int total = 0; 8 | for(int i = 0; i <= n; i++) { 9 | total += i; 10 | } 11 | return total; 12 | } 13 | 14 | int s2(int n) { 15 | int total = 0; 16 | for(int i = 1; i < 2*n; i+=2) { 17 | total += i; 18 | } 19 | return total; 20 | } 21 | 22 | int s3(int n) { 23 | int total = 0; 24 | for(int i = 0; i < 2*n+1; i+=2) { 25 | total += i; 26 | } 27 | return total; 28 | } 29 | 30 | int main() { 31 | int n; 32 | cin >> n; 33 | 34 | for(int i = 0; i < n; i++) { 35 | int temp; 36 | cin >> temp; 37 | cin >> temp; 38 | 39 | cout << i+1 << " " << s1(temp) << " " << s2(temp) << " " << s3(temp) << endl; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /sumoftheothers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() { 9 | string s; 10 | 11 | while(getline(cin, s)) { 12 | istringstream is(s); 13 | 14 | vector v; 15 | 16 | int sum = 0; 17 | 18 | int n; 19 | while(is >> n) { 20 | v.push_back(n); 21 | sum += n; 22 | } 23 | 24 | bool printed = false; 25 | for(auto i : v) { 26 | if(sum - 2*i == 0 && !printed) { 27 | cout << i << endl; 28 | printed = true; 29 | } 30 | } 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /sumsquareddigits.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | void solve() { 6 | int k, b, n; 7 | cin >> k >> b >> n; 8 | 9 | int ans = 0; 10 | while(n > 0) { 11 | ans += (n % b) * (n % b); 12 | n /= b; 13 | } 14 | 15 | cout << k << " " << ans << endl; 16 | } 17 | 18 | int main() { 19 | int cases; 20 | cin >> cases; 21 | while(cases--) { 22 | solve(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /swaptosort.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int find(vector& d, int a) { 6 | if(d[a] == -1) return a; 7 | return d[a] = find(d, d[a]); 8 | } 9 | 10 | void join(vector& d, int a, int b) { 11 | a = find(d, a); 12 | b = find(d, b); 13 | if(a == b) return; 14 | d[a] = b; 15 | } 16 | 17 | int main() { 18 | int n, m; 19 | cin >> n >> m; 20 | 21 | vector d(n,-1); 22 | for(int i = 0; i < m; i++) { 23 | int n1, n2; 24 | cin >> n1 >> n2; 25 | n1--; n2--; 26 | join(d,n1,n2); 27 | } 28 | 29 | bool works = true; 30 | for(int i = 0; i < n; i++) { 31 | if(find(d,i) != find(d,n-i-1)) works = false; 32 | } 33 | 34 | if(works) cout << "Yes" << endl; 35 | else cout << "No" << endl; 36 | } 37 | -------------------------------------------------------------------------------- /taisform.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | 6 | int main() { 7 | double total = 0; 8 | int n; 9 | cin >> n; 10 | vector> pairs(n); 11 | 12 | for(auto& i : pairs) { 13 | cin >> i.first >> i.second; 14 | } 15 | 16 | for(int i = 1; i < n; i++) { 17 | pair p1,p2; 18 | p1 = pairs[i-1]; 19 | p2 = pairs[i]; 20 | 21 | total += (p1.second+p2.second) * (p2.first - p1.first) / 2; 22 | } 23 | 24 | cout << fixed; 25 | cout.precision(10); 26 | 27 | cout << total / 1000 << endl; 28 | } 29 | -------------------------------------------------------------------------------- /tajna.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() { 9 | string s; 10 | cin >> s; 11 | 12 | int size = s.size(); 13 | int rows = sqrt(size); 14 | 15 | while(size % rows != 0) { 16 | rows--; 17 | } 18 | 19 | int cols = size / rows; 20 | swap(rows, cols); 21 | 22 | vector> v; 23 | v.resize(rows, vector(cols)); 24 | 25 | int n = 0; 26 | for(int i = 0; i < rows; i++) { 27 | for(int j = 0; j < cols; j++) { 28 | v[i][j] = s[n]; 29 | n++; 30 | } 31 | } 32 | 33 | for(int j = 0; j < cols; j++) { 34 | for(int i = 0; i < rows; i++) { 35 | cout << v[i][j]; 36 | } 37 | } 38 | cout << endl; 39 | } 40 | -------------------------------------------------------------------------------- /tarifa.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int megabytes = 0; 7 | int months = 0; 8 | 9 | cin >> megabytes >> months; 10 | 11 | int used = 0; 12 | for(int i = 0; i < months; i++) { 13 | int temp; 14 | cin >> temp; 15 | used += temp; 16 | } 17 | 18 | cout << megabytes * (months+1) - used << endl; 19 | } 20 | -------------------------------------------------------------------------------- /temperature.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | double a, b; 7 | cin >> a >> b; 8 | 9 | b--; 10 | 11 | if(b < .5) { 12 | if(a == 0) { 13 | cout << "ALL GOOD" << endl; 14 | } 15 | else { 16 | cout << "IMPOSSIBLE" << endl; 17 | } 18 | } 19 | 20 | else { 21 | cout << fixed; 22 | cout.precision(9); 23 | cout << - (a / b) << endl; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /tetration.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | double d; 8 | cin >> d; 9 | 10 | cout << fixed; 11 | cout.precision(6); 12 | 13 | cout << pow(d, (1/d)) << endl; 14 | } 15 | 16 | -------------------------------------------------------------------------------- /textureanalysis.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | string s; 8 | int i = 1; 9 | while(getline(cin, s) && s != "END") { 10 | cout << i << " "; 11 | i++; 12 | 13 | if(s.size() == 1) { 14 | cout << "EVEN" << endl; 15 | continue; 16 | } 17 | 18 | string pattern = "*"; 19 | s.erase(s.begin()); 20 | 21 | while(s[0] == '.') { 22 | pattern.push_back(s[0]); 23 | s.erase(s.begin()); 24 | } 25 | 26 | while(s.find(pattern) == 0) { 27 | s.erase(0, pattern.length()); 28 | } 29 | 30 | if(s.size() <= 1) { 31 | cout << "EVEN" << endl; 32 | } 33 | else { 34 | cout << "NOT EVEN" << endl; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /thanos.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | typedef long long ll; 5 | 6 | void solve() { 7 | ll a, b, c; 8 | cin >> a >> b >> c; 9 | ll ct = 0; 10 | while(a <= c) { 11 | a *= b; 12 | ct++; 13 | } 14 | cout << ct << endl; 15 | } 16 | 17 | int main() { 18 | ll cases; 19 | cin >> cases; 20 | while(cases--) { 21 | solve(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /thebackslashproblem.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | int n; 9 | while(cin >> n) { 10 | cin.ignore(); 11 | string s; 12 | getline(cin, s); 13 | 14 | string temp = ""; 15 | string backslashes; 16 | backslashes.resize(pow(2, n) - 1, '\\'); 17 | 18 | for(auto c : s) { 19 | if(('!' <= c && c <= '*') || ('[' <= c && c <= ']')) { 20 | temp += backslashes; 21 | } 22 | temp.push_back(c); 23 | } 24 | 25 | cout << temp << endl; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /threepowers.py: -------------------------------------------------------------------------------- 1 | def solve(n): 2 | v = [] 3 | 4 | curr = 1; 5 | while n > 0: 6 | if n % 2 == 1: 7 | v.append(curr) 8 | curr *= 3 9 | n //= 2 10 | 11 | print("{ ", end="") 12 | for i in range(len(v)): 13 | print(v[i], end="") 14 | if i != len(v)-1: 15 | print(",", end="") 16 | print(" ", end="") 17 | print("}") 18 | 19 | while True: 20 | n = int(input()) 21 | if n == 0: 22 | break 23 | solve(n-1) 24 | -------------------------------------------------------------------------------- /throwns.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | vector commands; 8 | int k, c; 9 | cin >> k >> c; 10 | 11 | for(int i = 0; i < c; i++) { 12 | cin.ignore(); 13 | if(cin.peek() == 'u') { 14 | string undo; 15 | cin >> undo; 16 | int drops; 17 | cin >> drops; 18 | for(int i = 0; i < drops; i++) { 19 | commands.pop_back(); 20 | } 21 | } 22 | else { 23 | int n; 24 | cin >> n; 25 | commands.push_back(n); 26 | } 27 | } 28 | 29 | int spot = 0; 30 | 31 | for(auto i : commands) { 32 | spot += i; 33 | spot %= k; 34 | while(spot < 0) { 35 | spot += k; 36 | } 37 | } 38 | 39 | cout << spot << endl; 40 | } 41 | -------------------------------------------------------------------------------- /timeloop.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int i; 7 | cin >> i; 8 | for(int j = 1; j <= i; j++) { 9 | cout << j << " Abracadabra" << endl; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /tiredterry.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n, p, d; 7 | cin >> n >> p >> d; 8 | 9 | string s; 10 | cin >> s; 11 | s += s; 12 | 13 | int tired = 0; 14 | int w = 0; 15 | int z = 0; 16 | for(int i = 0; i < s.size(); i++) { 17 | if(s[i] == 'W') w++; 18 | else z++; 19 | 20 | if(i - p >= 0) { 21 | if(s[i-p] == 'W') w--; 22 | else z--; 23 | } 24 | 25 | if(i >= n) { 26 | if(z < d) { 27 | tired++; 28 | } 29 | } 30 | } 31 | 32 | cout << tired << endl; 33 | } 34 | -------------------------------------------------------------------------------- /triangle.py: -------------------------------------------------------------------------------- 1 | import fileinput, math 2 | 3 | def div(hi, lo): 4 | #return hi//lo 5 | return (hi+lo-1)//lo 6 | 7 | casenum = 1 8 | for line in fileinput.input(): 9 | # length of 3**(n+1) / 2**n 10 | line = int(line) 11 | print("Case", str(casenum)+": ", end="") 12 | print(math.ceil(math.log10(div(3**(line+1), 2**line)))) 13 | casenum += 1 14 | -------------------------------------------------------------------------------- /trik.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | bool ball[3] = {true, false, false}; 8 | string moves; 9 | cin >> moves; 10 | for(int i = 0; i < moves.size(); i++) { 11 | if(moves[i] == 'A') { 12 | swap(ball[0], ball[1]); 13 | } 14 | if(moves[i] == 'B') { 15 | swap(ball[1], ball[2]); 16 | } 17 | if(moves[i] == 'C') { 18 | swap(ball[0], ball[2]); 19 | } 20 | } 21 | if(ball[0]) { 22 | cout << "1" << endl; 23 | } 24 | if(ball[1]) { 25 | cout << "2" << endl; 26 | } 27 | if(ball[2]) { 28 | cout << "3" << endl; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /trollhunt.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | int b, k, g; 8 | cin >> b >> k >> g; 9 | 10 | b--; 11 | int groups = k / g; 12 | int days = ceil(double(b) / groups); 13 | 14 | cout << days << endl; 15 | } 16 | -------------------------------------------------------------------------------- /tutorial.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | def main(): 4 | limit, n, operation = input().split() 5 | 6 | limit = int(limit) 7 | n = int(n) 8 | operation = int(operation) 9 | 10 | # ans stores if it's too long 11 | 12 | if operation == 1: 13 | if n > 15: 14 | ans = True 15 | else: 16 | ans = limit < math.factorial(n) 17 | 18 | if operation == 2: 19 | ans = limit < 2**n 20 | 21 | if operation == 3: 22 | ans = limit < n**4 23 | 24 | if operation == 4: 25 | ans = limit < n**3 26 | 27 | if operation == 5: 28 | ans = limit < n**2 29 | 30 | if operation == 6: 31 | ans = limit < n * math.log(n, 2) 32 | 33 | if operation == 7: 34 | ans = limit < n 35 | 36 | if ans: 37 | print("TLE") 38 | else: 39 | print("AC") 40 | 41 | 42 | if __name__ == "__main__": 43 | main() 44 | -------------------------------------------------------------------------------- /ummcode.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | typedef long long ll; 5 | 6 | int main() { 7 | string s; 8 | string t; 9 | while(cin >> s) { 10 | bool good = true; 11 | string a; 12 | for(auto i : s) { 13 | if(isalpha(i)) { 14 | a.push_back(i); 15 | } 16 | } 17 | s = a; 18 | for(auto i : s) { 19 | if(i != 'u' && i != 'm') { 20 | good = false; 21 | } 22 | } 23 | if(good) t += s; 24 | } 25 | 26 | vector v(t.size()/7,0); 27 | for(int i = 0; i < t.size(); i++) { 28 | if(t[i] == 'u') 29 | v[i/7] += pow(2,7-(i%7)-1); 30 | } 31 | 32 | for(auto i : v) { 33 | cout << char(i); 34 | } 35 | cout << endl; 36 | } 37 | -------------------------------------------------------------------------------- /vacuumba.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | double DtoR(double a) { 7 | return a * M_PI / 180; 8 | } 9 | 10 | double RtoD(double a) { 11 | return a / 180 * M_PI; 12 | } 13 | 14 | int main() { 15 | int n; 16 | cin >> n; 17 | 18 | for(int i = 0; i < n; i++) { 19 | int segments; 20 | cin >> segments; 21 | double x = 0, y = 0; 22 | double angle = 90; 23 | 24 | for(int j = 0; j < segments; j++) { 25 | double a, d; 26 | cin >> a >> d; 27 | 28 | angle += a; 29 | x += d * cos(DtoR(angle)); 30 | y += d * sin(DtoR(angle)); 31 | } 32 | 33 | cout << fixed; 34 | cout.precision(6); 35 | cout << x << " " << y << endl; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /veci.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | string s, t; 9 | cin >> s; 10 | t = s; 11 | 12 | next_permutation(t.begin(), t.end()); 13 | 14 | if(t <= s) { 15 | cout << "0" << endl; 16 | } 17 | else { 18 | cout << t << endl; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /virus.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | list l1, l2; 8 | 9 | // Take in Data 10 | char c; 11 | while(cin.get(c) && c != '\n') { 12 | l1.push_back(c); 13 | } 14 | while(cin.get(c) && c != '\n') { 15 | l2.push_back(c); 16 | } 17 | 18 | // Remove beginning items 19 | while(!l1.empty() && !l2.empty() && l1.front() == l2.front()) { 20 | l1.pop_front(); 21 | l2.pop_front(); 22 | } 23 | 24 | // Remove ending items 25 | while(!l1.empty() && !l2.empty() && l1.back() == l2.back()) { 26 | l1.pop_back(); 27 | l2.pop_back(); 28 | } 29 | 30 | // Print answer 31 | cout << l2.size() << endl; 32 | } 33 | -------------------------------------------------------------------------------- /volim.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int player; 7 | cin >> player; 8 | 9 | int time = 0; 10 | bool exploded = false; 11 | 12 | int n; 13 | cin >> n; 14 | 15 | do { 16 | int t; 17 | char c; 18 | 19 | cin >> t; 20 | cin >> c; 21 | 22 | time += t; 23 | 24 | if(time >= 210) { 25 | exploded = true; 26 | } 27 | else if(c == 'T') { 28 | player++; 29 | } 30 | } while(!exploded); 31 | 32 | player--; 33 | player %= 8; 34 | player++; 35 | cout << player << endl; 36 | } 37 | -------------------------------------------------------------------------------- /walrusweights.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | vector possible; 8 | possible.resize(2200, false); 9 | possible[0] = true; 10 | 11 | int n; 12 | cin >> n; 13 | for(int i = 0; i < n; i++) { 14 | int weight; 15 | cin >> weight; 16 | for(int j = possible.size()-weight-1; j >= 0; j--) { 17 | if(possible[j]) { 18 | possible[j+weight] = true; 19 | } 20 | } 21 | 22 | } 23 | 24 | int closest = 0; 25 | for(int j = 0; j < possible.size(); j++) { 26 | if(possible[j] && abs(1000-j) <= abs(1000-closest)) { 27 | closest = j; 28 | } 29 | } 30 | 31 | cout << closest << endl; 32 | } 33 | -------------------------------------------------------------------------------- /warehouse.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | void solve() { 6 | int n; 7 | cin >> n; 8 | 9 | map m; 10 | for(int i = 0; i < n; i++) { 11 | string s; 12 | int t; 13 | cin >> s >> t; 14 | 15 | m[s] += t; 16 | } 17 | 18 | vector> v; 19 | for(auto i : m) { 20 | v.push_back({-i.second, i.first}); 21 | } 22 | 23 | sort(v.begin(), v.end()); 24 | 25 | cout << v.size() << endl; 26 | for(auto i : v) { 27 | cout << i.second << " " << -i.first << endl; 28 | } 29 | } 30 | 31 | int main() { 32 | int cases; 33 | cin >> cases; 34 | while(cases--) { 35 | solve(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /whatdoesthefoxsay.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | def main(): 4 | n = int(raw_input()) 5 | 6 | while n > 0: 7 | n -= 1 8 | words = sys.stdin.readline().split() 9 | 10 | while True: 11 | line = sys.stdin.readline() 12 | if line == 'what does the fox say?\n': 13 | break 14 | word = line.split()[-1] 15 | words = [i for i in words if i != word] 16 | 17 | for word in words: 18 | print word, 19 | 20 | print "" 21 | 22 | if __name__ == "__main__": 23 | main() 24 | -------------------------------------------------------------------------------- /wizardofodds.py: -------------------------------------------------------------------------------- 1 | def main(): 2 | number, guess = input().split() 3 | number = int(number) 4 | guess = int(guess) 5 | 6 | if 2 ** guess >= number: 7 | print("Your wish is granted!") 8 | else: 9 | print("You will become a flying monkey!") 10 | 11 | 12 | if __name__ == "__main__": 13 | main() 14 | -------------------------------------------------------------------------------- /yinyangstones.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | string s; 8 | cin >> s; 9 | int w = 0; 10 | int b = 0; 11 | for(int i = 0; i < s.length(); i++) { 12 | if(s[i] == 'W') { 13 | w++; 14 | } 15 | if(s[i] == 'B') { 16 | b++; 17 | } 18 | } 19 | if(w == b) { 20 | cout << 1 << endl; 21 | } 22 | else { 23 | cout << 0 << endl; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /zamka.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int getDigits(int n) { 6 | int sum = 0; 7 | while(n > 0) { 8 | sum += n % 10; 9 | n /= 10; 10 | } 11 | return sum; 12 | } 13 | 14 | int main() { 15 | int min, max, digits; 16 | cin >> min >> max >> digits; 17 | 18 | for(int i = min; i <= max; i++) { 19 | if(getDigits(i) == digits) { 20 | cout << i << endl; 21 | break; 22 | } 23 | } 24 | 25 | for(int i = max; i >= min; i--) { 26 | if(getDigits(i) == digits) { 27 | cout << i << endl; 28 | break; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /zanzibar.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int positive(int n) { 6 | if(n < 0) { 7 | n = 0; 8 | } 9 | return n; 10 | } 11 | 12 | int main() { 13 | int n; 14 | cin >> n; 15 | 16 | for(int i = 0; i < n; i++) { 17 | int total = 0; 18 | int a, b; 19 | cin >> a; 20 | while(cin >> b && b != 0) { 21 | total += positive(b-(2*a)); 22 | a = b; 23 | } 24 | cout << total << endl; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /zebrasocelots.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | typedef long long ll; 8 | 9 | int main() { 10 | ios::sync_with_stdio(false); 11 | cin.tie(NULL); 12 | 13 | int n; 14 | cin >> n; 15 | 16 | ll ans = 0; 17 | for(int i = 0; i < n; i++) { 18 | char c; 19 | cin >> c; 20 | 21 | ans <<= 1; 22 | if( c == 'O') { 23 | ans++; 24 | } 25 | } 26 | cout << ans << endl; 27 | } 28 | 29 | -------------------------------------------------------------------------------- /znanstvenik.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int n, m; 7 | cin >> n >> m; 8 | 9 | vector v(n); 10 | for(auto& i : v) { 11 | cin >> i; 12 | } 13 | 14 | int c = 0; 15 | vector row(m); 16 | for(int i = n-1; i >= 0; i--) { 17 | map, int> thing; 18 | for(int j = 0; j < m; j++) { 19 | if(thing.count({row[j],v[i][j]}) > 0) { 20 | row[j] = thing[{row[j],v[i][j]}]; 21 | } 22 | else { 23 | c++; 24 | thing[{row[j],v[i][j]}] = c; 25 | row[j] = c; 26 | } 27 | } 28 | 29 | if(thing.size() == m) { 30 | cout << i << endl; 31 | return 0; 32 | } 33 | } 34 | 35 | cout << 0 << endl; 36 | } 37 | --------------------------------------------------------------------------------