├── .gitignore ├── LICENSE ├── README.md ├── imp.md ├── resource ├── ESCR.gif └── sublime-shortcut-keys.png ├── setup ├── a.cpp ├── b.cpp ├── basics.cpp ├── c.cpp ├── cpp-default.code-snippets ├── d.cpp ├── e.cpp ├── input.txt ├── leetcode.cpp ├── lic │ ├── GNU.txt │ ├── LICENSE.txt │ └── MIT ├── other │ ├── Java-custom.sublime-build │ ├── default.md │ ├── lc.cpp │ ├── test.c │ ├── test.cpp │ ├── test.java │ ├── test.js │ ├── test.py │ └── untitled.sublime-build └── output.txt └── src ├── Algorithm-Based ├── DijkstraAlgo.cpp ├── EularTotientCoPrime.cpp ├── EulerTotient.cpp ├── GreedyGame.cpp ├── HuffmanEncoder.java ├── KnightsTour.cpp ├── Kruskals.cpp ├── Nqueen.cpp ├── SnakesAndLadder.cpp ├── euclid.cpp ├── extendedEuclid.cpp ├── nKing.java └── nKingsOri.java ├── Anagram ├── AllAnagramInString.cpp ├── AllAnagramSubstring.cpp ├── Anagram.cpp ├── AnagramClass.cpp ├── CountAnagram.cpp ├── IsAnagram.cpp └── SeperateAnagrams.cpp ├── Arrays ├── KadaneMaximumSumSubarray.cpp ├── LongSubArraySum.cpp ├── LongestSubArrayDistinctNotMoreOne.js ├── MaxSumRect2DArray.cpp ├── MaxSumRectSubArray.cpp ├── MaxSumSubArray.cpp ├── MaxiSubArraySum.cpp ├── PivotOfSortedAndRotatedArray.cpp ├── SubArrayWithDistinctElements.cpp ├── mcm.cpp ├── mcmdp.cpp └── sum-of-subarray-of-distinct-elements.cpp ├── AtCoder ├── 1-sat.cpp ├── CreamPuff.cpp ├── DNASequence.cpp ├── FourtuneCookies.cpp ├── PlusMinus.cpp ├── Quizzes.cpp ├── TakahashiUnevolved.cpp ├── TrapezoidSum.cpp ├── VariousDistances.cpp ├── box.cpp ├── increment-of-coins.cpp ├── programming-contest.cpp └── super-ryuma.cpp ├── Code-Chef ├── A1.cpp ├── ACBALL.cpp ├── ADAMAT_AdaMatrix.cpp ├── ADAMAT_AdaMatrix.py ├── AGCY.cpp ├── ALEXNUMB.cpp ├── ALPHABET.cpp ├── ALTARAY.cpp ├── AMIFIB.cpp ├── AMMEAT.cpp ├── AMMEAT2.cpp ├── AMR15A.cpp ├── AMSGAME1.cpp ├── ANDOR.cpp ├── ANUBTG.cpp ├── ANUDTC.cpp ├── ANUTHM.cpp ├── ANUWTA.cpp ├── APL3_AnAppleADay.cpp ├── APPROX.cpp ├── APR2021-Long │ ├── BOOLGAME.cpp │ ├── CHAOSEMP.cpp │ ├── KAVGMAT.CPP │ ├── MEXSTR.cpp │ ├── SDICE.cpp │ ├── TREEPERM.cpp │ └── WTRSORT.cpp ├── ARRANGE.cpp ├── ARRAYTRM.cpp ├── AVG.cpp ├── BESTBATS.cpp ├── BIGARRAY.cpp ├── BINTREE.cpp ├── BROKPHON.cpp ├── BUYING2.cpp ├── CAB.cpp ├── CANDLE.cpp ├── CAPPLE.cpp ├── CARVANS.cpp ├── CHBLLNS.cpp ├── CHCHCL.cpp ├── CHCOINSG.cpp ├── CHEFA.cpp ├── CHEFCBA.cpp ├── CHEFCH.cpp ├── CHEFFED.cpp ├── CHEFGR.cpp ├── CHEFHOME.cpp ├── CHEFLR.cpp ├── CHEFLUCK.cpp ├── CHEFRP.cpp ├── CHEFSOCK.cpp ├── CHEFST.cpp ├── CHEFSTLT.cpp ├── CHFNSWAP_Chefina-and-Swap.cpp ├── CHGIFT1.cpp ├── CHN09.cpp ├── CHOPRT.cpp ├── CHRECT.cpp ├── CHRL2.cpp ├── CIELAB.cpp ├── CIELRCPT.cpp ├── CLEANUP.cpp ├── CLMBSTRS.cpp ├── CNOTE.cpp ├── COFDQ1.cpp ├── COFDQ2.py ├── COINS.cpp ├── COLOR.cpp ├── COMM3.cpp ├── COMMUTE.cpp ├── CONFLIP.cpp ├── COOK126B_ANDPREF.cpp ├── COOK126B_EQLGIFTS.cpp ├── COOK126B_MEXSUB.cpp ├── COOK126B_MINIL.cpp ├── COOK126B_NTCOL.cpp ├── COOK126B_PTUPLES.cpp ├── COOLGUYS.cpp ├── COOLING.cpp ├── COUPON.cpp ├── COVID19B_CoronavirusSpread2.cpp ├── CRDGAME2_Chef and Trump Cards.cpp ├── CSUB.cpp ├── DCE05.cpp ├── DEC2020-Long │ ├── EVENPSUM.cpp │ ├── HXOR.cpp │ ├── POSPREFS.cpp │ ├── STROPERS.cpp │ ├── VACCINE1.cpp │ └── VACCINE2.cpp ├── DECSTR.cpp ├── DEVARRAY.cpp ├── DISTCODE.cpp ├── DIVGAME-old.cpp ├── DIVGAME.cpp ├── DIVIDING.cpp ├── DIVNINE.cpp ├── DIVSUBS.cpp ├── DONUTS.cpp ├── DOUBLE.cpp ├── DRAGNXOR.cpp ├── EASYPROB.cpp ├── EMA01.cpp ├── EMITL.cpp ├── ENCDNOV.cpp ├── EOOPR.cpp ├── EQUALITY.cpp ├── EQUATION.cpp ├── ERROR.cpp ├── FACEDIR.cpp ├── FCTRL.cpp ├── FCTRL2.cpp ├── FILLGRID.cpp ├── FINXOR_Find-XOR.py ├── FIRSTTEST.cpp ├── FLOW001.cpp ├── FLOW002.cpp ├── FLOW004.cpp ├── FLOW005.cpp ├── FLOW006.cpp ├── FLOW007.cpp ├── FLOW008.cpp ├── FLOW009.cpp ├── FLOW010.cpp ├── FLOW011.cpp ├── FLOW013.cpp ├── FLOW014.cpp ├── FLOW016.cpp ├── FLOW017.cpp ├── FLOW018.cpp ├── FROGV.cpp ├── FRUITS.cpp ├── FSQRT.cpp ├── Feb2021-Long │ ├── ATWNT.cpp │ ├── BASH.cpp │ ├── CUTCAKE.cpp │ ├── FROGS.cpp │ ├── MAXFUN.cpp │ ├── MULGAME.cpp │ ├── PRIGAME.cpp │ ├── SUMXOR2.cpp │ └── TEAMNAME.cpp ├── GCD2.cpp ├── GDOG.cpp ├── GIVCANDY.cpp ├── GSUB.cpp ├── HEADBOB.cpp ├── HELPLIRA.cpp ├── HOLES.cpp ├── HORSES.cpp ├── HS08TEST.cpp ├── INTEST.cpp ├── IPCCERT.cpp ├── ITGUY28.cpp ├── J7.cpp ├── JAN2021-Long │ ├── ANTSCHEF.cpp │ ├── BILLRD.cpp │ ├── BLKJK.cpp │ ├── COOLSBST.cpp │ ├── CURMAT.cpp │ ├── FAIRELCT.cpp │ ├── ORAND.cpp │ ├── RCTEXSCC.cpp │ ├── TILESQRS.cpp │ └── WIPL.cpp ├── JOHNY.cpp ├── JUNE2021-Long │ └── COCONUT.cpp ├── KTTABLE.cpp ├── LCH15JAB.cpp ├── LCKYST.cpp ├── LCOLLIS.cpp ├── LEBOMBS.cpp ├── LECANDY.cpp ├── LEDIV.cpp ├── LELEMON.cpp ├── LFEB14B.cpp ├── LIFE.cpp ├── LUCKFOUR.cpp ├── LUCKY5.cpp ├── LUCKYSTR.cpp ├── MAKEART.cpp ├── MAR2021-Long │ ├── CCNF.cpp │ ├── COLGLF4.cpp │ ├── CONSADD.cpp │ ├── DENSEGRP.cpp │ ├── IRSTXOR.cpp │ ├── LCKDSAFE.cpp │ ├── MAXTOPO.cpp │ ├── PAPARAZI.cpp │ ├── RWALKS.cpp │ ├── SPACEARR.cpp │ └── WIREL.cpp ├── MARBLES.cpp ├── MARCHA1.cpp ├── MAXCOUNT.cpp ├── MAXDIFF.cpp ├── MAX_DIFF.cpp ├── MAY2021-Long │ ├── ISS.cpp │ ├── KKLING.cpp │ ├── MODEQ.cpp │ ├── TCTCTOE.cpp │ ├── THOUSES.cpp │ ├── VPATH.cpp │ └── XOREQUAL.cpp ├── MCHAIRS.cpp ├── MGCRNK.cpp ├── MIKE2.cpp ├── MISINTER.cpp ├── MISSP.cpp ├── MIXTURES.cpp ├── MNMX.cpp ├── MOVIEWKN.cpp ├── MSTEP.cpp ├── MUFFINS3.cpp ├── NAME1.cpp ├── NAME2.cpp ├── NDIFFPAL.cpp ├── NOCODING.cpp ├── NOTATRI.cpp ├── NOV2020-Long │ ├── ADADISH.cpp │ ├── CNDYGAME.cpp │ ├── FEMA2.cpp │ └── RESTORE.java ├── NUKES.cpp ├── NUMFACT.cpp ├── NUMGAME.cpp ├── NUMGAME2.cpp ├── OCT2020-Long │ ├── CHEFEZQ.cpp │ ├── CVDRUN.cpp │ ├── DDIMMST.java │ ├── POSAND.cpp │ ├── REPLESX.cpp │ └── SEGCOMPR.cpp ├── OJUMPS.cpp ├── OMWG.cpp ├── ONP.cpp ├── ORDERS.cpp ├── P1Z2S.cpp ├── PAIRING.cpp ├── PALIN.cpp ├── PALL01.cpp ├── PCYCLE.cpp ├── PERMUT2.cpp ├── PLZLYKME.cpp ├── POINTS.cpp ├── POTATOES.cpp ├── PPNUM.cpp ├── PRB01.cpp ├── PREDICT.cpp ├── PRIME1.cpp ├── PRIMES2.cpp ├── PROB.cpp ├── PRPALIN.cpp ├── PUPPYGM.cpp ├── RANKLIST.cpp ├── RECIPE.cpp ├── RECTSQ.cpp ├── REMISS.cpp ├── RESQ.cpp ├── RETPO.cpp ├── RGAME.cpp ├── ROTATION.cpp ├── RRCOPY.cpp ├── RRECIPE.cpp ├── RTCG001.cpp ├── RTCG002.cpp ├── RTCG003.cpp ├── RTCG004.cpp ├── SALARY.cpp ├── SDSQUARE.cpp ├── SEAVOTE.cpp ├── SMPAIR.cpp ├── SNIPE.cpp ├── SPALNUM.cpp ├── SPCANDY.cpp ├── SQNUMBF.cpp ├── STACKS.cpp ├── STADIUM.cpp ├── START01.cpp ├── STONES.cpp ├── STUDVOTE.cpp ├── SUBGCD.cpp ├── SUBINC.cpp ├── SUMTRIAN.cpp ├── TAAND.cpp ├── TACHSTCK.cpp ├── TADELIVE.cpp ├── TAPALIN.cpp ├── TEMPLATE.cpp ├── TICKETS5.cpp ├── TIDRICE.cpp ├── TLG.cpp ├── TOTR.cpp ├── TREE2_AProblemonSticks.cpp ├── TREEROOT.cpp ├── TRICOIN.cpp ├── TRISQ.cpp ├── TSORT.cpp ├── TWOSTR.cpp ├── TWTCLOSE.cpp ├── VBR_Vibrating-Paths.cpp ├── VCS.cpp ├── VOTERS.cpp ├── WALK.cpp ├── WSC.cpp └── XORNUBER.cpp ├── Code-Forces ├── #674_floor-number.cpp ├── #678_prime-squares.cpp ├── #678_re-order.cpp ├── #685_non-substring-subsequence.cpp ├── #685_string-equality.cpp ├── #685_subtract-divide.cpp ├── #686_unique-bid-auction.cpp ├── #687_prison-break.cpp ├── #687_repainting-street.cpp ├── #688_cancel-the-trains.cpp ├── #691_move-and-turn.cpp ├── #691_red-blue-shuffle.cpp ├── #691_row-gcd.cpp ├── #693_cards-for-friends.cpp ├── #693_even-odd-game.cpp ├── #693_fair-division.cpp ├── #693_long-jumps.cpp ├── #694_strange-birthday-party.cpp ├── #694_strange-list.cpp ├── #694_strange-partition.cpp ├── #696_array-destruction.cpp ├── #696_cleaning.cpp ├── #696_different-divisors.cpp ├── #696_puzzle-from-the-future.cpp ├── #696_what-is-it.cpp ├── #698_nezzar-and-board.cpp ├── #698_nezzar-and-colorful-balls.cpp ├── #698_nezzar-and-lucky-number.cpp ├── #698_nezzar-and-symmetric-array.cpp ├── #699_ab-graph.cpp ├── #699_fence-painting.cpp ├── #699_new-colony.cpp ├── #699_space-navigation.cpp ├── #700_d1-painting-the-array-i.cpp ├── #700_d2-painting-the-array-ii.cpp ├── #700_searching-local-maximum.cpp ├── #700_the-great-hero.cpp ├── #700_yet-another-string-game.cpp ├── #708_meximization.cpp ├── #734_wonderful-coloring-i.cpp ├── ABBB.cpp ├── Good_Bye2020_apollo-versus-pan.cpp ├── Good_Bye2020_bovine-dilemma.cpp ├── Good_Bye2020_canine-poetry.cpp ├── Good_Bye2020_euclids-nightmare.cpp ├── Good_Bye2020_last-minute-enhancements.cpp ├── Good_Bye_13th-labour-of-heracles.cpp ├── array-sums.cpp ├── belted-rooms.cpp ├── box-is-pull.cpp ├── buy-line.cpp ├── carrots-for-rabbits.cpp ├── circle-colouring.cpp ├── cubes.cpp ├── discreate-acceleration.cpp ├── edu#100_dungeon.cpp ├── edu#100_find-the-array.cpp ├── edu#101_building-a-fence.cpp ├── edu#101_ceil-divisions.cpp ├── edu#101_red-blue.cpp ├── edu#102_minimum-path.cpp ├── edu#102_no-more-inversions.cpp ├── edu#102_program.cpp ├── edu#102_replacing-elements.cpp ├── edu#102_string-lcm.cpp ├── edu#103_inflation.cpp ├── edu#103_journey.cpp ├── edu#103_k-divisible-sum.cpp ├── edu#103_longest-simple-cycle.cpp ├── edu#106_binary-removals.cpp ├── edu#106_domino-on-windowsill.cpp ├── edu#106_minimum-grid-path.cpp ├── edu#96_barrels.cpp ├── edu#96_number-of-apartments.cpp ├── edu#96_numbers-on-whiteboard.cpp ├── edu#97_chef-monocrap.cpp ├── edu#97_marketing-scheme.cpp ├── edu#97_reverse-binary-string.cpp ├── edu#98_robot-program.cpp ├── edu#99_jumps.cpp ├── edu#99_ping-pong.cpp ├── edu#99_sequence-and-swaps.cpp ├── edu#99_strange-functions.cpp ├── global#11_avoiding-zero.cpp ├── global#11_chess-cheater.cpp ├── global#12_Errich-Tac-Toe(Easy).cpp ├── global#12_Errich-Tac-Toe(Hard).cpp ├── global#12_ball-of-steel.cpp ├── global#12_rating-compression.cpp ├── ham-burgers.cpp ├── make-it-increasing.cpp ├── maximum-gcd.cpp ├── pythagorean-triples.cpp └── symmetric-matrix.cpp ├── Coding-Blocks ├── ActiveTraders.cpp ├── AggressiveCows.cpp ├── AliceAndTotient.cpp ├── Aquaman.cpp ├── BirthdayParaDox.cpp ├── BookAllocationProblem.cpp ├── Cashflow.cpp ├── CoinGame.cpp ├── DeepakAndHisJourney.cpp ├── DeepakAndPrimes.cpp ├── DeepakAndPrimes2.cpp ├── DutchNationalFlag(DNF).cpp ├── EditDistance.cpp ├── ExpandThePond.cpp ├── FarmerFrenzy.java ├── FindIt.cpp ├── FriendsAtCodingBlocks.cpp ├── FriendsPairing.cpp ├── FriendsPairingDP.cpp ├── FriendsPairing_ori.cpp ├── Friends_Pairing.cpp ├── GameTheory_1.cpp ├── HelpRahulSearch.cpp ├── HostelVisit.cpp ├── IncredibleHulk.cpp ├── LimitedBudgetParty.cpp ├── MaxTipCalc.cpp ├── MikeAndInfiniteGrid.cpp ├── MikeAndORTree.cpp ├── MinCostPath.cpp ├── MinWeightMaxValue.cpp ├── MixturesDP.cpp ├── MoveAllXtoEnd.java ├── NotSoEasyMaths.cpp ├── PilesAgain.cpp ├── PrateekLovesCandy.cpp ├── PrimeVisits.cpp ├── Prims.cpp ├── RodCutting.cpp ├── RopeCutMAxProduct.cpp ├── Roy_ProfilePic.cpp ├── SanjeetAndStrings.cpp ├── SankatAndStrings.cpp ├── StockSpan.cpp ├── StringWindow.cpp ├── TPrime.cpp ├── UniqueNum_1.cpp ├── UniqueNum_2.cpp ├── UniqueNum_3.cpp ├── Unlock.cpp ├── ViratAndFactorials.cpp ├── ViratAndNcR.cpp ├── WinningCBScholarship.cpp ├── WordBreak.cpp ├── cubeFreeNumbers.cpp ├── cubefree.java └── mixtures.cpp ├── Common-Problems ├── 2sDecomposition.cpp ├── CountSetBits.cpp ├── GaneshaPattern.cpp ├── GeneratePranthsis.cpp ├── GeneratePranthsis.py ├── KthRoot.cpp ├── KthRootOri.cpp ├── LastTwoDigitsOf2PowN.cpp ├── LexicoLarger.java ├── Lexicographical.cpp ├── MinInsertionsToFormPalindrome.cpp ├── NoConsecutiveOne.cpp ├── NumOfDivisors.cpp ├── PlayingWithBits.cpp ├── PythagoreanTriblet.cpp ├── PythagoreanTriptlet.cpp ├── StaircaseRecursion.cpp ├── UltraFastMathematicians.cpp ├── XOR_4.cpp ├── XOR_Profit.cpp ├── count3divisors.cpp ├── divisorofFactorial.java ├── nFactorialDivisors.cpp ├── replacepi.cpp ├── sieve.cpp └── trie.cpp ├── Data-Structure-Based ├── AdjacencyListGraphs.cpp └── BFS.cpp ├── Fibonacci ├── Nth-fibbanacci.cpp ├── all-fibonacci-solutions.cpp ├── fibonacci-recursion.cpp ├── fibonacci-series.cpp └── fibonacci-sum-dp.cpp ├── FoodFill ├── apple.txt ├── floodFill.cpp ├── floodFillForWindows.cpp ├── heart.txt └── square.txt ├── GCD ├── BigGCD.cpp ├── GCD.cpp └── advancedGCD.cpp ├── GeeksforGeeks-Hiring-Contest-Problems ├── binary-numbers.cpp ├── geek-and-allies.cpp └── geek-and-lines.cpp ├── Google-competitions └── KickStart │ ├── 2020-H-Rugby.cpp │ ├── 2020-H-boring-numbers.cpp │ ├── 2020-H-friends.cpp │ └── 2020-H-retype.cpp ├── Hacker-Rank ├── a-numbers.cpp ├── attribute-parser.cpp ├── bitset-1.cpp ├── cpp-variadics.cpp ├── fraudulent-activity-notifications.cpp ├── good-bad-string.cpp ├── matrix-script.py ├── maximize-it.py ├── merge-the-tools.py ├── no-idea.py ├── post-transition.c ├── simple-recursion.cpp ├── small-triangles-large-triangles.c ├── structuring-the-document.c ├── the-minion-game.py ├── the-nutritionist.cpp ├── validating-postalcode.py └── word-order.py ├── HackerEarth ├── OperationArray.cpp └── SortSubstring.cpp ├── Interview-Problems ├── CursorGame.cpp ├── FAANG │ ├── apple_min-time.cpp │ └── apple_social-groups.cpp ├── MarioAndPrincess.cpp ├── minimize-the-maximum-difference-between-the-heights.cpp ├── n-red-m-blue-candies-arrangements.cpp ├── pattern-1.cpp ├── pattern-2.cpp ├── raffaele-esposito-eatten-pizza.c └── vowels-count-with-proper-ds.cpp ├── Knapsack ├── 0-1Knapsack_both_DP_Approaches.cpp ├── 0-NKnapSack.cpp ├── ColorfulKnapsack.py ├── FractionalKnapsack.cpp ├── FractionalKnapsack.java ├── FractionalKnapsack_1.cpp └── Knapsack.cpp ├── Leetcode ├── 100_same-tree.cpp ├── 1022_sum-of-root-to-leaf-binary-numbers.cpp ├── 1032_stream-of-characters.cpp ├── 1041_robot-bounded-in-circle.cpp ├── 1094_car-pooling.cpp ├── 1108_defanging-an-ip-address.cpp ├── 1128_number-of-equivalent-domino-pairs.cpp ├── 1154_day-of-the-year.cpp ├── 1162_as-far-from-land-as-possible.cpp ├── 1184_distance-between-bus-stops.cpp ├── 1185_day-of-the-week.cpp ├── 119_pascal-triangle.cpp ├── 1206_design-skiplist.cpp ├── 1217_minimum-cost-to-move-chips-to-the-same-position.cpp ├── 121_best-time-to-buy-and-sell-stock.cpp ├── 122_best-time-to-buy-and-sell-stock-ii.cpp ├── 123_best-time-to-buy-and-sell-stock-iii.cpp ├── 123_best-time-to-buy-and-sell-stock-iii.java ├── 1254_number-closed-is-lands.cpp ├── 125_vaild-palindrome.cpp ├── 1262_greatest-sum-divisible-by-three.cpp ├── 1266_minimum-time-visiting-all-points.cpp ├── 1268_search-suggestions-system.cpp ├── 1286_iterator-for-combination.cpp ├── 1291_sequential-digits.cpp ├── 129_sum-root-to-leaf-numbers.cpp ├── 1305_all-elements-in-two-binary-search-trees.cpp ├── 1309_decrypt-string-from-alphabet-to-integer-mapping.cpp ├── 1313_decompress-run-length-encoded-list.cpp ├── 1317_convert-integer-to-the-sum-of-two-no-zero-integers.cpp ├── 1318_minimum-flips-to-make-a-or-b-equal-to-c.cpp ├── 1323_maximum-69-number.cpp ├── 134_gas-station.cpp ├── 1351_count-negative-numbers-in-a-sorted-matrix.cpp ├── 1365_how-many-numbers-are-smaller-than-the-current-number.cpp ├── 136_single-number.cpp ├── 1380_lucky-numbers-in-a-matrix.cpp ├── 1389_create-target-array-in-the-given-order.cpp ├── 1394_find-lucky-integer-in-an-array.cpp ├── 1399_count-largest-group.cpp ├── 139_word-break.cpp ├── 13_roman-to-integer.cpp ├── 1404_number-of-steps-to-reduce-a-number-in-binary-representation-to-one.cpp ├── 141_linked-list-cycle.cpp ├── 143_reorder-list.cpp ├── 1446_consecutive-characters.cpp ├── 1451_rearrange-words-in-sentence.cpp ├── 1455_check-If-a-word-occurs-prefix-any-word-sentence.cpp ├── 1460_make-two-arrays-equal-by-reversing-sub-arrays.cpp ├── 1464_maximum-product-two-elements-in-array.cpp ├── 1480_running-sum-of-1d-array.cpp ├── 1486_xor-operation-array.cpp ├── 1494_parallel-courses-ii.cpp ├── 14_longest-common-prefix.cpp ├── 1518_water-bottles.cpp ├── 1523_count-odd-numbers-in-an-interval-range.cpp ├── 152_maximum-product-subarray.cpp ├── 1534_count-good-triplets.cpp ├── 1550_three-consecutive-odds.cpp ├── 1551_minimum-operations-make-array-equal.cpp ├── 1556_thousand-seperator.cpp ├── 1559_detect-cycles-2d-grid.cpp ├── 1560_MostVisitedSectorInCircularTrack.cpp ├── 1561_MaxNumberCoinsYouCanGet.cpp ├── 1563_stone-game-v.cpp ├── 1567_maximum-length-of-subarray-with-positive-product.cpp ├── 1572_matrix-diagonal-sum.cpp ├── 1576_replace-all-s-to-avoid-consecutive-repeating-characters.cpp ├── 1577_number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers.cpp ├── 1578_minimum-deletion-cost-to-avoid-repeating-letters.cpp ├── 1579_remove-max-number-of-edges-to-keep-graph-fully-traversable.cpp ├── 1582_special-positions-in-a-binary-matrix.cpp ├── 1583_count-unhappy-friends.cpp ├── 1584_min-cost-to-connect-all-points.cpp ├── 1585_check-if-string-is-transformable-with-substring-sort-operations.cpp ├── 1592_rearrange-spaces-between-words.cpp ├── 1603_design-parking-system.cpp ├── 1604_alert-using-same-key-card-three-or-more-times-in-a-one-hour-period.cpp ├── 1605_find-valid-matrix-given-row-and-column-sums.cpp ├── 1608_special-array-with-x-elements-greater-than-or-equal-x.cpp ├── 1614_maximum-nesting-depth-of-the-parentheses.cpp ├── 1652_defuse-the-bomb.cpp ├── 165_compare-version-numbers.cpp ├── 1662_check-if-two-string-arrays-are-equivalent.cpp ├── 1663_smallest-string-with-a-given-numeric-value.cpp ├── 1664_ways-to-make-a-fair-array.cpp ├── 168_excel-sheet-column-title.cpp ├── 169_majority-element.cpp ├── 1700_number-of-students-unable-to-eat-lunch.cpp ├── 1701_average-waiting-time.cpp ├── 171_excel-sheet-column-number.cpp ├── 179_largest-number.cpp ├── 183_customers-who-never-order.sql ├── 188_best-time-to-buy-and-sell-stock-iv.cpp ├── 189_rotate-array.cpp ├── 18_4-sum.cpp ├── 191_number-of-1-bits.cpp ├── 192_factorial-trailing-zeroes.cpp ├── 196_delete-duplicate-emails.sql ├── 197_rising-temperature.sql ├── 198_house-robber.cpp ├── 199_binary-tree-right-side-view.cpp ├── 200_number-of-islands.cpp ├── 202_happy-number.cpp ├── 204_count-primes.cpp ├── 205_isomorphic-strings.cpp ├── 208_Trie(PrefixTree).cpp ├── 209_minimum-size-subarray-sum.cpp ├── 20_valid-parentheses.cpp ├── 214_shortest-palindrome.cpp ├── 216_combination-sum-iii.cpp ├── 217_contains-duplicate.cpp ├── 219_contains-duplicate-ii.cpp ├── 21_merge-two-sorted-lists.cpp ├── 220_contains-duplicate-iii.cpp ├── 230_kth-smallest-element-in-a-bst.cpp ├── 231_power-of-two.cpp ├── 238_product-of-array-except-self.cpp ├── 242_valid-anagram.cpp ├── 258_add-digits.cpp ├── 268_missing-number.cpp ├── 26_remove-duplicates-from-sorted-array.cpp ├── 274_H-Index.cpp ├── 278_bad-version.cpp ├── 27_remove-element.cpp ├── 283_move-zeroes.cpp ├── 284_peeking-iterator.cpp ├── 287_find-the-duplicate-number.cpp ├── 28_implement-strstr.cpp ├── 290_word-pattern.cpp ├── 292_nim-game.cpp ├── 299_bulls-and-cows.cpp ├── 303_range-sum-query-immutable.cpp ├── 304_range-sum-query-2d-immutable.cpp ├── 307_range-sum-query-mutable.cpp ├── 315_count-of-smaller-numbers-after-self.cpp ├── 316_remove-duplicate-letters.cpp ├── 326_power-of-three.cpp ├── 328_odd-even-linked-list.cpp ├── 342_power-of-four.cpp ├── 344_reverse-string.cpp ├── 345_reverse-vowels-of-a-string.cpp ├── 35_search-insert-position.cpp ├── 367_valid-perfect-square.cpp ├── 389_find-the-difference.cpp ├── 38_count-and-say.cpp ├── 399_evaluate-division.cpp ├── 404_LeafNodesOfTree.cpp ├── 405_convert-a-number-to-hexadecimal.cpp ├── 407_trapping-rain-water-ii.cpp ├── 409_longest-palindrome-case-sensitive.cpp ├── 412_fizz-buzz.cpp ├── 414_third-maximum-number.cpp ├── 41_first-missing-positive.cpp ├── 421_maximum-xor-of-two-numbers-in-an-array.cpp ├── 42_trapping-rain-water.cpp ├── 435_non-overlapping-iIntervals.cpp ├── 436_find-right-interval.cpp ├── 437_path-sum-iii.cpp ├── 442_find-duplicates.cpp ├── 44_wildcard-matching.cpp ├── 450_d-eleting-node-bst.cpp ├── 452_minimum-number-of-arrows-to-burst-balloons.cpp ├── 453_minimum-moves-to-equal-array-elements.cpp ├── 455_assign-cookies.cpp ├── 459_repeated-substring-pattern.cpp ├── 461_hamming-distance.cpp ├── 463_island-perimeter.cpp ├── 470_implement-rand10-using-rand7.cpp ├── 475_heaters.cpp ├── 476_number-complement.cpp ├── 482_license-key-formatting.cpp ├── 485_max-consecutive-ones.cpp ├── 492_construct-the-rectangle.cpp ├── 495_teemo-attacking.cpp ├── 496_next-greater-element-i.cpp ├── 497_random-point-non-overlapping-rectangles.cpp ├── 4_median-of-two-sorted-arrays.cpp ├── 500_keyboard-row.cpp ├── 504_base-7.cpp ├── 506_relative-ranks.cpp ├── 507_perfect-number.cpp ├── 509_fibonacci-number.cpp ├── 520_DetectCapital.cpp ├── 521_longest-uncommon-subsequence-i.cpp ├── 523-continuous-subarray-sum.cpp ├── 524-longest-word-in-dictionary-through-deleting.cpp ├── 529-minesweeper.cpp ├── 530-minimum-absolute-difference-in-bst.cpp ├── 532_k-diff-pairs-in-an-array.cpp ├── 53_max-sub-array.cpp ├── 541_reverse-string-ii.cpp ├── 551_student-attendance-record-i.cpp ├── 557_reverse-words-in-a-string-iii.cpp ├── 561_array-partition-i.cpp ├── 566_reshape-the-matrix.cpp ├── 575_distribute-candies.cpp ├── 57_insert-interval.cpp ├── 581_shortest-unsorted-continuous-subarray.cpp ├── 58_length-of-last-word.cpp ├── 593_vaild-square.cpp ├── 594_longest-harmonious-subsequence.cpp ├── 595_big-countries.sql ├── 596_classes-more-than-5-students.sql ├── 598_range-addition-ii.cpp ├── 599_minimum-index-sum-of-two-lists.cpp ├── 605_can-place-flowers.cpp ├── 620_not-boring-movies.sql ├── 627_swap-salary.sql ├── 628_maximum-product-of-three-numbers.cpp ├── 633_sum-of-square-numbers.cpp ├── 643_maximum-average-subarray-i.cpp ├── 645_set-mismatch.cpp ├── 65_valid-number.cpp ├── 665_non-decreasing-array.cpp ├── 669_trim-a-binary-search-tree.cpp ├── 66_plus-one.cpp ├── 674_longest-continuous-increasing-subsequence.cpp ├── 67_add-binary.cpp ├── 682_baseball-game.cpp ├── 690_employee-importance.cpp ├── 693_binary-number-with-alternating-bits.cpp ├── 696_count-binary-substrings.cpp ├── 697_degree-of-an-array.cpp ├── 69_sqrtx.cpp ├── 700_search-in-a-binary-search-tree.cpp ├── 705_design-hashset.cpp ├── 70_climbing-stairs.cpp ├── 713_subarray-product-less-than-k.cpp ├── 71_simplify-path.cpp ├── 728_self-dividing-numbers.cpp ├── 748_shortest-completing-word.cpp ├── 74_search-a-2d-matrix.cpp ├── 752_OpenTheLock.cpp ├── 763_partition-labels.cpp ├── 766_toeplitz-matrix.cpp ├── 795_number-of-subarrays-with-bounded-maximum.cpp ├── 821_shortest-distance-to-a-character.cpp ├── 824_latin-goat.cpp ├── 830_positions-of-large-groups.cpp ├── 835_image-overlap.cpp ├── 836_rectangle-overlap.cpp ├── 83_remove-duplicates-from-sorted-list.cpp ├── 84_largest-rectangle-in-histogram.cpp ├── 859_buddy-strings.cpp ├── 871_minimum-number-of-refueling-stops.cpp ├── 874_walking-robot-simulation.cpp ├── 880_decoded-string-at-index.cpp ├── 884_rotting-oranges.cpp ├── 887_super-egg-drop.py ├── 887_super-egg-dropping.cpp ├── 88_merge-sorted-array.cpp ├── 8_string-to-integer-atoi.cpp ├── 903_valid-permutations-for-di-sequence.cpp ├── 905_sort-array-by-parity.cpp ├── 908_smallest-range-i.cpp ├── 917_reverse-only-letters.cpp ├── 925_long-pressed-name.cpp ├── 929_unique-email-addresses.cpp ├── 933_number-of-recent-calls.cpp ├── 942_di-string-match.cpp ├── 949_largest-time-for-given-digits.cpp ├── 952_largest-component-size-by-common-factor.cpp ├── 953_verifying-an-alien-dictionary.cpp ├── 967_numbers-with-same-consecutive-differences.cpp ├── 969_pancake-sorting.cpp ├── 975_odd-even-jump.cpp ├── 980_unique-paths-iii.cpp ├── 983_minimum-cost-for-tickets.cpp ├── 987_vertical-order-traversal-binary-tree.cpp ├── 989_add-to-array-form-of-integer.cpp ├── 99_recover-binary-search-tree.cpp ├── 9_palindrome-number.cpp ├── addSearch(.)_TrieStructure.cpp ├── course-schedule.cpp ├── distribute-candies-two-people.cpp └── sort-array-by-increasing-frequency.cpp ├── Matrices ├── LongestSquareSubmatrixWithAllOne.cpp ├── LongestSquareWithAllOneTopDown.cpp ├── MatrixChainMulti.cpp ├── MatrixChainMultiDP.cpp ├── MatrixChainMultiplication.cpp ├── MatrixSearch.cpp ├── MaxCircularSum.cpp ├── MaximumCircles.cpp ├── MaximumSumRectangle.cpp ├── SpiralMatrix.cpp └── largestBinaryMatrixDim.cpp ├── Modular-Exponentation ├── ModularExp.cpp └── ModularExponentation.cpp ├── Permutation ├── PermutationRepeat.cpp ├── Permutations.cpp ├── largest-permutation.cpp ├── letter-case-permutation.cpp ├── permutation-of-string.cpp └── permutation-word.cpp ├── Problems-on-Strings ├── Alphabet_Matching_with_Num.cpp ├── CodeOfStrings.java ├── CodesOfString.cpp ├── CountNumBinaryString.cpp ├── CountOccString.cpp ├── DigitalDict.cpp ├── DigitalDict.java ├── LongestSubstringWithRepeat.cpp ├── StringGame.cpp ├── StringMatchingAlgo.cpp ├── StringSort.cpp ├── splitSentanceUsingGetLine.cpp └── transform-a-string.cpp ├── Rat-and-Maze ├── CountMazePath.cpp ├── CountMazePathDiagonal.cpp ├── MazePath(count_print).cpp ├── MazePath_2(count_print).cpp ├── MazePath_D(count_print).cpp ├── MazePath_D2(count_print).cpp ├── PrintMazePath.cpp ├── RatInMaze.cpp ├── RatMazeCodechef.cpp ├── Rats.cpp └── RatsInJUNCLE.cpp ├── Recursion ├── RecDictLargOrder.java ├── RecDictLargOrderOri.cpp ├── RecrDictOrderLarger.cpp ├── RecurObedientStr.cpp ├── RecursionConvertStr_Int.java ├── RecursionKeyPadCodes.cpp ├── RecursionKeyPadCodes.java ├── RecursionSubSeq.cpp └── RecursionTwins.cpp ├── Searching-and-Sorting ├── SortingAccordingToTheirOccurances.cpp ├── SquareRootUsingBinarySearch.cpp └── minimum-swap-required-to-sort.cpp ├── Subsequences ├── ChefAndInterestingSubsequences.cpp ├── CountSubSeq.cpp ├── DistinctSubSeq.cpp ├── IncreasingDecreasingSeq.cpp ├── KorderedLCS.cpp ├── LCS.cpp ├── LIS_LongestIncreasingSubsequence.cpp ├── LongestBitonicSubsequence(LBS) │ └── LongestBiotonicSubsequence.cpp ├── LongestCommonSubsequence(LCS) │ ├── LCM.cpp │ ├── LCS.cpp │ ├── LCSForThreeStrings.cpp │ ├── LCS_RecursionBottomUp.cpp │ ├── LCS_RecursionTopDown.cpp │ ├── LCS_RepeatingSubSeq.cpp │ └── LengthOfLCS.cpp ├── LongestIncreasingSubsequence.cpp ├── LongestPalindromicSubSeq.cpp ├── LongestPalindromicSubsequence.cpp ├── LongestRepeatingSubsequence.cpp ├── MaxLengthBiotonicSubArray.java ├── MaxLengthBiotonicSubSeq.cpp ├── PrintLCS.cpp ├── PrintLCS2.cpp ├── SubSequences-Recursion.txt ├── Subsequences.cpp ├── Subsequences_ASCII.cpp ├── Uncommon_LCS.cpp ├── subsequence.cpp ├── subsequence_ori.cpp ├── subsequenceascii.cpp └── subsequenceascii_ori.cpp └── Subsets ├── TargetSubset.cpp └── targetSumSubset.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | *.exe 2 | *.javac 3 | *.class 4 | .project 5 | .DS_Store 6 | .cph/ 7 | -------------------------------------------------------------------------------- /resource/ESCR.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ravireddy07/cpp-book/7a03aa56b2e6e2a28776e56514ac061303db406e/resource/ESCR.gif -------------------------------------------------------------------------------- /resource/sublime-shortcut-keys.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ravireddy07/cpp-book/7a03aa56b2e6e2a28776e56514ac061303db406e/resource/sublime-shortcut-keys.png -------------------------------------------------------------------------------- /setup/c.cpp: -------------------------------------------------------------------------------- 1 | // Problem Statement: 2 | 3 | /** 4 | * Author: Ravi Kanth Gojur 5 | * Code Forces: ravireddy07 6 | * Code Chef: ravireddy115 7 | * Github: ravireddy07 8 | **/ 9 | 10 | #include 11 | #define ll long long int 12 | #define yes printf("YES\n") 13 | #define no printf("NO\n") 14 | using namespace std; 15 | 16 | int main() { 17 | #ifndef ONLINE_JUDGE 18 | freopen("input.txt", "r", stdin); 19 | freopen("output.txt", "w", stdout); 20 | #endif 21 | 22 | int t; 23 | scanf("%d", &t); 24 | while (t--) { 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /setup/d.cpp: -------------------------------------------------------------------------------- 1 | // Problem Statement: 2 | 3 | /** 4 | * Author: Ravi Kanth Gojur 5 | * Code Forces: ravireddy07 6 | * Code Chef: ravireddy115 7 | * Github: ravireddy07 8 | **/ 9 | 10 | #include 11 | #define ll long long int 12 | #define yes printf("YES\n") 13 | #define no printf("NO\n") 14 | using namespace std; 15 | 16 | int main() 17 | { 18 | #ifndef ONLINE_JUDGE 19 | freopen("input.txt", "r", stdin); 20 | freopen("output.txt", "w", stdout); 21 | #endif 22 | 23 | int t; 24 | scanf("%d", &t); 25 | while (t--) 26 | { 27 | } 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /setup/input.txt: -------------------------------------------------------------------------------- 1 | 2 2 | 3 3 | 3 1 2 4 | 4 5 | 2 8 1 9 6 | 5 7 | 8 | 9 | 4 10 | 1 100 4 3 11 | 6 12 | 15 10 12 5 1 10 13 | 6 14 | -------------------------------------------------------------------------------- /setup/leetcode.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems// 2 | 3 | #include 4 | using namespace std; 5 | 6 | class Solution { 7 | public: 8 | }; 9 | 10 | int main() 11 | { 12 | #ifndef ONLINE_JUDGE 13 | freopen("input.txt", "r", stdin); 14 | freopen("output.txt", "w", stdout); 15 | #endif 16 | Solution a; 17 | int t = 1; 18 | //cin >> t; 19 | 20 | while (t--) { 21 | /* 22 | vector res = a.shortestToChar("loveleetcode", 'c'); 23 | for (auto i : res) 24 | cout << i << " "; 25 | */ 26 | } 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /setup/other/Java-custom.sublime-build: -------------------------------------------------------------------------------- 1 | { 2 | "cmd": ["javac", "$test", "&&", "java" ,"$test"], 3 | "selector": "source.java", 4 | "file_regex": "^\\s*File \"(...*?)\", line ([0-9]*)", 5 | "C:\\Program Files\\Java\\jdk-13.0.1\\bin", 6 | "shell":true 7 | } 8 | /* 9 | { 10 | "cmd": ["javac", "$test", "&&", "java" ,"$test"], 11 | "selector": "source.java", 12 | "file_regex": "^\\s*File \"(...*?)\", line ([0-9]*)", "path" : 13 | "C:\\Program Files\\Java\\jdk-13.0.1\\bin", 14 | "shell":true 15 | } 16 | */ -------------------------------------------------------------------------------- /setup/other/default.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # c 4 | 5 | **Syntax:** "gcc $fileName -o $fileNameWithoutExt && $dir $fileNameWithoutExt" 6 | **Example:** gcc filename.c -o filename && ./filename 7 | **Shortcut:** Ctrl+Alt+N 8 | 9 | # cpp 10 | 11 | **Syntax:** "g++ $fileName -o $fileNameWithoutExt && $dir $fileNameWithoutExt" 12 | **Example:** g++ filename.cpp -o filename && ./filename 13 | **Shortcut:** Ctrl+Alt+N 14 | 15 | # html 16 | 17 | **Shortcut:** ctrl+shft+V 18 | 19 | # md 20 | 21 | **Shortcut:** ctrl+shft+V 22 | -------------------------------------------------------------------------------- /setup/other/test.js: -------------------------------------------------------------------------------- 1 | var b = [1, 2, 3, 4]; 2 | (function () { 3 | b.push(5) 4 | return b; 5 | })(); -------------------------------------------------------------------------------- /setup/other/test.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ravireddy07/cpp-book/7a03aa56b2e6e2a28776e56514ac061303db406e/setup/other/test.py -------------------------------------------------------------------------------- /setup/other/untitled.sublime-build: -------------------------------------------------------------------------------- 1 | { 2 | "cmd": ["javac", "$test", "&&", "java" ,"$test"], 3 | "selector": "source.java", 4 | "file_regex": "^\\s*File \"(...*?)\", line ([0-9]*)", 5 | "C:\\Program Files\\Java\\jdk-13.0.1\\bin", 6 | "shell":true 7 | } 8 | /* 9 | { 10 | "cmd": ["javac", "$test", "&&", "java" ,"$test"], 11 | "selector": "source.java", 12 | "file_regex": "^\\s*File \"(...*?)\", line ([0-9]*)", "path" : 13 | "C:\\Program Files\\Java\\jdk-13.0.1\\bin", 14 | "shell":true 15 | } 16 | */ -------------------------------------------------------------------------------- /setup/output.txt: -------------------------------------------------------------------------------- 1 | 7 2 | 3 | 3 ms 4 | -------------------------------------------------------------------------------- /src/Algorithm-Based/EularTotientCoPrime.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | #define ll long long int 5 | 6 | int* FindCoPrime(int n) { 7 | int *arr = new int[n+1]; 8 | for(int i=0;i<=n;i++) { 9 | arr[i] = i; 10 | } 11 | 12 | for(int i=2;i<=n;i++) { 13 | if(arr[i] == i) { 14 | for(int j=i*2;j<=n;j+=i) { 15 | arr[j] = (arr[j] * (i-1))/(i); 16 | } 17 | arr[i]--; 18 | } 19 | } 20 | return arr; 21 | } 22 | 23 | 24 | int main(int argc, char const *argv[]) { 25 | int *arr; 26 | arr = FindCoPrime(100); 27 | for(int i=0;i<100;i++) { 28 | cout< 2 | using namespace std; 3 | 4 | int* totient(int n) { 5 | int *arr = new int[n+1]; 6 | for(int i=0;i<=n;i++) { 7 | arr[i] = i; 8 | } 9 | for(int i=2;i<=n;i++) { 10 | if(arr[i] == i) { 11 | for(int j=i*2;j<=n;j+=i) { 12 | arr[j] = (arr[j] * (i-1))/(i); 13 | } 14 | arr[i]--; 15 | } 16 | } 17 | return arr; 18 | } 19 | 20 | int main(int argc, char const *argv[]) 21 | { 22 | /* code */ 23 | int *arr; 24 | arr = totient(100); 25 | for(int i=0;i<100;i++) { 26 | cout< 2 | using namespace std; 3 | 4 | int game(int *arr, int n, char start) { 5 | int even = 0; 6 | int odd = 0; 7 | for(int i=1;i<=n;i++) { 8 | if(i%2) { 9 | odd += arr[i-1]; 10 | } else { 11 | even += arr[i-1]; 12 | } 13 | } 14 | cout< even) { 17 | return odd; 18 | } else { 19 | return even; 20 | } 21 | } 22 | 23 | int main(int argc, char const *argv[]) { 24 | int n; 25 | cin>>n; 26 | char start; 27 | cin>>start; 28 | int *arr = new int[n]; 29 | for(int i=0;i>arr[i]; 31 | } 32 | cout< 2 | using namespace std; 3 | 4 | int gcd(int a, int b) { 5 | if(b==0) return a; 6 | return gcd(b, a%b); 7 | } 8 | 9 | int main(int argc, char const *argv[]) 10 | { 11 | cout< 2 | using namespace std; 3 | 4 | class triplet { 5 | public: 6 | int x, y, gcd; 7 | }; 8 | 9 | triplet extendedEuclid(int a, int b) { 10 | if(b == 0) { 11 | triplet base; 12 | base.gcd = a; 13 | base.y = 4; 14 | base.x = 1; 15 | return base; 16 | } 17 | triplet recursionAns = extendedEuclid(b, a%b); 18 | triplet result; 19 | result.x = recursionAns.y; 20 | result.y = recursionAns.x - ((a/b)*recursionAns.y); 21 | result.gcd = recursionAns.gcd; 22 | return result; 23 | } 24 | 25 | int main(int argc, char const *argv[]) 26 | { 27 | /* code */ 28 | triplet ans = extendedEuclid(10, 4); 29 | cout< 2 | using namespace std; 3 | 4 | bool isAnagram(int *hash1, int *hash2) 5 | { 6 | for (int i = 0; i < 26; i++) 7 | if (hash1[i] != hash2[i]) 8 | return false; 9 | return true; 10 | } 11 | 12 | int main(int argc, char const *argv[]) 13 | { 14 | string s1, s2; 15 | cin >> s1 >> s2; 16 | int hash1[26] = {0}; 17 | int hash2[26] = {0}; 18 | if (s1.size() != s2.size()) 19 | cout << "false"; 20 | else 21 | { 22 | for (int i = 0; i < s1.size(); i++) 23 | hash1[s1[i] - 'a']++; 24 | for (int i = 0; i < s2.size(); i++) 25 | hash2[s2[i] - 'a']++; 26 | if (isAnagram(hash1, hash2)) 27 | cout << "true"; 28 | else 29 | cout << "false"; 30 | } 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /src/Arrays/KadaneMaximumSumSubarray.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int kadane(int *arr, int n) { 5 | int curr_sum = 0; 6 | int global_max = INT_MIN; 7 | 8 | for(int i=0;i global_max) { 14 | global_max = curr_sum; 15 | } 16 | } 17 | return global_max; 18 | } 19 | 20 | int main(int argc, char const *argv[]) 21 | { 22 | int n; 23 | cin>>n; 24 | int *arr = new int[n]; 25 | for(int i=0;i>arr[i]; 27 | } 28 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | int n,t,z; 6 | cin>>t; 7 | for(z=0;z>n; 9 | int a[100];///CHANGE. array size was small. 10 | //Input 11 | for(int i=0;i>a[i]; 13 | } 14 | 15 | //Kadane's Algorithm 16 | int cs=0,ms=0; 17 | for(int i=0;i 2 | #include 3 | using namespace std; 4 | #define ll long long int 5 | 6 | int MaxSumSubArray(int* arr, int n) { 7 | int curr_sum = 0; 8 | int global_max = INT_MIN; 9 | 10 | //-1 4 -2 -5 6 -8 11 | for(int i=0;i global_max) { 17 | global_max = curr_sum; 18 | } 19 | } 20 | return global_max; 21 | } 22 | 23 | 24 | int main(int argc, char const *argv[]) { 25 | int t,n; 26 | cin>>t; 27 | for(int i=0;i>n; 29 | int *ar = new int[n]; 30 | cin>>ar[i]; 31 | cout< 2 | using namespace std; 3 | 4 | int findPivot(int a[],int s,int e) { 5 | if(s>e) { 6 | return -1; 7 | } 8 | while(s<=e) { 9 | int mid = (s+e)/2; 10 | if(mida[mid+1]) { 11 | return mid; 12 | } 13 | if(mid>s&&a[mid]=a[mid]) { 17 | e = mid-1; 18 | } 19 | else { 20 | s = mid + 1; 21 | } 22 | } 23 | return -1; 24 | } 25 | 26 | 27 | int main() { 28 | int n; 29 | cin>>n; 30 | int b[n]; 31 | for(int i=0;i>b[i]; 33 | } 34 | cout< 2 | using namespace std; 3 | 4 | int sumOflength(int arr, int n) 5 | { 6 | unordered_set s; 7 | int j = 0, ans = 0; 8 | for (int i = 0; i < n; ++i) 9 | { 10 | while (j < n and s.find(arr[j]) == s.end()) 11 | { 12 | s.insert(arr[j]); 13 | j++; 14 | } 15 | ans += ((j - i) * (j - i + 1)) / 2; 16 | s.erase(arr[i]); 17 | } 18 | return ans; 19 | } 20 | 21 | int main() 22 | { 23 | cout << sumOflength({1, 4, 2, 6, 8, 4, 9, 3, 2, 8}, sizeof(arr) / sizeof(arr[0])) << "\n"; 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /src/Arrays/mcm.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int mcm(int *arr, int i, int j) { 5 | if(abs((int)(i - j)) == 1) { 6 | return 0; 7 | } 8 | 9 | int result = INT_MAX; 10 | for(int k=i;k<=j-2;k++) { 11 | int retval = mcm(arr, i, k+1) + mcm(arr, k+1, j) + arr[i-1]*arr[k]*arr[j-1]; 12 | if(retval < result) result = retval; 13 | } 14 | return result; 15 | } 16 | 17 | int main(int argc, char const *argv[]) 18 | { 19 | int n; 20 | cin>>n; 21 | int *arr = new int[n]; 22 | for(int i=0;i>arr[i]; 24 | } 25 | cout< 4 | #include 5 | #include 6 | #define ll long long int 7 | using namespace std; 8 | 9 | int main() 10 | { 11 | ll x; 12 | cin >> x; 13 | vector result; 14 | ll i = 1; 15 | while (i * i <= x) 16 | { 17 | if (x % i == 0) 18 | { 19 | result.push_back(i); 20 | if (x / i != i) 21 | result.push_back(x / i); 22 | } 23 | i++; 24 | } 25 | sort(result.begin(), result.end()); 26 | for (ll k = 0; k < result.size(); ++k) 27 | cout << result[k] << endl; 28 | return 0; 29 | } -------------------------------------------------------------------------------- /src/AtCoder/FourtuneCookies.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long int 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | ll a, b, c, d; 8 | cin >> a >> b >> c >> d; 9 | if (a == b + c + d) 10 | cout << "Yes" << endl; 11 | else if (b == a + c + d) 12 | cout << "Yes" << endl; 13 | else if (c == b + a + d) 14 | cout << "Yes" << endl; 15 | else if (d == b + c + a) 16 | cout << "Yes" << endl; 17 | else if (a + b == c + d) 18 | cout << "Yes" << endl; 19 | else if (c + a == b + d) 20 | cout << "Yes" << endl; 21 | else if (c + b == d + a) 22 | cout << "Yes" << endl; 23 | else 24 | cout << "No" << endl; 25 | return 0; 26 | } -------------------------------------------------------------------------------- /src/AtCoder/PlusMinus.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | We have given A, B. 3 | where, X+Y = A. 4 | X-Y = B. We have to find X,Y 5 | */ 6 | 7 | #include 8 | using namespace std; 9 | 10 | int main() 11 | { 12 | int a, b; 13 | cin >> a >> b; 14 | cout << (a + b) / 2 << " " << (a - b) / 2 << endl; 15 | return 0; 16 | } -------------------------------------------------------------------------------- /src/AtCoder/Quizzes.cpp: -------------------------------------------------------------------------------- 1 | // Problem Statement: https://atcoder.jp/contests/abc184/tasks/abc184_b 2 | 3 | #include 4 | #define lli long long int 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int n, x; 10 | string s; 11 | 12 | scanf("%d%d", &n, &x); 13 | cin >> s; 14 | int res = x; 15 | for (int i = 0; i < n; i++) 16 | { 17 | if (s[i] == 'o') 18 | res += 1; 19 | else if (s[i] == 'x' and res > 0) 20 | res -= 1; 21 | } 22 | printf("%d\n", res); 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /src/AtCoder/TakahashiUnevolved.cpp: -------------------------------------------------------------------------------- 1 | // https://atcoder.jp/contests/abc180/tasks/abc180_d 2 | 3 | #include 4 | #define ll long long int 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | ll x, y, a, b; 10 | cin >> x >> y >> a >> b; 11 | // X Y A B 12 | // 4 20 2 10 13 | ll str = x; 14 | ll exp = 0; 15 | 16 | while (str < y) 17 | { 18 | str *= 2; 19 | exp += 1; 20 | if (str < y) 21 | { 22 | str += b; 23 | exp += 1; 24 | } 25 | } 26 | cout << exp - 1 << endl; 27 | return 0; 28 | } -------------------------------------------------------------------------------- /src/AtCoder/TrapezoidSum.cpp: -------------------------------------------------------------------------------- 1 | // https://atcoder.jp/contests/abc181/tasks/abc181_b 2 | 3 | #include 4 | #define ll long long int 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | ll n; 10 | scanf("%lld", &n); 11 | vector a(n + 1), b(n + 1); 12 | ll sum = 0; 13 | 14 | for (int i = 0; i < n; i++) 15 | { 16 | scanf("%lld", &a[i]); 17 | scanf("%lld", &b[i]); 18 | } 19 | 20 | for (int i = 0; i < n; i++) 21 | for (int j = a[i]; j <= b[i]; j++) 22 | sum += j; 23 | 24 | printf("%lld\n", sum); 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /src/AtCoder/box.cpp: -------------------------------------------------------------------------------- 1 | // https://atcoder.jp/contests/abc180/tasks/abc180_a 2 | 3 | #include 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n, a, b; 9 | cin >> n >> a >> b; 10 | cout << (n - a) + b << endl; 11 | return 0; 12 | } -------------------------------------------------------------------------------- /src/Code-Chef/A1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int t; 7 | cin >> t; 8 | while (t--) 9 | { 10 | int n, m; 11 | cin >> n >> m; 12 | vector v(m + 1, 0); 13 | v[0] = true; 14 | while (n--) 15 | { 16 | int x; 17 | cin >> x; 18 | for (int p = m; p >= x; p--) 19 | v[p] = v[p - x] | v[p]; 20 | } 21 | string res = (v[m] ? "Yes" : "No"); 22 | cout << res << endl; 23 | } 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /src/Code-Chef/ACBALL.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int t; 7 | cin >> t; 8 | while (t--) 9 | { 10 | string x, y; 11 | cin >> x >> y; 12 | string z(x); 13 | cout << z << endl; 14 | for (int p = 0; p < z.size(); p++) 15 | { 16 | if (x[p] == 'B' && y[p] == 'B') 17 | z[p] = 'W'; 18 | else if (x[p] == 'W' && y[p] == 'W') 19 | z[p] = 'B'; 20 | else 21 | z[p] = 'B'; 22 | } 23 | cout << z << endl; 24 | } 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /src/Code-Chef/ADAMAT_AdaMatrix.py: -------------------------------------------------------------------------------- 1 | # cook your dish here 2 | t = int(input()) 3 | while(t>0): 4 | t-=1 5 | pp =int(input()) 6 | count=0; blist=[] 7 | for i in range(pp): 8 | blist.append([int(x) for x in input().split()]) 9 | for d in range(pp-1, 0, -1): 10 | done = blist[d][d-1]+1 11 | if done!=blist[d][d]: 12 | count+=1 13 | don = d+1 14 | for i in range(don): 15 | for j in range(i, don): 16 | trav = blist[i][j] 17 | blist[i][j] = blist[j][i] 18 | blist[j][i] = trav 19 | print(count) -------------------------------------------------------------------------------- /src/Code-Chef/ALEXNUMB.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int t; 7 | cin >> t; 8 | while (t--) 9 | { 10 | long long n; 11 | cin >> n; 12 | cout << n * (n - 1) / 2 << endl; 13 | } 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /src/Code-Chef/ALPHABET.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | const int N = 26; 7 | string a; 8 | cin >> a; 9 | vector v(N, 0); 10 | for (int p = 0; p < a.size(); p++) 11 | v[a[p] - 'a'] = 1; 12 | int t; 13 | cin >> t; 14 | while (t--) 15 | { 16 | string u; 17 | cin >> u; 18 | bool possible(1); 19 | for (int p = 0; p < u.size(); p++) 20 | if (!v[u[p] - 'a']) 21 | { 22 | possible = 0; 23 | break; 24 | } 25 | string res = (possible ? "Yes" : "No"); 26 | cout << res << endl; 27 | } 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /src/Code-Chef/AMMEAT2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | 6 | int numCases; scanf("%d\n",&numCases); 7 | 8 | int upperLimit = 0, numPlates = 0; 9 | while(numCases--){ 10 | scanf("%d %d\n", &upperLimit, &numPlates); 11 | if(upperLimit == 1 && numPlates == 1){printf("1");} 12 | else if(numPlates > upperLimit / 2){printf("-1");} 13 | else{for(int k = 1; k <= numPlates; k++){printf("%d ",2 * k);}} 14 | printf("\n"); 15 | } 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /src/Code-Chef/AMR15A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | int n; scanf("%d\n", &n); 6 | int ready(0); 7 | while(n--){ 8 | int a; scanf("%d", &a); 9 | ready += (a % 2) ? (-1) : 1; 10 | } 11 | 12 | puts((ready > 0) ? "READY FOR BATTLE" : "NOT READY"); 13 | 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /src/Code-Chef/AMSGAME1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | inline size_t gcd (size_t a, size_t b){return (b == 0) ? a : gcd (b, a%b);} 5 | 6 | int main(){ 7 | 8 | size_t length, temp = 0, output = 0; 9 | int numCases; scanf("%d\n",&numCases); 10 | while(numCases--){ 11 | scanf("%zd\n", &length); 12 | output = 0; 13 | for(size_t k = 0; k < length; k++){ 14 | scanf("%zd", &temp); 15 | output = gcd(output, temp); 16 | } 17 | printf("%zd\n",output); 18 | } 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /src/Code-Chef/ANUBTG.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(){ 6 | 7 | int t; scanf("%d\n", &t); 8 | while(t--){ 9 | long n; scanf("%ld\n", &n); 10 | std::vector v(n); 11 | for(long p = 0; p < n; p++){scanf("%ld", &v[p]);} 12 | sort(v.begin(), v.end()); 13 | long total(0); 14 | for(int p = 0; p < n; p++){total += ((n - 1 - p) % 4 <= 1) * v[p];} 15 | printf("%ld\n", total); 16 | } 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /src/Code-Chef/ANUDTC.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | const int C = 360; 6 | long t; scanf("%ld\n", &t); 7 | while(t--){ 8 | long n; scanf("%ld\n", &n); 9 | bool a1 = (C % n == 0); 10 | bool a2 = (n <= C); 11 | bool a3 = (n * (n + 1) / 2 <= C); 12 | printf("%c %c %c\n", (a1 ? 'y' : 'n'), (a2 ? 'y' : 'n'), (a3 ? 'y' : 'n')); 13 | } 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /src/Code-Chef/ANUTHM.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | int t; scanf("%d\n", &t); 6 | while(t--){ 7 | double n, m; scanf("%lf %lf\n", &n, &m); 8 | printf("%.7lf\n", m + n - 1); //The sum of each diagonal is equal to 1 :-) 9 | } 10 | 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /src/Code-Chef/ANUWTA.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | long t; scanf("%ld\n", &t); 6 | while(t--){ 7 | long long n; scanf("%lld\n", &n); 8 | printf("%lld\n", n * (n + 3) / 2); 9 | } 10 | 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /src/Code-Chef/APL3_AnAppleADay.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main() { 7 | int t, n; 8 | cin>>t; 9 | while(t--) { 10 | cin>>n; 11 | vector ar(n); 12 | fill(ar.begin(), ar.end(), 0); 13 | int count, sum=0; 14 | for(int i=0;i>ar[i]; 16 | sum += ar[i]; 17 | } 18 | float a = (float)sum/n; 19 | count = ceil(a); 20 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | size_t num = 103993, den = 33102, numDigits = 0; 6 | 7 | int numCases; scanf("%d\n",&numCases); 8 | while(numCases--){ 9 | num = 103993; den = 33102; 10 | scanf("%zd",&numDigits); 11 | printf("%zd", num / den); 12 | num = 10*(num % den); 13 | if(numDigits == 0){printf("\n");continue;} 14 | 15 | printf("."); 16 | for(size_t k = 0; k < numDigits; k++){printf("%zd", num/den); num = 10 * (num % den);} 17 | printf("\n"); 18 | } 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /src/Code-Chef/ARRANGE.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int binaryReverse(int input, int numBits){ 6 | int output = 0; 7 | for(int k = 0; k < numBits; k++){output = 2 * output + (input % 2); input /= 2;} 8 | return output; 9 | } 10 | 11 | 12 | int main(){ 13 | 14 | int numCases; scanf("%d",&numCases); 15 | while(numCases--){ 16 | int numBits;scanf("%d ",&numBits); 17 | size_t length = (size_t)pow(2.0,numBits); 18 | char *message = new char[length]; scanf("%s",message); 19 | for(int k = 0; k < length ; k++){printf("%c",message[binaryReverse(k,numBits)]);} 20 | printf("\n"); 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /src/Code-Chef/ARRAYTRM.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(){ 5 | 6 | int t; scanf("%d\n", &t); 7 | while(t--){ 8 | int n, k; scanf("%d %d\n", &n, &k); 9 | std::vector mods(k + 1, 0); 10 | for(int p = 0; p < n; p++){ 11 | int a; scanf("%d", &a); 12 | ++mods[a % (k + 1)]; 13 | } 14 | 15 | bool possible(false); 16 | for(int p = 0; p <= k; p++){if(mods[p] >= n - 1){possible = true; break;}} 17 | puts(possible ? "YES" : "NO"); 18 | } 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /src/Code-Chef/AVG.cpp: -------------------------------------------------------------------------------- 1 | // Problem Statement : https://www.codechef.com/problems/AVG 2 | 3 | #include 4 | #define lli long long int 5 | using namespace std; 6 | 7 | void test1() 8 | { 9 | int n, k, v; 10 | scanf("%d %d %d ", &n, &k, &v); 11 | int temp = 0, sum = 0; 12 | 13 | for (int i = 0; i < n; i++) 14 | { 15 | scanf("%d", &temp); 16 | sum += temp; 17 | } 18 | int ans = (v * (n + k) - sum) / k; 19 | if (ans <= 0 || ((v * (n + k) - sum) % k != 0)) 20 | printf("-1\n"); 21 | else 22 | printf("%d\n", ans); 23 | return; 24 | } 25 | 26 | int main() 27 | { 28 | int t; 29 | scanf("%d", &t); 30 | while (t--) 31 | test1(); 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /src/Code-Chef/BROKPHON.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(){ 5 | 6 | int t; scanf("%d\n", &t); 7 | while(t--){ 8 | long n; scanf("%ld\n", &n); 9 | std::vector a(n); 10 | std::vector b(n); 11 | for(int p = 0; p < n; p++){scanf("%ld", &a[p]);} 12 | for(int p = 1; p < n; p++){if(a[p] != a[p - 1]){b[p] = b[p - 1] = 1;}} 13 | long count(0); 14 | for(int p = 0; p < n; p++){count += b[p];} 15 | printf("%ld\n", count); 16 | } 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /src/Code-Chef/BUYING2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | 6 | int numCases; scanf("%d",&numCases); 7 | const int maxNote = 1000; 8 | int N, X, minNote, value; 9 | 10 | while(numCases--){ 11 | 12 | scanf("%d %d",&N, &X); 13 | int *banknotes = new int[N]; 14 | value = 0, minNote = maxNote; 15 | for(int k = 0; k < N; k++){ 16 | scanf("%d",banknotes + k); 17 | minNote = min(minNote, banknotes[k]); 18 | value += banknotes[k]; 19 | } 20 | 21 | if(value % X >= minNote){printf("-1\n");} 22 | else{printf("%d\n", value / X);} 23 | } 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /src/Code-Chef/CANDLE.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | 6 | size_t t; scanf("%zd",&t); 7 | int *counts = new int[10]; 8 | int min, candle; 9 | while(t--){ 10 | 11 | min = 9; 12 | for(int k = 0; k <= 9 ; k++){scanf("%d",(counts+k));} 13 | for(int k = 0; k <= 9 ; k++){ 14 | if( counts[k] < min ){ 15 | min = counts[k]; 16 | candle = k; 17 | } 18 | } 19 | 20 | if( candle == 0 ) {printf("1");} 21 | for(int k = 0 ; k <= min ; k++){printf("%d",candle);} 22 | printf("\n"); 23 | } 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /src/Code-Chef/CAPPLE.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(){ 5 | 6 | int t; scanf("%d\n", &t); 7 | while(t--){ 8 | long n; scanf("%ld\n", &n); 9 | std::set s; 10 | while(n--){long x; scanf("%ld", &x); s.insert(x);} 11 | printf("%ld\n", s.size()); 12 | } 13 | 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /src/Code-Chef/CARVANS.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main(){ 6 | 7 | int t; scanf("%d",&t); 8 | int n,currentMin,currentSpeed,maxSpeedCars; 9 | while(t--){ 10 | scanf("%d",&n); 11 | currentMin = INT_MAX; 12 | 13 | maxSpeedCars = 0; 14 | for(int k = 0; k < n ; k++){ 15 | scanf("%d",¤tSpeed); 16 | if(currentSpeed <= currentMin){ 17 | currentMin = currentSpeed; 18 | maxSpeedCars++; 19 | } 20 | } 21 | printf("%d\n",maxSpeedCars); 22 | } 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /src/Code-Chef/CHBLLNS.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | int t; scanf("%d\n", &t); 6 | while(t--){ 7 | long r, g, b; scanf("%ld %ld %ld\n", &r, &g, &b); 8 | long k; scanf("%ld\n", &k); 9 | long long ans(1); 10 | ans += (r < (k - 1)) ? r : (k - 1); 11 | ans += (g < (k - 1)) ? g : (k - 1); 12 | ans += (b < (k - 1)) ? b : (k - 1); 13 | printf("%lld\n", ans); 14 | } 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /src/Code-Chef/CHCHCL.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | int t; scanf("%d\n", &t); 6 | while(t--){ 7 | long long n, m; scanf("%lld %lld\n", &n, &m); 8 | puts( ((m % 2) && (n % 2)) ? "No" : "Yes"); 9 | } 10 | 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /src/Code-Chef/CHCOINSG.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | int t; scanf("%d\n", &t); 6 | while(t--){ 7 | long n; scanf("%ld\n", &n); 8 | puts((n % 6) ? "Chef" : "Misha"); 9 | } 10 | 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /src/Code-Chef/CHEFA.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(){ 6 | 7 | long t; scanf("%ld\n", &t); 8 | while(t--){ 9 | long n; scanf("%ld\n", &n); 10 | std::vector a(n); 11 | for(long p = 0; p < n; p++){scanf("%ld", &a[p]);} 12 | sort(a.begin(), a.end()); 13 | long long total(0); 14 | for(int p = (n + 1) % 2; p < n; p += 2){total += a[p];} 15 | printf("%lld\n", total); 16 | } 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /src/Code-Chef/CHEFCBA.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | long a, b, c, d; scanf("%ld %ld %ld %ld\n", &a, &b, &c, &d); 6 | puts((a * b == c * d) || (a * c == b * d) || (a * d == b * c) ? "Possible" : "Impossible"); 7 | 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /src/Code-Chef/CHEFCH.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | int t; scanf("%d\n", &t); 6 | while(t--){ 7 | std::string s; std::cin >> s; 8 | long a(0), b(0); 9 | for(size_t p = 0; p < s.size(); p++){ 10 | if(p % 2){ 11 | a += (s[p] == '+'); 12 | b += (s[p] == '-'); 13 | } 14 | else{ 15 | a += (s[p] == '-'); 16 | b += (s[p] == '+'); 17 | } 18 | } 19 | 20 | std::cout << ((a < b) ? a : b) << std::endl; 21 | } 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /src/Code-Chef/CHEFFED.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int sumDigits(long x){ 4 | int sum(0); 5 | while(x > 0){sum += x % 10; x /= 10;} 6 | return sum; 7 | } 8 | 9 | 10 | int main(){ 11 | 12 | long n; scanf("%ld\n", &n); 13 | long count(0); 14 | for(long p = n - 200; p <= n; p++){ 15 | if(p <= 0){continue;} 16 | count += (p + sumDigits(p) + sumDigits(sumDigits(p)) == n); 17 | } 18 | 19 | printf("%ld\n", count); 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /src/Code-Chef/CHEFGR.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(){ 5 | 6 | int t; scanf("%d\n", &t); 7 | while(t--){ 8 | long n, m; scanf("%ld %ld\n", &n, &m); 9 | std::vector a(n); 10 | long max(0); 11 | for(long p = 0; p < n; p++){ 12 | scanf("%ld", &a[p]); 13 | max = (a[p] > max) ? a[p] : max; 14 | } 15 | 16 | long needed(0); 17 | for(long p = 0; p < n; p++){needed += (max - a[p]);} 18 | puts((needed == m) || ((needed - m) % n == 0) ? "Yes" : "No"); 19 | } 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /src/Code-Chef/CHEFHOME.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(){ 6 | 7 | int t; scanf("%d\n", &t); 8 | while(t--){ 9 | int n; scanf("%d\n", &n); 10 | std::vector x(n); 11 | std::vector y(n); 12 | for(int p = 0; p < n; p++){scanf("%ld %ld\n", &x[p], &y[p]);} 13 | 14 | if(n % 2){puts("1"); continue;} 15 | 16 | long long num(1); 17 | sort(x.begin(), x.end()); 18 | sort(y.begin(), y.end()); 19 | num *= (1 + x[n/2] - x[(n - 1) / 2]); 20 | num *= (1 + y[n/2] - y[(n - 1) / 2]); 21 | printf("%lld\n", num); 22 | } 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /src/Code-Chef/CHEFLR.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | const long long MOD = 1000000007; 6 | int t; std::cin>> t; 7 | while(t--){ 8 | std::string s; std::cin >> s; 9 | long long x(1); 10 | for(long p = 0; p < s.size(); p++){ 11 | if((p % 2 == 0) && (s[p] == 'l')){x = 2 * x;} 12 | if((p % 2 == 0) && (s[p] == 'r')){x = 2 * x + 2;} 13 | if((p % 2 == 1) && (s[p] == 'l')){x = 2 * x - 1;} 14 | if((p % 2 == 1) && (s[p] == 'r')){x = 2 * x + 1;} 15 | x %= MOD; 16 | } 17 | 18 | std::cout << x << std::endl; 19 | } 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /src/Code-Chef/CHEFRP.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | int t; scanf("%d\n", &t); 6 | while(t--){ 7 | long n; scanf("%ld\n", &n); 8 | long total(0), min(1000000); 9 | while(n--){ 10 | long a; scanf("%ld\n", &a); 11 | total += a; 12 | min = (a < min) ? a : min; 13 | } 14 | 15 | if(min < 2){puts("-1");} 16 | else{printf("%ld\n", total - min + 2);} 17 | } 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /src/Code-Chef/CHEFSOCK.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | long j, s, m; scanf("%ld %ld %ld\n", &j, &s, &m); 6 | puts( (((m - j) / s) % 2) ? "Unlucky Chef" : "Lucky Chef"); 7 | 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /src/Code-Chef/CHEFST.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | long t; scanf("%ld\n", &t); 6 | while(t--){ 7 | long long n1, n2, m; scanf("%lld %lld %lld\n", &n1, &n2, &m); 8 | long long rem = (n1 < n2) ? n1 : n2; 9 | rem = (rem < (m * (m + 1) / 2)) ? rem : (m * (m + 1) / 2); 10 | printf("%lld\n", n1 + n2 - 2 * rem); 11 | } 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /src/Code-Chef/CHEFSTLT.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | int t; std::cin >> t; 6 | while(t--){ 7 | std::string s1, s2; std::cin >> s1 >> s2; 8 | int min(0), max(0); 9 | for(int p = 0; p < s1.size(); p++){ 10 | if(s1[p] != '?' && s2[p] != '?'){ 11 | min += (s1[p] != s2[p]); 12 | max += (s1[p] != s2[p]); 13 | } 14 | else{++max;} 15 | } 16 | 17 | std::cout << min << " " << max << std::endl; 18 | } 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /src/Code-Chef/CHN09.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | std::ios_base::sync_with_stdio(false); 6 | int t; std::cin >> t; 7 | while(t--){ 8 | std::string s; std::cin >> s; 9 | long countA(0), countB(0); 10 | for(size_t p = 0; p < s.size(); p++){ 11 | countA += (s[p] == 'a'); 12 | countB += (s[p] == 'b'); 13 | } 14 | 15 | std::cout << ((countA < countB) ? countA : countB) << std::endl; 16 | } 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /src/Code-Chef/CHOPRT.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | int t; scanf("%d\n", &t); 6 | while(t--){ 7 | long x, y; scanf("%ld %ld\n", &x, &y); 8 | if(x < y){puts("<");} 9 | else if(x > y){puts(">");} 10 | else if(x == y){puts("=");} 11 | } 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /src/Code-Chef/CHRECT.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | int t; scanf("%d\n", &t); 6 | while(t--){ 7 | int n, m, k; scanf("%d %d %d\n", &n, &m, &k); 8 | int ans(0); 9 | if((n==1 && m==1)|| (n==1 && m==2) || (n==2 && m==1)){ans=0;} 10 | else if(n==1 || m==1){ans=k;} 11 | else{ans=(k+1)/2;} 12 | printf("%d\n",ans); 13 | } 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /src/Code-Chef/CHRL2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | std::ios_base::sync_with_stdio(false); 6 | long c(0), h(0), e(0), f(0); 7 | std::string s; std::cin >> s; 8 | for(size_t p = 0; p < s.size(); p++){ 9 | if(s[p] == 'C'){++c;} 10 | else if(s[p] == 'H'){h += (h < c);} 11 | else if(s[p] == 'E'){e += (e < h);} 12 | else if(s[p] == 'F'){f += (f < e);} 13 | } 14 | 15 | std::cout << f << std::endl; 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /src/Code-Chef/CIELAB.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | 6 | int A,B,result; 7 | scanf("%d %d",&A , &B); 8 | result = ( (A - B) % 10 != 9) ? (A - B + 1):(A - B - 1); 9 | printf("%d\n",result); 10 | 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /src/Code-Chef/CIELRCPT.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(int argc, char* argv[]){ 5 | 6 | const size_t maxPrice = 2048; 7 | size_t divisor, menuItems, total; 8 | size_t N; scanf("%zd",&N); 9 | 10 | for(size_t k = 0; k < N ; k++){ 11 | size_t number; scanf("%zd",&number); 12 | 13 | divisor = maxPrice; 14 | total = 0; 15 | 16 | while(divisor > 0){ 17 | menuItems = number / divisor ; 18 | total += menuItems; 19 | number = number - (menuItems * divisor) ; 20 | if(number == 0){break;} 21 | divisor /= 2; 22 | } 23 | printf("%zd\n",total); 24 | } 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /src/Code-Chef/CLMBSTRS.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int countOnes(long long x){ 5 | int count(0); 6 | while(x > 0){count += (x % 2); x /= 2;} 7 | return count; 8 | } 9 | 10 | int main(){ 11 | 12 | const long N = 1000000; 13 | const long long MOD = 1000000007; 14 | std::vector f(N + 1); 15 | f[0] = 1; f[1] = 1; 16 | for(long p = 2; p <= N; p++){f[p] = (f[p - 1] + f[p - 2]) % MOD;} 17 | 18 | long t; scanf("%ld\n", &t); 19 | while(t--){ 20 | long n, g; scanf("%ld %ld\n", &n, &g); 21 | puts((countOnes(n) == g) ? "CORRECT" : "INCORRECT"); 22 | } 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /src/Code-Chef/CNOTE.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | long t; 6 | scanf("%ld\n", &t); 7 | while(t--) { 8 | long x, y, k, n; 9 | scanf("%ld %ld %ld %ld\n", &x, &y, &k, &n); 10 | bool possible(0); 11 | while(n--) { 12 | long a, b; 13 | scanf("%ld %ld\n", &a, &b); 14 | if((x - y <= a) && (b <= k)) 15 | possible = 1; 16 | } 17 | puts(possible ? "LuckyChef" : "UnluckyChef"); 18 | } 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /src/Code-Chef/COFDQ2.py: -------------------------------------------------------------------------------- 1 | # Problem Statement: https://www.codechef.com/COFDEC20/problems/COFDQ2 2 | 3 | R,C=map(int,input().split()) 4 | A=[] 5 | for i in range(R): 6 | p=list(map(int,input().split())) 7 | A.append(p) 8 | m, n = len(A), len(A[0]) 9 | for i in range(m): 10 | if A[i][0] == 0: 11 | for j in range(n): A[i][j] ^= 1 12 | 13 | for j in range(n): 14 | cnt = sum(A[i][j] for i in range(m)) 15 | if cnt < m - cnt: 16 | for i in range(m): A[i][j] ^= 1 17 | 18 | print(sum(int("".join(map(str, A[i])), 2) for i in range(m))) 19 | 20 | 21 | 22 | # Author: Ravi Kanth Gojur 23 | # Github: ravireddy07 24 | -------------------------------------------------------------------------------- /src/Code-Chef/COINS.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | long find(long n, std::map &memo){ 5 | 6 | if(n < 12){return n;} 7 | if(memo.count(n) > 0){return memo[n];} 8 | 9 | long cand = find(n/2, memo) + find(n / 3, memo) + find(n / 4, memo); 10 | long ans = (cand > n) ? cand : n; 11 | memo[n] = ans; 12 | return ans; 13 | } 14 | 15 | 16 | 17 | int main(){ 18 | 19 | long n; 20 | std::map computed; 21 | while(scanf("%ld\n", &n) == 1){printf("%ld\n", find(n, computed));} 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /src/Code-Chef/COLOR.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | int t; std::cin >> t; 6 | while(t--){ 7 | long n; std::cin >> n; 8 | std::string s; std::cin >> s; 9 | long r(0), b(0), g(0); 10 | for(long p = 0; p < s.size(); p++){ 11 | if(s[p] == 'R'){++r;} 12 | else if(s[p] == 'B'){++b;} 13 | else if(s[p] == 'G'){++g;} 14 | } 15 | 16 | long max = r; 17 | if(b > max){max = b;} 18 | if(g > max){max = g;} 19 | long ans = n - max; 20 | std::cout << ans << std::endl; 21 | } 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /src/Code-Chef/COMMUTE.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | 6 | int numCases; scanf("%d",&numCases); 7 | 8 | int numTrips,time, start, duration, freq, waitingTime; 9 | while(numCases--){ 10 | scanf("%d",&numTrips); 11 | time = 0; 12 | for(int trip = 0; trip < numTrips ; trip++){ 13 | scanf("%d %d %d",&start, &duration, &freq); 14 | waitingTime = (time <= start) ? (start - time) : freq - 1 - (time - start - 1)%freq ; 15 | time += waitingTime + duration ; 16 | } 17 | printf("%d\n",time); 18 | } 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /src/Code-Chef/CONFLIP.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | 6 | int numCases; scanf("%d\n",&numCases); 7 | int numGames = 0, I = 0, Q = 0; 8 | size_t N = 0; 9 | 10 | while(numCases--){ 11 | scanf("%d\n",&numGames); 12 | while(numGames--){ 13 | scanf("%d %zd %d\n", &I , &N , &Q); 14 | if( N%2 == 1 && I != Q){printf("%zd\n",(N+1)/2);} 15 | else{printf("%zd\n",N/2);} 16 | } 17 | } 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /src/Code-Chef/COOLGUYS.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | uint64_t gcd(uint64_t a, uint64_t b){return (a == 0) ? b : gcd(b % a, a);} 5 | 6 | int main(){ 7 | 8 | std::ios_base::sync_with_stdio(false); 9 | long t; std::cin >> t; 10 | while(t--){ 11 | uint64_t n; std::cin >> n; 12 | uint64_t num(0), den(n * n); 13 | for(long p=1; p * p <= n; p++){num += n / p;} 14 | num *= 2; 15 | long long sn = sqrt(n); 16 | num -= sn * sn; 17 | 18 | uint64_t div = gcd(num, den); 19 | num /= div; den /= div; 20 | std::cout << num << "/" << den << std::endl; 21 | } 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /src/Code-Chef/CSUB.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | std::ios_base::sync_with_stdio(false); 6 | long t; std::cin >> t; 7 | while(t--){ 8 | long n; std::cin >> n; 9 | std::string s; std::cin >> s; 10 | long long ones(0); 11 | for(size_t p = 0; p < n; p++){ones += (s[p] == '1');} 12 | std::cout << (ones * (ones + 1) / 2) << std::endl; 13 | } 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /src/Code-Chef/DCE05.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(){ 4 | unsigned long applicants = 0, position = 1; 5 | int numCases; scanf("%d\n",&numCases); 6 | while(numCases--){ 7 | scanf("%lu\n",&applicants); 8 | position = 1; while(position <= applicants){position *= 2;}; position /= 2; 9 | printf("%lu\n",position); 10 | } 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /src/Code-Chef/DEC2020-Long/EVENPSUM.cpp: -------------------------------------------------------------------------------- 1 | // Problem Statement: https://www.codechef.com/DEC20B/problems/EVENPSUM 2 | 3 | #include 4 | #define ll long long int 5 | using namespace std; 6 | 7 | void test() 8 | { 9 | ll a, b; 10 | scanf("%lld%lld", &a, &b); 11 | 12 | if (a == 1 and b == 1) 13 | printf("1\n"); 14 | else if (a % 2 != 0 and b % 2 != 0) 15 | printf("%lld\n", ((a * b) / 2) + 1); 16 | else 17 | printf("%lld\n", (a * b) / 2); 18 | return; 19 | } 20 | 21 | int main() 22 | { 23 | int t; 24 | scanf("%d", &t); 25 | while (t--) 26 | test(); 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /src/Code-Chef/DEC2020-Long/VACCINE1.cpp: -------------------------------------------------------------------------------- 1 | // Problem Statement: https://www.codechef.com/DEC20B/problems/VACCINE1 2 | 3 | #include 4 | #define ll long long int 5 | using namespace std; 6 | 7 | void test() 8 | { 9 | int d1, d2, v1, v2, p; 10 | scanf("%d %d %d %d %d", &d1, &v1, &d2, &v2, &p); 11 | int days = 1, vacc = 0; 12 | while (p > vacc) 13 | { 14 | if (days >= d1) 15 | vacc += v1; 16 | if (days >= d2) 17 | vacc += v2; 18 | days++; 19 | } 20 | printf("%d\n", days - 1); 21 | return; 22 | } 23 | 24 | int main() 25 | { 26 | /*int t; 27 | scanf("%d", &t); 28 | while (t--)*/ 29 | test(); 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /src/Code-Chef/DECSTR.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | 6 | const int numLetters = 26; 7 | int cases; scanf("%d",&cases); 8 | int positions, length; 9 | 10 | while(cases--){ 11 | scanf("%d",&positions); 12 | string msg = "",output = ""; 13 | length = positions + 1 + (positions-1)/(numLetters-1); 14 | for(int k = 0; k < length ; k++){msg += 'a'+ k % numLetters;} 15 | for(int k = 0; k < length ; k++){output += msg[length - k - 1];} 16 | cout << output << endl; 17 | } 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /src/Code-Chef/DEVARRAY.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | long n, q; scanf("%ld %ld\n", &n, &q); 6 | long min(1000000000), max(0); 7 | while(n--){ 8 | long x; scanf("%ld", &x); 9 | min = (x < min) ? x : min; 10 | max = (x > max) ? x : max; 11 | } 12 | 13 | while(q--){ 14 | long t; scanf("%ld\n", &t); 15 | puts((min <= t && t <= max) ? "Yes" : "No"); 16 | } 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /src/Code-Chef/DISTCODE.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(){ 5 | 6 | std::ios_base::sync_with_stdio(false); 7 | int t; std::cin >> t; 8 | while(t--){ 9 | std::string s; std::cin >> s; 10 | std::set codes; 11 | for(int p = 0; p < s.size() - 1; p++){codes.insert(s.substr(p, 2));} 12 | std::cout << codes.size() << std::endl; 13 | } 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /src/Code-Chef/DIVGAME-old.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(){ 5 | 6 | long n = 100000001; 7 | std::vector res(n + 1, 0); 8 | res[0] = 0; res[1] = 0; res[2] = 1; 9 | for(long p = 3; p <= n; p++){ 10 | if(res[p]){continue;} 11 | else if(!res[p - 1]){res[p] = 1;} 12 | else{for(long q = 2 * p; q <= n; q += p){res[q] = 1;}} 13 | } 14 | 15 | long t; scanf("%ld\n", &t); 16 | while(t--){ 17 | long x; scanf("%ld\n", &x); 18 | puts(res[x] ? "Mike" : "Tom"); 19 | } 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /src/Code-Chef/DIVGAME.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | bool game(long n){ 5 | if(n == 2){return true;} 6 | if(n == 16){return false;} 7 | if(n == 17){return true;} 8 | if(n == 34){return false;} 9 | if(n == 289){return false;} 10 | for(long p = 2; p * p <= n; p++){if(n % p == 0){return true;}} 11 | return false; 12 | } 13 | 14 | 15 | int main(){ 16 | 17 | long t; scanf("%ld\n", &t); 18 | while(t--){ 19 | long x; scanf("%ld\n", &x); 20 | puts(game(x) ? "Mike" : "Tom"); 21 | } 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /src/Code-Chef/DIVIDING.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | long long n; scanf("%ld\n", &n); 6 | long long s(0); 7 | for(long p = 0; p < n; p++){long long x; scanf("%lld", &x); s += x;} 8 | puts( (s == (n * (n + 1) / 2)) ? "YES" : "NO"); 9 | 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /src/Code-Chef/DONUTS.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | long t; scanf("%ld\n", &t); 6 | while(t--){ 7 | long n, m; scanf("%ld %ld\n", &n, &m); 8 | long a(0); 9 | for(int p = 0; p < m; p++){long x; scanf("%ld", &x); a += (x == 1);} 10 | long ans = m - a - 1; 11 | if(ans < m / 2){ans = m / 2;} 12 | printf("%ld\n", ans); 13 | } 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /src/Code-Chef/DOUBLE.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(int argc, char* argv[]){ 5 | size_t N; scanf("%zd",&N); 6 | 7 | size_t temp; 8 | for(size_t k = 0; k < N ; k++){ 9 | scanf("%zd",&temp); 10 | printf("%zd\n", temp - (temp % 2) ); 11 | } 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /src/Code-Chef/DRAGNXOR.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int countBinaryOnes(int x){ 5 | int output = 0; 6 | while(x > 0){output += x%2;x /= 2;} 7 | return output; 8 | } 9 | 10 | int main(){ 11 | 12 | int t; scanf("%d",&t); 13 | int x, y, N, a, b, c, output; 14 | 15 | while(t--){ 16 | scanf("%d %d %d", &N, &x, &y); 17 | a = countBinaryOnes(x); 18 | b = countBinaryOnes(y); 19 | c = (a + b < N) ? (a+b):(2*N -(a + b)); 20 | 21 | output = 0; 22 | for(int k = 0; k < N ; k++){output = 2 * output + (k < c);} 23 | printf("%d\n",output); 24 | } 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /src/Code-Chef/EASYPROB.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | printf("137=2(2(2)+2+2(0))+2(2+2(0))+2(0)\n"); 4 | printf("1315=2(2(2+2(0))+2)+2(2(2+2(0)))+2(2(2)+2(0))+2+2(0)\n"); 5 | printf("73=2(2(2)+2)+2(2+2(0))+2(0)\n"); 6 | printf("136=2(2(2)+2+2(0))+2(2+2(0))\n"); 7 | printf("255=2(2(2)+2+2(0))+2(2(2)+2)+2(2(2)+2(0))+2(2(2))+2(2+2(0))+2(2)+2+2(0)\n"); 8 | printf("1384=2(2(2+2(0))+2)+2(2(2+2(0)))+2(2(2)+2)+2(2(2)+2(0))+2(2+2(0))\n"); 9 | printf("16385=2(2(2+2(0))+2(2)+2)+2(0)\n"); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /src/Code-Chef/EMA01.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | long long x(0); 6 | while(scanf("%lld\n", &x) != EOF){ 7 | long long pow = 5; 8 | long long count(0); 9 | while(pow <= x){count += x / pow; pow *= 5;} 10 | printf("%lld\n", count); 11 | } 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /src/Code-Chef/EQUALITY.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(){ 5 | 6 | long t; scanf("%ld\n", &t); 7 | while(t--){ 8 | long n; scanf("%ld\n", &n); 9 | std::vector a(n); 10 | long long sum(0); 11 | for(long p = 0; p < n; p++){ 12 | scanf("%lld", &a[p]); 13 | sum += a[p]; 14 | } 15 | 16 | long long A = sum / (n - 1); 17 | 18 | for(long p = 0; p < n; p++){printf("%lld ", A - a[p]);} 19 | puts(""); 20 | } 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /src/Code-Chef/EQUATION.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | long long Nc3(long long n){ 5 | if(n < 0){return 0;} 6 | return (n+1)*(n+2)*(n+3)/6; 7 | } 8 | 9 | 10 | int main(){ 11 | 12 | int numCases; scanf("%d\n",&numCases); 13 | long long A = 0, B = 0, C = 0, N = 0, output = 0; 14 | while(numCases--){ 15 | scanf("%lld %lld %lld %lld\n", &N, &A, &B, &C); 16 | output = Nc3(N) - Nc3(N-A-1) - Nc3(N-B-1) - Nc3(N-C-1) + Nc3(N-A-B-2) + Nc3(N-B-C-2) + Nc3(N-A-C-2) - Nc3(N-A-B-C-3); 17 | printf("%lld\n",output); 18 | } 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /src/Code-Chef/ERROR.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | std::ios_base::sync_with_stdio(false); 6 | int t; 7 | std::cin >> t; 8 | const std::string a = "010"; 9 | const std::string b = "101"; 10 | while (t--) 11 | { 12 | std::string s; 13 | std::cin >> s; 14 | std::cout << ((s.find(a) == std::string::npos && s.find(b) == std::string::npos) ? "Bad" : "Good") << std::endl; 15 | } 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /src/Code-Chef/FCTRL.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(int argc, char *argv[]){ 5 | size_t inputNumber, factor, output; 6 | int N; cin >> N; 7 | 8 | for(size_t k = 0; k < N ; k++){ 9 | cin >> inputNumber; 10 | factor = 5, output = 0; 11 | while(factor <= inputNumber){ 12 | output += inputNumber / factor; 13 | factor *= 5; 14 | } 15 | cout << output << endl; 16 | } 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /src/Code-Chef/FINXOR_Find-XOR.py: -------------------------------------------------------------------------------- 1 | tc = int(input()) 2 | for i in range(22): 3 | a=[0]*i 4 | a[0]= 1 5 | for i in range(1,21): 6 | a[i] = 2*a[i-1] 7 | while(tc != 0): 8 | n = int(input()) 9 | print(1," ",a[20]) 10 | 11 | sum1 = int(input()) 12 | sum1 = sum1 - (a[20]*n) 13 | 14 | xor = 0 15 | if(sum1%2 != 0): 16 | xor= xor+1 17 | 18 | for i in range(1,20): 19 | usersum = sum1+(a[i]*n) 20 | print(1," ",a[i]) 21 | 22 | givensum = int(input()) 23 | if(((usersum-givensum)/(a[i]*2))%2 != 0): 24 | xor+=a[i] 25 | print(2," ",xor,"\n") 26 | output = int(input()) 27 | tc-=1 -------------------------------------------------------------------------------- /src/Code-Chef/FIRSTTEST.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main( int argc , char *argv[] ){ 5 | 6 | int inputNumber = 0; 7 | const int answer = 42; 8 | 9 | while(true){ 10 | cin >> inputNumber; 11 | if(inputNumber == answer){break;} 12 | cout << inputNumber << endl; 13 | } 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /src/Code-Chef/FLOW001.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | int T; scanf("%d\n", &T); 6 | while(T--){ 7 | long a, b; scanf("%ld %ld\n", &a, &b); 8 | printf("%ld\n", a + b); 9 | } 10 | 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /src/Code-Chef/FLOW002.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | int T; scanf("%d\n", &T); 6 | while(T--){ 7 | long x, y; scanf("%ld %ld\n", &x, &y); 8 | printf("%ld\n", x % y); 9 | } 10 | 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /src/Code-Chef/FLOW004.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int getLSD(long x){return (x % 10);} 4 | int getMSD(long x){while(x > 9){x /= 10;}; return x;} 5 | 6 | int main(){ 7 | 8 | int t; scanf("%d\n", &t); 9 | while(t--){ 10 | long a; scanf("%ld\n", &a); 11 | printf("%d\n", getLSD(a) + getMSD(a)); 12 | } 13 | 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /src/Code-Chef/FLOW005.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(){ 5 | 6 | std::vector v(6); 7 | v[0] = 100; v[1] = 50; v[2] = 10; v[3] = 5; v[4] = 2; v[5] = 1; 8 | 9 | int t; scanf("%d\n", &t); 10 | while(t--){ 11 | long n; scanf("%ld\n", &n); 12 | long count(0); 13 | for(int p = 0; p < v.size(); p++){count += n / v[p]; n %= v[p];} 14 | printf("%ld\n", count); 15 | } 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /src/Code-Chef/FLOW006.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int sumOfDigits(long x){ 4 | int res(0); 5 | while(x > 0){res += (x % 10); x /= 10;} 6 | return res; 7 | } 8 | 9 | 10 | int main(){ 11 | 12 | int T; scanf("%d\n", &T); 13 | while(T--){ 14 | long num; scanf("%ld\n", &num); 15 | printf("%d\n", sumOfDigits(num)); 16 | } 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /src/Code-Chef/FLOW007.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | long numReverse(long x){ 5 | 6 | if(x <= 0){return x;} 7 | std::vector digits; 8 | while(x > 0){digits.push_back(x % 10); x /= 10;} 9 | long res(0); 10 | for(int p = 0; p < digits.size(); p++){res = 10 * res + digits[p];} 11 | return res; 12 | } 13 | 14 | int main(){ 15 | 16 | int T; scanf("%d\n", &T); 17 | while(T--){ 18 | long n; scanf("%ld\n", &n); 19 | printf("%ld\n", numReverse(n)); 20 | } 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /src/Code-Chef/FLOW008.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | int t; scanf("%d\n", &t); 6 | while(t--){ 7 | int n; scanf("%d\n", &n); 8 | puts((n < 10) ? "What an obedient servant you are!" : "-1"); 9 | } 10 | 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /src/Code-Chef/FLOW009.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | const double Q = 1000.0; 6 | const double mult = 0.9; 7 | int t; scanf("%d\n", &t); 8 | while(t--){ 9 | double q, p; scanf("%lf %lf\n", &q, &p); 10 | if(q > Q){p *= mult;} 11 | printf("%.6lf\n", p * q); 12 | } 13 | 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /src/Code-Chef/FLOW010.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(){ 5 | 6 | int t; std::cin >> t; 7 | while(t--){ 8 | std::string s; std::cin >> s; 9 | if(s[0] == 'B' || s[0] == 'b'){puts("BattleShip");} 10 | else if(s[0] == 'C' || s[0] == 'c'){puts("Cruiser");} 11 | else if(s[0] == 'D' || s[0] == 'd'){puts("Destroyer");} 12 | else if(s[0] == 'F' || s[0] == 'f'){puts("Frigate");} 13 | } 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /src/Code-Chef/FLOW011.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | const long B = 1500; 6 | int t; scanf("%d\n", &t); 7 | while(t--){ 8 | long base; scanf("%ld\n", &base); 9 | double total(0); 10 | if(base < B){total = 2 * base;} 11 | else{total = 500 + 1.98 * base;} 12 | printf("%g\n", total); 13 | } 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /src/Code-Chef/FLOW013.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | int T; scanf("%d\n", &T); 6 | while(T--){ 7 | int a, b, c; scanf("%d %d %d\n", &a, &b, &c); 8 | puts((a > 0 && b > 0 && c > 0 && a + b + c == 180) ? "YES" : "NO"); 9 | } 10 | 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /src/Code-Chef/FLOW014.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | const double h = 50; 6 | const double c = 0.7; 7 | const double s = 5600; 8 | 9 | int t; scanf("%d\n", &t); 10 | while(t--){ 11 | double x, y, z; scanf("%lf %lf %lf\n", &x, &y, &z); 12 | if((x > h) && (y < c) && (z > s)){puts("10");} 13 | else if((x > h) && (y < c)){puts("9");} 14 | else if((y < c) && (z > s)){puts("8");} 15 | else if((x > h) && (z > s)){puts("7");} 16 | else if((x > h) || (y < c) || (z > s)){puts("6");} 17 | else if(!(x > h) && !(y < c) && !(z > s)){puts("5");} 18 | else{puts("-1");} 19 | } 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /src/Code-Chef/FLOW016.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | long gcd(long a, long b){return (a == 0) ? b : gcd(b % a, a);} 4 | 5 | int main(){ 6 | 7 | int T; scanf("%d\n", &T); 8 | while(T--){ 9 | 10 | long x, y; scanf("%ld %ld\n", &x, &y); 11 | printf("%ld %ld\n", gcd(x, y), (x * y / gcd(x, y))); 12 | } 13 | 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /src/Code-Chef/FLOW017.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | int t; scanf("%d\n", &t); 6 | while(t--){ 7 | long a, b, c; scanf("%ld %ld %ld\n", &a, &b, &c); 8 | long res(0); 9 | if(a <= b && b <= c){res = b;} 10 | else if(a <= c && c <= b){res = c;} 11 | else if(b <= a && a <= c){res = a;} 12 | else if(b <= c && c <= a){res = c;} 13 | else if(c <= a && a <= b){res = a;} 14 | else if(c <= b && b <= a){res = b;} 15 | 16 | printf("%ld\n", res); 17 | } 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /src/Code-Chef/FLOW018.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int64_t factorial(int a){ 4 | int64_t res(1); 5 | for(int p = 1; p <= a; p++){res *= p;} 6 | return res; 7 | } 8 | 9 | 10 | int main(){ 11 | 12 | int T; std::cin >> T; 13 | while(T--){ 14 | int64_t x; std::cin >> x; 15 | std::cout << factorial(x) << std::endl; 16 | } 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /src/Code-Chef/FROGV.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(){ 6 | 7 | long n, k, p; scanf("%ld %ld %ld\n", &n, &k, &p); 8 | std::vector > x(n); 9 | for(int r = 0; r < n; r++){ 10 | long d; scanf("%ld", &d); 11 | x[r] = std::make_pair(d, r + 1); 12 | } 13 | sort(x.begin(), x.end()); 14 | std::vector g(n + 1); 15 | g[0] = x[0].second; 16 | for(int r = 0; r < n; r++){g[r] = (x[r - 1].first + k < x[r].first) ? x[r].second : g[r - 1];} 17 | while(p--){ 18 | long a, b; scanf("%ld %ld\n", &a, &b); 19 | puts( (g[a] == g[b]) ? "Yes" : "No"); 20 | } 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /src/Code-Chef/FRUITS.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | int t; scanf("%d\n", &t); 6 | while(t--){ 7 | int n, m, k; scanf("%d %d %d\n", &n, &m, &k); 8 | int diff = n - m; if(diff < 0){diff = -diff;} 9 | diff = (diff < k) ? 0 : (diff - k); 10 | printf("%d\n", diff); 11 | } 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /src/Code-Chef/FSQRT.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(){ 5 | 6 | int T; std::cin >> T; 7 | while(T--){ 8 | long x; std::cin >> x; 9 | long r = sqrt(x); 10 | std::cout << r << std::endl; 11 | } 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /src/Code-Chef/GCD2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | long gcd (long a, long b){return (b == 0) ? a : gcd (b, a%b);} 4 | 5 | int main(){ 6 | 7 | int t(0); scanf("%d\n", &t); 8 | while(t--){ 9 | long a; std::string b; std::cin >> a >> b; 10 | if(a == 0){std::cout << b << std::endl; continue;} 11 | 12 | long c(0); 13 | for(int p = 0; p < b.size(); p++){ 14 | c = 10 * c + (b[p] - '0'); 15 | c %= a; 16 | } 17 | 18 | std::cout << gcd(a, c) << std::endl; 19 | } 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /src/Code-Chef/GDOG.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | int t; scanf("%d\n", &t); 6 | while(t--){ 7 | long n, k; scanf("%ld %ld\n", &n, &k); 8 | long max(0); 9 | for(int p = 1; p <= k; p++){ 10 | if(max < (n % p)){max = n % p;} 11 | } 12 | 13 | printf("%ld\n", max); 14 | } 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /src/Code-Chef/GIVCANDY.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | long long gcd(long long a, long long b){return (a == 0) ? b : gcd(b % a, a);} 4 | 5 | int main(){ 6 | 7 | long t; scanf("%ld", &t); 8 | while(t--){ 9 | long long a, b, c, d; scanf("%lld %lld %lld %lld\n", &a, &b, &c, &d); 10 | long long f = (a < b) ? (b - a) : (a - b); 11 | long long g = gcd(c, d); 12 | f %= g; 13 | long long ans = (f < g - f) ? f : (g - f); 14 | printf("%lld\n", ans); 15 | } 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /src/Code-Chef/HEADBOB.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(){ 5 | 6 | std::ios_base::sync_with_stdio(false); 7 | int T; std::cin >> T; 8 | while(T--){ 9 | int len; std::string s; std::cin >> len >> s; 10 | bool y(0), n(0), i(0); 11 | for(int p = 0; p < s.size(); p++){ 12 | if(s[p] == 'Y'){y = 1;} 13 | else if(s[p] == 'N'){n = 1;} 14 | else if(s[p] == 'I'){i = 1;} 15 | } 16 | 17 | if(i){puts("INDIAN");} 18 | else if(y){puts("NOT INDIAN");} 19 | else{puts("NOT SURE");} 20 | } 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /src/Code-Chef/HELPLIRA.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | int n; scanf("%d\n", &n); 6 | double min(1e8), max(-1); 7 | int mintr(0), maxtr(0); 8 | for(int p = 1; p <= n; p++){ 9 | long x1, y1, x2, y2, x3, y3; scanf("%ld %ld %ld %ld %ld %ld\n", &x1, &y1, &x2, &y2, &x3, &y3); 10 | double area = 0.5 *((x1 - x3) * (y2 - y1) - (x1 - x2) * (y3 - y1)); //Shoelace formula 11 | if(area < 0){area = -area;} 12 | if(area <= min){min = area; mintr = p;} 13 | if(area >= max){max = area; maxtr = p;} 14 | } 15 | 16 | printf("%d %d\n", mintr, maxtr); 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /src/Code-Chef/HOLES.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(int argc, char * argv[]){ 5 | 6 | int holes[26]={1,2,0,1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0}; 7 | // A B C D E F G H I J K L M N O P Q R S T U V W X Y Z; 8 | 9 | string input; 10 | size_t N,output; 11 | 12 | scanf("%zd\n",&N); 13 | for(size_t k = 0; k < N ;k++){ 14 | getline(cin,input); 15 | output =0; 16 | for(size_t m = 0; m < input.size(); m++){output += holes[ input[m]-'A'];} 17 | cout << output << endl; 18 | } 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /src/Code-Chef/HS08TEST.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(int argc, char* argv[]){ 5 | 6 | size_t withdrawal;double currentBalance; 7 | 8 | cin >> withdrawal; 9 | cin >> currentBalance; 10 | 11 | const double fee = 0.5; 12 | double newBalance = currentBalance; 13 | 14 | if( (withdrawal % 5) == 0 && currentBalance > withdrawal + fee){newBalance = currentBalance - (withdrawal + fee);} 15 | cout << newBalance << endl; 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /src/Code-Chef/INTEST.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | 6 | size_t n,k; scanf("%zd %zd", &n, &k); 7 | size_t currentInput, counter = 0; 8 | 9 | for(size_t m = 0; m < n ; m++){ 10 | scanf("%zd", ¤tInput); 11 | if(currentInput % k == 0){counter++;} 12 | } 13 | cout << counter << endl; 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /src/Code-Chef/IPCCERT.cpp: -------------------------------------------------------------------------------- 1 | // Problem Statemnet: https://www.codechef.com/COOK124B/problems/IPCCERT 2 | 3 | #include 4 | #define lli long long int 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | lli n, m, k; 10 | scanf("%lld %lld %lld", &n, &m, &k); 11 | 12 | lli v[n][n]; 13 | lli q[n]; 14 | 15 | lli sum, res = 0; 16 | 17 | for (int i = 0; i < n; i++) 18 | { 19 | sum = 0; 20 | for (int j = 0; j < n; j++) 21 | { 22 | scanf("%lld", &v[i][j]); 23 | sum += v[i][j]; 24 | } 25 | scanf("%lld", &q[i]); 26 | if (sum >= m and q[i] <= 10) 27 | res++; 28 | } 29 | 30 | printf("%lld\n", res); 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /src/Code-Chef/J7.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main(int argc, char* argv[]){ 6 | 7 | size_t N; scanf("%zd",&N); 8 | float L, S, D; 9 | double x, y, z, vol; 10 | 11 | for(size_t k = 0; k < N ; k++){ 12 | scanf("%f %f",&L,&S); 13 | D = sqrt(L*L - 24*S); 14 | x = (L - D) / 12.0; 15 | y = (L - D) / 12.0; 16 | z = (L +2*D) / 12.0; 17 | vol = x * y * z; 18 | printf("%.2f\n",vol); 19 | } 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /src/Code-Chef/JOHNY.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(){ 5 | 6 | int t; scanf("%d\n", &t); 7 | while(t--){ 8 | int n; scanf("%d\n", &n); 9 | std::vector a(n, 0); 10 | for(int p = 0; p < n; p++){scanf("%ld ", &a[p]);} 11 | int k; scanf("%d\n", &k); 12 | long x = a[k - 1]; 13 | int count(0); 14 | for(int p = 0; p < n; p++){count += (a[p] <= x);} 15 | printf("%d\n", count); 16 | } 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /src/Code-Chef/KTTABLE.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | int main(){ 6 | 7 | int t; scanf("%d\n", &t); 8 | while(t--){ 9 | long n; scanf("%ld\n", &n); 10 | std::vector a(n); 11 | for(int p = 0; p < n; p++){scanf("%ld", &a[p]);} 12 | std::vector b(n); 13 | for(int p = 0; p < n; p++){scanf("%ld", &b[p]);} 14 | 15 | long count(b[0] <= a[0]); 16 | for(int p = 1; p < n; p++){count += (b[p] <= a[p] - a[p - 1]);} 17 | printf("%ld\n", count); 18 | } 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /src/Code-Chef/LCH15JAB.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(){ 6 | 7 | const int N = 26; 8 | int t; std::cin >> t; 9 | while(t--){ 10 | std::string s; std::cin >> s; 11 | std::vector count(N, 0); 12 | for(int p = 0; p < s.size(); p++){++count[s[p] - 'a'];} 13 | sort(count.begin(), count.end()); 14 | std::cout << ((2 * count[N - 1] == s.size()) ? "YES" : "NO") << std::endl; 15 | } 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /src/Code-Chef/LCKYST.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | long n; scanf("%ld\n", &n); 6 | while(n--){ 7 | long long a; scanf("%lld\n", &a); 8 | int fives(0), twos(0); 9 | long long b(a); 10 | while(b % 2 == 0){++twos; b /= 2;} 11 | while(b % 5 == 0){++fives; b /= 5;} 12 | int diff = fives - twos; 13 | 14 | for(int p = 0; p < (diff + 1) / 2; p++){a *= 4;} 15 | printf("%lld\n", a); 16 | 17 | } 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /src/Code-Chef/LCOLLIS.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(){ 5 | 6 | std::ios_base::sync_with_stdio(false); 7 | int t; std::cin >> t; 8 | while(t--){ 9 | int n, m; std::cin >> n >> m; 10 | std::vector count(m, 0); 11 | while(n--){ 12 | std::string s; std::cin >> s; 13 | for(int p = 0; p < m; p++){count[p] += (s[p] == '1');} 14 | } 15 | 16 | long total(0); 17 | for(int p = 0; p < m; p++){total += count[p] * (count[p] - 1) / 2;} 18 | std::cout << total << std::endl; 19 | } 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /src/Code-Chef/LEBOMBS.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | 6 | string input, shiftLeft, shiftRight; 7 | int numCases; scanf("%d\n",&numCases); 8 | while(numCases--){ 9 | int numBuildings; scanf("%d\n",&numBuildings); 10 | getline(cin, input); 11 | shiftLeft = input.substr(1,numBuildings-1)+'0'; 12 | shiftRight = '0'+input.substr(0,numBuildings-1); 13 | size_t destroyed = 0; 14 | for(size_t k = 0; k < numBuildings; k++){if(input[k] == '1' || shiftLeft[k] == '1' || shiftRight[k] == '1'){destroyed++;}} 15 | printf("%zd\n",numBuildings - destroyed); 16 | } 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /src/Code-Chef/LECANDY.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | int t; scanf("%d",&t); 6 | size_t temp, sum, N, C; 7 | while(t--){ 8 | scanf("%zd %zd",&N, &C); 9 | sum = 0; 10 | for(size_t k = 0; k < N ; k++){ 11 | scanf("%zd",&temp); 12 | sum += temp; 13 | } 14 | if(sum <= C){printf("Yes\n");} 15 | else{printf("No\n");} 16 | } 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /src/Code-Chef/LEDIV.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | long gcd(long a, long b){return (a == 0) ? b : gcd(b % a, a);} 4 | 5 | int main(){ 6 | 7 | long t; scanf("%ld\n", &t); 8 | while(t--){ 9 | long n; scanf("%ld\n", &n); 10 | long g(0); 11 | while(n--){ 12 | long x; scanf("%ld", &x); 13 | g = gcd(g, x); 14 | } 15 | 16 | if(g > 1){ 17 | long ans(g); 18 | for(long p = 2; p * p <= g; p++){if(g % p == 0){ans = p; break;}} 19 | printf("%ld\n", ans); 20 | } 21 | else{puts("-1");} 22 | } 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /src/Code-Chef/LFEB14B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | const long long MOD = 1000000007; 6 | 7 | int t; scanf("%d\n", &t); 8 | while(t--){ 9 | long n; scanf("%ld\n", &n); 10 | long max(0), maxCount(0); 11 | while(n--){ 12 | long a; scanf("%ld", &a); 13 | if(a > max){max = a; maxCount = 1;} 14 | else if(a == max){++maxCount;} 15 | } 16 | 17 | long long ans(1); 18 | for(long p = 0; p < maxCount; p++){ans *= 2; ans %= MOD;} 19 | ans = (ans + MOD - 1) % MOD; 20 | printf("%lld\n", ans); 21 | } 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /src/Code-Chef/LUCKFOUR.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | int T; scanf("%d\n", &T); 6 | while(T--){ 7 | long x; scanf("%ld\n", &x); 8 | int count(0); 9 | while(x > 0){count += (x % 10 == 4); x /= 10;} 10 | printf("%d\n", count); 11 | } 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /src/Code-Chef/LUCKY5.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | std::ios_base::sync_with_stdio(false); 6 | int t; std::cin >> t; 7 | while(t--){ 8 | std::string s; std::cin >> s; 9 | int count(0); 10 | for(size_t p = 0; p < s.size(); p++){count += ((s[p] != '4') && (s[p] != '7'));} 11 | std::cout << count << std::endl; 12 | } 13 | 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /src/Code-Chef/LUCKYSTR.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main(){ 6 | 7 | const int luckySize = 47; 8 | int K = 0, N = 0; 9 | scanf("%d %d\n", &K, &N); 10 | 11 | string number = ""; vector likes; bool found = 0; 12 | for(int v = 0; v < K ; v++){getline(cin,number);likes.push_back(number);} 13 | 14 | for(int u = 0; u < N ; u++){ 15 | getline(cin, number); 16 | 17 | if(number.size() >= luckySize){printf("Good\n");continue;} 18 | 19 | found = 0; 20 | for(int v = 0; v < K ; v++){if(number.find(likes[v]) != string::npos){found = 1; break;}} 21 | if(found){printf("Good\n");} else{printf("Bad\n");} 22 | } 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /src/Code-Chef/MAKEART.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(){ 5 | 6 | long t; scanf("%ld\n", &t); 7 | while(t--){ 8 | long n; scanf("%ld\n", &n); 9 | std::vector a(n, 0); 10 | for(long p = 0; p < n; p++){scanf("%ld", &a[p]);} 11 | bool possible(0); 12 | for(int p = 2; p < n; p++){if(a[p] == a[p - 1] && a[p] == a[p - 2]){possible = 1; break;}} 13 | puts(possible ? "Yes" : "No"); 14 | } 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /src/Code-Chef/MARBLES.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | uint64_t gcd(uint64_t a, uint64_t b){return (a == 0) ? b : gcd(b % a, a);} 4 | 5 | uint64_t nCr(uint64_t n, uint64_t k){ 6 | 7 | uint64_t num(1), den(1); 8 | for(int p = 1; p <= k; p++){ 9 | num *= (n - k + p); den *= p; 10 | uint64_t div = gcd(num, den); 11 | num /= div; den /= div; 12 | } 13 | 14 | return (num / den); //den should be trivially one; 15 | } 16 | 17 | 18 | int main(){ 19 | 20 | std::ios_base::sync_with_stdio(false); 21 | int t; std::cin >> t; 22 | while(t--){ 23 | long n, r; std::cin >> n >> r; 24 | std::cout << nCr(n - 1, r - 1) << std::endl; 25 | } 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /src/Code-Chef/MARCHA1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | bool checkSum(int amount, std::vector money, int start){ 5 | if(amount == 0){return 1;} 6 | if(start < 0 || amount < 0 || start >= money.size()){return 0;} 7 | return checkSum(amount - money[start], money, start + 1) || checkSum(amount, money, start + 1); 8 | } 9 | 10 | 11 | int main(){ 12 | 13 | 14 | int numCases(0); scanf("%d\n", &numCases); 15 | while(numCases--){ 16 | int n(0), m(0); scanf("%d %d", &n, &m); 17 | std::vector money(n,0); for(int k = 0; k < n; k++){scanf("%d", &money[k]);} 18 | puts(checkSum(m, money, 0) ? "Yes" : "No"); 19 | 20 | } 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /src/Code-Chef/MAXDIFF.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(){ 6 | 7 | int t; scanf("%d\n", &t); 8 | while(t--){ 9 | int n, k; scanf("%d %d\n", &n, &k); 10 | std::vector w(n); 11 | long long total(0); 12 | for(int p = 0; p < n; p++){scanf("%ld", &w[p]); total += w[p];} 13 | sort(w.begin(), w.end()); 14 | long long small(0); 15 | for(int p = 0; p < k; p++){small += w[p];} 16 | printf("%lld\n", total - 2 * small); 17 | } 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /src/Code-Chef/MCHAIRS.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(){ 5 | 6 | const long long MOD = 1000000007; 7 | int t; scanf("%d\n", &t); 8 | while(t--){ 9 | long n; scanf("%ld\n", &n); 10 | long long res(1); 11 | std::vector b; 12 | while(n > 0){b.push_back(n % 2); n /= 2;} 13 | for(int p = b.size() - 1; p >= 0; p--){ 14 | res = res * res; 15 | if(b[p]){res *= 2;} 16 | res %= MOD; 17 | } 18 | 19 | res = (res + MOD - 1) % MOD; 20 | printf("%lld\n", res); 21 | } 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /src/Code-Chef/MIKE2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(){ 6 | 7 | long long n, x; scanf("%lld %lld\n", &n, &x); 8 | std::vector a(n, 0); 9 | for(long long p = 0; p < n; p++){scanf("%lld", &a[p]);} 10 | sort(a.begin(), a.end()); 11 | 12 | long long failed(n); 13 | for(int p = 0; p < n; p++){ 14 | long long needed = (a[p] + 1) / 2; 15 | if(x >= needed){a[p] -= needed; x -= needed; --failed;} 16 | } 17 | 18 | long long succeeded(0); 19 | for(int p = 0; p < n; p++){if(x >= a[p]){x -= a[p]; ++succeeded;}} 20 | 21 | printf("%lld %lld\n", failed, succeeded); 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /src/Code-Chef/MISSP.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | int t; scanf("%d\n", &t); 6 | while(t--){ 7 | long n; scanf("%ld\n", &n); 8 | long a(0); 9 | while(n--){long x; scanf("%ld\n", &x); a ^= x;} 10 | printf("%ld\n", a); 11 | } 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /src/Code-Chef/MNMX.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | int t; scanf("%d\n", &t); 6 | while(t--){ 7 | long long n; scanf("%lld\n", &n); 8 | long long min(1000000); 9 | for(long long p = 0; p < n; p++){ 10 | long long a; scanf("%lld", &a); 11 | min = (a < min) ? a : min; 12 | } 13 | printf("%lld\n", (n - 1) * min); 14 | } 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /src/Code-Chef/MOVIEWKN.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(){ 5 | 6 | int t; scanf("%d\n", &t); 7 | while(t--){ 8 | int n; scanf("%d\n", &n); 9 | std::vector l(n, 0); 10 | for(int p = 0; p < n; p++){scanf("%ld", &l[p]);} 11 | std::vector r(n, 0); 12 | for(int p = 0; p < n; p++){scanf("%ld", &r[p]);} 13 | 14 | long prodMax(0), rmax(0), pick(0); 15 | for(int p = 0; p < n; p++){ 16 | if((l[p] * r[p] > prodMax) || (l[p] * r[p] == prodMax && r[p] > rmax)){ 17 | prodMax = l[p] * r[p]; rmax = r[p]; pick = p + 1; 18 | } 19 | } 20 | 21 | printf("%ld\n", pick); 22 | } 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /src/Code-Chef/MUFFINS3.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(int argc, char *argv[]){ 5 | size_t N,temp; 6 | scanf("%zd",&N); 7 | for(size_t k = 0; k < N ; k++){ 8 | scanf("%zd",&temp); 9 | printf("%zd\n",1 + temp/2); 10 | } 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /src/Code-Chef/NDIFFPAL.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | std::ios_base::sync_with_stdio(false); 6 | int t; scanf("%d\n", &t); 7 | while(t--){ 8 | long n; std::cin >> n; 9 | std::string s(""); 10 | std::string r("abc"); 11 | for(long p = 0; p < n; p++){s += r[p % 3];} 12 | std::cout << s << std::endl; 13 | } 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /src/Code-Chef/NOCODING.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | 6 | int numCases; scanf("%d\n",&numCases); 7 | string message = ""; 8 | const int mult = 11; 9 | const int numLetters = 26; 10 | int length = 0, count = 0, diff = 0; 11 | 12 | while(numCases--){ 13 | getline(cin, message); 14 | length = message.size(); 15 | count = 2; 16 | for(int k =1 ; k < length; k++){ 17 | diff = message[k] - message[k-1]; 18 | if(diff < 0){diff += numLetters;} 19 | count += 1 + diff; 20 | } 21 | if(count <= length * mult){printf("YES\n");} else{printf("NO\n");} 22 | } 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /src/Code-Chef/NUKES.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | size_t A,N,K; 6 | scanf("%zd %zd %zd", &A, &N, &K); 7 | 8 | for(size_t comp = 0 ; comp < K ; comp++){ 9 | printf("%zd ",A%(N+1)); 10 | A /= (N+1); 11 | } 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /src/Code-Chef/NUMGAME.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | //By induction: Odd numbers are losing numbers, even numbers are winning; 4 | int main(){ 5 | size_t T; scanf("%zd",&T); 6 | size_t N; 7 | for(size_t k = 0; k < T ; k++){ 8 | scanf("%zd",&N); 9 | if(N&1){printf("BOB\n");} 10 | else{printf("ALICE\n");} 11 | } 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /src/Code-Chef/NUMGAME2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | int t; scanf("%d",&t); 6 | int temp; 7 | while(t--){ 8 | scanf("%d",&temp); 9 | if(temp % 4 == 1){printf("ALICE\n");} 10 | else{printf("BOB\n");} 11 | } 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /src/Code-Chef/OJUMPS.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | long long a; scanf("%lld\n", &a); 6 | puts(((a % 6 == 0) || (a % 6 == 1) || (a % 6 == 3)) ? "yes" : "no"); 7 | 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /src/Code-Chef/OMWG.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | int t; scanf("%d\n", &t); 6 | while(t--){ 7 | long m, n; scanf("%ld %ld\n", &m, &n); 8 | printf("%ld\n", 2 * m * n - m - n); 9 | } 10 | 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /src/Code-Chef/ONP.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(){ 6 | 7 | int t(0); scanf("%d\n", &t); 8 | 9 | while(t--){ 10 | 11 | std::string expr(""); getline(std::cin, expr); 12 | std::vector operators; 13 | 14 | for(int k = 0; k < expr.size(); k++){ 15 | if(expr[k] == '('){continue;} 16 | else if(expr[k] == '+' || expr[k] == '-' || expr[k] == '*' || expr[k] == '/' || expr[k] == '^'){operators.push_back(expr[k]);} 17 | else if(expr[k] == ')'){printf("%c", operators.back()); operators.pop_back();} 18 | else{printf("%c", expr[k]);} 19 | } 20 | puts(""); 21 | } 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /src/Code-Chef/P1Z2S.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | long n; scanf("%ld\n", &n); 6 | long long count(0); 7 | for(long p = 0; p < n; p++){long a; scanf("%ld", &a); count += a;} 8 | printf("%lld\n", (n > (count + 1)/ 2) ? n : (count + 1) / 2); 9 | 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /src/Code-Chef/PALL01.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | int t; std::cin >> t; 6 | while(t--){ 7 | std::string s; std::cin >> s; 8 | bool pal(true); 9 | for(int p = 0; p < s.size() / 2; p++){ 10 | if(s[p] != s[s.size() - 1 - p]){pal = 0; break;} 11 | } 12 | std::cout << (pal ? "wins" : "losses") << std::endl; 13 | } 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /src/Code-Chef/PERMUT2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(int argc, char* argv[]){ 5 | 6 | int flag = 0; 7 | int n = 0; scanf("%d",&n); 8 | 9 | while(n > 0){ 10 | int *perm = new int[n+1]; int *invperm = new int[n+1]; 11 | for(size_t k = 1; k <= n; k++){ scanf("%d",(perm+k)); invperm[perm[k]] = k; } 12 | 13 | flag = 1; 14 | for(size_t k = 1; k<=n ; k++){ if( invperm[k] != perm[k] ){ flag = 0; break;} } 15 | flag ? printf("ambiguous\n") : printf("not ambiguous\n"); 16 | 17 | scanf("%d",&n); 18 | } 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /src/Code-Chef/PLZLYKME.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | int t; scanf("%d\n", &t); 6 | while(t--){ 7 | long long L, D, S, C; scanf("%lld %lld %lld %lld\n", &L, &D, &S, &C); 8 | long long likes(S); 9 | bool alive = (S >= L); 10 | for(int p = 2; p <= D; p++){ 11 | likes *= (1 + C); 12 | if(likes >= L){alive = 1; break;} 13 | } 14 | puts(alive ? "ALIVE AND KICKING" : "DEAD AND ROTTING"); 15 | } 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /src/Code-Chef/POTATOES.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | std::vector getPrimes(long B){ 5 | 6 | std::vector isPrime(B + 1, 1); 7 | isPrime[0] = isPrime[1] = 0; 8 | for(int p = 2; p * p <= B; p++){ 9 | if(!isPrime[p]){continue;} 10 | for(int q = 2 * p; q <= B; q += p){isPrime[q] = 0;} 11 | } 12 | 13 | return isPrime; 14 | } 15 | 16 | 17 | 18 | int main(){ 19 | 20 | const long B = 3100; 21 | std::vector isPrime = getPrimes(B); 22 | int t; scanf("%d\n", &t); 23 | while(t--){ 24 | int x, y; scanf("%d %d\n", &x, &y); 25 | int ans(1); 26 | while(!isPrime[x + y + ans]){++ans;} 27 | printf("%d\n", ans); 28 | } 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /src/Code-Chef/PPNUM.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(){ 5 | 6 | const long long MOD = 1000000007; 7 | const int N = 10; 8 | int t; scanf("%d\n", &t); 9 | while(t--){ 10 | long long a, b; scanf("%lld %lld\n", &a, &b); 11 | long long pow(1); 12 | int numDigits(1); 13 | long long total(0); 14 | for(int p = 1; p < N; p++){ 15 | long long s = (a > pow) ? a : pow; 16 | long long f = (b < (10 * pow - 1)) ? b : (10 * pow - 1); 17 | if(s <= f){total += (numDigits * ((f * (f + 1) / 2 - s * (s - 1) / 2)) % MOD) % MOD;} 18 | pow *= 10; ++numDigits; 19 | } 20 | printf("%lld\n", total); 21 | } 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /src/Code-Chef/PRB01.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | bool isPrime(long x){ 4 | for(long p = 2; p * p <= x; p++){if(x % p == 0){return false;}} 5 | return true; 6 | } 7 | 8 | 9 | int main(){ 10 | 11 | int T; scanf("%d\n", &T); 12 | while(T--){ 13 | long n; scanf("%ld\n", &n); 14 | puts(isPrime(n) ? "yes" : "no"); 15 | } 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /src/Code-Chef/PREDICT.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | const long M = 10000; 6 | long t; scanf("%ld\n", &t); 7 | while(t--){ 8 | double p; scanf("%lf\n", &p); 9 | if(p < 0.5){p = 1 - p;} 10 | printf("%.7lf\n", p * (3 - 2 * p) * M); 11 | } 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /src/Code-Chef/PROB.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | int t; scanf("%d\n", &t); 6 | while(t--){ 7 | double t1, t2, t3, t4; scanf("%lf %lf %lf %lf\n", &t1, &t2, &t3, &t4); 8 | printf("%.7lf\n", t1 / (t1 + t2)); 9 | } 10 | 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /src/Code-Chef/PUPPYGM.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | int t; scanf("%d\n", &t); 6 | while(t--){ 7 | long a, b; scanf("%ld %ld\n", &a, &b); 8 | puts( ((a % 2 == 0) || (b % 2 == 0)) ? "Tuzik" : "Vanka"); //Proof by induction 9 | } 10 | 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /src/Code-Chef/RANKLIST.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | int t; scanf("%d\n", &t); 6 | while(t--){ 7 | long long n, s; scanf("%lld %lld\n", &n, &s); 8 | long long S = n * (n + 1) / 2; 9 | long long diff = S - s; 10 | 11 | long count(0); 12 | while(diff > 0){++count; diff -= count;} 13 | printf("%ld\n", count); 14 | } 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /src/Code-Chef/RECIPE.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int gcd (int a, int b){return (b == 0) ? a : gcd (b, a%b);} 5 | 6 | int main(){ 7 | int t; scanf("%d",&t); 8 | int number, divisor; 9 | 10 | while(t--){ 11 | scanf("%d",&number); 12 | int *quantities = new int[number]; 13 | 14 | scanf("%d",quantities); 15 | divisor = quantities[0]; 16 | for(int k = 1; k < number ; k++){ 17 | scanf("%d",(quantities+k)); 18 | divisor = gcd(divisor, quantities[k]); 19 | } 20 | for(int k = 0; k < number ; k++){printf("%d ",quantities[k]/divisor);} 21 | printf("\n"); 22 | } 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /src/Code-Chef/RECTSQ.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | long gcd (long a, long b){return (b == 0) ? a : gcd (b, a%b);} 4 | 5 | int main(){ 6 | 7 | int t; scanf("%d\n", &t); 8 | while(t--){ 9 | long m, n; scanf("%ld %ld\n", &n, &m); 10 | printf("%ld\n", m * n / (gcd(m, n) * gcd(m, n))); 11 | } 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /src/Code-Chef/REMISS.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | int t; scanf("%d", &t); 6 | while(t--){ 7 | long A, B; scanf("%ld %ld\n", &A, &B); 8 | printf("%ld %ld\n", ((A > B) ? A : B), A + B); 9 | } 10 | 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /src/Code-Chef/RESQ.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main(){ 6 | 7 | int numCases; scanf("%d\n",&numCases); 8 | size_t cakes = 0, length = 0; 9 | 10 | while(numCases--){ 11 | scanf("%zd",&cakes); 12 | length = sqrt(cakes); 13 | while( cakes != length * (cakes / length) ){length--;} 14 | printf("%zd\n", cakes/length - length ); 15 | } 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /src/Code-Chef/RETPO.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | long t; scanf("%ld\n", &t); 6 | while(t--){ 7 | long x, y; scanf("%ld %ld\n", &x, &y); 8 | if(x < 0){x = -x;} 9 | if(y < 0){y = -y;} 10 | long res = 2 * ((x > y) ? x : y); 11 | res += ((x > y) ? 1 : (-1)) * ((x + y) % 2); 12 | printf("%ld\n", res); 13 | } 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /src/Code-Chef/ROTATION.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(){ 5 | 6 | std::ios_base::sync_with_stdio(false); 7 | 8 | long n, m; std::cin >> n >> m; 9 | std::vector a(n); 10 | for(long p = 0; p < n; p++){std::cin >> a[p];} 11 | long offset(0); 12 | while(m--){ 13 | std::string s; long x; std::cin >> s >> x; 14 | if(s[0] == 'C'){offset += x;} 15 | if(s[0] == 'A'){offset -= x;} 16 | offset %= n; offset = (offset + n) % n; //ensure that it is positive; 17 | if(s[0] == 'R'){printf("%ld\n", a[(x + offset - 1 + 2 * n) % n]);} 18 | } 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /src/Code-Chef/RRCOPY.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(){ 5 | 6 | int t; scanf("%d\n", &t); 7 | while(t--){ 8 | long n; scanf("%ld\n", &n); 9 | std::set s; 10 | while(n--){long a; scanf("%ld", &a); s.insert(a);} 11 | printf("%ld\n", s.size()); 12 | } 13 | 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /src/Code-Chef/SALARY.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(){ 5 | 6 | int t; scanf("%d\n", &t); 7 | while(t--){ 8 | int n; scanf("%d\n", &n); 9 | std::vector a(n); 10 | long min = 10000001; 11 | for(int p = 0; p < n; p++){ 12 | scanf("%ld", &a[p]); 13 | min = (a[p] < min) ? a[p] : min; 14 | } 15 | 16 | long count(0); 17 | for(int p = 0; p < n; p++){count += (a[p] - min);} 18 | printf("%ld\n", count); 19 | } 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /src/Code-Chef/SEAVOTE.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | const int S = 100; 6 | int t; scanf("%d\n", &t); 7 | while(t--){ 8 | long n; scanf("%ld\n", &n); 9 | long total(0), zeroes(0); 10 | for(int p = 0; p < n; p++){ 11 | int b; scanf("%d", &b); 12 | if(b == 0){++zeroes;} 13 | total += b; 14 | } 15 | 16 | bool possible = (total >= S) && (total < S + (n - zeroes)); 17 | puts(possible ? "YES" : "NO"); 18 | } 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /src/Code-Chef/SMPAIR.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | long T; scanf("%ld\n", &T); 6 | while(T--){ 7 | 8 | long N; scanf("%ld\n", &N); 9 | long smallestA(0), smallestB(0); 10 | for(long p = 0; p < N; p++){ 11 | long x; scanf("%ld\n", &x); 12 | if(smallestA == 0 || x < smallestA){smallestB = smallestA; smallestA = x;} 13 | else if(smallestB == 0 || x < smallestB){smallestB = x;} 14 | } 15 | 16 | printf("%ld\n", smallestA + smallestB); 17 | } 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /src/Code-Chef/SNIPE.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | int main(){ 6 | 7 | int T; scanf("%d\n", &T); 8 | 9 | while(T--){ 10 | double b, ls; scanf("%lf %lf\n", &b, &ls); 11 | printf("%.4lf %.4lf\n", sqrt(ls * ls - b * b), sqrt(ls * ls + b * b)); 12 | } 13 | 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /src/Code-Chef/SPCANDY.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | int t; scanf("%d\n", &t); 6 | while(t--){ 7 | long long n, k; scanf("%lld %lld\n", &n, &k); 8 | printf("%lld %lld\n", n / k, n % k); 9 | } 10 | 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /src/Code-Chef/STACKS.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(){ 6 | 7 | int t; scanf("%d\n", &t); 8 | while(t--){ 9 | long n; scanf("%ld\n", &n); 10 | std::vector a; 11 | while(n--){ 12 | long x; scanf("%ld", &x); 13 | if(a.empty() || a.back() <= x){a.push_back(x);} 14 | else{ 15 | std::vector::iterator vecIter = std::upper_bound(a.begin(), a.end(), x); 16 | *vecIter = x; 17 | } 18 | } 19 | 20 | printf("%ld ", a.size()); 21 | for(long p = 0; p < a.size(); p++){printf("%ld ", a[p]);} 22 | puts(""); 23 | } 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /src/Code-Chef/START01.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | long long x; 6 | scanf("%lld\n", &x); 7 | printf("%lld\n", x); 8 | 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /src/Code-Chef/STONES.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | 6 | int numCases; scanf("%d\n",&numCases); 7 | const int numChars= 256; 8 | 9 | string J = "", S = ""; 10 | int output = 0; 11 | 12 | while(numCases--){ 13 | getline(cin, J); getline(cin, S); 14 | bool *present = new bool[numChars]; 15 | output = 0; 16 | 17 | for(int k = 0; k < numChars; k++){present[k] = 0;} 18 | for(int k = 0; k < J.size(); k++){present[J[k]] = 1;} 19 | for(int k = 0; k < S.size(); k++){output += present[S[k]];} 20 | 21 | printf("%d\n",output); 22 | } 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /src/Code-Chef/STUDVOTE.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(){ 5 | 6 | int t; scanf("%d\n", &t); 7 | while(t--){ 8 | int n, k; scanf("%d %d\n", &n, &k); 9 | std::vector votes(n + 1, 0); 10 | std::vector qualified(n + 1, 1); 11 | for(int p = 1; p <= n; p++){ 12 | int x; scanf("%d", &x); 13 | ++votes[x]; 14 | qualified[p] = (x != p); 15 | } 16 | int count(0); 17 | for(int p = 1; p <= n; p++){if(qualified[p] && votes[p] >= k){++count;}} 18 | printf("%d\n", count); 19 | } 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /src/Code-Chef/SUBGCD.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | long gcd(long a, long b){return (a == 0) ? b : gcd(b % a, a);} 4 | 5 | int main(){ 6 | 7 | int t; scanf("%d\n", &t); 8 | while(t--){ 9 | long n; scanf("%ld\n", &n); 10 | long current(0); 11 | for(long p = 0; p < n; p++){ 12 | long a; scanf("%ld", &a); current = gcd(current , a); 13 | } 14 | printf("%ld\n", (current == 1) ? n : -1); 15 | } 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /src/Code-Chef/SUBINC.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | int t; scanf("%d\n", &t); 6 | while(t--){ 7 | long long n; scanf("%lld\n", &n); 8 | long long run(0), total(0), prev(-1); 9 | while(n--){ 10 | long long x; scanf("%lld\n", &x); 11 | if((prev < 0) || (x < prev)){run = 1;} 12 | else{++run;} 13 | total += run; 14 | prev = x; 15 | } 16 | 17 | printf("%lld\n", total); 18 | } 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /src/Code-Chef/TAAND.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(){ 6 | 7 | long n; scanf("%ld\n", &n); 8 | std::vector a(n); 9 | for(long p = 0; p < n; p++){scanf("%ld", &a[p]);} 10 | sort(a.begin(), a.end()); 11 | 12 | long ans(0); 13 | for(int p = 1; p < n; p++){ans = (ans > (a[p - 1] & a[p])) ? ans : (a[p - 1] & a[p]);} 14 | printf("%ld\n", ans); 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /src/Code-Chef/TACHSTCK.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(){ 6 | 7 | long n, d; scanf("%ld %ld\n", &n, &d); 8 | std::vector a(n); 9 | for(long p = 0; p < n; p++){scanf("%ld", &a[p]);} 10 | sort(a.begin(), a.end()); 11 | 12 | long count(0); 13 | long ind(1); 14 | while(ind < n){ 15 | if(a[ind] - a[ind - 1] <= d){++count; ++ind;} 16 | ++ind; 17 | } 18 | 19 | printf("%ld\n", count); 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /src/Code-Chef/TEMPLATE.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | 6 | int numCases; scanf("%d\n",&numCases); 7 | 8 | while(numCases--){ 9 | 10 | 11 | 12 | 13 | 14 | printf("%\n",output); 15 | } 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /src/Code-Chef/TICKETS5.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | int t; std::cin >> t; 6 | while(t--){ 7 | std::string s; std::cin >> s; 8 | bool lucky(s[0] != s[1]); 9 | for(int p = 2; p < s.size(); p++){if(s[p] != s[p % 2]){lucky = 0; break;}} 10 | puts(lucky ? "YES" : "NO"); 11 | } 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /src/Code-Chef/TREEROOT.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | 6 | int numCases = 0, numNodes = 0, nodeID = 0, sumChildren = 0, root = 0; 7 | scanf("%d\n",&numCases); 8 | 9 | do{ scanf("%d\n",&numNodes); 10 | root = 0; 11 | do{ scanf("%d %d\n", &nodeID, &sumChildren); 12 | root += nodeID - sumChildren; 13 | }while(--numNodes); 14 | printf("%d\n",root); 15 | }while(--numCases); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /src/Code-Chef/TRICOIN.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | int t; scanf("%d\n", &t); 6 | while(t--){ 7 | long n; scanf("%ld\n", &n); 8 | long r(0), sum(0); 9 | for(int p = 1; p <= n; p++){ 10 | sum += p; 11 | if(sum > n){break;} 12 | r = p; 13 | } 14 | printf("%ld\n", r); 15 | } 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /src/Code-Chef/TRISQ.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | int t; scanf("%d\n", &t); 6 | while(t--){ 7 | long b; scanf("%ld\n", &b); 8 | long u = (b - 2) / 2; 9 | printf("%ld\n", u * (u + 1) / 2); 10 | 11 | } 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /src/Code-Chef/TSORT.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(){ 6 | 7 | long t; scanf("%ld\n", &t); 8 | std::vector a(t); 9 | for(long p = 0; p < t; p++){scanf("%ld\n", &a[p]);} 10 | sort(a.begin(), a.end()); 11 | for(long p = 0; p < t; p++){printf("%ld\n", a[p]);}; 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /src/Code-Chef/TWOSTR.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(){ 5 | 6 | int T; scanf("%d\n", &T); 7 | while(T--){ 8 | std::string s1, s2; std::cin >> s1 >> s2; 9 | bool match(1); 10 | for(int p = 0; p < s1.size(); p++){ 11 | if(s1[p] == '?' || s2[p] == '?' || s1[p] == s2[p]){continue;} 12 | match = 0; break; 13 | } 14 | puts(match ? "Yes" : "No"); 15 | } 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /src/Code-Chef/WALK.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(){ 5 | 6 | int t; scanf("%d\n", &t); 7 | while(t--){ 8 | long n; scanf("%ld\n", &n); 9 | long v(0); 10 | for(long p = 0; p < n; p++){ 11 | long w; scanf("%ld", &w); 12 | v = (v > (w + p)) ? v : (w + p); 13 | } 14 | printf("%ld\n", v); 15 | } 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /src/Code-Chef/XORNUBER.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | int t; scanf("%d\n", &t); 6 | while(t--){ 7 | long n; scanf("%ld\n", &n); 8 | bool possible(1); 9 | long r(n); 10 | while(r > 0){if(r % 2 == 0){possible = 0; break;}; r /= 2;} 11 | if(n == 1){n = 4;} //Need positive integer 12 | printf("%ld\n", possible ? (n / 2) : (-1)); 13 | } 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /src/Code-Forces/#674_floor-number.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int t; 7 | cin >> t; 8 | while (t) 9 | { 10 | int n, x; 11 | cin >> n >> x; 12 | int currPos = 2; 13 | int floor = 1; 14 | while (currPos < n) 15 | { 16 | floor += 1; 17 | currPos += x; 18 | } 19 | cout << floor << endl; 20 | t--; 21 | } 22 | return 0; 23 | } -------------------------------------------------------------------------------- /src/Code-Forces/#678_re-order.cpp: -------------------------------------------------------------------------------- 1 | // https://codeforces.com/contest/1436/problem/A 2 | 3 | #include 4 | #define ll long long int 5 | using namespace std; 6 | 7 | void test() 8 | { 9 | int n, m; 10 | cin >> n >> m; 11 | vector v(n); 12 | int sum = 0; 13 | for (int i = 0; i < n; i++) 14 | { 15 | cin >> v[i]; 16 | sum += v[i]; 17 | } 18 | if (sum == m) 19 | { 20 | cout << "YES" << endl; 21 | return; 22 | } 23 | cout << "NO" << endl; 24 | return; 25 | } 26 | 27 | int main() 28 | { 29 | int t; 30 | cin >> t; 31 | while (t--) 32 | test(); 33 | return 0; 34 | } -------------------------------------------------------------------------------- /src/Code-Forces/#685_subtract-divide.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define lli long long int 3 | using namespace std; 4 | 5 | void test() 6 | { 7 | lli n; 8 | scanf("%lld", &n); 9 | if (n == 1) 10 | cout << 0 << endl; 11 | else if (n == 2) 12 | cout << 1 << endl; 13 | else if (n % 2 == 0 or n == 3) 14 | cout << 2 << endl; 15 | else 16 | cout << 3 << endl; 17 | return; 18 | } 19 | 20 | int main() 21 | { 22 | int t; 23 | scanf("%d", &t); 24 | while (t--) 25 | test(); 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /src/Code-Forces/#687_prison-break.cpp: -------------------------------------------------------------------------------- 1 | // Problem Statement: https://codeforces.com/contest/1457/problem/A/ 2 | 3 | #include 4 | #define lli long long int 5 | using namespace std; 6 | 7 | void test1() 8 | { 9 | lli n, m, r, c; 10 | scanf("%lld %lld %lld %lld", &n, &m, &r, &c); 11 | printf("%lld\n", max(n - r, r - 1) + max(m - c, c - 1)); 12 | return; 13 | } 14 | 15 | int main() 16 | { 17 | int t; 18 | scanf("%d", &t); 19 | while (t--) 20 | test1(); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /src/Code-Forces/box-is-pull.cpp: -------------------------------------------------------------------------------- 1 | // https://codeforces.com/contest/1428/problem/A 2 | 3 | #include 4 | #define ll long long int 5 | using namespace std; 6 | 7 | void test() 8 | { 9 | int x1, y1, x2, y2; 10 | cin >> x1 >> y1 >> x2 >> y2; 11 | 12 | if (x1 == x2 && y1 == y2) 13 | cout << 0 << endl; 14 | else if (x1 == x2 || y1 == y2) 15 | cout << abs(x1 - x2) + abs(y1 - y2) << endl; 16 | else 17 | cout << abs(x1 - x2) + abs(y1 - y2) + 2 << endl; 18 | return; 19 | } 20 | 21 | int main() 22 | { 23 | int t; 24 | cin >> t; 25 | while (t--) 26 | test(); 27 | return 0; 28 | } -------------------------------------------------------------------------------- /src/Code-Forces/cubes.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define lli long long int 3 | using namespace std; 4 | 5 | void test() 6 | { 7 | lli n; 8 | scanf("%lld", &n); 9 | vector k(n); 10 | 11 | lli sum = 0; 12 | 13 | for (int i = 0; i < n; i++) 14 | { 15 | cin >> k[i]; 16 | sum += k[i]; 17 | } 18 | 19 | sort(k.begin(), k.end()); 20 | lli req = k[n - 1] * (n - 1); 21 | 22 | while (req < sum) 23 | req += (n - 1); 24 | 25 | printf("%lld\n", req - sum); 26 | return; 27 | } 28 | 29 | int main() 30 | { 31 | int t; 32 | scanf("%d", &t); 33 | while (t--) 34 | test(); 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /src/Code-Forces/edu#97_marketing-scheme.cpp: -------------------------------------------------------------------------------- 1 | // Problem Statement: https://codeforces.com/contest/1437/problem/A 2 | 3 | #include 4 | #define ll long long int 5 | using namespace std; 6 | 7 | void test() 8 | { 9 | ll l, r; 10 | cin >> l >> r; 11 | ll res = r + 1; 12 | if (((l % res + res / 2) > r) && (r % res + res / 2) > r) 13 | { 14 | cout << "YES" << endl; 15 | return; 16 | } 17 | cout << "NO" << endl; 18 | return; 19 | } 20 | 21 | int main() 22 | { 23 | int t; 24 | cin >> t; 25 | while (t--) 26 | test(); 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /src/Code-Forces/edu#99_ping-pong.cpp: -------------------------------------------------------------------------------- 1 | // Problem Statement: https://codeforces.com/contest/1455/problem/C 2 | 3 | #include 4 | #define lli long long int 5 | using namespace std; 6 | 7 | void test() 8 | { 9 | lli x, y; 10 | scanf("%lld %lld", &x, &y); 11 | printf("%lld %lld\n", x - 1, y); 12 | return; 13 | } 14 | 15 | int main() 16 | { 17 | int t; 18 | scanf("%d", &t); 19 | while (t--) 20 | test(); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /src/Code-Forces/maximum-gcd.cpp: -------------------------------------------------------------------------------- 1 | // Problem Link: https://codeforces.com/problemset/problem/1370/A 2 | 3 | #include 4 | 5 | int main() 6 | { 7 | int t, n; 8 | scanf("%d", &t); 9 | while (t--) 10 | { 11 | scanf("%d", &n); 12 | printf("%d\n", n / 2); 13 | } 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /src/Coding-Blocks/AliceAndTotient.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | #define ll long long int 5 | 6 | int a[1000001]={0}; 7 | 8 | int GCD(int one,int two) { 9 | if(one%two == 0) { 10 | return two; 11 | } 12 | return GCD(two,one % two); 13 | } 14 | 15 | int main() { 16 | int t; 17 | cin>>t; 18 | for(int i=0;i>n; 21 | if(a[n] != 0) { 22 | cout< 2 | #include 3 | using namespace std; 4 | int result = 0; 5 | void trident(int a, int b, string osf, int sum, int k) { 6 | if(sum == a) { 7 | cout< a) { 12 | return; 13 | } 14 | if(pow(k, b) > a) { 15 | return; 16 | } 17 | 18 | trident(a, b, osf+to_string(k)+" ", sum+pow(k, b), k+1); 19 | trident(a, b, osf, sum, k+1); 20 | } 21 | 22 | int main(int argc, char const *argv[]) 23 | { 24 | /* code */ 25 | int a, b; 26 | cin>>a>>b; 27 | trident(a, b, "", 0, 1); 28 | cout< 2 | #include 3 | using namespace std; 4 | int main () 5 | { 6 | float p, a; 7 | int n; 8 | cin >> p; 9 | if(p!=1) 10 | { 11 | //Finding Probability for a 12 | a = log(1/(1-p)); 13 | //Minimum number of people required 14 | n = sqrt (2*365*a); 15 | } 16 | //If given probability is one 17 | else 18 | { 19 | n = 365; 20 | } 21 | cout << n+1; 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /src/Coding-Blocks/DeepakAndHisJourney.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(int argc, char const *argv[]) { 5 | long long int T,N,Min,sum; 6 | cin>>T; 7 | while(T--) { 8 | cin>>N; 9 | 10 | int*C=new int[N]; 11 | int*L=new int[N]; 12 | 13 | for(int i=0;i>C[i]; 15 | } 16 | 17 | for(int i=0;i>L[i]; 19 | } 20 | 21 | Min=C[0]; 22 | sum=0; 23 | 24 | for(int i=0;i 2 | #include 3 | using namespace std; 4 | 5 | #define sizz 100000001 6 | #define ll long long int 7 | 8 | bool sieve[sizz]; 9 | int main() { 10 | int N; 11 | cin>>N; 12 | sieve[0]=sieve[1]=1; 13 | for(int i=2;i*i<=sizz-1;i++) 14 | if(!sieve[i]) 15 | for(int j=i*i;j<=sizz-1;j+=i) 16 | sieve[j]=1; 17 | 18 | ll result=1; 19 | while(N && result 2 | using namespace std; 3 | 4 | void dnf(int *arr, int n) { 5 | int start = 0, mid = 0, end = n-1; 6 | while(mid <= end) { 7 | if(arr[mid]==1) { 8 | mid++; 9 | } else if(arr[mid] == 2) { 10 | swap(arr[mid], arr[end]); 11 | end--; 12 | } else { 13 | swap(arr[start], arr[mid]); 14 | start++; 15 | mid++; 16 | } 17 | } 18 | } 19 | 20 | int main(int argc, char const *argv[]) 21 | { 22 | int n; 23 | cin>>n; 24 | int *arr = new int[n]; 25 | for(int i=0;i>arr[i]; 27 | } 28 | dnf(arr, n); 29 | for(int i=0;i 2 | using namespace std; 3 | 4 | int dp[100005] = {0}; 5 | 6 | int friendsDP(int n) { 7 | // Base case 8 | if(n==0 or n==1) return 1; 9 | if(n==2) return 2; 10 | if(dp[n]!=0) return dp[n]; 11 | int result = friendsDP(n-1) + ((n-1)*friendsDP(n-2)); 12 | dp[n] = result; 13 | return dp[n]; 14 | } 15 | 16 | int main(int argc, char const *argv[]) 17 | { 18 | int n; 19 | cin>>n; 20 | cout< 2 | using namespace std; 3 | 4 | int DParr[100000] = {0}; 5 | 6 | int friends(int n) { 7 | // Base case 8 | if(n==0 or n==1) return 1; 9 | if(DParr[n] != 0) return DParr[n]; 10 | if(n==2) return 2; 11 | DParr[n] = friends(n-1) + ((n-1)*friends(n-2)); 12 | return friends(n-1) + ((n-1)*friends(n-2)); 13 | } 14 | 15 | int main(int argc, char const *argv[]) 16 | { 17 | int n; 18 | cin>>n; 19 | cout< 2 | using namespace std; 3 | 4 | int friends(int n) { 5 | // Base case 6 | if(n==0 or n==1) return 1; 7 | if(n==2) return 2; 8 | 9 | return friends(n-1) + ((n-1)*friends(n-2)); 10 | } 11 | 12 | int main(int argc, char const *argv[]) 13 | { 14 | int n; 15 | cin>>n; 16 | cout< 2 | using namespace std; 3 | 4 | long long int friends(long long int n){ 5 | //Base Case 6 | if(n==0 or n==1) return 1; 7 | if(n==2) return 2; 8 | return friends(n-1) +((n-1)*friends(n-2)); 9 | } 10 | 11 | int main(int argc, char const *argv[]){ 12 | long long int n,t; 13 | cin>>t; 14 | for(int i=0;i>n; 16 | cout< 2 | #include 3 | using namespace std; 4 | #define ll long long int 5 | 6 | ll rodCut(ll n, ll ar[]) { 7 | ll result[n+1]; 8 | result[0]=0; 9 | for(ll i=1;i<=n;i++) { 10 | result[i]=INT_MIN; 11 | for(ll j=0;j>n; 21 | ll ar[n]; 22 | for(ll i=0;i>ar[i]; 24 | } 25 | cout< 3 | int main() 4 | { 5 | int l,n,w,h,i; 6 | scanf("%d",&l); 7 | scanf("%d",&n); 8 | for(i=0;il ||w==l)&&(h>l||h==l)&&(w==h)) 12 | { 13 | printf("ACCEPTED\n"); 14 | } 15 | else if((w>l || w==l) && (h>l ||h==l)) 16 | { 17 | printf("CROP IT\n"); 18 | } 19 | else{ 20 | printf("UPLOAD ANOTHER\n"); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Coding-Blocks/StockSpan.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void StockSpan(int a[], int n){ 5 | stack s; 6 | int ans[n]= {0}; 7 | for(int day = 0 ; day < n ; day++){ 8 | while( !s.empty() && a[s.top()] < a[day]){ 9 | s.pop(); 10 | } 11 | 12 | ans[day] = s.empty()?day+1:day-s.top(); 13 | s.push(day); 14 | } 15 | for(int i=0;i>n; 24 | int a[n]; 25 | for(int i=0 ; i< n; i++){ 26 | cin >> a[i]; 27 | } 28 | if(n>0){ 29 | StockSpan(a,n); 30 | } 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /src/Coding-Blocks/UniqueNum_1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | #define ll long long int 6 | 7 | int main() { 8 | int t; 9 | cin>>t; 10 | int result = 0; 11 | for(int i=0;i>n; 14 | result^=n; 15 | } 16 | cout< 2 | #include 3 | using namespace std; 4 | 5 | #define ll long long int 6 | 7 | int Unique3(int arr[], int n) { 8 | int siz[64] = {0}; 9 | for(int i=0;i0) { 13 | siz[j]+= num&1; 14 | j++; 15 | num>>=1; 16 | } 17 | } 18 | int temp=1; 19 | long result=0; 20 | for(int i=0;i<64;i++) { 21 | siz[i] %= 3; 22 | result += siz[i]*temp; 23 | temp = temp<<1; 24 | } 25 | return result; 26 | } 27 | 28 | 29 | int main() { 30 | int n; 31 | cin>>n; 32 | int arr[n]; 33 | for(int i=0;i>arr[i]; 35 | } 36 | cout< 2 | using namespace std; 3 | #define ll long long int 4 | 5 | int main() { 6 | ll n, k; 7 | cin>>n>>k; 8 | int *arr = new int[n+1]; 9 | 10 | unordered_map m; 11 | 12 | for(int i=1; i<=n; i++){ 13 | cin>>arr[i]; 14 | m[arr[i]] = i; 15 | } 16 | 17 | for(int i=n;i>=1&&k>0;i--){ 18 | int best = n-i+1; 19 | int ind=0; 20 | if(m.count(i)) 21 | ind = m[i]; 22 | 23 | if(best!=ind){ 24 | swap(arr[best],arr[ind]); 25 | k--; 26 | m[arr[best]] = best; 27 | m[arr[ind]] = ind; 28 | } 29 | } 30 | 31 | for(int i=1; i<=n; i++) 32 | cout< 2 | #include 3 | #define ll long long int 4 | using namespace std; 5 | 6 | bool check(ll n, ll m, ll x, ll y, ll ans) { 7 | return ((n-ans)*y + m) >= ans*x; 8 | } 9 | 10 | int main(int argc, char const *argv[]) 11 | { 12 | ll n,m,x,y; 13 | scanf("%lld %lld %lld %lld", &n, &m, &x, &y); 14 | ll start = 1, end = n; 15 | ll ans = -1; 16 | while(start <= end) { 17 | ll mid = (start+end)/2; 18 | 19 | 20 | 21 | 22 | if(check(n,m,x,y, mid)) { 23 | start = mid+1; 24 | ans = mid; 25 | } else { 26 | end = mid-1; 27 | } 28 | } 29 | cout< 16 | using namespace std; 17 | 18 | int main() 19 | { 20 | int n = 424; 21 | //cin >> n; 22 | while (n % 2 == 0) 23 | { 24 | n = n / 2; 25 | cout << 2 << " * "; 26 | } 27 | cout << n; 28 | return 0; 29 | } -------------------------------------------------------------------------------- /src/Common-Problems/CountSetBits.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int count setBits(int n) { 5 | int result = 0; 6 | while(n > 0) { 7 | n = n& (n-1); 8 | result++; 9 | } 10 | return result; 11 | } 12 | 13 | int main(int argc, char const *argv[]) 14 | { 15 | /* code */ 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /src/Common-Problems/GeneratePranthsis.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void GenPar(int n, int var1, int var2, string str) { 5 | if(var2 == n) { 6 | cout<var2) { 10 | GenPar(n, var1, var2+1, str+')'); 11 | } 12 | if(var1>n; 20 | GenPar(n, 0, 0,""); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /src/Common-Problems/GeneratePranthsis.py: -------------------------------------------------------------------------------- 1 | def prnts(c,num): 2 | if(num > 0): 3 | _prnts(c,0,num,0,0); 4 | return; 5 | 6 | def _prnts(c,ind,num,start,endd): 7 | 8 | if(endd == num): 9 | for i in c: 10 | print(i,end = ""); 11 | print(); 12 | return; 13 | else: 14 | if(start>endd): 15 | c[ind] = '}'; 16 | _prnts(c,ind+1,num,start,endd+1); 17 | if(start < num): 18 | c[ind] = '{'; 19 | _prnts(c,ind+1,num,start+1,endd); 20 | 21 | 22 | value = 3; 23 | countt = 2*value*[""]; 24 | prnts(countt,value); -------------------------------------------------------------------------------- /src/Common-Problems/Lexicographical.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void lexico(int n, int limit) { 5 | if(n>limit) { // Base case 6 | return; 7 | } 8 | if(n == limit) { 9 | cout<>limit; 23 | lexico(0, limit); 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /src/Common-Problems/NoConsecutiveOne.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void ones(int n, string osf) { 5 | // Base case 6 | if(n==0) { 7 | cout<>n; 24 | ones(n, ""); 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /src/Common-Problems/PlayingWithBits.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | #define ll long long int 5 | 6 | ll playwithbits(ll a) { 7 | int ans = 0; 8 | for(;a>0; a= a>>1) 9 | ans += a&1; 10 | return ans; 11 | } 12 | 13 | int main() { 14 | ll q,a,b,ans; 15 | cin>>q; 16 | while(q!=0) { 17 | cin>>a>>b; 18 | ans = 0; 19 | for(ll i = a; i<=b; i++) 20 | ans += playwithbits(i); 21 | cout< 2 | #include 3 | using namespace std; 4 | #define ll long long int 5 | /* 6 | [](m^2 - n^2), (2mn), (m^2 + n^2)] 7 | */ 8 | int Pythogorus(int x) { 9 | 10 | return 0; 11 | } 12 | 13 | 14 | int main(int argc, char const *argv[]) { 15 | int x; 16 | cin>>x; 17 | 18 | cout< 2 | #include 3 | #include 4 | using namespace std; 5 | int main(){ 6 | int x; 7 | 8 | while( cin >> x){ 9 | if(x < 3){ printf("-1\n"); continue; } 10 | 11 | if(x & 1) printf("%d %d", (x*x-1)/2, (x*x+1)/2); 12 | else{ 13 | x /= 2; 14 | printf("%d %d", x*x-1, x*x+1); 15 | } 16 | } 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /src/Common-Problems/StaircaseRecursion.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int countStairPath(int n, int current, int k) { 5 | // Base case 6 | if(current > n) { 7 | return 0; 8 | } 9 | if(current == n) { 10 | return 1; 11 | } 12 | // Recursion 13 | int result = 0; 14 | for(int i=1;i<=k;i++) { 15 | result += countStairPath(n, current+i, k); 16 | } 17 | return result; 18 | } 19 | 20 | int main(int argc, char const *argv[]) 21 | { 22 | cout< 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | string s1, s2; 9 | int t; 10 | cin>>t; 11 | for(int i=0;i>s1>>s2; 13 | for(size_t i=0;i 2 | #define re(i,j,n) for(int i=j;i>n; 8 | re(i,0,n)cin>>a[i]; 9 | re(i,0,n) 10 | re(j,i+1,n) 11 | re(k,j+1,n) 12 | re(l,k+1,n) 13 | if((a[i]^a[j]^a[k]^a[l])==0){cout<<"Yes";return 0;} 14 | cout<<"No"; 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /src/Common-Problems/XOR_Profit.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(int argc, char* argv[]) { 4 | int x,y; 5 | cin>>x>>y; 6 | int num = x^y; 7 | int msb=0; 8 | while(num!=0) { 9 | num=num>>1; 10 | msb++; 11 | } 12 | int result = 1; 13 | while(msb--) { 14 | result=result<<1; 15 | } 16 | cout< 2 | using namespace std; 3 | 4 | void replacepi(string str, string osf) { 5 | // Base case 6 | if(str.size() == 0) { 7 | cout<= 2 and str[1] == 'i') 18 | replacepi(str.substr(2), osf+"3.14"); 19 | else { 20 | char ch=str[0]; 21 | replacepi(str.substr(1), osf+ch); 22 | } 23 | } 24 | } 25 | 26 | int main(int argc, char const *argv[]) 27 | { 28 | /* code */ 29 | string str; 30 | cin>>str; 31 | replacepi(str, ""); 32 | return 0; 33 | } -------------------------------------------------------------------------------- /src/Common-Problems/sieve.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define maxx 100005 3 | using namespace std; 4 | 5 | bool sieve[maxx] = {}; 6 | int main() 7 | { 8 | sieve[0] = true; 9 | sieve[1] = true; 10 | for (int i = 2; i <= sqrt(maxx); i++) 11 | if (!sieve[i]) 12 | for (int j = i; j * i < maxx; j++) 13 | sieve[j * i] = true; 14 | 15 | for (int i = 0; i < maxx; i++) 16 | if (!sieve[i]) 17 | cout << i << " "; 18 | 19 | cout << "\n"; 20 | } -------------------------------------------------------------------------------- /src/Fibonacci/Nth-fibbanacci.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define ll long long int 4 | 5 | void SetValues(ll f[]) 6 | { 7 | f[0] = 0; 8 | f[1] = 1; 9 | for (ll i = 2; i < 300; i++) 10 | f[i] = (f[i - 1] + f[i - 2]) % 100; 11 | } 12 | 13 | int N_Fibbnaci(ll f[], int n) 14 | { 15 | return f[n % 300]; 16 | } 17 | 18 | int main() 19 | { 20 | ll f[300] = {0}; 21 | SetValues(f); 22 | 23 | ll n; 24 | cin >> n; 25 | cout << N_Fibbnaci(f, n) << endl; 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /src/Fibonacci/fibonacci-recursion.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int fib(int n) 5 | { 6 | // Base case 7 | if (n == 0 or n == 1) 8 | return n; 9 | return fib(n - 1) + fib(n - 2); // Self work and assumption 10 | } 11 | 12 | int main() 13 | { 14 | cout << fib(8); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /src/Fibonacci/fibonacci-series.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void fibDP(int n) 5 | { 6 | if (n == 0 or n == 1) 7 | cout << n; 8 | int count = 2; 9 | int res = 1, a = 0, b = 1, nextB = 0; 10 | cout << 0 << " " << 1 << " "; 11 | while (count < n) 12 | { 13 | nextB = a + b; 14 | count++; 15 | a = b; 16 | b = nextB; 17 | res += nextB; 18 | cout << nextB << " "; 19 | } 20 | } 21 | 22 | int main() 23 | { 24 | fibDP(8); 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /src/Fibonacci/fibonacci-sum-dp.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int dp[100005] = {0}; 5 | 6 | int fibDP(int n) { 7 | if (n == 0 or n == 1) 8 | return n; 9 | if (dp[n] != 0) 10 | return dp[n]; 11 | return dp[n] = fibDP(n - 1) + fibDP(n - 2); 12 | } 13 | 14 | int main() { 15 | cout << fibDP(8) << "\n"; 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /src/FoodFill/apple.txt: -------------------------------------------------------------------------------- 1 | 15 30 2 | .............................. 3 | .............#####............ 4 | .............#...#............ 5 | .....#########...#######...... 6 | ....###.....######.....###.... 7 | ...##....................##... 8 | ..##......................#... 9 | ..##.....................##... 10 | ..###...................##.... 11 | ....###................###.... 12 | ......###............###...... 13 | ........###........###........ 14 | ..........##########.......... 15 | .............................. 16 | ...........A.P.P.L.E.......... 17 | 7 15 18 | 19 | -------------------------------------------------------------------------------- /src/FoodFill/square.txt: -------------------------------------------------------------------------------- 1 | 15 30 2 | .............................. 3 | .....###################...... 4 | .....#.................#...... 5 | .....#.................#...... 6 | .....#.................#...... 7 | .....#.................#...... 8 | .....#.................#...... 9 | .....#.................#...... 10 | .....#.................#...... 11 | .....#.................#...... 12 | .....#.................#...... 13 | .....#.................#...... 14 | .....###################...... 15 | .............................. 16 | ............SQUARE............ 17 | 7 15 18 | 19 | -------------------------------------------------------------------------------- /src/GCD/BigGCD.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | #define ll long long int 6 | 7 | ll Fun(string c,int a) { 8 | ll num = 0; 9 | for(int i=0;i>a>>c; 26 | if(a==0) { 27 | cout<b) { 32 | swap(a,b); 33 | } 34 | ll result=1; 35 | result=GCD(a,b); 36 | cout< 2 | using namespace std; 3 | 4 | int gcd(int a, int b) 5 | { 6 | return b == 0 ? a : gcd(b, a % b); 7 | } 8 | 9 | int main() 10 | { 11 | int n1, n2; 12 | cin >> n1 >> n2; 13 | cout << gcd(n1, n2) << endl; 14 | return 0; 15 | } -------------------------------------------------------------------------------- /src/GCD/advancedGCD.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ravireddy07/cpp-book/7a03aa56b2e6e2a28776e56514ac061303db406e/src/GCD/advancedGCD.cpp -------------------------------------------------------------------------------- /src/Google-competitions/KickStart/2020-H-retype.cpp: -------------------------------------------------------------------------------- 1 | // Problem Statement: https://codingcompetitions.withgoogle.com/kickstart/round/000000000019ff49/000000000043adc7 2 | 3 | #include 4 | #define lli long long int 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int t; 10 | scanf("%d", &t); 11 | for (int tt = 0; tt < t; tt++) 12 | { 13 | lli n, k, s; 14 | scanf("%lld%lld%lld", &n, &k, &s); 15 | lli res = k; 16 | lli b = k - s; 17 | if ((res + b * 2) + (n - k) <= (k + n)) 18 | res = k + b * 2 + (n - k); 19 | else 20 | res = k + n; 21 | printf("Case #%d: %lld\n", tt + 1, res); 22 | } 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /src/Hacker-Rank/good-bad-string.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Sample Input: Sample Output: 4 | babba 2 7 5 | 6 | */ 7 | 8 | #include 9 | #define ll long long 10 | using namespace std; 11 | 12 | int main() 13 | { 14 | string word; 15 | cin >> word; 16 | int n = word.size(); 17 | ll odd = 0, even = 0; 18 | int pos = 0, next = 0; 19 | for (int i = 0; i < n; i++) 20 | { 21 | next = (pos + 1) % 2; 22 | odd += val[word[i] - '0'][pos]; 23 | even += val[word[i] - '0'][next]; 24 | odd++; 25 | val[word[i] - '0'][pos]++; 26 | pos = next; 27 | } 28 | cout << even << " " << odd << endl; 29 | 30 | return 0; 31 | } -------------------------------------------------------------------------------- /src/Hacker-Rank/matrix-script.py: -------------------------------------------------------------------------------- 1 | import math 2 | import os 3 | import random 4 | import re 5 | import sys 6 | import re 7 | 8 | n, m = map(int, input().split()) 9 | a, b = [], "" 10 | for _ in range(n): 11 | a.append(input()) 12 | 13 | for z in zip(*a): 14 | b += "".join(z) 15 | 16 | print(re.sub(r"(?<=\w)([^\w]+)(?=\w)", " ", b)) 17 | -------------------------------------------------------------------------------- /src/Hacker-Rank/maximize-it.py: -------------------------------------------------------------------------------- 1 | 2 | K, M = [int(x) for x in input().split()] 3 | arrayN = [] 4 | for _i_ in range(K): 5 | arrayN.append([int(x) for x in input().split()][1:]) 6 | 7 | from itertools import product 8 | possible_combination = list(product(*arrayN)) 9 | 10 | def func(nums): 11 | return sum(x*x for x in nums) % M 12 | 13 | print(max(list(map(func, possible_combination)))) -------------------------------------------------------------------------------- /src/Hacker-Rank/merge-the-tools.py: -------------------------------------------------------------------------------- 1 | def merge_the_tools(s, k): 2 | temp = [] 3 | len_temp = 0 4 | for item in s: 5 | len_temp += 1 6 | if item not in temp: 7 | temp.append(item) 8 | if len_temp == k: 9 | print(''.join(temp)) 10 | temp = [] 11 | len_temp = 0 12 | 13 | if __name__ == '__main__': 14 | string, k = input(), int(input()) 15 | merge_the_tools(string, k) -------------------------------------------------------------------------------- /src/Hacker-Rank/no-idea.py: -------------------------------------------------------------------------------- 1 | n, m = input().split() 2 | sc_ar = input().split() 3 | 4 | A = set(input().split()) 5 | B = set(input().split()) 6 | print(sum([(i in A) - (i in B) for i in sc_ar])) -------------------------------------------------------------------------------- /src/Hacker-Rank/the-minion-game.py: -------------------------------------------------------------------------------- 1 | def minion_game(string): 2 | vowels = 'AEIOU' 3 | kevsc = 0 4 | stusc = 0 5 | for i in range(len(s)): 6 | if s[i] in vowels: 7 | kevsc += (len(s)-i) 8 | else: 9 | stusc += (len(s)-i) 10 | 11 | if kevsc > stusc: 12 | print("Kevin", kevsc) 13 | elif kevsc < stusc: 14 | print("Stuart", stusc) 15 | else: 16 | print("Draw") 17 | 18 | if __name__ == '__main__': 19 | s = input() 20 | minion_game(s) -------------------------------------------------------------------------------- /src/Hacker-Rank/validating-postalcode.py: -------------------------------------------------------------------------------- 1 | s = input() 2 | print(s.isdigit() and 100000 <= int(s) <= 999999 and 3 | sum([s[i] == s[i+2] for i in range(0, 4)]) < 2) 4 | 5 | ''' 6 | import re 7 | 8 | print(bool(re.match( 9 | r'^' 10 | r'(?!.*(.).\1.*(.).\2)' 11 | r'(?!.*(.)(.)\3\4)' 12 | r'[1-9]\d{5}' 13 | r'$', input() 14 | ))) ''' -------------------------------------------------------------------------------- /src/Hacker-Rank/word-order.py: -------------------------------------------------------------------------------- 1 | from collections import OrderedDict 2 | #define empty ordered dictionary, which counts occurences 3 | dict = OrderedDict() 4 | 5 | for i in range(int(input())): 6 | #If input not in the dictionary, then add it 7 | #else increment the counter 8 | key = input() 9 | if not key in dict.keys(): 10 | dict.update({key : 1}) 11 | continue 12 | dict[key] += 1 13 | 14 | print(len(dict.keys())) 15 | print(*dict.values()) -------------------------------------------------------------------------------- /src/Knapsack/ColorfulKnapsack.py: -------------------------------------------------------------------------------- 1 | for j from 1 to x: 2 | dp[1][j]=-1 3 | for weight in vector(1): 4 | if weight<=j: 5 | dp[1][j]=max(dp[1][j],weight) 6 | 7 | 8 | for i from 2 to m: 9 | for j from 1 to x: 10 | dp[i][j]=-1 11 | if i>x: 12 | break 13 | for weight in vector(m): 14 | if j>weight && dp[i-1][j-weight]>0: 15 | dp[i][j]=max(dp[i][j],dp[i-1][j-weight]+weight) 16 | -------------------------------------------------------------------------------- /src/Leetcode/1108_defanging-an-ip-address.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/defanging-an-ip-address/ 2 | 3 | #include 4 | using namespace std; 5 | 6 | class Solution 7 | { 8 | public: 9 | string defangIPaddr(string address) 10 | { 11 | string res = ""; 12 | for (int i = 0; i < address.length(); i++) 13 | { 14 | if (address[i] == '.') 15 | res += "[.]"; 16 | else 17 | res += address[i]; 18 | } 19 | return res; 20 | } 21 | }; 22 | 23 | int main() 24 | { 25 | Solution a; 26 | cout << a.defangIPaddr("1.1.1.1") << endl; 27 | return 0; 28 | } -------------------------------------------------------------------------------- /src/Leetcode/122_best-time-to-buy-and-sell-stock-ii.cpp: -------------------------------------------------------------------------------- 1 | // Problem Statement: https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/ 2 | 3 | #include 4 | using namespace std; 5 | 6 | class Solution 7 | { 8 | public: 9 | int maxProfit(vector prices) 10 | { 11 | if (prices.empty()) 12 | return 0; 13 | int profit = 0; 14 | for (int i = 1; i < prices.size(); i++) 15 | if (prices[i] - prices[i - 1] > 0) 16 | profit += (prices[i] - prices[i - 1]); 17 | return profit; 18 | } 19 | }; 20 | 21 | int main() 22 | { 23 | Solution a; 24 | cout << a.maxProfit({7, 1, 5, 3, 6, 4}) << "\n"; 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /src/Leetcode/1323_maximum-69-number.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/maximum-69-number/ 2 | 3 | #include 4 | using namespace std; 5 | 6 | class Solution 7 | { 8 | public: 9 | int maximum69Number(int num) 10 | { 11 | string res = to_string(num); 12 | for (int i = 0; i < res.length(); ++i) 13 | if (res[i] == '6') 14 | { 15 | res[i] = '9'; 16 | break; 17 | } 18 | int a = stoi(res); 19 | return a; 20 | } 21 | }; 22 | 23 | int main() 24 | { 25 | Solution a; 26 | cout << a.maximum69Number(9669) << endl; 27 | return 0; 28 | } -------------------------------------------------------------------------------- /src/Leetcode/136_single-number.cpp: -------------------------------------------------------------------------------- 1 | // Problem Statement: https://leetcode.com/problems/single-number/ 2 | 3 | #include 4 | using namespace std; 5 | 6 | class Solution 7 | { 8 | public: 9 | int singleNumber(vector nums) 10 | { 11 | return std::accumulate(nums.begin(), nums.end(), 0, [](const int &a, const int &b) { return a ^ b; }); 12 | } 13 | 14 | int singleNumber(vector &nums) 15 | { 16 | int result = nums[0]; 17 | for (int i = 1; i < nums.size(); i++) 18 | result ^= nums[i]; 19 | return result; 20 | } 21 | }; 22 | 23 | int main() 24 | { 25 | Solution a; 26 | cout << a.singleNumber({4, 1, 2, 1, 2}) << "\n"; 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /src/Leetcode/141_linked-list-cycle.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/linked-list-cycle/ 2 | 3 | struct ListNode { 4 | int val; 5 | ListNode *next; 6 | ListNode(int x) : val(x), next(NULL) {} 7 | }; 8 | 9 | class Solution { 10 | public: 11 | bool hasCycle(ListNode *head) { 12 | if (!head) 13 | return false; 14 | 15 | ListNode *slow = head, *fast = head; 16 | 17 | while (fast->next && fast->next->next) { 18 | slow = slow->next; 19 | fast = fast->next->next; 20 | if (slow == fast) 21 | return true; 22 | } 23 | 24 | return false; 25 | } 26 | }; 27 | -------------------------------------------------------------------------------- /src/Leetcode/1486_xor-operation-array.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/xor-operation-in-an-array/ 2 | 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | class Solution 9 | { 10 | public: 11 | int xorOperation(int n, int start) 12 | { 13 | int res = start, temp = 2; 14 | for (int i = 1; i < n; i++) 15 | { 16 | res ^= (start + temp); 17 | temp += 2; 18 | } 19 | return res; 20 | } 21 | }; 22 | 23 | int main() 24 | { 25 | Solution a; 26 | cout << a.xorOperation(5, 0) << endl; 27 | return 0; 28 | } -------------------------------------------------------------------------------- /src/Leetcode/1518_water-bottles.cpp: -------------------------------------------------------------------------------- 1 | // Problem Statement: https://leetcode.com/problems/water-bottles/ 2 | 3 | #include 4 | using namespace std; 5 | 6 | class Solution 7 | { 8 | public: 9 | int numWaterBottles(int numBottles, int numExchange) 10 | { 11 | int sum = numBottles; 12 | while (numBottles >= numExchange) 13 | { 14 | sum += numBottles / numExchange; 15 | numBottles = numBottles % numExchange + numBottles / numExchange; 16 | cout << numBottles % numExchange << "\n"; 17 | } 18 | return sum; 19 | } 20 | }; 21 | 22 | int main() 23 | { 24 | Solution a; 25 | cout << a.numWaterBottles(15, 4) << "\n"; 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /src/Leetcode/1523_count-odd-numbers-in-an-interval-range.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/count-odd-numbers-in-an-interval-range/ 2 | 3 | #include 4 | using namespace std; 5 | 6 | class Solution 7 | { 8 | public: 9 | int countOdds(int low, int high) 10 | { 11 | int count = 0; 12 | for (int i = low; i <= high; i++) 13 | if (i % 2 != 0) 14 | count++; 15 | return count; 16 | //return (high + 1) / 2 - low / 2; 17 | } 18 | }; 19 | 20 | int main() 21 | { 22 | Solution a; 23 | cout << a.countOdds(3, 7) << endl; 24 | return 0; 25 | } -------------------------------------------------------------------------------- /src/Leetcode/1551_minimum-operations-make-array-equal.cpp: -------------------------------------------------------------------------------- 1 | // Problem Statement: https://leetcode.com/problems/minimum-operations-to-make-array-equal/ 2 | 3 | #include 4 | using namespace std; 5 | 6 | class Solution 7 | { 8 | public: 9 | int minOperations(int n) 10 | { 11 | int ans = 0; 12 | for (int i = 1; i <= n; i = i + 2) 13 | 14 | ans = ans + (n - i); 15 | 16 | return ans; 17 | } 18 | }; 19 | 20 | int main() 21 | { 22 | Solution a; 23 | cout << a.minOperations(3) << "\n"; 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /src/Leetcode/1556_thousand-seperator.cpp: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/thousand-separator/ 2 | 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | class Solution 9 | { 10 | public: 11 | string thousandSeparator(int n) 12 | { 13 | string s = to_string(n), res; 14 | for (int i = 0; i < s.size(); ++i) 15 | { 16 | if (i > 0 && (s.size() - i) % 3 == 0) 17 | res += "."; 18 | res += s[i]; 19 | } 20 | return res; 21 | } 22 | }; 23 | 24 | int main() 25 | { 26 | Solution a; 27 | string result = a.thousandSeparator(9887); 28 | cout << result << endl; 29 | } -------------------------------------------------------------------------------- /src/Leetcode/1561_MaxNumberCoinsYouCanGet.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | class Solution 7 | { 8 | public: 9 | int maxCoins(vector &A) 10 | { 11 | sort(A.begin(), A.end()); 12 | int res = 0, n = A.size(); 13 | for (int i = n / 3; i < n; i += 2) 14 | res += A[i]; 15 | return res; 16 | } 17 | }; 18 | 19 | int main() 20 | { 21 | Solution a; 22 | vector input = {2, 4, 1, 2, 7, 8}; 23 | int result = a.maxCoins(input); 24 | cout << result << endl; 25 | return 0; 26 | } -------------------------------------------------------------------------------- /src/Leetcode/1614_maximum-nesting-depth-of-the-parentheses.cpp: -------------------------------------------------------------------------------- 1 | // Problem Statement: https://leetcode.com/problems/maximum-nesting-depth-of-the-parentheses/ 2 | 3 | #include 4 | using namespace std; 5 | 6 | class Solution 7 | { 8 | public: 9 | int maxDepth(string s) 10 | { 11 | int res = 0, count = 0; 12 | for (int i = 0; i < s.size(); ++i) 13 | { 14 | if (s[i] == '(') 15 | count++; 16 | else if (s[i] == ')') 17 | count--; 18 | res = max(count, res); 19 | } 20 | return res; 21 | } 22 | }; 23 | 24 | int main() 25 | { 26 | Solution a; 27 | cout << a.maxDepth("(1+(2*3)+((8)/4))+1") << "\n"; 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /src/Leetcode/1662_check-if-two-string-arrays-are-equivalent.cpp: -------------------------------------------------------------------------------- 1 | // Problem Statement: https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/ 2 | 3 | #include 4 | using namespace std; 5 | 6 | class Solution 7 | { 8 | public: 9 | bool arrayStringsAreEqual(vector word1, vector word2) 10 | { 11 | string a = "", b = ""; 12 | for (auto i : word1) 13 | a += i; 14 | for (auto i : word2) 15 | b += i; 16 | return a == b; 17 | } 18 | }; 19 | 20 | int main() 21 | { 22 | Solution a; 23 | cout << a.arrayStringsAreEqual({"ab", "c"}, {"a", "bc"}) << "\n"; 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /src/Leetcode/168_excel-sheet-column-title.cpp: -------------------------------------------------------------------------------- 1 | // Problem Statement: https://leetcode.com/problems/excel-sheet-column-number/ 2 | 3 | #include 4 | using namespace std; 5 | 6 | class Solution 7 | { 8 | public: 9 | string convertToTitle(int n) 10 | { 11 | string result; 12 | while (n) 13 | result.push_back('A' + (n - 1) % 26), n = (n - 1) / 26; 14 | reverse(result.begin(), result.end()); 15 | return result; 16 | } 17 | 18 | string convertToTitle(int n) 19 | { 20 | return (n == 0) ? "" : convertToTitle((n - 1) / 26) + char(--n % 26 + 65); 21 | } 22 | }; 23 | 24 | int main() 25 | { 26 | Solution a; 27 | cout << a.convertToTitle(800) << "\n"; 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /src/Leetcode/171_excel-sheet-column-number.cpp: -------------------------------------------------------------------------------- 1 | // Problem Statement: https://leetcode.com/problems/excel-sheet-column-number/ 2 | 3 | #include 4 | using namespace std; 5 | 6 | class Solution 7 | { 8 | public: 9 | int titleToNumber(string s) 10 | { 11 | int result = 0, comb = s.size(); 12 | for (int i = comb - 1; i >= 0; i--) 13 | result += pow(26, comb - i - 1) * ((int)s[i] - 64); 14 | return result; 15 | } 16 | }; 17 | 18 | int main() 19 | { 20 | Solution a; 21 | cout << a.titleToNumber("AX") << "\n"; 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /src/Leetcode/183_customers-who-never-order.sql: -------------------------------------------------------------------------------- 1 |