├── 39 └── 39J-J-SpellingCheck.cpp ├── 40 ├── 40A-A-FindColor.cpp └── 40D-D-InterestingSequence.cpp ├── 112 ├── 112B-B-PetyaandSquare.cpp ├── 112C-C-PetyaandInequiations.cpp └── 112A-A-PetyaandStrings.cpp ├── 158 ├── 158A-A-NextRound.cpp ├── 158B-B-Taxi.cpp ├── 158D-D-IceSculptures.cpp └── 158E-E-PhoneTalks.cpp ├── 235 └── 235A-A-LCMChallenge.cpp ├── 236 ├── 236A-A-BoyorGirl.cpp └── 236B-B-EasyNumberChallenge.cpp ├── 280 └── 280B-B-MaximumXorSecondary.cpp ├── 281 ├── 281A-A-WordCapitalization.cpp └── 281B-B-NearestFraction.cpp ├── 282 ├── 282C-C-XORandOR.cpp └── 282B-B-PaintingEggs.cpp ├── 339 └── 339A-A-HelpfulMaths.cpp ├── 378 ├── 378A-A-PlayingwithDice.cpp └── 378B-B-Semifinals.cpp ├── 488 └── 488A-A-GigaTower.cpp ├── 492 ├── 492A-A-VanyaandCubes.cpp ├── 492B-B-VanyaandLanterns.cpp └── 492D-D-VanyaandComputerGame.cpp ├── 493 ├── 493D-D-VasyaandChess.cpp ├── 493A-A-VasyaandFootball.cpp └── 493B-B-VasyaandWrestling.cpp ├── 495 ├── 495A-A-DigitalCounter.cpp └── 495B-B-ModularEquations.cpp ├── 496 ├── 496A-A-MinimumDifficulty.cpp └── 496B-B-SecretCombination.cpp ├── 498 └── 498A-A-CrazyTown.cpp ├── 499 ├── 499A-A-Watchingamovie.cpp └── 499B-B-Lecture.cpp ├── 500 └── 500A-A-NewYearTransportation.cpp ├── 501 ├── 501A-A-Contest.cpp └── 501B-B-MishaandChangingHandles.cpp ├── 598 └── 598A-A-TrickySum.cpp ├── 600 └── 600B-B-Queriesaboutlessorequalelements.cpp ├── 609 └── 609C-C-LoadBalancing.cpp ├── 612 └── 612A-A-TheTextSplitting.cpp ├── 641 └── 641A-A-LittleArtemandGrasshopper.cpp ├── 669 └── 669A-A-LittleArtemandPresents.cpp ├── 702 ├── 702D-D-RoadtoPostOffice.cpp └── 702B-B-PowersofTwo.cpp ├── 706 └── 706A-A-Beru-taxi.cpp ├── 707 ├── 707A-A-Brain'sPhotos.cpp └── 707C-C-PythagoreanTriples.cpp ├── 708 └── 708A-A-LettersCyclicShift.cpp ├── 709 ├── 709A-A-Juicer.cpp └── 709B-B-Checkpoints.cpp ├── 710 ├── 710B-B-OptimalPointonaLine.cpp ├── 710A-A-KingMoves.cpp └── 710C-C-MagicOddSquare.cpp ├── 712 ├── 712C-C-MemoryandDe-Evolution.cpp ├── 712A-A-MemoryandCrow.cpp └── 712B-B-MemoryandTrident.cpp ├── 714 ├── 714A-A-MeetingofOldFriends.cpp └── 714B-B-FilyaandHomework.cpp ├── 715 └── 715A-A-PlusandSquareRoot.cpp ├── 716 └── 716A-A-CrazyComputer.cpp ├── 717 └── 717C-C-PotionsHomework.cpp ├── 724 └── 724E-E-Goodstransportation.cpp ├── 725 ├── 725A-A-JumpingBall.cpp └── 725B-B-FoodonthePlane.cpp ├── 765 ├── 765A-A-Neverendingcompetitions.cpp ├── 765C-C-TableTennisGame2.cpp └── 765B-B-Codeobfuscation.cpp ├── 793 └── 793A-A-Olegandshares.cpp ├── 800 └── 800B-B-VolatileKite.cpp ├── 801 ├── 801B-B-ValuedKeys.cpp └── 801A-A-ViciousKeyboard.cpp ├── 827 └── 827B-B-HighLoad.cpp ├── 1085 ├── 1085B-B-DivTimesMod.cpp ├── 1085A-A-Right-LeftCipher.cpp └── 1085D-D-MinimumDiameterTree.cpp ├── 1091 ├── 1091A-A-NewYearandtheChristmasOrnament.cpp ├── 1091B-B-NewYearandtheTreasureGeolocation.cpp ├── 1091C-C-NewYearandtheSphereTransmission.cpp └── 1091G-G-NewYearandtheFactorisationCollaboration.cpp ├── 1096 ├── 1096A-A-FindDivisible.cpp └── 1096C-C-PolygonfortheAngle.cpp ├── 1470 └── 1470A-A-StrangeBirthdayParty.cpp ├── 1472 ├── 1472A-A-CardsforFriends.cpp ├── 1472C-C-LongJumps.cpp └── 1472B-B-FairDivision.cpp ├── 1473 └── 1473A-A-ReplacingElements.cpp ├── 1479 └── 1479A-A-SearchingLocalMinimum.cpp ├── 1485 ├── 1485C-C-FloorandMod.cpp ├── 1485B-B-ReplaceandKeepSorted.cpp ├── 1485D-D-MultiplesandPowerDifferences.cpp └── 1485A-A-AddandDivide.cpp ├── 1491 ├── 1491A-A-K-thLargestValue.cpp └── 1491B-B-MinimalCost.cpp ├── 1503 └── 1503C-C-TravellingSalesmanProblem.cpp ├── 1504 └── 1504A-A-DéjàVu.cpp ├── 1505 ├── 1505B-B-DMCA.cpp ├── 1505A-A-Isitrated-2.cpp └── 1505C-C-FibonacciWords.cpp ├── 1511 ├── 1511A-A-ReviewSite.cpp ├── 1511B-B-GCDLength.cpp ├── 1511D-D-MinCostString.cpp └── 1511C-C-YetAnotherCardDeck.cpp ├── 1515 └── 1515B-B-PhoenixandPuzzle.cpp ├── 1517 └── 1517A-A-Sumof2050.cpp ├── 1519 ├── 1519B-B-TheCakeIsaLie.cpp └── 1519A-A-RedandBlueBeans.cpp ├── 1520 └── 1520E-E-ArrangingTheSheep.cpp ├── 1525 ├── 1525A-A-Potion-making.cpp └── 1525B-B-PermutationSort.cpp ├── 1530 └── 1530A-A-BinaryDecimal.cpp ├── 1533 └── 1533A-A-TraveltoBertown.cpp ├── 1539 ├── 1539A-A-ContestStart.cpp ├── 1539B-B-LoveSong.cpp └── 1539C-C-StableGroups.cpp ├── 1542 ├── 1542C-C-StrangeFunction.cpp └── 1542B-B-PlusandMultiply.cpp ├── 1543 ├── 1543A-A-ExcitingBets.cpp └── 1543B-B-CustomisingtheTrack.cpp ├── 1550 ├── 1550A-A-FindTheArray.cpp └── 1550B-B-MaximumCostDeletion.cpp ├── 1555 ├── 1555A-A-PizzaForces.cpp └── 1555C-C-CoinRows.cpp ├── 1574 ├── 1574A-A-RegularBracketSequences.cpp └── 1574B-B-CombinatoricsHomework.cpp ├── 1606 ├── 1606A-A-ABBalance.cpp ├── 1606B-B-UpdateFiles.cpp └── 1606C-C-Banknotes.cpp ├── 1615 ├── 1615A-A-ClosingTheGap.cpp └── 1615B-B-AndIt'sNon-Zero.cpp ├── 1616 ├── 1616A-A-IntegerDiversity.cpp └── 1616B-B-MirrorintheString.cpp ├── 1617 └── 1617B-B-GCDProblem.cpp ├── 1618 ├── 1618A-A-PolycarpandSumsofSubsequences.cpp └── 1618D-D-ArrayandOperations.cpp ├── 1619 └── 1619B-B-SquaresandCubes.cpp ├── 1621 └── 1621A-A-StableArrangementofRooks.cpp ├── 1622 └── 1622A-A-ConstructaRectangle.cpp ├── 1623 ├── 1623A-A-RobotCleaner.cpp └── 1623B-B-GameonRanges.cpp ├── 1624 └── 1624A-A-PlusOneontheSubset.cpp ├── 1635 └── 1635A-A-MinOrSum.cpp ├── 1638 ├── 1638B-B-OddSwapSort.cpp └── 1638C-C-InversionGraph.cpp ├── 1641 └── 1641A-A-GreatSequence.cpp ├── 1644 ├── 1644B-B-Anti-FibonacciPermutation.cpp └── 1644A-A-DoorsandKeys.cpp ├── 1646 └── 1646A-A-SquareCounting.cpp ├── 1670 └── 1670D-D-VerySuspicious.cpp ├── 1674 ├── 1674B-B-Dictionary.cpp ├── 1674C-C-InfiniteReplacement.cpp ├── 1674D-D-A-B-CSort.cpp ├── 1674E-E-BreakingtheWall.cpp └── 1674A-A-NumberTransformation.cpp ├── 1675 ├── 1675A-A-FoodforAnimals.cpp ├── 1675B-B-MakeItIncreasing.cpp └── 1675C-C-DetectiveTask.cpp ├── 1676 ├── 1676A-A-Lucky?.cpp ├── 1676B-B-EqualCandies.cpp └── 1676G-G-White-BlackBalancedSubtrees.cpp ├── 1679 └── 1679A-A-AvtoBus.cpp ├── 1680 ├── 1680A-A-MinimumsandMaximums.cpp ├── 1680B-B-Robots.cpp └── 1680C-C-BinaryString.cpp ├── 1682 ├── 1682A-A-PalindromicIndices.cpp ├── 1682B-B-ANDSorting.cpp └── 1682C-C-LISorReverseLIS?.cpp ├── 1684 ├── 1684B-B-ZmodX=C.cpp ├── 1684A-A-DigitMinimization.cpp └── 1684D-D-Traps.cpp ├── 1686 └── 1686A-A-EverythingEverywhereAllButOne.cpp ├── 1692 ├── 1692A-A-Marathon.cpp ├── 1692B-B-AllDistinct.cpp └── 1692G-G-2^Sort.cpp ├── 1694 ├── 1694A-A-Creep.cpp └── 1694B-B-ParanoidString.cpp ├── 1696 └── 1696A-A-NITorz!.cpp ├── 1697 ├── 1697A-A-ParkwayWalk.cpp └── 1697B-B-Promo.cpp ├── 1698 ├── 1698A-A-XORMixup.cpp └── 1698B-B-RisingSand.cpp ├── 1700 ├── 1700A-A-OptimalPath.cpp └── 1700C-C-HelpingtheNature.cpp ├── 1719 └── 1719A-A-ChipGame.cpp ├── 1726 └── 1726C-C-Jatayu'sBalancedBracketSequence.cpp ├── 1728 ├── 1728A-A-ColoredBalls:Revisited.cpp └── 1728B-B-BestPermutation.cpp ├── 1729 ├── 1729A-A-TwoElevators.cpp ├── 1729E-E-GuesstheCycleSize.cpp └── 1729B-B-DecodeString.cpp ├── 1730 ├── 1730A-A-Planets.cpp └── 1730B-B-MeetingontheLine.cpp ├── 1733 ├── 1733A-A-ConsecutiveSum.cpp └── 1733B-B-RuleofLeague.cpp ├── 1734 ├── 1734B-B-Bright,Nice,Brilliant.cpp ├── 1734E-E-RectangularCongruence.cpp ├── 1734A-A-SelectThreeSticks.cpp └── 1734C-C-RemovingSmallestMultiples.cpp ├── 1735 ├── 1735A-A-WorkingWeek.cpp └── 1735B-B-TeawithTangerines.cpp ├── 1736 ├── 1736A-A-MakeAEqualtoB.cpp └── 1736B-B-PlayingwithGCD.cpp ├── 1739 ├── 1739A-A-ImmobileKnight.cpp └── 1739B-B-ArrayRecovery.cpp ├── 1741 ├── 1741B-B-FunnyPermutation.cpp └── 1741A-A-CompareT-ShirtSizes.cpp ├── 1742 ├── 1742A-A-Sum.cpp ├── 1742B-B-Increasing.cpp ├── 1742D-D-Coprime.cpp └── 1742E-E-Scuza.cpp ├── 1743 ├── 1743B-B-PermutationValue.cpp └── 1743A-A-Password.cpp ├── 1744 ├── 1744A-A-NumberReplacement.cpp └── 1744C-C-TrafficLight.cpp ├── 1746 ├── 1746A-A-Maxmina.cpp ├── 1746B-B-Rebellion.cpp └── 1746C-C-PermutationOperations.cpp ├── 1806 ├── 1806A-A-WalkingMaster.cpp └── 1806B-B-MexMaster.cpp ├── 1807 ├── 1807C-C-FindandReplace.cpp └── 1807D-D-OddQueries.cpp ├── 1809 └── 1809A-A-Garland.cpp ├── 1812 ├── 1812J-J-UnmysteriousLanguage.cpp ├── 1812E-E-NotaGeometryProblem.cpp └── 1812B-B-WasitRated?.cpp ├── 1817 └── 1817D-D-ToyMachine.cpp ├── 1818 ├── 1818A-A-Politics.cpp └── 1818B-B-Indivisible.cpp ├── 1820 └── 1820A-A-Yura'sNewName.cpp ├── 1821 └── 1821A-A-Matching.cpp ├── 1822 ├── 1822C-C-BunLover.cpp ├── 1822D-D-Super-Permutation.cpp └── 1822A-A-TubeTubeFeed.cpp ├── 1823 ├── 1823B-B-SortwithStep.cpp └── 1823A-A-A-characteristic.cpp ├── test ├── error ├── cuiaoxiang ├── 1663 │ └── 1663A-A-WhoTested?.cpp └── parse.py ├── parse.py ├── 1807G ├── 1807G1-G1-SubsequenceAddition(EasyVersion).cpp └── 1807G2-G2-SubsequenceAddition(HardVersion).cpp └── 1736C └── 1736C1-C1-GoodSubarrays(EasyVersion).cpp /test: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /error: -------------------------------------------------------------------------------- 1 | nohup: ignoring input and appending output to 'nohup.out' 2 | -------------------------------------------------------------------------------- /cuiaoxiang/1663/1663A-A-WhoTested?.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1663/problem/A 2 | // time:2022-04-01 17:41:14 3 | // name:A-WhoTested? 4 | 5 | BucketPotato 6 | 7 | -------------------------------------------------------------------------------- /1812/1812J-J-UnmysteriousLanguage.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1812/problem/J 2 | // time:2023-04-01 18:07:58 3 | // name:J-UnmysteriousLanguage 4 | 5 | can you give me AC please? 6 | -------------------------------------------------------------------------------- /339/339A-A-HelpfulMaths.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/339/problem/A 2 | // time:2023-04-28 12:54:08 3 | // name:A-HelpfulMaths 4 | 5 | a = list(map(int, input().split('+'))) 6 | a.sort() 7 | print('+'.join(map(str, a))) 8 | -------------------------------------------------------------------------------- /1812/1812E-E-NotaGeometryProblem.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1812/problem/E 2 | // time:2023-04-01 18:03:54 3 | // name:E-NotaGeometryProblem 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | std::cout << 0 << "\n"; 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /495/495A-A-DigitalCounter.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/495/problem/A 2 | // time:2021-06-21 19:14:20 3 | // name:A-DigitalCounter 4 | 5 | #include 6 | constexpr int A[] = {2, 7, 2, 3, 3, 4, 2, 5, 1, 2}; 7 | int main() { 8 | std::ios::sync_with_stdio(false); 9 | std::cin.tie(nullptr); 10 | int n; 11 | std::cin >> n; 12 | std::cout << A[n / 10] * A[n % 10] << "\n"; 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /1505/1505B-B-DMCA.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1505/problem/B 2 | // time:2021-04-01 18:07:57 3 | // name:B-DMCA 4 | 5 | #include 6 | using i64 = int64_t; 7 | using u64 = uint64_t; 8 | using u32 = uint32_t; 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | int a; 13 | std::cin >> a; 14 | std::cout << (a - 1) % 9 + 1 << "\n"; 15 | return 0; 16 | } 17 | 18 | -------------------------------------------------------------------------------- /669/669A-A-LittleArtemandPresents.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/669/problem/A 2 | //time:2021-07-09 23:29:12 3 | //name:A-LittleArtemandPresents 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | int n; 14 | std::cin >> n; 15 | 16 | std::cout << (n / 3 * 2 + (n % 3 > 0)) << "\n"; 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /1505/1505A-A-Isitrated-2.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1505/problem/A 2 | //time:2021-04-01 18:03:08 3 | //name:A-Isitrated-2 4 | 5 | #include 6 | using i64 = int64_t; 7 | using u64 = uint64_t; 8 | using u32 = uint32_t; 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | std::string s; 13 | while (std::cin >> s) { 14 | std::cout << "NO" << std::endl; 15 | } 16 | return 0; 17 | } 18 | 19 | -------------------------------------------------------------------------------- /39/39J-J-SpellingCheck.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/39/problem/J 2 | // time:2023-04-20 14:31:52 3 | // name:J-SpellingCheck 4 | 5 | a = input() 6 | b = input() 7 | 8 | i = 0 9 | while i < len(b) and a[i] == b[i] : 10 | i += 1 11 | 12 | c = a[:i]+a[i+1:] 13 | if b != c : 14 | print(0) 15 | exit() 16 | 17 | j = i 18 | while j and a[j - 1] == a[j] : 19 | j -= 1 20 | ans = list(range(j + 1, i + 2)) 21 | print(len(ans)) 22 | print(' '.join(map(str, ans))) 23 | -------------------------------------------------------------------------------- /493/493D-D-VasyaandChess.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/493/problem/D 2 | // time:2021-06-21 20:06:43 3 | // name:D-VasyaandChess 4 | 5 | #include 6 | int main() { 7 | std::ios::sync_with_stdio(false); 8 | std::cin.tie(nullptr); 9 | int n; 10 | std::cin >> n; 11 | if (n % 2 == 0) { 12 | std::cout << "white\n"; 13 | std::cout << "1 2\n"; 14 | } else { 15 | std::cout << "black\n"; 16 | } 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /1091/1091A-A-NewYearandtheChristmasOrnament.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1091/problem/A 2 | //time:2021-07-15 21:14:28 3 | //name:A-NewYearandtheChristmasOrnament 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | int y, b, r; 14 | std::cin >> y >> b >> r; 15 | 16 | std::cout << std::min({y, b - 1, r - 2}) * 3 + 3 << "\n"; 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /492/492A-A-VanyaandCubes.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/492/problem/A 2 | // time:2021-06-24 18:47:49 3 | // name:A-VanyaandCubes 4 | 5 | #include 6 | using i64 = long long; 7 | int main() { 8 | std::ios::sync_with_stdio(false); 9 | std::cin.tie(nullptr); 10 | int n; 11 | std::cin >> n; 12 | int d = 0; 13 | int s = 0; 14 | while (s + (d + 1) * (d + 2) / 2 <= n) { 15 | d++; 16 | s += d * (d + 1) / 2; 17 | } 18 | std::cout << d << "\n"; 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /1096/1096A-A-FindDivisible.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1096/problem/A 2 | //time:2021-07-15 20:32:20 3 | //name:A-FindDivisible 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | int t; 14 | std::cin >> t; 15 | while (t--) { 16 | int l, r; 17 | std::cin >> l >> r; 18 | 19 | std::cout << l << " " << 2 * l << "\n"; 20 | } 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /1812/1812B-B-WasitRated?.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1812/problem/B 2 | // time:2023-04-01 17:52:19 3 | // name:B-WasitRated? 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | int n; 14 | std::cin >> n; 15 | 16 | if (n == 15 || n == 20 || n == 21) { 17 | std::cout << "NO\n"; 18 | } else { 19 | std::cout << "YES\n"; 20 | } 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /281/281A-A-WordCapitalization.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/281/problem/A 2 | // time:2023-04-28 20:35:59 3 | // name:A-WordCapitalization 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | std::string s; 14 | std::cin >> s; 15 | 16 | if (std::islower(s[0])) { 17 | s[0] = std::toupper(s[0]); 18 | } 19 | 20 | std::cout << s << "\n"; 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /715/715A-A-PlusandSquareRoot.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/715/problem/A 2 | // time:2021-07-07 11:06:44 3 | // name:A-PlusandSquareRoot 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | int n; 14 | std::cin >> n; 15 | 16 | for (int i = 1; i <= n; i++) { 17 | std::cout << i64(i) * (i + 1) * (i + 1) - i + 1 - (i == 1 ? 2 : 0) << "\n"; 18 | } 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /765/765A-A-Neverendingcompetitions.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/765/problem/A 2 | //time:2021-07-12 14:47:05 3 | //name:A-Neverendingcompetitions 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | int n; 14 | std::cin >> n; 15 | 16 | if (n % 2 == 1) { 17 | std::cout << "contest\n"; 18 | } else { 19 | std::cout << "home\n"; 20 | } 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /236/236A-A-BoyorGirl.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/236/problem/A 2 | // time:2023-04-30 11:28:56 3 | // name:A-BoyorGirl 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | std::string s; 14 | std::cin >> s; 15 | 16 | if (std::set(s.begin(), s.end()).size() % 2) { 17 | std::cout << "IGNORE HIM!\n"; 18 | } else { 19 | std::cout << "CHAT WITH HER!\n"; 20 | } 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /112/112B-B-PetyaandSquare.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/112/problem/B 2 | // time:2023-04-27 10:26:58 3 | // name:B-PetyaandSquare 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | int n, x, y; 14 | std::cin >> n >> x >> y; 15 | 16 | if ((x == n/2 || x == n/2+1) && (y == n/2 || y == n/2+1)) { 17 | std::cout << "NO\n"; 18 | } else { 19 | std::cout << "YES\n"; 20 | } 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /1735/1735A-A-WorkingWeek.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1735/problem/A 2 | //time:2022-10-04 11:40:25 3 | //name:A-WorkingWeek 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | std::cout << (n - 6) / 3 << "\n"; 14 | } 15 | 16 | int main() { 17 | std::ios::sync_with_stdio(false); 18 | std::cin.tie(nullptr); 19 | 20 | int t; 21 | std::cin >> t; 22 | 23 | while (t--) { 24 | solve(); 25 | } 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /282/282C-C-XORandOR.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/282/problem/C 2 | // time:2023-04-27 08:52:58 3 | // name:C-XORandOR 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | std::string a, b; 14 | std::cin >> a >> b; 15 | 16 | if (a.size() == b.size() && (a.find('1') != -1) == (b.find('1') != -1)) { 17 | std::cout << "YES\n"; 18 | } else { 19 | std::cout << "NO\n"; 20 | } 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /1822/1822C-C-BunLover.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1822/problem/C 2 | // time:2023-04-25 15:32:56 3 | // name:C-BunLover 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | std::cout << 1LL * n * n + n * 2 + 2 << "\n"; 14 | } 15 | 16 | int main() { 17 | std::ios::sync_with_stdio(false); 18 | std::cin.tie(nullptr); 19 | 20 | int t; 21 | std::cin >> t; 22 | 23 | while (t--) { 24 | solve(); 25 | } 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /1525/1525A-A-Potion-making.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1525/problem/A 2 | // time:2022-03-01 14:29:07 3 | // name:A-Potion-making 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int k; 11 | std::cin >> k; 12 | 13 | std::cout << 100 / std::gcd(100, k) << "\n"; 14 | } 15 | 16 | int main() { 17 | std::ios::sync_with_stdio(false); 18 | std::cin.tie(nullptr); 19 | 20 | int t; 21 | std::cin >> t; 22 | 23 | while (t--) { 24 | solve(); 25 | } 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /488/488A-A-GigaTower.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/488/problem/A 2 | // time:2021-06-24 22:02:01 3 | // name:A-GigaTower 4 | 5 | #include 6 | using i64 = long long; 7 | bool check(int a) { 8 | auto s = std::to_string(a); 9 | return s.find('8') != -1; 10 | } 11 | int main() { 12 | std::ios::sync_with_stdio(false); 13 | std::cin.tie(nullptr); 14 | int a; 15 | std::cin >> a; 16 | int b = 1; 17 | a++; 18 | while (!check(a)) { 19 | a++; 20 | b++; 21 | } 22 | std::cout << b << "\n"; 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /1550/1550A-A-FindTheArray.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1550/problem/A 2 | //time:2021-07-14 17:36:27 3 | //name:A-FindTheArray 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | int t; 14 | std::cin >> t; 15 | while (t--) { 16 | int s; 17 | std::cin >> s; 18 | 19 | int x = 1; 20 | while (x * x < s) { 21 | x++; 22 | } 23 | 24 | std::cout << x << "\n"; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /1646/1646A-A-SquareCounting.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1646/problem/A 2 | // time:2022-03-04 19:43:40 3 | // name:A-SquareCounting 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | i64 s; 12 | std::cin >> n >> s; 13 | 14 | std::cout << s / n / n << "\n"; 15 | } 16 | 17 | int main() { 18 | std::ios::sync_with_stdio(false); 19 | std::cin.tie(nullptr); 20 | 21 | int t; 22 | std::cin >> t; 23 | 24 | while (t--) { 25 | solve(); 26 | } 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /1530/1530A-A-BinaryDecimal.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1530/problem/A 2 | //time:2021-07-17 17:36:22 3 | //name:A-BinaryDecimal 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | int t; 14 | std::cin >> t; 15 | while (t--) { 16 | int n; 17 | std::cin >> n; 18 | 19 | auto s = std::to_string(n); 20 | 21 | std::cout << (*std::max_element(s.begin(), s.end()) - '0') << "\n"; 22 | } 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /1692/1692A-A-Marathon.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1692/problem/A 2 | //time:2022-06-14 17:36:16 3 | //name:A-Marathon 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int a, b, c, d; 11 | std::cin >> a >> b >> c >> d; 12 | 13 | std::cout << (b > a) + (c > a) + (d > a) << "\n"; 14 | } 15 | 16 | int main() { 17 | std::ios::sync_with_stdio(false); 18 | std::cin.tie(nullptr); 19 | 20 | int t; 21 | std::cin >> t; 22 | 23 | while (t--) { 24 | solve(); 25 | } 26 | 27 | return 0; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /500/500A-A-NewYearTransportation.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/500/problem/A 2 | // time:2021-06-22 11:14:44 3 | // name:A-NewYearTransportation 4 | 5 | #include 6 | int main() { 7 | std::ios::sync_with_stdio(false); 8 | std::cin.tie(nullptr); 9 | int n, t; 10 | std::cin >> n >> t; 11 | t--; 12 | std::vector a(n - 1); 13 | for (int i = 0; i < n - 1; i++) { 14 | std::cin >> a[i]; 15 | } 16 | int u = 0; 17 | while (u < t) { 18 | u += a[u]; 19 | } 20 | std::cout << (u == t ? "YES" : "NO") << "\n"; 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /499/499A-A-Watchingamovie.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/499/problem/A 2 | // time:2021-06-21 22:20:12 3 | // name:A-Watchingamovie 4 | 5 | #include 6 | int main() { 7 | std::ios::sync_with_stdio(false); 8 | std::cin.tie(nullptr); 9 | int n, x; 10 | std::cin >> n >> x; 11 | int last = 0; 12 | int ans = 0; 13 | for (int i = 0; i < n; i++) { 14 | int l, r; 15 | std::cin >> l >> r; 16 | l--; 17 | ans += r - l; 18 | ans += (l - last) % x; 19 | last = r; 20 | } 21 | std::cout << ans << "\n"; 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /1606/1606A-A-ABBalance.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1606/problem/A 2 | //time:2022-06-09 16:56:34 3 | //name:A-ABBalance 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | std::string s; 11 | std::cin >> s; 12 | if (s[0] != s.back()) { 13 | s[0] = s.back(); 14 | } 15 | std::cout << s << "\n"; 16 | } 17 | 18 | int main() { 19 | std::ios::sync_with_stdio(false); 20 | std::cin.tie(nullptr); 21 | 22 | int t; 23 | std::cin >> t; 24 | 25 | while (t--) { 26 | solve(); 27 | } 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /1555/1555A-A-PizzaForces.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1555/problem/A 2 | //time:2022-06-12 10:17:59 3 | //name:A-PizzaForces 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | i64 n; 11 | std::cin >> n; 12 | 13 | i64 slice = std::max(3LL, (n + 1) / 2); 14 | 15 | std::cout << 5 * slice << "\n"; 16 | } 17 | 18 | int main() { 19 | std::ios::sync_with_stdio(false); 20 | std::cin.tie(nullptr); 21 | 22 | int t; 23 | std::cin >> t; 24 | 25 | while (t--) { 26 | solve(); 27 | } 28 | 29 | return 0; 30 | } 31 | 32 | -------------------------------------------------------------------------------- /714/714A-A-MeetingofOldFriends.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/714/problem/A 2 | // time:2021-07-07 17:11:12 3 | // name:A-MeetingofOldFriends 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | i64 l1, r1, l2, r2, k; 14 | std::cin >> l1 >> r1 >> l2 >> r2 >> k; 15 | 16 | i64 ans = 0; 17 | ans += std::max(0LL, std::min(r1, r2) - std::max(l1, l2) + 1); 18 | ans -= (l1 <= k && k <= r1 && l2 <= k && k <= r2); 19 | 20 | std::cout << ans << "\n"; 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /801/801B-B-ValuedKeys.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/801/problem/B 2 | //time:2021-01-03 17:21:41 3 | //name:B-ValuedKeys 4 | 5 | #include 6 | using i64 = long long; 7 | using u64 = unsigned long long; 8 | using u32 = unsigned; 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | std::string x, y; 13 | std::cin >> x >> y; 14 | int n = x.length(); 15 | for (int i = 0; i < n; i++) { 16 | if (x[i] < y[i]) { 17 | std::cout << "-1\n"; 18 | return 0; 19 | } 20 | } 21 | std::cout << y << "\n"; 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /1729/1729A-A-TwoElevators.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1729/problem/A 2 | //time:2022-09-12 17:36:39 3 | //name:A-TwoElevators 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int a, b, c; 11 | std::cin >> a >> b >> c; 12 | a--; 13 | b = std::abs(b - c) + c - 1; 14 | std::cout << (a < b ? 1 : a > b ? 2 : 3) << "\n"; 15 | } 16 | 17 | int main() { 18 | std::ios::sync_with_stdio(false); 19 | std::cin.tie(nullptr); 20 | 21 | int t; 22 | std::cin >> t; 23 | 24 | while (t--) { 25 | solve(); 26 | } 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /1700/1700A-A-OptimalPath.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1700/problem/A 2 | //time:2022-06-19 12:06:25 3 | //name:A-OptimalPath 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n, m; 11 | std::cin >> n >> m; 12 | 13 | i64 ans = 1LL * m * (m + 1) / 2 + 1LL * m * n * (n + 1) / 2 - m; 14 | std::cout << ans << "\n"; 15 | } 16 | 17 | int main() { 18 | std::ios::sync_with_stdio(false); 19 | std::cin.tie(nullptr); 20 | 21 | int t; 22 | std::cin >> t; 23 | 24 | while (t--) { 25 | solve(); 26 | } 27 | 28 | return 0; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /710/710B-B-OptimalPointonaLine.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/710/problem/B 2 | // time:2021-07-07 22:05:50 3 | // name:B-OptimalPointonaLine 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | int n; 14 | std::cin >> n; 15 | 16 | std::vector x(n); 17 | for (int i = 0; i < n; i++) { 18 | std::cin >> x[i]; 19 | } 20 | 21 | int m = (n - 1) / 2; 22 | std::nth_element(x.begin(), x.begin() + m, x.end()); 23 | std::cout << x[m] << "\n"; 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /1505/1505C-C-FibonacciWords.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1505/problem/C 2 | //time:2021-04-01 18:12:13 3 | //name:C-FibonacciWords 4 | 5 | #include 6 | using i64 = int64_t; 7 | using u64 = uint64_t; 8 | using u32 = uint32_t; 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | std::string s; 13 | std::cin >> s; 14 | for (int i = 2; i < int(s.length()); i++) { 15 | if ((s[i] - 'A') != (s[i - 1] - 'A' + s[i - 2] - 'A') % 26) { 16 | std::cout << "NO\n"; 17 | return 0; 18 | } 19 | } 20 | std::cout << "YES\n"; 21 | return 0; 22 | } 23 | 24 | -------------------------------------------------------------------------------- /1542/1542C-C-StrangeFunction.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1542/problem/C 2 | // time:2021-07-03 16:14:00 3 | // name:C-StrangeFunction 4 | 5 | #include 6 | using i64 = long long; 7 | constexpr int P = 1000000007; 8 | int main() { 9 | std::ios::sync_with_stdio(false); 10 | std::cin.tie(nullptr); 11 | int t; 12 | std::cin >> t; 13 | while (t--) { 14 | i64 n; 15 | std::cin >> n; 16 | int ans = 0; 17 | for (i64 x = 1, i = 1; x <= n; x = std::lcm(i, x), i++) { 18 | ans = (ans + n / x) % P; 19 | } 20 | std::cout << ans << "\n"; 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /1674/1674B-B-Dictionary.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1674/problem/B 2 | // time:2022-05-02 17:43:50 3 | // name:B-Dictionary 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | std::string s; 11 | std::cin >> s; 12 | 13 | int a = s[0] - 'a'; 14 | int b = s[1] - 'a'; 15 | 16 | std::cout << a * 25 + b - (b > a) + 1 << "\n"; 17 | } 18 | 19 | int main() { 20 | std::ios::sync_with_stdio(false); 21 | std::cin.tie(nullptr); 22 | 23 | int t; 24 | std::cin >> t; 25 | 26 | while (t--) { 27 | solve(); 28 | } 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /501/501A-A-Contest.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/501/problem/A 2 | // time:2021-06-24 16:17:04 3 | // name:A-Contest 4 | 5 | #include 6 | using i64 = long long; 7 | int main() { 8 | std::ios::sync_with_stdio(false); 9 | std::cin.tie(nullptr); 10 | int a, b, c, d; 11 | std::cin >> a >> b >> c >> d; 12 | int s1 = std::max(3 * a / 10, a - a / 250 * c); 13 | int s2 = std::max(3 * b / 10, b - b / 250 * d); 14 | if (s1 > s2) { 15 | std::cout << "Misha\n"; 16 | } else if (s1 < s2) { 17 | std::cout << "Vasya\n"; 18 | } else { 19 | std::cout << "Tie\n"; 20 | } 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /1085/1085B-B-DivTimesMod.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1085/problem/B 2 | //time:2021-07-15 11:19:20 3 | //name:B-DivTimesMod 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | int n, k; 14 | 15 | std::cin >> n >> k; 16 | 17 | int x = 1e9; 18 | 19 | for (int y = 1; y < k; y++) { 20 | if (n % y != 0) { 21 | continue; 22 | } 23 | 24 | x = std::min(x, n / y * k + y); 25 | } 26 | 27 | std::cout << x << "\n"; 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /1096/1096C-C-PolygonfortheAngle.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1096/problem/C 2 | //time:2021-07-15 20:43:45 3 | //name:C-PolygonfortheAngle 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | int t; 14 | std::cin >> t; 15 | while (t--) { 16 | int ang; 17 | std::cin >> ang; 18 | 19 | int n = 3; 20 | while (ang * n % 180 != 0 || n * ang > (n - 2) * 180) { 21 | n++; 22 | } 23 | 24 | std::cout << n << "\n"; 25 | } 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /112/112C-C-PetyaandInequiations.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/112/problem/C 2 | // time:2023-04-27 10:28:50 3 | // name:C-PetyaandInequiations 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | int n; 14 | i64 x, y; 15 | std::cin >> n >> x >> y; 16 | 17 | if (n > y || n - 1 + (y - n + 1) * (y - n + 1) < x) { 18 | std::cout << -1 << "\n"; 19 | return 0; 20 | } 21 | for (int i = 0; i < n; i++) { 22 | std::cout << (i ? 1 : y - n + 1) << "\n"; 23 | } 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /1472/1472A-A-CardsforFriends.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1472/problem/A 2 | //time:2021-01-04 17:36:39 3 | //name:A-CardsforFriends 4 | 5 | #include 6 | using i64 = long long; 7 | using u64 = unsigned long long; 8 | using u32 = unsigned; 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | int t; 13 | std::cin >> t; 14 | while (t--) { 15 | int w, h, n; 16 | std::cin >> w >> h >> n; 17 | if ((w & -w) * (h & -h) >= n) { 18 | std::cout << "YES\n"; 19 | } else { 20 | std::cout << "NO\n"; 21 | } 22 | } 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /1719/1719A-A-ChipGame.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1719/problem/A 2 | //time:2022-09-29 14:33:55 3 | //name:A-ChipGame 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n, m; 11 | std::cin >> n >> m; 12 | 13 | if ((n + m) % 2 == 0) { 14 | std::cout << "Tonya\n"; 15 | } else { 16 | std::cout << "Burenka\n"; 17 | } 18 | } 19 | 20 | int main() { 21 | std::ios::sync_with_stdio(false); 22 | std::cin.tie(nullptr); 23 | 24 | int t; 25 | std::cin >> t; 26 | 27 | while (t--) { 28 | solve(); 29 | } 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /598/598A-A-TrickySum.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/598/problem/A 2 | // time:2023-04-23 17:57:14 3 | // name:A-TrickySum 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | i64 ans = 1LL * n * (n+1) / 2; 14 | int m = 1 << std::__lg(n); 15 | ans -= 2 * (2LL * m - 1); 16 | std::cout << ans << "\n"; 17 | } 18 | 19 | int main() { 20 | std::ios::sync_with_stdio(false); 21 | std::cin.tie(nullptr); 22 | 23 | int t; 24 | std::cin >> t; 25 | 26 | while (t--) { 27 | solve(); 28 | } 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /1539/1539A-A-ContestStart.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1539/problem/A 2 | // time:2021-06-20 13:16:02 3 | // name:A-ContestStart 4 | 5 | #include 6 | using i64 = long long; 7 | int main() { 8 | std::ios::sync_with_stdio(false); 9 | std::cin.tie(nullptr); 10 | int k; 11 | std::cin >> k; 12 | while (k--) { 13 | int n, x, t; 14 | std::cin >> n >> x >> t; 15 | int v = t / x; 16 | if (n <= v) { 17 | std::cout << i64(n) * (n - 1) / 2 << "\n"; 18 | } else { 19 | std::cout << i64(v) * (v - 1) / 2 + i64(v) * (n - v) << "\n"; 20 | } 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /1618/1618A-A-PolycarpandSumsofSubsequences.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1618/problem/A 2 | // time:2021-12-22 10:15:19 3 | // name:A-PolycarpandSumsofSubsequences 4 | 5 | #include 6 | 7 | void solve() { 8 | std::vector b(7); 9 | for (int i = 0; i < 7; i++) { 10 | std::cin >> b[i]; 11 | } 12 | 13 | std::cout << b[0] << " " << b[1] << " " << b[5] - b[1] << "\n"; 14 | } 15 | 16 | int main() { 17 | std::ios::sync_with_stdio(false); 18 | std::cin.tie(nullptr); 19 | 20 | int t; 21 | std::cin >> t; 22 | 23 | while (t--) { 24 | solve(); 25 | } 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /1684/1684B-B-ZmodX=C.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1684/problem/B 2 | // time:2022-05-19 17:40:27 3 | // name:B-ZmodX=C 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | i64 a, b, c; 11 | std::cin >> a >> b >> c; 12 | 13 | i64 z = c; 14 | i64 y = b; 15 | i64 x = a + b * c; 16 | 17 | std::cout << x << " " << y << " " << z << "\n"; 18 | } 19 | 20 | int main() { 21 | std::ios::sync_with_stdio(false); 22 | std::cin.tie(nullptr); 23 | 24 | int t; 25 | std::cin >> t; 26 | 27 | while (t--) { 28 | solve(); 29 | } 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /1743/1743B-B-PermutationValue.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1743/problem/B 2 | // time:2022-10-17 17:47:02 3 | // name:B-PermutationValue 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | std::cout << 1; 14 | for (int i = n; i > 1; i--) { 15 | std::cout << " " << i; 16 | } 17 | std::cout << "\n"; 18 | } 19 | 20 | int main() { 21 | std::ios::sync_with_stdio(false); 22 | std::cin.tie(nullptr); 23 | 24 | int t; 25 | std::cin >> t; 26 | 27 | while (t--) { 28 | solve(); 29 | } 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /765/765C-C-TableTennisGame2.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/765/problem/C 2 | //time:2021-07-12 14:51:49 3 | //name:C-TableTennisGame2 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | int k, a, b; 14 | std::cin >> k >> a >> b; 15 | 16 | if (a < k && b % k > 0) { 17 | std::cout << "-1\n"; 18 | return 0; 19 | } 20 | 21 | if (b < k && a % k > 0) { 22 | std::cout << "-1\n"; 23 | return 0; 24 | } 25 | 26 | std::cout << a / k + b / k << "\n"; 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /1519/1519B-B-TheCakeIsaLie.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1519/problem/B 2 | //time:2022-06-27 11:28:15 3 | //name:B-TheCakeIsaLie 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n, m, k; 11 | std::cin >> n >> m >> k; 12 | 13 | if (k == n * m - 1) { 14 | std::cout << "YES\n"; 15 | } else { 16 | std::cout << "NO\n"; 17 | } 18 | } 19 | 20 | int main() { 21 | std::ios::sync_with_stdio(false); 22 | std::cin.tie(nullptr); 23 | 24 | int t; 25 | std::cin >> t; 26 | 27 | while (t--) { 28 | solve(); 29 | } 30 | 31 | return 0; 32 | } 33 | 34 | -------------------------------------------------------------------------------- /1676/1676A-A-Lucky?.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1676/problem/A 2 | // time:2022-05-10 17:46:44 3 | // name:A-Lucky? 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | std::string s; 11 | std::cin >> s; 12 | 13 | if (s[0] + s[1] + s[2] == s[3] + s[4] + s[5]) { 14 | std::cout << "YES\n"; 15 | } else { 16 | std::cout << "NO\n"; 17 | } 18 | } 19 | 20 | int main() { 21 | std::ios::sync_with_stdio(false); 22 | std::cin.tie(nullptr); 23 | 24 | int t; 25 | std::cin >> t; 26 | 27 | while (t--) { 28 | solve(); 29 | } 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /1698/1698A-A-XORMixup.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1698/problem/A 2 | // time:2022-07-02 11:06:53 3 | // name:A-XORMixup 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | std::vector a(n); 14 | for (int i = 0; i < n; i++) { 15 | std::cin >> a[i]; 16 | } 17 | 18 | std::cout << a[0] << "\n"; 19 | } 20 | 21 | int main() { 22 | std::ios::sync_with_stdio(false); 23 | std::cin.tie(nullptr); 24 | 25 | int t; 26 | std::cin >> t; 27 | 28 | while (t--) { 29 | solve(); 30 | } 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /712/712C-C-MemoryandDe-Evolution.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/712/problem/C 2 | // time:2023-03-15 11:25:03 3 | // name:C-MemoryandDe-Evolution 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | int x, y; 14 | std::cin >> x >> y; 15 | 16 | int a[3] = {y, y, y}; 17 | 18 | int ans = 0; 19 | while (a[0] != x) { 20 | a[0] = std::min(x, a[1] + a[2] - 1); 21 | std::rotate(a, a + 1, a + 3); 22 | ans += 1; 23 | } 24 | 25 | std::cout << ans << "\n"; 26 | 27 | return 0; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /1539/1539B-B-LoveSong.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1539/problem/B 2 | // time:2021-06-20 13:17:43 3 | // name:B-LoveSong 4 | 5 | #include 6 | using i64 = long long; 7 | int main() { 8 | std::ios::sync_with_stdio(false); 9 | std::cin.tie(nullptr); 10 | int n, q; 11 | std::cin >> n >> q; 12 | std::vector sum(n + 1); 13 | for (int i = 0; i < n; i++) { 14 | char c; 15 | std::cin >> c; 16 | sum[i + 1] = sum[i] + c - 'a' + 1; 17 | } 18 | while (q--) { 19 | int l, r; 20 | std::cin >> l >> r; 21 | l--; 22 | std::cout << sum[r] - sum[l] << "\n"; 23 | } 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /1743/1743A-A-Password.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1743/problem/A 2 | // time:2022-10-17 17:46:39 3 | // name:A-Password 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | for (int i = 0; i < n; i++) { 14 | int x; 15 | std::cin >> x; 16 | } 17 | 18 | std::cout << (10 - n) * (9 - n) * 3 << "\n"; 19 | } 20 | 21 | int main() { 22 | std::ios::sync_with_stdio(false); 23 | std::cin.tie(nullptr); 24 | 25 | int t; 26 | std::cin >> t; 27 | 28 | while (t--) { 29 | solve(); 30 | } 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /725/725A-A-JumpingBall.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/725/problem/A 2 | // time:2021-07-06 21:26:57 3 | // name:A-JumpingBall 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | int n; 14 | std::cin >> n; 15 | 16 | std::string s; 17 | std::cin >> s; 18 | 19 | int i = 0, j = n; 20 | while (i < n && s[i] == '<') { 21 | i++; 22 | } 23 | while (j > 0 && s[j - 1] == '>') { 24 | j--; 25 | } 26 | 27 | int ans = i + n - j; 28 | std::cout << ans << "\n"; 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /765/765B-B-Codeobfuscation.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/765/problem/B 2 | //time:2021-07-12 14:48:26 3 | //name:B-Codeobfuscation 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | std::string s; 14 | std::cin >> s; 15 | 16 | char x = 'a'; 17 | for (auto c : s) { 18 | if (c > x) { 19 | std::cout << "NO\n"; 20 | return 0; 21 | } 22 | 23 | if (c == x) { 24 | x++; 25 | } 26 | } 27 | 28 | std::cout << "YES\n"; 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /parse.py: -------------------------------------------------------------------------------- 1 | import re 2 | from collections import defaultdict 3 | import glob 4 | cm = defaultdict(list) 5 | sm = defaultdict(list) 6 | for file in glob.glob("./*/*cpp"): 7 | f = open(file, 'r') 8 | text = f.read() 9 | res = set(re.findall("struct\s+(\w+)\s?\{", text)) 10 | 11 | for tag in res: 12 | sm[tag].append(file) 13 | 14 | 15 | res = set(re.findall("class\s+(\w+)\s?\{", text)) 16 | 17 | 18 | print("# The data structure") 19 | print("") 20 | for name, candi in sm.items(): 21 | print(f"## {name} {len(candi)}") 22 | for c in candi: 23 | # print (c) [词向量 (Word Embedding)](./word_embedding/) 24 | print(f"- [{c.split('/')[-1]}]({c})") 25 | print("") 26 | -------------------------------------------------------------------------------- /1679/1679A-A-AvtoBus.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1679/problem/A 2 | // time:2022-05-16 15:08:57 3 | // name:A-AvtoBus 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | i64 n; 11 | std::cin >> n; 12 | 13 | if (n % 2 == 1 || n < 4) { 14 | std::cout << "-1\n"; 15 | return; 16 | } 17 | 18 | std::cout << (n + 5) / 6 << " " << n / 4 << "\n"; 19 | } 20 | 21 | int main() { 22 | std::ios::sync_with_stdio(false); 23 | std::cin.tie(nullptr); 24 | 25 | int t; 26 | std::cin >> t; 27 | 28 | while (t--) { 29 | solve(); 30 | } 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /702/702D-D-RoadtoPostOffice.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/702/problem/D 2 | //time:2021-07-12 19:12:29 3 | //name:D-RoadtoPostOffice 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | i64 d; 14 | int k, a, b, t; 15 | std::cin >> d >> k >> a >> b >> t; 16 | 17 | i64 ans = (d - 1) / k * t + d * a; 18 | if (k < d) { 19 | ans = std::min(ans, i64(k) * a + (d - k) * b); 20 | ans = std::min(ans, (d / k - 1) * t + d * a + d % k * (b - a)); 21 | } 22 | 23 | std::cout << ans << "\n"; 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /1617/1617B-B-GCDProblem.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1617/problem/B 2 | //time:2021-12-25 11:20:27 3 | //name:B-GCDProblem 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | n--; 13 | 14 | int a = 2; 15 | while (std::gcd(n, a) > 1) { 16 | a++; 17 | } 18 | 19 | std::cout << a << " " << n - a << " 1\n"; 20 | } 21 | 22 | int main() { 23 | std::ios::sync_with_stdio(false); 24 | std::cin.tie(nullptr); 25 | 26 | int t; 27 | std::cin >> t; 28 | 29 | while (t--) { 30 | solve(); 31 | } 32 | 33 | return 0; 34 | } 35 | 36 | -------------------------------------------------------------------------------- /712/712A-A-MemoryandCrow.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/712/problem/A 2 | // time:2023-03-15 11:18:11 3 | // name:A-MemoryandCrow 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | int n; 14 | std::cin >> n; 15 | 16 | std::vector a(n); 17 | for (int i = 0; i < n; i++) { 18 | std::cin >> a[i]; 19 | } 20 | for (int i = 0; i < n - 1; i++) { 21 | a[i] += a[i + 1]; 22 | } 23 | for (int i = 0; i < n; i++) { 24 | std::cout << a[i] << " \n"[i == n - 1]; 25 | } 26 | 27 | return 0; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /1543/1543A-A-ExcitingBets.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1543/problem/A 2 | // time:2021-07-07 17:37:04 3 | // name:A-ExcitingBets 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | int t; 14 | std::cin >> t; 15 | while (t--) { 16 | 17 | i64 a, b; 18 | std::cin >> a >> b; 19 | if (a == b) { 20 | std::cout << "0 0\n"; 21 | continue; 22 | } 23 | i64 d = std::abs(a - b); 24 | std::cout << d << " " << std::min(a % d, d - a % d) << "\n"; 25 | } 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /158/158A-A-NextRound.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/158/problem/A 2 | // time:2023-04-26 19:38:12 3 | // name:A-NextRound 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | int n, k; 14 | std::cin >> n >> k; 15 | 16 | std::vector a(n); 17 | for (int i = 0; i < n; i++) { 18 | std::cin >> a[i]; 19 | } 20 | 21 | std::sort(a.begin(), a.end()); 22 | 23 | int v = std::max(1, a[n-k]); 24 | int ans = a.end() - std::lower_bound(a.begin(), a.end(), v); 25 | std::cout << ans << "\n"; 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /1739/1739A-A-ImmobileKnight.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1739/problem/A 2 | //time:2022-09-29 17:53:22 3 | //name:A-ImmobileKnight 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n, m; 11 | std::cin >> n >> m; 12 | 13 | if (n == 1 || m == 1) { 14 | std::cout << 1 << " " << 1 << "\n"; 15 | } else { 16 | std::cout << 2 << " " << 2 << "\n"; 17 | } 18 | } 19 | 20 | int main() { 21 | std::ios::sync_with_stdio(false); 22 | std::cin.tie(nullptr); 23 | 24 | int t; 25 | std::cin >> t; 26 | 27 | while (t--) { 28 | solve(); 29 | } 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /1091/1091B-B-NewYearandtheTreasureGeolocation.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1091/problem/B 2 | //time:2021-07-15 21:16:19 3 | //name:B-NewYearandtheTreasureGeolocation 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | int n; 14 | std::cin >> n; 15 | 16 | i64 x = 0, y = 0; 17 | for (int i = 0; i < 2 * n; i++) { 18 | int a, b; 19 | std::cin >> a >> b; 20 | x += a; 21 | y += b; 22 | } 23 | 24 | x /= n; 25 | y /= n; 26 | 27 | std::cout << x << " " << y << "\n"; 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /1742/1742A-A-Sum.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1742/problem/A 2 | // time:2022-10-13 17:51:34 3 | // name:A-Sum 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int a[3]; 11 | std::cin >> a[0] >> a[1] >> a[2]; 12 | 13 | std::sort(a, a + 3); 14 | if (a[0] + a[1] == a[2]) { 15 | std::cout << "YES\n"; 16 | } else { 17 | std::cout << "NO\n"; 18 | } 19 | } 20 | 21 | int main() { 22 | std::ios::sync_with_stdio(false); 23 | std::cin.tie(nullptr); 24 | 25 | int t; 26 | std::cin >> t; 27 | 28 | while (t--) { 29 | solve(); 30 | } 31 | 32 | return 0; 33 | } 34 | 35 | -------------------------------------------------------------------------------- /716/716A-A-CrazyComputer.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/716/problem/A 2 | // time:2021-07-07 15:35:00 3 | // name:A-CrazyComputer 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | int n, c; 14 | std::cin >> n >> c; 15 | 16 | std::vector t(n); 17 | int ans = 0; 18 | for (int i = 0; i < n; i++) { 19 | std::cin >> t[i]; 20 | if (i > 0 && t[i] - t[i - 1] <= c) { 21 | ans++; 22 | } else { 23 | ans = 1; 24 | } 25 | } 26 | 27 | std::cout << ans << "\n"; 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /1485/1485C-C-FloorandMod.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1485/problem/C 2 | // time:2021-02-12 18:03:39 3 | // name:C-FloorandMod 4 | 5 | #include 6 | using i64 = long long; 7 | using u64 = unsigned long long; 8 | using u32 = unsigned; 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | int t; 13 | std::cin >> t; 14 | while (t--) { 15 | int x, y; 16 | std::cin >> x >> y; 17 | i64 ans = 0; 18 | for (int i = 1; i * (i + 1) <= x; i++) { 19 | int r = std::min(y, x / i - 1); 20 | ans += std::max(0, r - i); 21 | } 22 | std::cout << ans << "\n"; 23 | } 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /1519/1519A-A-RedandBlueBeans.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1519/problem/A 2 | //time:2022-06-27 11:25:20 3 | //name:A-RedandBlueBeans 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int r, b, d; 11 | std::cin >> r >> b >> d; 12 | 13 | if (r <= 1LL * (d + 1) * b && b <= 1LL * (d + 1) * r) { 14 | std::cout << "YES\n"; 15 | } else { 16 | std::cout << "NO\n"; 17 | } 18 | } 19 | 20 | int main() { 21 | std::ios::sync_with_stdio(false); 22 | std::cin.tie(nullptr); 23 | 24 | int t; 25 | std::cin >> t; 26 | 27 | while (t--) { 28 | solve(); 29 | } 30 | 31 | return 0; 32 | } 33 | 34 | -------------------------------------------------------------------------------- /1734/1734B-B-Bright,Nice,Brilliant.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1734/problem/B 2 | //time:2022-09-23 15:31:21 3 | //name:B-Bright,Nice,Brilliant 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | for (int i = 0; i < n; i++) { 14 | for (int j = 0; j <= i; j++) { 15 | std::cout << (j == 0 || j == i) << " \n"[j == i]; 16 | } 17 | } 18 | } 19 | 20 | int main() { 21 | std::ios::sync_with_stdio(false); 22 | std::cin.tie(nullptr); 23 | 24 | int t; 25 | std::cin >> t; 26 | 27 | while (t--) { 28 | solve(); 29 | } 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /717/717C-C-PotionsHomework.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/717/problem/C 2 | // time:2023-03-15 16:21:08 3 | // name:C-PotionsHomework 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | int n; 14 | std::cin >> n; 15 | 16 | std::vector a(n); 17 | for (int i = 0; i < n; i++) { 18 | std::cin >> a[i]; 19 | } 20 | std::sort(a.begin(), a.end()); 21 | 22 | i64 ans = 0; 23 | for (int i = 0; i < n; i++) { 24 | ans += 1LL * a[i] * a[n - 1 - i]; 25 | } 26 | std::cout << ans % 10007 << "\n"; 27 | 28 | return 0; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /1085/1085A-A-Right-LeftCipher.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1085/problem/A 2 | //time:2021-07-15 11:15:40 3 | //name:A-Right-LeftCipher 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | std::string t; 14 | std::cin >> t; 15 | 16 | std::string s; 17 | for (int i = t.length() - 1, l = 0, r = t.length(); i >= 0; i--) { 18 | if (i % 2 == 0) { 19 | s += t[l++]; 20 | } else { 21 | s += t[--r]; 22 | } 23 | } 24 | 25 | std::reverse(s.begin(), s.end()); 26 | std::cout << s << "\n"; 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /1675/1675A-A-FoodforAnimals.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1675/problem/A 2 | // time:2022-05-05 17:36:18 3 | // name:A-FoodforAnimals 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int a, b, c, x, y; 11 | std::cin >> a >> b >> c >> x >> y; 12 | 13 | if (a + c >= x && b + c >= y && a + b + c >= x + y) { 14 | std::cout << "YES\n"; 15 | } else { 16 | std::cout << "NO\n"; 17 | } 18 | } 19 | 20 | int main() { 21 | std::ios::sync_with_stdio(false); 22 | std::cin.tie(nullptr); 23 | 24 | int t; 25 | std::cin >> t; 26 | 27 | while (t--) { 28 | solve(); 29 | } 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /1821/1821A-A-Matching.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1821/problem/A 2 | // time:2023-04-20 19:02:17 3 | // name:A-Matching 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | std::string s; 11 | std::cin >> s; 12 | 13 | int ans = 1; 14 | for (int i = 0; i < s.size(); i++) { 15 | ans *= (s[i] == '?' ? 10 : 1) - ((s[i] == '?' || s[i] == '0') && !i); 16 | } 17 | std::cout << ans << "\n"; 18 | } 19 | 20 | int main() { 21 | std::ios::sync_with_stdio(false); 22 | std::cin.tie(nullptr); 23 | 24 | int t; 25 | std::cin >> t; 26 | 27 | while (t--) { 28 | solve(); 29 | } 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /235/235A-A-LCMChallenge.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/235/problem/A 2 | // time:2023-04-30 12:04:59 3 | // name:A-LCMChallenge 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | int n; 14 | std::cin >> n; 15 | 16 | if (n <= 2) { 17 | std::cout << n << "\n"; 18 | } else if (n % 2) { 19 | std::cout << 1LL * n * (n - 1) * (n - 2) << "\n"; 20 | } else if (n % 3) { 21 | std::cout << 1LL * n * (n - 1) * (n - 3) << "\n"; 22 | } else { 23 | std::cout << 1LL * (n - 1) * (n - 2) * (n - 3) << "\n"; 24 | } 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /492/492B-B-VanyaandLanterns.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/492/problem/B 2 | // time:2021-06-24 18:45:25 3 | // name:B-VanyaandLanterns 4 | 5 | #include 6 | using i64 = long long; 7 | int main() { 8 | std::ios::sync_with_stdio(false); 9 | std::cin.tie(nullptr); 10 | int n, l; 11 | std::cin >> n >> l; 12 | std::vector a(n); 13 | for (int i = 0; i < n; i++) { 14 | std::cin >> a[i]; 15 | } 16 | std::sort(a.begin(), a.end()); 17 | int ans = 2 * std::max(a[0], l - a.back()); 18 | for (int i = 0; i < n - 1; i++) { 19 | ans = std::max(a[i + 1] - a[i], ans); 20 | } 21 | std::cout << ans / 2 << "." << "05"[ans % 2] << "\n"; 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /725/725B-B-FoodonthePlane.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/725/problem/B 2 | // time:2021-07-06 21:32:15 3 | // name:B-FoodonthePlane 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | i64 n; 14 | std::cin >> n; 15 | char s; 16 | std::cin >> s; 17 | 18 | n--; 19 | i64 ans = n / 4 * 16; 20 | n %= 4; 21 | if (n == 1 || n == 3) { 22 | ans += 7; 23 | } 24 | if (s >= 'd') { 25 | ans += 'f' - s + 1; 26 | } else { 27 | ans += s - 'a' + 4; 28 | } 29 | 30 | std::cout << ans << "\n"; 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /1543/1543B-B-CustomisingtheTrack.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1543/problem/B 2 | // time:2021-07-07 17:38:57 3 | // name:B-CustomisingtheTrack 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | int t; 14 | std::cin >> t; 15 | while (t--) { 16 | 17 | int n; 18 | std::cin >> n; 19 | i64 sum = 0; 20 | for (int i = 0; i < n; i++) { 21 | int x; 22 | std::cin >> x; 23 | sum += x; 24 | } 25 | 26 | std::cout << sum % n * (n - sum % n) << "\n"; 27 | } 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /1635/1635A-A-MinOrSum.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1635/problem/A 2 | // time:2022-02-20 18:00:40 3 | // name:A-MinOrSum 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | int ans = 0; 14 | for (int i = 0; i < n; i++) { 15 | int x; 16 | std::cin >> x; 17 | ans |= x; 18 | } 19 | 20 | std::cout << ans << "\n"; 21 | } 22 | 23 | int main() { 24 | std::ios::sync_with_stdio(false); 25 | std::cin.tie(nullptr); 26 | 27 | int t; 28 | std::cin >> t; 29 | 30 | for (int i = 0; i < t; i++) { 31 | solve(); 32 | } 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /1818/1818A-A-Politics.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1818/problem/A 2 | // time:2023-04-29 21:23:12 3 | // name:A-Politics 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n, k; 11 | std::cin >> n >> k; 12 | 13 | std::vector s(n); 14 | for (int i = 0; i < n; i++) { 15 | std::cin >> s[i]; 16 | } 17 | 18 | std::cout << std::count(s.begin(), s.end(), s[0]) << "\n"; 19 | } 20 | 21 | int main() { 22 | std::ios::sync_with_stdio(false); 23 | std::cin.tie(nullptr); 24 | 25 | int t; 26 | std::cin >> t; 27 | 28 | while (t--) { 29 | solve(); 30 | } 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /496/496A-A-MinimumDifficulty.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/496/problem/A 2 | // time:2021-06-20 20:43:22 3 | // name:A-MinimumDifficulty 4 | 5 | #include 6 | using i64 = long long; 7 | int main() { 8 | std::ios::sync_with_stdio(false); 9 | std::cin.tie(nullptr); 10 | int n; 11 | std::cin >> n; 12 | std::vector a(n); 13 | for (int i = 0; i < n; i++) { 14 | std::cin >> a[i]; 15 | } 16 | int ans = 1e9; 17 | for (int i = 0; i < n - 2; i++) { 18 | ans = std::min(ans, a[i + 2] - a[i]); 19 | } 20 | for (int i = 0; i < n - 1; i++) { 21 | ans = std::max(ans, a[i + 1] - a[i]); 22 | } 23 | std::cout << ans << "\n"; 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /40/40A-A-FindColor.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/40/problem/A 2 | // time:2023-04-23 06:38:10 3 | // name:A-FindColor 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | int x, y; 14 | std::cin >> x >> y; 15 | 16 | if (!x || !y) { 17 | std::cout << "black\n"; 18 | } else { 19 | int z = x * x + y * y; 20 | int w = std::sqrt(z); 21 | if (w * w == z || ((w % 2) ^ (x < 0) ^ (y < 0)) == 0) { 22 | std::cout << "black\n"; 23 | } else { 24 | std::cout << "white\n"; 25 | } 26 | } 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /1511/1511A-A-ReviewSite.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1511/problem/A 2 | // time:2022-06-27 16:27:24 3 | // name:A-ReviewSite 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | int ans = 0; 14 | for (int i = 0; i < n; i++) { 15 | int x; 16 | std::cin >> x; 17 | 18 | ans += (x != 2); 19 | } 20 | 21 | std::cout << ans << "\n"; 22 | } 23 | 24 | int main() { 25 | std::ios::sync_with_stdio(false); 26 | std::cin.tie(nullptr); 27 | 28 | int t; 29 | std::cin >> t; 30 | 31 | while (t--) { 32 | solve(); 33 | } 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /1696/1696A-A-NITorz!.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1696/problem/A 2 | //time:2022-06-25 17:52:27 3 | //name:A-NITorz! 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n, z; 11 | std::cin >> n >> z; 12 | 13 | int ans = 0; 14 | for (int i = 0; i < n; i++) { 15 | int a; 16 | std::cin >> a; 17 | ans = std::max(ans, a | z); 18 | } 19 | 20 | std::cout << ans << "\n"; 21 | } 22 | 23 | int main() { 24 | std::ios::sync_with_stdio(false); 25 | std::cin.tie(nullptr); 26 | 27 | int t; 28 | std::cin >> t; 29 | 30 | while (t--) { 31 | solve(); 32 | } 33 | 34 | return 0; 35 | } 36 | 37 | -------------------------------------------------------------------------------- /1485/1485B-B-ReplaceandKeepSorted.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1485/problem/B 2 | // time:2021-02-12 17:57:40 3 | // name:B-ReplaceandKeepSorted 4 | 5 | #include 6 | using i64 = long long; 7 | using u64 = unsigned long long; 8 | using u32 = unsigned; 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | int n, q, k; 13 | std::cin >> n >> q >> k; 14 | std::vector a(n); 15 | for (int i = 0; i < n; i++) { 16 | std::cin >> a[i]; 17 | } 18 | while (q--) { 19 | int l, r; 20 | std::cin >> l >> r; 21 | l--; 22 | r--; 23 | std::cout << a[r] - a[l] + k + 1 - 2 * (r - l + 1) << "\n"; 24 | } 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /1680/1680A-A-MinimumsandMaximums.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1680/problem/A 2 | // time:2022-05-16 16:41:40 3 | // name:A-MinimumsandMaximums 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int l1, r1, l2, r2; 11 | std::cin >> l1 >> r1 >> l2 >> r2; 12 | 13 | if (std::max(l1, l2) <= std::min(r1, r2)) { 14 | std::cout << std::max(l1, l2) << "\n"; 15 | } else { 16 | std::cout << l1 + l2 << "\n"; 17 | } 18 | } 19 | 20 | int main() { 21 | std::ios::sync_with_stdio(false); 22 | std::cin.tie(nullptr); 23 | 24 | int t; 25 | std::cin >> t; 26 | 27 | while (t--) { 28 | solve(); 29 | } 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /1684/1684A-A-DigitMinimization.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1684/problem/A 2 | // time:2022-05-19 17:36:55 3 | // name:A-DigitMinimization 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | if (n < 100) { 14 | std::cout << n % 10 << "\n"; 15 | } else { 16 | auto s = std::to_string(n); 17 | std::cout << *std::min_element(s.begin(), s.end()) << "\n"; 18 | } 19 | } 20 | 21 | int main() { 22 | std::ios::sync_with_stdio(false); 23 | std::cin.tie(nullptr); 24 | 25 | int t; 26 | std::cin >> t; 27 | 28 | while (t--) { 29 | solve(); 30 | } 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /cuiaoxiang/parse.py: -------------------------------------------------------------------------------- 1 | import re 2 | from collections import defaultdict 3 | import glob 4 | cm = defaultdict(list) 5 | sm = defaultdict(list) 6 | for file in glob.glob("./*/*cpp"): 7 | f = open(file, 'r') 8 | text = f.read() 9 | res = set(re.findall("struct\s+(\w+)\s?\{", text)) 10 | 11 | for tag in res: 12 | sm[tag].append(file) 13 | 14 | 15 | res = set(re.findall("class\s+(\w+)\s?\{", text)) 16 | 17 | 18 | print("# The data structure") 19 | print("") 20 | for name, candi in sm.items(): 21 | if name == 'fast_ios': 22 | continue 23 | print(f"## {name} {len(candi)}") 24 | for c in candi: 25 | # print (c) [词向量 (Word Embedding)](./word_embedding/) 26 | print(f"- [{c.split('/')[-1]}]({c})") 27 | print("") 28 | -------------------------------------------------------------------------------- /158/158B-B-Taxi.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/158/problem/B 2 | // time:2023-04-26 19:41:02 3 | // name:B-Taxi 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | int n; 14 | std::cin >> n; 15 | 16 | int cnt[5] {}; 17 | for (int i = 0; i < n; i++) { 18 | int s; 19 | std::cin >> s; 20 | cnt[s]++; 21 | } 22 | 23 | int ans = cnt[4]; 24 | int t = std::min(cnt[1], cnt[3]); 25 | cnt[1] -= t, cnt[3] -= t; 26 | ans += t; 27 | ans += cnt[3]; 28 | ans += (cnt[2] * 2 + cnt[1] + 3) / 4; 29 | std::cout << ans << "\n"; 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /1728/1728A-A-ColoredBalls:Revisited.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1728/problem/A 2 | //time:2022-09-08 17:38:15 3 | //name:A-ColoredBalls:Revisited 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | std::vector a(n); 14 | for (int i = 0; i < n; i++) { 15 | std::cin >> a[i]; 16 | } 17 | 18 | std::cout << std::max_element(a.begin(), a.end()) - a.begin() + 1 << "\n"; 19 | } 20 | 21 | int main() { 22 | std::ios::sync_with_stdio(false); 23 | std::cin.tie(nullptr); 24 | 25 | int t; 26 | std::cin >> t; 27 | 28 | while (t--) { 29 | solve(); 30 | } 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /827/827B-B-HighLoad.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/827/problem/B 2 | //time:2021-03-31 15:46:11 3 | //name:B-HighLoad 4 | 5 | #include 6 | using i64 = int64_t; 7 | using u64 = uint64_t; 8 | using u32 = uint32_t; 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | int n, k; 13 | std::cin >> n >> k; 14 | int d = (n - 1) / k; 15 | int r = n - k * d; 16 | std::cout << 2 * d + std::min(r - 1, 2) << "\n"; 17 | for (int i = 1; i < n; i++) { 18 | if (i < r) { 19 | std::cout << "1 " << i + 1 << "\n"; 20 | } else { 21 | std::cout << std::max(0, i - k) + 1 << " " << i + 1 << "\n"; 22 | } 23 | } 24 | return 0; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /1574/1574A-A-RegularBracketSequences.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1574/problem/A 2 | //time:2022-06-12 07:21:30 3 | //name:A-RegularBracketSequences 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | for (int k = 0; k < n; k++) { 14 | std::cout << std::string(k, '(') + std::string(k, ')') + 15 | std::string(n - k, '(') + std::string(n - k, ')') << "\n"; 16 | } 17 | } 18 | 19 | int main() { 20 | std::ios::sync_with_stdio(false); 21 | std::cin.tie(nullptr); 22 | 23 | int t; 24 | std::cin >> t; 25 | 26 | while (t--) { 27 | solve(); 28 | } 29 | 30 | return 0; 31 | } 32 | 33 | -------------------------------------------------------------------------------- /282/282B-B-PaintingEggs.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/282/problem/B 2 | // time:2023-04-27 08:50:38 3 | // name:B-PaintingEggs 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | int n; 14 | std::cin >> n; 15 | 16 | std::vector a(n), b(n); 17 | int s = 0; 18 | for (int i = 0; i < n; i++) { 19 | std::cin >> a[i] >> b[i]; 20 | if (s + a[i] <= 500) { 21 | s += a[i]; 22 | std::cout << 'A'; 23 | } else { 24 | s -= b[i]; 25 | std::cout << 'G'; 26 | } 27 | } 28 | std::cout << '\n'; 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /498/498A-A-CrazyTown.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/498/problem/A 2 | // time:2021-06-21 21:15:47 3 | // name:A-CrazyTown 4 | 5 | #include 6 | using i64 = long long; 7 | int main() { 8 | std::ios::sync_with_stdio(false); 9 | std::cin.tie(nullptr); 10 | int x1, y1, x2, y2; 11 | std::cin >> x1 >> y1 >> x2 >> y2; 12 | int ans = 0; 13 | int n; 14 | std::cin >> n; 15 | for (int i = 0; i < n; i++) { 16 | int a, b, c; 17 | std::cin >> a >> b >> c; 18 | i64 A = i64(a) * x1 + i64(b) * y1 + c; 19 | i64 B = i64(a) * x2 + i64(b) * y2 + c; 20 | if ((A > 0) != (B > 0)) { 21 | ans++; 22 | } 23 | } 24 | std::cout << ans << "\n"; 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /708/708A-A-LettersCyclicShift.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/708/problem/A 2 | // time:2021-12-24 04:40:55 3 | // name:A-LettersCyclicShift 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | std::string s; 14 | std::cin >> s; 15 | 16 | const int n = s.length(); 17 | 18 | int i = 0; 19 | while (i < n && s[i] == 'a') { 20 | i++; 21 | } 22 | if (i == n) { 23 | s[n - 1] = 'z'; 24 | } 25 | int j = i; 26 | while (j < n && s[j] != 'a') { 27 | s[j]--; 28 | j++; 29 | } 30 | 31 | std::cout << s << "\n"; 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /1676/1676B-B-EqualCandies.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1676/problem/B 2 | // time:2022-05-10 17:47:46 3 | // name:B-EqualCandies 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | std::vector a(n); 14 | for (int i = 0; i < n; i++) { 15 | std::cin >> a[i]; 16 | } 17 | 18 | std::cout << std::accumulate(a.begin(), a.end(), 0) - n * *std::min_element(a.begin(), a.end()) << "\n"; 19 | } 20 | 21 | int main() { 22 | std::ios::sync_with_stdio(false); 23 | std::cin.tie(nullptr); 24 | 25 | int t; 26 | std::cin >> t; 27 | 28 | while (t--) { 29 | solve(); 30 | } 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /378/378A-A-PlayingwithDice.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/378/problem/A 2 | // time:2021-06-19 22:58:59 3 | // name:A-PlayingwithDice 4 | 5 | #include 6 | int main() { 7 | std::ios::sync_with_stdio(false); 8 | std::cin.tie(nullptr); 9 | int a, b; 10 | std::cin >> a >> b; 11 | int ans[3] = {}; 12 | for (int x = 1; x <= 6; x++) { 13 | int da = std::abs(a - x); 14 | int db = std::abs(b - x); 15 | if (da < db) { 16 | ans[0]++; 17 | } else if (da == db) { 18 | ans[1]++; 19 | } else { 20 | ans[2]++; 21 | } 22 | } 23 | for (int i = 0; i <= 2; i++) { 24 | std::cout << ans[i] << " \n"[i == 2]; 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /499/499B-B-Lecture.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/499/problem/B 2 | // time:2021-06-21 22:18:04 3 | // name:B-Lecture 4 | 5 | #include 6 | int main() { 7 | std::ios::sync_with_stdio(false); 8 | std::cin.tie(nullptr); 9 | int n, m; 10 | std::cin >> n >> m; 11 | std::map dic; 12 | for (int i = 0; i < m; i++) { 13 | std::string a, b; 14 | std::cin >> a >> b; 15 | if (a.size() <= b.size()) { 16 | dic[a] = a; 17 | } else { 18 | dic[a] = b; 19 | } 20 | } 21 | for (int i = 1; i <= n; i++) { 22 | std::string a; 23 | std::cin >> a; 24 | std::cout << dic[a] << " \n"[i == n]; 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /709/709A-A-Juicer.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/709/problem/A 2 | //time:2021-12-24 06:07:11 3 | //name:A-Juicer 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | int n, b, d; 14 | std::cin >> n >> b >> d; 15 | 16 | int ans = 0; 17 | 18 | int s = 0; 19 | for (int i = 0; i < n; i++) { 20 | int x; 21 | std::cin >> x; 22 | if (x > b) { 23 | continue; 24 | } 25 | s += x; 26 | if (s > d) { 27 | ans++; 28 | s = 0; 29 | } 30 | } 31 | 32 | std::cout << ans << "\n"; 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /1533/1533A-A-TraveltoBertown.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1533/problem/A 2 | // time:2021-07-02 20:33:01 3 | // name:A-TraveltoBertown 4 | 5 | import kotlin.collections.* 6 | 7 | fun readLn() = readLine()!! 8 | fun readInt() = readLn().toInt() 9 | fun readInts() = readLn().split(' ').map(String::toInt) 10 | fun readLong() = readLn().toInt() 11 | fun readLongs() = readLn().split(' ').map(String::toLong) 12 | 13 | fun main() { 14 | var t = readInt() 15 | repeat(t) { 16 | var (n, k) = readInts() 17 | var ans = 0 18 | repeat(n) { 19 | var (l, r) = readInts() 20 | if (l <= k && k <= r) { 21 | ans = maxOf(ans, r - k + 1) 22 | } 23 | } 24 | println(ans) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /1682/1682A-A-PalindromicIndices.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1682/problem/A 2 | // time:2022-05-22 17:45:51 3 | // name:A-PalindromicIndices 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | std::string s; 14 | std::cin >> s; 15 | 16 | int l = n / 2; 17 | while (l > 0 && s[l - 1] == s[l]) { 18 | l--; 19 | } 20 | int r = n - l - 1; 21 | std::cout << r - l + 1 << "\n"; 22 | } 23 | 24 | int main() { 25 | std::ios::sync_with_stdio(false); 26 | std::cin.tie(nullptr); 27 | 28 | int t; 29 | std::cin >> t; 30 | 31 | while (t--) { 32 | solve(); 33 | } 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /1624/1624A-A-PlusOneontheSubset.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1624/problem/A 2 | // time:2022-01-10 17:36:42 3 | // name:A-PlusOneontheSubset 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | std::vector a(n); 14 | for (int i = 0; i < n; i++) { 15 | std::cin >> a[i]; 16 | } 17 | 18 | std::cout << *std::max_element(a.begin(), a.end()) - *std::min_element(a.begin(), a.end()) << "\n"; 19 | } 20 | 21 | int main() { 22 | std::ios::sync_with_stdio(false); 23 | std::cin.tie(nullptr); 24 | 25 | int t; 26 | std::cin >> t; 27 | 28 | while (t--) { 29 | solve(); 30 | } 31 | 32 | return 0; 33 | } 34 | 35 | -------------------------------------------------------------------------------- /281/281B-B-NearestFraction.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/281/problem/B 2 | // time:2023-04-28 20:43:53 3 | // name:B-NearestFraction 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | i64 x, y, n; 14 | std::cin >> x >> y >> n; 15 | 16 | i64 a = 0, b = 1; 17 | for (int j = 1; j <= n; j++) { 18 | i64 t = x * j / y; 19 | for (auto i : {t, t + 1}) { 20 | if (std::abs(i * b * y - x * b * j) < std::abs(a * j * y - x * b * j)) { 21 | a = i; 22 | b = j; 23 | } 24 | } 25 | } 26 | std::cout << a << "/" << b << "\n"; 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /706/706A-A-Beru-taxi.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/706/problem/A 2 | // time:2023-03-14 20:43:08 3 | // name:A-Beru-taxi 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | int a, b; 14 | std::cin >> a >> b; 15 | 16 | int n; 17 | std::cin >> n; 18 | double ans = 1E9; 19 | for (int i = 0; i < n; i++) { 20 | int x, y, v; 21 | std::cin >> x >> y >> v; 22 | 23 | ans = std::min(ans, std::sqrt((x - a) * (x - a) + (y - b) * (y - b)) / v); 24 | } 25 | 26 | std::cout << std::fixed << std::setprecision(10); 27 | std::cout << ans << "\n"; 28 | 29 | return 0; 30 | } 31 | 32 | -------------------------------------------------------------------------------- /1806/1806A-A-WalkingMaster.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1806/problem/A 2 | // time:2023-03-20 20:49:18 3 | // name:A-WalkingMaster 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int a, b, c, d; 11 | std::cin >> a >> b >> c >> d; 12 | 13 | a -= b; 14 | c -= d; 15 | 16 | if (a < c || b > d) { 17 | std::cout << -1 << "\n"; 18 | return; 19 | } 20 | 21 | int ans = (a - c) + (d - b); 22 | std::cout << ans << "\n"; 23 | } 24 | 25 | int main() { 26 | std::ios::sync_with_stdio(false); 27 | std::cin.tie(nullptr); 28 | 29 | int t; 30 | std::cin >> t; 31 | 32 | while (t--) { 33 | solve(); 34 | } 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /707/707A-A-Brain'sPhotos.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/707/problem/A 2 | // time:2023-03-15 09:07:05 3 | // name:A-Brain'sPhotos 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | int n, m; 14 | std::cin >> n >> m; 15 | 16 | for (int i = 0; i < n; i++) { 17 | for (int j = 0; j < m; j++) { 18 | char c; 19 | std::cin >> c; 20 | 21 | if (c == 'C' || c == 'M' || c == 'Y') { 22 | std::cout << "#Color\n"; 23 | return 0; 24 | } 25 | } 26 | } 27 | 28 | std::cout << "#Black&White\n"; 29 | 30 | return 0; 31 | } 32 | 33 | -------------------------------------------------------------------------------- /1515/1515B-B-PhoenixandPuzzle.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1515/problem/B 2 | // time:2021-05-02 17:40:44 3 | // name:B-PhoenixandPuzzle 4 | 5 | #include 6 | using i64 = long long; 7 | using u64 = unsigned long long; 8 | using u32 = unsigned; 9 | bool issquare(int n) { 10 | int x = std::sqrt(n); 11 | return x * x == n; 12 | } 13 | int main() { 14 | std::ios::sync_with_stdio(false); 15 | std::cin.tie(nullptr); 16 | int t; 17 | std::cin >> t; 18 | while (t--) { 19 | int n; 20 | std::cin >> n; 21 | if ((n % 4 == 0 && issquare(n / 4)) || (n % 2 == 0 && issquare(n / 2))) { 22 | std::cout << "YES\n"; 23 | } else { 24 | std::cout << "NO\n"; 25 | } 26 | } 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /1606/1606B-B-UpdateFiles.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1606/problem/B 2 | //time:2022-06-10 11:05:14 3 | //name:B-UpdateFiles 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | i64 n, k; 11 | std::cin >> n >> k; 12 | 13 | i64 cur = 1; 14 | i64 ans = 0; 15 | while (cur < k) { 16 | cur *= 2; 17 | ans++; 18 | } 19 | 20 | if (cur < n) { 21 | ans += (n - cur + k - 1) / k; 22 | } 23 | 24 | std::cout << ans << "\n"; 25 | } 26 | 27 | int main() { 28 | std::ios::sync_with_stdio(false); 29 | std::cin.tie(nullptr); 30 | 31 | int t; 32 | std::cin >> t; 33 | 34 | while (t--) { 35 | solve(); 36 | } 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /1682/1682B-B-ANDSorting.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1682/problem/B 2 | // time:2022-05-22 17:49:52 3 | // name:B-ANDSorting 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | int ans = -1; 14 | 15 | std::vector p(n); 16 | for (int i = 0; i < n; i++) { 17 | std::cin >> p[i]; 18 | if (p[i] != i) { 19 | ans &= i; 20 | } 21 | } 22 | 23 | std::cout << ans << "\n"; 24 | } 25 | 26 | int main() { 27 | std::ios::sync_with_stdio(false); 28 | std::cin.tie(nullptr); 29 | 30 | int t; 31 | std::cin >> t; 32 | 33 | while (t--) { 34 | solve(); 35 | } 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /1504/1504A-A-DéjàVu.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1504/problem/A 2 | //time:2021-12-24 12:04:12 3 | //name:A-DéjàVu 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | std::string s; 11 | std::cin >> s; 12 | 13 | for (auto t : {'a' + s, s + 'a'}) { 14 | if (t != std::string(t.rbegin(), t.rend())) { 15 | std::cout << "YES\n"; 16 | std::cout << t << "\n"; 17 | return; 18 | } 19 | } 20 | 21 | std::cout << "NO\n"; 22 | } 23 | 24 | int main() { 25 | std::ios::sync_with_stdio(false); 26 | std::cin.tie(nullptr); 27 | 28 | int t; 29 | std::cin >> t; 30 | 31 | while (t--) { 32 | solve(); 33 | } 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /1694/1694A-A-Creep.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1694/problem/A 2 | //time:2022-06-27 11:15:56 3 | //name:A-Creep 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int a, b; 11 | std::cin >> a >> b; 12 | 13 | std::string s; 14 | for (int i = 0; i < std::max(a, b); i++) { 15 | if (i < a) { 16 | s += '0'; 17 | } 18 | if (i < b) { 19 | s += '1'; 20 | } 21 | } 22 | 23 | std::cout << s << "\n"; 24 | } 25 | 26 | int main() { 27 | std::ios::sync_with_stdio(false); 28 | std::cin.tie(nullptr); 29 | 30 | int t; 31 | std::cin >> t; 32 | 33 | while (t--) { 34 | solve(); 35 | } 36 | 37 | return 0; 38 | } 39 | 40 | -------------------------------------------------------------------------------- /1746/1746A-A-Maxmina.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1746/problem/A 2 | // time:2022-10-15 17:45:30 3 | // name:A-Maxmina 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n, k; 11 | std::cin >> n >> k; 12 | 13 | std::vector a(n); 14 | for (int i = 0; i < n; i++) { 15 | std::cin >> a[i]; 16 | } 17 | 18 | if (std::count(a.begin(), a.end(), 1)) { 19 | std::cout << "YES\n"; 20 | } else { 21 | std::cout << "NO\n"; 22 | } 23 | } 24 | 25 | int main() { 26 | std::ios::sync_with_stdio(false); 27 | std::cin.tie(nullptr); 28 | 29 | int t; 30 | std::cin >> t; 31 | 32 | while (t--) { 33 | solve(); 34 | } 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /1809/1809A-A-Garland.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1809/problem/A 2 | // time:2023-03-23 17:42:45 3 | // name:A-Garland 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | std::string s; 11 | std::cin >> s; 12 | 13 | std::sort(s.begin(), s.end()); 14 | 15 | if (s[0] == s[3]) { 16 | std::cout << -1 << "\n"; 17 | } else if (s[0] == s[2] || s[1] == s[3]) { 18 | std::cout << 6 << "\n"; 19 | } else { 20 | std::cout << 4 << "\n"; 21 | } 22 | } 23 | 24 | int main() { 25 | std::ios::sync_with_stdio(false); 26 | std::cin.tie(nullptr); 27 | 28 | int t; 29 | std::cin >> t; 30 | 31 | while (t--) { 32 | solve(); 33 | } 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /600/600B-B-Queriesaboutlessorequalelements.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/600/problem/B 2 | // time:2023-04-24 06:27:45 3 | // name:B-Queriesaboutlessorequalelements 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | int n, m; 14 | std::cin >> n >> m; 15 | 16 | std::vector a(n), b(m); 17 | for (auto &x : a) { 18 | std::cin >> x; 19 | } 20 | for (auto &x : b) { 21 | std::cin >> x; 22 | } 23 | 24 | std::sort(a.begin(), a.end()); 25 | for (int i = 0; i < m; i++) { 26 | std::cout << std::upper_bound(a.begin(), a.end(), b[i]) - a.begin() << " \n"[i == m-1]; 27 | } 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /1511/1511B-B-GCDLength.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1511/problem/B 2 | // time:2022-06-27 16:31:49 3 | // name:B-GCDLength 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int a, b, c; 11 | std::cin >> a >> b >> c; 12 | 13 | auto x = '1' + std::string(a - 1, '0'); 14 | auto y = '1' + std::string(b - 1, '0'); 15 | 16 | if (a > b) { 17 | x[a - c]++; 18 | } else { 19 | y[b - c]++; 20 | } 21 | 22 | std::cout << x << " " << y << "\n"; 23 | } 24 | 25 | int main() { 26 | std::ios::sync_with_stdio(false); 27 | std::cin.tie(nullptr); 28 | 29 | int t; 30 | std::cin >> t; 31 | 32 | while (t--) { 33 | solve(); 34 | } 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /1818/1818B-B-Indivisible.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1818/problem/B 2 | // time:2023-04-29 21:45:44 3 | // name:B-Indivisible 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | if (n == 1) { 14 | std::cout << 1 << "\n"; 15 | } else if (n % 2) { 16 | std::cout << -1 << "\n"; 17 | } else { 18 | for (int i = 0; i < n; i++) { 19 | std::cout << (i ^ 1) + 1 << " \n"[i == n - 1]; 20 | } 21 | } 22 | } 23 | 24 | int main() { 25 | std::ios::sync_with_stdio(false); 26 | std::cin.tie(nullptr); 27 | 28 | int t; 29 | std::cin >> t; 30 | 31 | while (t--) { 32 | solve(); 33 | } 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /501/501B-B-MishaandChangingHandles.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/501/problem/B 2 | // time:2021-06-24 16:20:22 3 | // name:B-MishaandChangingHandles 4 | 5 | #include 6 | using i64 = long long; 7 | int main() { 8 | std::ios::sync_with_stdio(false); 9 | std::cin.tie(nullptr); 10 | int q; 11 | std::cin >> q; 12 | std::map old; 13 | while (q--) { 14 | std::string a, b; 15 | std::cin >> a >> b; 16 | if (!old.count(a)) { 17 | old[b] = a; 18 | } else { 19 | old[b] = old[a]; 20 | old.erase(a); 21 | } 22 | } 23 | std::cout << old.size() << "\n"; 24 | for (auto [b, a] : old) { 25 | std::cout << a << " " << b << "\n"; 26 | } 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /1517/1517A-A-Sumof2050.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1517/problem/A 2 | // time:2021-04-23 17:36:34 3 | // name:A-Sumof2050 4 | 5 | #include 6 | using i64 = long long; 7 | using u64 = unsigned long long; 8 | using u32 = unsigned; 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | int t; 13 | std::cin >> t; 14 | while (t--) { 15 | i64 n; 16 | std::cin >> n; 17 | if (n % 2050 != 0) { 18 | std::cout << "-1\n"; 19 | } else { 20 | n /= 2050; 21 | int ans = 0; 22 | while (n > 0) { 23 | ans += n % 10; 24 | n /= 10; 25 | } 26 | std::cout << ans << "\n"; 27 | } 28 | } 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /707/707C-C-PythagoreanTriples.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/707/problem/C 2 | // time:2023-03-15 09:14:14 3 | // name:C-PythagoreanTriples 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | int n; 14 | std::cin >> n; 15 | 16 | if (n <= 2) { 17 | std::cout << -1 << "\n"; 18 | return 0; 19 | } 20 | 21 | int k = __builtin_ctz(n); 22 | int m = n >> k; 23 | 24 | if (m == 1) { 25 | std::cout << n / 4 * 3 << " " << n / 4 * 5 << "\n"; 26 | return 0; 27 | } 28 | 29 | std::cout << (1LL * m * m / 2) * (1 << k) << " " << (1LL * m * m / 2 + 1) * (1 << k) << "\n"; 30 | 31 | return 0; 32 | } 33 | 34 | -------------------------------------------------------------------------------- /1615/1615A-A-ClosingTheGap.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1615/problem/A 2 | //time:2021-12-24 17:36:50 3 | //name:A-ClosingTheGap 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | int sum = 0; 14 | for (int i = 0; i < n; i++) { 15 | int x; 16 | std::cin >> x; 17 | sum += x; 18 | } 19 | 20 | if (sum % n == 0) { 21 | std::cout << "0\n"; 22 | } else { 23 | std::cout << "1\n"; 24 | } 25 | } 26 | 27 | int main() { 28 | std::ios::sync_with_stdio(false); 29 | std::cin.tie(nullptr); 30 | 31 | int t; 32 | std::cin >> t; 33 | 34 | while (t--) { 35 | solve(); 36 | } 37 | 38 | return 0; 39 | } 40 | 41 | -------------------------------------------------------------------------------- /1697/1697A-A-ParkwayWalk.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1697/problem/A 2 | //time:2022-06-12 17:41:00 3 | //name:A-ParkwayWalk 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n, m; 11 | std::cin >> n >> m; 12 | 13 | std::vector a(n); 14 | for (int i = 0; i < n; i++) { 15 | std::cin >> a[i]; 16 | } 17 | 18 | int sum = std::accumulate(a.begin(), a.end(), 0); 19 | 20 | int ans = std::max(0, sum - m); 21 | 22 | std::cout << ans << "\n"; 23 | } 24 | 25 | int main() { 26 | std::ios::sync_with_stdio(false); 27 | std::cin.tie(nullptr); 28 | 29 | int t; 30 | std::cin >> t; 31 | 32 | while (t--) { 33 | solve(); 34 | } 35 | 36 | return 0; 37 | } 38 | 39 | -------------------------------------------------------------------------------- /1734/1734E-E-RectangularCongruence.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1734/problem/E 2 | //time:2022-09-23 15:48:51 3 | //name:E-RectangularCongruence 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | int n; 14 | std::cin >> n; 15 | 16 | std::vector b(n); 17 | for (int i = 0; i < n; i++) { 18 | std::cin >> b[i]; 19 | } 20 | 21 | for (int i = 0; i < n; i++) { 22 | for (int j = 0; j < n; j++) { 23 | int a = (i * j + b[i] - i * i) % n; 24 | if (a < 0) { 25 | a += n; 26 | } 27 | std::cout << a << " \n"[j == n - 1]; 28 | } 29 | } 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /1735/1735B-B-TeawithTangerines.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1735/problem/B 2 | //time:2022-10-04 12:03:54 3 | //name:B-TeawithTangerines 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | std::vector a(n); 14 | for (int i = 0; i < n; i++) { 15 | std::cin >> a[i]; 16 | } 17 | 18 | i64 ans = 0; 19 | for (int i = 0; i < n; i++) { 20 | ans += (a[i] - 1) / (2 * a[0] - 1); 21 | } 22 | std::cout << ans << "\n"; 23 | } 24 | 25 | int main() { 26 | std::ios::sync_with_stdio(false); 27 | std::cin.tie(nullptr); 28 | 29 | int t; 30 | std::cin >> t; 31 | 32 | while (t--) { 33 | solve(); 34 | } 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /1742/1742B-B-Increasing.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1742/problem/B 2 | // time:2022-10-13 17:52:53 3 | // name:B-Increasing 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | std::set s; 14 | for (int i = 0; i < n; i++) { 15 | int x; 16 | std::cin >> x; 17 | s.insert(x); 18 | } 19 | if (int(s.size()) == n) { 20 | std::cout << "YES\n"; 21 | } else { 22 | std::cout << "NO\n"; 23 | } 24 | } 25 | 26 | int main() { 27 | std::ios::sync_with_stdio(false); 28 | std::cin.tie(nullptr); 29 | 30 | int t; 31 | std::cin >> t; 32 | 33 | while (t--) { 34 | solve(); 35 | } 36 | 37 | return 0; 38 | } 39 | 40 | -------------------------------------------------------------------------------- /1091/1091C-C-NewYearandtheSphereTransmission.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1091/problem/C 2 | //time:2021-07-15 21:21:08 3 | //name:C-NewYearandtheSphereTransmission 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | int n; 14 | std::cin >> n; 15 | 16 | std::set s; 17 | for (int i = 1; i * i <= n; i++) { 18 | if (n % i == 0) { 19 | s.insert(i64(n / i) * (n / i - 1) / 2 * i + n / i); 20 | if (i * i != n) { 21 | s.insert(i64(i) * (i - 1) / 2 * (n / i) + i); 22 | } 23 | } 24 | } 25 | 26 | for (auto x : s) { 27 | std::cout << x << " "; 28 | } 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /1644/1644B-B-Anti-FibonacciPermutation.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1644/problem/B 2 | // time:2022-02-23 08:07:38 3 | // name:B-Anti-FibonacciPermutation 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | for (int i = 1; i <= n; i++) { 14 | std::cout << i; 15 | for (int j = n; j > 0; j--) { 16 | if (i != j) { 17 | std::cout << " " << j; 18 | } 19 | } 20 | std::cout << "\n"; 21 | } 22 | } 23 | 24 | int main() { 25 | std::ios::sync_with_stdio(false); 26 | std::cin.tie(nullptr); 27 | 28 | int t; 29 | std::cin >> t; 30 | 31 | while (t--) { 32 | solve(); 33 | } 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /493/493A-A-VasyaandFootball.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/493/problem/A 2 | // time:2021-06-21 19:26:43 3 | // name:A-VasyaandFootball 4 | 5 | #include 6 | int main() { 7 | std::ios::sync_with_stdio(false); 8 | std::cin.tie(nullptr); 9 | std::string home, away; 10 | std::cin >> home >> away; 11 | int n; 12 | std::cin >> n; 13 | std::vector a(200); 14 | for (int i = 0; i < n; i++) { 15 | int t, m; 16 | char team, tp; 17 | std::cin >> t >> team >> m >> tp; 18 | int u = (team == 'a') * 100 + m; 19 | a[u] += (tp == 'y' ? 1 : 2); 20 | if (a[u] >= 2) { 21 | std::cout << (team == 'h' ? home : away) << " " << m << " " << t << "\n"; 22 | a[u] = -1e9; 23 | } 24 | } 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /112/112A-A-PetyaandStrings.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/112/problem/A 2 | // time:2023-04-27 10:23:53 3 | // name:A-PetyaandStrings 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | std::string s, t; 14 | std::cin >> s >> t; 15 | 16 | auto f = [](char &c) { 17 | if (std::isupper(c)) { 18 | c = std::tolower(c); 19 | } 20 | }; 21 | 22 | std::ranges::for_each(s, f); 23 | std::ranges::for_each(t, f); 24 | 25 | if (s < t) { 26 | std::cout << -1 << "\n"; 27 | } else if (s > t) { 28 | std::cout << 1 << "\n"; 29 | } else { 30 | std::cout << 0 << "\n"; 31 | } 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /1616/1616A-A-IntegerDiversity.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1616/problem/A 2 | // time:2021-12-29 18:37:51 3 | // name:A-IntegerDiversity 4 | 5 | #include 6 | 7 | void solve() { 8 | int n; 9 | std::cin >> n; 10 | 11 | int cnt[101] = {}; 12 | for (int i = 0; i < n; i++) { 13 | int x; 14 | std::cin >> x; 15 | cnt[std::abs(x)]++; 16 | } 17 | int ans = (cnt[0] > 0); 18 | for (int i = 1; i <= 100; i++) { 19 | ans += std::min(2, cnt[i]); 20 | } 21 | std::cout << ans << "\n"; 22 | } 23 | 24 | int main() { 25 | std::ios::sync_with_stdio(false); 26 | std::cin.tie(nullptr); 27 | 28 | int t; 29 | std::cin >> t; 30 | 31 | while (t--) { 32 | solve(); 33 | } 34 | 35 | return 0; 36 | } 37 | 38 | -------------------------------------------------------------------------------- /702/702B-B-PowersofTwo.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/702/problem/B 2 | //time:2021-07-12 19:01:21 3 | //name:B-PowersofTwo 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | int n; 14 | std::cin >> n; 15 | 16 | i64 ans = 0; 17 | 18 | std::map cnt; 19 | for (int i = 0; i < n; i++) { 20 | int x; 21 | std::cin >> x; 22 | 23 | for (int j = 1; j <= 30; j++) { 24 | if ((1 << j) > x && cnt.count((1 << j) - x)) { 25 | ans += cnt[(1 << j) - x]; 26 | } 27 | } 28 | 29 | cnt[x]++; 30 | } 31 | 32 | std::cout << ans << "\n"; 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /1085/1085D-D-MinimumDiameterTree.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1085/problem/D 2 | //time:2021-07-15 11:30:33 3 | //name:D-MinimumDiameterTree 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | int n, s; 14 | std::cin >> n >> s; 15 | 16 | std::vector deg(n); 17 | for (int i = 0; i < n - 1; i++) { 18 | int u, v; 19 | std::cin >> u >> v; 20 | u--; 21 | v--; 22 | deg[u]++; 23 | deg[v]++; 24 | } 25 | 26 | int leaves = std::count(deg.begin(), deg.end(), 1); 27 | 28 | double ans = 2.0 * s / leaves; 29 | 30 | std::cout << std::fixed << std::setprecision(10) << ans << "\n"; 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /1692/1692B-B-AllDistinct.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1692/problem/B 2 | //time:2022-06-14 17:37:42 3 | //name:B-AllDistinct 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | std::set a; 14 | for (int i = 0; i < n; i++) { 15 | int x; 16 | std::cin >> x; 17 | a.insert(x); 18 | } 19 | 20 | int m = a.size(); 21 | 22 | if ((n - m) % 2 != 0) { 23 | m--; 24 | } 25 | 26 | std::cout << m << "\n"; 27 | } 28 | 29 | int main() { 30 | std::ios::sync_with_stdio(false); 31 | std::cin.tie(nullptr); 32 | 33 | int t; 34 | std::cin >> t; 35 | 36 | while (t--) { 37 | solve(); 38 | } 39 | 40 | return 0; 41 | } 42 | 43 | -------------------------------------------------------------------------------- /1473/1473A-A-ReplacingElements.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1473/problem/A 2 | //time:2021-01-14 17:39:00 3 | //name:A-ReplacingElements 4 | 5 | #include 6 | using i64 = long long; 7 | using u64 = unsigned long long; 8 | using u32 = unsigned; 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | int t; 13 | std::cin >> t; 14 | while (t--) { 15 | int n, d; 16 | std::cin >> n >> d; 17 | std::vector a(n); 18 | for (int i = 0; i < n; i++) { 19 | std::cin >> a[i]; 20 | } 21 | std::sort(a.begin(), a.end()); 22 | if (a[0] + a[1] <= d || a[n - 1] <= d) { 23 | std::cout << "YES\n"; 24 | } else { 25 | std::cout << "NO\n"; 26 | } 27 | } 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /1485/1485D-D-MultiplesandPowerDifferences.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1485/problem/D 2 | // time:2021-02-12 18:09:59 3 | // name:D-MultiplesandPowerDifferences 4 | 5 | #include 6 | using i64 = long long; 7 | using u64 = unsigned long long; 8 | using u32 = unsigned; 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | int n, m; 13 | std::cin >> n >> m; 14 | for (int i = 0; i < n; i++) { 15 | for (int j = 0; j < m; j++) { 16 | int x; 17 | std::cin >> x; 18 | if ((i + j) % 2 == 0) { 19 | std::cout << 720720; 20 | } else { 21 | std::cout << 720720 - x * x * x * x; 22 | } 23 | std::cout << " \n"[j == m - 1]; 24 | } 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /1726/1726C-C-Jatayu'sBalancedBracketSequence.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1726/problem/C 2 | //time:2022-09-06 17:43:47 3 | //name:C-Jatayu'sBalancedBracketSequence 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | std::string s; 14 | std::cin >> s; 15 | 16 | int ans = n + 1; 17 | for (int i = 0; i < 2 * n - 1; i++) { 18 | if (s[i] == '(' && s[i + 1] == ')') { 19 | ans--; 20 | } 21 | } 22 | 23 | std::cout << ans << "\n"; 24 | } 25 | 26 | int main() { 27 | std::ios::sync_with_stdio(false); 28 | std::cin.tie(nullptr); 29 | 30 | int t; 31 | std::cin >> t; 32 | 33 | while (t--) { 34 | solve(); 35 | } 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /710/710A-A-KingMoves.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/710/problem/A 2 | // time:2021-07-07 22:04:13 3 | // name:A-KingMoves 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | const std::vector> moves = {{0, 1}, {0, -1}, {-1, 0}, {1, 0}, {1, 1}, {1, -1}, {-1, -1}, {-1, 1}}; 10 | 11 | int main() { 12 | std::ios::sync_with_stdio(false); 13 | std::cin.tie(nullptr); 14 | 15 | char a, b; 16 | std::cin >> a >> b; 17 | int x = a - 'a', y = b - '1'; 18 | 19 | int ans = 0; 20 | for (auto move : moves) { 21 | int x1 = x + move.first; 22 | int y1 = y + move.second; 23 | if (0 <= x1 && x1 < 8 && 0 <= y1 && y1 < 8) { 24 | ans++; 25 | } 26 | } 27 | 28 | std::cout << ans << "\n"; 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /1542/1542B-B-PlusandMultiply.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1542/problem/B 2 | // time:2021-07-03 16:11:36 3 | // name:B-PlusandMultiply 4 | 5 | #include 6 | using i64 = long long; 7 | int main() { 8 | std::ios::sync_with_stdio(false); 9 | std::cin.tie(nullptr); 10 | int t; 11 | std::cin >> t; 12 | while (t--) { 13 | int a, b, n; 14 | std::cin >> n >> a >> b; 15 | bool ok = false; 16 | for (i64 x = 1; x <= n; x *= a) { 17 | if ((n - x) % b == 0) { 18 | ok = true; 19 | } 20 | if (a == 1) { 21 | break; 22 | } 23 | } 24 | if (ok) { 25 | std::cout << "Yes\n"; 26 | } else { 27 | std::cout << "No\n"; 28 | } 29 | } 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /1674/1674C-C-InfiniteReplacement.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1674/problem/C 2 | // time:2022-05-02 17:45:24 3 | // name:C-InfiniteReplacement 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | std::string s, t; 11 | std::cin >> s >> t; 12 | 13 | if (t == "a") { 14 | std::cout << "1\n"; 15 | return; 16 | } 17 | 18 | if (std::count(t.begin(), t.end(), 'a') > 0) { 19 | std::cout << "-1\n"; 20 | return; 21 | } 22 | 23 | std::cout << (1LL << s.length()) << "\n"; 24 | } 25 | 26 | int main() { 27 | std::ios::sync_with_stdio(false); 28 | std::cin.tie(nullptr); 29 | 30 | int t; 31 | std::cin >> t; 32 | 33 | while (t--) { 34 | solve(); 35 | } 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /1730/1730A-A-Planets.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1730/problem/A 2 | //time:2022-09-25 17:55:11 3 | //name:A-Planets 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n, c; 11 | std::cin >> n >> c; 12 | 13 | std::vector a(n); 14 | std::map cnt; 15 | for (int i = 0; i < n; i++) { 16 | std::cin >> a[i]; 17 | cnt[a[i]]++; 18 | } 19 | 20 | int ans = 0; 21 | for (auto [_, x] : cnt) { 22 | ans += std::min(x, c); 23 | } 24 | std::cout << ans << "\n"; 25 | } 26 | 27 | int main() { 28 | std::ios::sync_with_stdio(false); 29 | std::cin.tie(nullptr); 30 | 31 | int t; 32 | std::cin >> t; 33 | 34 | while (t--) { 35 | solve(); 36 | } 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /1623/1623A-A-RobotCleaner.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1623/problem/A 2 | //time:2021-12-28 17:41:56 3 | //name:A-RobotCleaner 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n, m, rb, cb, rd, cd; 11 | std::cin >> n >> m >> rb >> cb >> rd >> cd; 12 | rb--; 13 | cb--; 14 | rd--; 15 | cd--; 16 | 17 | int ans = std::min({ 18 | rb <= rd ? rd - rb : 2 * (n - 1) - rb - rd, 19 | cb <= cd ? cd - cb : 2 * (m - 1) - cb - cd 20 | }); 21 | 22 | std::cout << ans << "\n"; 23 | } 24 | 25 | 26 | int main() { 27 | std::ios::sync_with_stdio(false); 28 | std::cin.tie(nullptr); 29 | 30 | int t; 31 | std::cin >> t; 32 | 33 | while (t--) { 34 | solve(); 35 | } 36 | 37 | return 0; 38 | } 39 | 40 | -------------------------------------------------------------------------------- /1644/1644A-A-DoorsandKeys.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1644/problem/A 2 | // time:2022-02-23 09:48:27 3 | // name:A-DoorsandKeys 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | std::string s; 11 | std::cin >> s; 12 | 13 | std::set keys; 14 | for (auto c : s) { 15 | if (std::islower(c)) { 16 | keys.insert(c); 17 | } else if (!keys.count(std::tolower(c))) { 18 | std::cout << "NO\n"; 19 | return; 20 | } 21 | } 22 | 23 | std::cout << "YES\n"; 24 | } 25 | 26 | int main() { 27 | std::ios::sync_with_stdio(false); 28 | std::cin.tie(nullptr); 29 | 30 | int t; 31 | std::cin >> t; 32 | 33 | while (t--) { 34 | solve(); 35 | } 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /1823/1823B-B-SortwithStep.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1823/problem/B 2 | // time:2023-04-28 08:43:25 3 | // name:B-SortwithStep 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n, k; 11 | std::cin >> n >> k; 12 | 13 | int cnt = 0; 14 | for (int i = 0; i < n; i++) { 15 | int x; 16 | std::cin >> x; 17 | x--; 18 | cnt += (x % k != i % k); 19 | } 20 | if (cnt > 2) { 21 | std::cout << -1 << "\n"; 22 | return; 23 | } 24 | std::cout << cnt / 2 << "\n"; 25 | } 26 | 27 | int main() { 28 | std::ios::sync_with_stdio(false); 29 | std::cin.tie(nullptr); 30 | 31 | int t; 32 | std::cin >> t; 33 | 34 | while (t--) { 35 | solve(); 36 | } 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /1479/1479A-A-SearchingLocalMinimum.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1479/problem/A 2 | // time:2021-02-07 17:43:53 3 | // name:A-SearchingLocalMinimum 4 | 5 | #include 6 | using i64 = long long; 7 | using u64 = unsigned long long; 8 | using u32 = unsigned; 9 | int query(int x) { 10 | std::cout << "? " << x + 1 << std::endl; 11 | std::cin >> x; 12 | return x - 1; 13 | } 14 | int main() { 15 | std::ios::sync_with_stdio(false); 16 | std::cin.tie(nullptr); 17 | int n; 18 | std::cin >> n; 19 | int l = -1, r = n; 20 | while (r - l > 2) { 21 | int m1 = (l + r) / 2; 22 | int m2 = m1 + 1; 23 | if (query(m1) > query(m2)) { 24 | l = m1; 25 | } else { 26 | r = m2; 27 | } 28 | } 29 | std::cout << "! " << r << "\n"; 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /1574/1574B-B-CombinatoricsHomework.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1574/problem/B 2 | //time:2022-06-12 07:23:42 3 | //name:B-CombinatoricsHomework 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int a[3], m; 11 | std::cin >> a[0] >> a[1] >> a[2] >> m; 12 | 13 | std::sort(a, a + 3); 14 | 15 | if (std::max(0, a[0] - 1) + std::max(0, a[1] - 1) + std::max(0, a[2] - 1) >= m && 16 | a[0] + a[1] + m >= a[2] - 1) { 17 | std::cout << "YES\n"; 18 | } else { 19 | std::cout << "NO\n"; 20 | } 21 | } 22 | 23 | int main() { 24 | std::ios::sync_with_stdio(false); 25 | std::cin.tie(nullptr); 26 | 27 | int t; 28 | std::cin >> t; 29 | 30 | while (t--) { 31 | solve(); 32 | } 33 | 34 | return 0; 35 | } 36 | 37 | -------------------------------------------------------------------------------- /1694/1694B-B-ParanoidString.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1694/problem/B 2 | //time:2022-06-27 11:21:45 3 | //name:B-ParanoidString 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | std::string s; 14 | std::cin >> s; 15 | 16 | i64 ans = 0; 17 | for (int i = 0; i < n; i++) { 18 | if (i > 0 && s[i] != s[i - 1]) { 19 | ans += i + 1; 20 | } else { 21 | ans += 1; 22 | } 23 | } 24 | 25 | std::cout << ans << "\n"; 26 | } 27 | 28 | int main() { 29 | std::ios::sync_with_stdio(false); 30 | std::cin.tie(nullptr); 31 | 32 | int t; 33 | std::cin >> t; 34 | 35 | while (t--) { 36 | solve(); 37 | } 38 | 39 | return 0; 40 | } 41 | 42 | -------------------------------------------------------------------------------- /40/40D-D-InterestingSequence.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/40/problem/D 2 | // time:2023-04-23 08:46:26 3 | // name:D-InterestingSequence 4 | 5 | A = int(input()) 6 | 7 | pw = 0 8 | 9 | while A % 12 == 0 : 10 | A //= 12 11 | pw += 1 12 | 13 | x, y = 2, 13 14 | p = 1 15 | 16 | pos = -1 17 | 18 | while x <= A : 19 | if x == A : 20 | pos = p 21 | x, y = y, 13 * y - 12 * x 22 | p += 1 23 | 24 | if pos == -1 : 25 | print('NO') 26 | exit() 27 | 28 | print('YES') 29 | print(1) 30 | print(pos + 2 * pw) 31 | 32 | x, y = 2, 13 33 | p = 1 34 | 35 | oth = [] 36 | 37 | while p <= pos + 2 * pw : 38 | if (pos - p) % 2 == 0 and pos != p : 39 | oth.append(x * 12 ** ((pos + 2 * pw - p) // 2)) 40 | x, y = y, 13 * y - 12 * x 41 | p += 1 42 | print(len(oth)) 43 | print(' '.join(map(str, oth))) 44 | -------------------------------------------------------------------------------- /1622/1622A-A-ConstructaRectangle.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1622/problem/A 2 | //time:2022-06-09 15:42:13 3 | //name:A-ConstructaRectangle 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | std::array l; 11 | for (int i = 0; i < 3; i++) { 12 | std::cin >> l[i]; 13 | } 14 | 15 | std::sort(l.begin(), l.end()); 16 | 17 | if (l[0] + l[1] == l[2] || (l[0] % 2 == 0 && l[1] == l[2]) || (l[2] % 2 == 0 && l[0] == l[1])) { 18 | std::cout << "YES\n"; 19 | } else { 20 | std::cout << "NO\n"; 21 | } 22 | } 23 | 24 | int main() { 25 | std::ios::sync_with_stdio(false); 26 | std::cin.tie(nullptr); 27 | 28 | int t; 29 | std::cin >> t; 30 | 31 | while (t--) { 32 | solve(); 33 | } 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /1741/1741B-B-FunnyPermutation.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1741/problem/B 2 | // time:2022-10-11 17:43:35 3 | // name:B-FunnyPermutation 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | if (n == 3) { 14 | std::cout << -1 << "\n"; 15 | return; 16 | } 17 | if (n == 2) { 18 | std::cout << 2 << " " << 1 << "\n"; 19 | return; 20 | } 21 | 22 | for (int i = 0; i < n; i++) { 23 | std::cout << (i + 2) % n + 1 << " \n"[i == n - 1]; 24 | } 25 | } 26 | 27 | int main() { 28 | std::ios::sync_with_stdio(false); 29 | std::cin.tie(nullptr); 30 | 31 | int t; 32 | std::cin >> t; 33 | 34 | while (t--) { 35 | solve(); 36 | } 37 | 38 | return 0; 39 | } 40 | 41 | -------------------------------------------------------------------------------- /710/710C-C-MagicOddSquare.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/710/problem/C 2 | // time:2021-07-07 22:14:08 3 | // name:C-MagicOddSquare 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | int n; 14 | std::cin >> n; 15 | 16 | int m = (n - 1) / 2; 17 | int odd = 1, even = 2; 18 | for (int i = 0; i < n; i++) { 19 | for (int j = 0; j < n; j++) { 20 | int x; 21 | if (std::abs(i - m) + std::abs(j - m) <= m) { 22 | x = odd; 23 | odd += 2; 24 | } else { 25 | x = even; 26 | even += 2; 27 | } 28 | std::cout << x << " \n"[j == n - 1]; 29 | } 30 | } 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /495/495B-B-ModularEquations.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/495/problem/B 2 | // time:2021-06-21 19:16:43 3 | // name:B-ModularEquations 4 | 5 | #include 6 | int main() { 7 | std::ios::sync_with_stdio(false); 8 | std::cin.tie(nullptr); 9 | int a, b; 10 | std::cin >> a >> b; 11 | if (a == b) { 12 | std::cout << "infinity\n"; 13 | return 0; 14 | } 15 | if (a < b) { 16 | std::cout << "0\n"; 17 | return 0; 18 | } 19 | int n = a - b; 20 | int ans = 0; 21 | for (int i = 1; i * i <= n; i++) { 22 | if (n % i == 0) { 23 | if (i > b) { 24 | ans++; 25 | } 26 | if (i * i != n && n / i > b) { 27 | ans++; 28 | } 29 | } 30 | } 31 | std::cout << ans << "\n"; 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /1550/1550B-B-MaximumCostDeletion.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1550/problem/B 2 | //time:2021-07-14 17:40:45 3 | //name:B-MaximumCostDeletion 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | int t; 14 | std::cin >> t; 15 | while (t--) { 16 | int n, a, b; 17 | std::cin >> n >> a >> b; 18 | 19 | std::string s; 20 | std::cin >> s; 21 | 22 | int cnt = 1; 23 | for (int i = 1; i < n; i++) { 24 | if (s[i] != s[i - 1]) { 25 | cnt++; 26 | } 27 | } 28 | 29 | int ans = a * n + std::max(n * b, (cnt / 2 + 1) * b); 30 | 31 | std::cout << ans << "\n"; 32 | } 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /1733/1733A-A-ConsecutiveSum.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1733/problem/A 2 | //time:2022-09-19 17:37:51 3 | //name:A-ConsecutiveSum 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n, k; 11 | std::cin >> n >> k; 12 | 13 | std::vector a(n); 14 | for (int i = 0; i < n; i++) { 15 | std::cin >> a[i]; 16 | } 17 | 18 | for (int i = k; i < n; i++) { 19 | a[i % k] = std::max(a[i % k], a[i]); 20 | } 21 | 22 | i64 ans = std::accumulate(a.begin(), a.begin() + k, 0LL); 23 | std::cout << ans << "\n"; 24 | } 25 | 26 | int main() { 27 | std::ios::sync_with_stdio(false); 28 | std::cin.tie(nullptr); 29 | 30 | int t; 31 | std::cin >> t; 32 | 33 | while (t--) { 34 | solve(); 35 | } 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /1734/1734A-A-SelectThreeSticks.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1734/problem/A 2 | //time:2022-09-23 15:31:03 3 | //name:A-SelectThreeSticks 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | std::vector a(n); 14 | for (int i = 0; i < n; i++) { 15 | std::cin >> a[i]; 16 | } 17 | 18 | std::sort(a.begin(), a.end()); 19 | 20 | int ans = 2E9; 21 | for (int i = 0; i < n - 2; i++) { 22 | ans = std::min(ans, a[i + 2] - a[i]); 23 | } 24 | std::cout << ans << "\n"; 25 | } 26 | 27 | int main() { 28 | std::ios::sync_with_stdio(false); 29 | std::cin.tie(nullptr); 30 | 31 | int t; 32 | std::cin >> t; 33 | 34 | while (t--) { 35 | solve(); 36 | } 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /1472/1472C-C-LongJumps.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1472/problem/C 2 | //time:2021-01-04 17:40:17 3 | //name:C-LongJumps 4 | 5 | #include 6 | using i64 = long long; 7 | using u64 = unsigned long long; 8 | using u32 = unsigned; 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | int t; 13 | std::cin >> t; 14 | while (t--) { 15 | int n; 16 | std::cin >> n; 17 | std::vector a(n); 18 | for (int i = 0; i < n; i++) { 19 | std::cin >> a[i]; 20 | } 21 | int ans = 0; 22 | for (int i = n - 1; i >= 0; i--) { 23 | if (i + a[i] < n) { 24 | a[i] += a[i + a[i]]; 25 | } 26 | ans = std::max(ans, a[i]); 27 | } 28 | std::cout << ans << "\n"; 29 | } 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /1697/1697B-B-Promo.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1697/problem/B 2 | //time:2022-06-12 17:53:28 3 | //name:B-Promo 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | int n, q; 14 | std::cin >> n >> q; 15 | 16 | std::vector p(n); 17 | for (int i = 0; i < n; i++) { 18 | std::cin >> p[i]; 19 | } 20 | 21 | std::sort(p.begin(), p.end()); 22 | 23 | std::vector sum(n + 1); 24 | for (int i = 0; i < n; i++) { 25 | sum[i + 1] = sum[i] + p[i]; 26 | } 27 | 28 | for (int i = 0; i < q; i++) { 29 | int x, y; 30 | std::cin >> x >> y; 31 | 32 | std::cout << sum[n - (x - y)] - sum[n - x] << "\n"; 33 | } 34 | 35 | return 0; 36 | } 37 | 38 | -------------------------------------------------------------------------------- /793/793A-A-Olegandshares.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/793/problem/A 2 | //time:2021-01-03 17:25:49 3 | //name:A-Olegandshares 4 | 5 | #include 6 | using i64 = long long; 7 | using u64 = unsigned long long; 8 | using u32 = unsigned; 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | int n, k; 13 | std::cin >> n >> k; 14 | std::vector a(n); 15 | for (int i = 0; i < n; i++) { 16 | std::cin >> a[i]; 17 | } 18 | for (int i = 0; i < n; i++) { 19 | if (a[i] % k != a[0] % k) { 20 | std::cout << "-1\n"; 21 | return 0; 22 | } 23 | } 24 | i64 sum = std::accumulate(a.begin(), a.end(), 0ll); 25 | int mn = *std::min_element(a.begin(), a.end()); 26 | i64 ans = (sum - i64(n) * mn) / k; 27 | std::cout << ans << "\n"; 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /1511/1511D-D-MinCostString.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1511/problem/D 2 | //time:2022-09-22 13:59:15 3 | //name:D-MinCostString 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | int n, k; 14 | std::cin >> n >> k; 15 | 16 | const int m = (n - 1) / (k * k) + 1; 17 | 18 | std::vector a; 19 | 20 | for (int i = 0; i < k; i++) { 21 | for (int j = k - 1; j > i; j--) { 22 | a.push_back(i); 23 | a.push_back(j); 24 | } 25 | } 26 | for (int i = k - 1; i >= 0; i--) { 27 | a.push_back(i); 28 | } 29 | 30 | for (int i = 0; i < n; i++) { 31 | std::cout << char('a' + a[i % (k * k)]); 32 | } 33 | std::cout << "\n"; 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /496/496B-B-SecretCombination.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/496/problem/B 2 | // time:2021-06-20 20:45:35 3 | // name:B-SecretCombination 4 | 5 | #include 6 | using i64 = long long; 7 | int main() { 8 | std::ios::sync_with_stdio(false); 9 | std::cin.tie(nullptr); 10 | int n; 11 | std::cin >> n; 12 | std::string s; 13 | std::cin >> s; 14 | std::string ans(s); 15 | for (int i = 0; i < n; i++) { 16 | for (int j = 0; j < 10; j++) { 17 | ans = std::min(ans, s); 18 | for (int k = 0; k < n; k++) { 19 | if (s[k] == '9') { 20 | s[k] = '0'; 21 | } else { 22 | s[k]++; 23 | } 24 | } 25 | } 26 | std::rotate(s.begin(), s.begin() + 1, s.end()); 27 | } 28 | std::cout << ans << "\n"; 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /1807/1807C-C-FindandReplace.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1807/problem/C 2 | // time:2023-03-20 15:55:19 3 | // name:C-FindandReplace 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | std::string s; 14 | std::cin >> s; 15 | 16 | int a[26]; 17 | std::fill(a, a + 26, -1); 18 | for (int i = 0; i < n; i++) { 19 | int x = s[i] - 'a'; 20 | if (a[x] == !(i % 2)) { 21 | std::cout << "NO\n"; 22 | return; 23 | } 24 | a[x] = i % 2; 25 | } 26 | std::cout << "YES\n"; 27 | } 28 | 29 | int main() { 30 | std::ios::sync_with_stdio(false); 31 | std::cin.tie(nullptr); 32 | 33 | int t; 34 | std::cin >> t; 35 | 36 | while (t--) { 37 | solve(); 38 | } 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /236/236B-B-EasyNumberChallenge.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/236/problem/B 2 | // time:2023-04-30 11:30:57 3 | // name:B-EasyNumberChallenge 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | constexpr int N = 1E6; 10 | 11 | int main() { 12 | std::ios::sync_with_stdio(false); 13 | std::cin.tie(nullptr); 14 | 15 | std::vector d(N + 1); 16 | for (int i = 1; i <= N; i++) { 17 | for (int j = i; j <= N; j += i) { 18 | d[j]++; 19 | } 20 | } 21 | 22 | int a, b, c; 23 | std::cin >> a >> b >> c; 24 | 25 | int ans = 0; 26 | for (int i = 1; i <= a; i++) { 27 | for (int j = 1; j <= b; j++) { 28 | for (int k = 1; k <= c; k++) { 29 | ans += d[i * j * k]; 30 | } 31 | } 32 | } 33 | std::cout << ans << "\n"; 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /1670/1670D-D-VerySuspicious.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1670/problem/D 2 | // time:2022-05-06 18:47:44 3 | // name:D-VerySuspicious 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | int l = 1, r = 40000; 14 | while (l < r) { 15 | int m = (l + r) / 2; 16 | int a = m / 3; 17 | int b = (m - a) / 2; 18 | int c = m - a - b; 19 | if ((a * b + b * c + c * a) * 2 >= n) { 20 | r = m; 21 | } else { 22 | l = m + 1; 23 | } 24 | } 25 | 26 | std::cout << l << "\n"; 27 | } 28 | 29 | int main() { 30 | std::ios::sync_with_stdio(false); 31 | std::cin.tie(nullptr); 32 | 33 | int t; 34 | std::cin >> t; 35 | 36 | while (t--) { 37 | solve(); 38 | } 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /378/378B-B-Semifinals.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/378/problem/B 2 | // time:2021-06-19 22:56:54 3 | // name:B-Semifinals 4 | 5 | #include 6 | int main() { 7 | std::ios::sync_with_stdio(false); 8 | std::cin.tie(nullptr); 9 | int n; 10 | std::cin >> n; 11 | std::vector> a; 12 | std::vector ans(2, std::string(n, '0')); 13 | for (int i = 0; i < n / 2; i++) { 14 | ans[0][i] = ans[1][i] = '1'; 15 | } 16 | for (int i = 0; i < n; i++) { 17 | int x, y; 18 | std::cin >> x >> y; 19 | a.emplace_back(x, i); 20 | a.emplace_back(y, n + i); 21 | } 22 | std::sort(a.begin(), a.end()); 23 | for (int i = 0; i < n; i++) { 24 | int j = a[i].second; 25 | ans[j / n][j % n] = '1'; 26 | } 27 | std::cout << ans[0] << "\n"; 28 | std::cout << ans[1] << "\n"; 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /712/712B-B-MemoryandTrident.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/712/problem/B 2 | // time:2023-03-15 11:21:43 3 | // name:B-MemoryandTrident 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | std::string s; 14 | std::cin >> s; 15 | 16 | if (s.size() % 2 == 1) { 17 | std::cout << -1 << "\n"; 18 | return 0; 19 | } 20 | 21 | int x = 0, y = 0; 22 | for (auto c : s) { 23 | if (c == 'L') { 24 | x--; 25 | } else if (c == 'R') { 26 | x++; 27 | } else if (c == 'U') { 28 | y++; 29 | } else { 30 | y--; 31 | } 32 | } 33 | 34 | int ans = (std::abs(x) + std::abs(y)) / 2; 35 | std::cout << ans << "\n"; 36 | 37 | return 0; 38 | } 39 | 40 | -------------------------------------------------------------------------------- /1684/1684D-D-Traps.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1684/problem/D 2 | // time:2022-05-19 17:51:46 3 | // name:D-Traps 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n, k; 11 | std::cin >> n >> k; 12 | 13 | i64 ans = 0; 14 | std::vector a(n); 15 | for (int i = 0; i < n; i++) { 16 | std::cin >> a[i]; 17 | ans += a[i]; 18 | a[i] = n - i - a[i]; 19 | } 20 | std::sort(a.begin(), a.end()); 21 | for (int i = 0; i < k; i++) { 22 | ans += a[i]; 23 | } 24 | ans -= 1LL * k * (k + 1) / 2; 25 | 26 | std::cout << ans << "\n"; 27 | } 28 | 29 | int main() { 30 | std::ios::sync_with_stdio(false); 31 | std::cin.tie(nullptr); 32 | 33 | int t; 34 | std::cin >> t; 35 | 36 | while (t--) { 37 | solve(); 38 | } 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /1746/1746B-B-Rebellion.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1746/problem/B 2 | // time:2022-10-15 17:45:42 3 | // name:B-Rebellion 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | std::vector a(n); 14 | for (int i = 0; i < n; i++) { 15 | std::cin >> a[i]; 16 | } 17 | 18 | int c1 = 0, c0 = std::count(a.begin(), a.end(), 0); 19 | int ans = c0; 20 | for (int i = 0; i < n; i++) { 21 | c1 += a[i]; 22 | c0 -= !a[i]; 23 | ans = std::min(ans, std::max(c0, c1)); 24 | } 25 | std::cout << ans << "\n"; 26 | } 27 | 28 | int main() { 29 | std::ios::sync_with_stdio(false); 30 | std::cin.tie(nullptr); 31 | 32 | int t; 33 | std::cin >> t; 34 | 35 | while (t--) { 36 | solve(); 37 | } 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /800/800B-B-VolatileKite.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/800/problem/B 2 | //time:2021-01-03 15:45:02 3 | //name:B-VolatileKite 4 | 5 | #include 6 | using i64 = long long; 7 | using u64 = unsigned long long; 8 | using u32 = unsigned; 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | int n; 13 | std::cin >> n; 14 | std::vector x(n), y(n); 15 | for (int i = 0; i < n; i++) { 16 | std::cin >> x[i] >> y[i]; 17 | } 18 | double ans = 1e10; 19 | for (int i = 0; i < n; i++) { 20 | int u = (i - 1 + n) % n, v = (i + 1) % n; 21 | ans = std::min(ans, (i64(x[u] - x[i]) * (y[v] - y[i]) - i64(x[v] - x[i]) * (y[u] - y[i])) / std::sqrt(i64(x[u] - x[v]) * (x[u] - x[v]) + i64(y[u] - y[v]) * (y[u] - y[v]))); 22 | } 23 | std::cout << std::fixed << std::setprecision(10) << ans / 2 << "\n"; 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /1485/1485A-A-AddandDivide.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1485/problem/A 2 | // time:2021-02-12 17:51:43 3 | // name:A-AddandDivide 4 | 5 | #include 6 | using i64 = long long; 7 | using u64 = unsigned long long; 8 | using u32 = unsigned; 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | int t; 13 | std::cin >> t; 14 | while (t--) { 15 | int a, b; 16 | std::cin >> a >> b; 17 | int ans = 1e9; 18 | for (int i = 0; i < 30; i++) { 19 | if (b + i == 1) { 20 | continue; 21 | } 22 | int res = i; 23 | int x = a; 24 | while (x > 0) { 25 | x /= b + i; 26 | res++; 27 | } 28 | ans = std::min(ans, res); 29 | } 30 | std::cout << ans << "\n"; 31 | } 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /158/158D-D-IceSculptures.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/158/problem/D 2 | // time:2023-04-26 19:53:21 3 | // name:D-IceSculptures 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | int n; 14 | std::cin >> n; 15 | 16 | std::vector t(n); 17 | for (int i = 0; i < n; i++) { 18 | std::cin >> t[i]; 19 | } 20 | 21 | i64 ans = -1E18; 22 | for (int x = 3; x <= n; x++) { 23 | if (n % x) { 24 | continue; 25 | } 26 | for (int i = 0; i < n/x; i++) { 27 | i64 s = 0; 28 | for (int j = i; j < n; j += n/x) { 29 | s += t[j]; 30 | } 31 | ans = std::max(ans, s); 32 | } 33 | } 34 | std::cout << ans << "\n"; 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /1539/1539C-C-StableGroups.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1539/problem/C 2 | // time:2021-06-20 13:21:28 3 | // name:C-StableGroups 4 | 5 | #include 6 | using i64 = long long; 7 | int main() { 8 | std::ios::sync_with_stdio(false); 9 | std::cin.tie(nullptr); 10 | int n; 11 | i64 k, x; 12 | std::cin >> n >> k >> x; 13 | int ans = 0; 14 | std::vector a(n); 15 | for (int i = 0; i < n; i++) { 16 | std::cin >> a[i]; 17 | } 18 | std::sort(a.begin(), a.end()); 19 | std::vector v; 20 | for (int i = 0; i < n - 1; i++) { 21 | v.push_back(std::max(0, a[i + 1] - a[i] - 1) / x); 22 | } 23 | std::sort(v.begin(), v.end()); 24 | for (int i = 0; i < n - 1; i++) { 25 | if (k >= v[i]) { 26 | ans++; 27 | k -= v[i]; 28 | } 29 | } 30 | std::cout << n - ans << "\n"; 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /1822/1822D-D-Super-Permutation.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1822/problem/D 2 | // time:2023-04-25 15:33:07 3 | // name:D-Super-Permutation 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | if (n == 1) { 14 | std::cout << 1 << "\n"; 15 | } else if (n % 2 == 1) { 16 | std::cout << -1 << "\n"; 17 | } else { 18 | for (int i = 0; i < n; i++) { 19 | int x = i % 2 ? n - i : i; 20 | if (!i) { 21 | x = n; 22 | } 23 | std::cout << x << " \n"[i == n-1]; 24 | } 25 | } 26 | } 27 | 28 | int main() { 29 | std::ios::sync_with_stdio(false); 30 | std::cin.tie(nullptr); 31 | 32 | int t; 33 | std::cin >> t; 34 | 35 | while (t--) { 36 | solve(); 37 | } 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /714/714B-B-FilyaandHomework.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/714/problem/B 2 | // time:2021-07-07 17:14:04 3 | // name:B-FilyaandHomework 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | int n; 14 | std::cin >> n; 15 | std::set s; 16 | for (int i = 0; i < n; i++) { 17 | int x; 18 | std::cin >> x; 19 | s.insert(x); 20 | } 21 | 22 | if (s.size() <= 2) { 23 | std::cout << "YES\n"; 24 | return 0; 25 | } 26 | 27 | if (s.size() >= 4) { 28 | std::cout << "NO\n"; 29 | return 0; 30 | } 31 | 32 | if (*s.begin() + *s.rbegin() == 2 * *std::next(s.begin())) { 33 | std::cout << "YES\n"; 34 | } else { 35 | std::cout << "NO\n"; 36 | } 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /1728/1728B-B-BestPermutation.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1728/problem/B 2 | //time:2022-09-08 17:41:32 3 | //name:B-BestPermutation 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | if (n % 2 == 0) { 14 | for (int i = n - 2; i >= 1; i--) { 15 | std::cout << i << " "; 16 | } 17 | std::cout << n - 1 << " " << n << "\n"; 18 | } else { 19 | for (int i = n - 2; i >= 4; i--) { 20 | std::cout << i << " "; 21 | } 22 | std::cout << 1 << " " << 2 << " " << 3 << " " << n - 1 << " " << n << "\n"; 23 | } 24 | } 25 | 26 | int main() { 27 | std::ios::sync_with_stdio(false); 28 | std::cin.tie(nullptr); 29 | 30 | int t; 31 | std::cin >> t; 32 | 33 | while (t--) { 34 | solve(); 35 | } 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /1616/1616B-B-MirrorintheString.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1616/problem/B 2 | //time:2021-12-29 18:42:13 3 | //name:B-MirrorintheString 4 | 5 | #include 6 | 7 | void solve() { 8 | int n; 9 | std::cin >> n; 10 | 11 | std::string s; 12 | std::cin >> s; 13 | 14 | if (n == 1 || s[0] <= s[1]) { 15 | std::cout << s[0] << s[0] << "\n"; 16 | } else { 17 | int i = 1; 18 | while (i < n && s[i] <= s[i - 1]) { 19 | i++; 20 | } 21 | s = s.substr(0, i); 22 | std::cout << s; 23 | std::reverse(s.begin(), s.end()); 24 | std::cout << s << "\n"; 25 | } 26 | } 27 | 28 | int main() { 29 | std::ios::sync_with_stdio(false); 30 | std::cin.tie(nullptr); 31 | 32 | int t; 33 | std::cin >> t; 34 | 35 | while (t--) { 36 | solve(); 37 | } 38 | 39 | return 0; 40 | } 41 | 42 | -------------------------------------------------------------------------------- /1618/1618D-D-ArrayandOperations.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1618/problem/D 2 | // time:2021-12-22 10:23:44 3 | // name:D-ArrayandOperations 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n, k; 11 | std::cin >> n >> k; 12 | 13 | std::vector a(n); 14 | for (int i = 0; i < n; i++) { 15 | std::cin >> a[i]; 16 | } 17 | std::sort(a.begin(), a.end(), std::greater()); 18 | 19 | int ans = 0; 20 | for (int i = 0; i < k; i++) { 21 | ans += a[i + k] / a[i]; 22 | } 23 | ans += std::accumulate(a.begin() + 2 * k, a.end(), 0); 24 | std::cout << ans << "\n"; 25 | } 26 | 27 | int main() { 28 | std::ios::sync_with_stdio(false); 29 | std::cin.tie(nullptr); 30 | 31 | int t; 32 | std::cin >> t; 33 | 34 | while (t--) { 35 | solve(); 36 | } 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /1692/1692G-G-2^Sort.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1692/problem/G 2 | //time:2022-06-14 17:49:20 3 | //name:G-2^Sort 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n, k; 11 | std::cin >> n >> k; 12 | 13 | std::vector a(n); 14 | for (int i = 0; i < n; i++) { 15 | std::cin >> a[i]; 16 | } 17 | 18 | int cur = 0, ans = 0; 19 | for (int i = 0; i < n - 1; i++) { 20 | if (a[i] < 2 * a[i + 1]) { 21 | cur++; 22 | ans += (cur >= k); 23 | } else { 24 | cur = 0; 25 | } 26 | } 27 | std::cout << ans << "\n"; 28 | } 29 | 30 | int main() { 31 | std::ios::sync_with_stdio(false); 32 | std::cin.tie(nullptr); 33 | 34 | int t; 35 | std::cin >> t; 36 | 37 | while (t--) { 38 | solve(); 39 | } 40 | 41 | return 0; 42 | } 43 | 44 | -------------------------------------------------------------------------------- /1823/1823A-A-A-characteristic.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1823/problem/A 2 | // time:2023-04-28 08:40:27 3 | // name:A-A-characteristic 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n, k; 11 | std::cin >> n >> k; 12 | 13 | for (int c = 0; c <= n; c++) { 14 | int res = c * (c - 1) / 2 + (n - c) * (n - c - 1) / 2; 15 | if (res == k) { 16 | std::cout << "YES\n"; 17 | for (int i = 0; i < n; i++) { 18 | std::cout << (i < c ? 1 : -1) << " \n"[i == n - 1]; 19 | } 20 | return; 21 | } 22 | } 23 | std::cout << "NO\n"; 24 | } 25 | 26 | int main() { 27 | std::ios::sync_with_stdio(false); 28 | std::cin.tie(nullptr); 29 | 30 | int t; 31 | std::cin >> t; 32 | 33 | while (t--) { 34 | solve(); 35 | } 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /1698/1698B-B-RisingSand.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1698/problem/B 2 | // time:2022-07-02 11:08:55 3 | // name:B-RisingSand 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n, k; 11 | std::cin >> n >> k; 12 | 13 | int ans = 0; 14 | 15 | std::vector a(n); 16 | for (int i = 0; i < n; i++) { 17 | std::cin >> a[i]; 18 | } 19 | 20 | for (int i = 1; i < n - 1; i++) { 21 | ans += (a[i] > a[i - 1] + a[i + 1]); 22 | } 23 | 24 | if (k == 1) { 25 | std::cout << (n - 1) / 2 << "\n"; 26 | } else { 27 | std::cout << ans << "\n"; 28 | } 29 | } 30 | 31 | int main() { 32 | std::ios::sync_with_stdio(false); 33 | std::cin.tie(nullptr); 34 | 35 | int t; 36 | std::cin >> t; 37 | 38 | while (t--) { 39 | solve(); 40 | } 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /1686/1686A-A-EverythingEverywhereAllButOne.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1686/problem/A 2 | // time:2022-05-30 06:03:41 3 | // name:A-EverythingEverywhereAllButOne 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | std::vector a(n); 14 | for (int i = 0; i < n; i++) { 15 | std::cin >> a[i]; 16 | } 17 | 18 | int sum = std::accumulate(a.begin(), a.end(), 0); 19 | for (int i = 0; i < n; i++) { 20 | if (sum == n * a[i]) { 21 | std::cout << "YES\n"; 22 | return; 23 | } 24 | } 25 | 26 | std::cout << "NO\n"; 27 | } 28 | 29 | int main() { 30 | std::ios::sync_with_stdio(false); 31 | std::cin.tie(nullptr); 32 | 33 | int t; 34 | std::cin >> t; 35 | 36 | while (t--) { 37 | solve(); 38 | } 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /1733/1733B-B-RuleofLeague.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1733/problem/B 2 | //time:2022-09-19 17:40:46 3 | //name:B-RuleofLeague 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n, x, y; 11 | std::cin >> n >> x >> y; 12 | 13 | if (x > y) { 14 | std::swap(x, y); 15 | } 16 | if (x != 0) { 17 | std::cout << -1 << "\n"; 18 | return; 19 | } 20 | 21 | if (y == 0 || (n - 1) % y != 0) { 22 | std::cout << -1 << "\n"; 23 | return; 24 | } 25 | 26 | for (int i = 0; i < n - 1; i++) { 27 | std::cout << i - i % y + 2 << " \n"[i == n - 2]; 28 | } 29 | } 30 | 31 | int main() { 32 | std::ios::sync_with_stdio(false); 33 | std::cin.tie(nullptr); 34 | 35 | int t; 36 | std::cin >> t; 37 | 38 | while (t--) { 39 | solve(); 40 | } 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /609/609C-C-LoadBalancing.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/609/problem/C 2 | // time:2023-04-24 08:23:26 3 | // name:C-LoadBalancing 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | int n; 14 | std::cin >> n; 15 | 16 | std::vector m(n); 17 | for (int i = 0; i < n; i++) { 18 | std::cin >> m[i]; 19 | } 20 | 21 | int sum = std::accumulate(m.begin(), m.end(), 0); 22 | int lo = sum / n; 23 | int hi = (sum+n-1) / n; 24 | 25 | int l = 0, r = 0; 26 | for (int i = 0; i < n; i++) { 27 | if (m[i] < lo) { 28 | l += lo - m[i]; 29 | } 30 | if (m[i] > hi) { 31 | r += m[i] - hi; 32 | } 33 | } 34 | int ans = std::max(l, r); 35 | 36 | std::cout << ans << "\n"; 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /641/641A-A-LittleArtemandGrasshopper.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/641/problem/A 2 | //time:2021-07-09 22:03:49 3 | //name:A-LittleArtemandGrasshopper 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | int n; 14 | std::cin >> n; 15 | 16 | std::string s; 17 | std::cin >> s; 18 | 19 | std::vector d(n); 20 | for (int i = 0; i < n; i++) { 21 | std::cin >> d[i]; 22 | } 23 | 24 | int p = 0; 25 | for (int t = 0; t < n; t++) { 26 | if (s[p] == '<') { 27 | p -= d[p]; 28 | } else { 29 | p += d[p]; 30 | } 31 | if (p < 0 || p >= n) { 32 | std::cout << "FINITE\n"; 33 | return 0; 34 | } 35 | } 36 | 37 | std::cout << "INFINITE\n"; 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /1674/1674D-D-A-B-CSort.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1674/problem/D 2 | // time:2022-05-02 17:48:01 3 | // name:D-A-B-CSort 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | std::vector a(n); 14 | for (int i = 0; i < n; i++) { 15 | std::cin >> a[i]; 16 | } 17 | 18 | for (int i = n - 2; i >= 0; i -= 2) { 19 | if (a[i] > a[i + 1]) { 20 | std::swap(a[i], a[i + 1]); 21 | } 22 | } 23 | 24 | if (std::is_sorted(a.begin(), a.end())) { 25 | std::cout << "YES\n"; 26 | } else { 27 | std::cout << "NO\n"; 28 | } 29 | } 30 | 31 | int main() { 32 | std::ios::sync_with_stdio(false); 33 | std::cin.tie(nullptr); 34 | 35 | int t; 36 | std::cin >> t; 37 | 38 | while (t--) { 39 | solve(); 40 | } 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /1729/1729E-E-GuesstheCycleSize.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1729/problem/E 2 | //time:2022-09-12 17:49:50 3 | //name:E-GuesstheCycleSize 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | for (int i = 1; ; i++) { 14 | for (int j = 1; j < i; j++) { 15 | i64 x, y; 16 | std::cout << "? " << i << " " << j << std::endl; 17 | std::cin >> x; 18 | std::cout << "? " << j << " " << i << std::endl; 19 | std::cin >> y; 20 | if (x == -1 || y == -1) { 21 | std::cout << "! " << i - 1 << std::endl; 22 | return 0; 23 | } 24 | if (x != y) { 25 | std::cout << "! " << x + y << std::endl; 26 | return 0; 27 | } 28 | } 29 | } 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /280/280B-B-MaximumXorSecondary.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/280/problem/B 2 | // time:2023-04-30 08:44:00 3 | // name:B-MaximumXorSecondary 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | int n; 14 | std::cin >> n; 15 | 16 | std::vector a(n); 17 | for (int i = 0; i < n; i++) { 18 | std::cin >> a[i]; 19 | } 20 | 21 | int ans = 0; 22 | std::vector s; 23 | for (int i = 0; i < n; i++) { 24 | while (!s.empty() && a[i] > a[s.back()]) { 25 | ans = std::max(a[i] ^ a[s.back()], ans); 26 | s.pop_back(); 27 | } 28 | if (!s.empty()) { 29 | ans = std::max(a[i] ^ a[s.back()], ans); 30 | } 31 | s.push_back(i); 32 | } 33 | 34 | std::cout << ans << "\n"; 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /1615/1615B-B-AndIt'sNon-Zero.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1615/problem/B 2 | //time:2021-12-24 17:39:46 3 | //name:B-AndIt'sNon-Zero 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int sum[20][200001]; 10 | 11 | void solve() { 12 | int l, r; 13 | std::cin >> l >> r; 14 | 15 | int ans = 0; 16 | for (int i = 0; i < 20; i++) { 17 | ans = std::max(ans, sum[i][r] - sum[i][l - 1]); 18 | } 19 | ans = r - l + 1 - ans; 20 | std::cout << ans << "\n"; 21 | } 22 | 23 | int main() { 24 | std::ios::sync_with_stdio(false); 25 | std::cin.tie(nullptr); 26 | 27 | for (int c = 0; c < 20; c++) { 28 | for (int i = 1; i <= 200000; i++) { 29 | sum[c][i] = sum[c][i - 1] + (i >> c & 1); 30 | } 31 | } 32 | 33 | int t; 34 | std::cin >> t; 35 | 36 | while (t--) { 37 | solve(); 38 | } 39 | 40 | return 0; 41 | } 42 | 43 | -------------------------------------------------------------------------------- /493/493B-B-VasyaandWrestling.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/493/problem/B 2 | // time:2021-06-21 19:29:51 3 | // name:B-VasyaandWrestling 4 | 5 | #include 6 | int main() { 7 | std::ios::sync_with_stdio(false); 8 | std::cin.tie(nullptr); 9 | int n; 10 | std::cin >> n; 11 | std::vector a, b; 12 | int last = 0; 13 | for (int i = 0; i < n; i++) { 14 | int x; 15 | std::cin >> x; 16 | if (x > 0) { 17 | a.push_back(x); 18 | last = 0; 19 | } else { 20 | b.push_back(-x); 21 | last = 1; 22 | } 23 | } 24 | auto suma = std::accumulate(a.begin(), a.end(), 0ll); 25 | auto sumb = std::accumulate(b.begin(), b.end(), 0ll); 26 | if (suma > sumb || (suma == sumb && (a > b || (a == b && last == 0)))) { 27 | std::cout << "first\n"; 28 | } else { 29 | std::cout << "second\n"; 30 | } 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /1525/1525B-B-PermutationSort.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1525/problem/B 2 | // time:2022-03-01 14:35:08 3 | // name:B-PermutationSort 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | std::vector a(n); 14 | for (int i = 0; i < n; i++) { 15 | std::cin >> a[i]; 16 | } 17 | 18 | if (std::is_sorted(a.begin(), a.end())) { 19 | std::cout << "0\n"; 20 | } else if (a[0] == 1 || a[n - 1] == n) { 21 | std::cout << "1\n"; 22 | } else if (a[0] != n || a[n - 1] != 1) { 23 | std::cout << "2\n"; 24 | } else { 25 | std::cout << "3\n"; 26 | } 27 | } 28 | 29 | int main() { 30 | std::ios::sync_with_stdio(false); 31 | std::cin.tie(nullptr); 32 | 33 | int t; 34 | std::cin >> t; 35 | 36 | while (t--) { 37 | solve(); 38 | } 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /1700/1700C-C-HelpingtheNature.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1700/problem/C 2 | //time:2022-06-19 12:15:41 3 | //name:C-HelpingtheNature 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | std::vector a(n); 14 | for (int i = 0; i < n; i++) { 15 | std::cin >> a[i]; 16 | } 17 | 18 | i64 ans = 0; 19 | i64 a0 = a[0]; 20 | for (int i = 0; i < n - 1; i++) { 21 | int b = a[i + 1] - a[i]; 22 | ans += std::abs(b); 23 | if (b < 0) { 24 | a0 += b; 25 | } 26 | } 27 | ans += std::abs(a0); 28 | 29 | std::cout << ans << "\n"; 30 | } 31 | 32 | int main() { 33 | std::ios::sync_with_stdio(false); 34 | std::cin.tie(nullptr); 35 | 36 | int t; 37 | std::cin >> t; 38 | 39 | while (t--) { 40 | solve(); 41 | } 42 | 43 | return 0; 44 | } 45 | 46 | -------------------------------------------------------------------------------- /1734/1734C-C-RemovingSmallestMultiples.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1734/problem/C 2 | //time:2022-09-23 15:34:01 3 | //name:C-RemovingSmallestMultiples 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | std::string t; 14 | std::cin >> t; 15 | 16 | i64 ans = 0; 17 | 18 | std::vector vis(n); 19 | for (int i = 1; i <= n; i++) { 20 | for (int j = i; j <= n && t[j - 1] == '0'; j += i) { 21 | if (!vis[j - 1]) { 22 | vis[j - 1] = true; 23 | ans += i; 24 | } 25 | } 26 | } 27 | 28 | std::cout << ans << "\n"; 29 | } 30 | 31 | int main() { 32 | std::ios::sync_with_stdio(false); 33 | std::cin.tie(nullptr); 34 | 35 | int t; 36 | std::cin >> t; 37 | 38 | while (t--) { 39 | solve(); 40 | } 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /1741/1741A-A-CompareT-ShirtSizes.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1741/problem/A 2 | // time:2022-10-11 17:40:21 3 | // name:A-CompareT-ShirtSizes 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int f(auto a) { 10 | if (a == "M") { 11 | return 0; 12 | } else if (a.back() == 'S') { 13 | return -int(a.length()); 14 | } else { 15 | return a.length(); 16 | } 17 | } 18 | 19 | void solve() { 20 | std::string a, b; 21 | std::cin >> a >> b; 22 | 23 | if (f(a) < f(b)) { 24 | std::cout << "<\n"; 25 | } else if (f(a) == f(b)) { 26 | std::cout << "=\n"; 27 | } else { 28 | std::cout << ">\n"; 29 | } 30 | } 31 | 32 | int main() { 33 | std::ios::sync_with_stdio(false); 34 | std::cin.tie(nullptr); 35 | 36 | int t; 37 | std::cin >> t; 38 | 39 | while (t--) { 40 | solve(); 41 | } 42 | 43 | return 0; 44 | } 45 | 46 | -------------------------------------------------------------------------------- /1807G/1807G1-G1-SubsequenceAddition(EasyVersion).cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1807/problem/G1 2 | // time:2023-03-20 16:12:17 3 | // name:G1-SubsequenceAddition(EasyVersion) 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | std::vector c(n); 14 | for (int i = 0; i < n; i++) { 15 | std::cin >> c[i]; 16 | } 17 | std::sort(c.begin(), c.end()); 18 | 19 | int s = 0; 20 | for (int i = 0; i < n; i++) { 21 | if (s + (i == 0) < c[i]) { 22 | std::cout << "NO\n"; 23 | return; 24 | } 25 | s += c[i]; 26 | } 27 | std::cout << "YES\n"; 28 | } 29 | 30 | int main() { 31 | std::ios::sync_with_stdio(false); 32 | std::cin.tie(nullptr); 33 | 34 | int t; 35 | std::cin >> t; 36 | 37 | while (t--) { 38 | solve(); 39 | } 40 | 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /1807G/1807G2-G2-SubsequenceAddition(HardVersion).cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1807/problem/G2 2 | // time:2023-03-20 16:13:06 3 | // name:G2-SubsequenceAddition(HardVersion) 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | std::vector c(n); 14 | for (int i = 0; i < n; i++) { 15 | std::cin >> c[i]; 16 | } 17 | std::sort(c.begin(), c.end()); 18 | 19 | i64 s = 0; 20 | for (int i = 0; i < n; i++) { 21 | if (s + (i == 0) < c[i]) { 22 | std::cout << "NO\n"; 23 | return; 24 | } 25 | s += c[i]; 26 | } 27 | std::cout << "YES\n"; 28 | } 29 | 30 | int main() { 31 | std::ios::sync_with_stdio(false); 32 | std::cin.tie(nullptr); 33 | 34 | int t; 35 | std::cin >> t; 36 | 37 | while (t--) { 38 | solve(); 39 | } 40 | 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /1817/1817D-D-ToyMachine.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1817/problem/D 2 | // time:2023-04-29 20:38:21 3 | // name:D-ToyMachine 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | using namespace std::literals::string_literals; 10 | 11 | int main() { 12 | std::ios::sync_with_stdio(false); 13 | std::cin.tie(nullptr); 14 | 15 | int n, k; 16 | std::cin >> n >> k; 17 | 18 | n -= 2; 19 | 20 | std::string s; 21 | if (k == (n + 1) / 2) { 22 | s = "DL"s; 23 | } else if (k < (n + 1) / 2) { 24 | for (int i = 0; i < k - 1; i++) { 25 | s += "LDRU"; 26 | } 27 | s += "L"; 28 | } else { 29 | for (int i = 0; i < n - k; i++) { 30 | s += "RDLU"; 31 | } 32 | for (int i = 0; i < n; i++) { 33 | s += "LDLU"; 34 | } 35 | s += "RDL"; 36 | } 37 | std::cout << s << "\n"; 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /1472/1472B-B-FairDivision.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1472/problem/B 2 | //time:2021-01-04 17:38:53 3 | //name:B-FairDivision 4 | 5 | #include 6 | using i64 = long long; 7 | using u64 = unsigned long long; 8 | using u32 = unsigned; 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | int t; 13 | std::cin >> t; 14 | while (t--) { 15 | int n; 16 | std::cin >> n; 17 | int one = 0, two = 0; 18 | for (int i = 0; i < n; i++) { 19 | int a; 20 | std::cin >> a; 21 | if (a == 1) { 22 | one++; 23 | } else { 24 | two++; 25 | } 26 | } 27 | int total = one + 2 * two; 28 | if (total % 2 == 0 && (total % 4 == 0 || one > 0)) { 29 | std::cout << "YES\n"; 30 | } else { 31 | std::cout << "NO\n"; 32 | } 33 | } 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /1674/1674E-E-BreakingtheWall.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1674/problem/E 2 | // time:2022-05-02 17:52:36 3 | // name:E-BreakingtheWall 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | int n; 14 | std::cin >> n; 15 | 16 | std::vector a(n), b(n); 17 | for (int i = 0; i < n; i++) { 18 | std::cin >> a[i]; 19 | b[i] = (a[i] + 1) / 2; 20 | } 21 | std::nth_element(b.begin(), b.begin() + 2, b.end()); 22 | 23 | int ans = b[0] + b[1]; 24 | 25 | for (int i = 0; i < n - 1; i++) { 26 | ans = std::min(ans, std::max({(a[i] + 1) / 2, (a[i + 1] + 1) / 2, (a[i] + a[i + 1] + 2) / 3})); 27 | } 28 | for (int i = 0; i < n - 2; i++) { 29 | ans = std::min(ans, 1 + a[i] / 2 + a[i + 2] / 2); 30 | } 31 | 32 | std::cout << ans << "\n"; 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /724/724E-E-Goodstransportation.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/724/problem/E 2 | // time:2021-12-23 17:49:44 3 | // name:E-Goodstransportation 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | int n, c; 14 | std::cin >> n >> c; 15 | 16 | std::vector p(n), s(n); 17 | for (int i = 0; i < n; i++) { 18 | std::cin >> p[i]; 19 | } 20 | for (int i = 0; i < n; i++) { 21 | std::cin >> s[i]; 22 | } 23 | 24 | std::vector dp(n + 1, 1E18); 25 | 26 | dp[0] = 0; 27 | for (int i = 0; i < n; i++) { 28 | for (int j = i; j >= 0; j--) { 29 | dp[j + 1] = std::min(dp[j + 1], dp[j] + s[i]); 30 | dp[j] += p[i] + 1LL * j * c; 31 | } 32 | } 33 | 34 | std::cout << *std::min_element(dp.begin(), dp.end()) << "\n"; 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /1511/1511C-C-YetAnotherCardDeck.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1511/problem/C 2 | // time:2022-06-27 16:35:15 3 | // name:C-YetAnotherCardDeck 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | int n, q; 14 | std::cin >> n >> q; 15 | 16 | std::array c; 17 | c.fill(n); 18 | 19 | for (int i = 0; i < n; i++) { 20 | int x; 21 | std::cin >> x; 22 | x--; 23 | c[x] = std::min(c[x], i); 24 | } 25 | 26 | for (int i = 0; i < q; i++) { 27 | int x; 28 | std::cin >> x; 29 | x--; 30 | 31 | std::cout << c[x] + 1 << " \n"[i == q - 1]; 32 | for (int j = 0; j < 50; j++) { 33 | if (c[j] < c[x]) { 34 | c[j]++; 35 | } 36 | } 37 | c[x] = 0; 38 | } 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /1736/1736A-A-MakeAEqualtoB.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1736/problem/A 2 | // time:2022-10-10 18:39:51 3 | // name:A-MakeAEqualtoB 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | std::vector a(n), b(n); 14 | for (auto &i : a) { 15 | std::cin >> i; 16 | } 17 | for (auto &i : b) { 18 | std::cin >> i; 19 | } 20 | 21 | int ans = 0; 22 | for (int i = 0; i < n; i++) { 23 | ans += a[i] ^ b[i]; 24 | } 25 | 26 | ans = std::min(ans, int(std::abs(std::count(a.begin(), a.end(), 1) - std::count(b.begin(), b.end(), 1)) + 1)); 27 | std::cout << ans << "\n"; 28 | } 29 | 30 | int main() { 31 | std::ios::sync_with_stdio(false); 32 | std::cin.tie(nullptr); 33 | 34 | int t; 35 | std::cin >> t; 36 | 37 | while (t--) { 38 | solve(); 39 | } 40 | 41 | return 0; 42 | } 43 | 44 | -------------------------------------------------------------------------------- /1091/1091G-G-NewYearandtheFactorisationCollaboration.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1091/problem/G 2 | //time:2021-07-16 11:16:52 3 | //name:G-NewYearandtheFactorisationCollaboration 4 | 5 | from math import gcd 6 | from sys import stdout 7 | from random import randint 8 | 9 | n = int(input()) 10 | 11 | cand = [6,7,3] 12 | 13 | for t in range(50) : 14 | x = randint(0, n - 1) 15 | print("sqrt", x * x % n) 16 | stdout.flush() 17 | y = int(input()) 18 | if x == y : 19 | continue 20 | if x < y : 21 | [x, y] = [y, x] 22 | x -= y 23 | cand.append(x) 24 | cand.append(n // x) 25 | 26 | primes = [] 27 | 28 | while n != 1 : 29 | p = n 30 | for x in cand : 31 | y = gcd(p, x) 32 | if y != 1 : 33 | p = y 34 | for x in cand : 35 | if x % p == 0 : 36 | x //= p 37 | primes.append(p) 38 | n //= p 39 | print(p) 40 | 41 | print("!", len(primes), " ".join(map(str, primes))) 42 | -------------------------------------------------------------------------------- /1674/1674A-A-NumberTransformation.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1674/problem/A 2 | // time:2022-05-02 17:42:22 3 | // name:A-NumberTransformation 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int x, y; 11 | std::cin >> x >> y; 12 | 13 | if (x == y) { 14 | std::cout << "1 1\n"; 15 | return; 16 | } 17 | 18 | for (int b = 2; b * x <= y; b++) { 19 | int v = x; 20 | for (int a = 1; v <= y; a++) { 21 | v *= b; 22 | if (v == y) { 23 | std::cout << a << " " << b << "\n"; 24 | return; 25 | } 26 | } 27 | } 28 | 29 | std::cout << "0 0\n"; 30 | } 31 | 32 | int main() { 33 | std::ios::sync_with_stdio(false); 34 | std::cin.tie(nullptr); 35 | 36 | int t; 37 | std::cin >> t; 38 | 39 | while (t--) { 40 | solve(); 41 | } 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /1675/1675B-B-MakeItIncreasing.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1675/problem/B 2 | // time:2022-05-05 17:37:41 3 | // name:B-MakeItIncreasing 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | std::vector a(n); 14 | for (int i = 0; i < n; i++) { 15 | std::cin >> a[i]; 16 | } 17 | 18 | int ans = 0; 19 | for (int i = n - 2; i >= 0; i--) { 20 | if (a[i + 1] == 0) { 21 | std::cout << "-1\n"; 22 | return; 23 | } 24 | while (a[i] >= a[i + 1]) { 25 | a[i] /= 2; 26 | ans++; 27 | } 28 | } 29 | std::cout << ans << "\n"; 30 | } 31 | 32 | int main() { 33 | std::ios::sync_with_stdio(false); 34 | std::cin.tie(nullptr); 35 | 36 | int t; 37 | std::cin >> t; 38 | 39 | while (t--) { 40 | solve(); 41 | } 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /1676/1676G-G-White-BlackBalancedSubtrees.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1676/problem/G 2 | // time:2022-05-10 17:58:40 3 | // name:G-White-BlackBalancedSubtrees 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | std::vector s(n), p(n); 13 | p[0] = -1; 14 | for (int i = 1; i < n; i++) { 15 | std::cin >> p[i]; 16 | p[i]--; 17 | } 18 | for (int i = 0; i < n; i++) { 19 | char c; 20 | std::cin >> c; 21 | s[i] = c == 'W' ? 1 : -1; 22 | } 23 | for (int i = n - 1; i > 0; i--) { 24 | s[p[i]] += s[i]; 25 | } 26 | std::cout << std::count(s.begin(), s.end(), 0) << "\n"; 27 | } 28 | 29 | int main() { 30 | std::ios::sync_with_stdio(false); 31 | std::cin.tie(nullptr); 32 | 33 | int t; 34 | std::cin >> t; 35 | 36 | while (t--) { 37 | solve(); 38 | } 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /1729/1729B-B-DecodeString.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1729/problem/B 2 | //time:2022-09-12 17:39:45 3 | //name:B-DecodeString 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | std::string t; 14 | std::cin >> t; 15 | 16 | std::string s; 17 | for (int i = n - 1; i >= 0; ) { 18 | if (t[i] == '0') { 19 | int x = (t[i - 2] - '0') * 10 + t[i - 1] - '0' - 1; 20 | s += 'a' + x; 21 | i -= 3; 22 | } else { 23 | s += 'a' + t[i] - '0' - 1; 24 | i--; 25 | } 26 | } 27 | std::reverse(s.begin(), s.end()); 28 | std::cout << s << "\n"; 29 | } 30 | 31 | int main() { 32 | std::ios::sync_with_stdio(false); 33 | std::cin.tie(nullptr); 34 | 35 | int t; 36 | std::cin >> t; 37 | 38 | while (t--) { 39 | solve(); 40 | } 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /1730/1730B-B-MeetingontheLine.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1730/problem/B 2 | //time:2022-09-25 18:05:20 3 | //name:B-MeetingontheLine 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | constexpr int inf = 1E9; 10 | 11 | void solve() { 12 | int n; 13 | std::cin >> n; 14 | 15 | int min = inf, max = -inf; 16 | std::vector x(n), t(n); 17 | for (int i = 0; i < n; i++) { 18 | std::cin >> x[i]; 19 | } 20 | for (int i = 0; i < n; i++) { 21 | std::cin >> t[i]; 22 | min = std::min(min, x[i] - t[i]); 23 | max = std::max(max, x[i] + t[i]); 24 | } 25 | std::cout << 0.5 * (min + max) << "\n"; 26 | } 27 | 28 | int main() { 29 | std::ios::sync_with_stdio(false); 30 | std::cin.tie(nullptr); 31 | 32 | std::cout << std::fixed; 33 | 34 | int t; 35 | std::cin >> t; 36 | 37 | while (t--) { 38 | solve(); 39 | } 40 | 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /1736/1736B-B-PlayingwithGCD.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1736/problem/B 2 | // time:2022-10-10 18:41:22 3 | // name:B-PlayingwithGCD 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | std::vector a(n), b(n + 1); 14 | for (auto &i : a) { 15 | std::cin >> i; 16 | } 17 | b[0] = a[0], b[n] = a[n - 1]; 18 | for (int i = 1; i < n; i++) { 19 | b[i] = std::lcm(a[i - 1], a[i]); 20 | } 21 | for (int i = 0; i < n; i++) { 22 | if (std::gcd(b[i], b[i + 1]) != a[i]) { 23 | std::cout << "NO\n"; 24 | return; 25 | } 26 | } 27 | std::cout << "YES\n"; 28 | } 29 | 30 | int main() { 31 | std::ios::sync_with_stdio(false); 32 | std::cin.tie(nullptr); 33 | 34 | int t; 35 | std::cin >> t; 36 | 37 | while (t--) { 38 | solve(); 39 | } 40 | 41 | return 0; 42 | } 43 | 44 | -------------------------------------------------------------------------------- /612/612A-A-TheTextSplitting.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/612/problem/A 2 | // time:2023-04-24 10:23:31 3 | // name:A-TheTextSplitting 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | int n, p, q; 14 | std::cin >> n >> p >> q; 15 | 16 | std::string s; 17 | std::cin >> s; 18 | 19 | for (int i = 0; i*p <= n; i++) { 20 | if ((n - i*p) % q == 0) { 21 | std::cout << i + (n - i*p) / q << "\n"; 22 | int j = 0; 23 | while (j < i*p) { 24 | std::cout << s.substr(j, p) << "\n"; 25 | j += p; 26 | } 27 | while (j < n) { 28 | std::cout << s.substr(j, q) << "\n"; 29 | j += q; 30 | } 31 | return 0; 32 | } 33 | } 34 | std::cout << -1 << "\n"; 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /1641/1641A-A-GreatSequence.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1641/problem/A 2 | // time:2022-02-23 13:14:11 3 | // name:A-GreatSequence 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n, x; 11 | std::cin >> n >> x; 12 | 13 | std::vector a(n); 14 | for (int i = 0; i < n; i++) { 15 | std::cin >> a[i]; 16 | } 17 | 18 | std::multiset s; 19 | 20 | std::sort(a.begin(), a.end()); 21 | for (auto v : a) { 22 | if (v % x == 0 && s.find(v / x) != s.end()) { 23 | s.erase(s.find(v / x)); 24 | } else { 25 | s.insert(v); 26 | } 27 | } 28 | 29 | std::cout << s.size() << "\n"; 30 | } 31 | 32 | int main() { 33 | std::ios::sync_with_stdio(false); 34 | std::cin.tie(nullptr); 35 | 36 | int t; 37 | std::cin >> t; 38 | 39 | while (t--) { 40 | solve(); 41 | } 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /1822/1822A-A-TubeTubeFeed.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1822/problem/A 2 | // time:2023-04-25 15:32:26 3 | // name:A-TubeTubeFeed 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n, t; 11 | std::cin >> n >> t; 12 | 13 | std::vector a(n), b(n); 14 | for (int i = 0; i < n; i++) { 15 | std::cin >> a[i]; 16 | } 17 | for (int i = 0; i < n; i++) { 18 | std::cin >> b[i]; 19 | } 20 | 21 | int x = -2; 22 | for (int i = 0; i < n; i++) { 23 | if (a[i] + i <= t) { 24 | if (x == -2 || b[x] < b[i]) { 25 | x = i; 26 | } 27 | } 28 | } 29 | std::cout << x+1 << "\n"; 30 | } 31 | 32 | int main() { 33 | std::ios::sync_with_stdio(false); 34 | std::cin.tie(nullptr); 35 | 36 | int t; 37 | std::cin >> t; 38 | 39 | while (t--) { 40 | solve(); 41 | } 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /1675/1675C-C-DetectiveTask.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1675/problem/C 2 | // time:2022-05-05 17:41:02 3 | // name:C-DetectiveTask 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int ans = 0; 11 | std::string s; 12 | std::cin >> s; 13 | 14 | int n = s.length(); 15 | 16 | int zero = 0; 17 | while (zero < n && s[zero] != '0') { 18 | zero++; 19 | } 20 | 21 | int one = n - 1; 22 | while (one >= 0 && s[one] != '1') { 23 | one--; 24 | } 25 | 26 | for (int i = 0; i < n; i++) { 27 | if (zero >= i && one <= i) { 28 | ans++; 29 | } 30 | } 31 | 32 | std::cout << ans << "\n"; 33 | } 34 | 35 | int main() { 36 | std::ios::sync_with_stdio(false); 37 | std::cin.tie(nullptr); 38 | 39 | int t; 40 | std::cin >> t; 41 | 42 | while (t--) { 43 | solve(); 44 | } 45 | 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /1682/1682C-C-LISorReverseLIS?.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1682/problem/C 2 | // time:2022-05-22 17:53:12 3 | // name:C-LISorReverseLIS? 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | std::map cnt; 14 | for (int i = 0; i < n; i++) { 15 | int x; 16 | std::cin >> x; 17 | if (cnt[x] < 2) { 18 | cnt[x]++; 19 | } 20 | } 21 | 22 | int ans = 0, v = 0; 23 | for (auto [x, c] : cnt) { 24 | if (c == 2) { 25 | ans++; 26 | } else { 27 | v++; 28 | } 29 | } 30 | ans += (v + 1) / 2; 31 | std::cout << ans << "\n"; 32 | } 33 | 34 | int main() { 35 | std::ios::sync_with_stdio(false); 36 | std::cin.tie(nullptr); 37 | 38 | int t; 39 | std::cin >> t; 40 | 41 | while (t--) { 42 | solve(); 43 | } 44 | 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /158/158E-E-PhoneTalks.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/158/problem/E 2 | // time:2023-04-26 20:12:58 3 | // name:E-PhoneTalks 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | constexpr int N = 86400; 10 | 11 | int main() { 12 | std::ios::sync_with_stdio(false); 13 | std::cin.tie(nullptr); 14 | 15 | int n, k; 16 | std::cin >> n >> k; 17 | 18 | std::vector t(n), d(n); 19 | for (int i = 0; i < n; i++) { 20 | std::cin >> t[i] >> d[i]; 21 | } 22 | 23 | int ans = n ? t[0] - 1 : N; 24 | std::vector dp(k+1); 25 | for (int i = 0; i < n; i++) { 26 | for (int j = k; j >= 0; j--) { 27 | if (j < k) { 28 | dp[j+1] = std::min(dp[j+1], dp[j]); 29 | } 30 | dp[j] = std::max(dp[j]+1, t[i]) + d[i] - 1; 31 | } 32 | ans = std::max(ans, (i < n-1 ? t[i+1]-1 : N) - dp[k]); 33 | } 34 | std::cout << ans << "\n"; 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /1623/1623B-B-GameonRanges.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1623/problem/B 2 | //time:2021-12-28 17:39:41 3 | //name:B-GameonRanges 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | std::vector l(n), r(n); 14 | for (int i = 0; i < n; i++) { 15 | std::cin >> l[i] >> r[i]; 16 | l[i]--; 17 | } 18 | for (int i = 0; i < n; i++) { 19 | int x = l[i]; 20 | for (int j = 0; j < n; j++) { 21 | if (l[i] == l[j] && r[j] < r[i]) { 22 | x = std::max(x, r[j]); 23 | } 24 | } 25 | std::cout << l[i] + 1 << " " << r[i] << " " << x + 1 << "\n"; 26 | } 27 | } 28 | 29 | 30 | int main() { 31 | std::ios::sync_with_stdio(false); 32 | std::cin.tie(nullptr); 33 | 34 | int t; 35 | std::cin >> t; 36 | 37 | while (t--) { 38 | solve(); 39 | } 40 | 41 | return 0; 42 | } 43 | 44 | -------------------------------------------------------------------------------- /1680/1680B-B-Robots.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1680/problem/B 2 | // time:2022-05-16 16:44:26 3 | // name:B-Robots 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n, m; 11 | std::cin >> n >> m; 12 | 13 | std::vector s(n); 14 | int r = n, c = m; 15 | for (int i = 0; i < n; i++) { 16 | std::cin >> s[i]; 17 | for (int j = 0; j < m; j++) { 18 | if (s[i][j] == 'R') { 19 | r = std::min(r, i); 20 | c = std::min(c, j); 21 | } 22 | } 23 | } 24 | 25 | if (s[r][c] == 'R') { 26 | std::cout << "YES\n"; 27 | } else { 28 | std::cout << "NO\n"; 29 | } 30 | } 31 | 32 | int main() { 33 | std::ios::sync_with_stdio(false); 34 | std::cin.tie(nullptr); 35 | 36 | int t; 37 | std::cin >> t; 38 | 39 | while (t--) { 40 | solve(); 41 | } 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /1680/1680C-C-BinaryString.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1680/problem/C 2 | // time:2022-05-16 16:50:35 3 | // name:C-BinaryString 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | std::string s; 11 | std::cin >> s; 12 | 13 | int n = s.length(); 14 | 15 | std::vector s0(n + 1), s1(n + 1); 16 | for (int i = 0; i < n; i++) { 17 | s0[i + 1] = s0[i] + (s[i] == '0'); 18 | s1[i + 1] = s1[i] + (s[i] == '1'); 19 | } 20 | 21 | int ans = n; 22 | int t = s1[n]; 23 | for (int i = 0; i + t <= n; i++) { 24 | ans = std::min(ans, std::max(s0[i + t] - s0[i], s1[i] + t - s1[i + t])); 25 | } 26 | 27 | std::cout << ans << "\n"; 28 | } 29 | 30 | int main() { 31 | std::ios::sync_with_stdio(false); 32 | std::cin.tie(nullptr); 33 | 34 | int t; 35 | std::cin >> t; 36 | 37 | while (t--) { 38 | solve(); 39 | } 40 | 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /1470/1470A-A-StrangeBirthdayParty.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1470/problem/A 2 | //time:2021-01-05 17:38:48 3 | //name:A-StrangeBirthdayParty 4 | 5 | #include 6 | using i64 = long long; 7 | using u64 = unsigned long long; 8 | using u32 = unsigned; 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | int t; 13 | std::cin >> t; 14 | while (t--) { 15 | int n, m; 16 | std::cin >> n >> m; 17 | std::vector k(n); 18 | for (int i = 0; i < n; i++) { 19 | std::cin >> k[i]; 20 | k[i]--; 21 | } 22 | std::vector c(m); 23 | for (int i = 0; i < m; i++) { 24 | std::cin >> c[i]; 25 | } 26 | std::sort(k.begin(), k.end()); 27 | i64 ans = 0; 28 | for (int i = n - 1; i >= 0; i--) { 29 | ans += c[std::min(k[i], n - 1 - i)]; 30 | } 31 | std::cout << ans << "\n"; 32 | } 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /1491/1491A-A-K-thLargestValue.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1491/problem/A 2 | // time:2021-02-28 16:36:54 3 | // name:A-K-thLargestValue 4 | 5 | #include 6 | using i64 = long long; 7 | using u64 = unsigned long long; 8 | using u32 = unsigned; 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | int n, q; 13 | std::cin >> n >> q; 14 | std::vector a(n); 15 | int sum = 0; 16 | for (int i = 0; i < n; i++) { 17 | std::cin >> a[i]; 18 | sum += a[i]; 19 | } 20 | while (q--) { 21 | int t, x; 22 | std::cin >> t >> x; 23 | if (t == 1) { 24 | x--; 25 | sum -= a[x]; 26 | a[x] = 1 - a[x]; 27 | sum += a[x]; 28 | } else { 29 | if (x <= sum) { 30 | std::cout << "1\n"; 31 | } else { 32 | std::cout << "0\n"; 33 | } 34 | } 35 | } 36 | return 0; 37 | } 38 | 39 | -------------------------------------------------------------------------------- /1621/1621A-A-StableArrangementofRooks.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1621/problem/A 2 | // time:2022-01-03 17:37:31 3 | // name:A-StableArrangementofRooks 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n, k; 11 | std::cin >> n >> k; 12 | 13 | if (n < 2 * k - 1) { 14 | std::cout << "-1\n"; 15 | } else { 16 | for (int i = 0; i < n; i++) { 17 | for (int j = 0; j < n; j++) { 18 | if (i == j && i % 2 == 0 && i < 2 * k) { 19 | std::cout << "R"; 20 | } else { 21 | std::cout << "."; 22 | } 23 | } 24 | std::cout << "\n"; 25 | } 26 | } 27 | } 28 | 29 | int main() { 30 | std::ios::sync_with_stdio(false); 31 | std::cin.tie(nullptr); 32 | 33 | int t; 34 | std::cin >> t; 35 | 36 | while (t--) { 37 | solve(); 38 | } 39 | 40 | return 0; 41 | } 42 | 43 | -------------------------------------------------------------------------------- /1520/1520E-E-ArrangingTheSheep.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1520/problem/E 2 | // time:2021-05-05 18:27:11 3 | // name:E-ArrangingTheSheep 4 | 5 | #include 6 | using i64 = long long; 7 | using u64 = unsigned long long; 8 | using u32 = unsigned; 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | int t; 13 | std::cin >> t; 14 | while (t--) { 15 | int n; 16 | std::cin >> n; 17 | std::string s; 18 | std::cin >> s; 19 | std::vector a; 20 | int empty = 0; 21 | for (int i = 0; i < n; i++) { 22 | if (s[i] == '.') { 23 | empty++; 24 | } else { 25 | a.push_back(empty); 26 | } 27 | } 28 | int mid = (a.size() - 1) / 2; 29 | i64 ans = 0; 30 | for (auto x : a) { 31 | ans += std::abs(x - a[mid]); 32 | } 33 | std::cout << ans << "\n"; 34 | } 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /1606/1606C-C-Banknotes.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1606/problem/C 2 | //time:2022-06-10 11:37:35 3 | //name:C-Banknotes 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n, k; 11 | std::cin >> n >> k; 12 | 13 | std::vector a(n); 14 | for (int i = 0; i < n; i++) { 15 | int x; 16 | std::cin >> x; 17 | a[i] = 1; 18 | while (x--) { 19 | a[i] *= 10; 20 | } 21 | } 22 | 23 | i64 ans = 0; 24 | k++; 25 | for (int i = 0; i < n; i++) { 26 | int x = std::min(k, i == n - 1 ? k : a[i + 1] / a[i] - 1); 27 | k -= x; 28 | ans += 1LL * x * a[i]; 29 | } 30 | 31 | std::cout << ans << "\n"; 32 | } 33 | 34 | int main() { 35 | std::ios::sync_with_stdio(false); 36 | std::cin.tie(nullptr); 37 | 38 | int t; 39 | std::cin >> t; 40 | 41 | while (t--) { 42 | solve(); 43 | } 44 | 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /1638/1638B-B-OddSwapSort.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1638/problem/B 2 | // time:2022-02-14 18:46:33 3 | // name:B-OddSwapSort 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | std::vector odd, even; 14 | for (int i = 0; i < n; i++) { 15 | int x; 16 | std::cin >> x; 17 | 18 | if (x % 2 == 1) { 19 | odd.push_back(x); 20 | } else { 21 | even.push_back(x); 22 | } 23 | } 24 | 25 | if (std::is_sorted(odd.begin(), odd.end()) && std::is_sorted(even.begin(), even.end())) { 26 | std::cout << "Yes\n"; 27 | } else { 28 | std::cout << "No\n"; 29 | } 30 | } 31 | 32 | int main() { 33 | std::ios::sync_with_stdio(false); 34 | std::cin.tie(nullptr); 35 | 36 | int t; 37 | std::cin >> t; 38 | 39 | while (t--) { 40 | solve(); 41 | } 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /1742/1742D-D-Coprime.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1742/problem/D 2 | // time:2022-10-13 17:59:06 3 | // name:D-Coprime 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | std::vector last(1001); 14 | for (int i = 0; i < n; i++) { 15 | int x; 16 | std::cin >> x; 17 | last[x] = i + 1; 18 | } 19 | 20 | int ans = -1; 21 | for (int i = 1; i <= 1000; i++) { 22 | for (int j = 1; j <= i; j++) { 23 | if (last[i] && last[j] && std::gcd(i, j) == 1) { 24 | ans = std::max(ans, last[i] + last[j]); 25 | } 26 | } 27 | } 28 | 29 | std::cout << ans << "\n"; 30 | } 31 | 32 | int main() { 33 | std::ios::sync_with_stdio(false); 34 | std::cin.tie(nullptr); 35 | 36 | int t; 37 | std::cin >> t; 38 | 39 | while (t--) { 40 | solve(); 41 | } 42 | 43 | return 0; 44 | } 45 | 46 | -------------------------------------------------------------------------------- /1744/1744A-A-NumberReplacement.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1744/problem/A 2 | // time:2022-10-18 14:05:09 3 | // name:A-NumberReplacement 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | std::vector a(n); 14 | for (int i = 0; i < n; i++) { 15 | std::cin >> a[i]; 16 | } 17 | 18 | std::string s; 19 | std::cin >> s; 20 | 21 | std::map mp; 22 | for (int i = 0; i < n; i++) { 23 | if (!mp.contains(a[i])) { 24 | mp[a[i]] = s[i]; 25 | } else if (mp[a[i]] != s[i]) { 26 | std::cout << "NO\n"; 27 | return; 28 | } 29 | } 30 | std::cout << "YES\n"; 31 | } 32 | 33 | int main() { 34 | std::ios::sync_with_stdio(false); 35 | std::cin.tie(nullptr); 36 | 37 | int t; 38 | std::cin >> t; 39 | 40 | while (t--) { 41 | solve(); 42 | } 43 | 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /1806/1806B-B-MexMaster.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1806/problem/B 2 | // time:2023-03-20 20:52:07 3 | // name:B-MexMaster 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | std::vector a(n); 14 | for (int i = 0; i < n; i++) { 15 | std::cin >> a[i]; 16 | } 17 | 18 | int cnt0 = std::count(a.begin(), a.end(), 0); 19 | 20 | if (cnt0 * 2 - 1 <= n) { 21 | std::cout << 0 << "\n"; 22 | return; 23 | } 24 | 25 | int cnt1 = std::count(a.begin(), a.end(), 1); 26 | if (cnt0 + cnt1 == n && cnt1 > 0) { 27 | std::cout << 2 << "\n"; 28 | } else { 29 | std::cout << 1 << "\n"; 30 | } 31 | } 32 | 33 | int main() { 34 | std::ios::sync_with_stdio(false); 35 | std::cin.tie(nullptr); 36 | 37 | int t; 38 | std::cin >> t; 39 | 40 | while (t--) { 41 | solve(); 42 | } 43 | 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /709/709B-B-Checkpoints.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/709/problem/B 2 | //time:2021-12-24 11:59:51 3 | //name:B-Checkpoints 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | 13 | int n, a; 14 | std::cin >> n >> a; 15 | 16 | if (n == 1) { 17 | std::cout << "0\n"; 18 | return 0; 19 | } 20 | 21 | std::vector x(n); 22 | for (int i = 0; i < n; i++) { 23 | std::cin >> x[i]; 24 | } 25 | 26 | std::sort(x.begin(), x.end()); 27 | 28 | int ans = 1E9; 29 | for (auto c : {0, 1}) { 30 | int l = a, r = a; 31 | l = std::min(l, x[c]); 32 | r = std::max(r, x[c]); 33 | l = std::min(l, x[c + n - 2]); 34 | r = std::max(r, x[c + n - 2]); 35 | ans = std::min(ans, r - l + std::min(r - a, a - l)); 36 | } 37 | 38 | std::cout << ans << "\n"; 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /801/801A-A-ViciousKeyboard.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/801/problem/A 2 | //time:2021-01-03 17:19:44 3 | //name:A-ViciousKeyboard 4 | 5 | #include 6 | using i64 = long long; 7 | using u64 = unsigned long long; 8 | using u32 = unsigned; 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | std::string s; 13 | std::cin >> s; 14 | int n = s.length(); 15 | int ans = 0; 16 | for (int i = 0; i < n - 1; i++) { 17 | if (s[i] == 'V' && s[i + 1] == 'K') { 18 | ans++; 19 | } 20 | } 21 | bool add = false; 22 | for (int i = 0; i < n - 1; i++) { 23 | if (s[i] == 'V' && s[i + 1] == 'V' && (i == n - 2 || s[i + 2] == 'V')) { 24 | add = true; 25 | } 26 | if (s[i] == 'K' && s[i + 1] == 'K' && (i == 0 || s[i - 1] == 'K')) { 27 | add = true; 28 | } 29 | } 30 | if (add) { 31 | ans++; 32 | } 33 | std::cout << ans << "\n"; 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /1555/1555C-C-CoinRows.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1555/problem/C 2 | //time:2022-06-12 10:25:10 3 | //name:C-CoinRows 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int m; 11 | std::cin >> m; 12 | 13 | std::vector a(2, std::vector(m)); 14 | for (int i = 0; i < 2; i++) { 15 | for (int j = 0; j < m; j++) { 16 | std::cin >> a[i][j]; 17 | } 18 | } 19 | 20 | i64 L = 0; 21 | i64 R = std::accumulate(a[0].begin(), a[0].end(), 0LL); 22 | i64 ans = R; 23 | for (int i = 0; i < m; i++) { 24 | R -= a[0][i]; 25 | ans = std::min(ans, std::max(L, R)); 26 | L += a[1][i]; 27 | } 28 | 29 | std::cout << ans << "\n"; 30 | } 31 | 32 | int main() { 33 | std::ios::sync_with_stdio(false); 34 | std::cin.tie(nullptr); 35 | 36 | int t; 37 | std::cin >> t; 38 | 39 | while (t--) { 40 | solve(); 41 | } 42 | 43 | return 0; 44 | } 45 | 46 | -------------------------------------------------------------------------------- /492/492D-D-VanyaandComputerGame.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/492/problem/D 2 | // time:2021-06-24 18:40:24 3 | // name:D-VanyaandComputerGame 4 | 5 | #include 6 | using i64 = long long; 7 | int main() { 8 | std::ios::sync_with_stdio(false); 9 | std::cin.tie(nullptr); 10 | int n, x, y; 11 | std::cin >> n >> x >> y; 12 | while (n--) { 13 | int a; 14 | std::cin >> a; 15 | a = (a - 1) % (x + y) + 1; 16 | int lo = 1, hi = y; 17 | while (lo < hi) { 18 | int mid = (lo + hi) / 2; 19 | if (mid + i64(mid) * x / y >= a) { 20 | hi = mid; 21 | } else { 22 | lo = mid + 1; 23 | } 24 | } 25 | if (lo - 1 + (i64(lo) * x - 1) / y >= a) { 26 | std::cout << "Vanya\n"; 27 | } else if (i64(lo) * x % y == 0) { 28 | std::cout << "Both\n"; 29 | } else { 30 | std::cout << "Vova\n"; 31 | } 32 | } 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /1491/1491B-B-MinimalCost.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1491/problem/B 2 | // time:2021-02-28 16:44:40 3 | // name:B-MinimalCost 4 | 5 | #include 6 | using i64 = long long; 7 | using u64 = unsigned long long; 8 | using u32 = unsigned; 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | int t; 13 | std::cin >> t; 14 | while (t--) { 15 | int n, u, v; 16 | std::cin >> n >> u >> v; 17 | std::vector a(n); 18 | for (int i = 0; i < n; i++) { 19 | std::cin >> a[i]; 20 | } 21 | int mx = 0; 22 | for (int i = 0; i < n - 1; i++) { 23 | mx = std::max(mx, std::abs(a[i] - a[i + 1])); 24 | } 25 | if (mx > 1) { 26 | std::cout << "0\n"; 27 | } else if (mx == 1) { 28 | std::cout << std::min(u, v) << "\n"; 29 | } else { 30 | std::cout << std::min(u + v, 2 * v) << "\n"; 31 | } 32 | } 33 | return 0; 34 | } 35 | 36 | -------------------------------------------------------------------------------- /1503/1503C-C-TravellingSalesmanProblem.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1503/problem/C 2 | //time:2021-04-03 18:14:03 3 | //name:C-TravellingSalesmanProblem 4 | 5 | #include 6 | using i64 = int64_t; 7 | using u64 = uint64_t; 8 | using u32 = uint32_t; 9 | int main() { 10 | std::ios::sync_with_stdio(false); 11 | std::cin.tie(nullptr); 12 | int n; 13 | std::cin >> n; 14 | std::vector a(n), c(n); 15 | i64 ans = 0; 16 | for (int i = 0; i < n; i++) { 17 | std::cin >> a[i] >> c[i]; 18 | ans += c[i]; 19 | c[i] += a[i]; 20 | } 21 | std::vector p(n); 22 | std::iota(p.begin(), p.end(), 0); 23 | std::sort(p.begin(), p.end(), [&](int i, int j) { 24 | return a[i] < a[j]; 25 | }); 26 | int r = a[p[0]]; 27 | for (int i = 0; i < n; i++) { 28 | if (a[p[i]] > r) { 29 | ans += a[p[i]] - r; 30 | } 31 | r = std::max(r, c[p[i]]); 32 | } 33 | std::cout << ans << "\n"; 34 | return 0; 35 | } 36 | 37 | -------------------------------------------------------------------------------- /1739/1739B-B-ArrayRecovery.cpp: -------------------------------------------------------------------------------- 1 | //url:https://codeforces.com/contest/1739/problem/B 2 | //time:2022-09-29 17:55:29 3 | //name:B-ArrayRecovery 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | std::vector d(n); 14 | for (int i = 0; i < n; i++) { 15 | std::cin >> d[i]; 16 | } 17 | 18 | std::vector a(n); 19 | a[0] = d[0]; 20 | for (int i = 1; i < n; i++) { 21 | if (d[i] > 0 && a[i - 1] >= d[i]) { 22 | std::cout << -1 << "\n"; 23 | return; 24 | } 25 | a[i] = a[i - 1] + d[i]; 26 | } 27 | 28 | for (int i = 0; i < n; i++) { 29 | std::cout << a[i] << " \n"[i == n - 1]; 30 | } 31 | } 32 | 33 | int main() { 34 | std::ios::sync_with_stdio(false); 35 | std::cin.tie(nullptr); 36 | 37 | int t; 38 | std::cin >> t; 39 | 40 | while (t--) { 41 | solve(); 42 | } 43 | 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /1742/1742E-E-Scuza.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1742/problem/E 2 | // time:2022-10-13 18:01:29 3 | // name:E-Scuza 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n, q; 11 | std::cin >> n >> q; 12 | 13 | std::vector a(n); 14 | std::vector s(n + 1); 15 | for (int i = 0; i < n; i++) { 16 | std::cin >> a[i]; 17 | s[i + 1] = s[i] + a[i]; 18 | } 19 | for (int i = 1; i < n; i++) { 20 | a[i] = std::max(a[i], a[i - 1]); 21 | } 22 | 23 | for (int i = 0; i < q; i++) { 24 | int k; 25 | std::cin >> k; 26 | 27 | std::cout << s[std::upper_bound(a.begin(), a.end(), k) - a.begin()] << " \n"[i == q - 1]; 28 | } 29 | } 30 | 31 | int main() { 32 | std::ios::sync_with_stdio(false); 33 | std::cin.tie(nullptr); 34 | 35 | int t; 36 | std::cin >> t; 37 | 38 | while (t--) { 39 | solve(); 40 | } 41 | 42 | return 0; 43 | } 44 | 45 | -------------------------------------------------------------------------------- /1744/1744C-C-TrafficLight.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1744/problem/C 2 | // time:2022-10-18 14:10:35 3 | // name:C-TrafficLight 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | char c; 12 | std::cin >> n >> c; 13 | 14 | std::string s; 15 | std::cin >> s; 16 | 17 | int ans = 0, x = 0; 18 | for (int t = 0; t < 2; t++) { 19 | for (int i = n - 1; i >= 0; i--) { 20 | if (s[i] == 'g') { 21 | x = 0; 22 | } else { 23 | x++; 24 | } 25 | if (s[i] == c && t) { 26 | ans = std::max(ans, x); 27 | } 28 | } 29 | } 30 | 31 | std::cout << ans << "\n"; 32 | } 33 | 34 | int main() { 35 | std::ios::sync_with_stdio(false); 36 | std::cin.tie(nullptr); 37 | 38 | int t; 39 | std::cin >> t; 40 | 41 | while (t--) { 42 | solve(); 43 | } 44 | 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /1820/1820A-A-Yura'sNewName.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1820/problem/A 2 | // time:2023-04-19 09:55:45 3 | // name:A-Yura'sNewName 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | std::string s; 11 | std::cin >> s; 12 | 13 | if (s == "^") { 14 | std::cout << 1 << "\n"; 15 | return; 16 | } 17 | 18 | s = "^_" + s + "_^"; 19 | int n = s.size(); 20 | 21 | std::vector p; 22 | for (int i = 0; i < n; i++) { 23 | if (s[i] == '^') { 24 | p.push_back(i); 25 | } 26 | } 27 | int ans = 0; 28 | for (int i = 1; i < p.size(); i++) { 29 | ans += std::max(0, p[i] - p[i - 1] - 2); 30 | } 31 | std::cout << ans << "\n"; 32 | } 33 | 34 | int main() { 35 | std::ios::sync_with_stdio(false); 36 | std::cin.tie(nullptr); 37 | 38 | int t; 39 | std::cin >> t; 40 | 41 | while (t--) { 42 | solve(); 43 | } 44 | 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /1619/1619B-B-SquaresandCubes.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1619/problem/B 2 | // time:2021-12-20 17:56:00 3 | // name:B-SquaresandCubes 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | std::vector good; 10 | 11 | void solve() { 12 | int n; 13 | std::cin >> n; 14 | 15 | std::cout << std::upper_bound(good.begin(), good.end(), n) - good.begin() << "\n"; 16 | } 17 | 18 | int main() { 19 | std::ios::sync_with_stdio(false); 20 | std::cin.tie(nullptr); 21 | 22 | const int limit = 1E9; 23 | 24 | for (int i = 1; i * i <= limit; i++) { 25 | good.push_back(i * i); 26 | } 27 | for (int i = 1; i * i * i <= limit; i++) { 28 | good.push_back(i * i * i); 29 | } 30 | 31 | std::sort(good.begin(), good.end()); 32 | good.erase(std::unique(good.begin(), good.end()), good.end()); 33 | 34 | int t; 35 | std::cin >> t; 36 | 37 | while (t--) { 38 | solve(); 39 | } 40 | 41 | return 0; 42 | } 43 | 44 | -------------------------------------------------------------------------------- /1736C/1736C1-C1-GoodSubarrays(EasyVersion).cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1736/problem/C1 2 | // time:2022-10-10 18:47:42 3 | // name:C1-GoodSubarrays(EasyVersion) 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | std::vector a(n); 14 | for (auto &i : a) { 15 | std::cin >> i; 16 | i--; 17 | } 18 | 19 | for (int i = 0; i < n; i++) { 20 | a[i] -= i; 21 | } 22 | 23 | i64 ans = 0; 24 | for (int i = 0, j = 0; i < n; i++) { 25 | while (j < n && a[j] + i >= 0) { 26 | j++; 27 | } 28 | ans += j; 29 | } 30 | ans -= 1LL * n * (n - 1) / 2; 31 | std::cout << ans << "\n"; 32 | } 33 | 34 | int main() { 35 | std::ios::sync_with_stdio(false); 36 | std::cin.tie(nullptr); 37 | 38 | int t; 39 | std::cin >> t; 40 | 41 | while (t--) { 42 | solve(); 43 | } 44 | 45 | return 0; 46 | } 47 | 48 | -------------------------------------------------------------------------------- /1807/1807D-D-OddQueries.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1807/problem/D 2 | // time:2023-03-20 15:56:51 3 | // name:D-OddQueries 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n, q; 11 | std::cin >> n >> q; 12 | 13 | std::vector a(n); 14 | for (int i = 0; i < n; i++) { 15 | std::cin >> a[i]; 16 | } 17 | 18 | std::vector s(n + 1); 19 | for (int i = 0; i < n; i++) { 20 | s[i + 1] = s[i] + a[i]; 21 | } 22 | 23 | while (q--) { 24 | int l, r, k; 25 | std::cin >> l >> r >> k; 26 | l--; 27 | 28 | i64 sum = s[l] + s[n] - s[r] + 1LL * k * (r - l); 29 | std::cout << (sum % 2 ? "YES" : "NO") << "\n"; 30 | } 31 | } 32 | 33 | int main() { 34 | std::ios::sync_with_stdio(false); 35 | std::cin.tie(nullptr); 36 | 37 | int t; 38 | std::cin >> t; 39 | 40 | while (t--) { 41 | solve(); 42 | } 43 | 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /1638/1638C-C-InversionGraph.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1638/problem/C 2 | // time:2022-02-14 19:03:34 3 | // name:C-InversionGraph 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | std::vector a(n), b(n); 14 | for (int i = 0; i < n; i++) { 15 | std::cin >> a[i]; 16 | b[i] = a[i]; 17 | if (i > 0) { 18 | a[i] = std::max(a[i], a[i - 1]); 19 | } 20 | } 21 | 22 | for (int i = n - 2; i >= 0; i--) { 23 | b[i] = std::min(b[i], b[i + 1]); 24 | } 25 | 26 | int ans = 1; 27 | for (int i = 0; i < n - 1; i++) { 28 | ans += (a[i] < b[i + 1]); 29 | } 30 | 31 | std::cout << ans << "\n"; 32 | } 33 | 34 | int main() { 35 | std::ios::sync_with_stdio(false); 36 | std::cin.tie(nullptr); 37 | 38 | int t; 39 | std::cin >> t; 40 | 41 | while (t--) { 42 | solve(); 43 | } 44 | 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /1746/1746C-C-PermutationOperations.cpp: -------------------------------------------------------------------------------- 1 | // url:https://codeforces.com/contest/1746/problem/C 2 | // time:2022-10-15 17:45:56 3 | // name:C-PermutationOperations 4 | 5 | #include 6 | 7 | using i64 = long long; 8 | 9 | void solve() { 10 | int n; 11 | std::cin >> n; 12 | 13 | std::vector a(n); 14 | for (int i = 0; i < n; i++) { 15 | std::cin >> a[i]; 16 | } 17 | for (int i = n - 1; i > 0; i--) { 18 | a[i] -= a[i - 1]; 19 | } 20 | 21 | std::vector p(n); 22 | std::iota(p.begin(), p.end(), 0); 23 | std::sort(p.begin(), p.end(), [&](int i, int j) { 24 | return a[i] > a[j]; 25 | }); 26 | 27 | for (int i = 0; i < n; i++) { 28 | std::cout << p[i] + 1 << " \n"[i == n - 1]; 29 | } 30 | } 31 | 32 | int main() { 33 | std::ios::sync_with_stdio(false); 34 | std::cin.tie(nullptr); 35 | 36 | int t; 37 | std::cin >> t; 38 | 39 | while (t--) { 40 | solve(); 41 | } 42 | 43 | return 0; 44 | } 45 | --------------------------------------------------------------------------------