├── Atcoder Problems ├── ABC 146 │ ├── A.cpp │ └── B.cpp ├── ABC 161 │ ├── A.cpp │ ├── B.cpp │ └── C.cpp ├── ABC154 │ ├── A.cpp │ ├── B.cpp │ └── C.cpp ├── AtCoder Beginner Contest 131 │ └── Security.cpp ├── AtCoder Beginner Contest 133 │ └── Good Distance.cpp ├── AtCoder Beginner Contest 134 │ ├── Dodecagon.cpp │ └── Golden Apples.cpp ├── AtCoder Beginner Contest 135 │ ├── 0 or 1 Swap.cpp │ └── Harmony.cpp ├── AtCoder Beginner Contest 136 │ ├── Build Stairs.cpp │ ├── Transfer.cpp │ └── Uneven Numbers.cpp ├── AtCoder Beginner Contest 137 │ ├── +-x.cpp │ ├── Green Bin.cpp │ └── One Clue.cpp ├── AtCoder Beginner Contest 138 │ ├── Alchemist.cpp │ ├── Red or Not.cpp │ └── Resistors in Parallel.cpp ├── AtCoder Beginner Contest 139 │ ├── Lower.cpp │ ├── Power Socket.cpp │ └── Tenki.cpp ├── AtCoder Beginner Contest 140 │ ├── Buffet.cpp │ └── Password.cpp ├── AtCoder Beginner Contest 141 │ ├── Tap Dance.cpp │ └── Weather Prediction.cpp ├── AtCoder Beginner Contest 142 │ ├── Disjoint set of Common divisors.cpp │ ├── Go to School.cpp │ ├── Odds of Oddness.cpp │ └── Roller Coaster.cpp ├── AtCoder Beginner Contest 143 │ ├── Curtain.cpp │ ├── Slimes.cpp │ ├── Takoyaki Festival 2019.cpp │ └── Triangles.cpp ├── AtCoder Beginner Contest 144 │ ├── 81.cpp │ ├── 9 x 9.cpp │ └── Walk On Multiplication Table.cpp ├── Atcoder Beginner Contest │ └── abc176_a.cpp ├── Keyence Programming Contest │ └── Painting.cpp ├── Panasonic Programming Contest 2020 │ └── A.cpp ├── Social Infrastructure Information Systems Division, Hitachi Programming Contest 2020 │ ├── A.cpp │ └── B.cpp ├── abc152 │ ├── AC OR WA.cpp │ └── Comparing Strings.cpp ├── abc153 │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ └── D.cpp ├── abc173_c(Efficient).cpp └── abc173_c.cpp ├── CP Book Problems ├── 2 Queens Problem.cpp ├── Maximum_subarray_sum O(n).cpp ├── N-Queens Problem_ways.cpp ├── Peremutation Recusrsion.cpp └── Subsets_Creation_Recursion.cpp ├── CSES Problem Set ├── Dynamic Programming │ ├── Coin Combinations 1.cpp │ ├── Coin Combinations(2).cpp │ ├── Dice Combinations.cpp │ ├── Increasing Subsequence.cpp │ └── Minimizing Coins.cpp ├── Introductory Problems │ ├── Bit Strings.cpp │ ├── Chessboard and Queens.cpp │ ├── Coin Piles.cpp │ ├── Creating Strings I.cpp │ ├── Increasing Array.cpp │ ├── Missing Number.cpp │ ├── Palindrome Reorder.cpp │ ├── Permutations.cpp │ ├── Repetitions.cpp │ ├── Trailing Zeros.cpp │ ├── Two Knights.cpp │ ├── Two Sets.cpp │ └── Weird Algorithm.cpp ├── Maximum Subarray.cpp ├── Movie Festival.cpp ├── Number Spiral.cpp └── Sorting and Searching │ ├── Apartments.cpp │ ├── Array Division.cpp │ ├── Distinct Numbers.cpp │ ├── Factory Machines.cpp │ ├── Ferris Wheel.cpp │ ├── Maximum Subarray Sum(Appraoch 2).cpp) │ ├── Maximum Subarray Sum.cpp │ ├── Movie Festival.cpp │ ├── Nearest Smaller Values.cpp │ ├── Playlist.cpp │ ├── Reading Books.cpp │ ├── Restaurant Customers.cpp │ ├── Room Allocation.cpp │ ├── Sliding Cost.cpp │ ├── Sliding Median.cpp │ ├── Stick Lengths.cpp │ ├── Subarray Divisibility.cpp │ ├── Subarray Sums I.cpp │ ├── Subarray Sums II.cpp │ ├── Sum of Four Values.cpp │ ├── Sum of Three Values.cpp │ ├── Sum of Two Values.cpp │ ├── Tasks and Deadlines.cpp │ ├── Towers.cpp │ └── Traffic Lights.cpp ├── Codechef Problems ├── 1493A.cpp ├── 1493B.cpp ├── ADASHOP2.cpp ├── ADJLOVE.cpp ├── ALTERNATEDIV.cpp ├── ALTSTR.cpp ├── ANDOR.cpp ├── ANDORUNI.cpp ├── ANTI_PAL.cpp ├── ARRROT.cpp ├── AVG.cpp ├── AVOIDCONTACT.cpp ├── BALREV.cpp ├── BENCHCP.cpp ├── BFRIEND.cpp ├── BINFUN(Partial).cpp ├── BINSTRING.cpp ├── BIT2A.cpp ├── BOWLERS.cpp ├── BRKBKS.cpp ├── CACHEHIT.cpp ├── CASH.cpp ├── CATFEED.cpp ├── CCD.cpp ├── CCHEAVEN.cpp ├── CENS20D.cpp ├── CENS20G.cpp ├── CHARGES.cpp ├── CHEALG.cpp ├── CHECHOC.cpp ├── CHEFDIL.cpp ├── CHEFGRD.cpp ├── CHEFINSQ.cpp ├── CHEFNWRK.cpp ├── CHEFRECP.cpp ├── CHEFSETC.cpp ├── CHEFSORT.cpp ├── CHEFSTEP.cpp ├── CHEFSTLT.cpp ├── CHEFWARS.cpp ├── CHEFWM.cpp ├── CHEGLOVE.cpp ├── CHFCHK.cpp ├── CHFIDEAL.cpp ├── CHFM.cpp ├── CHFMOT18.cpp ├── CHPINTU.cpp ├── CIRCLEGAME.cpp ├── CKWLK.cpp ├── CLBRKT.cpp ├── CLPNT.cpp ├── CM164364.cpp ├── CNTAR.cpp ├── COINS.cpp ├── COKE.cpp ├── COLE2020.cpp ├── COMM3.cpp ├── CONDEL.cpp ├── COVID19.cpp ├── COW3A.cpp ├── COW3B.cpp ├── COW3C.cpp ├── COWA19B.cpp ├── CRDGAME3.cpp ├── CV.cpp ├── CXORJ.cpp ├── DCP.cpp ├── DIET.cpp ├── DIGSMPAR.cpp ├── DISTCON.cpp ├── DISTK.cpp ├── DIVREC.cpp ├── DSA Learning Series │ ├── CARVANS.cpp │ ├── CONFLIP.cpp │ ├── Contest 1 │ │ ├── LADDU.cpp │ │ └── MULTHREE.cpp │ ├── Contest 8 │ │ └── ENOC1.cpp │ ├── FCTRL.cpp │ ├── FLOW007.cpp │ ├── LAPIN.cpp │ ├── TEST.cpp │ ├── Week 2 │ │ ├── COMPILER.cpp │ │ ├── PSHOT.cpp │ │ ├── STFOOD.cpp │ │ └── STUPMACH.cpp │ └── ZCO14003.cpp ├── DSTAPLS.cpp ├── DYNAMO.cpp ├── EID2.cpp ├── ELOMAX.cpp ├── ELWINTER (Approach 2).cpp ├── ELWINTER.cpp ├── ENGXOR.cpp ├── EOOPR.cpp ├── EQLIS.cpp ├── EQUALMEX.cpp ├── EVENTUAL.cpp ├── EVENXOR.cpp ├── EXAM1.cpp ├── EXAMCHT.cpp ├── EXUNA.cpp ├── EXUNB.cpp ├── FFL.cpp ├── FIBEASY.cpp ├── FINDSHOES.cpp ├── FINXOR.cpp ├── FIXWEIGHT.cpp ├── FLIP.cpp ├── FLIPSORT.cpp ├── FLOW004.cpp ├── FLOW006.cpp ├── FLOW013.cpp ├── GCDOPS.cpp ├── GFTSHP.cpp ├── GIFTSRC.cpp ├── GOODBINTREE.cpp ├── GRIDXOR.cpp ├── GUESSIT.cpp ├── HIT.cpp ├── HRDSEQ.cpp ├── HS08TEST.cpp ├── IEMCO02.cpp ├── INCRDEC.cpp ├── INTEST.cpp ├── INTSEQ.cpp ├── IPCCERT.cpp ├── JKR1.cpp ├── JMARKET.cpp ├── KCHESS.cpp ├── KETEKI2A.cpp ├── KTTABLE.cpp ├── LIFTME.cpp ├── LINCHESS.cpp ├── LOSTWKND.cpp ├── MAGICMOD.cpp ├── MAGNETSORT.cpp ├── MARM.cpp ├── MATBREAK.cpp ├── MATCHES.cpp ├── MATHL.cpp ├── MATXOR.cpp ├── MAXAND18.cpp ├── MAXMEX.cpp ├── MAXTHEMIN.cpp ├── MDL.cpp ├── MEANMAX.cpp ├── MERGEBS.cpp ├── MERGEDLIS.cpp ├── MEXSPLIT.cpp ├── MINCOLOR.cpp ├── MINIAND.cpp ├── MODEFREQ.cpp ├── MSNSADM1.cpp ├── MSV.cpp ├── NCOPRIMEN.coo ├── NOPAL.cpp ├── NUMCOMP1.cpp ├── ORANDCON.cpp ├── OROFAND.cpp ├── ORTHODOX.cpp ├── PAJAPONG.cpp ├── PERCAPTA(Iterative DFS).cpp ├── PERCAPTA(Recursive DFS).cpp ├── PERFPERM.cpp ├── PERMEX.cpp ├── PERMXORITY.cpp ├── PHCUL.cpp ├── PILGRIMS.cpp ├── PIPSQUIK.cpp ├── PLAYSTR.cpp ├── PLMU.cpp ├── PLPROCESS.cpp ├── PMA.cpp ├── POLIN.cpp ├── POPGATES.cpp ├── PPSUM.cpp ├── PREFPERM.cpp ├── PREZ.cpp ├── PRFXGD.cpp ├── PRODUCT.cpp ├── PROXYC.cpp ├── PTMSSNG(XOR Approach).cpp ├── PTMSSNG.cpp ├── RAINDROPS.cpp ├── RECNDNOS.cpp ├── RECNDSTR.cpp ├── RECSTI.cpp ├── ROBOGAME.cpp ├── ROOKPATH.cpp ├── ROOTTREE.cpp ├── RPD.cpp ├── S10E.cpp ├── SAKTAN.cpp ├── SC31.cpp ├── SEDARR.cpp ├── SEGDIV.cpp ├── SHUFFLE.cpp ├── SIGNMOVE.cpp ├── SKMP.cpp ├── SNUG_FIT.cpp ├── SPECIALSTR.cpp ├── SPLITPAIR.cpp ├── SPTREE(60 POINTS).cpp ├── STFOOD.cpp ├── STRP.cpp ├── STR_REVERSE.cpp ├── SUBMEXS.cpp ├── SUBPERM.cpp ├── SUMPARITY.cpp ├── SUNDAY.cpp ├── SWAP10HG.cpp ├── SWPDGT.cpp ├── TANDJ1.cpp ├── TLAPM.cpp ├── TLG.cpp ├── TOWERTOP.cpp ├── TOWIN.cpp ├── TRAINPLN.cpp ├── TRAVELLING (01-BFS).cpp ├── TRAVELLING (dijkstra).cpp ├── TRISQ.cpp ├── TSTROBOT-approach-2.cpp ├── TSTROBOT.cpp ├── The Lead Game.cpp ├── UNCHANGEDOR.cpp ├── UWCOI20A.cpp ├── UWCOI20B.cpp ├── VCS.cpp ├── VILLINE.cpp ├── VOTERS.cpp ├── WATCHFB.cpp ├── WATMELON.cpp ├── WATSCORE.cpp ├── WWALK.cpp ├── XORAND.cpp ├── ZC015002.cpp ├── ZCO12001.cpp ├── ZCO12002.cpp ├── ZCO14001.cpp └── ZOMCAV.cpp ├── Codeforces problems ├── 1088A.cpp ├── 1088B.cpp ├── 1097B.cpp ├── 110A.cpp ├── 1174A.cpp ├── 1174B.cpp ├── 1178A.cpp ├── 1178B.cpp ├── 1178C.cpp ├── 1178D.cpp ├── 1180A.cpp ├── 1183A.cpp ├── 1183B.cpp ├── 1183C.cpp ├── 1183D.cpp ├── 1186A.cpp ├── 1187A.cpp ├── 1187B.cpp ├── 1187C.cpp ├── 1194A.cpp ├── 1194B.cpp ├── 1194C.cpp ├── 1196A.cpp ├── 1196B.cpp ├── 1197A.cpp ├── 1197B.cpp ├── 1197C.cpp ├── 1204A.cpp ├── 1204B.cpp ├── 1206A.cpp ├── 1206B.cpp ├── 1208A.cpp ├── 1216 A.cpp ├── 1216 B.cpp ├── 1221A.cpp ├── 1228A.cpp ├── 1228B.cpp ├── 1228C.cpp ├── 1230A.cpp ├── 1230B.cpp ├── 1234A.cpp ├── 1241A.cpp ├── 1241B.cpp ├── 1243A.cpp ├── 1244A.cpp ├── 1247A.cpp ├── 1249A.cpp ├── 1255A.cpp ├── 1256A.cpp ├── 1256B.cpp ├── 1257A.cpp ├── 1260A.cpp ├── 1279A.cpp ├── 1279B.cpp ├── 1282 A.cpp ├── 1282(B1).cpp ├── 1282(B2).cpp ├── 1283A.cpp ├── 1283B.cpp ├── 1285A.cpp ├── 1285B .cpp ├── 1285C.cpp ├── 1287A.cpp ├── 1288(B).cpp ├── 1293A.cpp ├── 1293B.cpp ├── 1294A.cpp ├── 1294B.cpp ├── 1296A.cpp ├── 1296B.cpp ├── 1303A.cpp ├── 1311A.cpp ├── 1311B.cpp ├── 1313A.cpp ├── 1321A.cpp ├── 1325A.cpp ├── 1325B.cpp ├── 1326A.cpp ├── 1327A.cpp ├── 1327B.cpp ├── 1328A.cpp ├── 1328B.cpp ├── 1330.cpp ├── 1330A(eff).cpp ├── 1330A.cpp ├── 1333B.cpp ├── 1339A.cpp ├── 1339B.cpp ├── 1341A.cpp ├── 1341B.cpp ├── 1342A.cpp ├── 1342B.cpp ├── 1343A.cpp ├── 1343B.cpp ├── 1343C.cpp ├── 1345A.cpp ├── 1345B.cpp ├── 1348A.cpp ├── 1348B.cpp ├── 1350A.cpp ├── 1350B.cpp ├── 1352A.cpp ├── 1352B.cpp ├── 1352C.cpp ├── 1352D.cpp ├── 1352E.cpp ├── 1352F.cpp ├── 1352G.cpp ├── 1353A.cpp ├── 1353B.cpp ├── 1353C.cpp ├── 1353D.cpp ├── 1354A.cpp ├── 1354B.cpp ├── 1355B.cpp ├── 1358A.cpp ├── 1358B.cpp ├── 1359A.cpp ├── 1359B.cpp ├── 1362A.cpp ├── 1362B.cpp ├── 1363A.cpp ├── 1363B.cpp ├── 1364A.cpp ├── 1364B.cpp ├── 1365A.cpp ├── 1365B.cpp ├── 1366A.cpp ├── 1366B.cpp ├── 1367A.cpp ├── 1367B.cpp ├── 1367C.cpp ├── 1368A.cpp ├── 1368B.cpp ├── 1368C.cpp ├── 1369A.cpp ├── 1370A.cpp ├── 1370B(Approach 2).cpp ├── 1370B.cpp ├── 1370C.cpp ├── 1371A.cpp ├── 1371C.cpp ├── 1372A.cpp ├── 1373A.cpp ├── 1373B.cpp ├── 1373C.cpp ├── 1374A.cpp ├── 1374B.cpp ├── 1374C.cpp ├── 1374D.cpp ├── 1375A.cpp ├── 1375B(Eff.Approach).cpp ├── 1375B.cpp ├── 1380A.cpp ├── 1380B.cpp ├── 1380C.cpp ├── 1382A.cpp ├── 1382B.cpp ├── 1382C1.cpp ├── 1385B.cpp ├── 1388A.cpp ├── 1388B.cpp ├── 1389A.cpp ├── 1391A.cpp ├── 1391B.cpp ├── 1392A.cpp ├── 1392B.cpp ├── 1393A.cpp ├── 1398A.cpp ├── 1398B.cpp ├── 1399A.cpp ├── 1399B.cpp ├── 1401A.cpp ├── 1401B.cpp ├── 1467A.cpp ├── 1467B.cpp ├── 1471A.cpp ├── 1471B.cpp ├── 1472A.cpp ├── 1472B.cpp ├── 1472C.cpp ├── 1473A.cpp ├── 1473B.cpp ├── 1476A.cpp ├── 1481A.cpp ├── 1481B.cpp ├── 1481C.cpp ├── 1481D.cpp ├── 1490C.cpp ├── 1494A.cpp ├── 1494B.cpp ├── 1496A.cpp ├── 1501A.cpp ├── 1501B.cpp ├── 1504A.cpp ├── 1506A.cpp ├── 1506B.cpp ├── 1506C.cpp ├── 1514A.cpp ├── 1529A.cpp ├── 1566A.cpp ├── 1566B.cpp ├── 1566C.cpp ├── 1566D1.cpp ├── 1566D2.cpp ├── 1604A.cpp ├── 1604B.cpp ├── 1604C.cpp ├── 1624A.cpp ├── 1624B.cpp ├── 1624C [approach 2].cpp ├── 1624C.cpp ├── 1624D.cpp ├── 1626A.cpp ├── 1626B.cpp ├── 1627A.cpp ├── 1627B.cpp ├── 1627C.cpp ├── 1627D(Approach 1).cpp ├── 1627D(Approach 2).cpp ├── 1629A.cpp ├── 1629B.cpp ├── 1629C.cpp ├── 1629D.cpp ├── 1633A.cpp ├── 1633B.cpp ├── 1633C.cpp ├── 1633D.cpp ├── 1634A.cpp ├── 1634B.cpp ├── 1634C.cpp ├── 1634D.cpp ├── 1635A.cpp ├── 1635B.cpp ├── 1635C.cpp ├── 1635D.cpp ├── 1637A.cpp ├── 1637B.cpp ├── 1637C.cpp ├── 1638A.cpp ├── 1638B.cpp ├── 1638C [Stack approach].cpp ├── 1638C.cpp ├── 1642A.cpp ├── 1642B.cpp ├── 1642C.cpp ├── 1644A.cpp ├── 1644B.cpp ├── 1644C.cpp ├── 1644D.cpp ├── 1646A.cpp ├── 1646B.cpp ├── 1646C.cpp ├── 1647A.cpp ├── 1647B.cpp ├── 1647C.cpp ├── 1650A.cpp ├── 1650B.cpp ├── 1650C.cpp ├── 1650D.cpp ├── 1651A.cpp ├── 1651B.cpp ├── 1654A.cpp ├── 1654B.cpp ├── 1654C.cpp ├── 1656A.cpp ├── 1656B.cpp ├── 1656C.cpp ├── 1657A.cpp ├── 1657B.cpp ├── 1657C.cpp ├── 1658A.cpp ├── 1658B.cpp ├── 1658C.cpp ├── 165A.cpp ├── 1661A.cpp ├── 1665B.cpp ├── 1775A1.cpp ├── 1775A2.cpp ├── 1775B.cpp ├── 224A.cpp ├── 34A.cpp ├── 445A.cpp ├── 476B(Without Bitset).cpp ├── 476B(nCr Approach).cpp ├── 476B.cpp ├── 766A.cpp ├── 959A.cpp ├── 959B.cpp ├── Codeforces Beta Round 99 │ └── Petr and Book.cpp ├── Codeforces Round #582 (Div. 3) │ └── chips.cpp ├── Codeforces Round 578 │ └── Hotelier.cpp ├── Codeforces Round 583 │ └── Optimal Currency Exchange.cpp ├── Codeforces Round 586 │ └── Cards.cpp └── OMWG.cpp ├── Commonlounge └── Basics Playlist │ ├── Add.cpp │ ├── Counting To Infinity.cpp │ ├── Dictionary.cpp │ ├── Drought.cpp │ ├── Encyclopedia.cpp │ ├── Mixed Fraction.cpp │ ├── SitStand.cpp │ ├── Tremendous Tak Tak.cpp │ └── Triple Hunting.cpp ├── Competitions ├── CodeGladiators │ ├── Problem A.cpp │ └── Problem B.cpp ├── Cogno AI │ └── Raj and cards.cpp ├── Facebook HackerCup 2020 │ ├── Alchemy.cpp │ └── Travel Restrictions.cpp ├── Google Code Jam │ └── 2022 │ │ ├── Qualification Round │ │ ├── 3D Printing.cpp │ │ ├── Punched Cards.cpp │ │ └── d1000000.cpp │ │ └── Round 1A │ │ └── Double or One Thing (10pts, 15pts).cpp └── Google Kickstart │ ├── 2022 │ ├── Practice Round 1 │ │ ├── Centauri_Prime.cpp │ │ ├── H_index.cpp │ │ └── Sample Problem.cpp │ └── Round A │ │ ├── Challenge Nine.cpp │ │ ├── Interesting Integers.cpp │ │ ├── Palindrome Free Strings (Partial).cpp │ │ └── Speed Typing.cpp │ ├── Round B │ ├── Bike Tour.cpp │ ├── Bus Routes.cpp │ └── RobotPathDecoding.cpp │ ├── Round C │ └── Countdown.cpp │ ├── Round D │ └── Record Breaker.cpp │ └── Round E │ └── Longest Arithmetic.cpp ├── Dynamic Programming ├── CSES │ ├── Coin Combinations 1.cpp │ ├── Dice Combinations.cpp │ ├── Increasing Subsequence.cpp │ └── Minimizing Coins.cpp ├── Codechef │ ├── CHEFWED.cpp │ ├── JAM11(Recursive).cpp │ ├── JAM11.cpp │ └── TILE.cpp ├── Codeforces │ ├── 1506B.cpp │ └── Choice_Diagram_1506B.jpeg ├── GeeksforGeeks │ ├── Fibonacci(1).cpp │ └── Ugly Numbers.cpp ├── Leetcode Problems │ ├── Coin-Change │ │ ├── Bottom_up.cpp │ │ └── Memoized.cpp │ └── Wildcard Matching.cpp └── Other Problems │ ├── Knapsack and it's Variants │ ├── 01 Knapsack │ │ ├── Bottom_up.cpp │ │ ├── Memoized.cpp │ │ └── Recursive.cpp │ ├── Count Subsets with given difference │ │ ├── Bottom_up.cpp │ │ ├── Memoized.cpp │ │ └── Recursion.cpp │ ├── Count subsets with given sum │ │ ├── Bottom_up.cpp │ │ ├── Memoized.cpp │ │ └── Recursion.cpp │ ├── Equal_Sum_Partition │ │ ├── Bottom_up.cpp │ │ ├── Memoized.cpp │ │ └── Recursive.cpp │ ├── Minimum_Subset_Difference │ │ ├── Bottom_up.cpp │ │ ├── Memoized.cpp │ │ └── Recursion.cpp │ ├── Subset Sum Problem │ │ ├── BottomUp.cpp │ │ ├── Memoized Recursion(DP).cpp │ │ └── Recursive.cpp │ └── Target_Sum │ │ ├── Bottom_up.cpp │ │ ├── Memoized.cpp │ │ └── Recursion.cpp │ ├── Longest_Common_Subsequence and its variants │ ├── LCS │ │ ├── Bottom_up and Printing LCS.cpp │ │ ├── Memoized.cpp │ │ └── Recursion.cpp │ ├── Longest Repeating Subsequence.cpp │ ├── Longest palindromic subsequence.cpp │ ├── Longest_Common_Substring │ │ ├── Bottom_up.cpp │ │ ├── Memoized.cpp │ │ └── Recursion.cpp │ ├── Min insertions and deletions to convert str a to str b.cpp │ ├── Min. Deletions in a string to make it palindrome.cpp │ ├── Min. Insertions in a string to make it palindrome.cpp │ ├── Sequence Pattern Matching.cpp │ └── Shortest common supersequence.cpp │ ├── Matrix chain multiplication and it's variants │ ├── Evaluate expression to true.cpp │ ├── Matric chain multiplication.cpp │ └── Palindrome Partitioning.cpp │ └── Unbounded Knapsack and it's variants │ ├── Coin_change2 │ ├── Bottom_up.cpp │ ├── Memoized.cpp │ └── Recursive.cpp │ ├── Minimum_Coins │ ├── Bottom_up.cpp │ ├── Memoized.cpp │ └── Recursive.cpp │ ├── Rod_Cutting │ ├── Bottom_up.cpp │ ├── Memoized.cpp │ └── Recursion.cpp │ └── Unbounded Knapsack │ ├── Bottom_up.cpp │ ├── Memoized.cpp │ └── Recursion.cpp ├── GeeksForGeeks Problems ├── Digit multiplier.cpp └── Maximum even sum subsequence of length K.cpp ├── Hackerrank Problems ├── Array Manipulation.cpp ├── Closest Numbers.cpp ├── Construct the array.cpp ├── Queue using Two Stacks.cpp ├── Service Lane.cpp └── The Coin Change Problem.cpp ├── Leetcode problems(contest) ├── 1448.cpp ├── 1822.cpp ├── 1911.cpp ├── 2160.cpp ├── 2161.cpp ├── 2162.cpp ├── 2163.cpp ├── 2176.cpp ├── 2177.cpp └── 2178.cpp ├── My Practice(Algorithms) ├── Binary Exponentiation.cpp ├── Difference_array.cpp ├── Dynamic Programming │ └── LIS │ │ ├── Exponential.cpp │ │ ├── N2.cpp │ │ └── NLogN.cpp ├── Graphs │ ├── 01 BFS (Shortest path).cpp │ ├── BFS.cpp │ ├── Connected_Components.cpp │ ├── DFS(Iterative).cpp │ ├── DFS(Recursive).cpp │ ├── Dijkstra Algorithm.cpp │ ├── Kuhn's algorithm(Maximum bipartite macthing).cpp │ └── Lowest common ancestor(LCA) │ │ └── ENOC1.cpp ├── Linked List implementation.cpp ├── Merge_sort.cpp ├── Prime factorization │ ├── O(Log(n))_for_queries.cpp │ ├── O(n).cpp │ └── O(sqrt(n)).cpp └── Sieve of eratosthenes │ ├── Normal.cpp │ └── Optimized.cpp ├── Numpy_practice.ipynb ├── Plottting_in_python.ipynb ├── README.md ├── Random Problems ├── Digit_sum_to_N.cpp ├── Find longest palindromic digit formed by removing or shuffling digits from number.cpp ├── Interview Prep │ ├── Arrays │ │ ├── Hard │ │ │ └── Sliding Window Maximum.cpp │ │ └── Medium │ │ │ ├── Kadane's Algorithm.cpp │ │ │ ├── Min number of swaps to sort.cpp │ │ │ ├── Police and Theif.cpp │ │ │ └── Spiral Matrix.cpp │ ├── Binary Search Tree │ │ ├── Easy │ │ │ ├── Ceil In a BST.cpp │ │ │ ├── Floor in a BST.cpp │ │ │ ├── LCA of a BST.cpp │ │ │ ├── Search in a Binary Search Tree (700).cpp │ │ │ └── Two Sum IV - Input is a BST (653).cpp │ │ └── Medium │ │ │ ├── Binary Search Tree Iterator (173).cpp │ │ │ ├── Construct Binary Search Tree from Preorder Traversal (1008).cpp │ │ │ ├── Delete Node in a BST (450).cpp │ │ │ ├── Inorder Successor in BST.cpp │ │ │ ├── Insert into a Binary Search Tree.cpp │ │ │ ├── Kth Smallest Element in a BST (230).cpp │ │ │ ├── Largest BST Subtree.cpp │ │ │ ├── Recover Binary Search Tree(99).cpp │ │ │ └── Validate Binary Search Tree (98).cpp │ ├── Binary Tree │ │ ├── Easy │ │ │ ├── Balanced Binary Tree (110).cpp │ │ │ ├── Binary Tree Inorder Traversal (94).cpp │ │ │ ├── Binary Tree Postorder Traversal (145).cpp │ │ │ ├── Binary Tree Preorder Traversal (144).cpp │ │ │ ├── Diameter of Binary Tree (543).cpp │ │ │ ├── Maximum Depth of Binary Tree(104).cpp │ │ │ ├── Path to Given Node.cpp │ │ │ ├── Same Tree (100).cpp │ │ │ └── Symmetric Tree (101).cpp │ │ ├── Hard │ │ │ ├── Binary Tree Maximum Path Sum (124).cpp │ │ │ ├── Serialize and Deserialize Binary Tree (297).cpp │ │ │ ├── Time to burn tree.cpp │ │ │ └── Vertical Order Traversal of a Binary Tree (987).cpp │ │ └── Medium │ │ │ ├── All Nodes Distance K in Binary Tree.cpp │ │ │ ├── Binary Tree Level Order Traversal.cpp │ │ │ ├── Binary Tree Right side view (199).cpp │ │ │ ├── Binary Tree Zigzag Level Order Traversal (103).cpp │ │ │ ├── Bottom view of binary tree.cpp │ │ │ ├── Boundary Traversal.cpp │ │ │ ├── Children Sum property.cpp │ │ │ ├── Construct Binary Tree from Inorder and Postorder Traversal (106).cpp │ │ │ ├── Construct Binary Tree from Preorder and Inorder Traversal (105).cpp │ │ │ ├── Count Complete Tree Nodes (222).cpp │ │ │ ├── Flatten Binary Tree to Linked List (114).cpp │ │ │ ├── Lowest Common Ancestor (236).cpp │ │ │ ├── Maximum Width of Binary Tree (662).cpp │ │ │ └── Top view of Binary Tree.cpp │ ├── Get the Maximum Score.cpp │ ├── Graphs │ │ ├── Easy │ │ │ ├── BFS.cpp │ │ │ ├── DFS.cpp │ │ │ └── Flood Fill.cpp │ │ ├── Hard │ │ │ ├── Articulation points.cpp │ │ │ ├── Word Ladder 2.cpp │ │ │ └── Word Ladder.cpp │ │ └── Medium │ │ │ ├── Alien Dictionary.cpp │ │ │ ├── Bellman Ford Algorithm(Printing Negative weight cycle too).cpp │ │ │ ├── Bridges in Graph.cpp │ │ │ ├── Check if graph is Bipartite.cpp │ │ │ ├── Clone Graph.cpp │ │ │ ├── Course Schedule.cpp │ │ │ ├── Detect Cycle in undirected graph.cpp │ │ │ ├── Detect cycle in a directed graph.cpp │ │ │ ├── Dijkstra Algorithm.cpp │ │ │ ├── Kruskal's Algorithm MST.cpp │ │ │ ├── Min number of swaps to sort.cpp │ │ │ ├── Number of Islands.cpp │ │ │ ├── Prim's algorithm MST.cpp │ │ │ ├── Shortest Path in Directed Acyclic Graph (DAG).cpp │ │ │ ├── Shortest Path in undirected graph with 01 weights.cpp │ │ │ ├── Strongly Connected Components (Kosaraju's algorithm).cpp │ │ │ ├── Topological Sort.cpp │ │ │ └── Word_boggle.cpp │ ├── Linked List │ │ ├── Easy │ │ │ ├── Cycle in Linked List.cpp │ │ │ ├── Intersection of Two Linked List.cpp │ │ │ ├── Merge Two Sorted Lists.cpp │ │ │ ├── Remove Duplicates from Sorted List.cpp │ │ │ └── Remove Linked List Elements.cpp │ │ ├── Hard │ │ │ ├── LFU Cache (460).cpp │ │ │ ├── Merge k Sorted Lists (23).cpp │ │ │ └── Reverse Nodes in k-group (25).cpp │ │ └── Medium │ │ │ ├── LRU Cache (146).cpp │ │ │ ├── Partition List (86).cpp │ │ │ ├── Reverse Linked List II (92).cpp │ │ │ ├── Rotate List (61).cpp │ │ │ ├── Sort List (148).cpp │ │ │ └── Swap Nodes in Pairs.cpp │ ├── OOPS │ │ ├── Abstract Class.cpp │ │ ├── Const keyword │ │ │ ├── Const Member Function.cpp │ │ │ └── Const keyword in object creation.cpp │ │ ├── Constructors │ │ │ ├── Copy Constructor │ │ │ │ ├── Deep copy.cpp │ │ │ │ ├── Default Copy Constructor.cpp │ │ │ │ ├── Shallow Copy.cpp │ │ │ │ └── User-defined Copy Constructor.cpp │ │ │ ├── Default Constructor.cpp │ │ │ └── Parameterized Constructor.cpp │ │ ├── Copy Assignment Operator.cpp │ │ ├── Destructor.cpp │ │ ├── Friend Class.cpp │ │ ├── Friend Function.cpp │ │ ├── Getter and Setters.cpp │ │ ├── Initializer list │ │ │ ├── Basic.cpp │ │ │ └── Places where initializer list is used │ │ │ │ ├── Const object.cpp │ │ │ │ ├── Initialization of Private data members in child class.cpp │ │ │ │ ├── Reference variable.cpp │ │ │ │ ├── When constructor’s parameter name is same as data member .cpp │ │ │ │ └── member objects with no default constructor.cpp │ │ ├── Pillars of OOPS │ │ │ ├── Abstraction.cpp │ │ │ ├── Encapsulation.cpp │ │ │ ├── Inheritance │ │ │ │ ├── Access Modes │ │ │ │ │ ├── Private Mode.cpp │ │ │ │ │ ├── Protected Mode.cpp │ │ │ │ │ └── Public mode.cpp │ │ │ │ ├── Basic.cpp │ │ │ │ ├── Inheritance Ambiguity resolved using (::).cpp │ │ │ │ └── Types of Inheritance │ │ │ │ │ ├── Heirarachical Inheritance.cpp │ │ │ │ │ ├── Multi Level Inheritance │ │ │ │ │ ├── Basic.cpp │ │ │ │ │ ├── Diamond Problem.cpp │ │ │ │ │ └── Solution to diamond problem.cpp │ │ │ │ │ ├── Multiple Inheritance.cpp │ │ │ │ │ └── Single Inheritance.cpp │ │ │ └── Polymorphism │ │ │ │ ├── Compile Time Polymorphism │ │ │ │ ├── Function OverLoading.cpp │ │ │ │ └── Operator Overloading │ │ │ │ │ ├── Example 1.cpp │ │ │ │ │ └── Example 2.cpp │ │ │ │ └── Run Time PolyMorphism │ │ │ │ ├── With Virtual Function.cpp │ │ │ │ └── Without Virtual Function.cpp │ │ ├── Static Keyword │ │ │ ├── Static Member Functions.cpp │ │ │ └── Static member.cpp │ │ └── Static and Dynamic Allocation.cpp │ ├── Recursion & Backtracking │ │ └── Medium │ │ │ └── Gray Code.cpp │ ├── Rotate array k times.cpp │ └── String Without AAA or BBB.cpp ├── Largest_stick.cpp ├── Longest substring.cpp ├── MaxBookRead.cpp ├── Maximize_Frog_Distance.cpp ├── Min deletions to make array unique.cpp ├── Minimum_Split.cpp ├── Minimum_operations.cpp └── Water_Supply.cpp ├── SPOJ Problems └── Bytelandian gold coins.cpp ├── Striver's CP List ├── Dynamic Programming │ ├── 1633D(Knapsack).cpp │ ├── 1635D.cpp │ ├── 1637D.cpp │ ├── Dp+graph+combinatrics.cpp │ ├── GOODBINTREE.cpp │ ├── MERGEBS.cpp │ ├── Maximum Alternating Subsequence Sum.cpp │ └── SPECIALSTR(DP + Binary lifting).cpp ├── Graphs │ ├── 01 BFS │ │ └── TRAVELLING.cpp │ ├── BFS │ │ ├── 1654C.cpp │ │ ├── ELWINTER (Approach 1).cpp │ │ └── ELWINTER (Approach 2).cpp │ ├── Dijkstra Algorithm │ │ └── TRAVELLING.cpp │ └── Maximum Bipartite Matching │ │ ├── 1624C.cpp │ │ └── Marriage Media.cpp ├── Hashing │ └── OR in Matrix.cpp ├── Implementation, Constructive │ ├── 1337A.cpp │ ├── 1358A.cpp │ ├── 1360A.cpp │ ├── 1367B.cpp │ ├── 1374A.cpp │ ├── 151A.cpp │ ├── 263A.cpp │ ├── 282A.cpp │ ├── 514A.cpp │ └── 723A.cpp ├── Math │ ├── 1337A.cpp │ ├── 1426A.cpp │ └── 732A.cpp ├── Prefix Sum │ ├── 1.Cumulative Sum Query.cpp │ ├── 3.Digit Primes.cpp │ ├── 6.COWA19B.cpp │ ├── KJ and street lights.cpp │ ├── Man with No Name.cpp │ └── Simple Modification.cpp └── Sliding Window │ ├── 1.Min Max Riddle.cpp │ ├── 2.Fence.cpp │ ├── 3.Shivigawdz.cpp │ ├── 4.BDGFT.cpp │ ├── 5.ECAPR206.cpp │ ├── 6.1341B.cpp │ └── 7.SUMPOWER.cpp └── Striver's SDE sheet ├── Day:1 (Arrays) ├── Find Repeat and Missing Number.cpp ├── Find the duplicate in an array of N+1 integers.cpp ├── Maximum Subarray.cpp ├── Merge two sorted Arrays without extra space.cpp ├── Merge_Intervals.cpp └── Sort an array of 0’s 1’s 2’s without using extra space or sorting algo.cpp ├── Day:2 (Arrays) ├── Best Time to Buy and Sell Stock.cpp ├── Count inversions.cpp ├── Next Permutation.cpp ├── Pascal's Triangle.cpp ├── Rotate Image.cpp └── Set Matrix Zeroes.cpp ├── Day:3 (Array and Maths) ├── Majority Element II.cpp ├── Majority Element.cpp ├── Pow(x,n).cpp ├── Reverse pairs.cpp ├── Search a 2D Matrix (GFG version).cpp ├── Search a 2D Matrix (Leetcode version).cpp └── Unique Paths.cpp ├── Day:4 (Hashing) ├── 2 Sum Problem.cpp ├── 4Sum.cpp ├── Count Subarrays with given XOR.cpp ├── Largest subarray with 0 sum.cpp ├── Longest Consecutive Sequence.cpp └── Longest Substring Without Repeating Characters.cpp └── Day:5 Linked List ├── 1.Reverse a linked list.cpp ├── 2. Middle of the Linked List.cpp ├── 3.Add Two Numbers.cpp ├── 3.Merge Two Sorted Lists.cpp ├── 4.Remove Nth Node From End of List.cpp └── 5. Delete Node in a Linked List.cpp /Atcoder Problems/ABC 146/A.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | //ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 7 | int n,a; 8 | cin>>n; 9 | string s; 10 | cin>>s; 11 | 12 | for(int i=0;i90){a=a-90;a+=64;} 17 | char c=char(a); 18 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | //ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 6 | int n,a; 7 | cin>>n; 8 | string s; 9 | cin>>s; 10 | 11 | for(int i=0;i90){a=a-90;a+=64;} 16 | char c=char(a); 17 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 6 | #define int long long int 7 | int a,b,c; 8 | cin>>a>>b>>c; 9 | swap(a,b); 10 | swap(a,c); 11 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 6 | #define int long long int 7 | int n,m,sum=0,cn=0,flag=0,cn1=0; 8 | cin>>n>>m; 9 | int a[n+1000]; 10 | for(int i=0;i>a[i];sum+=a[i];} 11 | int w=4*m; 12 | float x=(float)sum/(float)w; 13 | for(int i=0;i=x){cn++;} 16 | } 17 | if(cn 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 6 | #define int long long int 7 | int n,k; 8 | cin>>n>>k; 9 | int s=n/k; 10 | n=n-(s*k); 11 | while(1) 12 | { 13 | if(n>abs(n-k))n=abs(n-k); 14 | else break; 15 | } 16 | cout< 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | string s,t,u; 8 | int a,b; 9 | cin>>s>>t; 10 | cin>>a>>b; 11 | cin>>u; 12 | if(s==u)cout< 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | string s; 8 | cin>>s; 9 | for(int i=0;i 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | #define int long long int 8 | int n,flag=1; 9 | cin>>n; 10 | int a[n]; 11 | for(int i=0;i>a[i]; 14 | } 15 | sort(a,a+n); 16 | for(int i=0;i 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | char S[4]; 9 | cin>>S; 10 | int flag=0; 11 | for(int i=0;i 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int r; 8 | cin>>r; 9 | cout<<3*r*r; 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /Atcoder Problems/AtCoder Beginner Contest 134/Golden Apples.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 8 | int n,d,c,temp=0,cnt=0; 9 | cin>>n>>d; 10 | 11 | while(1) 12 | { 13 | temp+=d*2+1; 14 | cnt++; 15 | if(temp>=n) break; 16 | } 17 | cout< 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int n,a,s,cnt=0; 8 | cin>>n; 9 | vector v,h; 10 | 11 | for(int i=0;i>a; 14 | v.push_back(a); 15 | h.push_back(a); 16 | } 17 | sort(v.begin(),v.end()); 18 | 19 | for(int i=0;i 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int a,b,flag=0,mid; 8 | cin>>a>>b; 9 | mid=(a+b)/2; 10 | if(fabs(a-mid)==fabs(b-mid)) {flag=1;} 11 | if(flag==0) cout<<"IMPOSSIBLE"< 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int a,b,c; 8 | cin>>a>>b>>c; 9 | if(a-b>c){cout<<"0"< 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 8 | int n,t,k,cnt=0; 9 | cin>>n; 10 | t=n; 11 | while(t!=0) 12 | { 13 | k=t%10; 14 | t=t/10; 15 | cnt++; 16 | } 17 | if(cnt==1)cout< 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int a,b,add,mi,mul; 8 | cin>>a>>b; 9 | add=a+b; 10 | mi=a-b; 11 | mul=a*b; 12 | if(add>mi) 13 | { 14 | if(add>mul) 15 | { 16 | cout<mul) 23 | { 24 | cout< 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 8 | long long int n,ans=0,l=1; 9 | cin>>n; 10 | vector s(n); 11 | for(int i=0;i>s[i]; 14 | sort(s[i].begin(),s[i].end()); 15 | } 16 | sort(s.begin(),s.end()); 17 | string check=s[0]; 18 | for(int i=1;i 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 8 | int k,x; 9 | cin>>k>>x; 10 | for(int i=x-k+1;i<=x+k-1;i++) 11 | { 12 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int n,d; 6 | float x,m,a; 7 | cin>>n; 8 | vector v; 9 | for(int i=0;i>a; 12 | v.push_back(a); 13 | } 14 | sort(v.begin(),v.end()); 15 | x=(v[0]+v[1])/2; 16 | m=x; 17 | for(int i=2;i 2 | using namespace std; 3 | int main() 4 | { 5 | int a; 6 | string s; 7 | cin>>a; 8 | cin>>s; 9 | if(a>=3200) 10 | { 11 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int n; 6 | cin>>n; 7 | float a[n]; 8 | float ac=0; 9 | for(int i=0;i>a[i]; 12 | } 13 | for(int i=0;i 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int n,a,maxm=0,cnt=0; 8 | cin>>n; 9 | vector v; 10 | for(int i=0;i>a; 13 | v.push_back(a); 14 | } 15 | 16 | for(int i=0;i=v[i+1]) cnt++; 19 | else cnt=0; 20 | if(cnt>maxm) 21 | { 22 | maxm=cnt; 23 | } 24 | } 25 | cout< 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int a,b,cnt=0,sum=1; 8 | cin>>a>>b; 9 | while(1) 10 | { 11 | if(sum>=b)break; 12 | sum--; 13 | cnt++; 14 | sum+=a; 15 | } 16 | cout< 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | string s,t; 8 | int cnt=0; 9 | cin>>s>>t; 10 | for(int i=0;i<3;i++) 11 | { 12 | if(s[i]==t[i]) 13 | { 14 | cnt++; 15 | } 16 | } 17 | cout< 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int n,a,sum=0,temp=0; 8 | cin>>n; 9 | int v[n]={0},b[n],c[n]; 10 | for(int i=1;i<=n;i++) 11 | { 12 | cin>>v[i]; 13 | } 14 | for(int i=1;i<=n;i++) 15 | { 16 | cin>>b[i]; 17 | } 18 | for(int i=1;i<=n-1;i++) 19 | { 20 | cin>>c[i]; 21 | } 22 | for(int i=1;i<=n;i++) 23 | { 24 | temp=v[i]; 25 | sum=sum+b[temp]; 26 | if(v[i]==v[i-1]+1 && i!=1) 27 | { 28 | sum=sum+c[temp-1]; 29 | } 30 | 31 | } 32 | cout< 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int n; 8 | cin>>n; 9 | cout< 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | string s; 8 | int i=0,flag=1; 9 | cin>>s; 10 | while(s[i]!='\0') 11 | { 12 | if(i%2==0) 13 | { 14 | if(s[i]=='R' ||s[i]=='U'||s[i]=='D') 15 | { 16 | flag=1; 17 | } 18 | else {flag=0;cout<<"No"< 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | string s; 8 | cin>>s; 9 | while(1) 10 | { 11 | if(s=="Sunny") {cout<<"Cloudy"; break;} 12 | else if(s=="Cloudy") {cout<<"Rainy"< 2 | #define int long long 3 | using namespace std; 4 | vector v; 5 | int gcd(int a,int b) 6 | { 7 | if(a2)cnt++; 23 | return cnt; 24 | 25 | } 26 | main() 27 | { 28 | int a,b; 29 | vector v; 30 | cin>>a>>b; 31 | cout< 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int n,a; 8 | cin>>n; 9 | int ar[100000]; 10 | for(int i=1;i<=n;i++) 11 | { 12 | cin>>a; 13 | ar[a]=i; 14 | } 15 | for(int i=1;i<=n;i++) 16 | { 17 | cout< 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | double n; 8 | vector v; 9 | cin>>n; 10 | for(int i=1;i<=n;i++) 11 | { 12 | if(i%2!=0)v.push_back(i); 13 | } 14 | double s=v.size(); 15 | double ans=s/n; 16 | cout< 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int n,k,a,cnt=0; 8 | cin>>n>>k; 9 | 10 | for(int i=0;i>a; 13 | if(a>=k)cnt++; 14 | 15 | } 16 | cout< 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int a,b; 8 | cin>>a>>b; 9 | int ans=a-2*b; 10 | if(ans<=0)cout<<0<0)cout< 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int n,i=0,cnt=0; 8 | string s; 9 | cin>>n>>s; 10 | 11 | while(s[i]!='\0') 12 | { 13 | if(s[i]!=s[i+1])cnt++; 14 | i++; 15 | } 16 | cout< 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int n,a,ans=1,sum=0; 8 | cin>>n; 9 | vectorv; 10 | for(int i=0;i>a; 13 | v.push_back(a); 14 | } 15 | 16 | for(int i=0;i 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int n,a,cnt=0; 8 | cin>>n; 9 | vectorv; 10 | for(int i=0;i>a; 13 | v.push_back(a); 14 | } 15 | sort(v.begin(),v.end(),greater()); 16 | for(int i=0;i 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int n,flag=1; 7 | vectorv; 8 | cin>>n; 9 | for (int i=1;i<=9;i++) if (n%i==0){v.push_back(i);} 10 | int s=v.size(); 11 | for(int i=0;i 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | #define int long long int 7 | int n,flag=1,t1,t2,minm=INT_MAX,t=0,p=0; 8 | vectorv; 9 | cin>>n; 10 | 11 | 12 | for (int i=1; i<=sqrt(n); i++) 13 | { 14 | if (n%i == 0) 15 | { 16 | if (n/i == i) v.push_back(i); 17 | else {v.push_back(i);v.push_back(n/i);} 18 | } 19 | } 20 | 21 | int s=v.size(); 22 | for(int i=0;i 2 | using namespace std; 3 | main() 4 | { 5 | int n,x,t; 6 | cin>>n>>x>>t; 7 | int ans=(n/x)+(n%x!=0); 8 | cout< 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | float h,w,n; 8 | cin>>h>>w>>n; 9 | if(h>w)cout< 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 6 | #define int long long int 7 | int a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51}; 8 | int k; 9 | cin>>k; 10 | cout< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 7 | #define int long long int 8 | string s; 9 | int c=0,flag=0; 10 | cin>>s; 11 | if(s.size()%2!=0){cout<<"No"< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 7 | #define int long long int 8 | int a,b,m,ans=INT_MAX; 9 | cin>>a>>b>>m; 10 | int p[a],q[b]; 11 | int x,y,c; 12 | for(int i=0;i>p[i]; 13 | for(int i=0;i>q[i]; 14 | for(int i=0;i>x>>y>>c; 17 | ans=min(p[x-1]+q[y-1]-c,ans); 18 | } 19 | int ans1=INT_MAX; 20 | 21 | sort(p,p+a); 22 | sort(q,q+b); 23 | 24 | cout< 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int a,b; 8 | cin>>a>>b; 9 | if(a==b)cout<<"Yes"< 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int a,b; 8 | cin>>a>>b; 9 | if(a>b) 10 | { 11 | for(int i=0;i 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 6 | #define int long long int 7 | int h,a,cnt=0; 8 | cin>>h>>a; 9 | while(1) 10 | { 11 | h-=a; 12 | cnt++; 13 | if(h<=0)break; 14 | } 15 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 6 | #define int long long int 7 | int h,n,cnt=0,a; 8 | cin>>h>>n; 9 | for(int i=0;i>a; 12 | cnt+=a; 13 | } 14 | if(cnt>=h)cout<<"Yes"< 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 6 | #define int long long int 7 | int n,k,a,cnt=0,p=0; 8 | vectorv; 9 | cin>>n>>k; 10 | for(int i=0;i>a;v.push_back(a); 13 | } 14 | if(k>=n){cout<<0<()); 18 | if(k>=1)p+=k; 19 | else p=0; 20 | for(int i=p;i 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 6 | #define int long long int 7 | int h,cnt=1,i=1; 8 | cin>>h; 9 | while(h!=1) 10 | { 11 | h=h/2; 12 | cnt+=i*2; 13 | i=i*2; 14 | } 15 | //cout< 2 | using namespace std; 3 | main() 4 | { 5 | int h,w,k; 6 | cin>>h>>w>>k; 7 | char v[h+1][w+1]; 8 | int ans=0; 9 | for(int i=0;i>v[i][j];} 10 | 11 | for(int i=0;i<(1< 2 | using namespace std; 3 | 4 | #define io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 5 | 6 | int ans(int n) 7 | { 8 | if(n==1 || n==2)return 0; 9 | return (ans(n-1)+((n-1)*(n-2)*((2*n)-1))-(n-1)*(n-2)); 10 | } 11 | 12 | int main() 13 | { 14 | 15 | int n; 16 | cin>>n; 17 | cout< 2 | using namespace std; 3 | 4 | #define io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 5 | #define int long long int 6 | 7 | int main() 8 | { 9 | int n; 10 | cin>>n; 11 | int a[n+1]; 12 | for(int i=0;i>a[i]; 13 | int ans=0,m=INT_MIN; 14 | for(int i=0;i 3 | using namespace std; 4 | vectorsubset; 5 | int sear(int a[],int k,int n) 6 | { 7 | if (k == n+1) 8 | { 9 | for(int i=0;i>n; 26 | int a[n+1]; 27 | for(int i=1;i<=n;i++)cin>>a[i]; 28 | sear(a,1,n); 29 | } 30 | -------------------------------------------------------------------------------- /CSES Problem Set/Introductory Problems/Bit Strings.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #define io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 5 | #define int long long int 6 | int mod=1e9+7; 7 | 8 | int power(int x, unsigned int y, int p) 9 | { 10 | int res = 1; 11 | x = x % p; 12 | if (x == 0) return 0; 13 | while (y > 0) 14 | { 15 | if (y & 1) res = (res*x) % p; 16 | y = y>>1; 17 | x = (x*x) % p; 18 | } 19 | return res; 20 | } 21 | 22 | int32_t main() 23 | { 24 | io 25 | //freopen 26 | int n; 27 | cin>>n; 28 | cout< 2 | 3 | #define int long long int 4 | 5 | int left[100],rit[100],col[100],ans=0; 6 | char a[10][10]; 7 | 8 | int ways(int x,int res[][100]) 9 | { 10 | if(x==9){ans++;} 11 | for(int y=1;y<=8;y++) 12 | { 13 | if(res[x][y])continue; 14 | if(col[y] || left[x+y] || rit[y-x+8])continue; 15 | col[y]=left[x+y]=rit[y-x+8]=1; 16 | ways(x+1,res); 17 | col[y]=left[x+y]=rit[y-x+8]=0; 18 | } 19 | return ans; 20 | } 21 | 22 | int32_t main() 23 | { 24 | int res[100][100]={0}; 25 | for(int i=1;i<=8;i++) 26 | { 27 | for(int j=1;j<=8;j++) 28 | { 29 | std::cin>>a[i][j]; 30 | if(a[i][j]=='*'){res[i][j]=1;} 31 | } 32 | } 33 | std::cout< 2 | using namespace std; 3 | 4 | #define io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 5 | #define int long long int 6 | 7 | int32_t main() 8 | { 9 | io 10 | int t; 11 | cin>>t; 12 | while(t--) 13 | { 14 | int a,b; 15 | cin>>a>>b; 16 | if((2*a-b>=0) && (2*b-a>=0) && ((2*a-b)%3==0) && ((2*b-a)%3==0))cout<<"YES"< 2 | using namespace std; 3 | 4 | #define io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 5 | #define int long long int 6 | 7 | int32_t main() 8 | { 9 | io 10 | string s; 11 | int c=0; 12 | cin>>s; 13 | sort(s.begin(),s.end()); 14 | do 15 | { 16 | c++; 17 | }while(next_permutation(s.begin(),s.end())); 18 | cout< 2 | using namespace std; 3 | #define io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 4 | #define int long long int 5 | int32_t main() 6 | { 7 | io 8 | //freopen 9 | int n; 10 | cin>>n; 11 | int a[n+1]; 12 | for(int i=0;i>a[i]; 13 | int ans=0; 14 | for(int i=0;ia[i+1]) 17 | { 18 | ans+=a[i]-a[i+1]; 19 | a[i+1]=a[i]; 20 | } 21 | } 22 | cout< 2 | using namespace std; 3 | 4 | #define io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 5 | #define int long long int 6 | 7 | int32_t main() 8 | { 9 | io 10 | //freopen 11 | int n; 12 | cin>>n; 13 | vectorv; 14 | int a; 15 | for(int i=0;i>a;v.push_back(a);} 16 | sort(v.begin(),v.end()); 17 | a=1; 18 | 19 | for(int i=0;i 2 | using namespace std; 3 | 4 | #define io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 5 | #define int long long int 6 | 7 | int32_t main() 8 | { 9 | io 10 | //freopen 11 | int n; 12 | cin>>n; 13 | if(n==1)cout<<1< 2 | using namespace std; 3 | 4 | #define io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 5 | #define int long long int 6 | 7 | int32_t main() 8 | { 9 | io 10 | //freopen 11 | string s; 12 | cin>>s; 13 | int m=INT_MIN,ans=1; 14 | for(int i=0;i 2 | using namespace std; 3 | 4 | #define io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 5 | #define int long long int 6 | 7 | int32_t main() 8 | { 9 | io 10 | int n,ans=0; 11 | cin>>n; 12 | for(int i=5;i<=n;i*=5) 13 | { 14 | if(n/i>0)ans+=n/i; 15 | else break; 16 | } 17 | cout< 2 | using namespace std; 3 | #define io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 4 | #define int long long int 5 | int32_t main() 6 | { 7 | int n; 8 | cin>>n; 9 | for(int i=1;i<=n;i++) 10 | { 11 | int ans=(i*i)*((i*i)-1)-(4*2)-24-((i-4)*4*4)-16-(24*(i-4))-(8*(i-4)*(i-4)); 12 | cout< 2 | using namespace std; 3 | 4 | #define io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 5 | 6 | int32_t main() 7 | { 8 | long long int n; 9 | cin>>n; 10 | cout< 2 | using namespace std; 3 | bool sortbysec(const pair &a,const pair &b) 4 | { 5 | return (a.second>n; 13 | vector< pair > v; 14 | for(int i=0;i>a>>b; 17 | v.push_back(make_pair(a,b)); 18 | } 19 | sort(v.begin(),v.end(),sortbysec); 20 | 21 | for(int i=1;i=v[k].second) 24 | { 25 | cnt++; 26 | k=i; 27 | } 28 | } 29 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 6 | int n,a,cnt=1; 7 | cin>>n; 8 | vector v; 9 | for(int i=0;i>a; 12 | v.push_back(a); 13 | } 14 | sort(v.begin(),v.end()); 15 | for(int i=0;i 2 | using namespace std; 3 | 4 | #define io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 5 | #define int long long int 6 | #define endl "\n" 7 | 8 | main() 9 | { 10 | int n,x,ans=0; 11 | cin>>n>>x; 12 | int a[n+1]; 13 | for(int i=0;i>a[i];} 14 | sort(a,a+n,greater()); 15 | int i=0,j=n-1; 16 | while(i<=j) 17 | { 18 | if(a[i]+a[j]<=x && i!=j) 19 | { 20 | i++;j--; 21 | ans++; 22 | } 23 | else if(a[i]+a[j]>x && i!=j) 24 | { 25 | ans++; 26 | i++; 27 | } 28 | else if(i==j){ans++;break;} 29 | } 30 | cout< 2 | using namespace std; 3 | 4 | #define int long long int 5 | 6 | main() 7 | { 8 | int n; 9 | cin>>n; 10 | int a[n+1]; 11 | for(int i=0;i>a[i]; 12 | int ans=INT_MIN,sum=0; 13 | for(int i=0;i 2 | using namespace std; 3 | 4 | bool comp(pair&a,pair&b) 5 | { 6 | return a.second>n; 13 | vector>v; 14 | for(int i=0;i>a>>b; 17 | v.push_back({a,b}); 18 | } 19 | 20 | sort(v.begin(),v.end(),comp); 21 | int ans=1; 22 | for(int i=1;i=v[upd].second) 25 | { 26 | ans++; 27 | upd=i; 28 | } 29 | } 30 | cout< 2 | using namespace std; 3 | 4 | main() 5 | { 6 | int n,a,b,c=0,mi=INT_MAX,ma=INT_MIN; 7 | unordered_mappl; 8 | unordered_mapml; 9 | cin>>n; 10 | vectorr; 11 | for(int i=0;i>a>>b; 14 | mi=min(mi,a); 15 | ma=max(ma,b); 16 | pl[a]=1; 17 | ml[b]=1; 18 | r.push_back(a); 19 | r.push_back(b); 20 | } 21 | sort(r.begin(),r.end()); 22 | int ans=INT_MIN,sum=0; 23 | 24 | for(int i=0;i 2 | using namespace std; 3 | 4 | #define int long long int 5 | main() 6 | { 7 | int n; 8 | cin>>n; 9 | int a[n+1]; 10 | for(int i=0;i>a[i]; 11 | int sum=0; 12 | sort(a,a+n); 13 | for(int i=0;i 2 | using namespace std; 3 | 4 | main() 5 | { 6 | int n,x,b; 7 | cin>>n>>x; 8 | vector>a; 9 | for(int i=0;i>b; 12 | a.push_back({b,i}); 13 | } 14 | 15 | sort(a.begin(),a.end()); 16 | int i=0,j=n-1,in1,in2,flag=1; 17 | 18 | while(ix)j--; 21 | else if(a[i].first+a[j].first 8 | using namespace std; 9 | #define io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 10 | 11 | #define int long long int 12 | #define endl "\n" 13 | main() 14 | { 15 | io 16 | int n,a; 17 | cin>>n; 18 | multisets; 19 | for(int i=0;i>a; 22 | auto it=s.upper_bound(a); 23 | if(it==s.end())s.insert(a); 24 | else 25 | { 26 | s.erase(it); 27 | s.insert(a); 28 | } 29 | } 30 | cout< 2 | using namespace std; 3 | main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int n,k; 10 | cin>>n>>k; 11 | vectorans; 12 | for(int i=k+1;i<=n;i++)ans.push_back(i); 13 | int has[n+1]={0}; 14 | for(int i=k-1;i>=1;i--) 15 | { 16 | if(has[i]==0)ans.push_back(i); 17 | has[k-i]=1; 18 | } 19 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | #define int long long int 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | int x; 11 | cin>>x; 12 | cout<<0<<" "< 2 | using namespace std; 3 | #define int long long int 4 | main() 5 | { 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | int n; 11 | scanf("%lld",&n); 12 | int a[n+1]; 13 | int b[n+1]; 14 | int ii=0; 15 | for(int i=0;i0) 19 | { 20 | b[ii]=a[i]; 21 | ii++; 22 | } 23 | } 24 | int ans=0; 25 | for (int i = 0; i < 32; i++) 26 | { 27 | int k = 0; 28 | for (int j = 0; j < ii; j++) 29 | if ( (b[j] & (1 << i)) ) 30 | k++; 31 | if(k>=2)ans |= (1< 2 | using namespace std; 3 | #define int long long int 4 | #define endl "\n" 5 | #define pb push_back 6 | 7 | int mod=1e9+7; 8 | main() 9 | { 10 | int n; 11 | cin>>n; 12 | int a[n+1]; 13 | int sum=0; 14 | for(int i=0;i>a[i];sum+=a[i];} 15 | int q,u; 16 | cin>>q; 17 | // int flag=0; 18 | for(int i=0;i>u; 21 | sum=(((sum*2)%mod)+mod)%mod; 22 | sum=sum%mod; 23 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | #define int long long int 6 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--) 10 | { 11 | int k,v,a; 12 | int sum=0.0,avg=0,n; 13 | cin>>n>>k>>v; 14 | vectorvec; 15 | for(int i=0;i>a;vec.push_back(a);} 16 | for(int i=0;i0 )cout<<(v*(n+k)-sum)/k< 7 | using namespace std; 8 | #define int long long int 9 | #define endl "\n" 10 | main() 11 | { 12 | int t; 13 | cin>>t; 14 | while(t--) 15 | { 16 | int n,k,l; 17 | cin>>n>>k>>l; 18 | int ans=(n/k); 19 | if(n%k!=0)ans++; 20 | 21 | if(k==1 && n>k && l>=ans){cout<<-1<=ans) 23 | { 24 | for(int i=1;i<=n;i++) 25 | { 26 | if(i%k!=0)cout< 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | #define int long long int 8 | ios::sync_with_stdio();cin.tie();cout.tie(); 9 | int t; 10 | cin>>t; 11 | while(t--) 12 | { 13 | int s,g,b,c,cnt=0; 14 | int a[10]; 15 | cin>>s>>g>>b>>c; 16 | a[0]=g; 17 | a[1]=b; 18 | a[2]=c; 19 | //sort(a,a+3,greater()); 20 | 21 | if(a[0]+a[1]+a[2]<=s)cnt++; 22 | else if(a[0]+a[1]<=s)cnt+=2; 23 | else if(a[0]<=s) 24 | { 25 | if(a[1]+a[2]<=s)cnt+=2; 26 | else if(a[1]<=s)cnt+=3; 27 | } 28 | 29 | 30 | cout< 2 | using namespace std; 3 | main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int n,b,m; 10 | cin>>n>>b>>m; 11 | int a[m+1]; 12 | for(int i=0;i>a[i]; 15 | a[i]++; 16 | } 17 | int upd; 18 | upd=a[0]/b; 19 | if(a[0]%b==0)upd--; 20 | int ans=1; 21 | for(int i=1;i 2 | using namespace std; 3 | #define int long long int 4 | #define endl "\n" 5 | #define pb push_back 6 | main() 7 | { 8 | int t; 9 | cin>>t; 10 | while(t--) 11 | { 12 | int n; 13 | cin>>n; 14 | string s; 15 | cin>>s; 16 | 17 | int good=0,bad=0; 18 | int flag=0; 19 | 20 | for(int i=0;i=life){flag=1;break;} 32 | } 33 | 34 | if(flag==1)cout<<"YES"< 2 | using namespace std; 3 | #define int long long int 4 | #define endl "\n" 5 | main() 6 | { 7 | int t; 8 | cin>>t; 9 | while(t--) 10 | { 11 | int n; 12 | cin>>n; 13 | int a[n+1]; 14 | int andi,cnt=0; 15 | for(int i=0;i>a[i]; 18 | } 19 | for(int i=0;i 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 7 | int t,cnt=0; 8 | cin>>t; 9 | while(t--) 10 | { 11 | cnt=0; 12 | string s; 13 | cin>>s; 14 | 15 | for(int i=0;i 2 | using namespace std; 3 | main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int n,x,y; 10 | cin>>n>>x>>y; 11 | int ans=x+y; 12 | if(ans%2==0)cout<<0< 2 | using namespace std; 3 | main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int n,k; 10 | cin>>n>>k; 11 | int a[n+1]; 12 | int ok=0; 13 | for(int i=0;i>a[i];if(a[i]>k)ok=1;} 14 | if(ok) 15 | { 16 | cout<<-1<k) 24 | { 25 | sum++; 26 | ans=a[i]; 27 | } 28 | } 29 | cout< 2 | using namespace std; 3 | main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int n,k,a; 10 | cin>>n>>k; 11 | for(int i=0;i>a; 14 | if(a%k==0)cout<<1; 15 | else cout<<0; 16 | } 17 | cout< 2 | using namespace std; 3 | main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | string a,b; 10 | cin>>a>>b; 11 | int minans=a.size(),maxans=0; 12 | for(int i=0;i 2 | using namespace std; 3 | main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int h,p; 10 | cin>>h>>p; 11 | while(p>0) 12 | { 13 | h-=p; 14 | p/=2; 15 | } 16 | if(h>0)cout<<0< 2 | using namespace std; 3 | main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int n; 10 | cin>>n; 11 | int a[n+1],b[n+1]; 12 | bool ok=1,ok1=1; 13 | for(int i=0;i>a[i]; 14 | for(int i=0;i>b[i]; 17 | if(a[i]>b[i])ok=0; 18 | if(a[n-i-1]>b[i])ok1=0; 19 | } 20 | if(ok1 && ok){cout<<"both"< 2 | using namespace std; 3 | int main() 4 | { 5 | #define int long long int 6 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--) 10 | { 11 | int na,a; 12 | cin>>na; 13 | vectorj; 14 | for(int i=0;i>a;j.push_back(a); 17 | } 18 | sort(j.begin(),j.end()); 19 | cout< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 7 | #define int long long int 8 | int n; 9 | cout<<1<>n; 12 | if(n==2)cout<<3< 2 | using namespace std; 3 | int main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int s,n; 10 | cin>>s>>n; 11 | if(s==1){cout<<1< 2 | using namespace std; 3 | signed main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int m,x; 10 | cin>>m>>x; 11 | m--; 12 | int winner[x+1]; 13 | winner[1]=0; 14 | int start=0; 15 | cout<<1<<" "; 16 | for(int i=2;i<=x;i++) 17 | { 18 | start=0; 19 | int cut=m%i; 20 | if(start==cut)start++; 21 | if(cut>start && cut<=(start+winner[i-1]))winner[i]=start+winner[i-1]+1; 22 | else winner[i]=start+winner[i-1]; 23 | cout< 2 | using namespace std; 3 | typedef tree, rb_tree_tag,tree_order_statistics_node_update> ordered_set; 4 | main() 5 | { 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | int n,ok=1,v; 11 | cin>>n; 12 | seta; 13 | ordered_set s; 14 | for(int i=0;i>v; 17 | a.insert(v); 18 | s.insert(v); 19 | } 20 | int q,x,y,cnt=0; 21 | cin>>q; 22 | int sl; 23 | for(int i=0;i>x>>y; 26 | if(x==0 && y==0){cout<<0< 2 | using namespace std; 3 | #define int long long int 4 | #define pb push_back 5 | 6 | int solve(int n,unordered_map&dp) 7 | { 8 | if(n==0)return 0; 9 | if(dp.count(n)){return dp[n];} 10 | return dp[n]=max(solve(n/2,dp)+solve(n/3,dp)+solve(n/4,dp),n); 11 | } 12 | main() 13 | { 14 | int n; 15 | while(cin>>n) 16 | { 17 | unordered_mapdp; 18 | int ans=solve(n,dp); 19 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int n,ok=1; 10 | cin>>n; 11 | int a[n+1]; 12 | for(int i=0;i>a[i]; 15 | if(a[i]%2==0)ok=0; 16 | } 17 | if(ok==0){cout<<"NO"< 2 | using namespace std; 3 | main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int r,a,b,c,d,e,f,ans1,ans2,ans3,ans=0; 10 | cin>>r>>a>>b>>c>>d>>e>>f; 11 | r*=r; 12 | ans1=((a-c)*(a-c))+((b-d)*(b-d)); 13 | ans2=((e-c)*(e-c))+((f-d)*(f-d)); 14 | ans3=((a-e)*(a-e))+((b-f)*(b-f)); 15 | if(ans1<=r)ans++; 16 | if(ans2<=r)ans++; 17 | if(ans3<=r)ans++; 18 | if(ans>=2)cout<<"yes"< 2 | using namespace std; 3 | #define int long long int 4 | main() 5 | { 6 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--) 10 | { 11 | int n,k,total=0; 12 | cin>>n>>k; 13 | int a[n+1]; 14 | for(int i=1;i<=n;i++){cin>>a[i];total+=a[i];} 15 | int mini=INT_MAX,sum=0; 16 | for(int i=1;i<=k;i++)sum+=a[i]; 17 | mini=sum; 18 | 19 | for(int i=2;i<=(n-k+1);i++) 20 | { 21 | sum-=a[i-1]; //sliding window 22 | sum+=a[i+k-1]; //sliding window 23 | mini=min(mini,sum); 24 | } 25 | int ans=0; 26 | ans=mini*(mini+1)/2; 27 | ans+=total-mini; 28 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 6 | #define int long long int 7 | #define pb push_back 8 | #define mk make_pair 9 | int t; 10 | cin>>t; 11 | while(t--) 12 | { 13 | 14 | 15 | int a,b,c,d; 16 | cin>>a>>b>>c>>d; 17 | 18 | cout< 3 | using namespace std; 4 | #define int long long int 5 | #define endl "\n" 6 | const int MOD=1e9+7; 7 | const int add=5e5; 8 | const int N=1e6+10; 9 | int d[N]; 10 | int32_t main() 11 | { 12 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 13 | int n,a,b; 14 | cin>>n; 15 | for(int i=0;i>a>>b; 18 | d[a+add]++; 19 | d[b+1+add]--; 20 | } 21 | int ans=0; 22 | for(int i=1;i 3 | using namespace std; 4 | int d1[1000009]={0},d2[1000009]={0}; 5 | int main() 6 | { 7 | int n; 8 | cin>>n; 9 | int q; 10 | cin>>q; 11 | while(q--) 12 | { 13 | int l,r; 14 | cin>>l>>r; 15 | //adding 1-L 16 | d1[l]+=(1-l); 17 | d1[r+1]-=(1-l); 18 | 19 | //adding i smartly by marking 1 20 | d2[l]++; 21 | d2[r+1]--; 22 | } 23 | for(int i=2;i<=n;i++) 24 | { 25 | d1[i]+=d1[i-1]; 26 | d2[i]+=d2[i-1]; 27 | } 28 | for(int i=1;i<=n;i++) 29 | { 30 | if(d2[i]>0)d1[i]+=d2[i]*i; 31 | } 32 | int m; 33 | cin>>m; 34 | while(m--) 35 | { 36 | int a; 37 | cin>>a; 38 | cout< 2 | using namespace std; 3 | main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int a,b; 10 | cin>>a>>b; 11 | int a1=(a/9)+(a%9!=0); 12 | int b1=(b/9)+(b%9!=0); 13 | if(a1 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int t,n; 8 | cin>>t; 9 | while(t--) 10 | { 11 | cin>>n; 12 | char s[n]; 13 | cin>>s; 14 | char vowel[]={'a','e','i','o','u'}; 15 | long count=0; 16 | for(int i=0; i 2 | using namespace std; 3 | main() 4 | { 5 | int t,sum=0; 6 | cin>>t; 7 | while(t--) 8 | { 9 | string s; 10 | cin>>s; 11 | int c1=0,c2=0; 12 | 13 | for(int i=0;i=97 && (int)s[i]<=122)c1++; 16 | else if(((int)s[i]>=65 && (int)s[i]<=90))c2++; 17 | } 18 | 19 | sum+=abs(c1-c2); 20 | 21 | } 22 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio();cin.tie();cout.tie(); 6 | #define int long long int 7 | int t; 8 | cin>>t; 9 | while(t--) 10 | { 11 | int n,k,a,temp=0,flag=1,t2=0; 12 | cin>>n>>k; 13 | vectorv; 14 | for(int i=0;i>a; 17 | v.push_back(a); 18 | } 19 | 20 | for(int i=0;i=k){temp=v[i]-k; v[i+1]+=temp;} 24 | } 25 | if(flag==0){cout<<"NO"<<" "< 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 6 | #define int long long int 7 | #define pb push_back 8 | #define mk make_pair 9 | #define endl "\n" 10 | int t; 11 | cin>>t; 12 | while(t--) 13 | { 14 | int n,a,c=0,flag=1; 15 | cin>>n; 16 | for(int i=5;i<=n;i*=5) 17 | { 18 | c+=n/i; 19 | } 20 | 21 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 6 | #define int long long int 7 | #define pb push_back 8 | #define mk make_pair 9 | int t; 10 | cin>>t; 11 | while(t--) 12 | { 13 | int n; 14 | cin>>n; 15 | string s=to_string(n); 16 | int i=0; 17 | reverse(s.begin(),s.end()); 18 | while(s[i]=='0'){s[i]=' ';i++;} 19 | for(int i=0;i 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 6 | #define int long long int 7 | #define pb push_back 8 | #define mk make_pair 9 | int t; 10 | while(1) 11 | { 12 | cin>>t; 13 | if(t!=42)cout< 3 | using namespace std; 4 | #define io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 5 | main() 6 | { 7 | io 8 | int t; 9 | cin>>t; 10 | while(t--) 11 | { 12 | int n,s,p,v; 13 | cin>>n; 14 | int ans=INT_MIN; 15 | for(int i=0;i>s>>p>>v; 18 | ans=max(ans,(p/(s+1))*v); 19 | } 20 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 6 | #define int long long int 7 | #define pb push_back 8 | #define mk make_pair 9 | int t; 10 | cin>>t; 11 | int r=t; 12 | vectorv; 13 | while(t--) 14 | { 15 | int n; 16 | cin>>n; 17 | v.pb(n); 18 | } 19 | sort(v.begin(),v.end()); 20 | int m=INT_MIN; 21 | for(int i=0;i 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int t; 8 | cin>>t; 9 | while(t--) 10 | { 11 | long long int n,k,y; 12 | cin>>n>>k; 13 | y=n/k; 14 | for(int i=0;i 2 | using namespace std; 3 | main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int n; 10 | cin>>n; 11 | string s; 12 | cin>>s; 13 | mapmp; 14 | for(int i=0;i 2 | using namespace std; 3 | #define ll long long int 4 | ll div(ll x) 5 | { 6 | ll cnt=0; 7 | for(ll i=1;i<=sqrt(x);i++) 8 | { 9 | if(x%i==0) 10 | { 11 | if(x/i==i){cnt++;} 12 | else {cnt+=2;} 13 | } 14 | 15 | } 16 | return cnt; 17 | } 18 | 19 | int main() 20 | { 21 | ll t; 22 | cin>>t; 23 | while(t--) 24 | { 25 | ll a,b; 26 | cin>>a>>b; 27 | cout< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 7 | #define int long long int 8 | int t; 9 | cin>>t; 10 | while(t--) 11 | { 12 | int n,ans; 13 | cin>>n; 14 | vector v; 15 | int a; 16 | for(int i=0;i>a; 19 | v.push_back(a); 20 | } 21 | sort(v.begin(),v.end()); 22 | ans=v[0]; 23 | for(int i=1;i 2 | using namespace std; 3 | #define int long long int 4 | main() 5 | { 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | int n,grader,origsum; 11 | cin>>n; 12 | int ans=0,k=(1<<20); 13 | cout<<"1 "<>grader; 15 | origsum=grader-n*k; 16 | 17 | if(origsum%2==1)ans=1; 18 | 19 | for(int i=1;i<=19;i++) 20 | { 21 | cout<<"1 "<<(1<>grader; 23 | 24 | int num=origsum-grader+(n*(1<>grader; 31 | if(grader==-1)return 0; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Codechef Problems/FLOW004.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 9 | int r; 10 | cin>>r; 11 | while(r--) 12 | { 13 | vector v; 14 | int n; 15 | cin>>n; 16 | int t=n; 17 | 18 | while (t!=0) 19 | { 20 | int y=t%10; 21 | t=t/10; 22 | v.push_back(y); 23 | } 24 | int k=v.size(); 25 | int h=v[0]+v[1]; 26 | cout< 3 | using namespace std; 4 | main() 5 | { 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | int a,b,c; 11 | cin>>a>>b>>c; 12 | if((a+b+c)==180)cout<<"YES"< 2 | using namespace std; 3 | #define int long long int 4 | #define endl "\n" 5 | main() 6 | { 7 | int t; 8 | cin>>t; 9 | while(t--) 10 | { 11 | int n; 12 | cin>>n; 13 | int a[n+1]; 14 | int ans=0,ok=1; 15 | for(int i=1;i<=n;i++) 16 | { 17 | cin>>a[i]; 18 | if(a[i]>i)ok=0; 19 | if(i%a[i]!=0)ok=0; 20 | } 21 | if(ok==0){cout<<"NO"< 2 | using namespace std; 3 | signed main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int n; 10 | cin>>n; 11 | for(int i=0;i 2 | using namespace std; 3 | #define int long long int 4 | main() 5 | { 6 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 7 | int t; 8 | cin>>t; 9 | vectorps; 10 | for(int i=1;i*i<=1000000;i++) 11 | { 12 | ps.push_back(i*i); 13 | } 14 | 15 | while(t--) 16 | { 17 | int i=0,ans,flag=0; 18 | while(1) 19 | { 20 | cout<>ans; 22 | fflush(stdout); 23 | 24 | if(ans==0) 25 | { 26 | i++; 27 | } 28 | else if(ans==-1){flag=1;break;} 29 | else if(ans==1){flag=-1;break;} 30 | } 31 | fflush(stdout); 32 | if(flag==1)break; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /Codechef Problems/HS08TEST.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | main() 4 | { 5 | float b; 6 | int a; 7 | cin>>a>>b; 8 | if(a%5==0 && (a+0.5)<=(b) && a>=5) 9 | { 10 | float ans=b-a-0.5; 11 | //if(ans<0.0)ans=0.00; 12 | cout< 2 | using namespace std; 3 | main() 4 | { 5 | int n,k,a,cnt=0; 6 | cin>>n>>k; 7 | for(int i=0;i>a; 10 | if(a%k==0)cnt++; 11 | } 12 | cout< 2 | using namespace std; 3 | #define int long long int 4 | #define endl "\n" 5 | #define int long long int 6 | main() 7 | { 8 | int n,m,k,a,q,ans=0; 9 | cin>>n>>m>>k; 10 | int cnt=0; 11 | for(int i=0;i>a; 17 | cnt+=a; 18 | } 19 | cin>>q; 20 | if(q<=10 && cnt>=m)ans++; 21 | } 22 | cout< 2 | using namespace std; 3 | 4 | int main() { 5 | int n,x,sum=0,sum1=0; 6 | vector v; 7 | cin>>n; 8 | for(int i=0;i>x; 11 | v.push_back(x); 12 | } 13 | int i=0,j=n; 14 | 15 | while(1) 16 | { 17 | sum=sum+v[i]; 18 | j--; 19 | if(i==j) break; 20 | sum1=sum1+v[j]; 21 | i++; 22 | if(i==j)break; 23 | } 24 | cout< 2 | using namespace std; 3 | main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int n,ans=0; 10 | cin>>n; 11 | int a[n+1],b[n+1]; 12 | vectorc; 13 | for(int i=0;i>a[i]; 16 | if(i>=1)c.pb(a[i]-a[i-1]); 17 | } 18 | for(int i=0;i>b[i]; 21 | if(i>=1)if(b[i]<=c[i-1])ans++; 22 | } 23 | if(b[0]<=a[0])ans++; 24 | cout< 2 | using namespace std; 3 | main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int n,k,a; 10 | cin>>n>>k; 11 | int ans=INT_MAX,final=-1; 12 | for(int i=0;i>a; 15 | if(k%a==0) 16 | { 17 | if(ans>=(k/a)) 18 | { 19 | ans=k/a; 20 | final=a; 21 | } 22 | } 23 | } 24 | if(final>=1)cout< 2 | using namespace std; 3 | main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int a[6]; 10 | int p; 11 | for(int i=0;i<5;i++)cin>>a[i]; 12 | cin>>p; 13 | for(int i=0;i<5;i++)a[i]*=p; 14 | int sum=0,ans=0; 15 | for(int i=0;i<5;i++) 16 | { 17 | sum=24-a[i]; 18 | ans+=sum; 19 | } 20 | if(ans>=0)cout<<"No"< 3 | using namespace std; 4 | int main() 5 | { 6 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 7 | long long int fac[1000005],ans[1000005]; 8 | long long int mod=1000000007; 9 | fac[0]=1;ans[0]=1; 10 | for(int i=1;i<1000003;i++) 11 | { 12 | fac[i]=(fac[i-1]*i)%mod; 13 | ans[i]=(ans[i-1]*fac[i])%mod; 14 | } 15 | int t; 16 | cin>>t; 17 | while(t--) 18 | { 19 | int n; 20 | cin>>n; 21 | cout< 2 | using namespace std; 3 | main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int n,m,ok=0,b; 10 | cin>>n>>m; 11 | vectora; 12 | maps; 13 | for(int i=0;i>b; 16 | s[b]++; 17 | if(b==1)ok=1; 18 | } 19 | if(ok==0){cout<<-1<m){c++;ans+=(s[a[i]]);} 28 | } 29 | if(cnt==m-1)cout< 2 | using namespace std; 3 | main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int n; 10 | cin>>n; 11 | int a[n+1]; 12 | mapmp; 13 | for(int i=0;i>a[i];mp[a[i]]++;} 14 | int ans=INT_MAX; 15 | mapcp; 16 | for(auto x:mp) 17 | { 18 | cp[x.second]++; 19 | } 20 | int mx=INT_MIN; 21 | for(auto x:cp) 22 | { 23 | mx=max(mx,x.second); 24 | } 25 | for(auto x:cp) 26 | { 27 | if(x.second==mx) 28 | { 29 | ans=min(ans,x.first); 30 | } 31 | } 32 | cout< 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | long long int t,a[1000],b[1000],p; 8 | cin>>t; 9 | while(t--) 10 | { 11 | long long int n,maxm=0; 12 | cin>>n; 13 | for(int i=0;i>a[i]; 16 | a[i]=a[i]*20; 17 | } 18 | for(int i=0;i>b[i]; 22 | b[i]=b[i]*10; 23 | } 24 | for(int i=0;imaxm) 28 | { 29 | maxm=p; 30 | } 31 | } 32 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 6 | #define int long long int 7 | int t; 8 | cin>>t; 9 | while(t--) 10 | { 11 | int n,star[1002000]={0},ans=0,a; 12 | cin>>n; 13 | for(int i=1;i<=n;i++) 14 | { 15 | cin>>a; 16 | ans=max(ans,star[a]); 17 | for(int j=1;j*j<=a;j++) {if(a%j==0){star[j]++;if(j*j!=a)star[a/j]++;}} 18 | } 19 | cout< 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int t,x,y,k; 8 | cin>>t; 9 | for(int i=0;i>x; 12 | cin>>y; 13 | cin>>k; 14 | 15 | int d=(x+y)/k; 16 | 17 | if(d%2==0) 18 | { 19 | cout<<"Chef"< 2 | 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | string s,r; 9 | int n,t,cnt,cnt1; 10 | cin>>t; 11 | while(t--) 12 | { 13 | cnt1=0; 14 | cnt=0; 15 | cin>>n; 16 | cin>>s; 17 | cin>>r; 18 | 19 | for(int j=0;j 2 | using namespace std; 3 | main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int d,n; 10 | cin>>d>>n; 11 | while(d--) 12 | { 13 | n=(n)*(n+1); 14 | n/=2; 15 | } 16 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 6 | #define int long long int 7 | int q; 8 | cin>>q; 9 | while(q--) 10 | { 11 | int k,x,c=0,d=0,i=0; 12 | string s; 13 | cin>>s; 14 | cin>>k>>x; 15 | int a[123]={0}; 16 | for(int i=0;i=1){k--;continue;} 23 | else break; 24 | } 25 | 26 | } 27 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int n,a,b; 10 | cin>>n; 11 | mapx,y; 12 | for(int i=0;i<((4*n)-1);i++) 13 | { 14 | cin>>a>>b; 15 | x[a]++; 16 | y[b]++; 17 | } 18 | int x1,y1; 19 | for(auto i:x)if(i.second%2!=0){x1=i.first;break;} 20 | for(auto i:y)if(i.second%2!=0){y1=i.first;break;} 21 | cout< 3 | using namespace std; 4 | int main() 5 | { 6 | long long int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | long long int right=1000000000,flag=1; 11 | string s; 12 | cin>>s; 13 | int n=s.size(); 14 | for(int i=n-1;i>=0;i--) 15 | { 16 | if(s[i]!='.') 17 | { 18 | if(i+(s[i]-'0')n)right=n; 22 | } 23 | } 24 | if(flag==0)cout<<"unsafe"< 2 | using namespace std; 3 | int main() 4 | { 5 | #define int long long int 6 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--) 10 | { 11 | int n,a,cnt=1,flag=1,c=0; 12 | cin>>n; 13 | vector v; 14 | for(int i=0;i>a; v.push_back(a);} 15 | 16 | for(int i=1;i=v[j]){flag=0;break;} 22 | } 23 | if(flag==1)cnt++; 24 | } 25 | cout< 2 | using namespace std; 3 | #define io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 4 | int main() 5 | { 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | int n,k,m,s=0; 11 | cin>>n>>k; 12 | int a[n+1]; 13 | for(int i=0;i>a[i];s+=a[i];} 14 | if(s%k==0) 15 | { 16 | cout<<0<<"\n"; 17 | continue; 18 | } 19 | cout<<1<<"\n"; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Codechef Problems/SNUG_FIT.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 6 | #define int long long int 7 | int t; 8 | cin>>t; 9 | while(t--) 10 | { 11 | int n,sum=0; 12 | cin>>n; 13 | int a[n+20],b[n+20]; 14 | for(int i=0;i>a[i]; 15 | for(int i=0;i>b[i]; 16 | sort(a,a+n); sort(b,b+n); 17 | for(int i=0;i 2 | using namespace std; 3 | int main() 4 | { 5 | #define int long long int 6 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--) 10 | { 11 | int n,a,b,c,te,itr,ans=0,an=1000000009,ind; 12 | cin>>n; 13 | int s[n],p[n],v[n+10000]; 14 | for(int i=0;i>s[i]>>p[i]>>v[i]; 17 | s[i]++; 18 | } 19 | 20 | for(int i=0;i 2 | using namespace std; 3 | signed main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int n,a; 10 | cin>>n>>a; 11 | 12 | if((1&a)==1) 13 | { 14 | if(n%2==0)cout<<"Even"< 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 6 | #define int long long int 7 | int q; 8 | cin>>q; 9 | while(q--) 10 | { 11 | int a,b,a1,a2,b1,b2,mx=INT_MIN; 12 | cin>>a>>b; 13 | a1=a%10; 14 | a2=a/10; 15 | b1=b%10; 16 | b2=b/10; 17 | mx=max(mx,(a2+b2)*10 + a1+b1); 18 | if(b2)mx=max(mx,(a1+a2)*10+b1+b2); 19 | if(a2)mx=max(mx,(b1+b2)*10+a1+a2); 20 | if(a2 && b2){mx=max(mx,(a1+a2)*10+b1+b2);mx=max(mx,(b1+b2)*10+a1+a2);} 21 | cout< 2 | using namespace std; 3 | #define int long long int 4 | #define endl "\n" 5 | main() 6 | { 7 | = int t; 8 | cin>>t; 9 | while(t--) 10 | { 11 | int a,b,c,d,k; 12 | cin>>a>>b>>c>>d>>k; 13 | int h=abs(a-c)+abs(b-d); 14 | 15 | if(h>k){cout<<"NO"< 2 | using namespace std; 3 | main() 4 | { 5 | int t,n,m; 6 | cin>>t; 7 | int mi=INT_MIN,ans,s1=0,s2=0; 8 | while(t--) 9 | { 10 | cin>>n>>m; 11 | s1+=n;s2+=m; 12 | if(mi<=abs(s1-s2)) 13 | { 14 | mi=abs(s1-s2); 15 | if(n>m)ans=1; 16 | else ans=2; 17 | } 18 | } 19 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int n,b; 10 | cin>>n; 11 | if(n%2!=0)n--; 12 | b=n/4; 13 | cout<<((n*n)/8)-b< 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int t; 10 | cin>>t; 11 | while(t--) 12 | { 13 | long long int n,x,mx=0,mn=0,c=0; 14 | cin>>n; 15 | cin>>x; 16 | string s; 17 | cin>>s; 18 | for(int i=0;s[i]!='\0';i++) 19 | { 20 | if(s[i]=='L') c--; 21 | else c++; 22 | mx=max(c,mx); 23 | 24 | mn=min(c,mn); 25 | 26 | } 27 | cout< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 7 | #define int long long int 8 | int t; 9 | cin>>t; 10 | while(t--) 11 | { 12 | int n; 13 | cin>>n; 14 | int a,ans=0; 15 | 16 | for(int i=0;i>a; 19 | ans=max(ans,a); 20 | 21 | } 22 | cout< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 7 | #define int long long int 8 | int t; 9 | cin>>t; 10 | while(t--) 11 | { 12 | int n,cnt=0,cnt1=0; 13 | cin>>n; 14 | int a[n]; 15 | for(int i=0;i>a[i]; 18 | if(a[i]%2==0)cnt++; 19 | else if(a[i]%2!=0)cnt1++; 20 | } 21 | if(cnt==0 || cnt1==0){cout<<0< 2 | using namespace std; 3 | main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int n,m,k,a; 10 | cin>>n>>m>>k; 11 | mapmp; 12 | for(int i=1;i<=n;i++)mp[i]=0; 13 | for(int i=0;i>a;mp[a]++;} 14 | for(int i=0;i>a;mp[a]++;} 15 | int a1=0,a2=0; 16 | for(auto x:mp) 17 | { 18 | if(x.second>=2)a1++; 19 | else if(x.second==0)a2++; 20 | } 21 | cout< 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int t1,t2,t3,a[1000000]={0},cnt=0; 8 | int x,y,z; 9 | cin>>t1>>t2>>t3; 10 | for(int i=0;i>x; 13 | a[x]+=1; 14 | } 15 | for(int i=0;i>y; 18 | a[y]+=1; 19 | } 20 | for(int i=0;i>z; 23 | a[z]+=1; 24 | } 25 | for(int i=0;i<1000000;i++) 26 | { 27 | if(a[i]>=2) 28 | { 29 | cnt++; 30 | } 31 | } 32 | cout<=2) 36 | { 37 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int n; 10 | cin>>n; 11 | int flag=1,la=0,lb=0; 12 | for(int i=0;i>pt>>a>>b; 16 | if(a==b){cout<<"YES"< 2 | using namespace std; 3 | int main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int n,a,b,ans=0,sum=0,ans1=0; 10 | cin>>n; 11 | int v[11]={0}; 12 | for(int i=0;i>a>>b; 15 | if(a!=9&&a!=10&&a!=11) v[a]=max(v[a],b); 16 | } 17 | for(int i=1;i<=8;i++) 18 | { 19 | sum+=v[i]; 20 | } 21 | cout< 2 | using namespace std; 3 | main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int n,x,sum=0; 10 | cin>>n; 11 | int a[n+10]; 12 | int b[n+10]; 13 | int c[n+10]; 14 | int d[n+10]; 15 | a[0]=0;b[0]=0; 16 | 17 | for(int i=1;i<=n;i++) 18 | { 19 | cin>>c[i]; 20 | sum+=c[i]; 21 | a[i]=sum; 22 | } 23 | sum=0; 24 | for(int i=1;i<=n;i++) 25 | { 26 | cin>>d[i]; 27 | sum+=d[i]; 28 | b[i]=sum; 29 | } 30 | int ans=0; 31 | for(int i=1;i<=n;i++) 32 | { 33 | if(c[i]==d[i] && a[i]==b[i])ans+=c[i]; 34 | } 35 | cout< 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | ios::sync_with_stdio(0);cout.tie(0);cin.tie(0); 10 | long long int n,k,cnt=0; 11 | cin>>n; 12 | cin>>k; 13 | long long int a[n]; 14 | 15 | for(int i=0;i>a[i]; 18 | } 19 | sort(a,a+n); 20 | 21 | 22 | for(int i=0;i=k) 28 | { 29 | cnt+=n-j; 30 | break; 31 | } 32 | } 33 | } 34 | cout< 2 | using namespace std; 3 | main() 4 | { 5 | int x; 6 | cin>>x; 7 | if(x==1){cout<<-1< 2 | using namespace std; 3 | main() 4 | { 5 | int n,k,b; 6 | cin>>n>>k; 7 | vectora; 8 | for(int i=0;i>b;if(b>0)a.push_back(b);} 9 | sort(a.begin(),a.end()); 10 | auto it=unique(a.begin(),a.end()); 11 | a.resize(distance(a.begin(),it)); 12 | int sum=a[0],temp=0; 13 | cout<=(a.size())){cout<<0< 2 | using namespace std; 3 | main() 4 | { 5 | #define int long long int 6 | int n; 7 | cin>>n; 8 | int a[n+1]; 9 | int sum=0; 10 | for(int i=0;i>a[i];sum+=a[i];} 11 | if(sum%360==0){cout<<"YES"<bits(i); 16 | sum=0; 17 | ok=0; 18 | for(int j=n-1;j>=0;j--) 19 | { 20 | if(bits[j])sum+=a[j]; 21 | else sum-=a[j]; 22 | } 23 | if(sum%360==0){ok=1;break;} 24 | } 25 | if(ok)cout<<"YES"< 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | long long int n,t,k; 9 | int cnt=0,cnt1=0; 10 | cin>>n; 11 | t=n; 12 | 13 | while(t!=0) 14 | { 15 | k=t%10; 16 | t=t/10; 17 | if(k==4) cnt++; 18 | else if(k==7)cnt1++; 19 | else continue; 20 | } 21 | int p=cnt1 +cnt; 22 | if(p==4 || p==7) 23 | { 24 | cout<<"YES"; 25 | } 26 | else 27 | { 28 | cout<<"NO"; 29 | } 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /Codeforces problems/1174A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | main() 4 | { 5 | int x; 6 | cin>>x; 7 | int a[(2*x)+1]; 8 | for(int i=0;i<(2*x);i++){cin>>a[i];} 9 | sort(a,a+(2*x)); 10 | if(a[0]==a[(2*x)-1]){cout<<-1< 2 | using namespace std; 3 | main() 4 | { 5 | int n,ok=0,ok1=0; 6 | cin>>n; 7 | int a[n+1]; 8 | for(int i=0;i>a[i]; 11 | if(a[i]%2)ok=1; 12 | else ok1=1; 13 | } 14 | 15 | if(ok && ok1) 16 | { 17 | sort(a,a+n); 18 | for(int i=0;i 2 | using namespace std; 3 | int main() 4 | { 5 | #define int long long int 6 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 7 | string s; 8 | cin>>s; 9 | int w=0,threshold=0,ans=0; 10 | for(int i=0;i 2 | using namespace std; 3 | #define int long long int 4 | int power(int x, unsigned int y, int p) 5 | { 6 | int res = 1; 7 | x = x % p; 8 | if (x == 0) return 0; 9 | 10 | while (y > 0) 11 | { 12 | if (y & 1) res = (res*x) % p; 13 | y = y>>1; 14 | x = (x*x) % p; 15 | } 16 | return res; 17 | } 18 | main() 19 | { 20 | int w,h; 21 | cin>>w>>h; 22 | int ans=power(2,w-1+h-1,998244353); 23 | int an=ans*pow(2,2); 24 | cout< 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n,r; 9 | cin>>n; 10 | r=pow(n,2) + pow(n-1,2); 11 | cout< 2 | using namespace std; 3 | int sum(int a) 4 | { 5 | int res=0,k; 6 | while(a!=0) 7 | { 8 | k=a%10; 9 | a/=10; 10 | res+=k; 11 | } 12 | return res; 13 | } 14 | int main() 15 | { 16 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 17 | int n; 18 | cin>>n; 19 | while(1) 20 | { 21 | if(sum(n)%4==0){cout< 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 6 | #define int long long int 7 | #define pb push_back 8 | #define mk make_pair 9 | 10 | int t; 11 | cin>>t; 12 | while(t--) 13 | { 14 | int n,k,in; 15 | cin>>n>>k; 16 | int a[n+100]; 17 | for(int i=0;i>a[i]; 20 | } 21 | sort(a,a+n); 22 | 23 | if(abs(a[n-1]-(a[0]+k))>k)cout<<-1< 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int n,m,k; 8 | cin>>n; 9 | cin>>m; 10 | cin>>k; 11 | 12 | if(n>=1 && m<=100) 13 | { 14 | if(n>=1 && k<=100) 15 | { 16 | if(m>=n && k>=n) 17 | { 18 | cout<<"Yes"; 19 | } 20 | else 21 | { 22 | cout<<"No"; 23 | } 24 | } 25 | } 26 | 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Codeforces problems/1187A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int n,s,t,mi,ma; 10 | cin>>n>>s>>t; 11 | if(s>t) 12 | { 13 | mi=t; 14 | ma=s; 15 | } 16 | else 17 | { 18 | mi=s; ma=t; 19 | } 20 | 21 | int ss=n-ma; 22 | mi-=ss; //st 23 | int tt=n-(ss+mi); 24 | 25 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | int n,x; 11 | cin>>n>>x; 12 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | #define int long long int 6 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--) 10 | { 11 | int a,b,c; 12 | cin>>a>>b>>c; 13 | int f[3]; 14 | f[0]=a; 15 | f[1]=b; 16 | f[2]=c; 17 | sort(f,f+3); 18 | int u=f[0]; 19 | f[0]+=(f[1]-f[0]); 20 | f[2]-=(f[1]-u); 21 | 22 | int e=f[2]/2; 23 | f[0]+=e; 24 | cout< 2 | using namespace std; 3 | #define endl "\n" 4 | int main() 5 | { 6 | #define int long long int 7 | int t; 8 | cin>>t; 9 | while(t--) 10 | { 11 | int n,a; 12 | cin>>n; 13 | vectorv; 14 | for(int i=0;i>a; 17 | v.push_back(a); 18 | } 19 | sort(v.begin(),v.end(),greater()); 20 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int n,m=INT_MIN,flag=1; 6 | cin>>n; 7 | vectorv; 8 | int a,in; 9 | for(int i=0;i>a; 12 | v.push_back(a); 13 | if(m=v[i+1]){flag=0;break;} 22 | } 23 | for(int i=in;i 2 | using namespace std; 3 | #define int long long int 4 | 5 | int32_t main() 6 | { 7 | string s; 8 | cin>>s; 9 | if(s=="0"){cout<<0<1)cout< 2 | using namespace std; 3 | #define int long long int 4 | int32_t main() 5 | { 6 | int n,l,r; 7 | cin>>n>>l>>r; 8 | int minsum=0,j=1,in,flag=1; 9 | for(int i=1;i<=n;i++) 10 | { 11 | if(l==0){flag=0;in=i;break;} 12 | minsum+=j; 13 | j*=2; 14 | l--; 15 | } 16 | if(flag==0)for(int i=in;i<=n;i++)minsum+=1; 17 | j=1; 18 | int maxsum=1,in1; 19 | r--; 20 | flag=1; 21 | for(int i=2;i<=n;i++) 22 | { 23 | if(r==0){flag=0;in=i;in1=j;break;} 24 | j*=2; 25 | maxsum+=j; 26 | r--; 27 | } 28 | //cout< 2 | using namespace std; 3 | int main() 4 | { 5 | #define int long long int 6 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 7 | 8 | int n,m; 9 | cin>>n; 10 | int a[n+1]; 11 | for(int i=0;i>a[i]; 14 | } 15 | 16 | cin>>m; 17 | int b[m+1]; 18 | for(int i=0;i>b[i]; 21 | } 22 | sort(a,a+n); 23 | sort(b,b+m); 24 | cout< 2 | using namespace std; 3 | #define int long long int 4 | int32_t main() 5 | { 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | int a,b,c,d; 11 | cin>>a>>b>>d; 12 | int h=a^b; 13 | int f[3]; 14 | f[0]=a; 15 | f[1]=b; 16 | f[2]=h; 17 | cout< 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 9 | int n,i=0,cnt=0,c=0,d1,d2,ans=0,flag=1; 10 | cin>>n; 11 | string s; 12 | cin>>s; 13 | for(int i=0;i 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 6 | int a; 7 | vector v; 8 | for(int i=0;i<4;i++) 9 | { 10 | cin>>a; 11 | v.push_back(a); 12 | } 13 | sort(v.begin(),v.end()); 14 | if(v[3]==v[0]+v[1]+v[2]){cout<<"YES"< 2 | using namespace std; 3 | #define int long long int 4 | main() 5 | { 6 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 7 | int n,k,flag=1,j=0; 8 | cin>>n>>k; 9 | string s; 10 | cin>>s; 11 | 12 | if(n==1 && s[0]!=1 && k!=0){cout<<0< 2 | using namespace std; 3 | int main() 4 | { 5 | #define int long long int 6 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 7 | int t,a; 8 | cin>>t; 9 | while(t--) 10 | { 11 | double sum=0,avg=0; 12 | int n; 13 | cin>>n; 14 | for(int i=0;i>a; 17 | sum+=a; 18 | } 19 | avg=sum/n; 20 | if(ceil(avg)==avg)cout<<(int)avg< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--) 10 | { 11 | int n; 12 | cin>>n; 13 | if(n<4)cout<<4-n< 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | #define int long long int 8 | int t; 9 | cin>>t; 10 | while(t--) 11 | { 12 | string t; 13 | string s; 14 | cin>>s; 15 | cin>>t; 16 | int flag=1; 17 | //sort(s.begin(),s.end()); 18 | //sort(t.begin(),t.end()); 19 | 20 | for(int i=0;i 2 | using namespace std; 3 | int main() 4 | { 5 | #define int long long int 6 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--) 10 | { 11 | int a,b,c,d,k,cnt=1,cnt1=1; 12 | cin>>a>>b>>c>>d>>k; 13 | for(int i=c;ik){cout<<"-1"< 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 6 | #define int long long int 7 | int a,b,flag=1; 8 | cin>>a>>b; 9 | if(a<=b) 10 | { 11 | if(b-a==1) 12 | { 13 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | #define int long long int 6 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--) 10 | { 11 | int n,a,cnt=0; 12 | cin>>n; 13 | vectorv; 14 | for(int i=0;i>a; 17 | v.push_back(a); 18 | } 19 | sort(v.begin(),v.end()); 20 | for(int i=0;i 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 7 | #define int long long int 8 | int t; 9 | cin>>t; 10 | while(t--) 11 | { 12 | int a,b,sum=0,cnt=0,t1; 13 | cin>>a>>b; 14 | int d=fabs(a-b); 15 | 16 | if(d>=5) 17 | { 18 | cnt+=d/5; 19 | d=d%5; 20 | } 21 | if(d<5 && d>=2) 22 | { 23 | cnt+=d/2; 24 | d=d%2; 25 | } 26 | if(d<2 && d>=1) 27 | { 28 | cnt+=d/1; 29 | d=d%1; 30 | } 31 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 6 | #define int long long int 7 | int t; 8 | cin>>t; 9 | while(t--) 10 | { 11 | int a,b,n,s,flag=1; 12 | cin>>a>>b>>n>>s; 13 | 14 | int div=s/n; 15 | 16 | if(a>div || a==div)a=div; 17 | 18 | if(a*n+b>=s)cout<<"YES"< 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | ios::sync_with_stdio();cin.tie();cout.tie(); 8 | #define int long long int 9 | int t; 10 | cin>>t; 11 | while(t--) 12 | { 13 | int h,m,h1,m1; 14 | cin>>h>>m; 15 | h1=23-h; 16 | m1=60-m; 17 | int ans=h1*60+m1; 18 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 6 | #define int long long 7 | int t; 8 | cin>>t; 9 | for(int i=1;i<=t;i++) 10 | { 11 | int n,k,ans,a; 12 | cin>>n>>k; 13 | a=n/k; 14 | ans=(a*k)+min(n%k,k/2); 15 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 6 | #define int long long int 7 | int n,i=0,l=0,r=0,cnt=1; 8 | cin>>n; 9 | string s; 10 | cin>>s; 11 | while(s[i]!='\0') 12 | { 13 | if(s[i]=='L')l++; 14 | else r++; 15 | i++; 16 | } 17 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 6 | #define int long long int 7 | int t; 8 | cin>>t; 9 | while(t--) 10 | { 11 | int a,cnt=0,flag=1; 12 | string b; 13 | cin>>a>>b; 14 | if(b.size()==1) 15 | { 16 | char v=b[0]; 17 | int p=v-'0'; 18 | if(p==9)cout< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 7 | #define int long long int 8 | float n,t=1,sum=0,s=0; 9 | cin>>n; 10 | while(n!=0) 11 | { 12 | sum+=t/n; 13 | n--; 14 | } 15 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 6 | #define int long long int 7 | int t; 8 | cin>>t; 9 | while(t--) 10 | { 11 | int a,b,c,n,sum=0; 12 | cin>>a>>b>>c>>n; 13 | vectorv; 14 | v.push_back(a); 15 | v.push_back(b); 16 | v.push_back(c); 17 | sort(v.begin(),v.end(),greater()); 18 | sum+=v[0]-v[1]; 19 | sum+=v[0]-v[2]; 20 | n-=sum; 21 | if(n%3==0 && n>=0)cout<<"YES"< 2 | using namespace std; 3 | main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int x; 10 | cin>>x; 11 | cout<<1<<" "< 2 | using namespace std; 3 | main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int x; 10 | cin>>x; 11 | int a; 12 | sets; 13 | for(int i=0;i>a;s.insert(a);} 14 | cout< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 7 | #define int long long int 8 | 9 | int t; 10 | cin>>t; 11 | while(t--) 12 | { 13 | int n; 14 | cin>>n; 15 | if(n==1){cout<<-1< 2 | using namespace std; 3 | int main() 4 | { 5 | #define int long long int 6 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 7 | 8 | int t; 9 | cin>>t; 10 | while(t--) 11 | { 12 | int n,k; 13 | cin>>n>>k; 14 | if(k%2==n%2 && n>=k*k)cout<<"YES"< 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 6 | #define int long long int 7 | int t; 8 | cin>>t; 9 | while(t--) 10 | { 11 | int a,b; 12 | cin>>a>>b; 13 | if(a%b==0 ){cout<<0< 2 | using namespace std; 3 | main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int n,x,ans; 10 | cin>>n>>x; 11 | int a[n+1]; 12 | mapmp; 13 | for(int i=0;i>a[i]; 16 | mp[a[i]]++; 17 | } 18 | for(int i=1;x;i++) 19 | { 20 | if(mp[i])continue; 21 | else x--; 22 | mp[i]++; 23 | } 24 | int i=1; 25 | while(1) 26 | { 27 | if(mp[i]==0){ans=i;break;} 28 | i++; 29 | } 30 | cout< 3 | using namespace std; 4 | int main() 5 | { 6 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 7 | #define int long long int 8 | #define pb push_back 9 | #define mk make_pair 10 | int t; 11 | cin>>t; 12 | while(t--) 13 | { 14 | int n; 15 | cin>>n; 16 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 6 | #define int long long int 7 | #define pb push_back 8 | #define mk make_pair 9 | int t; 10 | cin>>t; 11 | while(t--) 12 | { 13 | int n,a,b,c,d,flag=1; 14 | cin>>n>>a>>b>>c>>d; 15 | int m=a-b; 16 | int k=a+b; 17 | int g=c-d; 18 | int p=c+d; 19 | if(n*m>p || n*k 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 7 | #define int long long int 8 | #define pb push_back 9 | #define mk make_pair 10 | int t; 11 | cin>>t; 12 | while(t--) 13 | { 14 | int x,y,a,b,ans; 15 | cin>>x>>y; 16 | cin>>a>>b; 17 | int ans2=(x+y)*a; 18 | int d=min(x,y); 19 | ans=d*b; 20 | x-=d;y-=d; 21 | if(y>0) 22 | { 23 | ans+=y*a; 24 | } 25 | else if(x>0)ans+=x*a; 26 | 27 | 28 | cout< 2 | using namespace std; 3 | #define int long long int 4 | #define pb push_back 5 | 6 | int32_t main() 7 | { 8 | int t; 9 | cin>>t; 10 | while(t--) 11 | { 12 | int n,i=1,sum=1; 13 | cin>>n; 14 | while(1) 15 | { 16 | sum+=(1< 2 | using namespace std; 3 | int main() 4 | { 5 | #define int long long int 6 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--) 10 | { 11 | int n,m; 12 | cin>>n>>m; 13 | if(n==1)cout<<"YES"<=3 && m==1)cout<<"YES"< 2 | using namespace std; 3 | #define int long long int 4 | int ans=0; 5 | int f(int n) 6 | { 7 | int d=1,in,cd,g,k,i=1; 8 | while(1) 9 | { 10 | d=i*i + i +(i*(i-1))/2; 11 | if(d>n){in=i-1;break;} 12 | i++; 13 | } 14 | if(in>1)cd=in*in +in+(in*(in-1))/2; 15 | else cd=2; 16 | g=n/cd; 17 | ans+=g; 18 | k=n%cd; 19 | if(k!=0 && k!=1)f(k); 20 | else return ans; 21 | } 22 | main() 23 | { 24 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 25 | int t; 26 | cin>>t; 27 | while(t--) 28 | { 29 | int n; 30 | cin>>n; 31 | ans=0; 32 | cout< 2 | using namespace std; 3 | 4 | #define pb push_back 5 | int a[100001]; 6 | int dp[100001]; 7 | 8 | int solve(int i,int n,int ans) 9 | { 10 | ans=1; 11 | if(i>n)return ans; 12 | if(dp[i]!=-1)return dp[i]; 13 | for(int j=2*i;j<=n;j+=i) 14 | { 15 | if(a[j]>a[i]) ans=max(ans,1+solve(j,n,ans)); 16 | } 17 | return dp[i]=ans; 18 | } 19 | main() 20 | { 21 | int t; 22 | cin>>t; 23 | while(t--) 24 | { 25 | int n,maxi=INT_MIN; 26 | cin>>n; 27 | for(int i=1;i<=n;i++){cin>>a[i];dp[i]=-1;} 28 | int ans; 29 | for(int i=1;i<=n;i++)maxi=max(solve(i,n,ans),maxi); 30 | cout< 2 | using namespace std; 3 | #define int long long int 4 | int32_t main() 5 | { 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | string s,t; 11 | cin>>s; 12 | vectorv; 13 | for(int i=s.size()-1;i>=0;i--) 14 | { 15 | if(s[i]!='0') 16 | { 17 | t+=s[i]; 18 | for(int j=1;j<=s.size()-i-1;j++)t+='0'; 19 | v.push_back(t); 20 | } 21 | t.clear(); 22 | } 23 | cout< 2 | using namespace std; 3 | #define int long long int 4 | int32_t main() 5 | { 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | int n,k; 11 | cin>>n>>k; 12 | int ans=k/(n-1); 13 | if(k%(n-1)==0)cout<<(n*ans)-1< 2 | using namespace std; 3 | #define int long long int 4 | #define pb push_back 5 | int32_t main() 6 | { 7 | int t; 8 | cin>>t; 9 | while(t--) 10 | { 11 | int n; 12 | cin>>n; 13 | int a[n+5],cnt[n+5]={0}; 14 | int sum=0; 15 | for(int i=0;i>a[i]; 16 | int l=0,r=1; 17 | for(int i=0;i0)ans++; 29 | cout< 2 | using namespace std; 3 | #define int long long int 4 | #define pb push_back 5 | int32_t main() 6 | { 7 | int t; 8 | cin>>t; 9 | while(t--) 10 | { 11 | int n,pres,ok; 12 | cin>>n; 13 | if(n%2==0)ok=1; 14 | else ok=0; 15 | if(n<=3){cout<<-1<=0;i-=2) 20 | { 21 | if(i!=pres)cout< 2 | using namespace std; 3 | #define int long long int 4 | #define pb push_back 5 | #define mk make_pair 6 | int32_t main() 7 | { 8 | int t; 9 | cin>>t; 10 | while(t--) 11 | { 12 | int a,b; 13 | cin>>a>>b; 14 | if(a==1){cout<<0< 2 | using namespace std; 3 | #define int long long int 4 | #define pb push_back 5 | #define mk make_pair 6 | int32_t main() 7 | { 8 | int t; 9 | cin>>t; 10 | while(t--) 11 | { 12 | int n,k; 13 | cin>>n>>k; 14 | int a[n+1],b[n+1]; 15 | for(int i=0;i>a[i]; 16 | for(int i=0;i>b[i]; 17 | sort(a,a+n); 18 | sort(b,b+n,greater()); 19 | int sum=0; 20 | for(int i=0;i 2 | using namespace std; 3 | #define int long long int 4 | #define pb push_back 5 | #define mk make_pair 6 | int32_t main() 7 | { 8 | int t; 9 | cin>>t; 10 | while(t--) 11 | { 12 | int n; 13 | cin>>n; 14 | int h=n/2; 15 | int ans=0,c=1; 16 | for(int i=1;i<=h;i++) 17 | { 18 | ans+=(i*8*c); 19 | c++; 20 | } 21 | cout< 2 | using namespace std; 3 | #define io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 4 | #define int long long int 5 | int32_t main() 6 | { 7 | freopen 8 | io 9 | int t; 10 | cin>>t; 11 | while(t--) 12 | { 13 | int a,b,c,d; 14 | cin>>a>>b>>c>>d; 15 | if(b>=a){cout< 2 | using namespace std; 3 | main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int n; 10 | cin>>n; 11 | int a[n+1]; 12 | sets; 13 | for(int i=0;i>a[i]; 16 | s.insert(a[i]); 17 | } 18 | if(s.size()==1) 19 | { 20 | cout<=(a[i]-1)){ans++;sofar-=(a[i]-1);} 28 | else sofar++; 29 | } 30 | cout< 2 | using namespace std; 3 | #define int long long int 4 | #define endl "\n" 5 | main() 6 | { 7 | int t; 8 | cin>>t; 9 | while(t--) 10 | { 11 | int ar[3]; 12 | for(int i=0;i<3;i++)cin>>ar[i]; 13 | sort(ar,ar+3); 14 | int x,y,z; 15 | x=ar[0]; 16 | y=ar[1]; 17 | z=ar[2]; 18 | int a,b,c; 19 | b=x; 20 | c=y; 21 | int d,f; 22 | if(c==z) 23 | { 24 | cout<<"YES"< 2 | using namespace std; 3 | #define int long long int 4 | #define endl "\n" 5 | main() 6 | { 7 | int t; 8 | cin>>t; 9 | while(t--) 10 | { 11 | int n,a; 12 | cin>>n; 13 | mapmp; 14 | for(int i=0;i<(2*n);i++) 15 | { 16 | cin>>a; 17 | if(mp[a]==0)cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int n,m,k,maxi,add=0; 10 | cin>>n>>m>>k; 11 | 12 | int mil=min(n/k,m); 13 | m-=mil; 14 | if(m>0 && k-1>0) 15 | { 16 | if(m%(k-1)!=0)add=1; 17 | maxi=m/(k-1)+add; 18 | cout< 2 | using namespace std; 3 | #define int long long int 4 | main() 5 | { 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | int n,flag=1; 11 | cin>>n; 12 | int a[n+1]; 13 | mapmp; 14 | for(int i=0;i>a[i]; 17 | } 18 | if(n%2!=0){cout<<-1< 2 | using namespace std; 3 | main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | string s; 10 | int ans=INT_MAX,ans1=INT_MAX; 11 | cin>>s; 12 | int num1=0,num0=0,done1=0,done0=0; 13 | for(int i=0;i 2 | using namespace std; 3 | #define pb push_back 4 | main() 5 | { 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | int n,x,a,ok=0; 11 | cin>>n>>x; 12 | vectorv; 13 | int sum=0; 14 | for(int i=0;i>a;sum+=a;v.pb(a);if(a%x!=0)ok=1;} 15 | if(ok==0){cout<<-1<=0;i--) 23 | { 24 | if(v[i]%x!=0){ini=i;break;} 25 | } 26 | 27 | cout< 2 | using namespace std; 3 | #define pb push_back 4 | main() 5 | { 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | int n,a; 11 | cin>>n; 12 | vectorv; 13 | for(int i=0;i>a; 16 | v.pb(a); 17 | } 18 | vectorans; 19 | for(int i=0;i 2 | using namespace std; 3 | 4 | main() 5 | { 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | int n,a,b,flag=0; 11 | cin>>n; 12 | int upd=-1; 13 | for(int i=0;i>a; 16 | if(upd>a)flag=1; 17 | upd=a; 18 | } 19 | bool yes=0,ok=0; 20 | for(int i=0;i>a; 23 | if(a==0)ok=1; 24 | else if(a==1){yes=1;} 25 | } 26 | if(!flag){cout<<"Yes"< 2 | using namespace std; 3 | #define pb push_back 4 | main() 5 | { 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | int a,b; 11 | cin>>a>>b; 12 | if(a>=(2*b) || b>=(2*a)){cout<a)swap(a,b); 14 | int ans=a-b; 15 | a=a-2*ans; 16 | b=b-ans; 17 | //after (a-b)steps a equals b 18 | int check=a-(a/3)*3; 19 | ans+=(check==2)+(a/3)*2; 20 | cout< 2 | using namespace std; 3 | #define pb push_back 4 | main() 5 | { 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | int n,x,m,a,b,ans=1,ok=0; 11 | cin>>n>>x>>m; 12 | int l=x,r=x; 13 | for(int i=0;i>a>>b; 16 | if(max(l,a)<=min(r,b)) 17 | { 18 | l=min(l,a); 19 | r=max(r,b); 20 | } 21 | } 22 | cout< 2 | using namespace std; 3 | main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | string s; 10 | cin>>s; 11 | int sz=s.size(); 12 | vectorv; 13 | int j=1; 14 | v.pb(s[0]); 15 | for(int i=1;i<(sz-1);i+=2)v.pb(s[i]); 16 | v.pb(s[(sz-1)]); 17 | for(int i=0;i 2 | using namespace std; 3 | main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int n,a,b; 10 | cin>>a>>b>>n; 11 | if(a>n || b>n){cout<<0<f; 13 | f[0] = max(a,b); f[1] = a+b; 14 | if(f[1]>n){cout<<1<n)break; 22 | i++; 23 | } 24 | cout< 2 | using namespace std; 3 | main() 4 | { 5 | int t; 6 | cin>>t; 7 | int a[]={1,1,1,1,1,1,1,1,1,1}; 8 | string ans="codeforces"; 9 | if(t==1){cout<=t)break; 20 | } 21 | for(int i=0;i<10;i++) 22 | for(int j=0;j 2 | using namespace std; 3 | main() 4 | { 5 | int n; 6 | cin>>n; 7 | vector>v; 8 | int i=0,j=0,ans=0; 9 | v.pb({i,j}); 10 | while(1) 11 | { 12 | v.pb({i+1,j}); 13 | v.pb({i,j+1}); 14 | i++;j++; 15 | if(i>=2)ans++; 16 | v.pb({i,j}); 17 | if(ans==n)break; 18 | } 19 | cout< 2 | using namespace std; 3 | main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int n; 10 | cin>>n; 11 | if(n%4==0)cout<<"YES"< 2 | using namespace std; 3 | #define pb push_back 4 | main() 5 | { 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | int n,m=INT_MIN; 11 | cin>>n; 12 | cout< 2 | using namespace std; 3 | 4 | bool powerof2 (int x) { return x && (!(x&(x-1)));} 5 | 6 | bool isprime(int n) 7 | { 8 | if(n==2 || n==3)return 1; 9 | if(n%2==0 || n%3==0 || n==1)return 0; 10 | for(int i=5;i*i<=n;i+=6) 11 | { 12 | if(n%i==0 || n%(i+2)==0)return 0; 13 | } 14 | return 1; 15 | } 16 | main() 17 | { 18 | int t; 19 | cin>>t; 20 | while(t--) 21 | { 22 | int n; 23 | cin>>n; 24 | if(n==1)cout<<"FastestFinger"<2){cout<<"FastestFinger"< 2 | using namespace std; 3 | main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int n; 10 | cin>>n; 11 | if(n%2!=0) 12 | { 13 | n++; 14 | cout< 2 | using namespace std; 3 | main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int v,c,n,m; 10 | cin>>v>>c>>n>>m; 11 | if(min(v,c)=1){cout<<"No"<n && min(v,c)>m){cout<<"Yes"<=n)cout<<"Yes"< 2 | using namespace std; 3 | main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int n; 10 | cin>>n; 11 | for(int i=0;i 2 | using namespace std; 3 | int main() 4 | { 5 | #define int long long int 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | int a,b,c; 11 | cin>>a>>b>>c; 12 | if(a>c)cout<<-1<<" "<c)cout<<1<<" "< 2 | using namespace std; 3 | int main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | string s; 10 | cin>>s; 11 | int num1=0,num0=0; 12 | for(int i=0;i 2 | using namespace std; 3 | int main() 4 | { 5 | #define int long long int 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | string s; 11 | cin>>s; 12 | int num=0,num0=0,ans=s.size(); 13 | for(int i=0;i 2 | using namespace std; 3 | int main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int x,y,n; 10 | cin>>x>>y>>n; 11 | int ans=n%x; 12 | if(ans==y){cout<y) 22 | { 23 | int minu=ans-y; 24 | n-=minu; 25 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | #define int long long int 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | int n; 11 | cin>>n; 12 | if(n==1){cout<<0<1) 17 | { 18 | if(n%6==0) 19 | { 20 | n/=6; 21 | ans++; 22 | if(n==1){ok=1;break;} 23 | } 24 | else if(n%6!=0 && n%3==0) 25 | { 26 | n*=2; 27 | ans++; 28 | if(n==1){ok=1;break;} 29 | } 30 | else if(n%3!=0){flag=0;break;} 31 | } 32 | if(ok)cout< 2 | using namespace std; 3 | int main() 4 | { 5 | #define int long long int 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | int n; 11 | cin>>n; 12 | string s; 13 | cin>>s; 14 | stackq; 15 | int done=0; 16 | for(int i=0;i 2 | using namespace std; 3 | main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int n; 10 | cin>>n; 11 | int a[n+1]; 12 | for(int i=0;i>a[i]; 13 | for(int i=0;i 2 | using namespace std; 3 | main() 4 | { 5 | #define int long long int 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | string s; 11 | cin>>s; 12 | vector>ans; 13 | int a=0,b=0,c=0; 14 | for(int i=0;i 2 | using namespace std; 3 | main() 4 | { 5 | #define int long long int 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | int n,x; 11 | cin>>n>>x; 12 | int a[n+1],much=0,sofar=0; 13 | for(int i=0;i>a[i]; 14 | sort(a,a+n,greater()); 15 | int ans=0; 16 | for(int i=0;i=x)ans++; 19 | else if(x>a[i]) 20 | { 21 | much=0; 22 | if(x%a[i]!=0)much++; 23 | much+=(x/a[i]); 24 | much--; 25 | if(sofar>=much) 26 | { 27 | ans++; 28 | sofar-=much; 29 | } 30 | else sofar++; 31 | } 32 | } 33 | cout< 2 | using namespace std; 3 | #define io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 4 | main() 5 | { 6 | io 7 | int t; 8 | cin>>t; 9 | while(t--) 10 | { 11 | int n,m,a; 12 | cin>>n>>m; 13 | mapmp; 14 | int ans,flag=0; 15 | for(int i=0;i>a;mp[a]++;} 16 | for(int i=0;i>a; 19 | if(mp[a]){ans=a;flag=1;} 20 | } 21 | if(flag) 22 | { 23 | cout<<"YES"< 3 | using namespace std; 4 | #define io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 5 | #define int long long int 6 | main() 7 | { 8 | io 9 | int t; 10 | cin>>t; 11 | while(t--) 12 | { 13 | int n,ans=-1; 14 | cin>>n; 15 | int a[n+1]; 16 | for(int i=0;i>a[i]; 17 | for(int i=0;i1){ans=i;break;} 18 | if(ans==-1) 19 | { 20 | if(n%2==0)cout<<"Second"< 2 | using namespace std; 3 | #define int long long int 4 | #define endl "\n" 5 | main() 6 | { 7 | int t; 8 | cin>>t; 9 | while(t--) 10 | { 11 | int ar[3]; 12 | for(int i=0;i<3;i++)cin>>ar[i]; 13 | sort(ar,ar+3); 14 | int x,y,z; 15 | x=ar[0]; 16 | y=ar[1]; 17 | z=ar[2]; 18 | int a,b,c; 19 | b=x; 20 | c=y; 21 | int d,f; 22 | if(c==z) 23 | { 24 | cout<<"YES"< 2 | using namespace std; 3 | main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int l,r; 10 | cin>>l>>r; 11 | if(r>=2*l){cout< 2 | using namespace std; 3 | main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int n; 10 | cin>>n; 11 | for(int i=1;i<=n;i++)cout< 2 | using namespace std; 3 | main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int n,m; 10 | cin>>n>>m; 11 | char a[n+1][m+1]; 12 | for(int i=0;i>a[i][j]; 13 | int ans=0; 14 | for(int i=0;i 2 | using namespace std; 3 | main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int n,cnt=0; 10 | cin>>n; 11 | int a[n+1]; 12 | mapmp; 13 | for(int i=0;i>a[i]; 16 | mp[a[i]]++; 17 | } 18 | int ok=0; 19 | for(auto x:mp) 20 | { 21 | cnt++; 22 | if(cnt>=2){ok=1;break;} 23 | } 24 | if(ok)cout<<1< 2 | using namespace std; 3 | main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int n; 10 | cin>>n; 11 | if(n==1 || n==2){cout< 2 | using namespace std; 3 | #define int long long int 4 | #define endl "\n" 5 | main() 6 | { 7 | int t; 8 | cin>>t; 9 | while(t--) 10 | { 11 | int n; 12 | cin>>n; 13 | int a[n+1]; 14 | for(int i=0;i>a[i]; 15 | 16 | if(a[0]+a[1]<=a[n-1]) 17 | { 18 | cout<<1<<" "<<2<<" "< 2 | using namespace std; 3 | main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int n; 10 | cin>>n; 11 | int a[n+1]; 12 | for(int i=0;i>a[i]; 15 | } 16 | sort(a,a+n); 17 | int ok=0; 18 | for(int i=0;i1)ok=1; 21 | } 22 | if(ok==0)cout<<"YES"< 2 | using namespace std; 3 | main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int n,k; 10 | cin>>n>>k; 11 | 12 | if(k>=n) 13 | { 14 | cout< 2 | using namespace std; 3 | #define io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 4 | #define endl "\n" 5 | #define int long long int 6 | main() 7 | { 8 | io 9 | int t; 10 | cin>>t; 11 | while(t--) 12 | { 13 | int n; 14 | cin>>n; 15 | cout<<9; 16 | int s=8; 17 | for(int i=1;i 2 | using namespace std; 3 | #define io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 4 | #define pb push_back 5 | #define endl "\n" 6 | int main() 7 | { 8 | io 9 | #define int long long int 10 | int t; 11 | cin>>t; 12 | while(t--) 13 | { 14 | int w,h,n; 15 | cin>>w>>h>>n; 16 | int a=__gcd(w,1ll<<14); // Calculating largest power of 2 which can divide w 17 | int b=__gcd(h,1ll<<14); // Calculating largest power of 2 which can divide h 18 | //2^14 is taken as reference because its greater than 10^4 (input) 19 | if(a*b>=n)cout<<"YES"< 2 | using namespace std; 3 | #define io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 4 | #define pb push_back 5 | #define endl "\n" 6 | int main() 7 | { 8 | io 9 | #define int long long int 10 | int t; 11 | cin>>t; 12 | while(t--) 13 | { 14 | int n,a; 15 | cin>>n; 16 | int one=0,two=0; 17 | for(int i=0;i>a; 20 | if(a==2)two++; 21 | if(a==1)one++; 22 | } 23 | int sum=(two*2+one),var; 24 | if(sum%2==1){cout<<"NO"<0))cout<<"YES"< 2 | using namespace std; 3 | #define io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 4 | #define pb push_back 5 | #define endl "\n" 6 | 7 | int main() 8 | { 9 | io 10 | #define int long long int 11 | int t; 12 | cin>>t; 13 | while(t--) 14 | { 15 | int n; 16 | cin>>n; 17 | int a[n+1]; 18 | for(int i=1;i<=n;i++) cin>>a[i]; 19 | int score[n+1]={0}; 20 | int maxi=-1; 21 | for(int i=n;i>=1;i--) 22 | { 23 | if(i+a[i]>n)score[i]=a[i]; 24 | else score[i]=score[i+a[i]]+a[i]; 25 | maxi=max(maxi,score[i]); 26 | } 27 | cout< 2 | using namespace std; 3 | #define io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 4 | #define pb push_back 5 | #define endl "\n" 6 | #define int long long int 7 | main() 8 | { 9 | int t; 10 | cin>>t; 11 | while(t--) 12 | { 13 | int n,d,x,ok=0; 14 | cin>>n>>d; 15 | vectora; 16 | for(int i=0;i>x; 19 | a.pb(x); 20 | if(x>d)ok=1; 21 | } 22 | if(ok==0){cout<<"YES"< 2 | using namespace std; 3 | 4 | main() 5 | { 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | int n; 11 | cin>>n; 12 | int a[n+1],b[n+1],tm[n+1]; 13 | a[0]=0; b[0]=0; 14 | for(int i=1;i<=n;i++)cin>>a[i]>>b[i]; 15 | for(int i=1;i<=n;i++)cin>>tm[i]; 16 | 17 | int aa[n+1],bb[n+1]; 18 | 19 | aa[0]=0; bb[0]=0; 20 | 21 | for(int i=1;i<=n;i++) 22 | { 23 | int move=a[i]-b[i-1]; 24 | aa[i]=bb[i-1]+move+tm[i]; 25 | 26 | int diff = (b[i] - a[i]); 27 | if(diff % 2==1)diff=(diff/2)+1; 28 | else diff=(diff/2); 29 | bb[i]=aa[i]+diff; 30 | if(bb[i] 2 | using namespace std; 3 | #define freopen freopen("input.txt","r",stdin);freopen("output.txt","w",stdout); 4 | #define int long long int 5 | main() 6 | { 7 | int t; 8 | cin>>t; 9 | while(t--) 10 | { 11 | int n,m,x; 12 | cin>>n>>m>>x; 13 | int col=(x/n) + (x%n!=0); 14 | int row=x%n; 15 | if(row==0)row=n; 16 | int ans = m*(row-1)+1+col-1; 17 | cout< 2 | using namespace std; 3 | #define int long long int 4 | #define endl "\n" 5 | #define pb push_back 6 | 7 | main() 8 | { 9 | int t; 10 | cin>>t; 11 | while(t--) 12 | { 13 | int n; 14 | cin>>n; 15 | int a[n+1]; 16 | int flag=0; 17 | for(int i=0;i>a[i]; 20 | int sq=sqrt(a[i]); 21 | if(sq*sq!=a[i])flag=1; 22 | } 23 | 24 | if(flag==1)cout<<"YES"< 2 | using namespace std; 3 | #define int long long int 4 | #define freopen freopen("input.txt","r",stdin);freopen("output1.txt","w",stdout); 5 | main() 6 | { 7 | // freopen 8 | int t; 9 | cin>>t; 10 | while(t--) 11 | { 12 | int n; 13 | cin>>n; 14 | int a[n+1]; 15 | int mini=INT_MAX; 16 | for(int i=0;i>a[i]; 19 | mini=min(mini,a[i]); 20 | } 21 | 22 | int cnt=0; 23 | for(int i=0;i 2 | using namespace std; 3 | #define freopen freopen("input.txt","r",stdin);freopen("output.txt","w",stdout); 4 | #define pb push_back 5 | #define int long long int 6 | 7 | 8 | main() 9 | { 10 | int t; 11 | cin>>t; 12 | while(t--) 13 | { 14 | int n,s; 15 | cin>>n>>s; 16 | int median; 17 | 18 | if(n%2==0)median=n/2; 19 | else median=(n/2)+1; 20 | 21 | int left_values=n-median+1; 22 | cout< 2 | using namespace std; 3 | #define freopen freopen("input.txt","r",stdin);freopen("output.txt","w",stdout); 4 | #define int long long int 5 | #define pb push_back 6 | main() 7 | { 8 | int t; 9 | cin>>t; 10 | while(t--) 11 | { 12 | int n; 13 | cin>>n; 14 | int a[n+1]; 15 | for(int i=1;i<=n;i++)cin>>a[i]; 16 | int ans=0,upd=0; 17 | for(int i=1;i<=n;i++) 18 | { 19 | if(a[i]>(i+upd)) 20 | { 21 | ans+=a[i]-(i+upd); 22 | upd+=a[i]-(i+upd); 23 | } 24 | } 25 | cout< 2 | using namespace std; 3 | #define freopen freopen("input.txt","r",stdin);freopen("output.txt","w",stdout); 4 | #define int long long int 5 | #define pb push_back 6 | main() 7 | { 8 | int t; 9 | cin>>t; 10 | while(t--) 11 | { 12 | int n; 13 | cin>>n; 14 | int a[n+1]; 15 | for(int i=1;i<=n;i++)cin>>a[i]; 16 | if(n%2==0){cout<<"YES"<=a[i+1]){flag=1;break;} 21 | } 22 | if(flag==1)cout<<"YES"< 2 | using namespace std; 3 | #define freopen freopen("input.txt","r",stdin);freopen("output.txt","w",stdout); 4 | #define int long long int 5 | #define pb push_back 6 | main() 7 | { 8 | int t; 9 | cin>>t; 10 | while(t--) 11 | { 12 | int n; 13 | cin>>n; 14 | int a[n+1]; 15 | for(int i=1;i<=n;i++)cin>>a[i]; 16 | bool flag=1; 17 | int lcmnow=1; 18 | for(int i=1;i<=min(n,21ll);i++) 19 | { 20 | lcmnow = (lcmnow*(i+1))/__gcd(lcmnow,i+1); 21 | if(a[i]%lcmnow==0){flag=0;break;} 22 | } 23 | 24 | if(flag==0)cout<<"NO"< 3 | using namespace std; 4 | #define freopen freopen("input.txt","r",stdin);freopen("output.txt","w",stdout); 5 | #define pb push_back 6 | #define int long long int 7 | 8 | 9 | signed main() 10 | { 11 | // freopen 12 | int t; 13 | cin>>t; 14 | while(t--) 15 | { 16 | int n; 17 | cin>>n; 18 | int a[n+1]; 19 | for(int i=0;i>a[i]; 20 | 21 | sort(a,a+n); 22 | int ans=0; 23 | 24 | int addon=0; 25 | for(int i=n-2;i>=0;i--) 26 | { 27 | int d=a[n-1]-a[i]-addon; 28 | addon+=d; 29 | if(d>0)ans+=d; 30 | } 31 | cout< 3 | using namespace std; 4 | #define int long long int 5 | 6 | int yes() 7 | { 8 | cout<<"YES"<>t; 15 | while(t--) 16 | { 17 | int a,b,c; 18 | cin>>a>>b>>c; 19 | if(b-a==c-b){cout<<"YES"<0) 22 | { 23 | yes();continue; 24 | } 25 | //change a 26 | if(((2*b)-c)%a==0 && ((2*b)-c)>0) 27 | { 28 | yes();continue; 29 | } 30 | //change c 31 | if(((2*b)-a)%c==0 && ((2*b)-a)>0) 32 | { 33 | yes();continue; 34 | } 35 | cout<<"NO"< 2 | using namespace std; 3 | #define int long long int 4 | signed main() 5 | { 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | int n; 11 | cin>>n; 12 | int a[n+1]; 13 | int hash[n+1]={0}; 14 | for(int i=0;i>a[i]; 17 | while(a[i]>n)a[i]/=2; 18 | 19 | if(hash[a[i]]==0)hash[a[i]]=1; 20 | else 21 | { 22 | while(a[i]>0) 23 | { 24 | a[i]/=2; 25 | if(hash[a[i]]==0){hash[a[i]]=1;break;} 26 | } 27 | } 28 | } 29 | int flag=0; 30 | for(int i=1;i<=n;i++)if(hash[i]==0){flag=1;break;} 31 | if(flag==1)cout<<"NO"< 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 6 | int n,m; 7 | cin>>n>>m; 8 | char c[n][m]; 9 | for(int i=0;i>c[i][j]; 12 | } 13 | for(int i=0;i 2 | using namespace std; 3 | main() 4 | { 5 | string s,t; 6 | cin>>s>>t; 7 | if(s==t){cout<<-1< 2 | using namespace std; 3 | main() 4 | { 5 | int n; 6 | cin>>n; 7 | if(n%2)cout<<"Ehab"< 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int n,sum=0,flag=0,temp,a; 8 | vector v; 9 | cin>>n; 10 | for(int i=0;i<7;i++) 11 | { 12 | cin>>a; 13 | v.push_back(a); 14 | } 15 | 16 | for(int i=0;i<1000;i++) 17 | { 18 | for(int j=0;j<7;j++) 19 | { 20 | sum+=v[j]; 21 | temp=j+1; 22 | if(sum>=n) {flag=1;break;} 23 | } 24 | if(flag==1)break; 25 | } 26 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int n,a,cnt=0; 6 | cin>>n; 7 | vector v; 8 | for(int i=0;i>a; 11 | v.push_back(a); 12 | if(a%2==0) 13 | { 14 | cnt++; 15 | } 16 | } 17 | cout< 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int n,d,e,ans; 8 | cin>>n>>d>>e; 9 | ans=n; 10 | 11 | for(int i=0;i*5*e<=n;i++) 12 | { 13 | ans=min(ans,(n-i*5*e)%d); 14 | } 15 | cout< 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 8 | long long int n,i=0,cnt=0,c=0; 9 | string s; 10 | cin>>n; 11 | cin>>s; 12 | while(s[i]!='\0') 13 | { 14 | if(s[i]=='n')cnt++; 15 | else if(s[i]=='z')c++; 16 | i++; 17 | } 18 | for(int i=0;i 2 | using namespace std; 3 | int main() 4 | { 5 | int a,b; 6 | cin>>a>>b; 7 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | 6 | int n; 7 | cin>>n; 8 | for(int i=1;i<=n;i++) 9 | { 10 | 11 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int d,w,x; 6 | int arr[1000]; 7 | int ar[1000]; 8 | cin>>d>>w; 9 | for(int i=0;i>arr[i]>>ar[i]; 12 | } 13 | for(int i=0;i>x; 16 | for(int j=0;j 2 | using namespace std; 3 | int main() 4 | { 5 | int n,c,i,cnt=0,sum=0,k; 6 | cin>>n>>c; 7 | for(i=0;i>k; 10 | cnt++; 11 | sum=sum+k; 12 | if(sum>=c){cout< 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int arr[1000],n,q,x; 8 | cin>>n>>q; 9 | for(int i=0;i>arr[i]; 12 | } 13 | for(int i=0;i>x; 16 | x--; 17 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int n,d,a,b; 6 | cin>>n>>d; 7 | a=n/d; 8 | b=n%d; 9 | if(d!=0) cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int r,s,p,book; 6 | cin>>r>>s; 7 | cin>>book; 8 | p=r*s; 9 | 10 | if(book>p) cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int tnof,count=0; 6 | cin>>tnof; 7 | while(1) 8 | { 9 | if((tnof-1)%11!=0) 10 | { 11 | tnof=tnof*2; 12 | count++; 13 | } 14 | else 15 | { 16 | break; 17 | } 18 | } 19 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int a,b,cnt=0,j=0; 6 | int arr[50001],ar[50001]; 7 | cin>>a; 8 | for(int i=0;i>arr[i]; 11 | } 12 | for(int i=0;i 2 | using namespace std; 3 | main() 4 | { 5 | int n,x,ans=INT_MAX; 6 | cin>>n; 7 | 8 | int a[n+1]; 9 | for(int i=0;i>a[i]; 10 | 11 | for(int i=0;i>x; 14 | ans=min(ans,x/a[i]); 15 | } 16 | cout< 2 | using namespace std; 3 | main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int n,c; 10 | cin>>n; 11 | vectorb,a; 12 | for(int i=0;i>c;a.pb(c);} 13 | for(int i=0;i>c;b.pb(c);} 14 | sort(a.begin(),a.end()); 15 | sort(b.begin(),b.end()); 16 | int i=0,j=0,ans=0; 17 | while(ib[j]){i++;j++;ans++;} 20 | else if(a[i]<=b[j]){i++;} 21 | } 22 | cout< 2 | using namespace std; 3 | #define io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 4 | #define int long long int 5 | main() 6 | { 7 | io 8 | int t; 9 | cin>>t; 10 | for(int tt=1;tt<=t;tt++) 11 | { 12 | int n; 13 | cin>>n; 14 | string a; 15 | cin>>a; 16 | int h1=n/2,c1=0,c2=0; 17 | int h2=n-h1; 18 | for(int i=0;i 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | ios::sync_with_stdio();cin.tie(0);cout.tie(0); 7 | int t; 8 | cin>>t; 9 | for(int j=1;j<=t;j++) 10 | { 11 | int n,c=0; 12 | cin>>n; 13 | int a[n+100]; 14 | for(int i=0;i>a[i]; 15 | for(int i=1;ia[i-1] && a[i]>a[i+1])c++; 18 | } 19 | cout<<"Case #"< 3 | using namespace std; 4 | main() 5 | { 6 | #define int long long int 7 | int t; 8 | cin>>t; 9 | for(int j=1;j<=t;j++) 10 | { 11 | int n; 12 | cin>>n; 13 | int a[n+1]; 14 | for(int i=0;i>a[i]; 15 | int ans=0,mx=-1; 16 | 17 | for(int i=0;imx && a[i]>a[i+1] && imx)ans++; 21 | mx=max(mx,a[i]); 22 | } 23 | cout<<"Case #"< 2 | using namespace std; 3 | main() 4 | { 5 | int tt; 6 | cin>>tt; 7 | for(int i=1;i<=tt;i++) 8 | { 9 | int n; 10 | cin>>n; 11 | int a[n+1]; 12 | for(int i=0;i>a[i]; 13 | int ans=a[0]-a[1],cnt=0,flag=0,maxi=0; 14 | for(int i=1;i 3 | using namespace std; 4 | #define int long long int 5 | int mod=1000000007; 6 | int *dp={0}; 7 | int sol(int n) 8 | { 9 | if(dp[n]!=0)return dp[n]%mod; 10 | if(n-3>=0)dp[n]=sol(n-1)%mod+sol(n-2)%mod+sol(n-3)%mod; 11 | return dp[n]%mod; 12 | } 13 | main() 14 | { 15 | int t; 16 | cin>>t; 17 | dp=new int[100001]; //Saving memory 18 | while(t--) 19 | { 20 | int n; 21 | cin>>n; 22 | *dp=1; 23 | *(dp+1)=1; 24 | *(dp+2)=2; 25 | cout<1) 12 | { 13 | for(i=9;i>=1;i--) 14 | { 15 | if(N%i==0){N/=i;break;} 16 | } 17 | ans.push_back((char)i+48); 18 | if(i==1){ok=true;break;} 19 | } 20 | sort(ans.begin(),ans.end()); 21 | if(ok)return "-1"; 22 | return ans; 23 | } 24 | }; 25 | 26 | -------------------------------------------------------------------------------- /Hackerrank Problems/Array Manipulation.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 6 | #define int long long int 7 | #define pb push_back 8 | #define mk make_pair 9 | int n,m,b,k,q=INT_MIN,w,c; 10 | cin>>n>>m; 11 | vectora(n+10); 12 | 13 | for(int i=0;i>c>>b>>k; 16 | a[c]+=k; 17 | if(b!=n)a[b+1]-=k; 18 | } 19 | for(int i=2;i<=n;i++){a[i]+=a[i-1];q=max(q,a[i]);} 20 | q=max(q,a[1]); 21 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 6 | #define int long long int 7 | #define pb push_back 8 | #define mk make_pair 9 | int n; 10 | cin>>n; 11 | int a[n+100]; 12 | for(int i=0;i>a[i]; 15 | } 16 | 17 | sort(a,a+n); 18 | 19 | int v=INT_MAX; 20 | //cout< 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 6 | #define int long long int 7 | #define pb push_back 8 | #define mk make_pair 9 | int t,a,b; 10 | cin>>t; 11 | int c=0; 12 | vectorv; 13 | while(t--) 14 | { 15 | 16 | cin>>a; 17 | if(a==1) 18 | { 19 | cin>>b; 20 | v.push_back(b); 21 | } 22 | else if(a==2) 23 | { 24 | c++; 25 | } 26 | else if(a==3) 27 | { 28 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 6 | #define int long long int 7 | #define pb push_back 8 | #define mk make_pair 9 | int n,t,b,m=INT_MAX,c; 10 | cin>>n>>t; 11 | int a[n+10]; 12 | for(int i=0;i>a[i]; 13 | 14 | for(int i=0;i>c>>b; 17 | m=INT_MAX; 18 | for(int j=c;j<=b;j++) 19 | { 20 | m=min(m,a[j]); 21 | } 22 | cout<& nums) 4 | { 5 | int neg=0,z=0; 6 | for(auto x:nums)neg+=(x<0),z+=(x==0); 7 | if(z>0)return 0; 8 | if(!(neg&1))return 1; 9 | return -1; 10 | } 11 | }; 12 | -------------------------------------------------------------------------------- /Leetcode problems(contest)/1911.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | long long maxAlternatingSum(vector& nums) 4 | { 5 | long long int n=nums.size(); 6 | long long int dp[n][2]; 7 | dp[0][0]=0; 8 | dp[0][1]=nums[0]; 9 | for(int i=1;iv; 8 | while(n>0) 9 | { 10 | int k=n%10; 11 | n/=10; 12 | v.push_back(k); 13 | } 14 | sort(v.begin(),v.end()); 15 | 16 | int a,b; 17 | a=v[3]+(v[0]*10); 18 | b=v[2]+(v[1]*10); 19 | return a+b; 20 | } 21 | }; 22 | -------------------------------------------------------------------------------- /Leetcode problems(contest)/2161.cpp: -------------------------------------------------------------------------------- 1 | //https://leetcode.com/problems/partition-array-according-to-given-pivot/ 2 | class Solution { 3 | public: 4 | vector pivotArray(vector& nums, int pivot) 5 | { 6 | vectoraa,bb,cc; 7 | for(auto x: nums) 8 | { 9 | if(xans; 15 | for(auto x: aa)ans.push_back(x); 16 | for(auto x: bb)ans.push_back(x); 17 | for(auto x: cc)ans.push_back(x); 18 | return ans; 19 | 20 | } 21 | }; 22 | -------------------------------------------------------------------------------- /Leetcode problems(contest)/2176.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int countPairs(vector& nums, int k) 4 | { 5 | int sum=0; 6 | int n=nums.size(); 7 | for(int i=0;i sumOfThree(long long num) 4 | { 5 | 6 | vectorv; 7 | if(num%3!=0)return v; 8 | v.push_back((num/3)-1); 9 | v.push_back((num/3)); 10 | v.push_back((num/3)+1); 11 | return v; 12 | } 13 | }; 14 | -------------------------------------------------------------------------------- /My Practice(Algorithms)/Dynamic Programming/LIS/Exponential.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int LIS(int *a, int n) 5 | { 6 | if(n==0)return 1; 7 | int maxi=-1; 8 | for(int i=n-1;i>=0;i--) 9 | { 10 | if(a[i]<=a[n]) 11 | { 12 | int lis=1+LIS(a,i); 13 | maxi=max(maxi,lis); 14 | } 15 | } 16 | return maxi; 17 | } 18 | signed main() 19 | { 20 | int a[] = {1,1,1,1,2,2,3,3,4,6,4}; 21 | int n=sizeof(a)/sizeof(a[0]); 22 | cout< 3 | using namespace std; 4 | 5 | int LIS(int *a, int n) 6 | { 7 | int lis[n]={0}; 8 | lis[0]=1; 9 | for(int i=1;i=0;j--) 12 | { 13 | if(a[j] 2 | using namespace std; 3 | mapvisit; 4 | 5 | int dfs(int s,vectoradj[]) 6 | { 7 | if(visit[s]==0)cout<::iterator i; 10 | for(i=adj[s].begin();i!=adj[s].end();i++) 11 | { 12 | if(visit[*i]==0) 13 | { 14 | dfs(*i,adj); 15 | visit[*i]=1; 16 | } 17 | } 18 | } 19 | 20 | main() 21 | { 22 | int v,e,a,b; 23 | cin>>v>>e; 24 | vectoradj[v+1]; 25 | for(int i=0;i>a>>b; 28 | adj[a].pb(b); 29 | adj[b].pb(a); 30 | } 31 | int select; 32 | cin>>select; 33 | dfs(select,adj); 34 | } 35 | -------------------------------------------------------------------------------- /My Practice(Algorithms)/Linked List implementation.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | struct Node 5 | { 6 | int data; 7 | Node* next; 8 | }*head; 9 | 10 | int addnode(int data) 11 | { 12 | Node* new_node=new Node; 13 | new_node->data=data; 14 | new_node->next=head; 15 | head=new_node; 16 | } 17 | int search(int ele) 18 | { 19 | Node* current=head; 20 | while(current!=NULL) 21 | { 22 | if(current->data==ele){cout<<"found"<next; 24 | } 25 | } 26 | int main() 27 | { 28 | int a[5]; 29 | for(int i=0;i<5;i++){cin>>a[i]; addnode(a[i]);} 30 | search(12); 31 | } 32 | -------------------------------------------------------------------------------- /My Practice(Algorithms)/Prime factorization/O(n).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int prime_factorize(int n) 5 | { 6 | int power=0; 7 | for(int i=2;i<=n;i++) 8 | { 9 | if(n%i==0) 10 | { 11 | power=0; 12 | while(n%i==0) //keep on dividing it with i 13 | { 14 | n/=i; 15 | power++; 16 | } 17 | cout<>n; 27 | prime_factorize(n); 28 | } 29 | -------------------------------------------------------------------------------- /My Practice(Algorithms)/Prime factorization/O(sqrt(n)).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int prime_factorize(int n) 5 | { 6 | int power=0; 7 | for(int i=2;i*i<=n;i++) 8 | { 9 | if(n%i==0) 10 | { 11 | power=0; 12 | while(n%i==0) //keep on dividing it with i 13 | { 14 | n/=i; 15 | power++; 16 | } 17 | cout<1)cout<>n; 28 | prime_factorize(n); 29 | } 30 | -------------------------------------------------------------------------------- /My Practice(Algorithms)/Sieve of eratosthenes/Normal.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int sieve[1000000]={0}; 5 | int perform_sieve(int n) 6 | { 7 | for(int i=2;i<=n;i++) 8 | { 9 | if(sieve[i]==0) 10 | { 11 | for(int j=2*i;j<=n;j+=i) 12 | { 13 | sieve[j]=1; 14 | } 15 | } 16 | } 17 | for(int i=2;i<=n;i++) 18 | { 19 | if(sieve[i]==0)cout<left); 16 | int right=1+dia(root->right); 17 | ans=max(ans,left+right-2); 18 | return max(left,right); 19 | } 20 | int diameterOfBinaryTree(TreeNode* root) 21 | { 22 | if(root==NULL)return 0; 23 | dia(root); 24 | return ans; 25 | } 26 | }; 27 | -------------------------------------------------------------------------------- /Random Problems/Interview Prep/Binary Tree/Easy/Same Tree (100).cpp: -------------------------------------------------------------------------------- 1 | //https://leetcode.com/problems/same-tree/ 2 | /* 3 | Do any traversal simulataneously for both trees, if current nodes' values are not same, then return false. 4 | If one tree reaches NULL, while other isn't, then return false; 5 | otherwise return true 6 | 7 | //Below code is a preorder traversal 8 | */ 9 | class Solution 10 | { 11 | public: 12 | bool isSameTree(TreeNode* p, TreeNode* q) 13 | { 14 | if(p==NULL || q==NULL)return (p==q); 15 | if(p->val!=q->val)return false; 16 | return isSameTree(p->left,q->left) && isSameTree(p->right,q->right); 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /Random Problems/Interview Prep/Graphs/Easy/BFS.cpp: -------------------------------------------------------------------------------- 1 | //https://practice.geeksforgeeks.org/problems/bfs-traversal-of-graph/1/# 2 | class Solution 3 | { 4 | public: 5 | vector bfsOfGraph(int V, vector adj[]) 6 | { 7 | int visited[V]={0}; 8 | vectorbfs; 9 | queueq; 10 | q.push(0); 11 | visited[0]=1; 12 | while(!q.empty()) 13 | { 14 | int node=q.front(); 15 | bfs.push_back(node); 16 | q.pop(); 17 | for(auto x: adj[node]) 18 | { 19 | if(visited[x]==0) 20 | { 21 | q.push(x); 22 | visited[x]=1; 23 | } 24 | } 25 | } 26 | return bfs; 27 | } 28 | }; 29 | -------------------------------------------------------------------------------- /Random Problems/Interview Prep/OOPS/Friend Function.cpp: -------------------------------------------------------------------------------- 1 | 2 | class Rectangle 3 | { 4 | 5 | private: 6 | int length, breadth, area; 7 | public: 8 | int getArea() 9 | { 10 | area=length*breadth; 11 | } 12 | Rectangle(int length,int breadth) 13 | { 14 | (*this).length=length; 15 | this->breadth=breadth; 16 | } 17 | 18 | friend void printArea(Rectangle&); //Declaration of friend function 19 | 20 | }; 21 | 22 | void printArea(Rectangle& rect) //Friend Function 23 | { 24 | cout<<"Area of Rectangle is:"<age; 11 | } 12 | void setAge(int age) 13 | { 14 | this->age=age; 15 | } 16 | }; 17 | 18 | class Male: public Human 19 | { 20 | public: 21 | int skin_color; 22 | void sleep() 23 | { 24 | cout<<"Male is sleeping"<val); 12 | return result; 13 | } 14 | 15 | 16 | }; 17 | signed main() 18 | { 19 | Integer a(5); 20 | Integer b=-a; 21 | /* 22 | minus is used as unary operator to negate the value of a and 23 | assign it to b. 24 | 25 | We can also write above statement as: 26 | Integer b=a.operator-(); 27 | 28 | */ 29 | cout<<"value of a:"< 2 | using namespace std; 3 | #define int long long int 4 | #define pb push_back 5 | 6 | int solve(int n,unordered_map&dp) 7 | { 8 | if(n==0)return 0; 9 | if(dp.count(n)){return dp[n];} 10 | return dp[n]=max(solve(n/2,dp)+solve(n/3,dp)+solve(n/4,dp),n); 11 | } 12 | main() 13 | { 14 | int n; 15 | while(cin>>n) 16 | { 17 | unordered_mapdp; 18 | int ans=solve(n,dp); 19 | cout<& nums) 5 | { 6 | long long int n=nums.size(); 7 | long long int dp[n][2]; 8 | dp[0][0]=0; 9 | dp[0][1]=nums[0]; 10 | for(int i=1;i 2 | using namespace std; 3 | #define int long long int 4 | #define pb push_back 5 | 6 | main() 7 | { 8 | int n,q; 9 | cin>>n; 10 | int a[n],prefix[n],sum=0; 11 | for(int i=0;i>a[i]; 14 | sum+=a[i]; 15 | prefix[i]=sum; 16 | } 17 | cin>>q; 18 | for(int i=0;i>a>>b; 22 | if(a==0){cout< 3 | using namespace std; 4 | #define int long long int 5 | main() 6 | { 7 | int t; 8 | cin>>t; 9 | while(t--) 10 | { 11 | int n,sum=0; 12 | cin>>n; 13 | int a[n],prefix[n],ans[n]; 14 | for(int i=0;i>a[i]; 17 | if(a[i]<0)a[i]=(prefix[i-1])/(i); 18 | sum+=a[i]; 19 | prefix[i]=sum; 20 | cout< 3 | using namespace std; 4 | #define int long long int 5 | signed main() 6 | { 7 | int n,k; 8 | cin>>n>>k; 9 | int sum=0; 10 | int a[n+1]; 11 | for(int i=0;i>a[i]; 14 | if(isum) 22 | { 23 | mini=sum; 24 | ans=(i-k+1); 25 | } 26 | } 27 | cout<