├── 1-2-K Game.cpp ├── 1029B - Creating the Contest.java ├── 1036D - Vasya and Arrays.java ├── 1037C - Equalize.java ├── 1037D - Valid BFS?.java ├── 106C - Buns.java ├── 1097B - Petr and a Combination Lock.java ├── 1108D - Diverse Garland.java ├── 1109A - Sasha and a Bit of Relax.java ├── 110A - Nearly Lucky Number.java ├── 1114C - Trailing Loves (or L'oeufs?).java ├── 1140C - Playlist.java ├── 1140D - Minimum Triangulation.java ├── 1151B - Dima and a Bad XOR.java ├── 115A - Party.java ├── 1166C - A Tale of Two Lands.java ├── 116A - Tram.java ├── 1175B - Catch Overflow!.java ├── 1186D - Vus the Cossack and Numbers.java ├── 1188A1 - Add on a Tree.java ├── 118A - String Task.java ├── 118B - Present from Lena.java ├── 118D - Caesar's Legions.java ├── 1195C - Basketball Exercise.java ├── 1196D1 - RGB Substring (easy version).java ├── 1196D2 - RGB Substring (hard version).java ├── 1198A - MP3.java ├── 1198B - Welfare State.java ├── 1200B - Block Adventure.java ├── 1207B - Square Filling.java ├── 1213D2 - Equalizing by Division (hard version).java ├── 1217B - Zmei Gorynich.java ├── 1225C - p-binary.java ├── 1228C - Primes and Multiplication.java ├── 1230A - Dawid and Bags of Candies.java ├── 1230B - Ania and Minimizing.java ├── 1234A - Equalize Prices Again.java ├── 1234B2 - Social Network (hard version).java ├── 1234C - Pipes.java ├── 1234D - Distinct Characters Queries.java ├── 1236A - Stones.java ├── 1236B - Alice and the List of Presents.java ├── 1268A - Long Beautiful Integer.java ├── 126B - Password.java ├── 1278A - Shuffle Hashing.java ├── 1278B - A and B.java ├── 1279A - New Year Garland.java ├── 1279B - Verse For Santa.java ├── 1279C - Stack of Presents.java ├── 1282A - Temporarily unavailable.java ├── 1283A - Minutes Before the New Year.java ├── 1283B - Candies Division.java ├── 1283C - Friends and Gifts.java ├── 1283D - Christmas Trees.java ├── 1283E - New Year Parties.java ├── 1284A - New Year and Naming.java ├── 1284B - New Year and Ascent Sequence.java ├── 1287A - Angry Students.java ├── 1287B - Hyperset.java ├── 1288A - Deadline.java ├── 1288C - Two Arrays.java ├── 1291A - Even But Not Even.java ├── 1291B - Array Sharpening.java ├── 1291C - Mind Control.java ├── 1293A - ConneR and the A.R.C. Markland-N.java ├── 1293B - JOE is on TV!.java ├── 1293C - NEKO's Maze Game.java ├── 1294A - Collecting Coins.java ├── 1294B - Collecting Packages.java ├── 1294C - Product of Three Numbers.java ├── 1294D - MEX maximizing.java ├── 1294F - Three Paths on a Tree ├── 1295A - Display The Number.java ├── 1295B - Infinite Prefixes.java ├── 1295C - Obtain The String.java ├── 1295D - Same GCDs.java ├── 1296A - Array with Odd Sum.java ├── 1296B - Food Buying.java ├── 1296C - Yet Another Walking Robot.java ├── 1296D - Fight with Monsters.java ├── 1296F - Berland Beauty.java ├── 1300A - Non-zero.java ├── 1300B - Assigning to Classes.java ├── 1300C - Anu Has a Function.java ├── 1301A - Three Strings.java ├── 1301B - Motarack's Birthday.java ├── 1301C - Ayoub's function.java ├── 1301D - Time to Run.java ├── 1303A - Erasing Zeroes.java ├── 1303B - National Project.java ├── 1303C - Perfect Keyboard.java ├── 1303D - Fill The Bag.java ├── 1305C - Kuroni and Impossible Calculation.java ├── 1307A - Cow and Haybales.java ├── 1307B - Cow and Friend.java ├── 1307C - Cow and Message.java ├── 1307D - Cow and Fields.java ├── 1311A - Add Odd or Subtract Even.java ├── 1311B - WeirdSort.java ├── 1311C - Perform the Combo.java ├── 1311D - Three Integers.java ├── 1312B - Bogosort.java ├── 1312C - Adding Powers.java ├── 1312D - Count the Arrays.java ├── 1312E - Array Shrinking.java ├── 1315A - Dead Pixel.java ├── 1315B - Homecoming.java ├── 1315C - Restoring Permutation.java ├── 1315D - Recommendations.java ├── 1316B - String Modification.java ├── 1316C - Primitive Primes.java ├── 1316D - Nash Matrix.java ├── 1321A - Contest for Robots.java ├── 1321B - Journey Planning.java ├── 1321C - Remove Adjacent.java ├── 1321D - Navigation System.java ├── 1323A - Even Subset Sum Problem.java ├── 1323B - Count Subrectangles.java ├── 1323C - Unusual Competitions.java ├── 1323D - Present.java ├── 1324A - Yet Another Tetris Problem.java ├── 1324B - Yet Another Palindrome Problem.java ├── 1324C - Frog Jumps.java ├── 1324D - Pair of Topics.java ├── 1324E - Sleeping Schedule.java ├── 1324F - Maximum White Subtree.java ├── 1325A - EhAb AnD gCd.java ├── 1325B - CopyCopyCopyCopyCopy.java ├── 1325C - Ehab and Path-etic MEXs.java ├── 1325D - Ehab the Xorcist.java ├── 1326A - Bad Ugly Numbers.java ├── 1326B - Maximums.java ├── 1326C - Permutation Partitions.java ├── 1326D1 - Prefix-Suffix Palindrome (Easy version).java ├── 1326D2 - Prefix-Suffix Palindrome (Hard version).java ├── 1327C - Game with Chips.java ├── 1328D - Carousel.java ├── 1330A - Dreamoon and Ranking Collection.java ├── 1330B - Dreamoon Likes Permutations.java ├── 1330C - Dreamoon Likes Coloring.java ├── 1332A - Exercising Walk.java ├── 1332B - Composite Coloring.java ├── 1332C - K-Complete Word.java ├── 1332D - Walk on Matrix.java ├── 1333A - Little Artem.java ├── 1333B - Kind Anton.java ├── 1333C - Eugene and an array.java ├── 1333D - Challenges in school №41.java ├── 1334A - Level Statistics.java ├── 1334B - Middle Class.java ├── 1334C - Circle of Monsters.java ├── 1334D - Minimum Euler Cycle.java ├── 1335E2 - Three Blocks Palindrome (hard version).java ├── 1337A - Ichihime and Triangle.java ├── 1337B - Kana and Dragon Quest game.java ├── 1337C - Linova and Kingdom.java ├── 1337D - Xenia and Colorful Gems.java ├── 1339B - Sorted Adjacent Differences.java ├── 1339C - Powered Addition.java ├── 1339D - Edge Weight Assignment.java ├── 1341A - Nastya and Rice.java ├── 1341B - Nastya and Door.java ├── 1341C - Nastya and Strange Generator.java ├── 1341D - Nastya and Scoreboard.java ├── 1342A - Road To Zero.java ├── 1342B - Binary Period.java ├── 1342C - Yet Another Counting Problem.java ├── 1342D - Multiple Testcases.java ├── 1343D - Constant Palindrome Sum.java ├── 1345B - Card Constructions.java ├── 1348A - Phoenix and Balance.java ├── 1348B - Phoenix and Beauty.java ├── 1348C - Phoenix and Distribution.java ├── 1348D - Phoenix and Science.java ├── 1350A - Orac and Factors.java ├── 1350B - Orac and Models.java ├── 1350C - Orac and LCM.java ├── 1354B - Ternary String.java ├── 1354C1 - Simple Polygon Embedding.java ├── 1354C2 - Not So Simple Polygon Embedding.java ├── 1354D - Multiset.java ├── 1355A - Sequence with Digits.java ├── 1355B - Young Explorers.java ├── 1355C - Count Triangles.java ├── 1355D - Game With Array.java ├── 1355E - Restorer Distance.java ├── 1358B - Maria Breaks the Self-isolation.java ├── 1358C - Celex Update.java ├── 1358D - The Best Vacation.java ├── 1362A - Johnny and Ancient Computer.java ├── 1362B - Johnny and His Hobbies.java ├── 1362C - Johnny and Another Rating Drop.java ├── 1363A - Odd Selection.java ├── 1363B - Subsequence Hate.java ├── 1363C - Game On Leaves.java ├── 1364A - XXXXX.java ├── 1364B - Most socially-distanced subsequence.java ├── 1364C - Ehab and Prefix MEXs.java ├── 1364D - Ehab's Last Corollary.java ├── 1365A - Matrix Game.java ├── 1365B - Trouble Sort.java ├── 1365C - Rotation Matching.java ├── 1365D - Solve The Maze.java ├── 1367A - Short Substrings.java ├── 1367B - Even Array.java ├── 1367C - Social Distance.java ├── 1367D - Task On The Board.java ├── 1368A - C+=.java ├── 1368B - Codeforces Subsequences.java ├── 1369A - FashionabLee.java ├── 1369B - AccurateLee.java ├── 1369C - RationalLee.java ├── 1373B - 01 Game.java ├── 1373C - Pluses and Minuses.java ├── 1373D - Maximum Sum on Even Positions.java ├── 1374A - Required Remainder.java ├── 1374B - Multiply by 2, divide by 6.java ├── 1374C - Move Brackets.java ├── 1385D - a-Good String.java ├── 141A - Amusing Joke.java ├── 1422A - Fence.java ├── 1451B - Non-Substring Subsequence.java ├── 1451C - String Equality.java ├── 1471A - Strange Partition.java ├── 1471B - Strange List.java ├── 1471C - Strange Birthday Party.java ├── 1472B - Fair Division.java ├── 1472C - Long Jumps.java ├── 1472D - Even-Odd Game.java ├── 148D - Bag of mice.java ├── 152C - Pocket Book.java ├── 154A - Hometask.java ├── 156A - Message.java ├── 158B - Taxi.java ├── 158C - Cd and pwd commands.java ├── 158D - Ice Sculptures.java ├── 159D - Palindrome pairs.java ├── 160A - Twins.java ├── 161D - Distance in Tree.java ├── 165C - Another Problem on Strings.java ├── 166A - Rank List.java ├── 166E - Tetrahedron.java ├── 182D - Common Divisors.java ├── 189A - Cut Ribbon.cpp ├── 1B - Spreadsheet.java ├── 2048 Game.cpp ├── 20C - Dijkstra?.java ├── 214B - Hometask.java ├── 217A - Ice Skating.java ├── 219C - Color Stripe.java ├── 220A - Little Elephant and Problem.java ├── 224B - Array.java ├── 225C - Barcode.java ├── 230B - T-primes.java ├── 231C - To Add or Not to Add.java ├── 234C - Weather.java ├── 235A - LCM Challenge.java ├── 245B - Internet Address.java ├── 245H - Queries for Number of Palindromes.java ├── 246A - Alice and Bob.java ├── 246D - Colorful Graph.java ├── 248B - Chilly Willy.java ├── 255C - Almost Arithmetical Progression.java ├── 257C - View Angle.java ├── 258A - Little Elephant and Bits.java ├── 264A - Escape from Stones.java ├── 264B - Good Sequences.java ├── 268C - Beautiful Sets of Points.java ├── 269B - Greenhouse Effect.java ├── 26A - Almost Prime.java ├── 26B - Regular Bracket Sequence.java ├── 271D - Good Substrings ├── 272C - Dima and Staircase.java ├── 274A - k-Multiple Free Set.java ├── 274B - Zero Tree.java ├── 276C - Little Girl and Maximum Sum.java ├── 276D - Little Girl and Maximum XOR.java ├── 277A - Learning Languages.java ├── 279C - Ladder.java ├── 27A - Next Test.java ├── 282C - XOR and OR.java ├── 283A - Cows and Sequence.java ├── 285A - Slightly Decreasing Permutations.java ├── 285C - Building Permutation.java ├── 287B - Pipeline.java ├── 289B - Polo the Penguin and Matrix.java ├── 294B - Shaass and Bookshelf.java ├── 295A - Greg and Array.java ├── 295B - Greg and Graph.java ├── 2A - Winner.java ├── 300C - Beautiful Numbers.java ├── 313B - Ilya and Queries.java ├── 322B - Ciel and Flowers.java ├── 327A - Flipping Game.java ├── 332B - Maximum Absurdity.java ├── 337A - Puzzles.java ├── 339B - Xenia and Ringroad.java ├── 339C - Xenia and Weights.java ├── 339D - Xenia and Bit Operations.java ├── 340D - Bubble Sort Graph.java ├── 343A - Rational Resistance.java ├── 343B - Alternating Current.java ├── 348A - Mafia.java ├── 349A - Cinema Line.java ├── 349B - Color the Fence.java ├── 350C - Bombs.java ├── 356A - Knight Tournament.java ├── 358D - Dima and Hares.java ├── 359D - Pair of Numbers.java ├── 363B - Fence.java ├── 363C - Fixing Typos.java ├── 369C - Valera and Elections.java ├── 371C - Hamburgers.java ├── 372A - Counting Kangaroos is Fun.java ├── 377A - Maze.java ├── 382C - Arithmetic Progression.java ├── 385C - Bear and Prime Numbers.java ├── 388A - Fox and Box Accumulation.java ├── 400D - Dima and Bacteria.java ├── 404C - Restore Graph.java ├── 414B - Mashmokh and ACM.java ├── 416C - Booking System.java ├── 427C - Checkposts.java ├── 431C - k-Tree.java ├── 433B - Kuriyama Mirai's Stones.java ├── 437C - The Child and Toy.java ├── 439C - Devu and Partitioning of the Array.java ├── 439D - Devu and his Brother.java ├── 441C - Valera and Tubes.java ├── 443B - Kolya and Tandem Repeat.java ├── 446A - DZY Loves Sequences.java ├── 448C - Painting Fence.java ├── 448D - Multiplication Table.java ├── 451D - Count Good Substrings.java ├── 453A - Little Pony and Expected Maximum.java ├── 453B - Little Pony and Harmony Chest.java ├── 455A - Boredom.java ├── 456A - Laptops.java ├── 459E - Pashmak and Graph.java ├── 460B - Little Dima and Equation.java ├── 460C - Present.java ├── 463C - Gargari and Bishops.java ├── 466B - Wonder Room.java ├── 466C - Number of Ways.java ├── 467C - George and Job.java ├── 468A - 24 Game.java ├── 474D - Flowers.java ├── 476B - Dreamoon and WiF.java ├── 478C - Table Decorations.java ├── 479C - Exams.java ├── 479D - Long Jumps.java ├── 479E - Riding in a Lift.java ├── 483B - Friends and Presents.java ├── 484A - Bits.java ├── 486C - Palindrome Transformation.java ├── 486D - Valid Sets.java ├── 489B - BerSU Ball.java ├── 489C - Given Length and Sum of Digits....java ├── 490C - Hacking Cypher.java ├── 493C - Vasya and Basketball.java ├── 493D - Vasya and Chess.java ├── 496C - Removing Columns.java ├── 500B - New Year Permutation.java ├── 501A - Contest.java ├── 508C - Anya and Ghosts.java ├── 510C - Fox And Names.java ├── 514C - Watto and Mechanism.java ├── 514D - R2D2 and Droid Army.java ├── 518A - Vitaly and Strings.java ├── 519D - A and B and Interesting Substrings.java ├── 520B - Two Buttons.java ├── 522A - Reposts.java ├── 522B - Photo to Remember.java ├── 538B - Quasi Binary.java ├── 540C - Ice Cave.java ├── 545C - Woodcutters.java ├── 546D - Soldier and Number Game.java ├── 550A - Two Substrings.java ├── 550C - Divisibility by Eight.java ├── 553A - Kyoya and Colored Balls.java ├── 559A - Gerald's Hexagon.java ├── 559B - Equivalent Strings.java ├── 567C - Geometric Progression.java ├── 570C - Replacement.java ├── 577B - Modulo Sum.java ├── 580C - Kefa and Park.java ├── 58A - Chat Room.java ├── 598D - Igor In the Museum.java ├── 59B - Fortune Telling.java ├── 601A - The Two Routes.java ├── 603A - Alternative Thinking.java ├── 607A - Chain Reaction.java ├── 611C - New Year and Domino.java ├── 61A - Ultra-Fast Mathematician.java ├── 61D - Eternal Victory.java ├── 61E - Enemy is weak.java ├── 698A - Vacations(DP).java ├── 698A - Vacations(Greedy).java ├── 704A - Thor.java ├── 706C - Hard problem.java ├── 735C - Tennis Championship.java ├── 735D - Taxes.java ├── 75C - Modified GCD.java ├── 763A - Timofey and a tree.java ├── 778A - String Game.java ├── 785C - Anton and Fairy Tale.java ├── 788A - Functions again.java ├── 81A - Plug-in.java ├── 855B - Marvolo Gaunt's Ring.java ├── 86D - Powerful array.java ├── 888A - Local Extrema.java ├── 891A - Pride.java ├── 910A - The Way to Home.java ├── 913C - Party Lemonade.java ├── 920C - Swap Adjacent Elements.java ├── 94A - Restoring Password.java ├── 961B - Lecture Sleep.java ├── 96A - Football.java ├── 977F - Consecutive Subsequence.java ├── Alex and a Rhombus.cpp ├── All the Vowels Please.cpp ├── Almost All Divisors.cpp ├── Almost Equal.cpp ├── Another One Bites The Dust.cpp ├── Anton and currency you all know.cpp ├── Array Splitting.cpp ├── B2 - K for the Price of One (Hard Version).java ├── Basketball Exercise.cpp ├── Benches.cpp ├── Best Subsegment.cpp ├── Big Segment.cpp ├── Birthday.cpp ├── Books.cpp ├── BowWow and the Timetable.cpp ├── Boxers.cpp ├── Burning Midnight Oil.cpp ├── C - Ilya and Matrix.java ├── Candies.cpp ├── Candy Box (easy version).cpp ├── Cards.cpp ├── Chips Moving.cpp ├── Choose Two Numbers.cpp ├── Chunga-Changa.cpp ├── Cinema Line.cpp ├── Circle Metro.cpp ├── Circle of Students.cpp ├── City Day.cpp ├── Colored Boots.cpp ├── Common Divisors.cpp ├── Computer Game.cpp ├── Connect.cpp ├── Cover Points.cpp ├── DIY Wooden Ladder.cpp ├── Detective Book.cpp ├── Die Roll.cpp ├── Digital root.cpp ├── Distinct Characters Queries.cpp ├── Div Times Mod.cpp ├── Divide by three, multiply by two.cpp ├── Divisibility by Eight.cpp ├── Divisor Subtraction.cpp ├── Divisors of Two Integers.cpp ├── Domino.cpp ├── Drazil and Factorial.cpp ├── Drinks Choosing.cpp ├── Dubstep.cpp ├── Duff in Love.cpp ├── Eating Soup.cpp ├── Email from Polycarp.cpp ├── Enlarge GCD.cpp ├── Equal Rectangles.cpp ├── Equalize Prices Again.cpp ├── Equalize Prices.cpp ├── Filling Shapes.cpp ├── Football.cpp ├── Fox Dividing Cheese.cpp ├── From Hero to Zero.cpp ├── From S To T.cpp ├── Funky Numbers.cpp ├── Gambling.cpp ├── Game with string.cpp ├── Gas Pipeline.cpp ├── Given Length and Sum of Digits....cpp ├── Good String.cpp ├── Good Substrings.cpp ├── Gourmet Cat.cpp ├── Helpful Maths.cpp ├── Hide and Seek.cpp ├── High School: Become Human.cpp ├── Knights.cpp ├── Learning Languages.cpp ├── Letters Shop.cpp ├── Little C Loves 3 I.cpp ├── Little Elephant and Chess.cpp ├── Little Girl and Maximum Sum.cpp ├── Lost Numbers.cpp ├── Lucky Numbers (easy).cpp ├── Lucky Permutation Triple.cpp ├── Lucky Sum of Digits.cpp ├── Lunar New Year and Food Ordering.cpp ├── Lunar New Year and a Wander.cpp ├── Magic Numbers.cpp ├── Make It Equal.cpp ├── Make Product Equal One.cpp ├── Make The Fence Great Again.cpp ├── Make Them Equal.cpp ├── Math.cpp ├── Meme Problem.cpp ├── Mentors.cpp ├── Merge it!.cpp ├── Minimum Triangulation.cpp ├── Minimum Value Rectangle.cpp ├── Mislove Has Lost an Array.cpp ├── Multiplication Table.cpp ├── Nastya Is Playing Computer Games.cpp ├── Nastya Is Reading a Book.cpp ├── Nastya Is Transposing Matrices.cpp ├── Nauuo and Chess.cpp ├── Nauuo and Votes.cpp ├── Nearest Interesting Number.cpp ├── News Distribution.cpp ├── Nick and Array.cpp ├── Number Circle.cpp ├── Odd Sum Segments.cpp ├── Optimal Currency Exchange.cpp ├── Painting Pebbles.cpp ├── Perfect Team.cpp ├── Permutation.cpp ├── Petr and a Combination Lock.cpp ├── Pillars.cpp ├── Pipes.cpp ├── Playing Cubes.cpp ├── Points on Line.cpp ├── Polycarp Training.cpp ├── Prefix Sum Primes.cpp ├── Preparation for International Women's Day.cpp ├── Prime Graph.cpp ├── Prime Minister.cpp ├── Primes and Multiplication.cpp ├── Pythagorean Triples.cpp ├── Quasi Binary.cpp ├── Queen.cpp ├── Queries about less or equal elements.cpp ├── README.md ├── Recursive Queries.cpp ├── Remainder.cpp ├── Remove a Progression.cpp ├── Remove the Substring (easy version).cpp ├── Remove the Substring (hard version).cpp ├── Restoring Three Numbers.cpp ├── Road Construction.cpp ├── Rumor.cpp ├── Sagheer and Nubian Market.cpp ├── Sanatorium.cpp ├── Semifinals.cpp ├── Serval and Bus.cpp ├── Serval and Parenthesis Sequence.cpp ├── Serval and Toy Bricks.cpp ├── Shashlik Cooking.cpp ├── Silent Classroom.cpp ├── Social Network (easy version).cpp ├── Social Network (hard version).cpp ├── Soldier and Cards.cpp ├── Split a Number.cpp ├── Sport Mafia.cpp ├── Square Filling.cpp ├── Substring Game in the Lesson.cpp ├── Summarize to the Power of Two.cpp ├── Sushi for Two.cpp ├── Swap Letters.cpp ├── T-primes.cpp ├── Telephone Number.cpp ├── The Doctor Meets Vader (Easy).cpp ├── The Number of Products.cpp ├── The Party and Sweets.cpp ├── The World is a Theatre.cpp ├── Theatre Square.cpp ├── There Are Two Types Of Burgers.cpp ├── Ticket Game.cpp ├── Tiles.cpp ├── Tokitsukaze and Discard Items.cpp ├── Tokitsukaze and Mahjong.cpp ├── Tram.cpp ├── Two Bags of Potatoes.cpp ├── Two Buttons.cpp ├── Two Substrings.cpp ├── Ultra-Fast Mathematician.cpp ├── Uniqueness.cpp ├── Valeriy and Deque.cpp ├── Valhalla Siege.cpp ├── Vitamins.cpp ├── Vus the Cossack and Strings.cpp ├── WOW Factor.cpp ├── Walking Robot.cpp ├── Watchmen.cpp ├── Water Lily.cpp ├── Watto and Mechanism.cpp ├── Weather.cpp ├── World Cup.cpp ├── Worms.cpp ├── XORinacci.cpp ├── Xenia and Bit Operations.cpp ├── Xenia and Ringroad.cpp ├── Yellow Cards.cpp ├── You Are Given Two Binary Strings....cpp └── Zero Quantity Maximization.cpp /1-2-K Game.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define mod 1000000007 4 | #define pie 3.14 5 | typedef long long int ll; 6 | /* 7 | .d8b. d8888b. db db .d8b. d8b db 8 | d8' `8b 88 `8D `8b d8' d8' `8b 888o 88 9 | 88ooo88 88oobY' `8bd8' 88ooo88 88V8o 88 10 | 88~~~88 88`8b 88 88~~~88 88 V8o88 11 | 88 88 88 `88. 88 88 88 88 V888 12 | YP YP 88 YD YP YP YP VP V8P 13 | 14 | 15 | */ 16 | 17 | 18 | /////////////////////////////////////// 19 | int main() 20 | { 21 | ios_base::sync_with_stdio(false); 22 | cin.tie(NULL); 23 | #ifndef ONLINE_JUDGE 24 | freopen("input.txt","r",stdin); 25 | freopen("output.txt","w",stdout); 26 | #endif 27 | ll t; 28 | cin>>t; 29 | while(t--) 30 | { 31 | ll n,k,x,w=1; 32 | cin>>n>>k; 33 | if(k%3!=0) 34 | { 35 | if(n%3==0) 36 | w=0; 37 | } 38 | else 39 | { 40 | //cout<<"Heloo"; 41 | x=n%(k+1); 42 | if(x%3==0 && x!=k) 43 | w=0; 44 | } 45 | if(w==0) 46 | cout<<"Bob\n"; 47 | else 48 | cout<<"Alice\n"; 49 | } 50 | } -------------------------------------------------------------------------------- /110A - Nearly Lucky Number.java: -------------------------------------------------------------------------------- 1 | import java.io.IOException; 2 | import java.io.InputStreamReader; 3 | import java.sql.SQLOutput; 4 | import java.util.*; 5 | 6 | public class Candidate { 7 | public static void main(String[] args) throws Exception { 8 | Scanner sc=new Scanner(System.in); 9 | String s=sc.nextLine(); 10 | 11 | boolean a=false,b=false; 12 | int count=0; 13 | for(int i=0;i7){ 16 | System.out.println("NO");return; 17 | } 18 | } 19 | if(count==4 || count==7) System.out.println("YES"); 20 | else System.out.println("NO"); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /1140D - Minimum Triangulation.java: -------------------------------------------------------------------------------- 1 | import java.awt.*; 2 | import java.io.*; 3 | import java.util.Arrays; 4 | import java.util.HashSet; 5 | import java.util.Scanner; 6 | import java.util.Set; 7 | import java.util.ArrayList; 8 | import java.util.Collections; 9 | import java.util.StringTokenizer; 10 | import java.util.HashMap; 11 | import java.util.Map; 12 | 13 | public class problems { 14 | 15 | public static void main(String[] args) throws IOException { 16 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 17 | Scanner sc = new Scanner(System.in); 18 | int n=sc.nextInt(); 19 | long sol=0; 20 | for(int i=2;imin)min=count; 24 | } 25 | System.out.println(min); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /118A - String Task.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | import java.util.Scanner; 5 | import java.util.StringTokenizer; 6 | 7 | 8 | public class Candidate { 9 | public static void main(String[] args) throws Exception { 10 | Scanner sc=new Scanner(System.in); 11 | char[] c=sc.nextLine().toLowerCase().toCharArray(); 12 | 13 | for(int i=0;i[] hr,hb; 7 | static int[] dist; 8 | public static void main(String[] args) throws Exception { 9 | Scanner sc=new Scanner(System.in); 10 | StringBuilder sb=new StringBuilder(); 11 | int t=sc.nextInt(); 12 | while(t-->0){ 13 | int n=sc.nextInt(),x=sc.nextInt(); 14 | int max=Integer.MIN_VALUE; 15 | int dmax=-1; 16 | for(int i=0;imax){ 19 | max=d-h; 20 | } 21 | if(d>dmax)dmax=d; 22 | } 23 | if(max<=0 && x-dmax>0) sb.append(-1+"\n"); 24 | else{ 25 | x=x-dmax; 26 | sb.append((int)Math.ceil(x<=0?0:x/(double)max)+1+"\n"); 27 | } 28 | } 29 | System.out.println(sb); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /1230A - Dawid and Bags of Candies.java: -------------------------------------------------------------------------------- 1 | import java.io.DataInputStream; 2 | import java.io.FileInputStream; 3 | import java.io.IOException; 4 | import java.util.Arrays; 5 | import java.util.HashSet; 6 | import java.util.Scanner; 7 | import java.util.LinkedList; 8 | import java.util.Set; 9 | import java.util.ArrayList; 10 | import java.util.Collections; 11 | import java.util.StringTokenizer; 12 | import java.util.HashMap; 13 | import java.util.Map; 14 | import java.util.Stack; 15 | 16 | 17 | 18 | public class candidate { 19 | 20 | public static void main(String[] args) throws Exception { 21 | Scanner sc=new Scanner(System.in); 22 | int[] a=new int[4]; 23 | for(int i=0;i<4;i++)a[i]=sc.nextInt(); 24 | Arrays.sort(a); 25 | int x=0; 26 | int y=0; 27 | 28 | x=x+a[3]; 29 | y=y+a[2]+a[1]; 30 | if(x+a[0]==y){ 31 | System.out.println("YES"); 32 | return; 33 | } 34 | if(y+a[0]==x){ 35 | System.out.println("YES"); 36 | return; 37 | } 38 | System.out.println("NO"); 39 | 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /1234A - Equalize Prices Again.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | import java.util.HashSet; 3 | import java.util.Scanner; 4 | import java.util.Set; 5 | import java.util.ArrayList; 6 | import java.util.Collections; 7 | import java.util.StringTokenizer; 8 | import java.util.HashMap; 9 | import java.util.Map; 10 | import java.util.LinkedList; 11 | 12 | public class problems { 13 | public static void main(String[] args) { 14 | Scanner sc=new Scanner(System.in); 15 | int q=sc.nextInt(); 16 | while(q-->0){ 17 | int n=sc.nextInt(); 18 | int sum=0; 19 | for(int i=0;i0){ 11 | int a=sc.nextInt(); 12 | int b=sc.nextInt(); 13 | int c=sc.nextInt(); 14 | int sum=0; 15 | while(c>=2 && b>=1){ 16 | sum+=3; 17 | c=c-2; 18 | b=b-1; 19 | } 20 | while(b>=2 && a>=1){ 21 | sum+=3; 22 | b=b-2; 23 | a=a-1; 24 | } 25 | System.out.println(sum); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /1236B - Alice and the List of Presents.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | import java.util.*; 5 | 6 | public class Main { 7 | public static void main(String[] args) throws Exception { 8 | Scanner sc=new Scanner(System.in); 9 | int n=sc.nextInt(); 10 | int m=sc.nextInt(); // Number Of Ways -> ((2^m)-1)^n 11 | 12 | long sum=0; 13 | sum=binpow(2,m,1000000007); 14 | sum=sum-1; 15 | sum=binpow(sum,n,1000000007); 16 | System.out.println(sum); 17 | } 18 | static long binpow(long a, long b, long m){ 19 | a %= m; 20 | long res = 1; 21 | while (b > 0) { 22 | if ((b&1)==1) 23 | res = res * a % m; 24 | a = a * a % m; 25 | b >>= 1; 26 | } 27 | return res; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /1278B - A and B.java: -------------------------------------------------------------------------------- 1 | import java.awt.Point; 2 | import java.io.BufferedReader; 3 | import java.io.IOException; 4 | import java.io.InputStreamReader; 5 | import java.util.*; 6 | 7 | 8 | public class Candidate { 9 | public static void main(String[] args) throws Exception { 10 | Scanner sc=new Scanner(System.in); 11 | int t = sc.nextInt(); 12 | while (t-->0){ 13 | long a=sc.nextInt(),b=sc.nextInt(); 14 | if (a>b){ 15 | long tmp=a; 16 | a=b; 17 | b=tmp; 18 | } 19 | int sol=0; 20 | while (a0){ 13 | int[] arr=new int[3]; 14 | for(int i=0;i<3;i++)arr[i]=sc.nextInt(); 15 | Arrays.sort(arr); 16 | if(arr[0]+arr[1]0) { 9 | int n = sc.nextInt(); 10 | int m = sc.nextInt(); 11 | int[] a, b; 12 | a = new int[n]; 13 | for (int i = 0; i < n; i++) a[i] = sc.nextInt(); 14 | b = new int[m]; 15 | for (int i = 0; i < m; i++) b[i] = sc.nextInt(); 16 | HashSet hs = new HashSet<>(); 17 | int current = 0; 18 | long time = 0; 19 | for (int i = 0; i < m; i++) { 20 | if (hs.contains(b[i])) { 21 | time++; 22 | hs.remove(b[i]); 23 | } else { 24 | while (a[current] != b[i]) { 25 | hs.add(a[current]); 26 | current++; 27 | } 28 | time = time + 2 * hs.size() + 1; 29 | current++; 30 | } 31 | } 32 | System.out.println(time); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /1282A - Temporarily unavailable.java: -------------------------------------------------------------------------------- 1 | import java.awt.Point; 2 | import java.io.BufferedReader; 3 | import java.io.IOException; 4 | import java.io.InputStreamReader; 5 | import java.util.*; 6 | 7 | public class Candidate { 8 | public static void main(String[] args) throws Exception { 9 | Scanner sc=new Scanner(System.in); 10 | int t=sc.nextInt(); 11 | while(t-->0) { 12 | int a=sc.nextInt(),b=sc.nextInt(),c=sc.nextInt(),r=sc.nextInt(),l=c-r; 13 | r=c+r; 14 | if(b=0?(b-z):0); 22 | } 23 | else{ 24 | int z=Integer.min(b,l); 25 | System.out.println(z-a+(b-r>=0?b-r:0)); 26 | } 27 | 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /1283A - Minutes Before the New Year.java: -------------------------------------------------------------------------------- 1 | import java.awt.Point; 2 | import java.io.BufferedReader; 3 | import java.io.IOException; 4 | import java.io.InputStreamReader; 5 | import java.util.*; 6 | 7 | 8 | public class Candidate { 9 | public static void main(String[] args) throws Exception { 10 | Scanner sc=new Scanner(System.in); 11 | int t=sc.nextInt(); 12 | while(t-->0){ 13 | int h=sc.nextInt(); 14 | int m=sc.nextInt(); 15 | int c=(23-h)*60+(60-m); 16 | System.out.println(c); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /1283B - Candies Division.java: -------------------------------------------------------------------------------- 1 | import java.awt.Point; 2 | import java.io.BufferedReader; 3 | import java.io.IOException; 4 | import java.io.InputStreamReader; 5 | import java.util.*; 6 | 7 | 8 | public class Candidate { 9 | public static void main(String[] args) throws Exception { 10 | Scanner sc=new Scanner(System.in); 11 | int t=sc.nextInt(); 12 | while(t-->0){ 13 | int n=sc.nextInt(); 14 | int k=sc.nextInt(); 15 | int ans=(n/k); 16 | int sol=ans*k; 17 | 18 | n=n-sol; 19 | if(n<=Math.floor(k/2))sol+=n; 20 | else sol+=Math.floor(k/2); 21 | System.out.println(sol); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /1284A - New Year and Naming.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class Main { 5 | public static void main(String[] args) { 6 | FastReader sc = new FastReader(); 7 | int n=sc.nextInt(),m=sc.nextInt(); 8 | String[] str=new String[n+1]; 9 | String[] str2=new String[m+1]; 10 | for(int i=1;i<=n;i++)str[i]=sc.next(); 11 | for(int i=1;i<=m;i++)str2[i]=sc.next(); 12 | int q=sc.nextInt(); 13 | while(q-->0){ 14 | int y=sc.nextInt(); 15 | int a=y%n; 16 | int b=y%m; 17 | if(a==0)a=n; 18 | if(b==0)b=m; 19 | System.out.println(str[a]+""+str2[b]); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /1287A - Angry Students.java: -------------------------------------------------------------------------------- 1 | import java.awt.Point; 2 | import java.io.BufferedReader; 3 | import java.io.IOException; 4 | import java.io.InputStreamReader; 5 | import java.util.ArrayList; 6 | import java.util.Arrays; 7 | import java.util.HashSet; 8 | import java.util.StringTokenizer; 9 | 10 | 11 | public class Main { 12 | public static void main(String[] args) { 13 | Scanner sc=new Scanner(System.in); 14 | int t=sc.nextInt(); 15 | while(t-->0){ 16 | int n=sc.nextInt(); 17 | char[] c=sc.next().toCharArray(); 18 | int count=0; 19 | while(true){ 20 | boolean z=true; 21 | for(int i=0;i0) { 14 | long n = sc.nextInt(), d = sc.nextInt(); 15 | long x = (n - 1) / 2, b = n - d; 16 | long a = x * x + x * (1 - n); 17 | if (a <= b) sb.append("YES\n"); 18 | else sb.append("NO\n"); 19 | } 20 | System.out.println(sb); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /1291A - Even But Not Even.java: -------------------------------------------------------------------------------- 1 | import javax.print.attribute.standard.PrintQuality; 2 | import java.awt.*; 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStreamReader; 6 | import java.io.PrintWriter; 7 | import java.math.BigInteger; 8 | import java.util.*; 9 | import java.util.List; 10 | 11 | public class Main { 12 | static int mod = (int) 1e9 + 7; 13 | public static void main(String[] args) { 14 | Scanner sc=new Scanner(System.in); 15 | int t=sc.nextInt(); 16 | StringBuilder sb=new StringBuilder(); 17 | while (t-->0){ 18 | int n=sc.nextInt(); 19 | String s=sc.next(); 20 | int od=0; 21 | String ss=""; 22 | for (int i=0;i0) { 17 | int n=sc.nextInt(),m=sc.nextInt(),k=sc.nextInt(); 18 | int[] arr=new int[n]; 19 | for(int i=0;i0){ 13 | sum=sum+1/(double)n; 14 | n--; 15 | } 16 | System.out.println(sum); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /1294A - Collecting Coins.java: -------------------------------------------------------------------------------- 1 | import java.awt.*; 2 | import java.io.BufferedReader; 3 | import java.io.IOException; 4 | import java.io.InputStreamReader; 5 | import java.util.*; 6 | 7 | public class Main { 8 | static int mod=(int)1e9+7; 9 | public static void main(String[] args) throws Exception { 10 | Scanner sc=new Scanner(System.in); 11 | int t=sc.nextInt(); 12 | while(t-->0){ 13 | long a=sc.nextInt(),b=sc.nextInt(),c=sc.nextInt(),n=sc.nextInt(); 14 | double x=(n+a+b+c)/3.0; 15 | if(x>(int)x) System.out.println("NO"); 16 | else { 17 | if(x>=Math.max(a,Math.max(b,c)))System.out.println("YES"); 18 | else System.out.println("NO"); 19 | } 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /1294D - MEX maximizing.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | import java.util.*; 5 | 6 | public class Main { 7 | static int mod=(int)1e9+7; 8 | public static void main(String[] args) throws IOException { 9 | Scanner sc=new Scanner(System.in); 10 | int q=sc.nextInt(),x=sc.nextInt(); 11 | TreeSet array[]=new TreeSet[5*100000]; 12 | for (int i=0;i(); 13 | TreeSet treeset=new TreeSet<>(); 14 | for (int i=0;i<500000;i++){ 15 | array[i%x].add(i); 16 | treeset.add(i); 17 | } 18 | StringBuilder sb=new StringBuilder(); 19 | while (q-->0){ 20 | int z=sc.nextInt(); 21 | if (!array[z%x].isEmpty()){ 22 | int a=array[z%x].pollFirst(); 23 | treeset.remove(a); 24 | } 25 | sb.append(treeset.first()+"\n"); 26 | } 27 | System.out.print(sb); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /1295A - Display The Number.java: -------------------------------------------------------------------------------- 1 | import java.awt.*; 2 | import java.io.BufferedReader; 3 | import java.io.IOException; 4 | import java.io.InputStreamReader; 5 | import java.math.BigInteger; 6 | import java.util.*; 7 | import java.util.List; 8 | 9 | public class Main { 10 | static int mod = (int) 1e9 + 7; 11 | public static void main(String[] args){ 12 | Scanner sc=new Scanner(System.in); 13 | StringBuilder sb=new StringBuilder(); 14 | int t=sc.nextInt(); 15 | while(t-->0){ 16 | int n=sc.nextInt(); 17 | if(n%2==1){ 18 | sb.append('7'); 19 | n=n-3; 20 | } 21 | while(n>=2){ 22 | sb.append("1"); 23 | n=n-2; 24 | } 25 | sb.append('\n'); 26 | } 27 | System.out.println(sb); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /1295D - Same GCDs.java: -------------------------------------------------------------------------------- 1 | import java.awt.*; 2 | import java.io.BufferedReader; 3 | import java.io.IOException; 4 | import java.io.InputStreamReader; 5 | import java.math.BigInteger; 6 | import java.util.*; 7 | import java.util.List; 8 | 9 | public class Main { 10 | static int mod = (int) 1e9 + 7; 11 | public static void main(String[] args){ 12 | Scanner sc=new Scanner(System.in); 13 | StringBuilder sb=new StringBuilder(); 14 | int t=sc.nextInt(); 15 | while(t-->0) { 16 | long a=sc.nextLong(),m=sc.nextLong(); 17 | a=m/gcd(a,m); 18 | sb.append(eulerT(a)+"\n"); 19 | } 20 | System.out.println(sb); 21 | } 22 | static long gcd(long a,long b){ 23 | if(b==0)return a; 24 | else return gcd(b,a%b); 25 | } 26 | static long eulerT(long m){ 27 | long res=m; 28 | for(long i=2;i*i<=m;i++){ 29 | if(m%i==0){ 30 | res=res-res/i; 31 | while(m%i==0)m/=i; 32 | } 33 | } 34 | if(m>1)res-=res/m; 35 | return res; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /1296A - Array with Odd Sum.java: -------------------------------------------------------------------------------- 1 | import javax.print.attribute.standard.PrintQuality; 2 | import java.awt.*; 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStreamReader; 6 | import java.io.PrintWriter; 7 | import java.math.BigInteger; 8 | import java.util.*; 9 | import java.util.List; 10 | 11 | public class Main { 12 | static int mod = (int) 1e9 + 7; 13 | public static void main(String[] args) { 14 | Scanner sc=new Scanner(System.in); 15 | int t=sc.nextInt(); 16 | StringBuilder sb=new StringBuilder(); 17 | while(t-->0){ 18 | int n=sc.nextInt(); 19 | int[] arr=new int[n]; 20 | for(int i=0;i0){ 26 | if(odd==n && n%2==0)sb.append("NO"); 27 | else sb.append("YES"); 28 | } 29 | else sb.append("NO"); 30 | sb.append("\n"); 31 | } 32 | System.out.println(sb); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /1296B - Food Buying.java: -------------------------------------------------------------------------------- 1 | import java.awt.*; 2 | import java.io.BufferedReader; 3 | import java.io.IOException; 4 | import java.io.InputStreamReader; 5 | import java.io.PrintWriter; 6 | import java.math.BigInteger; 7 | import java.util.*; 8 | import java.util.List; 9 | 10 | public class Main { 11 | static int mod = (int) 1e9 + 7; 12 | public static void main(String[] args) { 13 | Scanner sc=new Scanner(System.in); 14 | int t = sc.nextInt(); 15 | StringBuilder sb = new StringBuilder(); 16 | while (t-- > 0) { 17 | int n = sc.nextInt(); 18 | int sol=0; 19 | while(n>0){ 20 | int temp=n/10; 21 | temp=temp*10; 22 | if(temp==0){ 23 | sol+=n; 24 | break; 25 | } 26 | n=n-temp; 27 | sol+=temp; 28 | n=n+(temp/10); 29 | } 30 | sb.append(sol+"\n"); 31 | } 32 | System.out.println(sb); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /1300A - Non-zero.java: -------------------------------------------------------------------------------- 1 | import java.awt.*; 2 | import java.io.BufferedReader; 3 | import java.io.IOException; 4 | import java.io.InputStreamReader; 5 | import java.io.PrintWriter; 6 | import java.math.BigInteger; 7 | import java.util.*; 8 | import java.util.List; 9 | 10 | public class Main { 11 | static int mod = (int) 1e9 + 7; 12 | public static void main(String[] args) { 13 | Scanner sc=new Scanner(System.in); 14 | int t=sc.nextInt(); 15 | while(t-->0){ 16 | int n=sc.nextInt(); 17 | int temp=0,sum=0,zero=0; 18 | for(int i=0;i0) System.out.println(sum+zero==0?zero+1:zero); 24 | else System.out.println(sum==0?1:0); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /1300B - Assigning to Classes.java: -------------------------------------------------------------------------------- 1 | import java.awt.*; 2 | import java.io.BufferedReader; 3 | import java.io.IOException; 4 | import java.io.InputStreamReader; 5 | import java.io.PrintWriter; 6 | import java.math.BigInteger; 7 | import java.util.*; 8 | import java.util.List; 9 | 10 | public class Main { 11 | static int mod = (int) 1e9 + 7; 12 | public static void main(String[] args) { 13 | Scanner sc=new Scanner(System.in); 14 | int t=sc.nextInt(); 15 | while(t-->0) { 16 | int n = sc.nextInt(); 17 | int arr[] = new int[2*n]; 18 | for(int i=0;i=0;i--){ 20 | int occur=0; 21 | for(int j=0;j=1){ 23 | index=j; 24 | occur++; 25 | } 26 | } 27 | if(occur==1)break; 28 | } 29 | int temp=arr[index]; 30 | arr[index]=arr[0]; 31 | arr[0]=temp; 32 | for(int i=0;i0){ 17 | String a=sc.nextLine(),b=sc.nextLine(),c=sc.nextLine(); 18 | boolean z=false; 19 | for(int i=0;i0){ 11 | long n=sc.nextInt(),m=sc.nextInt(); 12 | long zero=n-m; 13 | long k=zero/(m+1); 14 | sb.append((n*(n+1)/2)-((m+1)*k*(k+1)/2)-((k+1)*(zero%(m+1)))+"\n"); 15 | } 16 | System.out.println(sb); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /1303A - Erasing Zeroes.java: -------------------------------------------------------------------------------- 1 | import java.awt.*; 2 | import java.io.BufferedReader; 3 | import java.io.IOException; 4 | import java.io.InputStreamReader; 5 | import java.io.PrintWriter; 6 | import java.math.BigInteger; 7 | import java.util.*; 8 | import java.util.List; 9 | 10 | public class Main { 11 | static int mod = (int) 1e9 + 7; 12 | public static void main(String[] args) { 13 | Scanner sc=new Scanner(System.in); 14 | int t=sc.nextInt(); 15 | while(t-->0){ 16 | String s=sc.next(); 17 | boolean z=false; 18 | int first=s.length(); 19 | for(int i=0;i=0;i--){ 27 | if(s.charAt(i)=='1'){ 28 | last=i; 29 | break; 30 | } 31 | } 32 | int total=0; 33 | for(int i=first;i<=last;i++){ 34 | if(s.charAt(i)=='0')total++; 35 | } 36 | System.out.println(total); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /1303B - National Project.java: -------------------------------------------------------------------------------- 1 | import java.awt.*; 2 | import java.io.BufferedReader; 3 | import java.io.IOException; 4 | import java.io.InputStreamReader; 5 | import java.io.PrintWriter; 6 | import java.math.BigInteger; 7 | import java.util.*; 8 | import java.util.List; 9 | 10 | public class Main { 11 | static int mod = (int) 1e9 + 7; 12 | static int[][] shows; 13 | public static void main(String[] args) { 14 | Scanner sc=new Scanner(System.in); 15 | int t=sc.nextInt(); 16 | while(t-->0) { 17 | long n=sc.nextInt(),g=sc.nextInt(),b=sc.nextInt(); 18 | long x=(long)Math.ceil(n/(2.0*g)); 19 | if((x-1)*b<=n-x*g) System.out.println(n); 20 | else System.out.println((long)Math.ceil(n/2.0)+Math.max((x-1)*b,n-(long)Math.ceil(n/2.0))); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /1305C - Kuroni and Impossible Calculation.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | import java.util.*; 5 | 6 | public class Main { 7 | static int mod=(int)1e9+7; 8 | public static void main(String[] args) throws Exception { 9 | Scanner sc=new Scanner(System.in); 10 | int n=sc.nextInt(),m=sc.nextInt(); 11 | int[] arr=new int[n]; 12 | for(int i=0;im) System.out.println(0); 14 | else{ 15 | long ans=1; 16 | for(int i=0;i[] ll; 8 | public static void main(String[] args) throws Exception { 9 | Scanner sc=new Scanner(System.in); 10 | int t=sc.nextInt(); 11 | while(t-->0){ 12 | int n=sc.nextInt(),d=sc.nextInt(); 13 | int[] arr=new int[n]; 14 | for(int i=0;i0){ 16 | for (int i=1;i0){ 18 | arr[i]--; 19 | arr[i-1]++; 20 | break; 21 | } 22 | } 23 | System.out.println(arr[0]); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /1307B - Cow and Friend.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.lang.reflect.Array; 3 | import java.util.*; 4 | import java.awt.Point; 5 | 6 | public class Main { 7 | static LinkedList[] ll; 8 | public static void main(String[] args) throws Exception { 9 | Scanner sc=new Scanner(System.in); 10 | int t=sc.nextInt(); 11 | while(t-->0){ 12 | int n=sc.nextInt(),d=sc.nextInt(); 13 | int max=0; 14 | HashSet hs=new HashSet<>(); 15 | for(int i=0;i[] ll; 8 | public static void main(String[] args) throws Exception { 9 | Scanner sc=new Scanner(System.in); 10 | String s = sc.nextLine(); 11 | int[] arr = new int[26]; 12 | long[][] freq=new long[26][26]; 13 | for(int i=0;i0){ 13 | int a=sc.nextInt(),b=sc.nextInt(); 14 | if (a==b) sb.append(0+"\n"); 15 | else if (a-b<0){ 16 | if ((b-a)%2==1){ 17 | sb.append(1+"\n"); 18 | }else sb.append(2+"\n"); 19 | }else { 20 | if ((a-b)%2==0){ 21 | sb.append(1+"\n"); 22 | }else sb.append(2+"\n"); 23 | } 24 | } 25 | System.out.println(sb); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /1312B - Bogosort.java: -------------------------------------------------------------------------------- 1 | import java.awt.*; 2 | import java.io.*; 3 | import java.math.BigInteger; 4 | import java.util.*; 5 | 6 | public class Main { // Answer is reverse sort. 7 | static int mod = (int) 1e9 + 7; 8 | public static void main(String[] args) throws Exception { 9 | Scanner sc=new Scanner(System.in); 10 | int t=sc.nextInt(); 11 | while (t-->0){ 12 | int n=sc.nextInt(); 13 | int[] arr=new int[n]; 14 | for(int i=0;i0;j--){ 16 | int max=Integer.MIN_VALUE; 17 | int index=-1; 18 | for(int i=0;imax){ 20 | index=i; 21 | max=j-arr[i]; 22 | } 23 | } 24 | int temp=arr[j-1]; 25 | arr[j-1]=arr[index]; 26 | arr[index]=temp; 27 | } 28 | for(int i=0;i0) { 13 | int n = sc.nextInt(), k = sc.nextInt(); 14 | long[] arr = new long[n]; 15 | byte[] count=new byte[64]; 16 | for (int i = 0; i < n; i++) arr[i] = sc.nextLong(); 17 | boolean z=false; 18 | 19 | for(int i=0;i1)z=true; 23 | if(arr[i]%k!=0)count[c]++; 24 | if(count[c]>1)z=true; 25 | c++; 26 | arr[i]/=k; 27 | } 28 | if(z)break; 29 | } 30 | if(z)sb.append("NO\n"); 31 | else sb.append("YES\n"); 32 | } 33 | System.out.println(sb); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /1315A - Dead Pixel.java: -------------------------------------------------------------------------------- 1 | 2 | import java.awt.Point; 3 | import java.io.*; 4 | import java.util.*; 5 | 6 | public class Main { 7 | static int z=0; 8 | public static void main(String[] args)throws IOException{ 9 | Scanner sc=new Scanner(System.in); 10 | int t=sc.nextInt(); 11 | while (t-->0){ 12 | long a=sc.nextInt(),b=sc.nextInt(),x=sc.nextInt(),y=sc.nextInt(); 13 | long ans=Math.max(b*x,Math.max(y*a,Math.max((a-x-1)*b,(b-y-1)*a))); 14 | System.out.println(ans); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /1316C - Primitive Primes.java: -------------------------------------------------------------------------------- 1 | import java.awt.*; 2 | import java.io.BufferedReader; 3 | import java.io.IOException; 4 | import java.io.InputStreamReader; 5 | import java.util.*; 6 | 7 | public class Main { 8 | static int mod=(int)1e9+7; 9 | public static void main(String[] args) throws Exception { 10 | Scanner sc=new Scanner(System.in); 11 | StringBuilder sb=new StringBuilder(); 12 | int n=sc.nextInt(),m=sc.nextInt(),p=sc.nextInt(); 13 | int temp,x=-1,y=-1; 14 | 15 | for(int i=0;i0)System.out.println(2); 30 | else System.out.println(-1); 31 | } 32 | else System.out.println(1); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /1321B - Journey Planning.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | import java.util.*; 5 | 6 | public class Main { 7 | static int mod=(int)1e9+7; 8 | public static void main(String[] args) throws Exception { 9 | Scanner sc=new Scanner(System.in); 10 | int n=sc.nextInt(); 11 | int[] nums = new int[n]; 12 | HashMap hm = new HashMap(); 13 | for (int i = 0; i < n; i++) { 14 | nums[i] = sc.nextInt(); 15 | int x = nums[i]-i; 16 | hm.put(x, hm.getOrDefault(x, 0L)+(x+i+0L)); 17 | } 18 | long ans = 0; 19 | for (int key: hm.keySet()) ans = Math.max(ans,hm.get(key)); 20 | System.out.println(ans); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /1323A - Even Subset Sum Problem.java: -------------------------------------------------------------------------------- 1 | import java.awt.*; 2 | import java.io.*; 3 | import java.math.BigInteger; 4 | import java.util.*; 5 | 6 | public class Main { 7 | public static void main(String[] args) throws Exception { 8 | Scanner sc=new Scanner(System.in); 9 | int t=sc.nextInt(); 10 | while (t-->0){ 11 | int n=sc.nextInt(); 12 | int arr[]=new int[n]; 13 | int ind=-1; 14 | ArrayList ans=new ArrayList<>(); 15 | for (int i=0;i=2){ 25 | System.out.println(2); 26 | System.out.println(ans.get(0)+" "+ans.get(1)); 27 | }else System.out.println(-1); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /1323C - Unusual Competitions.java: -------------------------------------------------------------------------------- 1 | import java.awt.*; 2 | import java.io.*; 3 | import java.math.BigInteger; 4 | import java.util.*; 5 | 6 | public class Main { 7 | public static void main(String[] args) throws Exception { 8 | Scanner sc=new Scanner(System.in); 9 | int n=sc.nextInt(); 10 | char[] c=sc.next().toCharArray(); 11 | int count=0; 12 | for(int i=0;i0)min--; 24 | else{ 25 | min--; 26 | temp++; 27 | } 28 | } 29 | else{ 30 | if(min>=0)min++; 31 | else{ 32 | min++; 33 | temp++; 34 | } 35 | } 36 | if(min==0){ 37 | ans+=temp; 38 | temp=0; 39 | } 40 | } 41 | System.out.println(ans); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /1324A - Yet Another Tetris Problem.java: -------------------------------------------------------------------------------- 1 | import java.awt.*; 2 | import java.io.*; 3 | import java.util.*; 4 | 5 | public class Main { 6 | public static void main(String[] args) throws Exception { 7 | Scanner sc=new Scanner(System.in); 8 | StringBuilder sb=new StringBuilder(); 9 | int test=sc.nextInt(); 10 | while (test-->0){ 11 | int n=sc.nextInt(); 12 | int[] arr=new int[n]; 13 | int min=100; 14 | for(int i=0;i0){ 12 | int n=sc.nextInt(); 13 | int[] arr=new int[n]; 14 | for(int i=0;i0){ 11 | String s=sc.next(); 12 | int ans=0,z=0; 13 | for (int i=0;i0){ 21 | sum+=(n-(i+1)); 22 | } 23 | else{ 24 | int l=i+1,r=n-1,ans=-1; 25 | while(l<=r){ 26 | int mid=l+(r-l)/2; 27 | if(c[mid]+c[i]>0){ 28 | ans=mid; 29 | r=mid-1; 30 | } 31 | else l=mid+1; 32 | } 33 | if(ans!=-1)sum+=(n-ans); 34 | } 35 | } 36 | System.out.println(sum); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /1325A - EhAb AnD gCd.java: -------------------------------------------------------------------------------- 1 | import java.awt.*; 2 | import java.io.*; 3 | import java.util.*; 4 | 5 | public class Main { 6 | public static void main(String[] args) throws Exception { 7 | Scanner sc=new Scanner(System.in); 8 | StringBuilder sb=new StringBuilder(); 9 | int t=sc.nextInt(); 10 | while(t-->0){ 11 | int x=sc.nextInt(); 12 | sb.append(1+" "+(x-1)+"\n"); 13 | } 14 | System.out.println(sb); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /1325B - CopyCopyCopyCopyCopy.java: -------------------------------------------------------------------------------- 1 | import java.awt.*; 2 | import java.io.*; 3 | import java.util.*; 4 | 5 | public class Main { 6 | public static void main(String[] args) throws Exception { 7 | Scanner sc=new Scanner(System.in); 8 | StringBuilder sb=new StringBuilder(); 9 | int t=sc.nextInt(); 10 | while(t-->0) { 11 | int n = sc.nextInt(); 12 | HashSet hs = new HashSet<>(); 13 | for (int i = 0; i < n; i++) hs.add(sc.nextInt()); 14 | sb.append(hs.size()+"\n"); 15 | } 16 | System.out.println(sb); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /1325D - Ehab the Xorcist.java: -------------------------------------------------------------------------------- 1 | import java.awt.*; 2 | import java.io.*; 3 | import java.util.*; 4 | 5 | public class Main { 6 | public static void main(String[] args) throws Exception { 7 | Scanner sc=new Scanner(System.in); 8 | StringBuilder sb=new StringBuilder(); 9 | long u=sc.nextLong(),v=sc.nextLong(),x=(v-u)/2; 10 | if(u>v || ((u&1)!=(v&1))){ 11 | System.out.println(-1); 12 | } 13 | else if(u==v){ 14 | if(u==0) System.out.println(0); 15 | else{ 16 | System.out.println(1); 17 | System.out.println(u); 18 | } 19 | } 20 | else if((u&x)==0){ 21 | System.out.println(2); 22 | System.out.println(x+" "+(u+x)); 23 | } 24 | else{ 25 | System.out.println(3); 26 | System.out.println(x+" "+x+" "+u); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /1326A - Bad Ugly Numbers.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | import java.awt.*; 4 | 5 | public class Main { 6 | public static void main(String[] args) throws Exception { 7 | Scanner sc=new Scanner(System.in); 8 | StringBuilder sb=new StringBuilder(); 9 | int t=sc.nextInt(); 10 | while(t-->0){ 11 | int n=sc.nextInt(); 12 | if(n==1)sb.append(-1); 13 | else{ 14 | sb.append(2); 15 | n--; 16 | while(n-->0)sb.append(3); 17 | } 18 | sb.append("\n"); 19 | } 20 | System.out.println(sb); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /1330A - Dreamoon and Ranking Collection.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | import java.awt.*; 4 | 5 | public class Main { 6 | public static void main(String[] args) throws Exception { 7 | Scanner sc=new Scanner(System.in); 8 | StringBuilder sb=new StringBuilder(); 9 | int t=sc.nextInt(); 10 | while(t-->0) { 11 | int n = sc.nextInt(), x = sc.nextInt(); 12 | HashSet hs=new HashSet<>(); 13 | for(int i=0;i 0) { 16 | if(!hs.contains(i)) x--; 17 | i++; 18 | } 19 | while(hs.contains(i)) i++; 20 | i--; 21 | sb.append(i+"\n"); 22 | } 23 | System.out.println(sb); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /1332A - Exercising Walk.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.text.DecimalFormat; 3 | import java.util.*; 4 | import java.awt.*; 5 | 6 | public class Main { 7 | public static void main(String[] args) throws Exception { 8 | Scanner sc=new Scanner(System.in); 9 | StringBuilder sb=new StringBuilder(); 10 | int t=sc.nextInt(); 11 | while(t-->0) { 12 | int a=sc.nextInt(),b=sc.nextInt(),c=sc.nextInt(),d=sc.nextInt(); 13 | int x=sc.nextInt(),y=sc.nextInt(),x1=sc.nextInt(),y1=sc.nextInt(),x2=sc.nextInt(),y2=sc.nextInt(); 14 | int lr=Math.abs(a-b); 15 | int ud=Math.abs(c-d); 16 | boolean LR=false; 17 | boolean UD=false; 18 | if(a>b && x-(a-b)>=x1)LR=true; 19 | else if(b>a && x+(b-a)<=x2)LR=true; 20 | else if(a==b && (a==0 || x-1>=x1 || x+1<=x2))LR=true; 21 | 22 | if(c>d && y-(c-d)>=y1)UD=true; 23 | else if(d>c && y+(d-c)<=y2)UD=true; 24 | else if(d==c && (c==0 || y-1>=y1 || y+1<=y2))UD=true; 25 | 26 | if(LR && UD)sb.append("YES\n"); 27 | else sb.append("NO\n"); 28 | } 29 | System.out.println(sb); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /1332D - Walk on Matrix.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | import java.awt.*; 4 | 5 | public class Main { 6 | public static void main(String[] args) throws Exception { 7 | Scanner sc=new Scanner(System.in); 8 | StringBuilder sb=new StringBuilder(); 9 | int k=sc.nextInt(); 10 | sb.append("2 3\n"); 11 | sb.append(131072+k+" "+131072+" "+0+"\n"); 12 | sb.append(k+" "+(131072+k)+" "+k); 13 | System.out.println(sb); 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /1341A - Nastya and Rice.java: -------------------------------------------------------------------------------- 1 | import java.awt.*; 2 | import java.util.*; 3 | import java.io.*; 4 | 5 | public class Main { 6 | public static void main(String[] args) throws Exception { 7 | Scanner sc=new Scanner(System.in); 8 | StringBuilder sb=new StringBuilder(); 9 | int t=sc.nextInt(); 10 | while (t-->0){ 11 | int n=sc.nextInt(); 12 | int a=sc.nextInt(); 13 | int b=sc.nextInt(); 14 | int c=sc.nextInt(); 15 | int d=sc.nextInt(); 16 | 17 | if ((a-b)*n<=c+d && (a+b)*n>=c-d)sb.append("YES\n"); 18 | else sb.append("NO\n"); 19 | } 20 | System.out.println(sb); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /1374A - Required Remainder.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | import java.awt.*; 4 | 5 | public class Main{ 6 | static StringBuilder sb; 7 | public static void main(String[] args) { 8 | Scanner sc=new Scanner(System.in); 9 | sb=new StringBuilder(); 10 | int t=sc.nextInt(); 11 | while(t-->0){ 12 | int x=sc.nextInt(),y=sc.nextInt(),n=sc.nextInt(); 13 | int z=n%x; 14 | if(z>y){ 15 | n-=(z-y); 16 | sb.append(n); 17 | } 18 | else if(z==y)sb.append(n); 19 | else{ 20 | n-=x; 21 | n+=(y-z); 22 | sb.append(n); 23 | } 24 | sb.append("\n"); 25 | } 26 | System.out.println(sb); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /1374B - Multiply by 2, divide by 6.java: -------------------------------------------------------------------------------- 1 | import java.awt.*; 2 | import java.util.*; 3 | 4 | public class Main { 5 | public static void main(String[] args) { 6 | Scanner sc=new Scanner(System.in); 7 | StringBuilder sb=new StringBuilder(); 8 | int t=sc.nextInt(); 9 | while(t-->0){ 10 | int n=sc.nextInt(); 11 | int two=0,three=0; 12 | while(n%2==0){ 13 | n/=2; 14 | two++; 15 | } 16 | while(n%3==0){ 17 | n/=3; 18 | three++; 19 | } 20 | if(n>1)sb.append(-1); 21 | else{ 22 | if(two==three)sb.append(two); 23 | else if(two>three)sb.append(-1); 24 | else{ 25 | int ans=(three-two); 26 | two+=(three-two); 27 | ans+=three; 28 | sb.append(ans); 29 | } 30 | } 31 | sb.append("\n"); 32 | } 33 | System.out.println(sb); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /1374C - Move Brackets.java: -------------------------------------------------------------------------------- 1 | import java.awt.*; 2 | import java.util.*; 3 | 4 | public class Main { 5 | public static void main(String[] args) { 6 | Scanner sc=new Scanner(System.in); 7 | StringBuilder sb=new StringBuilder(); 8 | int t=sc.nextInt(); 9 | while(t-->0){ 10 | int n=sc.nextInt(); 11 | char[] c=sc.next().toCharArray(); 12 | int count=0; 13 | int move=0; 14 | for(int i=0;i0){ 10 | long a=sc.nextInt(),b=sc.nextInt(),c=sc.nextInt(); 11 | System.out.println(a+b+c-1); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /148D - Bag of mice.java: -------------------------------------------------------------------------------- 1 | import java.awt.*; 2 | import java.io.BufferedReader; 3 | import java.io.IOException; 4 | import java.io.InputStreamReader; 5 | import java.io.PrintWriter; 6 | import java.math.BigInteger; 7 | import java.util.*; 8 | import java.util.List; 9 | 10 | public class Main { 11 | static int mod = (int) 1e9 + 7; 12 | static double[][] dp; 13 | public static void main(String[] args) { 14 | Scanner sc=new Scanner(Sysetem.in); 15 | int w=sc.nextInt(),b=sc.nextInt(); 16 | dp=new double[w+1][b+1]; 17 | for(double[] i:dp)Arrays.fill(i,-1); 18 | int i=1; 19 | System.out.println(cal(w,b)); 20 | } 21 | static double cal(int w,int b){ 22 | if(w<=0)return 0; 23 | if(b<=0)return 1; 24 | 25 | if(dp[w][b]!=-1)return dp[w][b]; 26 | double res=(double)w/(w+b), cp=(double)b/(w+b); 27 | b--; 28 | cp*=(double)b/(w+b); 29 | b--; 30 | if(cp>1e-10){ 31 | double b_mice=cal(w,b-1)*(double)b/(w+b); 32 | double w_mice=cal(w-1,b)*(double)w/(w+b); 33 | res+=cp*(b_mice+w_mice); 34 | } 35 | return dp[w][b+2]=res; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /152C - Pocket Book.java: -------------------------------------------------------------------------------- 1 | import java.awt.Point; 2 | import java.io.BufferedReader; 3 | import java.io.IOException; 4 | import java.io.InputStreamReader; 5 | import java.util.Scanner; 6 | import java.util.HashSet; 7 | import java.util.StringTokenizer; 8 | 9 | 10 | public class Candidate { 11 | public static void main(String[] args) throws Exception{ 12 | Scanner sc=new Scanner(System.in); 13 | int n=sc.nextInt(); 14 | int m=sc.nextInt(); 15 | String[] str=new String[n]; 16 | for(int i=0;i(); 21 | for(int i=0;i0){ 19 | String z=sc.next(); 20 | int a=0,b=0; 21 | for(int i=0;i=2){ 22 | arr[2]++; 23 | arr[1]-=2; 24 | } 25 | else if(arr[1]==1){ 26 | arr[1]=0; 27 | } 28 | } 29 | int temp=Math.min(arr[1],arr[3]); 30 | arr[1]-=temp; 31 | arr[3]-=temp; 32 | System.out.println(temp+arr[4]+arr[3]+(int)Math.ceil(arr[2]/2.0)+(int)Math.ceil(arr[1]/4.0)); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /158D - Ice Sculptures.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | import java.util.*; 5 | 6 | public class Main { 7 | static int mod=(int)1e9+7; 8 | public static void main(String[] args) throws Exception { 9 | Scanner sc=new Scanner(System.in); 10 | int n=sc.nextInt(); 11 | int[] arr=new int[n]; 12 | for(int i=0;i=3){ 17 | for(int j=0;j=0;i--){ 23 | if(x>=y){ 24 | y+=arr[i]; 25 | min++; 26 | x=x-arr[i]; 27 | } 28 | else break; 29 | } 30 | System.out.println(min); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /165C - Another Problem on Strings.java: -------------------------------------------------------------------------------- 1 | import java.awt.Point; 2 | import java.io.*; 3 | import java.util.*; 4 | public class Main { 5 | public static void main(String[] args) throws Exception { 6 | Scanner sc=new Scanner(System.in); 7 | int k = sc.nextInt(); 8 | String s = sc.nextLine(); 9 | int n = s.length(); 10 | int[] sum = new int[n]; 11 | if (s.charAt(0) == '0') sum[0] = 0; 12 | else sum[0] = 1; 13 | for (int i = 1; i < n; i++) { 14 | sum[i] = sum[i - 1] + (s.charAt(i) - '0'); 15 | } 16 | long ans = 0; 17 | int[] count = new int[n + 1]; 18 | count[0] = 1; 19 | for (int i = 0; i < n; i++) { 20 | int temp = sum[i] - k; 21 | if (temp >= 0) ans += count[temp]; 22 | count[sum[i]]++; 23 | } 24 | System.out.println(ans); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /166E - Tetrahedron.java: -------------------------------------------------------------------------------- 1 | import java.awt.Point; 2 | import java.io.BufferedReader; 3 | import java.io.IOException; 4 | import java.io.InputStreamReader; 5 | import java.util.*; 6 | 7 | 8 | public class test { 9 | static int mod=(int)1e9+7; 10 | public static void main(String[] args) { 11 | Scanner sc=new Scanner(System.in); 12 | int n=sc.nextInt(); 13 | long[][] dp=new long[2][n+1]; 14 | dp[1][0]=1; //D represent by 1 -> We can reach to D by 3 states(A,B,C). 15 | dp[0][0]=0; //A,B,C represent by 0 -> We can reach to A or B or C by D + by two other same states. 16 | for(int i=1;i<=n;i++){ 17 | dp[1][i]=(3*dp[0][i-1]%mod)%mod; 18 | dp[0][i]=(2*dp[0][i-1]%mod)%mod +dp[1][i-1]; 19 | } 20 | System.out.println(dp[1][n]); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /189A - Cut Ribbon.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | 6 | int coinsNeeded(int coins[],int amount,int n){ 7 | //base case 8 | if(amount==0)return 0; 9 | int ans=INT_MAX; 10 | 11 | for(int i=0;i=0){ 13 | int smallerAns=coinsNeeded(coins,amount-coins[i],n); 14 | 15 | ans=min(ans,smallerAns+1); 16 | } 17 | } 18 | return ans; 19 | } 20 | int bottomUP(int coins[],int amount,int n){ 21 | int *dp=new int[amount+1]; 22 | dp[0]=0; 23 | for(int i=1;i<=amount;i++)dp[i]=-400000; 24 | 25 | for(int rs=1;rs<=amount;rs++){ 26 | //Iterate over coins 27 | for(int i=0;i=0){ 29 | int smallerAns=dp[rs-coins[i]]; 30 | 31 | dp[rs]=max(dp[rs],smallerAns+1); 32 | } 33 | } 34 | } 35 | return dp[amount]; 36 | } 37 | 38 | int main() { 39 | int n; 40 | cin>>n; 41 | int length[3]; 42 | for(int i=0;i<3;i++){ 43 | cin>>length[i]; 44 | } 45 | cout<>q; 15 | while(q--) 16 | { 17 | ll n,i; 18 | cin>>n; 19 | ll arr[100005]; 20 | for(i=0;i>arr[i]; 23 | } 24 | sort(arr,arr+n); 25 | ll j,sum=0,flag=0;; 26 | for(i=0;i2){ 23 | System.out.println("NO"); 24 | return; 25 | } 26 | } 27 | System.out.println("YES"); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /225C - Barcode.java: -------------------------------------------------------------------------------- 1 | import java.awt.Point; 2 | import java.io.BufferedReader; 3 | import java.io.IOException; 4 | import java.io.InputStreamReader; 5 | import java.util.*; 6 | 7 | 8 | public class Main { 9 | public static void main(String[] args) throws Exception { 10 | Scanner sc=new Scanner(System.in); 11 | int n=sc.nextInt(),m=sc.nextInt(),x=sc.nextInt(),y=sc.nextInt(); 12 | char[][] arr=new char[n][m]; 13 | for(int i=0;im)break; 25 | dp[0][i+j]=Integer.min(dp[0][i+j],dp[1][i]+sum[i+j]-sum[i]); 26 | dp[1][i+j]=Integer.min(dp[1][i+j],dp[0][i]+n*j-(sum[i+j]-sum[i])); 27 | } 28 | } 29 | System.out.println(Integer.min(dp[0][m],dp[1][m])); 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /234C - Weather.java: -------------------------------------------------------------------------------- 1 | import java.awt.Point; 2 | import java.io.*; 3 | import java.util.*; 4 | 5 | public class Main { 6 | public static void main(String[] args)throws IOException{ 7 | Scanner sc=new Scanner(new File("input.txt")); 8 | int n= sc.nextInt(); 9 | int[] arr=new int[n]; 10 | int[] dp=new int[n]; 11 | for(int i=0;i=0?1:0; 14 | else dp[i]=dp[i-1]+(arr[i]>=0?1:0); 15 | } 16 | int ans=Integer.MAX_VALUE,neg=0; 17 | for(int i=n-1;i>0;i--){ 18 | if(arr[i]<=0)neg++; 19 | ans=Math.min(ans,dp[i-1]+neg); 20 | } 21 | PrintWriter out=new PrintWriter("output.txt"); 22 | out.println(ans); 23 | out.close(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /235A - LCM Challenge.java: -------------------------------------------------------------------------------- 1 | import java.awt.*; 2 | import java.io.*; 3 | import java.util.*; 4 | 5 | public class Main { 6 | public static void main(String[] args) throws Exception { 7 | Scanner sc=new Scanner(System.in); 8 | StringBuilder sb = new StringBuilder(); 9 | long n=sc.nextLong(); 10 | if(n==1) System.out.println(1); 11 | else if(n==2) System.out.println(2); 12 | else if(n==3) System.out.println(6); 13 | else if((n&1)==1) System.out.println(n*(n-1)*(n-2)); 14 | else if(n%3!=0) System.out.println(n*(n-1)*(n-3)); 15 | else System.out.println((n-1)*(n-2)*(n-3)); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /245B - Internet Address.java: -------------------------------------------------------------------------------- 1 | import java.awt.Point; 2 | import java.io.BufferedReader; 3 | import java.io.IOException; 4 | import java.io.InputStreamReader; 5 | import java.util.*; 6 | 7 | 8 | public class test { 9 | public static void main(String[] args) { 10 | Scanner sc=new Scanner(System.in); 11 | char[] c=sc.nextLine().toCharArray(); 12 | StringBuilder sb=new StringBuilder(); 13 | int i=0; 14 | if(c[i]=='f'){ 15 | sb.append("ftp://"); 16 | i+=3; 17 | } 18 | else{ 19 | sb.append("http://"); 20 | i+=4; 21 | } 22 | boolean z=false; 23 | for(;i=0;i--){ 22 | if(s.charAt(i)=='l')sb.append((i+1)+"\n"); 23 | } 24 | System.out.println(sb); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /264B - Good Sequences.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.lang.reflect.Array; 3 | import java.util.*; 4 | import java.awt.Point; 5 | 6 | public class Main { 7 | static int mod=(int)1e9+7; 8 | public static void main(String[] args) throws Exception { 9 | Scanner sc=new Scanner(System.in); 10 | int n=sc.nextInt(); 11 | int[] arr=new int[n]; 12 | for(int i=0;i=0){ 15 | sb.append(l+" "+r+"\n"); 16 | count++; 17 | r--;l++; 18 | } 19 | System.out.println(count); 20 | System.out.println(sb); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /269B - Greenhouse Effect.java: -------------------------------------------------------------------------------- 1 | import java.awt.*; 2 | import java.io.BufferedReader; 3 | import java.io.IOException; 4 | import java.io.InputStreamReader; 5 | import java.io.PrintWriter; 6 | import java.math.BigInteger; 7 | import java.util.*; 8 | import java.util.List; 9 | 10 | public class Main { 11 | static int mod = (int) 1e9 + 7; 12 | public static void main(String[] args) { 13 | Scanner sc=new Scanner(System.in); 14 | int n=sc.nextInt(),m=sc.nextInt(); 15 | int[] arr=new int[n]; 16 | for(int i=0;i1)count++; 23 | if(count==2)ans++; 24 | } 25 | System.out.println(ans); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /272C - Dima and Staircase.java: -------------------------------------------------------------------------------- 1 | import java.awt.dnd.Autoscroll; 2 | import java.io.BufferedReader; 3 | import java.io.DataInputStream; 4 | import java.io.FileInputStream; 5 | import java.io.IOException; 6 | import java.util.*; 7 | import java.io.InputStreamReader; 8 | import java.util.Scanner; 9 | 10 | 11 | public class Main { 12 | public static void main(String[] args) throws IOException, NullPointerException { 13 | Scanner sc=new Scanner(System.in); 14 | int n = sc.nextInt(); 15 | int[] arr = new int[n]; 16 | for (int i = 0; i < n; i++) arr[i] = sc.nextInt(); 17 | int m = sc.nextInt(); 18 | long max=0; 19 | int w,h; 20 | StringBuilder sb=new StringBuilder(); 21 | for(int i=0;i0){ 16 | int l=sc.nextInt()-1; 17 | int r=sc.nextInt(); 18 | prefix[l]++; 19 | if(r=0;i--){ 26 | if(a[i]<=a[i+1])dp_dec[i]=dp_dec[i+1]+1; 27 | else dp_dec[i]=1; 28 | } 29 | 30 | while(m-->0){ 31 | int l=sc.nextInt()-1,r=sc.nextInt()-1; 32 | System.out.println(dp_dec[l]+dp_inc[r]>r-l+1?"Yes":"No"); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /27A - Next Test.java: -------------------------------------------------------------------------------- 1 | import java.awt.*; 2 | import java.io.*; 3 | import java.util.*; 4 | 5 | public class Main { 6 | static long INF=(long)1e18; 7 | public static void main(String[] args) throws Exception { 8 | Scanner sc=new Scanner(System.in); 9 | StringBuilder sb = new StringBuilder(); 10 | int n=sc.nextInt(); 11 | boolean[] present=new boolean[3002]; 12 | for(int i=0;i=n){ 30 | ans=k-(mid-1); 31 | l=mid+1; 32 | } 33 | else r=mid-1; 34 | } 35 | System.out.println(ans); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /289B - Polo the Penguin and Matrix.java: -------------------------------------------------------------------------------- 1 | import java.awt.Point; 2 | import java.io.*; 3 | import java.util.*; 4 | 5 | 6 | public class Main { 7 | public static void main(String[] args) throws Exception { 8 | Scanner sc=new Scanner(System.in); 9 | int n=sc.nextInt(),m=sc.nextInt(),d=sc.nextInt(); 10 | int[][] arr=new int[n][m]; 11 | int sum=0; 12 | for(int i=0;i=0)dp[i][j]=Math.min(dp[i-1][j]+w[i],dp[i-1][j-t[i]]); 27 | else dp[i][j]=dp[i-1][j]+w[i]; 28 | } 29 | } 30 | for(int i=1;i<201;i++){ 31 | if(dp[n][i]<=i){ 32 | System.out.println(i); 33 | return; 34 | } 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /2A - Winner.java: -------------------------------------------------------------------------------- 1 | import java.awt.*; 2 | import java.io.*; 3 | import java.util.*; 4 | 5 | public class Main { 6 | public static void main(String[] args) throws Exception { 7 | Scanner sc=new Scanner(System.in); 8 | StringBuilder sb=new StringBuilder(); 9 | int n=sc.nextInt(); 10 | String[] names=new String[n]; 11 | int[] scores=new int[n]; 12 | for(int i=0;i hm=new HashMap<>(); 17 | for(int i=0;i=1){ 19 | temp1=1+(arr[0]-1)/3+(arr[1]-1)/3+(arr[2]-1)/3; 20 | } 21 | if(arr[0]>=2){ 22 | temp2=2+(arr[0]-2)/3+(arr[1]-2)/3+(arr[2]-2)/3; 23 | } 24 | System.out.println(max(temp0,temp1,temp2)); 25 | } 26 | public static int max(int a,int b,int c){ 27 | if(a>=b && a>=c)return a; 28 | else if(b>=a && b>=c)return b; 29 | else return c; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /337A - Puzzles.java: -------------------------------------------------------------------------------- 1 | import java.io.IOException; 2 | import java.io.InputStreamReader; 3 | import java.util.Arrays; 4 | import java.util.Scanner; 5 | import java.util.StringTokenizer; 6 | 7 | 8 | public class Candidate { 9 | public static void main(String[] args) throws Exception { 10 | Scanner sc=new Scanner(System.in); 11 | int n=sc.nextInt(); 12 | int m=sc.nextInt(); 13 | int[] a=new int[m]; 14 | for(int i=0;icurrent){ 20 | count=count+(a[i]-current); 21 | current=a[i]; 22 | } 23 | else if(a[i] ts=new TreeSet<>(); 11 | for(int i=1;i<=n;i++)ts.add(i); 12 | int[] k=new int[n+1]; 13 | for(int i=0;i=2 && sb.charAt(m-2)==sb.charAt(m-1) && sb.charAt(m-1)==c[i])continue; 19 | if(m>=3 && sb.charAt(m-3)==sb.charAt(m-2) && sb.charAt(m-1)==c[i])continue; 20 | sb.append(c[i]); 21 | m++; 22 | } 23 | System.out.println(sb); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /372A - Counting Kangaroos is Fun.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | import java.awt.*; 4 | 5 | public class Main { 6 | public static void main(String[] args) throws Exception { 7 | Scanner sc=new Scanner(System.in): 8 | StringBuilder sb=new StringBuilder(); 9 | int n=sc.nextInt(); 10 | Integer[] arr=new Integer[n]; 11 | for(int i=0;i=count){ 32 | arr[i]=null; 33 | count++; 34 | } 35 | } 36 | pile++; 37 | } 38 | System.out.println(pile); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /439D - Devu and his Brother.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | import java.util.*; 5 | 6 | public class Main { 7 | static int mod=(int)1e9+7; 8 | public static void main(String[] args) throws Exception { 9 | Scanner sc=new Scanner(System.in); 10 | int n=sc.nextInt(),m=sc.nextInt(); 11 | Integer[] a=new Integer[n]; 12 | Integer[] b=new Integer[m]; 13 | for(int i=0;i() { 17 | @Override 18 | public int compare(Integer o1, Integer o2) { 19 | return o2-o1; 20 | } 21 | }); 22 | long sum=0; 23 | m=Math.min(n,m); 24 | for(int i=0;ia[i])sum+=b[i]-a[i]; 26 | } 27 | System.out.println(sum); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /446A - DZY Loves Sequences.java: -------------------------------------------------------------------------------- 1 | import java.awt.*; 2 | import java.io.BufferedReader; 3 | import java.io.IOException; 4 | import java.io.InputStreamReader; 5 | import java.math.BigInteger; 6 | import java.util.*; 7 | 8 | public class Main { 9 | static int mod = (int) 1e9 + 7; 10 | public static void main(String[] args) throws Exception { 11 | Scanner sc=new Scanner(System.in); 12 | int n=sc.nextInt(); 13 | int[] arr=new int[n]; 14 | for(int i=0;iarr[i-1])l[i]=l[i-1]+1; 21 | } 22 | for(int i=n-2;i>=0;i--){ 23 | if(arr[i]>1; 15 | if(k<=check(mid,n,m))r=mid; 16 | else l=mid+1; 17 | } 18 | System.out.println(r); 19 | } 20 | static long check(long mid,long n,long m){ 21 | long sum=0; 22 | for(int i=1;i<=n;i++){ 23 | sum+=Math.min(mid/i,m); 24 | } 25 | return sum; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /455A - Boredom.java: -------------------------------------------------------------------------------- 1 | import java.io.DataInputStream; 2 | import java.io.FileInputStream; 3 | import java.io.IOException; 4 | import java.math.BigInteger; 5 | import java.util.*; 6 | 7 | public class Main { 8 | public static void main(String[] args) throws IOException { 9 | Scanner sc = new Scanner(System.in); 10 | int n = sc.nextInt(); 11 | long[] a=new long[100001]; 12 | long[] dp=new long[100001]; 13 | 14 | for(int i=0;inode[i+1].quality){ 22 | System.out.println("Happy Alex"); 23 | return; 24 | } 25 | } 26 | System.out.println("Poor Alex"); 27 | } 28 | } 29 | class Node implements Comparable{ 30 | int price; 31 | int quality; 32 | public Node(int price,int quality){ 33 | this.price=price; 34 | this.quality=quality; 35 | } 36 | public int compareTo(Node o){ 37 | return this.price-o.price; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /460B - Little Dima and Equation.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | 5 | public class Main { 6 | public static void main(String[] args) { 7 | Scanner sc=new Scanner(System.in); 8 | int a=sc.nextInt(),b=sc.nextInt(),c=sc.nextInt(); 9 | StringBuilder sb=new StringBuilder(); 10 | long temp; 11 | int count=0; 12 | for(int i=1;i<=81;i++){ 13 | temp=b*(long)Math.pow(i,a)+c; 14 | if(temp<1e9 && temp>0 && sum(temp,i)){ 15 | count++; 16 | sb.append(temp+" "); 17 | } 18 | } 19 | System.out.println(count); 20 | System.out.println(sb); 21 | } 22 | public static boolean sum(long x,int i){ 23 | long sum = 0; 24 | for (sum = 0; x > 0; sum += x % 10,x/= 10); 25 | return sum==i; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /460C - Present.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | import java.util.*; 5 | 6 | public class Main { 7 | static int mod=(int)1e9+7; 8 | public static void main(String[] args) throws Exception { 9 | Scanner sc=new Scanner(System.in); 10 | int n=sc.nextInt(),m=sc.nextInt(),w=sc.nextInt(); 11 | long[] arr=new long[n]; 12 | long min=0; 13 | for(int i=0;i0)sum[i]+=sum[i-1]; 23 | if(arr[i]+sum[i]b){ 16 | long t=a; 17 | a=b; 18 | b=t; 19 | f=true; 20 | } 21 | long temp,a1=0,b1=0,s=(long)1e18; 22 | for(long i=a;i*i<=n;i++){ 23 | temp=n/i; 24 | if(temp*i0){ 35 | int x=sc.nextInt(); 36 | int y=sc.nextInt(); 37 | 38 | z=sum[y]-sum[x-1]; 39 | if(z<0)z+=1000000007; 40 | sb.append(z+"\n"); 41 | } 42 | System.out.println(sb); 43 | 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /478C - Table Decorations.java: -------------------------------------------------------------------------------- 1 | import java.awt.Point; 2 | import java.io.*; 3 | import java.util.*; 4 | 5 | 6 | public class Main { 7 | public static void main(String[] args) throws Exception { 8 | Scanne sc=new Scanner(System.in); 9 | long[] arr=new long[3]; 10 | for(int i=0;i<3;i++)arr[i]=sc.nextInt(); 11 | Arrays.sort(arr); 12 | if(arr[2]/2>=arr[1]+arr[0]) System.out.println(arr[1]+arr[0]); 13 | else System.out.println((arr[0]+arr[1]+arr[2])/3); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /479C - Exams.java: -------------------------------------------------------------------------------- 1 | import java.awt.Point; 2 | import java.io.*; 3 | import java.util.*; 4 | public class Main { 5 | public static void main(String[] args) throws Exception { 6 | Scanner sc=new Scanner(System.in); 7 | int n=sc.nextInt(); 8 | Node[] node=new Node[n]; 9 | for(int i=0;i() { 11 | @Override 12 | public int compare(Node o1, Node o2) { 13 | if(o1.a==o2.a)return o1.b-o2.b; 14 | else return o1.a-o2.a; 15 | } 16 | }); 17 | int min=-1; 18 | for(int i=0;i=min)min=temp; 21 | else min=Math.max(node[i].a,node[i].b); 22 | } 23 | System.out.println(min); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /483B - Friends and Presents.java: -------------------------------------------------------------------------------- 1 | import java.awt.Point; 2 | import java.io.BufferedReader; 3 | import java.io.IOException; 4 | import java.io.InputStreamReader; 5 | import java.util.*; 6 | 7 | 8 | public class Main { 9 | public static void main(String[] args) throws Exception { 10 | Scanne sc=new Scanner(System.in); 11 | int a=sc.nextInt(); 12 | int b=sc.nextInt(); 13 | int x=sc.nextInt(),y=sc.nextInt(); 14 | long l=1,r=(long)1e10; 15 | long ans=-1; 16 | while(l<=r){ 17 | long mid=l+(r-l)/2; 18 | if(a<=mid-mid/x && b<=mid-mid/y && a+b<=mid-mid/(x*y)){ 19 | ans=mid; 20 | r=mid-1; 21 | } 22 | else l=mid+1; 23 | 24 | } 25 | System.out.println(ans); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /484A - Bits.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | import java.awt.*; 4 | 5 | public class Main { 6 | public static void main(String[] args) throws Exception { 7 | Scanner sc=new Scanner(System.in); 8 | StringBuilder sb=new StringBuilder(); 9 | int t=sc.nextInt(); 10 | while(t-->0){ 11 | long l=sc.nextLong(),r=sc.nextLong(); 12 | while((l|(l+1))<=r){ 13 | l=l|(l+1); 14 | } 15 | sb.append(l+"\n"); 16 | } 17 | System.out.println(sb); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /493D - Vasya and Chess.java: -------------------------------------------------------------------------------- 1 | import java.awt.Point; 2 | import java.io.BufferedReader; 3 | import java.io.IOException; 4 | import java.io.InputStreamReader; 5 | import java.util.*; 6 | 7 | 8 | public class Candidate { 9 | public static void main(String[] args) throws Exception { 10 | Scanner sc=new Scanner(System.in); 11 | int n=sc.nextInt(); 12 | if(n%2==0) System.out.println("white\n1 2"); 13 | else System.out.println("black"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /501A - Contest.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | import java.util.StringTokenizer; 5 | 6 | 7 | public class Candidate { 8 | public static void main(String[] args) throws Exception { 9 | Scanner sc=new Scanner(System.in); 10 | 11 | int a=sc.nextInt(),b=sc.nextInt(),c=sc.nextInt(),d=sc.nextInt(); 12 | int m=Integer.max(3*a/10,a-(a/250)*c); 13 | int v=Integer.max(3*b/10,b-(b/250)*d); 14 | if(m>v) System.out.println("Misha"); 15 | else if(v>m) System.out.println("Vasya"); 16 | else System.out.println("Tie"); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /508C - Anya and Ghosts.java: -------------------------------------------------------------------------------- 1 | import java.awt.Point; 2 | import java.io.BufferedReader; 3 | import java.io.IOException; 4 | import java.io.InputStreamReader; 5 | import java.util.*; 6 | 7 | 8 | public class Candidate { 9 | public static void main(String[] args) throws Exception { 10 | Scanner sc=new Scanner(System.in); 11 | int m=sc.nextInt(); 12 | int t=sc.nextInt(); 13 | int r=sc.nextInt(); 14 | int[] arr=new int[m]; 15 | for(int i=0;i hm=new HashMap<>(); 11 | hm.put("polycarp",1); 12 | int ans=1; 13 | for(int i=0;i hs=new HashSet<>(); 7 | public static void main(String[] args) throws Exception { 8 | Scanner sc=new Scanner(System.in); 9 | StringBuilder sb=new StringBuilder(); 10 | String a=sc.next(),b=sc.next(); 11 | if(check(a,b)) System.out.println("YES"); 12 | else System.out.println("NO"); 13 | } 14 | static boolean check(String a,String b){ 15 | if(hs.contains(a+b))return true; 16 | if(a.length()==1 && b.length()==1){ 17 | if(a.charAt(0)==b.charAt(0))return true; 18 | else return false; 19 | } 20 | if(a.length()!=b.length())return false; 21 | if(a.equals(b))return true; 22 | if(a.length()%2==1)return false; 23 | String a1=a.substring(0,a.length()/2),a2=a.substring(a.length()/2,a.length()); 24 | String b1=b.substring(0,b.length()/2),b2=b.substring(b.length()/2,b.length()); 25 | boolean z=((check(a1,b1) && check(a2,b2)) || (check(a1,b2) && check(a2,b1))); 26 | if(z)hs.add(a+b); 27 | return z; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /58A - Chat Room.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | import java.util.StringTokenizer; 5 | 6 | 7 | public class Candidate { 8 | public static void main(String[] args) throws Exception { 9 | Scanner sc=new Scanner(System.in); 10 | 11 | String s=sc.nextLine(); 12 | String a="hello"; 13 | int j=0; 14 | int i; 15 | for(i=0;i odd=new ArrayList<>(100); 12 | int ans=0; 13 | for(int i=0;i treeset=new TreeSet<>(); 14 | int c=Math.min(a,b); 15 | for(int i=1;i*i<=c;i++){ 16 | if(a%i==0 && b%i==0)treeset.add(i); 17 | if(a%(c/i)==0 && b%(c/i)==0)treeset.add(c/i); 18 | } 19 | int q=sc.nextInt(); 20 | StringBuilder sb=new StringBuilder(); 21 | Integer temp; 22 | while(q-->0){ 23 | int l=sc.nextInt(),r=sc.nextInt(); 24 | temp=treeset.floor(r); 25 | if(temp!=null && temp>=l)sb.append(temp+"\n"); 26 | else sb.append("-1\n"); 27 | } 28 | System.out.println(sb); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /81A - Plug-in.java: -------------------------------------------------------------------------------- 1 | import java.awt.*; 2 | import java.io.BufferedReader; 3 | import java.io.IOException; 4 | import java.io.InputStreamReader; 5 | import java.util.*; 6 | 7 | public class Main { 8 | static int mod=(int)1e9+7; 9 | public static void main(String[] args) throws Exception { 10 | Scanner sc=new Scanner(System.in); 11 | StringBuilder sb=new StringBuilder(); 12 | String s=sc.nextLine(); 13 | Stack stack=new Stack<>(); 14 | for(int i=0;iarr[i+1] && arr[i]>arr[i-1])ans++; 16 | } 17 | System.out.println(ans); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /910A - The Way to Home.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | import java.util.*; 5 | 6 | public class Main { 7 | public static void main(String[] args) throws Exception { 8 | Scanner sc=new Scanner(System.in); 9 | int n=sc.nextInt(); 10 | int d=sc.nextInt(); 11 | String s=sc.nextLine(); 12 | 13 | int[] dp=new int[s.length()]; 14 | Arrays.fill(dp,Integer.MAX_VALUE); 15 | dp[0]=0; 16 | 17 | for(int i=1;i=0 ;j++){ 21 | if(s.charAt(i-j)=='1'){ 22 | if(dp[i-j]81)break; 15 | String temp=password.substring(i,i+10); 16 | for(int s=0;s<10;s++){ 17 | if(temp.equals(nums[s])) System.out.print(s); 18 | } 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /96A - Football.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | import java.util.StringTokenizer; 5 | 6 | 7 | public class Candidate { 8 | public static void main(String[] args) throws Exception { 9 | Scanner sc=new Scanner(System.in); 10 | 11 | String s=sc.nextLine(); 12 | int count=0; 13 | char current=s.charAt(0); 14 | count++; 15 | for(int i=1;i 2 | using namespace std; 3 | #define mod 1000000007 4 | #define pie 3.14 5 | typedef long long int ll; 6 | /////////////////////////////////////// 7 | int main() 8 | { 9 | ios_base::sync_with_stdio(false); 10 | cin.tie(NULL); 11 | #ifndef ONLINE_JUDGE 12 | freopen("input.txt","r",stdin); 13 | freopen("output.txt","w",stdout); 14 | #endif 15 | ll n; 16 | cin>>n; 17 | cout<<(2*n*n-2*n+1); 18 | } -------------------------------------------------------------------------------- /Almost Equal.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define mod 1000000007 4 | #define pie 3.14 5 | typedef long long int ll; 6 | /* 7 | .d8b. d8888b. db db .d8b. d8b db 8 | d8' `8b 88 `8D `8b d8' d8' `8b 888o 88 9 | 88ooo88 88oobY' `8bd8' 88ooo88 88V8o 88 10 | 88~~~88 88`8b 88 88~~~88 88 V8o88 11 | 88 88 88 `88. 88 88 88 88 V888 12 | YP YP 88 YD YP YP YP VP V8P 13 | 14 | 15 | */ 16 | 17 | 18 | /////////////////////////////////////// 19 | int main() 20 | { 21 | ios_base::sync_with_stdio(false); 22 | cin.tie(NULL); 23 | #ifndef ONLINE_JUDGE 24 | freopen("input.txt","r",stdin); 25 | freopen("output.txt","w",stdout); 26 | #endif 27 | ll n,i,sum=0; 28 | cin>>n; 29 | if(n%2==0) 30 | cout<<"NO\n"; 31 | else 32 | { 33 | cout<<"YES\n"; 34 | for(i=1;i<=n;i++) 35 | { 36 | if(i%2==1) 37 | sum=sum+1; 38 | else 39 | sum+=3; 40 | cout< 2 | using namespace std; 3 | #define mod 1000000007 4 | #define pie 3.14 5 | typedef long long int ll; 6 | /* 7 | .d8b. d8888b. db db .d8b. d8b db 8 | d8' `8b 88 `8D `8b d8' d8' `8b 888o 88 9 | 88ooo88 88oobY' `8bd8' 88ooo88 88V8o 88 10 | 88~~~88 88`8b 88 88~~~88 88 V8o88 11 | 88 88 88 `88. 88 88 88 88 V888 12 | YP YP 88 YD YP YP YP VP V8P 13 | 14 | 15 | */ 16 | 17 | 18 | /////////////////////////////////////// 19 | int main() 20 | { 21 | ios_base::sync_with_stdio(false); 22 | cin.tie(NULL); 23 | #ifndef ONLINE_JUDGE 24 | freopen("input.txt","r",stdin); 25 | freopen("output.txt","w",stdout); 26 | #endif 27 | ll a,b,c,ans; 28 | scanf("%lld %lld %lld",&a,&b,&c); 29 | if(b==a) 30 | ans=c*2+a*2; 31 | else 32 | ans=c*2+min(a,b)*2+1; 33 | printf("%lld",ans); 34 | } -------------------------------------------------------------------------------- /Anton and currency you all know.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define mod 1000000007 4 | #define pie 3.14 5 | typedef long long int ll; 6 | int main() 7 | { 8 | ios_base::sync_with_stdio(false); 9 | cin.tie(NULL); 10 | string s; 11 | cin>>s; 12 | ll a,b,x,n,flag=0,pt=-1,nf,i; 13 | n=s.length(); 14 | a=s[n-1]-'0'; 15 | if(a%2==0) 16 | flag=0; 17 | for(i=0;i 2 | using namespace std; 3 | #define mod 1000000007 4 | #define pie 3.14 5 | typedef long long int ll; 6 | /* 7 | .d8b. d8888b. db db .d8b. d8b db 8 | d8' `8b 88 `8D `8b d8' d8' `8b 888o 88 9 | 88ooo88 88oobY' `8bd8' 88ooo88 88V8o 88 10 | 88~~~88 88`8b 88 88~~~88 88 V8o88 11 | 88 88 88 `88. 88 88 88 88 V888 12 | YP YP 88 YD YP YP YP VP V8P 13 | 14 | 15 | */ 16 | 17 | 18 | /////////////////////////////////////// 19 | int main() 20 | { 21 | ios_base::sync_with_stdio(false); 22 | cin.tie(NULL); 23 | #ifndef ONLINE_JUDGE 24 | freopen("input.txt","r",stdin); 25 | freopen("output.txt","w",stdout); 26 | #endif 27 | ll n,k,i,sum=0; 28 | ll arr[300005]; 29 | ll ans[300005]; 30 | cin>>n>>k; 31 | for(i=0;i>arr[i]; 33 | sum=arr[n-1]-arr[0]; 34 | for(i=0;i0) { 13 | int n = sc.nextInt(); 14 | int p = sc.nextInt(); 15 | int k = sc.nextInt(); 16 | Integer[] arr = new Integer[n]; 17 | for (int i = 0; i < n; i++) arr[i] = sc.nextInt(); 18 | Arrays.sort(arr); 19 | Integer[] dp=new Integer[n+1]; 20 | dp[0]=0; 21 | for(int i=1;i=0;i--){ 28 | if(p>=dp[i]){ 29 | System.out.println(i); 30 | break; 31 | } 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Benches.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define mod 1000000007 4 | #define pie 3.14 5 | typedef long long int ll; 6 | /* 7 | .d8b. d8888b. db db .d8b. d8b db 8 | d8' `8b 88 `8D `8b d8' d8' `8b 888o 88 9 | 88ooo88 88oobY' `8bd8' 88ooo88 88V8o 88 10 | 88~~~88 88`8b 88 88~~~88 88 V8o88 11 | 88 88 88 `88. 88 88 88 88 V888 12 | YP YP 88 YD YP YP YP VP V8P 13 | 14 | 15 | */ 16 | 17 | 18 | /////////////////////////////////////// 19 | int main() 20 | { 21 | ios_base::sync_with_stdio(false); 22 | cin.tie(NULL); 23 | #ifndef ONLINE_JUDGE 24 | freopen("input.txt","r",stdin); 25 | freopen("output.txt","w",stdout); 26 | #endif 27 | ll n,m,sum=0,x,y,z,i; 28 | ll arr[100005]; 29 | ll ma=0; 30 | cin>>n>>m; 31 | for(i=0;i>arr[i]; 34 | if(arr[i]>ma) 35 | ma=arr[i]; 36 | } 37 | for(i=0;i 2 | #include 3 | #include 4 | using namespace std; 5 | int main() 6 | { 7 | long long int n,ma=-1,c=0,mac=-1,i; 8 | long long int a[100002]; 9 | scanf("%lld",&n); 10 | for(i=0;ima) 14 | ma=a[i]; 15 | } 16 | for(i=0;imac) 25 | mac=c; 26 | } 27 | printf("%lld\n",mac); 28 | } 29 | -------------------------------------------------------------------------------- /Big Segment.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | long long int n,i,mi=100000000001ll,ma=-1,k=0,pos; 6 | long long int a[100002]; 7 | long long int b[100002]; 8 | scanf("%lld",&n); 9 | for(i=0;ima) 15 | ma=b[i]; 16 | } 17 | //if there is any i for which a[i]<=mi and b[i]>=ma 18 | //then print its position 19 | //printf("%lld %lld\n",mi,ma); 20 | for(i=0;i=ma) 23 | { 24 | k=1; 25 | pos=i; 26 | } 27 | } 28 | if(k==1) 29 | printf("%lld\n",pos+1); 30 | else 31 | printf("-1\n"); 32 | } 33 | -------------------------------------------------------------------------------- /Birthday.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | long long int n,m,k,l,ans,x; 7 | double y; 8 | scanf("%lld %lld %lld %lld",&n,&m,&k,&l); 9 | if(n 2 | using namespace std; 3 | #define ll long long int 4 | int main() 5 | { 6 | ll n,i,ans=0,x; 7 | ll arr[150005]; 8 | ll coun[150005]={0}; 9 | cin>>n; 10 | for(i=0;i>arr[i]; 13 | } 14 | sort(arr,arr+n); 15 | for(i=0;in-1-curr;i--)sum+=arr[i]; 21 | curr/=4; 22 | } 23 | System.out.println(sum); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Cards.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define mod 1000000007 4 | #define pie 3.14 5 | typedef long long int ll; 6 | /* 7 | .d8b. d8888b. db db .d8b. d8b db 8 | d8' `8b 88 `8D `8b d8' d8' `8b 888o 88 9 | 88ooo88 88oobY' `8bd8' 88ooo88 88V8o 88 10 | 88~~~88 88`8b 88 88~~~88 88 V8o88 11 | 88 88 88 `88. 88 88 88 88 V888 12 | YP YP 88 YD YP YP YP VP V8P 13 | 14 | 15 | */ 16 | 17 | 18 | /////////////////////////////////////// 19 | int main() 20 | { 21 | ios_base::sync_with_stdio(false); 22 | cin.tie(NULL); 23 | #ifndef ONLINE_JUDGE 24 | freopen("input.txt","r",stdin); 25 | freopen("output.txt","w",stdout); 26 | #endif 27 | ll n,i; 28 | cin>>n; 29 | string s; 30 | cin>>s; 31 | ll arr[3]={0}; 32 | for(i=0;i 2 | using namespace std; 3 | int main() 4 | { 5 | int n,i,c1=0,c2=0,x; 6 | cin>>n; 7 | for(i=0;i>x; 10 | if(x%2==0) 11 | c1++; 12 | else 13 | c2++; 14 | } 15 | cout< 2 | using namespace std; 3 | #define mod 1000000007 4 | #define pie 3.14 5 | typedef long long int ll; 6 | /* 7 | .d8b. d8888b. db db .d8b. d8b db 8 | d8' `8b 88 `8D `8b d8' d8' `8b 888o 88 9 | 88ooo88 88oobY' `8bd8' 88ooo88 88V8o 88 10 | 88~~~88 88`8b 88 88~~~88 88 V8o88 11 | 88 88 88 `88. 88 88 88 88 V888 12 | YP YP 88 YD YP YP YP VP V8P 13 | 14 | 15 | */ 16 | 17 | 18 | /////////////////////////////////////// 19 | int main() 20 | { 21 | ios_base::sync_with_stdio(false); 22 | cin.tie(NULL); 23 | #ifndef ONLINE_JUDGE 24 | freopen("input.txt","r",stdin); 25 | freopen("output.txt","w",stdout); 26 | #endif 27 | ll n1,n2,i,ma=0,ma1=0,x; 28 | cin>>n1; 29 | for(i=0;i>x; 32 | if(x>ma) 33 | ma=x; 34 | } 35 | cin>>n2; 36 | for(i=0;i>x; 39 | if(x>ma1) 40 | ma1=x; 41 | } 42 | cout< 2 | using namespace std; 3 | #define mod 1000000007 4 | #define pie 3.14 5 | typedef long long int ll; 6 | /* 7 | .d8b. d8888b. db db .d8b. d8b db 8 | d8' `8b 88 `8D `8b d8' d8' `8b 888o 88 9 | 88ooo88 88oobY' `8bd8' 88ooo88 88V8o 88 10 | 88~~~88 88`8b 88 88~~~88 88 V8o88 11 | 88 88 88 `88. 88 88 88 88 V888 12 | YP YP 88 YD YP YP YP VP V8P 13 | 14 | 15 | */ 16 | 17 | 18 | /////////////////////////////////////// 19 | int main() 20 | { 21 | ios_base::sync_with_stdio(false); 22 | cin.tie(NULL); 23 | #ifndef ONLINE_JUDGE 24 | freopen("input.txt","r",stdin); 25 | freopen("output.txt","w",stdout); 26 | #endif 27 | ll a,b,c,k,x,y,mon; 28 | cin>>a>>b>>k; 29 | x=a/k; 30 | y=b/k; 31 | mon=a%k+b%k; 32 | if((mon/k)!=0) 33 | cout<<(x+y+mon/k)<<" "< 2 | int main() 3 | { 4 | int n,i,k=1,a,sum=0,sum1=0,x; 5 | scanf("%d",&n); 6 | // printf("hello\n"); 7 | for(i=0;i=1) 16 | { 17 | sum--; 18 | } 19 | else if(x==50 && (sum1>=1 || sum>=2)) 20 | { 21 | if(sum1>=1) 22 | sum1--; 23 | else if(sum>=2) 24 | sum=sum-2; 25 | } 26 | else if(x==75 && ((sum1>=1 && sum>=1)|| sum>=3)) 27 | { 28 | if(sum1>=1 && sum>=1) 29 | { 30 | sum1--; 31 | sum--; 32 | } 33 | else if(sum>=3) 34 | sum=sum-3; 35 | } 36 | else if(x==0) 37 | { 38 | 39 | } 40 | else 41 | { 42 | 43 | k=0; 44 | break; 45 | } 46 | //printf("%d %d %d\n",sum,sum1,x); 47 | 48 | } 49 | if(k==0) 50 | printf("NO\n"); 51 | else 52 | printf("YES\n"); 53 | } 54 | -------------------------------------------------------------------------------- /Circle of Students.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define ll long long int 4 | int main() 5 | { 6 | 7 | ll q; 8 | ll n; 9 | cin>>q; 10 | while(q--) 11 | { 12 | ll arr[100005],i,flag1=1,flag2=1; 13 | cin>>n; 14 | for(i=0;i>arr[i]; 16 | for(i=0;i<(n-1);i++) 17 | { 18 | if(arr[i]==n && arr[i+1]==1) 19 | continue; 20 | else if(arr[i+1]==arr[i]+1) 21 | continue; 22 | else 23 | { 24 | flag1=0; 25 | break; 26 | } 27 | } 28 | // cout< 2 | using namespace std; 3 | typedef long long int ll; 4 | int main() 5 | { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | ll n,i,j,x,pro=1; 9 | ll arr[1000005]; 10 | ll p[1000005]={0}; 11 | cin>>n; 12 | for(i=0;i>arr[i]; 14 | x=arr[0]; 15 | for(i=1;i2) 37 | // { 38 | // p[x]++; 39 | // } 40 | for(i=2;i<=1000000;i++) 41 | { 42 | pro=pro*(1+p[i]); 43 | } 44 | cout< 2 | using namespace std; 3 | #define mod 1000000007 4 | #define pie 3.14 5 | typedef long long int ll; 6 | 7 | /////////////////////////////////////// 8 | int main() 9 | { 10 | ios_base::sync_with_stdio(false); 11 | cin.tie(NULL); 12 | #ifndef ONLINE_JUDGE 13 | freopen("input.txt","r",stdin); 14 | freopen("output.txt","w",stdout); 15 | #endif 16 | ll t; 17 | cin>>t; 18 | while(t--) 19 | { 20 | ll n,k,a,b,x,y,z; 21 | cin>>n>>k>>a>>b; 22 | if((n-k*b)<=0) 23 | cout<<-1<<"\n"; 24 | else if((n-k*b)>0) 25 | { 26 | x=n-k*b-1; 27 | //cout<<"x is"< 2 | using namespace std; 3 | #define mod 1000000007 4 | #define pie 3.14 5 | typedef long long int ll; 6 | /* 7 | .d8b. d8888b. db db .d8b. d8b db 8 | d8' `8b 88 `8D `8b d8' d8' `8b 888o 88 9 | 88ooo88 88oobY' `8bd8' 88ooo88 88V8o 88 10 | 88~~~88 88`8b 88 88~~~88 88 V8o88 11 | 88 88 88 `88. 88 88 88 88 V888 12 | YP YP 88 YD YP YP YP VP V8P 13 | 14 | 15 | */ 16 | 17 | 18 | /////////////////////////////////////// 19 | int main() 20 | { 21 | ios_base::sync_with_stdio(false); 22 | cin.tie(NULL); 23 | #ifndef ONLINE_JUDGE 24 | freopen("input.txt","r",stdin); 25 | freopen("output.txt","w",stdout); 26 | #endif 27 | ll n,x,y,sum=0,ma=-1; 28 | cin>>n; 29 | while(n--) 30 | { 31 | cin>>x>>y; 32 | sum=x+y; 33 | if(sum>ma) 34 | ma=sum; 35 | } 36 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | long long int t,i,k,c=0; 6 | long long int a[100000]; 7 | scanf("%lld",&t); 8 | for(i=0;i 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | int a,b,ma,ans,x; 7 | scanf("%d %d",&a,&b); 8 | if(a>=b) 9 | ma=a; 10 | else 11 | ma=b; 12 | ans=6-ma+1; 13 | x=__gcd(ans,6); 14 | printf("%d/%d",(ans/x),(6/x)); 15 | } 16 | -------------------------------------------------------------------------------- /Digital root.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define mod 1000000007 4 | #define pie 3.14 5 | typedef long long int ll; 6 | 7 | int main() 8 | { 9 | ios_base::sync_with_stdio(false); 10 | cin.tie(NULL); 11 | ll n,i,k,x; 12 | cin>>n; 13 | for(i=0;i>k>>x; 16 | cout<<((k-1)*9+x)<<"\n"; 17 | } 18 | } 19 | 20 | -------------------------------------------------------------------------------- /Div Times Mod.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | int main() 6 | { 7 | int a,b,i,ans,x; 8 | scanf("%d %d",&a,&b); 9 | for(i=b-1;i>=1;i--) 10 | { 11 | if((((double)a/i)-floor(a/i))==0) 12 | { 13 | x=a/i; 14 | ans=x*b+i; 15 | break; 16 | } 17 | } 18 | printf("%d",ans); 19 | } 20 | -------------------------------------------------------------------------------- /Divisor Subtraction.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | int main() 6 | { 7 | long long int a,i,k,n,c=0; 8 | scanf("%lld",&n); 9 | while(1) 10 | { 11 | k=0; 12 | if(n==0) 13 | break; 14 | else 15 | { 16 | if(n%2==1) 17 | { 18 | for(i=2;i*i<=n;i++) 19 | { 20 | if(n%i==0) 21 | { 22 | c++; 23 | n=n-i; 24 | k=1; 25 | break; 26 | } 27 | 28 | } 29 | if(k==0) 30 | { 31 | c++; 32 | n=0; 33 | } 34 | } 35 | else 36 | { 37 | c=c+(n/2); 38 | break; 39 | } 40 | } 41 | } 42 | printf("%lld",c); 43 | } 44 | -------------------------------------------------------------------------------- /Divisors of Two Integers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define mod 1000000007 4 | #define pie 3.14 5 | typedef long long int ll; 6 | 7 | int main() 8 | { 9 | ios_base::sync_with_stdio(false); 10 | cin.tie(NULL); 11 | ll n,i,ans,ma=0; 12 | ll arr[10005]; 13 | ll co[10005]={0}; 14 | cin>>n; 15 | for(i=0;i>arr[i]; 18 | co[arr[i]]++; 19 | if(arr[i]>ma) 20 | ma=arr[i]; 21 | } 22 | //cout<<"Ma is"<=0;i--) 37 | { 38 | if(co[i]>0) 39 | { 40 | ans=i; 41 | break; 42 | } 43 | } 44 | cout< 2 | using namespace std; 3 | #define mod 1000000007 4 | #define pie 3.14 5 | typedef long long int ll; 6 | /* 7 | .d8b. d8888b. db db .d8b. d8b db 8 | d8' `8b 88 `8D `8b d8' d8' `8b 888o 88 9 | 88ooo88 88oobY' `8bd8' 88ooo88 88V8o 88 10 | 88~~~88 88`8b 88 88~~~88 88 V8o88 11 | 88 88 88 `88. 88 88 88 88 V888 12 | YP YP 88 YD YP YP YP VP V8P 13 | 14 | 15 | */ 16 | 17 | 18 | /////////////////////////////////////// 19 | int main() 20 | { 21 | ios_base::sync_with_stdio(false); 22 | cin.tie(NULL); 23 | #ifndef ONLINE_JUDGE 24 | freopen("input.txt","r",stdin); 25 | freopen("output.txt","w",stdout); 26 | #endif 27 | ll n,k,i,flag=0,x,z,c=0; 28 | ll arr[10005]={0}; 29 | cin>>n>>k; 30 | for(i=0;i>x; 33 | arr[x]++; 34 | } 35 | z=round((double)n/2); 36 | for(i=1;i<=k;i++) 37 | { 38 | z=z-arr[i]/2; 39 | arr[i]=arr[i]%2; 40 | if(arr[i]==1) 41 | c++; 42 | } 43 | //cout< 2 | #include 3 | int main() 4 | { 5 | int n,i; 6 | char a[1000]={0}; 7 | scanf("%s",a); 8 | n=strlen(a); 9 | for(i=0;i<(n-2);) 10 | { 11 | if(a[i]=='W' && a[i+1]=='U' && a[i+2]=='B') 12 | i=i+3; 13 | else 14 | break; 15 | } 16 | //printf("%d\n",i); 17 | for(;i<(n);) 18 | { 19 | if(a[i]=='W' && a[i+1]=='U' && a[i+2]=='B') 20 | { 21 | i=i+3; 22 | printf(" "); 23 | continue; 24 | } 25 | else 26 | {printf("%c",a[i]); 27 | i++;} 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /Eating Soup.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define mod 1000000007 4 | #define pie 3.14 5 | typedef long long int ll; 6 | /* 7 | .d8b. d8888b. db db .d8b. d8b db 8 | d8' `8b 88 `8D `8b d8' d8' `8b 888o 88 9 | 88ooo88 88oobY' `8bd8' 88ooo88 88V8o 88 10 | 88~~~88 88`8b 88 88~~~88 88 V8o88 11 | 88 88 88 `88. 88 88 88 88 V888 12 | YP YP 88 YD YP YP YP VP V8P 13 | 14 | 15 | */ 16 | 17 | 18 | /////////////////////////////////////// 19 | int main() 20 | { 21 | ios_base::sync_with_stdio(false); 22 | cin.tie(NULL); 23 | #ifndef ONLINE_JUDGE 24 | freopen("input.txt","r",stdin); 25 | freopen("output.txt","w",stdout); 26 | #endif 27 | ll n,m,k; 28 | cin>>n>>m; 29 | k=n/2; 30 | if(m==0) 31 | cout<<1<k) 35 | cout<<(n-m)< 2 | using namespace std; 3 | #define ll long long int 4 | int main() 5 | { 6 | ll q; 7 | cin>>q; 8 | while(q--) 9 | { 10 | ll n,flag=1,i,x,an,k; 11 | ll arr[100005]={0}; 12 | vectorv; 13 | cin>>n; 14 | for(i=0;i<4*n;i++) 15 | { 16 | cin>>x; 17 | v.push_back(x); 18 | arr[x]++; 19 | } 20 | for(i=1;i<=10000;i++) 21 | { 22 | if(arr[i]%2!=0) 23 | flag=0; //because n rectangles are not possible then 24 | } 25 | sort(v.begin(),v.end()); 26 | an=v[0]*v[4*n-1]; 27 | //cout<<"An is"< 2 | using namespace std; 3 | #define mod 1000000007 4 | #define pie 3.14 5 | typedef long long int ll; 6 | int main() 7 | { 8 | ios_base::sync_with_stdio(false); 9 | cin.tie(NULL); 10 | #ifndef ONLINE_JUDGE 11 | freopen("input.txt","r",stdin); 12 | freopen("output.txt","w",stdout); 13 | #endif 14 | ll t; 15 | cin>>t; 16 | while(t--) 17 | { 18 | ll n,k,ma=0,mi=100000000000ll,i; 19 | ll arr[500]; 20 | cin>>n>>k; 21 | for(i=0;i>arr[i]; 24 | if(arr[i]>ma) 25 | ma=arr[i]; 26 | if(arr[i](2*k)) 30 | cout<<-1<<"\n"; 31 | else 32 | cout<<(mi+k)<<"\n"; 33 | 34 | } 35 | } -------------------------------------------------------------------------------- /Filling Shapes.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define mod 1000000007 4 | #define pie 3.14 5 | typedef long long int ll; 6 | /* 7 | .d8b. d8888b. db db .d8b. d8b db 8 | d8' `8b 88 `8D `8b d8' d8' `8b 888o 88 9 | 88ooo88 88oobY' `8bd8' 88ooo88 88V8o 88 10 | 88~~~88 88`8b 88 88~~~88 88 V8o88 11 | 88 88 88 `88. 88 88 88 88 V888 12 | YP YP 88 YD YP YP YP VP V8P 13 | 14 | 15 | */ 16 | 17 | 18 | /////////////////////////////////////// 19 | int main() 20 | { 21 | ios_base::sync_with_stdio(false); 22 | cin.tie(NULL); 23 | #ifndef ONLINE_JUDGE 24 | freopen("input.txt","r",stdin); 25 | freopen("output.txt","w",stdout); 26 | #endif 27 | ll n; 28 | cin>>n; 29 | if(n%2==0) 30 | cout<<(ll)pow(2,n/2)<<"\n"; 31 | else 32 | cout<<0<<"\n"; 33 | } -------------------------------------------------------------------------------- /From Hero to Zero.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define mod 1000000007 4 | #define pie 3.14 5 | typedef long long int ll; 6 | /* 7 | .d8b. d8888b. db db .d8b. d8b db 8 | d8' `8b 88 `8D `8b d8' d8' `8b 888o 88 9 | 88ooo88 88oobY' `8bd8' 88ooo88 88V8o 88 10 | 88~~~88 88`8b 88 88~~~88 88 V8o88 11 | 88 88 88 `88. 88 88 88 88 V888 12 | YP YP 88 YD YP YP YP VP V8P 13 | 14 | 15 | */ 16 | 17 | 18 | /////////////////////////////////////// 19 | int main() 20 | { 21 | ios_base::sync_with_stdio(false); 22 | cin.tie(NULL); 23 | #ifndef ONLINE_JUDGE 24 | freopen("input.txt","r",stdin); 25 | freopen("output.txt","w",stdout); 26 | #endif 27 | ll t; 28 | cin>>t; 29 | while(t--) 30 | { 31 | ll n,k,i,ans=0; 32 | cin>>n>>k; 33 | while(n!=0) 34 | { 35 | ans+=n%k; 36 | n=n/k; 37 | if(n==0) 38 | break; 39 | ans++; 40 | //cout< 2 | using namespace std; 3 | #define mod 1000000007 4 | #define pie 3.14 5 | typedef long long int ll; 6 | 7 | int main() 8 | { 9 | ios_base::sync_with_stdio(false); 10 | cin.tie(NULL); 11 | string s; 12 | stackst; 13 | cin>>s; 14 | ll n,ans=0,i; 15 | n=s.length(); 16 | st.push(s[0]); 17 | //cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int t,n,c=0,i; 6 | scanf("%d",&t); 7 | while(t--) 8 | { 9 | c=0; 10 | char a[200]={0}; 11 | scanf("%d",&n); 12 | scanf("%s",a); 13 | for(i=0;i<(n/2);i++) 14 | { 15 | if(a[i]=='<' && a[n-i-1]=='>') 16 | c++; 17 | else 18 | break; 19 | } 20 | printf("%d\n",c); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Helpful Maths.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | int main() 7 | { 8 | char a[110]={0}; 9 | int b[110]={0}; 10 | int i,x,ans=0,c=0; 11 | scanf("%[^\n\t]s",a); 12 | for(i=0;i 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | long int a,b; 7 | long double x,y; 8 | scanf("%ld %ld",&a,&b); 9 | x=(long double)(a*log(b)); 10 | y=(long double)(b*log(a)); 11 | if(y==x) 12 | printf("="); 13 | else if(y>x) 14 | printf(">"); 15 | else 16 | printf("<"); 17 | } 18 | -------------------------------------------------------------------------------- /Little C Loves 3 I.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define mod 1000000007 4 | #define pie 3.14 5 | typedef long long int ll; 6 | /* 7 | .d8b. d8888b. db db .d8b. d8b db 8 | d8' `8b 88 `8D `8b d8' d8' `8b 888o 88 9 | 88ooo88 88oobY' `8bd8' 88ooo88 88V8o 88 10 | 88~~~88 88`8b 88 88~~~88 88 V8o88 11 | 88 88 88 `88. 88 88 88 88 V888 12 | YP YP 88 YD YP YP YP VP V8P 13 | 14 | 15 | */ 16 | 17 | 18 | /////////////////////////////////////// 19 | int main() 20 | { 21 | ios_base::sync_with_stdio(false); 22 | cin.tie(NULL); 23 | #ifndef ONLINE_JUDGE 24 | freopen("input.txt","r",stdin); 25 | freopen("output.txt","w",stdout); 26 | #endif 27 | ll n; 28 | cin>>n; 29 | if((n-2)%3!=0) 30 | cout<<1<<" "<<1<<" "<<(n-2); 31 | else 32 | cout<<1<<" "<<2<<" "<<(n-3); 33 | 34 | } -------------------------------------------------------------------------------- /Little Elephant and Chess.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int k=1,i,j,c1=0,c2=0; 5 | char a[9][9]; 6 | for(i=0;i<8;i++) 7 | { 8 | for(j=0;j<8;j++) 9 | { 10 | scanf("%1s",&a[i][j]); 11 | if(a[i][j]=='B') 12 | c1++; 13 | else if(a[i][j]=='W') 14 | c2++; 15 | } 16 | } 17 | for(i=0;i<8;i++) 18 | { 19 | for(j=0;j<8;j++) 20 | { 21 | if(a[i][j]==a[i][j+1]) 22 | { 23 | k=0;break; 24 | } 25 | } 26 | if(k==0) 27 | break; 28 | } 29 | if(k==0 || c1!=c2) 30 | printf("NO\n"); 31 | else 32 | printf("YES\n"); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /Little Girl and Maximum Sum.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define mod 1000000007 4 | #define pie 3.14 5 | typedef long long int ll; 6 | /* 7 | .d8b. d8888b. db db .d8b. d8b db 8 | d8' `8b 88 `8D `8b d8' d8' `8b 888o 88 9 | 88ooo88 88oobY' `8bd8' 88ooo88 88V8o 88 10 | 88~~~88 88`8b 88 88~~~88 88 V8o88 11 | 88 88 88 `88. 88 88 88 88 V888 12 | YP YP 88 YD YP YP YP VP V8P 13 | 14 | 15 | */ 16 | 17 | 18 | /////////////////////////////////////// 19 | int main() 20 | { 21 | ios_base::sync_with_stdio(false); 22 | cin.tie(NULL); 23 | #ifndef ONLINE_JUDGE 24 | freopen("input.txt","r",stdin); 25 | freopen("output.txt","w",stdout); 26 | #endif 27 | ll n,m,a,b,i; 28 | ll dp[200005]={0}; 29 | ll arr[200005]; 30 | cin>>n>>m; 31 | for(i=0;i>arr[i]; 33 | sort(arr,arr+n); 34 | while(m--) 35 | { 36 | cin>>a>>b; 37 | dp[a]=dp[a]+1; 38 | dp[b+1]+=-1; 39 | } 40 | for(i=1;i<=(n+1);i++) 41 | dp[i]=dp[i-1]+dp[i]; 42 | sort(dp,dp+n+1); 43 | ll sum=0; 44 | for(i=n;i>=1;i--) 45 | { 46 | sum=sum+dp[i]*arr[i-1]; 47 | } 48 | cout< 2 | int main() 3 | { 4 | int n,i,c=0,x,y; 5 | c=0; 6 | scanf("%d",&n); 7 | while(n%4!=0 && n>=0) 8 | { 9 | n=n-7; 10 | c++; 11 | } 12 | if(n<0) 13 | printf("-1\n"); 14 | else 15 | { 16 | x=n/4; 17 | y=x/7; 18 | x=x-7*y; 19 | c=c+4*y; 20 | for(i=0;i 2 | int main() 3 | { 4 | long long int n,i,sum=0; 5 | scanf("%lld",&n); 6 | for(i=3;i<=n;i++) 7 | { 8 | sum=sum+(i)*(i-1); 9 | } 10 | printf("%lld\n",sum); 11 | } 12 | -------------------------------------------------------------------------------- /Minimum Value Rectangle.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define forn(i, n) for (int i = 0; i < int(n); i++) 4 | 5 | typedef long long li; 6 | 7 | using namespace std; 8 | 9 | const int N = 1000 * 1000 + 13; 10 | 11 | int n, m; 12 | int a[N]; 13 | int b[N]; 14 | 15 | int main() { 16 | int T; 17 | scanf("%d", &T); 18 | forn(_, T){ 19 | scanf("%d", &n); 20 | forn(i, n) 21 | scanf("%d", &a[i]); 22 | sort(a, a + n); 23 | 24 | m = 0; 25 | forn(i, n - 1){ 26 | if (a[i] == a[i + 1]){ 27 | b[m++] = a[i]; 28 | ++i; 29 | } 30 | } 31 | 32 | int A = b[0], B = b[1]; 33 | li P2 = (A + B) * li(A + B); 34 | li S = A * li(B); 35 | 36 | forn(i, m - 1){ 37 | li p2 = (b[i] + b[i + 1]) * li(b[i] + b[i + 1]); 38 | li s = b[i] * li(b[i + 1]); 39 | if (s * P2 > S * p2){ 40 | A = b[i]; 41 | B = b[i + 1]; 42 | S = s; 43 | P2 = p2; 44 | } 45 | } 46 | 47 | printf("%d %d %d %d\n", A, A, B, B); 48 | } 49 | } -------------------------------------------------------------------------------- /Nastya Is Playing Computer Games.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | int a,b,z,ans,x,y; 7 | scanf("%d %d",&a,&b); 8 | x=b-1; 9 | y=a-b; 10 | z=min(x,y); 11 | ans=3*a+z; 12 | printf("%d\n",ans); 13 | } 14 | -------------------------------------------------------------------------------- /Nastya Is Reading a Book.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int n,c=0,i,k,pos; 5 | int a[100000]={0}; 6 | int b[100000]={0}; 7 | scanf("%d",&n); 8 | for(i=0;i=a[i]) 16 | pos=i; 17 | } 18 | printf("%d\n",(n-pos)); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /Nastya Is Transposing Matrices.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main() { 5 | ios_base::sync_with_stdio(false); 6 | cin.tie(NULL); 7 | long long int n,m; 8 | cin>>n>>m; 9 | vector a[n+m]; 10 | vector b[n+m]; 11 | for(long long int i=0;i>inp; 17 | a[i+j].push_back(inp); 18 | } 19 | } 20 | for(long long int i=0;i>inp; 26 | b[i+j].push_back(inp); 27 | } 28 | } 29 | long long int flag=1; 30 | for(long long int i=0;i 2 | using namespace std; 3 | #define mod 1000000007 4 | #define pie 3.14 5 | typedef long long int ll; 6 | /* 7 | .d8b. d8888b. db db .d8b. d8b db 8 | d8' `8b 88 `8D `8b d8' d8' `8b 888o 88 9 | 88ooo88 88oobY' `8bd8' 88ooo88 88V8o 88 10 | 88~~~88 88`8b 88 88~~~88 88 V8o88 11 | 88 88 88 `88. 88 88 88 88 V888 12 | YP YP 88 YD YP YP YP VP V8P 13 | 14 | 15 | */ 16 | 17 | 18 | /////////////////////////////////////// 19 | int main() 20 | { 21 | ios_base::sync_with_stdio(false); 22 | cin.tie(NULL); 23 | #ifndef ONLINE_JUDGE 24 | freopen("input.txt","r",stdin); 25 | freopen("output.txt","w",stdout); 26 | #endif 27 | ll n,ans=0,i,c=0; 28 | cin>>n; 29 | ans=(n/2)+1; 30 | cout< 2 | using namespace std; 3 | #define mod 1000000007 4 | #define pie 3.14 5 | typedef long long int ll; 6 | /* 7 | .d8b. d8888b. db db .d8b. d8b db 8 | d8' `8b 88 `8D `8b d8' d8' `8b 888o 88 9 | 88ooo88 88oobY' `8bd8' 88ooo88 88V8o 88 10 | 88~~~88 88`8b 88 88~~~88 88 V8o88 11 | 88 88 88 `88. 88 88 88 88 V888 12 | YP YP 88 YD YP YP YP VP V8P 13 | 14 | 15 | */ 16 | 17 | 18 | /////////////////////////////////////// 19 | int main() 20 | { 21 | ios_base::sync_with_stdio(false); 22 | cin.tie(NULL); 23 | #ifndef ONLINE_JUDGE 24 | freopen("input.txt","r",stdin); 25 | freopen("output.txt","w",stdout); 26 | #endif 27 | ll x,y,z; 28 | cin>>x>>y>>z; 29 | if(x==y && z==0) 30 | cout<<'0'; 31 | else if(x>=y) 32 | { 33 | if(x>(y+z)) 34 | cout<<'+'; 35 | else 36 | cout<<'?'; 37 | } 38 | else if(y>x) 39 | { 40 | if(y>(x+z)) 41 | cout<<'-'; 42 | else 43 | cout<<'?'; 44 | } 45 | } -------------------------------------------------------------------------------- /Nearest Interesting Number.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define mod 1000000007 4 | #define pie 3.14 5 | typedef long long int ll; 6 | 7 | int main() 8 | { 9 | ios_base::sync_with_stdio(false); 10 | cin.tie(NULL); 11 | #ifndef ONLINE_JUDGE 12 | freopen("input.txt","r",stdin); 13 | freopen("output.txt","w",stdout); 14 | #endif 15 | ll n,i,l,sum=0; 16 | cin>>n; 17 | for(i=n;i<=1500;i++) 18 | { 19 | l=i; 20 | sum=0; 21 | while(l!=0) 22 | { 23 | sum=sum+l%10; 24 | l=l/10; 25 | } 26 | // cout< 2 | using namespace std; 3 | #define mod 1000000007 4 | #define pie 3.14 5 | typedef long long int ll; 6 | 7 | /////////////////////////////////////// 8 | int main() 9 | { 10 | ios_base::sync_with_stdio(false); 11 | cin.tie(NULL); 12 | #ifndef ONLINE_JUDGE 13 | freopen("input.txt","r",stdin); 14 | freopen("output.txt","w",stdout); 15 | #endif 16 | ll n,x,i,mi=10000000000ll,c=0,co=0; 17 | ll arr[100002]; 18 | ll ne[100002]; 19 | cin>>n; 20 | for(i=0;i>arr[i]; 23 | co++; 24 | if(arr[i]<0) 25 | ne[i]=arr[i]; 26 | else 27 | ne[i]=-1*arr[i]-1; 28 | 29 | } 30 | for(i=0;ine[i]) 33 | mi=ne[i]; 34 | } 35 | if(co%2==0) 36 | { 37 | for(i=0;i 2 | using namespace std; 3 | #define mod 1000000007 4 | #define pie 3.14 5 | typedef long long int ll; 6 | /* 7 | .d8b. d8888b. db db .d8b. d8b db 8 | d8' `8b 88 `8D `8b d8' d8' `8b 888o 88 9 | 88ooo88 88oobY' `8bd8' 88ooo88 88V8o 88 10 | 88~~~88 88`8b 88 88~~~88 88 V8o88 11 | 88 88 88 `88. 88 88 88 88 V888 12 | YP YP 88 YD YP YP YP VP V8P 13 | 14 | 15 | */ 16 | 17 | 18 | /////////////////////////////////////// 19 | int main() 20 | { 21 | ios_base::sync_with_stdio(false); 22 | cin.tie(NULL); 23 | #ifndef ONLINE_JUDGE 24 | freopen("input.txt","r",stdin); 25 | freopen("output.txt","w",stdout); 26 | #endif 27 | ll n,i,c=1; 28 | cin>>n; 29 | ll arr[n+5]; 30 | ll ans[n+5]={0}; 31 | for(i=0;i>arr[i]; 33 | sort(arr,arr+n,greater()); 34 | if(arr[0]<(arr[1]+arr[2])) 35 | { 36 | cout<<"YES\n"; 37 | ans[0]=arr[0]; 38 | for(i=1;i 2 | using namespace std; 3 | int main() 4 | { 5 | long long int x,y,am,mi=1000000000000000000,i,j,l,z; 6 | cin>>am>>x>>y; 7 | x=x*1; 8 | y=y*5; 9 | for(i=0;(i*y)<=am;i++) 10 | { 11 | mi=min(mi,(am-y*i)%x); 12 | } 13 | cout< 2 | using namespace std; 3 | #define mod 1000000007 4 | #define pie 3.14 5 | typedef long long int ll; 6 | int main() 7 | { 8 | ios_base::sync_with_stdio(false); 9 | cin.tie(NULL); 10 | ll n,k,ma=0,mi=1000000000ll,i,j,c=0; 11 | ll arr[20005]; 12 | cin>>n>>k; 13 | for(i=0;i>arr[i]; 16 | ma=max(ma,arr[i]); 17 | mi=min(mi,arr[i]); 18 | } 19 | if(ma-mi>k) 20 | { 21 | 22 | cout<<"NO\n"; 23 | return 0; 24 | } 25 | cout<<"YES\n"; 26 | for(i=0;i 2 | using namespace std; 3 | #define mod 1000000007 4 | #define pie 3.14 5 | typedef long long int ll; 6 | /* 7 | .d8b. d8888b. db db .d8b. d8b db 8 | d8' `8b 88 `8D `8b d8' d8' `8b 888o 88 9 | 88ooo88 88oobY' `8bd8' 88ooo88 88V8o 88 10 | 88~~~88 88`8b 88 88~~~88 88 V8o88 11 | 88 88 88 `88. 88 88 88 88 V888 12 | YP YP 88 YD YP YP YP VP V8P 13 | 14 | 15 | */ 16 | 17 | 18 | /////////////////////////////////////// 19 | int main() 20 | { 21 | ios_base::sync_with_stdio(false); 22 | cin.tie(NULL); 23 | #ifndef ONLINE_JUDGE 24 | freopen("input.txt","r",stdin); 25 | freopen("output.txt","w",stdout); 26 | #endif 27 | ll n,k,l,x,i; 28 | cin>>n>>k; 29 | x=2*n-k*4; 30 | for(i=1;i 2 | int a[1000]={0}; 3 | int c=0; 4 | int n,ans=0; 5 | int solve(int x,int sum) 6 | { 7 | if(x>=n) 8 | { 9 | if(sum%360==0) 10 | ans=1; 11 | return 0; 12 | } 13 | solve(x+1,sum+a[x]); 14 | solve(x+1,sum-a[x]); 15 | } 16 | int main() 17 | { 18 | int c=0,i,k=0; 19 | scanf("%d",&n); 20 | for(i=0;i 2 | using namespace std; 3 | int main() 4 | { 5 | int n,m; 6 | scanf("%d %d",&n,&m); 7 | printf("%d %d",(n+m-1-min(n,m)),min(n,m)); 8 | } 9 | -------------------------------------------------------------------------------- /Points on Line.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | long long int n,d,k,i,sum=0,j,x; 5 | long long int a[100004]={0}; 6 | scanf("%lld %lld",&n,&d); 7 | for(i=0;i 2 | using namespace std; 3 | #define mod 1000000007 4 | #define pie 3.14 5 | typedef long long int ll; 6 | /* 7 | .d8b. d8888b. db db .d8b. d8b db 8 | d8' `8b 88 `8D `8b d8' d8' `8b 888o 88 9 | 88ooo88 88oobY' `8bd8' 88ooo88 88V8o 88 10 | 88~~~88 88`8b 88 88~~~88 88 V8o88 11 | 88 88 88 `88. 88 88 88 88 V888 12 | YP YP 88 YD YP YP YP VP V8P 13 | 14 | 15 | */ 16 | 17 | 18 | /////////////////////////////////////// 19 | int main() 20 | { 21 | ios_base::sync_with_stdio(false); 22 | cin.tie(NULL); 23 | #ifndef ONLINE_JUDGE 24 | freopen("input.txt","r",stdin); 25 | freopen("output.txt","w",stdout); 26 | #endif 27 | ll n,x,days=0,c=0; 28 | cin>>n; 29 | ll a[1000000]={0}; 30 | for(ll i=0;i>a[i]; 33 | } 34 | sort(a,a+n);days=1; 35 | for(ll i=0;i=days) 38 | { 39 | c++; 40 | days++; 41 | } 42 | } 43 | cout< 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | long long int n,k,x,i,c=0,ans,y; 7 | long long int a[100002]={0}; 8 | scanf("%lld %lld",&n,&k); 9 | for(i=0;i=1) 17 | { 18 | if(i==0) 19 | c=c+2*(a[i]/2); 20 | else if((double)i==((double)k/2)) 21 | { 22 | c=c+2*(a[i]/2); 23 | } 24 | else 25 | { 26 | y=k-i; 27 | ans=min(a[i],a[y])*2; 28 | c=c+ans; 29 | } 30 | } 31 | } 32 | printf("%lld\n",c); 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /Prime Graph.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | bool prime(int x) { 6 | if (x < 2) return false; 7 | for (int i = 2; i*i <= x; ++i) { 8 | if (x%i == 0) return false; 9 | } 10 | return true; 11 | } 12 | 13 | 14 | int main(int argc, char ** argv){ 15 | ios_base::sync_with_stdio(false); 16 | cin.tie(NULL); 17 | #ifndef ONLINE_JUDGE 18 | freopen("input.txt","r",stdin); 19 | freopen("output.txt","w",stdout); 20 | #endif 21 | int n; cin >> n; 22 | int m = n; 23 | while (!prime(m)) ++m; 24 | cout << m << "\n1 " << n << '\n'; 25 | for (int i = 0; i < n-1; ++i) { 26 | cout << i+1 << ' ' << i+2 << '\n'; 27 | } 28 | //cout< 2 | using namespace std; 3 | #define mod 1000000007 4 | #define pie 3.14 5 | typedef long long int ll; 6 | /* 7 | .d8b. d8888b. db db .d8b. d8b db 8 | d8' `8b 88 `8D `8b d8' d8' `8b 888o 88 9 | 88ooo88 88oobY' `8bd8' 88ooo88 88V8o 88 10 | 88~~~88 88`8b 88 88~~~88 88 V8o88 11 | 88 88 88 `88. 88 88 88 88 V888 12 | YP YP 88 YD YP YP YP VP V8P 13 | 14 | 15 | */ 16 | 17 | 18 | /////////////////////////////////////// 19 | int main() 20 | { 21 | ios_base::sync_with_stdio(false); 22 | cin.tie(NULL); 23 | #ifndef ONLINE_JUDGE 24 | freopen("input.txt","r",stdin); 25 | freopen("output.txt","w",stdout); 26 | #endif 27 | ll n,x,y; 28 | cin>>n>>x>>y; 29 | string s; 30 | cin>>s; 31 | //cout<=(n-x);i--) 37 | { 38 | if(i!=(n-1-y)) 39 | { 40 | if(s[i]=='1') 41 | { 42 | c++; 43 | //cout< 2 | using namespace std; 3 | #define mod 1000000007 4 | #define pie 3.14 5 | typedef long long int ll; 6 | /* 7 | .d8b. d8888b. db db .d8b. d8b db 8 | d8' `8b 88 `8D `8b d8' d8' `8b 888o 88 9 | 88ooo88 88oobY' `8bd8' 88ooo88 88V8o 88 10 | 88~~~88 88`8b 88 88~~~88 88 V8o88 11 | 88 88 88 `88. 88 88 88 88 V888 12 | YP YP 88 YD YP YP YP VP V8P 13 | 14 | 15 | */ 16 | 17 | 18 | /////////////////////////////////////// 19 | int main() 20 | { 21 | ios_base::sync_with_stdio(false); 22 | cin.tie(NULL); 23 | #ifndef ONLINE_JUDGE 24 | freopen("input.txt","r",stdin); 25 | freopen("output.txt","w",stdout); 26 | #endif 27 | ll t; 28 | cin>>t; 29 | while(t--) 30 | { 31 | ll a,b; 32 | cin>>a>>b; 33 | cout<<(b*2)<<"\n"; 34 | } 35 | } -------------------------------------------------------------------------------- /Remove the Substring (easy version).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define ll long long int 4 | int main() 5 | { 6 | string s1,s2,sub,str; 7 | cin>>s1>>s2; 8 | ll n1,n2,i,j,k,l,ans=0; 9 | n1=s1.length(); 10 | n2=s2.length(); 11 | for(i=0;i 2 | using namespace std; 3 | #define ll long long int 4 | int main() 5 | { 6 | string s1,s2,sub,str; 7 | cin>>s1>>s2; 8 | ll n1,n2,i,j,k,l,ans=0; 9 | n1=s1.length(); 10 | n2=s2.length(); 11 | ll c1[200005]={0}; 12 | ll c2[200005]={0}; 13 | for(i=0,j=0;i=0;) 24 | { 25 | if(s1[i]==s2[j]) 26 | { 27 | c2[j]=i; 28 | i--;j--; 29 | } 30 | else 31 | i--; 32 | } 33 | for(i=0;i 2 | using namespace std; 3 | #define mod 1000000007 4 | #define pie 3.14 5 | typedef long long int ll; 6 | /* 7 | .d8b. d8888b. db db .d8b. d8b db 8 | d8' `8b 88 `8D `8b d8' d8' `8b 888o 88 9 | 88ooo88 88oobY' `8bd8' 88ooo88 88V8o 88 10 | 88~~~88 88`8b 88 88~~~88 88 V8o88 11 | 88 88 88 `88. 88 88 88 88 V888 12 | YP YP 88 YD YP YP YP VP V8P 13 | 14 | 15 | */ 16 | 17 | 18 | /////////////////////////////////////// 19 | int main() 20 | { 21 | ios_base::sync_with_stdio(false); 22 | cin.tie(NULL); 23 | #ifndef ONLINE_JUDGE 24 | freopen("input.txt","r",stdin); 25 | freopen("output.txt","w",stdout); 26 | #endif 27 | ll a,b,c,d,ma; 28 | cin>>a>>b>>c>>d; 29 | if(a>b && a>c && a>d) 30 | cout<<(a-b)<<" "<<(a-c)<<" "<<(a-d)<a && b>c && b>d) 32 | cout<<(b-a)<<" "<<(b-c)<<" "<<(b-d)<b && c>a && c>d) 34 | cout<<(c-b)<<" "<<(c-a)<<" "<<(c-d)<b && d>a && d>c) 36 | cout<<(d-b)<<" "<<(d-a)<<" "<<(d-c)< 2 | using namespace std; 3 | #define mod 1000000007 4 | #define pie 3.14 5 | typedef long long int ll; 6 | int main() 7 | { 8 | ios_base::sync_with_stdio(false); 9 | cin.tie(NULL); 10 | ll n,k,a,b,mid,i; 11 | cin>>n>>k; 12 | ll arr[1001]={0}; 13 | for(i=0;i>a>>b; 16 | arr[a]=1; 17 | arr[b]=1; 18 | } 19 | for(i=1;i<=n;i++) 20 | { 21 | if(arr[i]==0) 22 | { 23 | mid=i; 24 | } 25 | } 26 | cout<<(n-1)<<"\n"; 27 | for(i=1;i<=n;i++) 28 | { 29 | if(i!=mid) 30 | cout< 2 | using namespace std; 3 | #define mod 1000000007 4 | #define pie 3.14 5 | typedef long long int ll; 6 | /* 7 | .d8b. d8888b. db db .d8b. d8b db 8 | d8' `8b 88 `8D `8b d8' d8' `8b 888o 88 9 | 88ooo88 88oobY' `8bd8' 88ooo88 88V8o 88 10 | 88~~~88 88`8b 88 88~~~88 88 V8o88 11 | 88 88 88 `88. 88 88 88 88 V888 12 | YP YP 88 YD YP YP YP VP V8P 13 | 14 | 15 | */ 16 | 17 | 18 | /////////////////////////////////////// 19 | int main() 20 | { 21 | ios_base::sync_with_stdio(false); 22 | cin.tie(NULL); 23 | #ifndef ONLINE_JUDGE 24 | freopen("input.txt","r",stdin); 25 | freopen("output.txt","w",stdout); 26 | #endif 27 | ll n,t,c=0,ans,min=1000005,a,b,pos=0; 28 | cin>>n>>t; 29 | while(n--) 30 | { 31 | c++; 32 | cin>>a>>b; 33 | ans=((t-1)/b)*b+a; 34 | while(ans>=t && ans>=a) 35 | { 36 | if((ans-b)>=t && (ans-b)>=a) 37 | ans=ans-b; 38 | else 39 | break; 40 | } 41 | ans=ans-t; 42 | while(ans<0) 43 | {ans=ans+b;} 44 | //cout< 2 | using namespace std; 3 | #define mod 1000000007 4 | #define pie 3.14 5 | typedef long long int ll; 6 | /* 7 | .d8b. d8888b. db db .d8b. d8b db 8 | d8' `8b 88 `8D `8b d8' d8' `8b 888o 88 9 | 88ooo88 88oobY' `8bd8' 88ooo88 88V8o 88 10 | 88~~~88 88`8b 88 88~~~88 88 V8o88 11 | 88 88 88 `88. 88 88 88 88 V888 12 | YP YP 88 YD YP YP YP VP V8P 13 | 14 | 15 | */ 16 | 17 | 18 | /////////////////////////////////////// 19 | int main() 20 | { 21 | ios_base::sync_with_stdio(false); 22 | cin.tie(NULL); 23 | #ifndef ONLINE_JUDGE 24 | freopen("input.txt","r",stdin); 25 | freopen("output.txt","w",stdout); 26 | #endif 27 | ll n,k,rem,i; 28 | cin>>n>>k; 29 | ll ans; 30 | ans=ceil((long double)n/(2*k+1)); 31 | cout< 2 | using namespace std; 3 | #define mod 1000000007 4 | #define pie 3.14 5 | typedef long long int ll; 6 | /* 7 | .d8b. d8888b. db db .d8b. d8b db 8 | d8' `8b 88 `8D `8b d8' d8' `8b 888o 88 9 | 88ooo88 88oobY' `8bd8' 88ooo88 88V8o 88 10 | 88~~~88 88`8b 88 88~~~88 88 V8o88 11 | 88 88 88 `88. 88 88 88 88 V888 12 | YP YP 88 YD YP YP YP VP V8P 13 | 14 | 15 | */ 16 | 17 | 18 | /////////////////////////////////////// 19 | int main() 20 | { 21 | ios_base::sync_with_stdio(false); 22 | cin.tie(NULL); 23 | #ifndef ONLINE_JUDGE 24 | freopen("input.txt","r",stdin); 25 | freopen("output.txt","w",stdout); 26 | #endif 27 | ll t,i,x,y,ans=0; 28 | cin>>t; 29 | string s; 30 | ll arr[100]={0}; 31 | for(i=0;i>s; 34 | arr[s[0]-'a']++; 35 | } 36 | //cout<0) 40 | { 41 | x=arr[i]/2; 42 | y=arr[i]-x; 43 | //cout< 5 | using namespace std; 6 | using ll = long long; 7 | 8 | int main() 9 | { 10 | ios::sync_with_stdio(false); 11 | cin.tie(NULL); 12 | ll n, k; 13 | cin >> n >> k; 14 | ll ans = (-3 + (ll)sqrt(9 + 8 * (n + k))) / 2; 15 | cout << n - ans; 16 | return 0; 17 | } -------------------------------------------------------------------------------- /Substring Game in the Lesson.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define mod 1000000007 4 | #define pie 3.14 5 | typedef long long int ll; 6 | /* 7 | .d8b. d8888b. db db .d8b. d8b db 8 | d8' `8b 88 `8D `8b d8' d8' `8b 888o 88 9 | 88ooo88 88oobY' `8bd8' 88ooo88 88V8o 88 10 | 88~~~88 88`8b 88 88~~~88 88 V8o88 11 | 88 88 88 `88. 88 88 88 88 V888 12 | YP YP 88 YD YP YP YP VP V8P 13 | 14 | 15 | */ 16 | 17 | 18 | /////////////////////////////////////// 19 | int main() 20 | { 21 | ios_base::sync_with_stdio(false); 22 | cin.tie(NULL); 23 | #ifndef ONLINE_JUDGE 24 | freopen("input.txt","r",stdin); 25 | freopen("output.txt","w",stdout); 26 | #endif 27 | string s; 28 | cin>>s; 29 | ll n,i,mi=mod,x; 30 | n=s.length(); 31 | for(i=0;i 2 | int main() 3 | { 4 | int n,ma=0,i,ans,c1=0,c2=0; 5 | int a[100001]; 6 | scanf("%d",&n); 7 | for(i=0;ic2)?c2:c1; 15 | if(ans>ma) 16 | ma=ans; 17 | if(a[i+1]==2) 18 | c2=0; 19 | } 20 | else if(a[i]==2) 21 | {c2++; 22 | ans=(c1>c2)?c2:c1; 23 | if(ans>ma) 24 | ma=ans; 25 | if(a[i+1]==1) 26 | c1=0; 27 | } 28 | } 29 | printf("%d\n",ma*2); 30 | } 31 | -------------------------------------------------------------------------------- /Telephone Number.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define mod 1000000007 4 | #define pie 3.14 5 | typedef long long int ll; 6 | /* 7 | .d8b. d8888b. db db .d8b. d8b db 8 | d8' `8b 88 `8D `8b d8' d8' `8b 888o 88 9 | 88ooo88 88oobY' `8bd8' 88ooo88 88V8o 88 10 | 88~~~88 88`8b 88 88~~~88 88 V8o88 11 | 88 88 88 `88. 88 88 88 88 V888 12 | YP YP 88 YD YP YP YP VP V8P 13 | 14 | 15 | */ 16 | 17 | 18 | /////////////////////////////////////// 19 | int main() 20 | { 21 | ios_base::sync_with_stdio(false); 22 | cin.tie(NULL); 23 | #ifndef ONLINE_JUDGE 24 | freopen("input.txt","r",stdin); 25 | freopen("output.txt","w",stdout); 26 | #endif 27 | ll t; 28 | cin>>t; 29 | while(t--) 30 | { 31 | ll n,c,i; 32 | cin>>n; 33 | string s; 34 | cin>>s; 35 | c=0; 36 | for(i=0;i<(n-10);i++) 37 | { 38 | if(s[i]=='8') 39 | { 40 | c++; 41 | break; 42 | } 43 | } 44 | //cout< 2 | using namespace std; 3 | #define mod 1000000007 4 | #define pie 3.14 5 | typedef long long int ll; 6 | /* 7 | .d8b. d8888b. db db .d8b. d8b db 8 | d8' `8b 88 `8D `8b d8' d8' `8b 888o 88 9 | 88ooo88 88oobY' `8bd8' 88ooo88 88V8o 88 10 | 88~~~88 88`8b 88 88~~~88 88 V8o88 11 | 88 88 88 `88. 88 88 88 88 V888 12 | YP YP 88 YD YP YP YP VP V8P 13 | 14 | 15 | */ 16 | 17 | 18 | /////////////////////////////////////// 19 | int main() 20 | { 21 | ios_base::sync_with_stdio(false); 22 | cin.tie(NULL); 23 | #ifndef ONLINE_JUDGE 24 | freopen("input.txt","r",stdin); 25 | freopen("output.txt","w",stdout); 26 | #endif 27 | ll b,p,f,ma,mi,h,c,x,y,sum=0; 28 | ll t; 29 | cin>>t; 30 | while(t--) 31 | { 32 | sum=0; 33 | cin>>b>>p>>f; 34 | cin>>h>>c; 35 | if(c>h) 36 | { 37 | x=min(b/2,f); 38 | b=b-x*2; 39 | f=f-x; 40 | sum+=x*c; 41 | y=min(b/2,p); 42 | sum+=y*h; 43 | } 44 | else 45 | { 46 | x=min(b/2,p); 47 | b=b-x*2; 48 | p=p-x; 49 | sum+=x*h; 50 | y=min(b/2,f); 51 | sum+=y*c; 52 | } 53 | cout< 2 | using namespace std; 3 | #define mod 1000000007 4 | #define pie 3.14 5 | typedef long long int ll; 6 | /* 7 | .d8b. d8888b. db db .d8b. d8b db 8 | d8' `8b 88 `8D `8b d8' d8' `8b 888o 88 9 | 88ooo88 88oobY' `8bd8' 88ooo88 88V8o 88 10 | 88~~~88 88`8b 88 88~~~88 88 V8o88 11 | 88 88 88 `88. 88 88 88 88 V888 12 | YP YP 88 YD YP YP YP VP V8P 13 | 14 | 15 | */ 16 | 17 | 18 | /////////////////////////////////////// 19 | ll po=1,y=998244353ll; 20 | ll power(ll n,ll k) 21 | { 22 | while(k!=0) 23 | { 24 | if(k%2==0) 25 | { 26 | n=(n%y*n%y)%y; 27 | k=k/2; 28 | } 29 | k--; 30 | po=(po%y*n%y)%y; 31 | } 32 | return po; 33 | } 34 | int main() 35 | { 36 | ios_base::sync_with_stdio(false); 37 | cin.tie(NULL); 38 | #ifndef ONLINE_JUDGE 39 | freopen("input.txt","r",stdin); 40 | freopen("output.txt","w",stdout); 41 | #endif 42 | ll a,b; 43 | cin>>a>>b; 44 | cout< 2 | int main() 3 | { 4 | long long int y,n,k,x,i,c=0; 5 | scanf("%lld %lld %lld",&y,&k,&n); 6 | x=ceil((1.0*y)/k)*k; 7 | for(i=x;i<=n;i=i+k) 8 | { 9 | if((i-y)>0) 10 | {printf("%lld ",(i-y)); 11 | c++;} 12 | 13 | } 14 | if(c==0) 15 | printf("-1\n"); 16 | } 17 | -------------------------------------------------------------------------------- /Two Buttons.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define mod 1000000007 4 | #define pie 3.14 5 | typedef long long int ll; 6 | /* 7 | .d8b. d8888b. db db .d8b. d8b db 8 | d8' `8b 88 `8D `8b d8' d8' `8b 888o 88 9 | 88ooo88 88oobY' `8bd8' 88ooo88 88V8o 88 10 | 88~~~88 88`8b 88 88~~~88 88 V8o88 11 | 88 88 88 `88. 88 88 88 88 V888 12 | YP YP 88 YD YP YP YP VP V8P 13 | 14 | 15 | */ 16 | 17 | 18 | /////////////////////////////////////// 19 | int main() 20 | { 21 | ios_base::sync_with_stdio(false); 22 | cin.tie(NULL); 23 | #ifndef ONLINE_JUDGE 24 | freopen("input.txt","r",stdin); 25 | freopen("output.txt","w",stdout); 26 | #endif 27 | ll n,m,c=0; 28 | cin>>n>>m; 29 | while(m>n) 30 | { 31 | if(m%2==0) 32 | { 33 | m=m/2; 34 | c++; 35 | } 36 | else 37 | { 38 | m++; 39 | c++; 40 | } 41 | } 42 | c=c+(n-m); 43 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int n; 6 | string s,s1,s2; 7 | cin>>s; 8 | n=s.length(); 9 | int x=s.find("AB"); 10 | int y=s.find("BA"); 11 | //cout< 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | int i; 7 | string a,b; 8 | cin>>a; 9 | cin>>b; 10 | for(i=0;i 2 | using namespace std; 3 | int main() 4 | { 5 | long long int t,c=0,a,b,sum1=0,sum2=0,sum3=0; 6 | mapx; 7 | mapy; 8 | map,long long int>xy; 9 | scanf("%lld",&t); 10 | while(t--) 11 | { 12 | scanf("%lld %lld",&a,&b); 13 | x[a]++; 14 | y[b]++; 15 | xy[make_pair(a,b)]++; 16 | } 17 | for(auto const& xc:x) 18 | { 19 | sum1=sum1+(xc.second)*(xc.second-1)/2; 20 | } 21 | for(auto const& yc:y) 22 | { 23 | sum2=sum2+(yc.second)*(yc.second-1)/2; 24 | } 25 | for(auto xyc:xy) 26 | { 27 | sum3=sum3+(xyc.second)*(xyc.second-1)/2; 28 | } 29 | printf("%lld\n",(sum1+sum2-sum3)); 30 | 31 | 32 | 33 | } 34 | -------------------------------------------------------------------------------- /Water Lily.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define mod 1000000007 4 | #define pie 3.14 5 | typedef long long int ll; 6 | /* 7 | .d8b. d8888b. db db .d8b. d8b db 8 | d8' `8b 88 `8D `8b d8' d8' `8b 888o 88 9 | 88ooo88 88oobY' `8bd8' 88ooo88 88V8o 88 10 | 88~~~88 88`8b 88 88~~~88 88 V8o88 11 | 88 88 88 `88. 88 88 88 88 V888 12 | YP YP 88 YD YP YP YP VP V8P 13 | 14 | 15 | */ 16 | 17 | 18 | /////////////////////////////////////// 19 | int main() 20 | { 21 | ios_base::sync_with_stdio(false); 22 | cin.tie(NULL); 23 | #ifndef ONLINE_JUDGE 24 | freopen("input.txt","r",stdin); 25 | freopen("output.txt","w",stdout); 26 | #endif 27 | ll l,h; 28 | cin>>h>>l; 29 | cout< 2 | using namespace std; 3 | #define mod 1000000007 4 | #define pie 3.14 5 | typedef long long int ll; 6 | /* 7 | .d8b. d8888b. db db .d8b. d8b db 8 | d8' `8b 88 `8D `8b d8' d8' `8b 888o 88 9 | 88ooo88 88oobY' `8bd8' 88ooo88 88V8o 88 10 | 88~~~88 88`8b 88 88~~~88 88 V8o88 11 | 88 88 88 `88. 88 88 88 88 V888 12 | YP YP 88 YD YP YP YP VP V8P 13 | 14 | 15 | */ 16 | 17 | 18 | /////////////////////////////////////// 19 | int main() 20 | { 21 | ios_base::sync_with_stdio(false); 22 | cin.tie(NULL); 23 | #ifndef ONLINE_JUDGE 24 | freopen("input.txt","r",stdin); 25 | freopen("output.txt","w",stdout); 26 | #endif 27 | ll t; 28 | cin>>t; 29 | while(t--) 30 | { 31 | ll x,y,z; 32 | cin>>x>>y>>z; 33 | z=z+1; 34 | if(z%3==1) 35 | cout< 2 | int main() 3 | { 4 | long long int n,m,sum=0,i; 5 | long long int a[100005]; 6 | scanf("%lld %lld",&n,&m); 7 | scanf("%lld",&a[0]); 8 | sum=sum+(a[0]-1); 9 | for(i=1;ia[i-1]) 13 | sum=sum+(a[i]-a[i-1]); 14 | else if(a[i] 2 | 3 | using namespace std; 4 | 5 | #define x first 6 | #define y second 7 | 8 | const int N = 200043; 9 | 10 | void norm(pair& p) 11 | { 12 | if(p.x < 0) 13 | { 14 | p.x *= -1; 15 | p.y *= -1; 16 | } 17 | else if (p.x == 0 && p.y < 0) 18 | { 19 | p.y *= -1; 20 | } 21 | int d = __gcd(abs(p.x), abs(p.y)); 22 | p.x /= d; 23 | p.y /= d; 24 | } 25 | 26 | map, int> m; 27 | 28 | int a[N]; 29 | int b[N]; 30 | int n; 31 | 32 | int main() 33 | { 34 | scanf("%d", &n); 35 | for(int i = 0; i < n; i++) 36 | scanf("%d", &a[i]); 37 | for(int i = 0; i < n; i++) 38 | scanf("%d", &b[i]); 39 | int ans = 0; 40 | int cnt0 = 0; 41 | for(int i = 0; i < n; i++) 42 | { 43 | if(a[i] == 0) 44 | { 45 | if(b[i] == 0) 46 | cnt0++; 47 | } 48 | else 49 | { 50 | pair p = make_pair(-b[i], a[i]); 51 | norm(p); 52 | m[p]++; 53 | ans = max(ans, m[p]); 54 | } 55 | } 56 | cout << cnt0 + ans << endl; 57 | } --------------------------------------------------------------------------------